Skip to content

fix(ai): keep provider checkpoints across model switches - #200208

Merged
obviyus merged 3 commits into
mainfrom
openclaw/wild-crayfish
Nov 16, 2026
Merged

obviyus merged 3 commits into
mainfrom
openclaw/wild-crayfish

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A session that changes models drops its own server compaction checkpoint, resends the full raw history, and falls back to client summarization. Model changes happen through fallbacks, per-turn overrides and model alternation within one session.

The provider replay check compared the model id. After #200063 removed the credential-path check, the model check was the other common cause. On the host that reported the original incident, model changes accounted for 357 of 800 dropped-checkpoint turns, mostly a session alternating between gpt-6-astra and gpt-6.1-sol.

Fix

  • The replay check is now provider API, endpoint and session. The model id stays in the stored record but is no longer compared.
  • Providers accept their own replay items across models. I checked this with raw API calls before changing anything:
    • OpenAI compaction items: gpt-6-astra ↔ gpt-6.1-sol and gpt-5.4-mini → gpt-5.4 are accepted, and the model recalls a fact that is only in the compacted history.
    • OpenAI encrypted reasoning: the same pairs are accepted.
    • Anthropic compaction blocks: claude-sonnet-4-6 → claude-opus-4-8 is accepted and recalls the compacted fact. These blocks are plaintext summaries.
  • An item a provider cannot use is still rejected server-side (invalid_encrypted_content / item_conflict), and the existing replay recovery handles it.

The production change is one comparison removed. The tests that asserted the model check are replaced with positive cases.

Evidence

Regression test: openai-responses-compaction-replay.test.ts › "replays a checkpoint written by another model in the same session". It fails on the old check and passes with the fix.

Real-model E2E (isolated state; each arm built from its own source):

  • Three seed turns on openai/gpt-5.4-mini with server compaction, then a final turn on openai/gpt-5.4 in the same session with the same key.
  • Request shapes come from OPENCLAW_DEBUG_MODEL_PAYLOAD=summary.
arm final-turn request items text chars answer
base messages only; compactionItems=0 11 113,090 correct
fix compaction, message:user, message:developer; compactionItems=1 3 656 correct

Checks:

  • The touched replay suites pass (100 tests).
  • check:changed passes except the dead-export scan. That scan reports unused exports in files this PR does not touch, which come from the current main tree.

Scope

Encrypted reasoning from a different model is still dropped on a model switch. The generic cross-model history transforms (transcript-transform.ts, transport-message-transform.ts) and dropStaleOpenAIReasoning strip it before the replay check runs. That costs one turn of reasoning context, not the session's history, so it is left for a separate change.

Follow-up

The context meter still estimates from the full transcript when a checkpoint is present. That fix is a separate PR.

obviyus and others added 2 commits November 16, 2026 23:58
The replay fence compared the model id, so a session that changed models
(fallbacks, per-turn overrides, astra/sol alternation) discarded its own
server compaction checkpoints and encrypted reasoning, resent the full
history and fell back to client summarization.

OpenAI compaction items and encrypted reasoning, and Anthropic compaction
blocks, are accepted across models of the same provider. The fence is now
provider API, endpoint and session. An item the provider cannot use is
still rejected server-side and handled by the existing replay recovery.

Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 062db4a7-d3c5-4845-a8d2-101d13f1edce
@clawsweeper

clawsweeper Bot commented Nov 16, 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.

@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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. 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 Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves provider compaction checkpoints when a session switches models within the same provider API and endpoint.

Example: A session compacts three turns with openai/gpt-5.4-mini, then continues with openai/gpt-5.4.

  • Before: The recorded request drops the checkpoint and sends 11 items containing 113,090 text characters.
  • After: The recorded request retains one compaction item and sends 3 items containing 656 text characters.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, minimal repair with recorded end-to-end proof, unchanged checkpoint serialization and readers, and no actionable findings; outstanding CI remains subject to normal landing gates.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR records isolated real-model runs through OpenClaw's request path: seed compaction with gpt-5.4-mini, continue with gpt-5.4, and observe one retained checkpoint with a compact request and a correct answer after the fix.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Sessions that switch models lose usable server compaction checkpoints and resend their full history.
Reason: The observed production failure and recorded real-model comparison establish value, and the maintainer-authored direction explicitly accepts cross-model replay with existing provider rejection recovery.

Merge readiness

✅ Ready for maintainer review

This PR addresses a demonstrated checkpoint-continuity bug with a focused shared-owner fix and recorded real-model proof; no introduced defect was found, and the failed UI assertion also fails on the base.

Priority: P1
Reviewed head: 9119c82aa7f4eb9aeedcac7c036438968c48e6dc

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared AI replay matcher selects checkpoints from saved conversation history for provider request conversion, history projection, and context accounting.

flowchart LR
  A[Saved conversation] --> C[Shared replay matcher]
  B[Selected provider route and session] --> C
  C --> D[Checkpoint and remaining history]
  D --> E[Provider request]
  E --> F[Provider response]
  F --> A
Loading

Technical review

Best possible solution:

Keep the shared matcher repair and focused checkpoint regression while preserving the existing route/session boundaries and rejection recovery.

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

Current main directly rejects matching-session checkpoints when model IDs differ, and the supplied real-model comparison demonstrates the resulting request expansion; no target code was executed during this review.

Is this the best way to solve the issue?

Removing the comparison at the existing shared owner is the smallest complete repair for checkpoint continuity, with no added state, wrapper, or competing policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against aa4d490a848b.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit ef68101 adds packages/ai/src/transports/provider-replay-context.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ef681015e567; files: packages/ai/src/transports/provider-replay-context.ts)
  • Peter Steinberger: Raw commit 1439894 adds packages/ai/src/transports/provider-replay-context.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 14398941a104; files: packages/ai/src/transports/provider-replay-context.ts)

PR surface

Source -1, Tests +13. Total +12 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 7 -1
Tests 4 17 4 +13
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 23 11 +12

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P1: Reported production model switches discard usable checkpoints in long-running sessions, resend large histories, and trigger client summarization.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Reported production model switches discard usable checkpoints in long-running sessions, resend large histories, and trigger client summarization.
  • 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.
  • 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.

Reviewed November 16, 2026, 1:51 PM ET / 18:51 UTC.

@obviyus
obviyus merged commit 7cb238a into main Nov 16, 2026
194 of 197 checks passed
@obviyus
obviyus deleted the openclaw/wild-crayfish branch November 16, 2026 19:02
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 7cb238a.

  • Bug: the replay check compared the model id. A session that changed models dropped its own server compaction checkpoint, resent the full history and fell back to client summarization.
  • Fix: the replay check is provider API, endpoint and session. OpenAI compaction items and Anthropic compaction blocks were each confirmed against the live API to replay across models.
  • Proof: in a real model switch from gpt-5.4-mini to gpt-5.4, base resent 11 items and 113k chars, while the fix sent the checkpoint and the new message (3 items, 656 chars). Both answers were correct. The local review was ready on the exact head, and CI was green.
  • Not covered: encrypted reasoning from another model is still stripped by the cross-model history transforms; that's out of scope here.

RomneyDa added a commit that referenced this pull request Nov 16, 2026
Backport canonical 7cb238a for the 2026.11.5 release, as requested by Dallin. Applies without adaptation on top of #200063. Preserve provider API, endpoint, and session boundaries; the provider owns checkpoint compatibility.

Proof: new checkpoint replay regression fails on the original owner; all 102 focused replay tests pass with the patch. Prefix stability 14/14 and formatting/diff checks pass. Live provider proof is retained in the canonical PR, not rerun locally. Full release qualification remains pending.

(cherry picked from commit 7cb238a)
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 16, 2026
Backport #200063, #200208, #200247, #200260 and #190065 to 2026.10.33. Preserve canonical source credit and maintenance-branch contracts.

All selected exact-head checks passed except the inherited Docker plugin API mismatch; aggregate ci-gate reports that same cause. Landing authorized with this attributed pre-existing failure.

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: miguelbranco80 <[email protected]>
Co-authored-by: Shakker <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…0208)

## Problem

A session that changes models drops its own server compaction checkpoint, resends the full raw history, and falls back to client summarization. Model changes happen through fallbacks, per-turn overrides and model alternation within one session.

The provider replay check compared the model id. After openclaw#200063 removed the credential-path check, the model check was the other common cause. On the host that reported the original incident, model changes accounted for 357 of 800 dropped-checkpoint turns, mostly a session alternating between `gpt-6-astra` and `gpt-6.1-sol`.

## Fix

- The replay check is now provider API, endpoint and session. The model id stays in the stored record but is no longer compared.
- Providers accept their own replay items across models. I checked this with raw API calls before changing anything:
  - **OpenAI compaction items:** `gpt-6-astra` ↔ `gpt-6.1-sol` and `gpt-5.4-mini` → `gpt-5.4` are accepted, and the model recalls a fact that is only in the compacted history.
  - **OpenAI encrypted reasoning:** the same pairs are accepted.
  - **Anthropic compaction blocks:** `claude-sonnet-4-6` → `claude-opus-4-8` is accepted and recalls the compacted fact. These blocks are plaintext summaries.
- An item a provider cannot use is still rejected server-side (`invalid_encrypted_content` / `item_conflict`), and the existing replay recovery handles it.

The production change is one comparison removed. The tests that asserted the model check are replaced with positive cases.

## Evidence

**Regression test:** `openai-responses-compaction-replay.test.ts` › "replays a checkpoint written by another model in the same session". It fails on the old check and passes with the fix.

**Real-model E2E** (isolated state; each arm built from its own source):
- Three seed turns on `openai/gpt-5.4-mini` with server compaction, then a final turn on `openai/gpt-5.4` in the same session with the same key.
- Request shapes come from `OPENCLAW_DEBUG_MODEL_PAYLOAD=summary`.

| arm | final-turn request | items | text chars | answer |
| --- | --- | --- | --- | --- |
| base | messages only; `compactionItems=0` | 11 | 113,090 | correct |
| fix | `compaction, message:user, message:developer`; `compactionItems=1` | 3 | 656 | correct |

**Checks:**
- The touched replay suites pass (100 tests).
- `check:changed` passes except the dead-export scan. That scan reports unused exports in files this PR does not touch, which come from the current `main` tree.

## Scope

Encrypted reasoning from a different model is still dropped on a model switch. The generic cross-model history transforms (`transcript-transform.ts`, `transport-message-transform.ts`) and `dropStaleOpenAIReasoning` strip it before the replay check runs. That costs one turn of reasoning context, not the session's history, so it is left for a separate change.

## Follow-up

The context meter still estimates from the full transcript when a checkpoint is present. That fix is a separate PR.

<!-- openclaw-publication:062db4a7-d3c5-4845-a8d2-101d13f1edce -->

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

P1 High-priority user-facing bug, regression, or broken workflow. 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