fix(codex): suppress inherited forked subagent usage
Merged
IV
6mo ago+155+155+012345678901234567890123456789-1-1-0123456789
Summary
- Suppresses inherited parent records in Codex forked child JSONL files until the child's first
turn_context. - Tracks the skipped inherited token baseline so the repeated post-
turn_contextsnapshot is not counted as child-local usage. - Preserves forked child provider, agent, and workspace metadata, and bumps the source-message cache schema for the updated Codex incremental state.
Why
Codex native subagent logs can include copied parent session history before the child session records its own turn_context. Those inherited token_count rows are parent work, not child-local work. Counting them inside every forked child can multiply the parent usage and produce large artificial spikes.
Fixes #520.
Test plan
cargo test -p tokscale-core sessions::codex::tests::test_forked_child(2 passed)cargo test -p tokscale-core codex(61 passed)cargo test -p tokscale-core(661 passed, 1 ignored)cargo test --workspace --all-features(passed)cargo clippy -p tokscale-core --all-features -- -D warnings(passed)cargo fmt --all --check(passed)git diff --check(passed)
Summary by cubic
Suppress inherited parent records in Codex forked child logs until the child’s first turn_context so token usage reflects only child-local work. This prevents double-counting by tracking the inherited baseline and keeps provider/agent/workspace metadata intact (fixes #520).
-
Bug Fixes
- Ignore copied parent
token_countrows before the child’s firstturn_context. - Compare the first post-
turn_contextsnapshot to the inherited baseline to avoid recounting. - Parse
total_tokensin usage payloads and preserve child provider/agent/workspace attribution.
- Ignore copied parent
-
Migration
- Bump source-message cache schema to v12 to store the forked-child suppression baseline in incremental state.