Expand description
How full each agent’s context is, as srv sees it
(docs/specs/SPEC_AGENT_SELF_COMPACTION_2026_10_23.md §3.2), for
Agents context, the self-compact rate limit and the turn-end hint.
Claude: the main agent’s per-call usage from message_start and assistant
frames (input + cache creation + cache read), as the pane’s own meter reads
it (frontend/app/view/agent/main-agent-usage.ts); subagent frames carry a
parent_tool_use_id and are skipped. The window and the auto-compact point
come from the CLI’s get_context_usage answer. Codex: the reading srv takes
from its session file after each turn (subprocess/codex_context.rs).
Structs§
- Context
Reading - One pane’s reading.
- HintFor
- What a turn-end hint is worked out and worded for: the kind of agent it goes to.
Constants§
- COMPACTION_
NOTE_ KEY - The key the result of an ACP agent’s compaction is held under.
- DEFAULT_
BACKSTOP_ AT - DEFAULT_
FRESH_ HINT_ AT - DEFAULT_
HINT_ AT - HINT_
NOTE_ KEY - The key the turn-end hint is held under (
reactive::held_notes). - MIN_
CALLS_ BETWEEN - No self-compaction this soon after the last one, in calls or in time: also what stops a compact, catch-up, compact loop.
- MIN_
MS_ BETWEEN - SETTING_
BACKSTOP_ AT agent:compactbackstopat: the context size, in tokens, over which srv itself compacts a container agent between turns (compact_backstop), because it ignored the hint. 0 turns it off.- SETTING_
FRESH_ HINT_ AT agent:freshhintat: from this many tokens, a turn that finished a task suggests a fresh session instead.- SETTING_
HINTS agent:compacthints: the turn-end hint (§3.5), on unlessfalse.- SETTING_
HINT_ AT agent:compacthintat: the context size, in tokens, from which the hint suggests compacting.
Functions§
- acp_
compaction_ carried_ by - The
/compactof a compaction begun forblock_idwas written to the harness as promptprompt_id. A/compactnobody begun (a person typed it) carries no compaction. - acp_
compaction_ turn_ ended - The prompt
prompt_idof an ACP agent ended,okor by an error. When it is the one that carried the compaction:Some(note)if it did not run (an error), else the compaction waits for the next reading of the size. Any other prompt’s end leaves the compaction alone. - backstop_
at - The size over which srv compacts a container agent itself, or
Nonewhen the setting is 0 (off). - begin_
acp_ compaction /compactis about to be sent to an ACP agent: remember the size it holds. The answer is the firstusage_updateafter the turn that carries it, because a reading during it may be of the summarizing call.- cancel_
acp_ compaction /compactcould not be sent to an ACP agent.- clear_
task_ boundary - A turn ended without giving its turn-end hint (an error result).
- compact_
sent - The scheduled self-compaction was sent (
sent), or given up or refused by the controller: only one that went counts toward the rate limit. - container_
turn_ ended - A container agent’s turn has ended well.
- drop_
model_ other_ than - A process was started on
model: a reply from another model, seen before it, says nothing about it. Its model is dropped until the first reply of the new process names its own; the rest of the reading (the conversation’s size) stands. - forget
- Forget
block_id(its pane closed). - fresh_
sent - The scheduled fresh session was started (
sent), or given up: one that started counts toward the rate limit and starts the reading over. - get
block_id’s reading now.- hint
- The hint for
block_idnow, by the live settings (nonewhen they’re off). - hint_
for hintfor an agent ofkind: one that may not be able to start a fresh session has a finished task count for nothing, so only the compact hint can come.- hint_of
- What the §3.5 rule says for a reading:
freshfromfresh_attokens when this turn finished a task, elsecompactfromhint_attokens; otherwisenone. - hold_
hint_ for_ kind hold_turn_end_hintfor an agent of anykind(an ACP harness’s turn end).- hold_
turn_ end_ hint - At the end of a turn that ended well: take the hint and hold it, so it rides the agent’s next message.
The persistent controller’s reader and a container’s turn both end a turn this way;
fresh_allowedis whether the agent can start a fresh session. - install_
config - Attach the live settings (bootstrap), so the hint’s settings can be read.
- mark_
fresh_ by_ choice - The next spawn of
block_idis the agent’s ownAgents fresh. - note_
task_ boundary block_id’s agent finished a task in this turn.- observe_
acp - An ACP harness’s
usage_update:usedtokens in the conversation of awindow-token context. Each one is a call. The first one after a compaction’s turn is the size the compaction left, and says so in a note for the agent. - observe_
claude_ frame - Take one Claude stream frame into
block_id’s reading; frames that say nothing about context are ignored. - observe_
codex - A Codex turn’s reading, from its session file.
- observe_
container_ turn_ ends - Register what
container_turn_endedtells (bootstrap, once). - refusal_
reason - Why a self-compaction (or a fresh session) can’t be scheduled now, or
None, saying when it will be allowed. The count of calls does not stop an ACP agent whose context is already past its fresh-start point: a harness’s updates are not one per model call and its context may grow far in few of them, and it may have no compaction to shed it with. The ten minutes between two always hold: they are what stops a compact, catch-up, compact loop. - schedule_
compact - Mark a self-compaction scheduled for
block_id, unless it can’t be:Err(reason). - set_
auto_ compact - The CLI’s
get_context_usageanswer forblock_id. - take_
fresh_ by_ choice - Whether this spawn is an
Agents freshone; read once, by the spawn. - take_
hint_ for_ kind take_turn_end_hint_forfor an agent of anykind.- take_
turn_ end_ hint - At the end of a turn: the hint’s note text when it’s due. A compact hint is marked given, so it isn’t repeated before the context drops and crosses again; a fresh hint belongs to the task that just finished, comes with each one and leaves the compact hint’s mark alone. A task boundary counts for the turn it happened in only.
- take_
turn_ end_ hint_ for take_turn_end_hintfor an agent that can’t start a fresh session whenfresh_allowedis false (Agents freshis refused in a container): it is never told to, and gets the compact wording alone.- tokens_
now - Tokens in
block_id’s context at its last reading, or 0 when there is none: for log lines, so what a compaction or a note about one cost can be counted from the logs. - window_
scaled - The hint’s sizes for a harness whose window is
window: the settings’ sizes assume a 1M window, so a smaller one gets them as shares of it (compact hint from 40%, fresh hint from 15%, re-arm below 25%) when those are lower.
Type Aliases§
- Turn
EndObserver - Told when a container agent’s turn has ended well, so the compaction backstop can look at its context. A container has no per-response event of its own, as a route agent’s spend watcher gives one.