Fixes #1645 (option B from the report; the parent-side pre-spawn compaction in option A is a separate change and is not included).
child_initial_input serialized the parent's whole history into the child's first user message with json.dumps — no token counting, no truncation. Compaction runs in the child's first _run_cycle, after that message exists, so a long parent run could overflow the child's window on its very first model call.
- newest inherited messages are kept up to
INHERITED_CONTEXT_MAX_TOKENS(8k), counted with the samecount_tokensthe compaction path uses; - the block starts with how many messages were dropped, so the child knows the background is partial rather than complete;
- an oversized newest message is still rendered — an empty block would hide that the parent had context at all;
- the spawn site passes the child's model, so the count uses that tokenizer instead of the UTF-8 byte fallback.
Validation (pytest tests/test_inputs.py -q -> 57 passed):
| case | result |
|---|---|
| history under the budget | rendered whole, no omission note |
| 6 messages over a 10-token budget | only the newest kept, 5 earlier inherited message(s) omitted |
| one oversized newest message | still rendered |
| no history | block absent (unchanged) |
Reverting inputs.py fails the trimming cases and keeps the under-budget and no-history cases green, which pins that a normal spawn renders exactly what it did before. pytest tests/ -k 'child or inputs or spawn' -> 73 passed, 3 failed; the 3 (test_runner_mcp, test_runner_teardown) fail identically with these changes stashed — an unrelated SimpleNamespace has no attribute 'telemetry' fixture error in this checkout. ruff check + format clean.
[Medium impact] The change affects the starting context of spawned child agents.
The PR appears safe to merge, with two non-blocking improvements to history selection and budget counting.
Findings
Fix with agent prompt
Summary
Limits the background history passed to child agents and adds an omission note.
Acknowledged scope:
lxcxjxhxexplicitly intends to retain an oversized newest message. The author also defers parent-side compaction to a separate change.Verification used source inspection; no tests were run during this review.
Reviews (1) · Last reviewed commit: "fix(core): bound the parent history a ch..." · Reviewed by Greptile