feat(server): enforce configurable thread context limits #10095
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/10095/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts lines 1298 to 1302OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1291,3 +1292,11 @@12911292 return;12921293 }12931294 const { message, hasOtherUserMessages } = turnStart.value;1295+ const isCompactCommand = isCompactCommandMessage(message);1296+ // Compaction is the only way an over-limit thread can lower its context, so1297+ // /compact and the messages queued behind it bypass the usage-limit gate below.1298+ const bypassesContextLimit =1299+ isCompactCommand ||1300+ resumed !== undefined ||1301+ compactingThreadIds.has(event.payload.threadId) ||1302+ turnsAfterCompaction.has(event.payload.threadId);docs/user/usage.md lines 71 to 72OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -64,3 +64,9 @@6464 API-key accounts may not report subscription limits. This also applies to Claude connections6565 using a proxy through `ANTHROPIC_AUTH_TOKEN`.666667+## Limit thread context68+69+Long threads resend their whole conversation on every turn. T3 Code stops new turns in a thread70+once its latest reported context reaches the **Thread token limit**, 250,000 tokens by default.71+Change it in **Settings → General**; the limit belongs to the environment, so it applies to every72+provider and client connected to it. When a thread reaches the limit, send `/compact` to shrink
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1234Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1291,3 +1292,7 @@12911292 return;12921293 }12931294 const { message, hasOtherUserMessages } = turnStart.value;1295+ const isCompactCommand = isCompactCommandMessage(message);1296+ // Compaction is the only way an over-limit thread can lower its context, so1297+ // /compact and the messages queued behind it bypass the usage-limit gate below.1298+ const bypassesContextLimit =
- apps/web/src/components/settings/SettingsPanels.tsx line 2593OutdatedResolvedby saphid(GitHub profile, opens in a new tab)@@ -2569,0 +2573,21 @@2573+ serverScoped2574+ settingKeys={["threadContextTokenLimit"]}2575+ {...searchableSetting("thread-context-token-limit")}2576+ description="Stop new turns in a thread after its reported context reaches this size. Send /compact or start a new thread to continue."2577+ resetAction={2578+ settings.threadContextTokenLimit !==2579+ DEFAULT_UNIFIED_SETTINGS.threadContextTokenLimit ? (2580+ <SettingResetButton2581+ label="thread token limit"2582+ onClick={() =>2583+ updateSettings({2584+ threadContextTokenLimit: DEFAULT_UNIFIED_SETTINGS.threadContextTokenLimit,2585+ })2586+ }2587+ />2588+ ) : null2589+ }2590+ control={2591+ <div className="flex items-center gap-2">2592+ <NumberField2593+ value={settings.threadContextTokenLimit / 1_000}
juliusmarminge closed this
Sign in to join this conversation.




Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR adds a default-on server admission gate that can stop provider turns when reported thread context reaches 250,000 tokens, along with a new environment setting and compaction recovery flow. Because it changes the product default and materially changes existing runtime behavior, the change warrants human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).