Skip to content

fix(codex): suppress inherited forked subagent usage - #521

Merged
junhoyeo merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/codex-forked-subagent-baseline
May 10, 2026
Merged

fix(codex): suppress inherited forked subagent usage#521
junhoyeo merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/codex-forked-subagent-baseline

Conversation

@IvGolovach

@IvGolovach IvGolovach commented May 6, 2026

Copy link
Copy Markdown
Collaborator

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_context snapshot 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_count rows before the child’s first turn_context.
    • Compare the first post-turn_context snapshot to the inherited baseline to avoid recounting.
    • Parse total_tokens in usage payloads and preserve child provider/agent/workspace attribution.
  • Migration

    • Bump source-message cache schema to v12 to store the forked-child suppression baseline in incremental state.

Written for commit e0f728e. Summary will update on new commits.

Codex forked child JSONL files can preserve parent records before the child turn_context. Detect forked child metadata, suppress inherited JSON records until the first child turn_context, retain the inherited token baseline for the repeated post-turn_context snapshot, and keep child metadata intact for provider, agent, and workspace attribution.

Bump the source-message cache schema because Codex incremental state now stores the forked-child suppression baseline.

Validation:

- cargo test -p tokscale-core sessions::codex::tests::test_forked_child: PASS, 2 passed

- cargo test -p tokscale-core codex: PASS, 61 passed

- cargo test -p tokscale-core: PASS, 661 passed, 1 ignored; codebuff 10 passed; hermes 3 passed; doc-tests 0 passed

- cargo test --workspace --all-features: PASS

- cargo clippy -p tokscale-core --all-features -- -D warnings: PASS

- cargo fmt --all --check: PASS

- git diff --check: PASS

- git diff --cached --check: PASS

- ASCII-only scan over touched Rust files: PASS, no matches

Rollback:

- Revert this commit to restore the previous Codex forked-session parsing behavior and source message cache schema.
@vercel

vercel Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview May 6, 2026 1:32am

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@junhoyeo
junhoyeo merged commit 4c28a1b into junhoyeo:main May 10, 2026
15 checks passed
@IvGolovach
IvGolovach deleted the codex/codex-forked-subagent-baseline branch May 10, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(codex): forked subagent logs can double-count preserved parent context before child turn_context

2 participants