Skip to content

fix(ai): preserve long Responses sessions after server compaction - #120457

Merged
steipete merged 15 commits into
mainfrom
steipete/clawstudio-1m-context-configuration-79869f
Aug 8, 2026
Merged

steipete merged 15 commits into
mainfrom
steipete/clawstudio-1m-context-configuration-79869f

Conversation

@steipete

@steipete steipete commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Related: #95788

What Problem This Solves

Fixes an issue where long stateless OpenAI Responses sessions could lose the provider's authoritative compressed history after automatic server compaction. OpenAI emitted an opaque encrypted compaction output item, but OpenClaw neither persisted nor replayed it on the next request, so continuation after compaction or a worker/Gateway restart could silently fall back to an incomplete transcript.

Issue #95788 is related but narrower: it asks whether the ChatGPT/Codex no-store route should emit context_management or diagnose that it cannot. This PR does not expand that OAuth/store contract and therefore does not close the issue.

Why This Change Was Made

The Responses transport is the architectural owner of provider replay state. It now captures the newest first-class compaction item from stream and terminal events, fences reuse by provider, API, model, base URL, session, and auth identity, and replays only a compatible newest item while pruning the prefix it replaces without separating tool calls from their outputs.

The typed replay state crosses the existing LLM, Gateway, SQLite transcript, and worker transcript-frame boundaries. Display, session-history, diagnostics, cache traces, and debug payloads remove the opaque encrypted content; request correlation remains redacted. Native Codex retains its own compaction policy and receives the same long-context budget through its catalog/app-server contract rather than through embedded Responses parameters.

Encrypted-content recovery is deliberately attributable and bounded through one transport-owned three-state plan shared by the SDK (including the canonical Azure Responses transport), native SSE, and native WebSocket paths. A mixed request first retries without encrypted reasoning while preserving compaction. Compaction is removed only after that compaction-preserving request receives the recognized rejection. SDK recovery records the route-fenced tombstone only after successful response acquisition; native SSE waits for a non-aborted 2xx response with a body, and native WebSocket waits for the first yielded response event. Fetch, observer, unrelated provider, abort, final-recovery, and post-stream-start failures cannot advance the semantic retry plan. The terminal stream owner also records provider output identities at their normalized content indexes so terminal-only compaction is replayed at the exact observed boundary.

Worker replay data is capped at 48 KiB without truncating ciphertext. Representative complete commit-frame overhead was 1,021-1,068 bytes, leaving about 15.3 KiB at the cap. A conservative identifier/signature envelope measured 3,829-3,831 bytes, leaving about 12.5 KiB; at 60 KiB only about 267 bytes remained. Projection checks both raw UTF-8 replay bytes and the exact JSON-encoded complete commit frame, omitting only unpersistable replay and emitting a redacted payload.large diagnostic.

No config/default surface or protocol version changes. Production growth is +1,146/-272 (net +874) across 29 files; that growth is justified by the external provider replay contract, its typed persistence and invalidation owner boundary, native retry attribution, exact worker-frame safety, and the privacy invariant around opaque provider state. Tests are +5,168/-101 across 26 files. Docs are +221/-69 across 3 files.

AI-assisted: yes. Codex assisted with the repair and fresh structured reviews. The final Azure recovery review reported no accepted/actionable findings at 0.98 confidence; the staged-recovery review was clean at 0.97 and earlier full-branch/focused reviews were clean at 0.98/0.99. TruffleHog was clean.

User Impact

Operators can run long embedded OpenAI Responses sessions through server-side compaction and continue across later turns, worker transcript commits, and Gateway restarts without losing the server's compressed history. The state remains internal and opaque rather than appearing in chat history or diagnostics.

If a provider rejects a replayed compaction item, encrypted-content recovery now persists a route-fenced suppression tombstone only after attributable successful recovery. A reasoning-only rejection cannot suppress valid compaction, a foreign-route tombstone cannot hide compatible replay, and an oversized opaque replay cannot turn otherwise successful worker inference into a terminal error.

Both explicit runtime recipes now share this policy:

  • Provider total window: 1,050,000 tokens
  • Maximum output reserve: 128,000 tokens
  • Embedded OpenClaw active input: 922,000 tokens
  • Automatic compaction threshold: 700,000 active tokens
  • Native Codex effective input after its 95% reserve: 875,900 tokens
  • Fast mode maps to OpenAI Priority processing

Pricing warning: OpenAI's current pricing states that GPT-5.5/GPT-5.6 requests above 272,000 input tokens bill the whole request at 2x input/cache and 1.5x output rates, while Fast/Priority is another 2x tier. Combined long-context Priority traffic is therefore 4x short-context Standard input-side pricing and 3x short-context Standard output pricing. The live suites are deliberately opt-in and expensive.

Upstream contracts checked:

Evidence

Full embedded OpenAI Responses proof

  • Prompt tokens: 9,524 -> 295,098 -> 586,562 -> 863,664
  • Observed a first-class encrypted compaction item, persisted it, replayed the exact opaque item, and structurally pruned the replaced prefix
  • Deterministic long response: 5,480 output tokens
  • Gateway restart: 12,081 ms
  • Every request reported Priority service; durable markers survived compaction and restart
  • Full suite: 220.03 seconds

Full native Codex proof

  • Active context: 197,032 -> 377,386 -> 561,957 -> 750,745
  • The next turn automatically compacted to 75,980 active tokens; minimum observed post-compaction snapshot 68,375
  • Persisted compaction count: 1; duration: 2,810 ms
  • Effective window: 875,900 tokens
  • Deterministic long response: 5,442 output tokens
  • Priority service throughout; durable markers and thread identity survived restart
  • Full suite: 401.37 seconds

Deterministic and static proof

  • Final P2 owner proof: 257 tests across replay/provider/prompt-observer, worker schema/projection/client, Gateway inference/transcript commit/redaction, and Gateway replay E2E passed
  • Final public-boundary repair proof: 343 tests across central transcript events, ordinary session accessor/conformance, worker transcript commit, plugin runtime/session transcript facade, and display/history/cache redaction passed
  • Public transcript listeners omit only the top-level opaque providerReplay; internal listeners and persisted ordinary/worker messages retain it, with source and nested object identity preserved and no source mutation
  • Native staged-recovery proof: 13/13 fault-injection regressions use the real request builder and replay selector across SSE and WebSocket, covering reasoning-first recovery, attributable compaction suppression, final failure, abort, unrelated errors, observer/fetch exceptions, post-start errors, socket reacquisition, compressed SSE bodies, prompt variants, and automatic WebSocket-to-SSE carry-over
  • Canonical Azure recovery proof: the Azure transport uses the same staged recovery owner; a focused regression proves rejected compaction recovery, route-fenced suppression after success, omission on the next turn, and prompt variants initial -> compaction-stripped -> initial. The Azure follow-up matrix passed 143 tests across two shards
  • Final native/replay sibling matrix: 271 tests passed across package unit, agents-core, and Gateway replay E2E shards
  • Staged retry regressions cover mixed reasoning+compaction recovery, attributable compaction rejection, reasoning-only and compaction-only recovery, unrelated/final failures, post-stream errors, observer ordering, and same-route suppression
  • Terminal-order regressions cover compaction before already-streamed output, between completed outputs, after output, and across collapsed message snapshots; conversion re-injects at the asserted normalized boundary
  • Worker-budget regressions cover exact 48 KiB and +1 schema boundaries, multibyte and escaped content, schema-valid large IDs, maximum frame-safe projection, redacted omission diagnostics, and terminal-to-commit success
  • Final post-rebase focused Vitest before this repair: 18 files across 9 shards, 489 tests passed
  • Post-rebase Codex service-tier table: 4 passed, 119 unrelated cases skipped
  • Mock terminal-event typing repair: focused Gateway replay E2E passed 1/1
  • Rejected-replay lifecycle repair: successful fallback then next-turn regression passed; 156 focused replay/lifecycle/redaction tests passed
  • Route-scoped suppression regression: both Responses converters ignored a newer foreign-route tombstone, replayed the older compatible compaction, and pruned its replaced prefix
  • Plugin SDK API baseline and surface checks passed
  • Full protocol registry/generation/Swift/Kotlin/since check passed with no generated drift
  • Targeted Oxfmt and Oxlint passed; production and package-test typechecks passed
  • pnpm build passed in 3m39s before publication
  • git diff --check passed
  • Fresh Azure recovery Codex autoreview: no accepted/actionable findings, patch correct, 0.98 confidence; staged-recovery review clean at 0.97 and earlier full-branch/focused reviews clean at 0.98/0.99; TruffleHog clean

Proof gaps: the paid live suites ran before the conflict-free rebase and were intentionally not repeated. The standalone packed-package consumer E2E was attempted twice locally: one run timed out its isolated consumer typecheck at 180 seconds and the second reached the suite's 300-second ceiling, with no assertion or code failure. Exact-head hosted CI remains the package-boundary and broad check/lint/build/type authority for the final head.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling extensions: codex labels Aug 8, 2026
@steipete
steipete marked this pull request as ready for review August 8, 2026 04:14
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR scripts Repository scripts labels Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 2:50 PM ET / 18:50 UTC.

ClawSweeper review

What this changes

This PR persists opaque OpenAI Responses compaction state across compatible turns, worker transcripts, and Gateway restarts while removing it from public display and diagnostic payloads.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this maintainer-owned PR open. The prior worker-replay omission blocker is repaired, but merge readiness still needs a maintainer decision on exact-head external-provider proof and the required direct Codex source audit.

Priority: P1
Reviewed head: d0510aed9c04614445638dc1ec361e20cda68cff
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has strong source and CI coverage, while independent exact-head external-provider and Codex-contract evidence remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate, but its supplied paid live runs predate the final head and do not replace the required exact-head external-contract validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate, but its supplied paid live runs predate the final head and do not replace the required exact-head external-contract validation.
Evidence reviewed 5 items Prior finding repaired: Both worker launch and terminal projection paths now report whole-replay omission through redacted payload.large diagnostics while preserving inference success; focused tests cover the launch and terminal paths.
Worker boundary: Replay projection checks raw replay size and the complete transcript-commit frame before retaining the optional replay field, preventing oversized ciphertext from invalidating a worker frame.
Persistence and privacy boundary: Transcript sanitization retains only route-fenced valid OpenAI Responses replay state, while public transcript updates strip providerReplay before delivery.
Findings None None.
Security None None.

How this fits together

Responses transports convert session transcripts into provider requests, then Gateway and worker paths persist the resulting messages. The PR carries provider-owned compaction state through that flow so compatible future requests can resume server-compressed history without exposing ciphertext to users.

flowchart LR
  A[Session transcript] --> B[Responses transport]
  B --> C[Compaction replay state]
  C --> D[Gateway and worker transcript]
  D --> E[Compatibility and redaction checks]
  E --> F[Next OpenAI Responses request]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned replay change be rebased and held for direct Codex-source and exact-head authenticated Responses proof before merge? Rebase and reprove: Refresh against current main, inspect the sibling Codex contract directly, and record an exact-head authenticated Responses compaction/restart result before merge.

Why: The patch is source-coherent, but repository policy requires direct Codex inspection for this Codex-backed behavior and the available live proof predates the final head.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main; GitHub reports it cleanly mergeable, but the merged result still needs an exact-head rebase/refresh review.
  • Resolve merge risk (P1) - The direct Codex source audit and exact-head authenticated Responses restart proof are unavailable, leaving external contract and live-provider behavior unverified.
  • Complete next step (P2) - A maintainer must decide whether the remaining direct-Codex and exact-head external-proof gap is closed before merge.
Agent review details

Security

None.

PR surface

Source +906, Tests +5219, Docs +152, Other +3. Total +6280 across 62 files.

View PR surface stats
Area Files Added Removed Net
Source 30 1189 283 +906
Tests 27 5321 102 +5219
Docs 3 221 69 +152
Config 0 0 0 0
Generated 0 0 0 0
Other 2 5 2 +3
Total 62 6736 456 +6280

Review metrics

Metric Value Why it matters
Production and test delta production +1,193/-284; tests +5,322/-103; docs +221/-69 The substantial production growth is tied to provider replay, persistence, retry attribution, frame safety, and redaction boundaries, so merge review should confirm those contracts together.

Stored data model

Persistent data-model change detected: durable storage schema: packages/gateway-protocol/src/schema/worker-admission.test.ts, durable storage schema: packages/gateway-protocol/src/schema/worker-admission.ts, durable storage schema: packages/gateway-protocol/src/schema/worker-inference.ts, durable storage schema: src/gateway/worker-environments/inference-runtime.test.ts, durable storage schema: src/gateway/worker-environments/inference-runtime.ts, durable storage schema: src/gateway/worker-environments/inference-terminal-message.ts, and 29 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh external proof before merge (recommended)
    Rebase the branch and obtain direct Codex-contract inspection plus an exact-head authenticated Responses compaction/restart trace.
  2. Accept the evidence gap
    A maintainer may merge based on the extensive source and CI evidence while explicitly accepting that the final head lacks independent live-provider proof.

Technical review

Best possible solution:

Retain the transport-owned replay design, rebase onto current main, and merge only after direct Codex contract inspection plus exact-head authenticated compaction/restart evidence confirm the documented behavior.

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

No live current-head reproduction was independently run in this read-only review; the added Gateway E2E and focused worker tests provide a clear source-level reproduction path.

Is this the best way to solve the issue?

Unclear for merge readiness: the owner boundary and prior-finding repair are sound in source, but direct Codex-contract inspection and exact-head external-provider proof remain required.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate, but its supplied paid live runs predate the final head and do not replace the required exact-head external-contract validation.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A failure can silently lose authoritative context in long-running OpenAI Responses sessions.
  • merge-risk: 🚨 session-state: The patch writes, retains, and replays opaque session state through Gateway and worker transcript boundaries.
  • merge-risk: 🚨 auth-provider: Replay eligibility and recovery are fenced by provider route, model, session, and authentication identity.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate, but its supplied paid live runs predate the final head and do not replace the required exact-head external-contract validation.

Evidence

What I checked:

  • Prior finding repaired: Both worker launch and terminal projection paths now report whole-replay omission through redacted payload.large diagnostics while preserving inference success; focused tests cover the launch and terminal paths. (src/gateway/worker-environments/inference-runtime.ts:771, d0510aed9c04)
  • Worker boundary: Replay projection checks raw replay size and the complete transcript-commit frame before retaining the optional replay field, preventing oversized ciphertext from invalidating a worker frame. (src/worker/transcript-message.ts:47, d0510aed9c04)
  • Persistence and privacy boundary: Transcript sanitization retains only route-fenced valid OpenAI Responses replay state, while public transcript updates strip providerReplay before delivery. (src/agents/transcript-redact.ts:280, d0510aed9c04)
  • Current-main necessity: Current main 82f6280 does not contain the new compaction replay symbols, so the central behavior is not already implemented or released. (packages/ai/src/transports/openai-responses-compaction-replay.ts:30, d0510aed9c04)
  • Codex contract gap: The required sibling ../codex checkout was absent and network resolution prevented obtaining it, so the direct Codex compaction/catalog contract was not independently verified.

Likely related people:

  • steipete: All supplied commits for the replay repair, including the latest persistence-boundary hardening, are attributed to steipete; related current-main transport history also points to this area. (role: recent area contributor; confidence: high; commits: f536c07ba8fb, e2179acd8f81, d0510aed9c04; files: packages/ai/src/transports/openai-responses-compaction-replay.ts, src/worker/transcript-message.ts)

Rank-up moves

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

  • Rebase onto current main and repeat the authenticated compaction/restart proof on that head.
  • Inspect the matching sibling Codex source before making a merge or proof-sufficiency decision.

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 (7 earlier review cycles)
  • reviewed 2026-08-08T04:48:39.525Z sha 5fc5d69 :: found issues before merge. :: [P2] Invalidate rejected persisted compaction state
  • reviewed 2026-08-08T05:50:07.237Z sha f414883 :: needs changes before merge. :: [P2] Fence suppression tombstones by replay identity
  • reviewed 2026-08-08T07:42:37.243Z sha f3c09a7 :: found issues before merge. :: [P2] Fence suppression tombstones by replay identity | [P2] Avoid tombstoning compaction after an ambiguous encrypted retry
  • reviewed 2026-08-08T13:48:34.072Z sha 3e6cd3b :: needs changes before merge. :: [P2] Persist suppression only after retry recovery
  • reviewed 2026-08-08T15:47:27.155Z sha 20244ef :: found issues before merge. :: [P1] Recover rejected compaction on ChatGPT transports
  • reviewed 2026-08-08T16:42:37.134Z sha 85fc0f4 :: found issues before merge. :: [P1] Route canonical Azure Responses through staged recovery
  • reviewed 2026-08-08T18:41:58.764Z sha d0510ae :: needs changes before merge. :: [P2] Report embedded-worker replay omissions

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 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 repository_dispatch).
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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 8, 2026
Persist opaque Responses compaction items as fenced provider replay state so long stateless sessions can resume authoritative compressed history without exposing it in display or diagnostics. Carry state through worker transcripts and prune replay prefixes without splitting tool pairs.

Release note: Preserve long OpenAI Responses sessions across server-side compaction and worker restarts.

Related: #95788
Make tool-result fixtures type-complete, use the canonical model selector helper, remove unused test-helper exports, and route the paid long-context live probe through the dedicated Gateway profile shard.
Give the mock SSE event collection an explicit open event shape so terminal response events coexist with output-item events under the root test typecheck.
Persist a route-fenced suppression tombstone when encrypted-content recovery rejects a compaction item, so later turns do not retry the same opaque state. Preserve the tombstone through transcript redaction and cover successful fallback followed by the next turn.
Keep the suppression contract local to its sole Responses transport owner and make the regression fixture satisfy root type and lint checks without widening the Plugin SDK surface.
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Use the shared encrypted-content retry owner for Azure Responses so compaction suppression and prompt-observer variants stay coherent across transports.
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Fence Azure replay by the resolved request endpoint, drop invalid replay during transcript sanitization, and surface worker-launch replay omissions through the existing redacted diagnostic path.
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 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 repository_dispatch).
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 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 8, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

ClawSweeper rank-up disposition for d0510aed9c04614445638dc1ec361e20cda68cff:

  • Direct sibling Codex source inspection was completed by the acting agent against openai/codex@c2bcb9a26b5b; the PR body cites the inspected compaction item, 95% effective-window catalog behavior, pre-turn auto-compaction, remote v2 compaction, and model-catalog symbols with exact source links.
  • The paid authenticated compaction/restart suites are not repeated on this head by explicit maintainer instruction. Their prior successful metrics remain documented honestly; the final head instead has 226 focused non-paid tests, clean type/lint/autoreview proof, and green exact-head hosted CI.
  • Current-main drift is advisory: GitHub reports the PR mergeable and the repository exact-head CI run is green. I am not rebasing solely to chase drift after that completed gate.

No actionable ClawSweeper finding remains. The maintainer accepts the explicitly documented live-proof timing gap for this landing.

@steipete
steipete merged commit 47f78a3 into main Aug 8, 2026
128 checks passed
@steipete
steipete deleted the steipete/clawstudio-1m-context-configuration-79869f branch August 8, 2026 18:55
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to IsaiahStapleton/openclaw that referenced this pull request Aug 8, 2026
…0807

* origin/main:
  fix(qa): honor Crabbox SSH fallback ports (openclaw#120539)
  refactor(core): adopt normalization-core leaf helpers across production (openclaw#120350)
  fix(release): scope upgrade plugin credentials (openclaw#120666)
  fix(ai): preserve long Responses sessions after server compaction (openclaw#120457)
  fix(test): keep fork E2E setup builds observable (openclaw#120653)
  fix(cloud-workers): retain provider operation ownership (openclaw#120661)
  docs: runners plan — one placement model for sessions, devices, and cloud (openclaw#120657)
  refactor(cli): inline state migration policy (openclaw#120641)
  feat(update): scheduled update campaigns with countdown, dev-channel auto-update, and Updates settings page (openclaw#120506)
  chore(i18n): refresh native locales (openclaw#120614)
  fix(ci): retry transient artifact API reads (openclaw#120654)
  fix(clawrouter): honor advertised reasoning efforts (openclaw#120631)
  fix(infra): unify env-truthiness, missing-path, realpath, and abort-sleep semantics (openclaw#120359)
  fix(maintainers): parse merge comment URL structurally (openclaw#120649)
  fix(ui): label only operator-pinned runtimes in model picker rows (openclaw#120646)
  docs(agents): replace exact-head re-review gate with 12-hour review window

# Conflicts:
#	src/agents/payload-redaction.ts
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
…enclaw#120457)

* fix(ai): preserve Responses server compaction state

Persist opaque Responses compaction items as fenced provider replay state so long stateless sessions can resume authoritative compressed history without exposing it in display or diagnostics. Carry state through worker transcripts and prune replay prefixes without splitting tool pairs.

Release note: Preserve long OpenAI Responses sessions across server-side compaction and worker restarts.

Related: openclaw#95788

* test(ai): align long-context fixtures with CI contracts

Make tool-result fixtures type-complete, use the canonical model selector helper, remove unused test-helper exports, and route the paid long-context live probe through the dedicated Gateway profile shard.

* test(ai): type mocked Responses terminal events

Give the mock SSE event collection an explicit open event shape so terminal response events coexist with output-item events under the root test typecheck.

* fix(ai): suppress rejected compaction replay

Persist a route-fenced suppression tombstone when encrypted-content recovery rejects a compaction item, so later turns do not retry the same opaque state. Preserve the tombstone through transcript redaction and cover successful fallback followed by the next turn.

* fix(ai): keep compaction suppression transport-private

Keep the suppression contract local to its sole Responses transport owner and make the regression fixture satisfy root type and lint checks without widening the Plugin SDK surface.

* refactor(ai): remove compaction suppression re-export

* fix(ai): scope compaction suppression to replay route

Keep foreign-route rejection tombstones from hiding the newest compatible Responses compaction while preserving same-route suppression.

* fix(ai): harden Responses replay recovery

Stage encrypted replay recovery so compaction is only suppressed after an attributable rejection. Preserve terminal ordering and keep provider replay within worker frame budgets without truncating opaque state.

* refactor(ai): centralize Responses output indexes

Keep normalized output identity tracking in the stream-slot owner, move response failure state to its diagnostic owner, and remove the obsolete replay clone export so exact-head static gates remain shrink-only.

* fix(ai): retain idless terminal tool identity

Use the canonical empty identity only when a provider supplies neither call nor item id, preventing terminal recovery from duplicating a done-only tool call while preserving stronger identities when available.

* fix(sessions): hide provider replay from public events

* fix(ai): stage encrypted replay recovery

* fix(ai): keep replay attempt kind internal

* fix(ai): route Azure through replay recovery

Use the shared encrypted-content retry owner for Azure Responses so compaction suppression and prompt-observer variants stay coherent across transports.

* fix(ai): harden replay persistence boundaries

Fence Azure replay by the resolved request endpoint, drop invalid replay during transcript sanitization, and surface worker-launch replay omissions through the existing redacted diagnostic path.
obviyus added a commit that referenced this pull request Nov 16, 2026
## Problem

Long OpenAI Responses sessions lost their server compaction checkpoint and fell back to client summarization, even though the provider had compacted the session.

The replay identity fence for compaction and encrypted reasoning items included the auth profile hash. One OpenAI key can reach a session two ways: through an auth profile (`openai:*`) or through `models.providers.openai.apiKey`. When runs alternate between those two sources, the fence rejects the session's own checkpoints. The next request then resends the full raw history (about 1M tokens on the affected host) and client summarization runs. In the reported incident, that summarization was refused, which left the session with no summary.

This was observed in production on one host where both sources hold the same key; four sessions were affected. The fence was added in #120457 and moved in #135727.

## Fix

- The replay identity is now session plus model route only. `authProfileHash` and `authProfileId` are removed from the replay context, the compaction and reasoning replay builders, the context-usage meter, and every provider, transport and agent call site.
- A checkpoint from a different org is still rejected by the server (`invalid_encrypted_content` / `item_conflict`). The existing recovery in `openai-responses-replay-internal.ts` already handles that.
- Checkpoints saved with a legacy `authProfileHash` still replay. No migration is needed.

Net change: 32 files, +42 −77 (tests that asserted the credential-source fence are removed).

## Evidence

**Regression test:** `provider-compaction-replay.test.ts` › "counts the returned prefix once after restart, including checkpoints with a legacy auth hash". It fails on base and passes with the fix.

**Real-model E2E** (isolated state, `openai/gpt-5.4-mini`, server compaction threshold 12k):
- Setup: three seed turns run through an auth profile only. The final turn runs with the config `apiKey` present, which takes precedence. It is the same key, so only the credential source changes.
- Request shapes come from `OPENCLAW_DEBUG_MODEL_PAYLOAD=summary`.

| arm | final-turn request | items | text chars | answer |
| --- | --- | --- | --- | --- |
| base `7f234bd` | `message×N, reasoning…`; `compactionItems=0` | 12 | 113,498 | correct |
| fix | `compaction, message:user, message:developer`; `compactionItems=1` | 3 | 758 | correct |

Base drops the checkpoint and the encrypted reasoning items and resends the full transcript. With the fix, the same checkpoint replays across the credential switch. At production scale, the same flip on a copy of a real session measured 331k tokens with a matching identity versus 900k with only the auth profile changed.

**Checks:**
- `pnpm check:changed` is green.
- Every replay test file that used the credential-source fence is updated. The changed test files pass (153/154; the remaining case needs `--expose-gc`).
- The full `packages/ai/src/transports` run shows 7 failures. The same 7 fail on base under the same invocation. They are the GC retention fixtures that need `--expose-gc`, plus two order-dependent tests that pass when run alone.

## Follow-up

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

<!-- openclaw-publication:4ab5fa4d-c2cc-4079-99d9-55f7c6a888a9 -->

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

## Problem

Long OpenAI Responses sessions lost their server compaction checkpoint and fell back to client summarization, even though the provider had compacted the session.

The replay identity fence for compaction and encrypted reasoning items included the auth profile hash. One OpenAI key can reach a session two ways: through an auth profile (`openai:*`) or through `models.providers.openai.apiKey`. When runs alternate between those two sources, the fence rejects the session's own checkpoints. The next request then resends the full raw history (about 1M tokens on the affected host) and client summarization runs. In the reported incident, that summarization was refused, which left the session with no summary.

This was observed in production on one host where both sources hold the same key; four sessions were affected. The fence was added in openclaw#120457 and moved in openclaw#135727.

## Fix

- The replay identity is now session plus model route only. `authProfileHash` and `authProfileId` are removed from the replay context, the compaction and reasoning replay builders, the context-usage meter, and every provider, transport and agent call site.
- A checkpoint from a different org is still rejected by the server (`invalid_encrypted_content` / `item_conflict`). The existing recovery in `openai-responses-replay-internal.ts` already handles that.
- Checkpoints saved with a legacy `authProfileHash` still replay. No migration is needed.

Net change: 32 files, +42 −77 (tests that asserted the credential-source fence are removed).

## Evidence

**Regression test:** `provider-compaction-replay.test.ts` › "counts the returned prefix once after restart, including checkpoints with a legacy auth hash". It fails on base and passes with the fix.

**Real-model E2E** (isolated state, `openai/gpt-5.4-mini`, server compaction threshold 12k):
- Setup: three seed turns run through an auth profile only. The final turn runs with the config `apiKey` present, which takes precedence. It is the same key, so only the credential source changes.
- Request shapes come from `OPENCLAW_DEBUG_MODEL_PAYLOAD=summary`.

| arm | final-turn request | items | text chars | answer |
| --- | --- | --- | --- | --- |
| base `e263be2` | `message×N, reasoning…`; `compactionItems=0` | 12 | 113,498 | correct |
| fix | `compaction, message:user, message:developer`; `compactionItems=1` | 3 | 758 | correct |

Base drops the checkpoint and the encrypted reasoning items and resends the full transcript. With the fix, the same checkpoint replays across the credential switch. At production scale, the same flip on a copy of a real session measured 331k tokens with a matching identity versus 900k with only the auth profile changed.

**Checks:**
- `pnpm check:changed` is green.
- Every replay test file that used the credential-source fence is updated. The changed test files pass (153/154; the remaining case needs `--expose-gc`).
- The full `packages/ai/src/transports` run shows 7 failures. The same 7 fail on base under the same invocation. They are the GC retention fixtures that need `--expose-gc`, plus two order-dependent tests that pass when run alone.

## Follow-up

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

<!-- openclaw-publication:4ab5fa4d-c2cc-4079-99d9-55f7c6a888a9 -->

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 app: web-ui App: web-ui docs Improvements or additions to documentation extensions: codex extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts 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