Repository navigation
fix: preserve engine-owned history on OpenAI Responses - #174881
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR prevents default OpenAI Responses compaction and checkpoint replay from overriding history selected by a compaction-owning context engine. Example: Lossless 1.1.1 reopens an OpenAI Responses session containing stored compaction checkpoints.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review The prior documentation finding is resolved, and no remaining actionable defect was found; this PR fixes a current history-ownership bug. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded attempt runner takes engine metadata, selected conversation history, and model parameters, then prepares provider requests and checkpoint-replay policy. flowchart TD
A[Active context engine] --> B[Session runtime preparation]
C[Model parameters] --> D[Transport preparation]
B --> D
E[Selected conversation history] --> F[Checkpoint projection]
D --> F
F --> G[OpenAI Responses request]
Technical reviewBest possible solution: Land the focused ownership repair once exact-head CI satisfies the repository gates. Do we have a high-confidence way to reproduce the issue? Current-main source permits provider replay independently of engine ownership, and the supplied CLI/Gateway before-and-after evidence demonstrates the resulting selection override; no target code was executed during review. Is this the best way to solve the issue? The repair belongs in existing transport preparation because that owner can coordinate compaction parameters and replay while using established non-mutating checkpoint utilities. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7034ca42b491. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +28, Tests +81, Docs +29. Total +138 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 16, 2026, 8:48 PM ET / October 17, 2026, 00:48 UTC (Revision 2). |
|
@clawsweeper re-review Addressed the V2 documentation finding in b995a36: the ownership guard and memory-flush statement now explicitly apply to direct API-key openai-responses routes, and the unchanged ChatGPT V2 behavior is restored. docs:check-links: 15,624 internal links checked, zero broken; git diff --check passed. The data-model compatibility explanation is now in the PR body. 77e2261 is not an ancestor of v2026.10.4, so that release did not write checkpoints through the affected default-on owning-engine path. No persisted fields, schema, writer, migration, or deletion are introduced. The real same-state main/beta checkpoint upgrade proves stored checkpoint hashes are unchanged and both post-upgrade turns retain the engine-selected markers. The new head differs from the fully rebuilt/live-proven runtime head only in two documentation files. |
|
🦞👀 Re-review progress:
|
|
Landed as 2354224.
|
Related: openclaw#168164 ([default-on change](openclaw@5d2c461)). ## What Problem This Solves Fixes OpenAI Responses native compaction replacing the history selected by a context engine that owns compaction, including when reopening an already-checkpointed session. ## User Impact Compaction-owning engines such as Lossless keep control of their selected history. Existing sessions need no reset: stored checkpoints are bypassed for the outgoing request, not deleted. The built-in `legacy` engine keeps its defaults. Explicit `params.responsesServerCompaction: true` still opts into provider-managed history, which can take precedence over engine assembly. Anthropic behavior is unchanged. ## Why This Change Was Made Default-on Responses compaction introduced a second history owner underneath engines declaring `info.ownsCompaction`. Disabling new compaction alone is insufficient: an old checkpoint can still slice the newly assembled history. Pass the active engine information to the existing attempt-transport preparation owner. One OpenAI-only decision controls server compaction, automatic `/responses/compact` eligibility, replay eligibility, and non-mutating checkpoint removal at stream entry. On these direct API-key routes, memory-extraction turns also bypass Responses compaction/replay. Native ChatGPT V2 (`openai-chatgpt-responses`) is unchanged. No new configuration, migration, or persistent state is introduced. The existing checkpoint utilities are reused. ## Evidence Baseline: `f35c075db7aca3c2a5db177ee56ffc8dc1e6dc63`. Current head: **`b995a36552f09bf88e5b2b928f298d87cf9bf826`**. The narrowed runtime was rebuilt and tested at **`b2c27afd646c1951dfb34f3fbf81b0cd08f0b203`**; the only later changes are the two documentation corrections requested by review. Tests use the installed Lossless 1.1.1 plugin, isolated Gateway state, direct API-key authentication, and the same CLI/session flow before and after. | E2E cell | BEFORE | AFTER | | --- | --- | --- | | Owning engine, default; five turns | The same upgrade fixture emitted compaction on all five requests, persisted checkpoints, and replaced selected literal markers with opaque replay on turns 2–5. | Narrowed runtime `b2c27afd646c`: 5/5 successful turns, no native compaction or checkpoint replay; complete response-ID chains contain every selected marker, including the early marker on all five turns. | | Checkpointed-session upgrade | Five turns on the baseline produced five stored checkpoints with Lossless loaded and owning compaction. | Narrowed runtime `b2c27afd646c` on the **same state**: plugin active, engine owns compaction, 2/2 successful turns, all selected markers present in reconstructed effective input, early marker recalled both times. Stored checkpoint hashes are unchanged; no compaction/replay was sent. Answers also included the original turn tag, so exact-output-format equality is not claimed. | | Owning engine, default, repeated | Baseline checkpoint override observed in the same flow. | Pre-narrowing `5abec9c7e5a`: two independent five-turn runs preserved all selected markers through complete effective chains. | | Upgrade, repeated | Each baseline phase persisted real checkpoints. | Pre-narrowing `5abec9c7e5a`: two independent upgrades preserved selection and recalled the early marker in both post-upgrade turns. One run also returned the turn tag. | | Lossless non-append selection | Not a separate baseline claim. | Pre-narrowing `5abec9c7e5a`: five successful turns, three real Lossless summary requests, two non-append assembly changes. Both changes sent full input without `previous_response_id`; every selected marker was present. No continuation retained the old raw prefix. | | `legacy` default, two repeats | Native compaction retained; five successful turns per repeat. | Pre-narrowing `5abec9c7e5a`: native compaction retained; five successful turns per repeat. | | Owning engine with explicit opt-in, two repeats | Native compaction retained; five successful turns per repeat. | Pre-narrowing `5abec9c7e5a`: native compaction retained; five successful turns per repeat. | | Binary-swap runtime controls, two repeats each | BEFORE → BEFORE and BEFORE → current-main control. | BEFORE → candidate also passed: installed plugin loaded/active after every swap. | The narrowed-runtime core and upgrade cells exercise the exact runtime source at the current head; only documentation changed afterward. The other AFTER rows are explicitly pre-narrowing evidence; their OpenAI behavior was not changed by removing the unproven Anthropic policy. No completed compatibility cell was rerun. Effective input is reconstructed as previous effective input + previous output + request delta. Full requests start new chains. Opaque provider checkpoints are **not** treated as readable context: BEFORE proves the literal-selection override, not the contents of the encrypted summary or an unobserved recall failure. AFTER chains are complete and contain all selected markers. Marker inclusion is not a claim of byte-for-byte equality for every transport-normalized item. The earlier plugin `Unexpected token ')'` error was an external observer-fixture syntax error. Correcting its Proxy closure resolved it on all three binary-swap controls. Anthropic experiments did not prove history loss because Lossless stubbed the oversized input; those behavior/doc changes were removed rather than extending the fix speculatively. **Stored-data compatibility:** `5d2c461f092` (openclaw#168164), which introduced the affected default-on provider compaction path, is not an ancestor of `v2026.10.4` (`git merge-base --is-ancestor` exits 1). That release did not write checkpoints through the affected default-on owning-engine path. This fix adds no persisted fields, schema, writer, migration, or deletion. The same-state checkpoint upgrade above covers affected main/beta sessions and verifies the original stored checkpoint hashes remain unchanged. A release-to-head run cannot qualify a default-on checkpoint path absent from that release. Focused checks on the unchanged narrowed runtime: - `node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-transport.test.ts src/agents/embedded-agent-runner/run/attempt-session-runtime-prepare.test.ts`: **2 files, 30 tests passed**; Vitest 64.42 s, wrapper 72.59 s. The matrix covers OpenAI ownership/default/false/true/memory and unchanged Anthropic behavior. The original regression failed on the baseline. - Scoped `oxfmt` and direct `oxlint`: passed. `pnpm build`: passed (9m 36s). After the docs-only review correction, `pnpm docs:check-links` checked 15,624 internal links with zero broken links, and `git diff --check` passed. [Current-head CI passed](https://github.com/openclaw/openclaw/actions/runs/38987676167): 35 successful jobs, zero failures or cancellations. ClawSweeper is ready on `b995a36552f09bf88e5b2b928f298d87cf9bf826` with no findings. - Total OpenAI accounted input including cached input: 1,593,120; conservative reservations: 1,923,335, below the 2.5M cap. No credentials retained. Simplification: one existing decision owner and no new state/helper layer; cumulative production delta +33/−5 lines and tests +82/−1. Unproven Anthropic behavior was removed. **Merge danger:** two-way code change, with no stored-data migration or deletion. Reverting restores the old behavior but cannot recover context a provider may summarize afterward. Blast radius is embedded OpenAI Responses sessions using compaction-owning engines (and Responses memory extraction); a wrong ownership decision could omit selected history or retain stale provider history. Legacy, explicit opt-in, and non-OpenAI routes keep their existing contracts. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #168164 (default-on change).
What Problem This Solves
Fixes OpenAI Responses native compaction replacing the history selected by a context engine that owns compaction, including when reopening an already-checkpointed session.
User Impact
Compaction-owning engines such as Lossless keep control of their selected history. Existing sessions need no reset: stored checkpoints are bypassed for the outgoing request, not deleted. The built-in
legacyengine keeps its defaults. Explicitparams.responsesServerCompaction: truestill opts into provider-managed history, which can take precedence over engine assembly. Anthropic behavior is unchanged.Why This Change Was Made
Default-on Responses compaction introduced a second history owner underneath engines declaring
info.ownsCompaction. Disabling new compaction alone is insufficient: an old checkpoint can still slice the newly assembled history.Pass the active engine information to the existing attempt-transport preparation owner. One OpenAI-only decision controls server compaction, automatic
/responses/compacteligibility, replay eligibility, and non-mutating checkpoint removal at stream entry. On these direct API-key routes, memory-extraction turns also bypass Responses compaction/replay. Native ChatGPT V2 (openai-chatgpt-responses) is unchanged. No new configuration, migration, or persistent state is introduced. The existing checkpoint utilities are reused.Evidence
Baseline:
a1506c240abaa0781b7a462c30c653d2caf14dd4. Current head:b995a36552f09bf88e5b2b928f298d87cf9bf826. The narrowed runtime was rebuilt and tested atb2c27afd646c1951dfb34f3fbf81b0cd08f0b203; the only later changes are the two documentation corrections requested by review. Tests use the installed Lossless 1.1.1 plugin, isolated Gateway state, direct API-key authentication, and the same CLI/session flow before and after.b2c27afd646c: 5/5 successful turns, no native compaction or checkpoint replay; complete response-ID chains contain every selected marker, including the early marker on all five turns.b2c27afd646con the same state: plugin active, engine owns compaction, 2/2 successful turns, all selected markers present in reconstructed effective input, early marker recalled both times. Stored checkpoint hashes are unchanged; no compaction/replay was sent. Answers also included the original turn tag, so exact-output-format equality is not claimed.5abec9c7e5a: two independent five-turn runs preserved all selected markers through complete effective chains.5abec9c7e5a: two independent upgrades preserved selection and recalled the early marker in both post-upgrade turns. One run also returned the turn tag.5abec9c7e5a: five successful turns, three real Lossless summary requests, two non-append assembly changes. Both changes sent full input withoutprevious_response_id; every selected marker was present. No continuation retained the old raw prefix.legacydefault, two repeats5abec9c7e5a: native compaction retained; five successful turns per repeat.5abec9c7e5a: native compaction retained; five successful turns per repeat.The narrowed-runtime core and upgrade cells exercise the exact runtime source at the current head; only documentation changed afterward. The other AFTER rows are explicitly pre-narrowing evidence; their OpenAI behavior was not changed by removing the unproven Anthropic policy. No completed compatibility cell was rerun.
Effective input is reconstructed as previous effective input + previous output + request delta. Full requests start new chains. Opaque provider checkpoints are not treated as readable context: BEFORE proves the literal-selection override, not the contents of the encrypted summary or an unobserved recall failure. AFTER chains are complete and contain all selected markers. Marker inclusion is not a claim of byte-for-byte equality for every transport-normalized item.
The earlier plugin
Unexpected token ')'error was an external observer-fixture syntax error. Correcting its Proxy closure resolved it on all three binary-swap controls. Anthropic experiments did not prove history loss because Lossless stubbed the oversized input; those behavior/doc changes were removed rather than extending the fix speculatively.Stored-data compatibility:
77e2261b573(#168164), which introduced the affected default-on provider compaction path, is not an ancestor ofv2026.10.4(git merge-base --is-ancestorexits 1). That release did not write checkpoints through the affected default-on owning-engine path. This fix adds no persisted fields, schema, writer, migration, or deletion. The same-state checkpoint upgrade above covers affected main/beta sessions and verifies the original stored checkpoint hashes remain unchanged. A release-to-head run cannot qualify a default-on checkpoint path absent from that release.Focused checks on the unchanged narrowed runtime:
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt-stream-transport.test.ts src/agents/embedded-agent-runner/run/attempt-session-runtime-prepare.test.ts: 2 files, 30 tests passed; Vitest 64.42 s, wrapper 72.59 s. The matrix covers OpenAI ownership/default/false/true/memory and unchanged Anthropic behavior. The original regression failed on the baseline.oxfmtand directoxlint: passed.pnpm build: passed (9m 36s). After the docs-only review correction,pnpm docs:check-linkschecked 15,624 internal links with zero broken links, andgit diff --checkpassed. Current-head CI passed: 35 successful jobs, zero failures or cancellations. ClawSweeper is ready onb995a36552f09bf88e5b2b928f298d87cf9bf826with no findings.Simplification: one existing decision owner and no new state/helper layer; cumulative production delta +33/−5 lines and tests +82/−1. Unproven Anthropic behavior was removed.
Merge danger: two-way code change, with no stored-data migration or deletion. Reverting restores the old behavior but cannot recover context a provider may summarize afterward. Blast radius is embedded OpenAI Responses sessions using compaction-owning engines (and Responses memory extraction); a wrong ownership decision could omit selected history or retain stale provider history. Legacy, explicit opt-in, and non-OpenAI routes keep their existing contracts.