Skip to content

chatd: admin setting for token-budget compaction (strategy and fallback) #321

Closed

Description

@ibetitsmike

Coder Agents created this issue on behalf of @ibetitsmike.

Part of #4. Follow-up to #283.

Gap

The token-budget context windows from #283 are on main (#285, #313, #315, #314, #316), behind the fork-token-budget experiment. There is no setting for them anywhere in the UI or the API:

  • The chatd: token-budget context windows instead of summary compaction #283 design chose "no new deployment setting". With the experiment on, every chat that has the notes and new_context tools uses token-budget windows. With it off, every chat uses summary compaction.
  • So the only switch is the server experiment list, which only ops can change and which needs a restart. An admin cannot see whether the feature is on, cannot turn it on or off, and cannot pick what happens when an agent ignores the handoff requests.
  • On 2026-11-14 Mike looked for the option on the daily server and did not find it.

The upstream prototype (coder#31191, read only) and Xum both have an admin setting for this. The prototype's version is a "Context window fallback" select on the Coder Agents settings page, stored in site_configs and served by /api/experimental/chats/config/context-windows.

Wanted

An admin setting on the Coder Agents settings page that controls token-budget compaction. It is shown only when fork-token-budget is on.

  • Compaction strategy: "Summary" (as on main) or "Token budget" (context windows). The default is "Summary". Ops can then turn the experiment on with no change in behavior, and an admin opts in from the UI.
  • Forced rollover fallback: what happens when a chat reaches the usable limit without calling new_context. The choices are "Start a new context window" (the current behavior of feat(coderd/x/chatd): start token-budget context windows behind fork-token-budget #314, and the default) or "Summarize the conversation".
  • The description says that the handoff point is the per-model compression threshold, which is set on the model config. It also says that a threshold of 100% turns the budget off for that model.

Backend:

  • Fork code only: fork_*.go files, one hook line per upstream file, forkdb queries, and no numbered migrations. Follow the existing fork settings pattern, ForkSubagentLimits (codersdk types, a /api/v2/chats/fork/... route, dbauthz, and ForkSubagentLimitsSettings.tsx on OrganizationAgentSettings). Choose between organization scope and deployment scope from that pattern and say why in the PR.
  • The read and the update need the same RBAC as the subagent limits setting. The route sits behind httpmw.RequireExperiment(api.Experiments, codersdk.ExperimentForkTokenBudget) in coderd/fork_chat_routes.go, like the other fork routes.
  • chatd reads the setting once per turn, where tokenBudgetTriggers runs in turn_environment.go. It does not add a store read per step. With "Summary", the turn takes exactly the main path: no handoff or final requests, no new_context tool, summary compaction. The notes and chat_history tools may stay, because they are useful without windows. The PR states which tools stay.
  • With the fallback set to "Summarize", the forced point runs the upstream summary compaction instead of the lead-in window.

Acceptance

  • API tests: get returns the defaults (summary, new_window) when unset. Update round-trips. Bad values return 400. A member without the permission gets 403. The route is refused with the experiment off.
  • chatd tests: with the experiment on and the strategy set to summary, a small-context-limit chat compacts by summary and gets no handoff request. With token_budget, the feat(coderd/x/chatd): start token-budget context windows behind fork-token-budget #314 end-to-end test still passes. With token_budget and the summary fallback, ignoring the requests summarizes at the usable limit.
  • A site test or story for the settings component, and a check that it is hidden when the experiment is off.
  • Docs: docs/fork/pstack-adapter.md, coderd/x/chatd/ARCHITECTURE.md (written in the PR, no TODOs), and make gen output.
  • Out of scope: a per-user or per-chat override, and turning the experiment on for the daily server (an ops step in Fork ops).

Activity

  1. ibetitsmike commented on Nov 14, 2026

    @ibetitsmike
    OwnerAuthor

    Coder Agents acted on behalf of @ibetitsmike.

    The API and chatd part (#330) merged as 9308bf6 at 16:02Z. The UI (#331) comes next, after the deploy, once it is retargeted to main and has fork-ci on its head.

  2. ibetitsmike commented on Nov 14, 2026

    @ibetitsmike
    OwnerAuthor

    Coder Agents acted on behalf of @ibetitsmike.

    Done. Backend #330 (9308bf6, live 17:11Z) and UI #331 (9f99450, merged 17:12Z, deploy pending) are on main. The setting is under Admin settings > AI > Coder Agents per organization: strategy summary (default) or token_budget, fallback new_window (default) or summary. It shows and works only with the fork-token-budget experiment on; enabling it on the daily server is an ops step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions