Browse Source

fix: avoid caching missing context limits

dhaern 3 months ago
parent
commit
6b73a42de2
2 changed files with 16 additions and 4 deletions
  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 () => {
     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 hook = createTodoContinuationHook(ctx);
       const output = userMessages('review this diff', 'sub1', 'oracle');
       const output = userMessages('review this diff', 'sub1', 'oracle');
 
 
@@ -763,6 +765,14 @@ describe('createTodoContinuationHook', () => {
       expect(allMessageText(output)).not.toContain(
       expect(allMessageText(output)).not.toContain(
         SUBAGENT_CONTEXT_HYGIENE_REMINDER,
         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 () => {
     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
           typeof context === 'number' && Number.isFinite(context) && context > 0
             ? context
             ? context
             : undefined;
             : undefined;
-        contextLimitByModel.set(key, limit);
+        if (limit !== undefined) {
+          contextLimitByModel.set(key, limit);
+        }
         return limit;
         return limit;
       } catch (error) {
       } catch (error) {
         log(
         log(