Skip to content

fix: preserve engine-owned history on OpenAI Responses - #174881

Merged
obviyus merged 4 commits into
mainfrom
fix/engine-owned-provider-compaction
Oct 17, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/engine-owned-provider-compaction

Conversation

@obviyus

@obviyus obviyus commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

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 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: a1506c240abaa0781b7a462c30c653d2caf14dd4. 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: 77e2261b573 (#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: 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.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Checkpoint replay replaces literal history selected by the engine with opaque provider context.
  • After: Requests retain the engine-selected history while stored checkpoints remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, worthwhile repair with shipped-entry-point evidence, same-state compatibility coverage, and the prior documentation defect resolved; current-head CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied isolated CLI/Gateway evidence exercises the changed transport with installed Lossless 1.1.1, complete effective request chains, repeated controls, and reopening real checkpointed state; the proven narrowed runtime is unchanged by the final documentation commit.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A compaction-owning engine can select conversation history that the Responses transport subsequently replaces with provider-managed context.
Reason: The maintainer-authored repair restores the existing engine ownership contract, preserves explicit provider opt-in, and avoids resetting or rewriting sessions.

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
Reviewed head: b995a36552f09bf88e5b2b928f298d87cf9bf826

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Provider compaction and memory-extraction policy changes intended behavior with a stated reason (77e2261: Enable provider-native compaction while retaining unsummarized history for memory extraction.)
  • Transport preparation placement keeps the original intent (b05a308: Consolidate prompt and stream phases without changing behavior; this PR keeps the decision in that existing owner.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +28, Tests +81, Docs +29. Total +138 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 33 5 +28
Tests 1 82 1 +81
Docs 3 32 3 +29
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 147 9 +138

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +33/-5 lines; tests +82/-1 lines Growth stays within the existing transport owner and covers ownership, explicit settings, memory turns, provider isolation, and checkpoint non-mutation.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The defect changes model-visible history for embedded Responses sessions using compaction-owning engines, with limited provider and engine scope.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-17T00:39:10.922Z sha b2c27af :: blocked before merge. :: [P3] Scope the ownership documentation to the guarded Responses route

Reviewed October 16, 2026, 8:48 PM ET / October 17, 2026, 00:48 UTC (Revision 2).

@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

@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.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus
obviyus merged commit 2354224 into main Oct 17, 2026
143 checks passed
@obviyus
obviyus deleted the fix/engine-owned-provider-compaction branch October 17, 2026 00:58
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 2354224.

  • Bug: since feat(compaction): default to provider-native compaction on OpenAI and Anthropic API-key routes #168164, direct API-key OpenAI Responses turns enabled provider-native compaction even when a context engine (e.g. lossless-claw) owned compaction; after the first provider checkpoint, replay replaced the engine's selected history with that checkpoint.
  • Fix: one attempt-level ownership decision: an owning engine turns off OpenAI server compaction and checkpoint replay unless the operator explicitly opts in. Plain-engine behavior is unchanged.
  • Proof: real gpt-5.4-mini + lossless-claw 1.1.1: main dropped selected history on turns 2–5; with the fix every selected message reached the provider, including a session upgraded from a checkpointed state. Anthropic is unchanged here (not proven live).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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