Repository navigation
feat(coderd/x/chatd): start token-budget context windows behind fork-token-budget - #314
Conversation
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6fa6ff5de
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1cd3f6cdf3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82a5a6d779
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@codex review |
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merged as 67c143c (squash) at 08:26Z. Before the merge, the server was confirmed on the previous deploy, 6ae5568. Gates on head 44daaea:
Not exercised: a live chat with a real model rolling over windows on a deployed server, and a real pre_compact hook. The tests use fake models. |
* feat(coderd/x/chatd): add organization token budget setting The fork-token-budget experiment now reads a per-organization setting. The summary strategy, the default, keeps main's summary compaction with notes and chat_history. The token_budget strategy keeps the windows of #314, and its fallback picks a new window or a summary at the usable limit. * fix(coderd/x/chatd): keep the token budget fallback with the turn's tools The new_context tool holds the fallback of the step that built it, so triggers and compaction follow one setting and a foreign new_context tool does not make a turn eligible. With the summary fallback, the compaction model override's trigger still applies.
* feat(coderd/x/chatd): add organization token budget setting The fork-token-budget experiment now reads a per-organization setting. The summary strategy, the default, keeps main's summary compaction with notes and chat_history. The token_budget strategy keeps the windows of #314, and its fallback picks a new window or a summary at the usable limit. * feat(site): add the organization token budget setting * fix(coderd/x/chatd): keep the token budget fallback with the turn's tools The new_context tool holds the fallback of the step that built it, so triggers and compaction follow one setting and a foreign new_context tool does not make a turn eligible. With the summary fallback, the compaction model override's trigger still applies. * fix(site): announce token budget save errors and name user thresholds * fix(site): describe token budget options to screen readers and keep saves * fix(site): scope token budget form ids and tighten its stories, tests and docs * fix(site): document token budget section contracts and show a failed save after an edit * test(site): cover token budget read-only, hidden and fallback gate states * fix(site): drop repeated token budget comments and the disabled label pointer
Part of #283
With the
fork-token-budgetexperiment on, an eligible turn no longer summarizes its conversation when the context fills up. It works in token-budget windows. The model keeps its state in notes and starts a fresh window from them.chat_history(#313) still reads the earlier windows.What changed
newTokenBudgetinfork_token_budget.go, from the model's context limit and the compression threshold that already applies (per-model value or the user's override):syncForkContextmay commit one model-only<context_budget>request: the handoff request once per window at the handoff point, and the final request once per window at the final point. A window whose first prompt is already past the handoff point, or whosenew_contextcall succeeded, gets none.new_context. It takes no arguments, runs serially after the other calls of its step, and refuses until a note changed in the current window.tokenBudgetTriggers(hook inturn_environment.go) makes compaction required whennew_contextsucceeded in the window or the last prompt reached the usable limit. The other automatic triggers do not apply. The binding trigger becomes the usable percent, so the existing still-over-limit guard stops a loop of rollovers.forkGenerateCompaction(hook ingeneration.go) sends an automatic compaction of an eligible turn tocontextWindowRollover. It makes no model call. Its summary is the lead-in<context_window id="w:N">, which lists the notes, points atcheckpoint.mdand carries the model context of apre_compacthook. The boundary rows and thechat_summarizedpart are unchanged, sochat_historylists and reads the earlier windows.decideGenerationAction), so a rollover never splits a tool call from its result./compactstill summarizes.Subagents and restricted turns
A turn is eligible only when it keeps
notes,chat_historyandnew_context, so the lead-in never points at a missing tool. Plan mode,explorechildren and read-only or allowlisted custom agent types drop those tools, so they keep summary compaction.tokenBudgetMessageapplies the same check before the tools exist, so those chats get no requests either. A general subagent chat has its own notes and its own windows; the parent's windows do not affect it.Experiment off
With
fork-token-budgetoff,tokenBudgetEligibleis false, the triggers come back unchanged,forkGenerateCompactioncallschatloop.GenerateCompactionas before, no request is sent andnew_contextis not listed.TestTokenBudgetWindows/ExperimentOffproves the summary path still runs.Tests
TestTokenBudgetWindowsruns a chat with a small context limit:Cooperative: the handoff request goes out once, the model writes the checkpoint and callsnew_context, the next window starts with the lead-in and no summary call, andchat_historyreads a message from the earlier window.ForcedRollover: the chat ignores the handoff and final requests, each sent once. The prompt that reaches the usable limit rolls the window over without anew_contextcall, and its tool call and result both stay in the first window.PlanModeSummarizes: plan mode keeps summary compaction.ExperimentOff: summary compaction as on main.Unit tests cover the ladder, the request schedule, the triggers and the eligibility.
Run locally, all passing:
flock ~/.fork-go.lock go build ./coderd/...flock ~/.fork-go.lock go test -count=1 ./coderd/x/chatd/...flock ~/.fork-go.lock go test -count=1 ./codersdk/flock ~/.fork-go.lock golangci-lint run --config=.golangci.new-code.yaml --new-from-merge-base=origin/main ./coderd/x/chatd/(0 issues)make lint/emdash lint/markdown lint/architecture lint/agentsNot verified: a live model on a deployed server. The UI divider for a window boundary comes in the next PR.
Docs:
coderd/x/chatd/ARCHITECTURE.mdanddocs/fork/pstack-adapter.md.