Skip to content

fix(agents): retain compaction references in adapters - #5309

Merged
giuliolovisotto merged 5 commits into
codex/fea-518-kilocodefrom
codex/fea-518-codex
Nov 4, 2026
Merged

giuliolovisotto merged 5 commits into
codex/fea-518-kilocodefrom
codex/fea-518-codex

Conversation

@giuliolovisotto

@giuliolovisotto giuliolovisotto commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex persists compaction summaries in its native transcript, but Gym drops the events and cannot identify the helper calls. Claude already observes compaction, but resolves its helper calls through a harness-specific import in the core collector. Assemble these references in each adapter before returning its observation bundle, leaving collection generic.

Codex parses native compacted records and matches them against completed responses identified by request_kind: "compaction" in the native client_metadata["x-codex-turn-metadata"] JSON. Its session transport uses this structured marker without a prompt-text fallback. The response stream is forwarded unchanged; only helper evidence is buffered, with an 8 MiB limit. Missing, failed, truncated, oversized or ambiguous evidence leaves a gap. The event and its owning invocation both receive model-scoped references.

Claude performs its existing exact summary/boundary association while preparing observations, on both local and sandbox paths. It waits for pending capture writes, reads the rollout's capture off the event loop, and restricts matching to its configured model server. Read failures preserve the bundle and record a gap. The matcher also accepts the one-newline continuation suffix emitted by Claude Code 2.1.108, alongside the existing two-newline form.

The core collector imports neither adapter and retains its generic verifier exclusion and reference join. Compaction helpers remain captured and invocation-owned for accounting, but are excluded from policy turns.

Compatibility

Claude's agent-server host must be able to read the configured shared model_call_capture_dir; the task sandbox does not need access. Missing or unreadable capture leaves explicit gaps. Execution, retry policy and production compaction thresholds are unchanged. No separate issue is needed for this scoped evidence fix and review follow-up.

Validation

Latest validation: the full Codex suite passed 506 tests with 7 runtime-dependent skips. Tests cover metadata-based detection with different prompt wording, rejection of prompt-only detection, and missing or malformed metadata. uvx pre-commit run --all-files passed.

python -m pytest responses_api_agents/codex_agent/tests -q --no-cov

Earlier Claude association validation: 926 tests passed:

python -m pytest responses_api_agents/claude_code_agent/tests \
  responses_api_agents/codex_agent/tests/test_observability.py \
  responses_api_agents/codex_agent/tests/test_sandbox_transport.py \
  tests/unit_tests/test_model_calls.py tests/unit_tests/test_rollout_collection.py \
  -q --no-cov

uvx pre-commit run --all-files passed, including package layering. Tests cover both Claude execution paths, missing/foreign capture, delayed writes, read failures, ambiguous helpers, summary matching, turn exclusion and retained usage.

A fresh Claude Code 2.1.108 run against a controlled local provider executed the shell command and automatically compacted: four captured calls (title, policy, compaction, policy), two policy turns, one linked event, summary reuse and helper usage retained in captured-call metrics. The smoke used synthetic input usage plus CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=10 and CLAUDE_CODE_DISABLE_1M_CONTEXT=1; these settings are confined to the smoke.

Claude's emitted response.usage still reports policy-only usage in this smoke; auxiliary-token aggregation in that field is outside this association cleanup.

A fresh Codex 0.144.4 compaction scenario with metadata-based detection passed all five behavioral checks and schema validation: 16 captured model calls, 15 policy turns, one linked helper, summary reuse and retained aggregate usage. Reproduce on the scenario layer with python scripts/run_harness_conformance.py --harness codex --scenario context_compaction --gate-tier P1 --output results/codex-compaction. The prior implementation was also validated across all nine scenarios with P1 gating. These runs validate local pinned runtimes and controlled providers; remote sandbox infrastructure, model quality and full repository CI are not qualified. Commits carry DCO sign-off and SSH signatures.

Based on #5308; #5310 and #5311 follow, then #5439 enables the shared scenario as the final PR of the original stack.

@giuliolovisotto giuliolovisotto added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Oct 29, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 29, 2026 13:45
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 30, 2026
Comment thread nemo_gym/observability/model_calls.py Resolved
@giuliolovisotto
giuliolovisotto removed this pull request from stack #5312 November 2, 2026 10:16
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 2, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 2, 2026 10:59
@giuliolovisotto
giuliolovisotto removed this pull request from stack #5437 November 2, 2026 10:59
marta-sd
marta-sd previously approved these changes Nov 3, 2026
marta-sd
marta-sd previously approved these changes Nov 3, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41802882054

This branch was previously deployed

1 inactive deployment
public — 3a3e270e Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #9906
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants