Skip to content

fix(ai): retain compaction-only replay checkpoints - #127106

Merged
RomneyDa merged 4 commits into
mainfrom
fix/openai-compaction-replay
Aug 21, 2026
Merged

RomneyDa merged 4 commits into
mainfrom
fix/openai-compaction-replay

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

Summary

  • preserve an OpenAI Responses compaction checkpoint when a sanitizer projects an unchanged empty assistant body
  • keep stripping the checkpoint when previously present owner content is actually removed
  • run the compaction replay Gateway E2E with the full prepared runtime lifecycle

Root cause

OpenAI Responses can finish a turn with only a provider compaction item, so the durable assistant owner legitimately has content: [] plus providerReplay. The shared image/history sanitizer projects assistant content into a fresh array before the next request. replaceCompactionReplayOwnerContent treated every empty projected array as destructive content removal and stripped the checkpoint, even when both the source and projection were unchanged empty arrays.

The transport then received the original user history and continuation prompt without the compaction item. The fix belongs in the shared replay-owner rewrite helper: unchanged projections retain provider state, while actual removals still invalidate prefix-bound state.

This PR is stacked on #127094 so that the E2E reaches the model transport. #127094 now remains focused on the independent prepared-runtime publication failure in the embedded cursor E2E; this PR owns the compaction test's full-startup opt-in and replay repair.

Proof

Pre-fix, in the original run order after enabling full startup:

OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs \
  test/gateway-openai-compaction-replay.e2e.test.ts \
  test/embedded-transcript-cursor.e2e.test.ts

gateway-openai-compaction-replay: expected request 2 to contain
{ type: "compaction", id: "cmp_gateway_replay", encrypted_content: "opaque-gateway-compaction" }

Post-fix:

OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway-openai-compaction-replay.e2e.test.ts
Test Files  1 passed (1)
Tests       1 passed (1)

Additional verification:

node scripts/run-vitest.mjs \
  src/agents/embedded-agent-helpers.sanitize-session-messages-images.removes-empty-assistant-text-blocks-but-preserves.test.ts \
  packages/ai/src/transports/provider-compaction-replay.test.ts
Test Files  2 passed (2)
Tests       27 passed (27)

node scripts/check-changed.mjs -- \
  packages/ai/src/transports/provider-compaction-replay.ts \
  packages/ai/src/transports/provider-compaction-replay.test.ts
passed

.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/fix/prepared-runtime-e2e
autoreview clean: no accepted/actionable findings reported (0.99)

Original release-validation failure: https://github.com/openclaw/openclaw/actions/runs/32457175968/job/96697080014

Scope

  • Architectural owner: shared provider compaction replay rewrite helper
  • Siblings covered: generic replay owner rewrite tests plus the image/history sanitizer lane
  • Production delta: +6/-0; tests/config: +8/-0
  • No schema, protocol, config contract, or extended-stable changes

@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 7:00 AM ET / 11:00 UTC.

ClawSweeper review

What this changes

The PR retains OpenAI Responses compaction replay checkpoints when history sanitization projects an already-empty assistant message, while retaining checkpoint removal when non-empty owner content is removed.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

No blocking line-level defect was found: the shared owner-boundary predicate correctly distinguishes unchanged empty content from actual removal. Keep this stacked, maintainer-labeled PR open for parent landing order and direct contract verification unavailable in this review environment.

Priority: P2
Reviewed head: 8e8b736dc0224f6d19d1fc74cbd27143f83bcac4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and backed by a real Gateway boundary run, with direct external-contract inspection remaining for maintainer review.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body records an after-fix ephemeral Gateway run through the production transport boundary and a mock Responses server, with the expected replay E2E passing.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records an after-fix ephemeral Gateway run through the production transport boundary and a mock Responses server, with the expected replay E2E passing.
Evidence reviewed 7 items Current-main defect: Current main strips a prefix checkpoint whenever the projected content is empty, including an assistant owner that was already empty.
Narrow owner-boundary repair: The branch retains the checkpoint only when both source and projected content are empty; it still strips state when owner content becomes empty after sanitization.
Caller and destructive sibling behavior: The image/history sanitizer routes replay-bearing assistant messages through this helper, while its existing test still asserts checkpoint removal after whitespace-only source content is deleted.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway-openai-compaction-replay.e2e.test.ts

Result: FAIL (failed) — step 1 run OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway-openai-compaction-replay.e2e.test.ts: terminal command did not produce output within 20 seconds: "OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway-openai-compaction-replay.e2e.test.ts"

OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway-openai-compaction-replay.e2e.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127106-Tjix3K/target$ OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway
-openai-compaction-replay.e2e.test.ts
[test] starting test/vitest/vitest.e2e.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127106-Tjix3K/target

OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs test/gateway-openai-compaction-replay.e2e.test.ts











































Assertions:

  • FAIL expect_output: Tests 1 passed (1)

How this fits together

Provider compaction state is persisted with an assistant message and reused when OpenClaw builds the next Responses request. History sanitization may project that message into a fresh content array before the provider transport emits the continuation request.

flowchart LR
  A[Persisted assistant turn] --> B[History sanitizer]
  B --> C[Replay owner rewrite]
  C --> D{Content actually removed?}
  D -->|Yes| E[Drop checkpoint and use full history]
  D -->|No| F[Retain checkpoint]
  F --> G[Responses continuation request]
Loading

Decision needed

Question Recommendation
After the stacked parent lands, should this PR require a direct Codex-source or authoritative Responses-contract check in addition to its mock-Responses Gateway E2E before merge? Verify the contract before merge: Inspect the cited Codex or authoritative Responses implementation, then rebase and rerun the focused Gateway E2E on the exact head.

Why: Repository policy requires the acting reviewer to inspect the sibling Codex source when the PR relies on that contract, but that checkout was unavailable in this read-only environment.

Before merge

  • Resolve merge risk (P1) - This changes persisted replay-state handling: an incorrectly classified empty projection would send an opaque checkpoint instead of falling back to full history. Existing destructive-empty coverage is preserved, but the cited Codex contract could not be independently inspected here.
  • Resolve merge risk (P1) - Production source is physically +3 lines; the growth is confined to the predicate needed to distinguish an unchanged empty owner from a destructive emptying.
  • Complete next step (P2) - This maintainer-authored, stacked PR has no mechanical repair remaining; a human must settle parent ordering and the direct contract-proof gate.
Agent review details

Security

None.

PR surface

Source +3, Tests +8. Total +11 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 2 8 0 +8
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 12 1 +11

Review metrics

Metric Value Why it matters
Production vs test LOC production +4/-1; tests +8/-0 The production change is one replay-state predicate; the added tests cover the owner helper and full Gateway boundary.

Merge-risk options

Maintainer options:

  1. Verify checkpoint retention at the exact merge head (recommended)
    After the parent resolves, directly verify the external compaction contract and rerun the child-Gateway replay path so persisted session state cannot preserve an invalid checkpoint.
  2. Accept the contract evidence as recorded
    Merge with the documented mock-provider E2E evidence while explicitly accepting that an authenticated provider contract check was not available.

Technical review

Best possible solution:

After #127094 resolves, retain the repair in the shared rewrite helper, directly verify the cited contract, then rebase and rerun the exact-head Gateway replay E2E plus the sanitizer removal coverage.

Do we have a high-confidence way to reproduce the issue?

Yes for a source-level reproduction: current main strips a checkpoint when both the original and projected owner contents are empty; the focused Gateway E2E reaches this path after its stacked startup prerequisite is present.

Is this the best way to solve the issue?

Yes. Repairing the shared replay-owner rewrite preserves the invariant for its sanitizer caller while retaining the existing destructive-removal invalidation path; downstream transport workarounds would be less maintainable.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 75c44b2b98d5.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The patch changes whether persisted assistant replay state survives sanitization and is reused on the next model request.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix ephemeral Gateway run through the production transport boundary and a mock Responses server, with the expected replay E2E passing.

Label justifications:

  • P2: This is a bounded provider replay correctness repair with limited but real session-context impact.
  • merge-risk: 🚨 session-state: The patch changes whether persisted assistant replay state survives sanitization and is reused on the next model request.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body records an after-fix ephemeral Gateway run through the production transport boundary and a mock Responses server, with the expected replay E2E passing.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix ephemeral Gateway run through the production transport boundary and a mock Responses server, with the expected replay E2E passing.

Evidence

What I checked:

Likely related people:

  • steipete: Current history attributes the foundational transcript-rewrite and Responses retained-compaction work to this area. (role: feature owner and recent area contributor; confidence: high; commits: c6fc12dc6745, d32c09f84364; files: packages/ai/src/transports/provider-compaction-replay.ts, packages/ai/src/transports/openai-responses-compaction-replay.ts, src/agents/embedded-agent-helpers/images.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Directly inspect the cited contract, then rerun the focused Gateway replay E2E after the stacked parent resolves.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-21T08:22:26.787Z sha 01e8494 :: needs maintainer review before merge. :: none

@RomneyDa
RomneyDa force-pushed the fix/prepared-runtime-e2e branch from ee16d57 to 0a6e6ba Compare August 21, 2026 10:38
@RomneyDa
RomneyDa force-pushed the fix/openai-compaction-replay branch from 01e8494 to 8e8b736 Compare August 21, 2026 10:54
@RomneyDa

Copy link
Copy Markdown
Member Author

Restacked onto exact parent #127094 head 0a6e6bad335212ebc7c2e0d7f28cc3f77fff919a; pushed exact child 8e8b736dc0224f6d19d1fc74cbd27143f83bcac4.

The old src/entry.run-main.test.ts red was shared baseline drift and now passes with the landed entry repair. The rank-up move is absorbed into the existing strip predicate: unchanged empty owner content preserves its checkpoint without the six-line identity scan. Production delta vs exact parent: +1/-1; tests: +8.

Proof:

  • unit + shared baseline: 2 files / 6 tests passed
  • real local Gateway + mock Responses server E2E: 1 passed
  • test audit: public Gateway-turn persistence behavior, no test-only production seam
  • deslop: clean
  • autoreview against exact parent: clean, no actionable findings (0.93)

Direct Codex contract proof: ../codex/codex-rs/protocol/src/models.rs:1148, ../codex/codex-rs/core/src/context_manager/history.rs:480, ../codex/codex-rs/core/src/compact_remote_v2.rs:400, and ../codex/codex-rs/codex-api/src/sse/responses.rs:340. These define, retain, collect, and parse compaction items, including compaction-only output. Current official Responses API docs likewise expose compaction items and response.output_item.done. No OPENAI_API_KEY was available for an authenticated external call, so the exact Gateway mock-provider E2E is the feasible runtime proof.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Aug 21, 2026
Base automatically changed from fix/prepared-runtime-e2e to main August 21, 2026 16:05
@RomneyDa
RomneyDa merged commit 566b0e5 into main Aug 21, 2026
157 checks passed
@RomneyDa
RomneyDa deleted the fix/openai-compaction-replay branch August 21, 2026 16:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 22, 2026
* test(gateway): publish runtime in agent E2Es

* test(gateway): leave replay fix to owner PR

* fix(ai): retain compaction-only replay checkpoints

* fix(ai): preserve empty compaction replay checkpoints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant