codex icon indicating copy to clipboard operation
codex copied to clipboard

Default full-history subagent fork can trigger compaction immediately after spawn (6/6 Luna workers)

Open abcjhby2871 opened this issue 3 days ago • 1 comments

Environment

  • Codex desktop app on macOS (Apple Silicon)
  • App version: 26.1120.50957 (build 30866)
  • Subagent session-reported CLI: 0.171.0-alpha.13.2
  • Subagent execution: GPT-6 Luna, xhigh reasoning
  • Session-reported effective context window: 258,400 tokens

Observed behavior

In a long-running, image-heavy parent conversation, I delegated six independent, self-contained tasks. Each spawn supplied a short task brief but omitted fork_turns, so the current default inherited the entire parent history. All six children performed a new context compaction within about 26–45 seconds of spawn, before they could complete their independent work.

I inspected local session records and distinguished the inherited compaction record copied at spawn from the subsequent, newly recorded compaction. The last nonzero input-token usage before each new compaction and the first nonzero input usage afterward were:

Worker Seconds from spawn to new compaction Input tokens before Input tokens after
1 45.2 329,389 43,697
2 26.5 341,444 43,247
3 27.7 341,623 43,269
4 31.4 341,834 43,149
5 33.2 342,033 43,137
6 34.5 342,270 43,489

Workers 2–6 each reported 296,064 cached input tokens before compaction; worker 1 reported zero. These are observed per-request token counts, not estimates of billed usage, and I am not claiming an accounting bug.

Steps to reproduce

  1. Use a long-running Codex desktop conversation containing substantial previous tool output and images.
  2. Delegate several tasks which only need a short independent brief (for example, inspect a single supplied image).
  3. Let the coordinator omit fork_turns in spawn_agent.
  4. Observe the new child sessions' context usage and newly recorded compaction events.

Expected behavior / request

For independent bounded tasks, the default should avoid copying unrelated parent history. Please consider either a context-efficient default (task brief plus a bounded relevant summary), or a user-configurable default that takes effect when the coordinator omits the argument. Explicit fork_turns: "all" should still support full-history collaboration, and "none" should remain available for isolated tasks.

It would also help to expose the estimated inherited context size before spawning and warn or switch to a compact handoff when the inherited history is already near the child's context limit. This would prevent spawning multiple workers that immediately need to summarize irrelevant context.

I understand that full-history inheritance is documented behavior, and using fork_turns: "none" is a current workaround. The issue is that an omitted argument in a long conversation can incur this startup overhead across every independent worker.

Related: #51032 (configurable default fork history), #20077 (full-history default), #33235 (image-heavy context amplification). This report adds a concrete six-worker startup-compaction observation.

No private prompts, workspace paths, account details, session identifiers, or raw logs are included.

abcjhby2871 avatar Nov 28 '26 16:11 abcjhby2871

Your table already answers the "why 26 to 45 seconds and not zero" question, and the answer moves the fix.

It is not a spawn-time decision that ran late

An omitted fork_turns becomes full history one line before anything else sees it: core/src/tools/handlers/multi_agents_v2/spawn.rs:226 is .unwrap_or("all").

The child then starts with no token accounting for what it inherited, on purpose. core/src/agent/history.rs:416 sets compacted.latest_token_usage_record = None on every inherited checkpoint, and the intent is asserted in core/src/agent/control_tests.rs:2865 and :2875 ("child rollout should not inherit parent token usage records", "child rollout should not inherit parent token usage checkpoints").

Pre-turn compaction decides on sess.get_total_token_usage() (core/src/session/context_window.rs:58), which is last reported usage plus the estimate of items recorded after the reporting boundary (core/src/context_manager/history.rs:1159-1177, boundary realigned to the last model-generated item at :1110). With the usage record gone and the boundary reset, the inherited prefix is not in that number. That is why the last nonzero usage before each new compaction in your table is 329k to 342k: the first request went out at full inherited size.

The response to that request is what arms the check. core/src/session/turn.rs:709-715 recomputes token status after sampling, and :773-800 rolls straight into a MidTurn compaction when the model needs a follow-up and the limit is reached. One round trip, then the compaction, inside the same turn. Your 26 to 45 seconds is that gap.

For your ask #3 this means a spawn-time estimate is not an optimization. It is the only place the decision can be made before the first request, because no existing check holds the number. It is also nearly free there: prepare_forked_history (core/src/agent/history.rs:192) already loads every forked item and walks them, and the estimator exists as History::estimate_token_count (core/src/context_manager/history.rs:835), surfaced as Session::get_estimated_token_count (core/src/session/mod.rs:1720), currently called only inside a trace at core/src/session/turn.rs:759. Compare it against model_info.auto_compact_token_limit() and put the number on the spawn result, which today carries only task_name and nickname (spawn.rs:244).

Two details in the parameter that decide behavior

A numeric fork_turns means full history. spawn.rs:231 sends any NonZeroUsize into SpawnAgentForkMode::FullHistory under the comment "Accept legacy turn counts without limiting the inherited history", while the schema says only all and none are supported (core/src/tools/handlers/multi_agents_spec.rs:667). A coordinator trying to bound the fork to "3" gets everything, silently. Bounding by turn count is the first mitigation anyone reaches for, so that leniency is worth either removing or documenting.

The description prices one direction only. multi_agents_spec.rs:808 warns that fork_turns="none" "will not pass any surrounding context to the spawned subagent, which may cause the agent to lack the context it needs to complete its task", and says nothing about what "all" costs. For the case you describe, "none" is not context-starved. A non-fork child is an ordinary session with inherited dynamic tools (fresh_child_history_and_tools, core/src/agent/control/spawn.rs:82-96, returns InitialHistory::New), so it still gets AGENTS.md, the environment sections, its tools, and your brief. It gives up the parent's turns, not its instructions. A description that priced both sides would move the coordinator's default without any new mechanism.

Your ask #2 in the shape this repo already uses

[agents] already carries default_subagent_model and default_subagent_reasoning_effort, applied in core/src/agent/child_config.rs:230-232 exactly when the spawn call does not select one, with the fields at core/src/config/mod.rs:1009-1012. A default_fork_turns beside them is the same shape and the same call site. The ordering is the catch: SpawnAgentArgs::fork_mode turns an omitted argument into FullHistory before that function runs, so the omission has to stay None through the handler for a configured default to be reachable.

Until one of those lands

Your brief is not what that first compaction consumes, which matters for how you triage the cost. run_pre_sampling_compact fires before the new input is recorded, and preserve_initial_input_during (core/src/session/turn.rs:168-199, called at :260) parks the input across it, so the summarized material is the parent's history and your brief is recorded afterward. You are paying for the compaction request and for a worker that now reasons from a summary of a conversation it never needed.

The lever you have today is instruction placement. AGENTS.md is a world-state section rendered from disk (core/src/context/world_state/agents_md.rs:17) rather than carried in history, so a line like "when delegating a self-contained task, pass fork_turns none; full history is for work that needs this conversation" survives compaction and reaches the coordinator at every spawn decision. Setting it once for the session is the missing config key, which is your ask #2.

The durable version of this problem is that a worker only knows what its window contains. I built MemoryRouter for that: an agent gets conversational memory that survives compaction instead of inheriting an entire parent conversation to recover the one paragraph it needs. https://docs.memoryrouter.ai/codex?utm_source=github&utm_medium=issue&utm_campaign=openai-codex

John-Rood avatar Nov 29 '26 04:11 John-Rood