Skip to content

refactor(ai): consolidate Responses replay paths - #123762

Merged
steipete merged 4 commits into
mainfrom
steipete/replay-consolidation
Aug 14, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/replay-consolidation

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The compaction campaign added roughly 636 net production lines across #123397, #123485, #123486, #123622, #123640, and related work. Its deep review identified a concrete maintenance risk: OpenAI Responses replay conversion was implemented in parallel in the transport and provider paths, so later compaction, encrypted-reasoning, and full-history fixes had to remain synchronized by hand.

This PR recovers 334 production lines from that neighborhood without changing behavior or tests.

Why This Change Was Made

Responses message conversion and replay preparation now have one transport-owned implementation with explicit provider-versus-transport policy for the pre-existing semantic differences: transcript transforms, media projection, reasoning provenance, Copilot item IDs, tool argument serialization, and empty-message indexing. The encrypted-content retry state machine remains shared, while the SSE, WebSocket, and SDK dispatch loops stay separate because their retry and acceptance timing differ.

The same pass also consolidates exact Codex notification/deferred plumbing and the repeated model-specific tool-result pairing policy. The strict native-compaction watcher remains independent because it must discover the compaction turn, prove the matching compaction item completed, capture post-compaction usage, and hold its lifecycle fence through terminal confirmation.

User Impact

No user-visible behavior changes. This is a pure net-negative refactor that reduces drift risk across compaction replay paths while preserving all existing validation, fencing, retry timing, and provider-specific behavior.

Production LOC: +639/-973 (net -334) | Tests: +0/-0

Evidence

  • Focused replay, prompt-observer, provider retry, Codex compact/watch, session-store, and compaction-session matrix: 1,009 tests passed across five Vitest shards.
  • CI follow-up proof: pnpm tsgo:prod, dependency dead-code, unused-file, and unused-export scans passed; the exact failed lint stripe is clean on rebased main.
  • Targeted core and Codex extension lint/package-boundary checks passed.
  • pnpm format and git diff --check passed.
  • Autoreview: clean, no accepted/actionable findings on both the full refactor and follow-up correction.
  • Existing tests were not modified or deleted.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 14, 2026 17:11
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: codex size: XL maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 1:35 PM ET / 17:35 UTC.

ClawSweeper review

What this changes

Consolidates OpenAI Responses replay conversion, Codex completion promises, and agent tool-result pairing behind shared helpers while removing duplicate code.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. The refactor has no concrete source-level defect in the reviewed conversion, notification, or pairing changes, but direct Codex contract inspection and the prior requested behavior proof remain incomplete.

Priority: P2
Reviewed head: 772f098758bf4420e45bd66211ab2310a0cc552f

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source refactor is coherent and net-negative, but dependency-contract and observed replay evidence remain incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; however, the previous review's requested redacted replay trace remains useful before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; however, the previous review's requested redacted replay trace remains useful before merge.
Evidence reviewed 7 items Current main has parallel replay owners: Current main retains separate provider and transport conversion implementations; the PR replaces that duplication with a style-aware shared converter.
Shared converter preserves explicit policy split: The PR keeps provider versus transport transcript transforms, developer-role handling, media filtering, reasoning replay, and tool-call serialization as explicit branches in one owner.
Transport entry point remains covered: The Responses transport continues to call the transport-style converter with its existing payload policy inputs.
Findings None None.
Security None None.

How this fits together

Agent session history is converted into OpenAI Responses input and replayed after compaction; Codex app-server notifications separately drive native turn completion. These paths affect whether a resumed session preserves its transcript and terminal state.

flowchart LR
  A[Session transcript] --> B[Replay conversion]
  B --> C[Responses transport]
  C --> D[Provider stream]
  D --> E[Compaction replay]
  F[Codex app-server events] --> G[Turn completion routing]
  G --> E
Loading

Before merge

  • Resolve merge risk (P1) - The required direct Codex source inspection cannot be completed while ../codex is absent, so the app-server portion lacks dependency-contract verification.
  • Resolve merge risk (P1) - The latest ClawSweeper review requested an after-fix replay trace; the PR body reports automated checks but does not include that observed runtime evidence.
  • Complete next step (P2) - Protected maintainer work needs direct Codex dependency verification and the already-requested replay evidence before a landing decision.
Agent review details

Security

None.

PR surface

Source -334. Total -334 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 19 639 973 -334
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 639 973 -334

Review metrics

Metric Value Why it matters
Production delta production +639/-973 (net -334); tests +0/-0 The net-negative refactor removes duplicate runtime conversion code, but all changed lines sit on replay and session-continuity paths.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/embedded-agent-runner/compaction-session-execution.ts, migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-history.ts, migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-setup.ts, migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-tool-call-replay-sanitization.ts, migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-transcript-helpers.ts, persistent cache schema: packages/ai/src/transports/openai-responses-replay-internal.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete replay evidence before merge (recommended)
    Inspect the required Codex source contract and add a redacted after-fix transport or app-server replay trace before landing this session-sensitive refactor.

Technical review

Best possible solution:

Land one canonical style-aware replay converter only after direct Codex contract review and a redacted after-fix replay trace confirm preserved transport and native-turn outcomes.

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

Not applicable: this refactor is evaluated through behavioral equivalence and replay-path evidence rather than a reported user failure.

Is this the best way to solve the issue?

Unclear: the shared owner is the best structural direction from source review, but direct Codex contract evidence and the requested observed replay proof are still absent.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a non-user-visible refactor with meaningful but bounded session replay blast radius.
  • merge-risk: 🚨 session-state: History conversion, compaction retry, and tool-result pairing determine whether resumed sessions retain valid replay state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; however, the previous review's requested redacted replay trace remains useful before merge.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the central tool-result pairing owner to Peter Steinberger, and all four commits in this refactor are authored by him. (role: recent area contributor; confidence: high; commits: 641821f25e3e, 13c59f8bcaf3, 27db589d6d1a; files: packages/ai/src/providers/openai-responses-shared.ts, extensions/codex/src/app-server/compact.ts, src/agents/session-transcript-repair.ts)

Rank-up moves

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

  • Inspect the matching sibling Codex runtime once available.
  • Add the requested redacted after-fix replay trace to the PR body.

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-14T17:17:54.191Z sha b2c200435abdbb62eb50d894a437d0782b5cc58a :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the steipete/replay-consolidation branch from b2c2004 to 772f098 Compare August 14, 2026 17:29
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@steipete
steipete merged commit 17eb646 into main Aug 14, 2026
310 of 313 checks passed
@steipete
steipete deleted the steipete/replay-consolidation branch August 14, 2026 18:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
* refactor(ai): consolidate Responses replay ownership

* refactor(codex): consolidate completion plumbing

* refactor(agents): centralize replay pairing repair

* refactor: preserve replay static contracts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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