Skip to main content

Module context_reading

Module context_reading 

Source
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§

ContextReading
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 unless false.
SETTING_HINT_AT
agent:compacthintat: the context size, in tokens, from which the hint suggests compacting.

Functions§

acp_compaction_carried_by
The /compact of a compaction begun for block_id was written to the harness as prompt prompt_id. A /compact nobody begun (a person typed it) carries no compaction.
acp_compaction_turn_ended
The prompt prompt_id of an ACP agent ended, ok or 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 None when the setting is 0 (off).
begin_acp_compaction
/compact is about to be sent to an ACP agent: remember the size it holds. The answer is the first usage_update after the turn that carries it, because a reading during it may be of the summarizing call.
cancel_acp_compaction
/compact could 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_id now, by the live settings (none when they’re off).
hint_for
hint for an agent of kind: 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: fresh from fresh_at tokens when this turn finished a task, else compact from hint_at tokens; otherwise none.
hold_hint_for_kind
hold_turn_end_hint for an agent of any kind (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_allowed is 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_id is the agent’s own Agents fresh.
note_task_boundary
block_id’s agent finished a task in this turn.
observe_acp
An ACP harness’s usage_update: used tokens in the conversation of a window-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_ended tells (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_usage answer for block_id.
take_fresh_by_choice
Whether this spawn is an Agents fresh one; read once, by the spawn.
take_hint_for_kind
take_turn_end_hint_for for an agent of any kind.
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_hint for an agent that can’t start a fresh session when fresh_allowed is false (Agents fresh is 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§

TurnEndObserver
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.