Skip to content

fix(codex): read subagent parent and compaction phase where they live - #4718

Merged
Sinity merged 2 commits into
masterfrom
lane/codex-content-losses
Sep 6, 2026
Merged

Sinity merged 2 commits into
masterfrom
lane/codex-content-losses

Conversation

@Sinity

@Sinity Sinity commented Sep 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two Codex parser reads target shapes the wire does not produce. Both are silent
losses that a rebuild would mint permanently.

Problem

Subagent parent (polylogue-zc11x). Lineage assignment was gated on
forked_from_id. Of 3,083 real subagent sessions only 545 carry that field;
2,538 name the parent solely under
source.subagent.thread_spawn.parent_thread_id. The parser computed the
subagent-spawn flag from that block but never read the parent out of it, so the
branch was skipped and the flag discarded. Those sessions ingested as orphans —
no parent, no topology edge, no branch type, no branch point.

Compaction phase (polylogue-4x49r). The replacement-history phase counter
read phase from each content item. Codex puts phase on the history entry;
content items are exactly {text,type} or {image_url,type}. Across a
600-file sample: 227,576 content items, zero carrying phase; 27,015 entries
carrying it. The counter was absent from all 18,561 real compaction events.

Both paths had passing tests. Each fixture asserted the shape the code expected
rather than the shape Codex emits — the lineage fixture supplied both carriers
(the 17.7% minority), the compaction fixture invented phase one level down.

Solution

Read the parent from whichever carrier is present: forked_from_id, then
thread_spawn.parent_thread_id, then a top-level parent_thread_id. Read
phase from the history entry.

Fixtures reshaped onto observed wire shapes, with the thread-spawn-only
majority case and the top-level-parent_thread_id case added.

Precedence is safe to order arbitrarily: across 1,497 first session_meta
records the carriers never disagree (1,076 spawn, 206 fork, 0 conflicts) and no
session names itself as parent, so the fallback introduces no topology
self-loop.

Verification

devtools verify --quick on the merged tree: all 14 gates ok, exit 0, no
out of sync.

The bead's own reproduction now resolves: parent= parent-2 branch= subagent
where it previously printed parent= None branch= None.

The focused pytest run did not execute. The host's pytest slot was starved --
one task held it for 35+ minutes with 14 lanes queued behind it -- so
devtools test tests/unit/sources/test_parsers_codex.py never started. This
merges on static gates plus the reproduction above, as a deliberate call under
quota pressure, not because test evidence was obtained.

Anti-vacuity conditions are named but not executed -- verifying them needs
the same starved slot. Reverting the spawn_parent_thread_id fallback should
redden test_subagent_thread_spawn_alone_sets_subagent_parent (parent becomes
None); reverting meta_parent_thread_id should redden
test_top_level_parent_thread_id_sets_parent; moving the phase read back to
the content item should empty replacement_history_phase_counts and redden
test_compacted_replacement_history_aggregates_phase_and_ghost_commit. Each
new test fails against unpatched parser code by construction, since each
asserts a value the old code could not produce.

Residuals

polylogue-vtyud (the ~1.34 GB item_completed exec-evidence drop) is not in
this PR. Its stated mechanism — pair payload.item to the adjacent
custom_tool_call_output — does not hold: item.id is exec-<uuid> and
shares no id space with call_id, and 518 of 2,067 CommandExecution items have
no positionally-following output (480 are back-to-back parallel execs). That
needs a pairing decision before implementation.

polylogue-amks7 (broader fixture reshaping) is untouched beyond the two
fixtures these fixes required.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid

Sinity and others added 2 commits September 6, 2026 01:32
Two Codex parser reads target shapes the wire does not produce.

The subagent parent link was gated on forked_from_id, which only 545 of
3,083 real spawn sessions carry. 2,538 name the parent solely under
source.subagent.thread_spawn.parent_thread_id, so they ingested with no
parent, no topology edge and no branch type. Fall back to the spawn block
and then to a top-level parent_thread_id.

The replacement-history phase counter read `phase` from each content item,
where it never appears; Codex puts it on the history entry. The counter was
absent from all 18,561 real compaction events.

The fixtures covering both paths asserted the shapes the code expected
rather than the shapes Codex emits, which is why they passed. Reshaped onto
observed wire shapes and added the thread-spawn-only majority case.

Refs: polylogue-zc11x, polylogue-4x49r

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DNGJ3awfNrsLaMdHgQZvid
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: cf3ffba3-b82d-418b-9f60-965f86a5b6a9


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-06T00:03:53.590561Z 7c31c53 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity enabled auto-merge (squash) September 6, 2026 00:01
@Sinity
Sinity merged commit 0f0b49e into master Sep 6, 2026
3 checks passed
@Sinity
Sinity deleted the lane/codex-content-losses branch September 6, 2026 00:07
Sinity added a commit that referenced this pull request Sep 22, 2026
…#5417)

## Summary

`devtools verify` ended its output with a gate's `ok` line whether it
passed or failed, so `devtools verify | tail` reported **tail's exit 0**
whatever the gates found. Salvaged from `fix/test-verify-reds`, a
two-week-old branch whose other five defects all turned out to be
superseded.

## Problem

Measured at base `74e1aa3d0`: the last line of a green `verify --quick`
is

```
  gate population-coverage ... ok (1.3s)
```

and a **failing** run ends identically. The verdict lived only in the
exit status, which a pipeline discards. `#4718` gave the last-line
verdict contract to `devtools test` (`run_tests.py:681`) but never to
`devtools verify`, whose `_main` ended at `_emit(payload, ...)`.

This is the hazard the environment contract already names — *read
command exit status directly; a pipeline's final status does not prove
an earlier check passed* — with no way to comply short of not piping.

## Solution

`_write_verdict_line`, called from `_emit`, covering all four terminal
paths: completion, checkout-import mismatch, affected-admission refusal,
and interruption.

Written to **stderr**, so the `--json` stdout contract stays exactly one
document. A green run's absent diagnosis is **omitted** rather than
reported as `diagnosis=unknown` — an absent determination is not a
failed one.

Live production output at the branch tip:

```
verify: PASSED exit=0 receipt=.cache/verify/runs/20260922T130618Z-quick-1977478-53268ffe/run.json
```

`TESTING.md:146` is corrected; it claimed the last-line-verdict contract
for `devtools test` alone.

## Anti-vacuity — four mutations, each executed and restored

1. **delete the write entirely** → `assert 'gate populat...... ok
(1.3s)' == 'verify: FAIL...0922/run.json'`, plus two `IndexError: list
index out of range` because stderr was empty. That is the defect itself:
a run that exited 1 whose last line is a gate's `ok`.
2. **guard with `if exit_code:`** so only failures speak → exactly 1
red, `test_a_passing_run_states_its_verdict_too`. The failing case
stayed green, so red/green separates on the named axis and a
failure-only verdict cannot pass.
3. **write to `sys.stdout`** → `json.decoder.JSONDecodeError: Extra
data: line 3 column 1` — the prose landed after the document, exactly as
the contract test names.
4. **restore `payload.get("diagnosis") or "unknown"`** → exactly 1 red:
`+ verify: PASSED exit=0 diagnosis=unknown receipt=...`. The failing
case, which has a real diagnosis, stayed green — so the test pins the
absence-vs-unknown distinction, not merely the presence of a line.

## Verification

- **Inherited-red baseline** at base `74e1aa3d0` before any edit:
`devtools verify --quick` exit 0, 25 gates all ok, zero FAILED. Nothing
to attribute.
- `devtools verify --quick` at the tip: exit 0, 25 gates, gate set
**byte-identical to the base run** (diffed).
- `devtools render all --check`: exit 0, `grep -c 'out of sync'` = **0**
— checked explicitly, since this command can print per-surface `sync OK`
and still exit 1.
- `devtools test` over `test_verify.py`, `test_run_tests.py`,
`test_pytest_invocation.py`: exit 0, **111 passed**, selected 111 /
terminal 111.
- **Schema closure**: both changed files `out`. Identity measured
directly on both trees, not inferred — `index=5274c9cc…`,
`ops=86866235…`, **identical**. Unlike several PRs today, this one
carries no rebuild-boundary constraint.

## The other five defects on that branch were superseded

Reported rather than landed:

- the rerun report path — landed as `pytest_rerun.py:72
_path_for_receipt`, identical remedy
- the venv diagnosis expectation — head is already parametrized
`[(False, "gate_unprovisioned_environment"), (True,
"gate_missing_executable")]`
- the pueue task-id identity hazard — closed by a *different, better*
mechanism: the pueue route is gone, replaced by `agentctl job start`
with a durable job id and a per-pid result file the runner unlinks first
- the testmon expectation — head carries the branch's exact assertions
- **`current-pytest-summary.json` — decided the opposite way on
purpose.** `#4718` closed the same bead choosing "stop naming it" over
"write it"; `run_tests.py:675` states *"The receipt is this run's own
file, never a `current-*` name a concurrent run in the same checkout
would overwrite."* Reviving the branch would have regressed a landed
adjudication.

## Residual

`devtools verify`'s agent-tier refusal (`verify.py:894-912`) returns 2
before any `VerifyRun` exists and still ends in its own prose refusal
rather than a `verify:` line. That is a refusal *before* a run, not a
run with a lost verdict, so it is left alone; if one sentence shape is
wanted for every exit, that path is the remaining gap.

Separately, `tests/unit/storage/test_index_generation.py:305` still says
*"which later blocks archive-root relocation"*, describing a mechanism
`#5086` deleted. It is the only surviving reference in the tracked tree
— a one-line follow-up owed by that change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant