Skip to content

fix(core): retain encrypted delegated messages during v2 compaction - #587

Merged
andrei-hasna merged 6 commits into
mainfrom
hotfix/compact-v2-agentmessage-preservation
Aug 13, 2026
Merged

fix(core): retain encrypted delegated messages during v2 compaction#587
andrei-hasna merged 6 commits into
mainfrom
hotfix/compact-v2-agentmessage-preservation

Conversation

@andrei-hasna

@andrei-hasna andrei-hasna commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixes task ee70ccaa-e263-4515-8d3e-e5ade8186075.

Root cause: v2 built its retention candidate from persisted assistant envelopes before the Responses request formatter converted encrypted delegated messages to AgentMessage items, so the role filter dropped them.

This extracts the shared Prompt input formatter, applies it before v2 retention, preserves raw trace history, and adds a regression test. Legacy compaction behavior is unchanged.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@andrei-hasna

Copy link
Copy Markdown
Contributor Author

[REVIEW] NO_GO — #587 @ 01316f9 — lens: correctness+security+gates, reviewer Hostus (1 of 1)

Commands and gates:

  • bun install — exit 0. Setup only; not a repository gate.
  • Typecheck — no typecheck script is declared in package.json.
  • Test gate — no test script is declared in package.json; this repository declares no test gate.
  • gh pr view 587 --repo hasna/codewith --json statusCheckRollup — exit 0. Forge status was read by check name, status, and conclusion; no failed conclusion was reported in the snapshot, but several checks were still in progress.

Forge checks read (name — conclusion/status):

  • Bazel test on ubuntu-24.04 for x86_64-unknown-linux-gnu — IN_PROGRESS
  • Check for spelling errors — IN_PROGRESS
  • cargo-deny — IN_PROGRESS
  • build-test — IN_PROGRESS
  • Build Codewith Linux CLI — IN_PROGRESS
  • python-sdk — IN_PROGRESS
  • cla — SUCCESS
  • Blob size policy — SUCCESS
  • Detect changed areas — SUCCESS
  • Bazel test on ubuntu-24.04 for x86_64-unknown-linux-musl — IN_PROGRESS
  • Format / etc — IN_PROGRESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 1/4 — IN_PROGRESS
  • sdks — IN_PROGRESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 2/4 — IN_PROGRESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 3/4 — IN_PROGRESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 4/4 — IN_PROGRESS
  • cargo shear — IN_PROGRESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm (native main) — SKIPPED
  • Bazel clippy on ubuntu-24.04 for x86_64-unknown-linux-gnu — IN_PROGRESS
  • Argument comment lint package — SKIPPED
  • Bazel clippy on windows-latest for x86_64-pc-windows-gnullvm — IN_PROGRESS
  • Argument comment lint - Linux — IN_PROGRESS
  • Verify release build on ubuntu-24.04 for x86_64-unknown-linux-gnu — IN_PROGRESS
  • Argument comment lint - Windows — IN_PROGRESS
  • Verify release build on windows-latest for x86_64-unknown-linux-gnullvm — SUCCESS
  • [code]smith — SKIPPED

Blocking P1 finding:

  • codex-rs/core/src/compact_remote_v2.rs:is_retained_for_remote_compaction_v2 only retains ResponseItem::Message roles user, developer, and system. The changed Prompt::format_input converts persisted encrypted delegated assistant envelopes into ResponseItem::AgentMessage, so build_v2_compacted_history drops those messages before installing compacted history. The newly added regression test constructs exactly that AgentMessage and expects it retained, but the current predicate returns an empty retained list and the test cannot pass when compiled. This is a reachable data/session-integrity defect in the PR’s stated fix.

Non-blocking follow-ups:

  • The repo-wide package.json does not declare a test script; forge checks remain the authoritative build/test evidence.
  • No additional concrete P0/P1 security or correctness finding was identified in the reviewed diff.

@andrei-hasna

Copy link
Copy Markdown
Contributor Author

Fixed the blocking P1 in commit 5c55c3e6d25e8fa3d8c31eba57f20db9f915d084.

is_retained_for_remote_compaction_v2 now retains ResponseItem::AgentMessage, matching the existing non-v2 retention path and allowing the added delegated-message regression to pass. The staged secrets scan was clean (exit 0). The focused re-review is limited to this fix and its direct regression; forge checks for the new head are still running.

@andrei-hasna

Copy link
Copy Markdown
Contributor Author

Fixed the new-head gate failure in commit 41f949ad9.

The authoritative ci / build-test run for 9000cde54f91… failed only just fmt-check because codex-rs/core/src/context_manager/mod.rs had the two re-exports in the wrong rustfmt order. The formatting-only correction is committed, staged-secret-scanned (exit 0), and pushed to the PR branch. The fresh head needs a new forge gate run before focused GO.

@andrei-hasna

Copy link
Copy Markdown
Contributor Author

[REVIEW] GO — #587 @ 20ed973 — lens: correctness+security+gates, reviewer Hostus (1 of 1)

Reviewed the exact diff from origin/main c74caee to 20ed973, including surrounding code in all four changed files. The change is confined to Responses compaction history formatting and bounded retention of encrypted delegated AgentMessage items.

Commands and gates:

  • bun install — exit 0; setup only, 521 packages installed; not a test result.
  • This repository declares no test script and no typecheck script in package.json; no local test/typecheck gate was invented.
  • gh pr view 587 --repo hasna/codewith --json statusCheckRollup — exit 0; forge readback: 21 SUCCESS, 0 FAILURE, 4 CANCELLED, 3 SKIPPED.
  • THE LANE'S CHOSEN COMMAND: git diff --check origin/main...HEAD — exit 0; 0 whitespace errors. This is not a repository gate and is not used as a blocker.

Forge check conclusions read:

  • Bazel test on ubuntu-24.04 for x86_64-unknown-linux-gnu: CANCELLED
  • cla: SUCCESS
  • Check for spelling errors: SUCCESS
  • Blob size policy: SUCCESS
  • cargo-deny: SUCCESS
  • build-test: SUCCESS
  • Build Codewith Linux CLI: SUCCESS
  • Detect changed areas: SUCCESS
  • python-sdk: SUCCESS
  • Bazel test on ubuntu-24.04 for x86_64-unknown-linux-musl: CANCELLED
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 1/4: SUCCESS
  • Format / etc: SUCCESS
  • sdks: SUCCESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 2/4: SUCCESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 3/4: SUCCESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm shard 4/4: SUCCESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm (native main): SKIPPED
  • cargo shear: SUCCESS
  • Bazel clippy on ubuntu-24.04 for x86_64-unknown-linux-gnu: CANCELLED
  • Argument comment lint package: SKIPPED
  • Bazel clippy on windows-latest for x86_64-pc-windows-gnullvm: SUCCESS
  • Verify release build on ubuntu-24.04 for x86_64-unknown-linux-gnu: CANCELLED
  • Argument comment lint - Linux: SUCCESS
  • Verify release build on windows-latest for x86_64-pc-windows-gnullvm: SUCCESS
  • Argument comment lint - Windows: SUCCESS
  • Bazel test on windows-latest for x86_64-pc-windows-gnullvm: SUCCESS
  • CI results (required): SUCCESS
  • [code]smith: SKIPPED

Blocking findings: none. I found no concrete, currently reachable P0/P1 correctness, security, data/session-integrity, unsafe-mutation, rollback, or required-gate defect in the reviewed candidate.

Non-blocking follow-up: the repository has no declared test gate; the focused regression in this PR is useful, but a future change could add an integration test covering the full remote-compaction install/reload path. This does not block this PR under the repository's declared gates and the green required CI aggregator.

@andrei-hasna
andrei-hasna merged commit 2c39d75 into main Aug 13, 2026
26 of 42 checks passed
@andrei-hasna
andrei-hasna deleted the hotfix/compact-v2-agentmessage-preservation branch August 13, 2026 13:38
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant