Skip to content

fix(codex): subagent lanes, per-request Context, compactions and interrupts - #52

Merged
adityajha2005 merged 4 commits into
Entelligence-AI:mainfrom
21lakshh:fix/codex-threads
Nov 2, 2026
Merged

adityajha2005 merged 4 commits into
Entelligence-AI:mainfrom
21lakshh:fix/codex-threads

Conversation

@21lakshh

@21lakshh 21lakshh commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the Codex data loss reported in #47 and #49. All changes are in the Codex read path, and maps for other agents are unchanged.

#47: Context, compactions, interrupts

  • Context: a Codex turn becomes one llm event per request (from llm.cost_events) instead of one per turn. Context is now the largest single request, not a turn's summed total. Tokens and cost are unchanged.
  • Compactions: each compacted record becomes a compaction event. Its "before" tokens are the last request's input when latest_token_usage_record is null.
  • Interrupts: each turn_aborted with reason interrupted becomes an interrupted error, counted once per Esc.

#49: subagents and "#" prompts

  • A: a subagent's first turn opens on the parent's agent_message, so its tool calls are kept. No instruction text is stored.
  • B: a prompt starting with # is a prompt. Only <…>, # AGENTS.md instructions and the IDE extension's # Context from my IDE setup count as injected.
  • C:
    • A subagent rollout (thread_source: subagent) drops the parent history copied in before subagent_history_start_ordinal.
    • It links to its parent's rollout (the latest _<window> file that started at or before it) and is folded into the parent map as a lane, with the spawn_agent call as its launch.
    • Subagents are no longer listed as main sessions. Each one is tagged role: subagent with its parentSessionId, so the session list, Insights and Run health skip it, as they already do for Claude Code and Antigravity subagents. Its work is counted once, in the parent.
    • Guardian reviews are left as they were.
    • Links that would form a cycle are refused.

Edge cases (found in review, each with a test):

  • The history cut uses the physical line number, so unreadable lines can't shift it.
  • A self-parented or cyclic parent_thread_id is never folded.
  • Two spawns with the same task name each link to their own lane.
  • A spawn_agent output longer than the 2,000-character cap still links to its lane.
  • A parent is rebuilt when any of its subagent rollouts grows.
  • A subagent whose parent window is missing stays its own session.
  • A subagent that can't be read still keeps its own subagents' lanes.

The README's Codex row is updated to match.

Closes #47
Closes #49

Test plan

Ran:

  • make check: lint, 1363 Python tests (16 new in tests/core/test_codex_threads.py, using synthetic rollouts only), 354 viewer tests, and the clean check.
  • Built my local sessions twice, once with main and once with this branch (Python 3.11 both times). That covers 192 Codex, 90 Claude Code, 34 Antigravity and 3 Cursor sessions. The diff:
    • Non-Codex: every map is identical, apart from transcripts that were still being written during the builds.
    • Codex: Context is above the model window in 0 sessions (88 before, as reported in Codex sessions: Context shows a whole turn's total, and compactions and interrupts are never recorded #47). Compactions and interrupts equal the rollout's records in every session, and no session lost calls or tokens.
    • Parents: each parent's new tokens, calls and cost equal its old values plus its subagents' old values, so nothing is counted twice.
    • Session list: 62 subagent copies leave the list and become lanes. The #-prompt session is no longer dropped.
  • Grepped every built map, the index titles and exports for about 2,800 phrases taken from prompts, agent_message bodies and spawn_agent messages: 0 hits.

Before and after, one pair per fix (dark theme). The screenshots were built with --no-titles --path-mode hashed, and repo names are replaced with repo-a…f.

#47 Context. For the same session, the Context lane goes from 10.7M max (per-turn sums) to 217.9K max (the largest single request):

Before After
47-context-before 47-context-after

#47 Compactions. The rollout has 3 compacted records; Compactions goes from 0 to 3. The drops are visible in the Context lane above ("216.5K→0"):

Before After
47-compactions-before 47-compactions-after

#47 Interrupts. The rollout has 2 turn_aborted records with reason interrupted. Agent orchestration goes from 0 to 2, and "interrupted by user ×2" appears:

Before After
47-interrupts-before 47-interrupts-after

#49 A: subagent tool calls. A parent whose subagents take their input from agent_message. Before, that work was missing; one of those subagents had 165 calls and showed 0. After, the parent has 5 subagent lanes, including "Sub 2 · 165 calls". Agents go from 1 to 6 and tool calls from 175 to 568:

Before After
49a-subagent-calls-before 49a-subagent-calls-after
49a-details-before 49a-details-after

#49 B: a prompt starting with #. The Apr 2 session (8 calls) was dropped. It now appears between Apr 5 and Apr 1:

Before After
49b-list-before 49b-list-after

#49 C: subagents no longer listed as main sessions. The Sep 13 group in the session list. Before, there were 3 subagent rows ("3 prompts", the copied parent history) next to their parent. After, there is one parent row with "8 subagents". The list goes from 97 to 36 Codex sessions:

Before After
49c-list-before 49c-list-after

#49 C: the parent shows its subagents. Agents go from 1 to 9, and the Subagents lane from (0) to (8). The Subagents sidebar tab lists them. Context goes from 12.6M to 220.3K, and tool calls from 338 to 765:

Before After
49c-parent-before 49c-parent-after

Existing maps rebuild on the next version bump (builtWith), or with agentplay build --rebuild --agents codex.

  • make check passes
  • No prompt text, model output, tool input/output, file contents or command arguments can reach a map, a log line or the viewer (redaction contract)
  • No new network calls or Python runtime dependencies

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Entelligence: code quality 4/5 — Good. No critical or significant findings; nits only.

@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

EntelligenceAI PR Summary

Codex ingestion now records context per request, surfaces compactions and user interrupts, and excludes copied parent history from subagent rollouts to prevent duplicate turns and token counts. Codex Desktop subagents are linked to their parent session and included as map lanes, with spawn calls linked to the corresponding lanes; guardian reviews and other agents remain separate or unchanged.

flowchart TD
    classDef newBehavior fill:#dcfce7,stroke:#16a34a,color:#14532d;
    A["Codex JSONL rollouts"] --> B["Index and link subagent threads"]
    B --> C["Parse requests, compactions, and interrupts"]
    C --> D["Build map with per-request events"]
    B --> E["Read child rollout spans"]
    D --> F["Match spawn calls to subagent lanes"]
    E --> F
    class A,B,C,D,E,F newBehavior;
Loading

🟢 Green = new or changed in this PR


Review Scorecard

Dimension Rating Basis
Code Quality ●●●●● 5/5 — Excellent no critical/significant findings — rated Excellent
Blast Radius Low changed symbols are referenced only within their own file(s); no high-impact surface touched, 5 file(s) / ~479 line(s) changed (size only — not a blast signal)
Merge Confidence ●●●●● 5/5 — Safe to Merge code quality 5/5 × Low blast radius
Test Coverage — unavailable dependencies failed to install
Security Scan No findings on changed lines SonarQube · Semgrep · TruffleHog on 3 changed files

Safe to merge with a low blast radius; code quality rated Excellent (5/5): the review found nothing to flag.

Key Findings:

  • No critical or significant issues found
Evaluated against
  • 3/3 changed files reviewed
  • criteria: correctness, security & access control, robustness & error handling, concurrency & data integrity, repo conventions / steering docs
  • steering docs: none found in repo
  • PR checks: unit tests (unavailable) · security scan (SonarQube, Semgrep, TruffleHog on 3 changed files)

@entelligence-ai-pr-reviews

entelligence-ai-pr-reviews Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Walkthrough

Adds end-to-end Codex subagent support, from rollout parsing and parent-child discovery to session-map lanes and request-level cost events. The update also handles fork-history trimming, compactions, interruptions, and prompt detection, documents Desktop support, and adds synthetic-rollout regression coverage.

Changes

Files

  • python/src/agentplay/_core/ingestion/coding_agent/_sources/local/parsers/codex.py
  • python/src/agentplay/_core/ingestion/coding_agent/_sources/local/source.py

Codex ingestion now discovers and links nested subagent rollouts, trims copied parent history, and records thread, parent, agent-path, compaction, and interruption metadata. Parsing also distinguishes injected context from user prompts and handles subagent first turns without counting task instructions as user prompts.

Files

  • python/src/agentplay/builder.py
  • python/src/agentplay/discover.py

Session-map construction now adds subagent lanes, links launches to parent-child sessions, assigns launch sequence numbers, and emits Codex LLM events per cost event. Discovery traverses nested subagents within depth and source-size limits; map building also handles compactions and interruptions and omits user events from subagent lanes.

Files

  • README.md

Documents Codex support in the Desktop app, including subagent lanes, parent-session rollup behavior, and reading compactions and interrupts.

Files

  • python/tests/core/test_codex_threads.py

Adds synthetic-rollout regression coverage for parsing, fork-history trimming, usage, compactions, interrupts, subagent discovery and linkage, and edge cases including missing parents, cycles, truncated spawn output, and unavailable spans.

Comment thread python/tests/core/test_codex_threads.py Resolved
Comment thread python/src/agentplay/discover.py Resolved

@entelligence-ai-pr-reviews entelligence-ai-pr-reviews Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Entelligence: code quality 5/5 — Excellent.

@adityajha2005

Copy link
Copy Markdown
Contributor

nice one @21lakshh, merging 🚀

@adityajha2005
adityajha2005 merged commit 6d728ae into Entelligence-AI:main Nov 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants