瀏覽代碼

fix: avoid caching missing context limits

dhaern 2 月之前
父節點
當前提交
6b73a42de2
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 13 3
      src/hooks/todo-continuation/index.test.ts
  2. 3 1
      src/hooks/todo-continuation/index.ts

+ 13 - 3
src/hooks/todo-continuation/index.test.ts

@@ -743,9 +743,11 @@ describe('createTodoContinuationHook', () => {
     });
 
     test('does not inject context warning when model has no configured context limit', async () => {
-      const ctx = createMockContext({
-        providersResult: providersWithContextLimit(),
-      });
+      let contextLimit: number | undefined;
+      const ctx = createMockContext();
+      ctx.client.config.providers = mock(async () =>
+        providersWithContextLimit(contextLimit),
+      );
       const hook = createTodoContinuationHook(ctx);
       const output = userMessages('review this diff', 'sub1', 'oracle');
 
@@ -763,6 +765,14 @@ describe('createTodoContinuationHook', () => {
       expect(allMessageText(output)).not.toContain(
         SUBAGENT_CONTEXT_HYGIENE_REMINDER,
       );
+
+      contextLimit = 1000;
+      await hook.handleToolExecuteAfter({ tool: 'grep', sessionID: 'sub1' });
+      await hook.handleMessagesTransform(output);
+
+      expect(allMessageText(output)).toContain(
+        SUBAGENT_CONTEXT_HYGIENE_REMINDER,
+      );
     });
 
     test('does not warn resumed high-context subagent until it uses another tool', async () => {

+ 3 - 1
src/hooks/todo-continuation/index.ts

@@ -273,7 +273,9 @@ export function createTodoContinuationHook(
           typeof context === 'number' && Number.isFinite(context) && context > 0
             ? context
             : undefined;
-        contextLimitByModel.set(key, limit);
+        if (limit !== undefined) {
+          contextLimitByModel.set(key, limit);
+        }
         return limit;
       } catch (error) {
         log(