Skip to content

fix(ai): prevent stale replay after context rewrites - #120786

Merged
steipete merged 1 commit into
mainfrom
steipete/zealous-thompson-7671a1
Aug 9, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/zealous-thompson-7671a1

Conversation

@steipete

@steipete steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users whose session transcripts were compacted, reset, truncated, or branch-rewritten could retain an OpenAI Responses compaction checkpoint tied to the old transcript prefix. Replaying that stale checkpoint after the prefix changed could send provider state that no longer matched the active conversation.

Why This Change Was Made

Compaction checkpoints are prefix-owned state, while route-scoped suppression tombstones are independent replay policy. This change puts invalidation at the provider-owned replay boundary: a pure helper removes only the exact openai-responses-compaction checkpoint and preserves suppression tombstones and unrelated replay state.

Transcript branch rewrites apply that invalidation to every message re-appended at or after the first changed entry. Local/Pi compaction and reset apply it only to retained pre-boundary messages, preserving post-boundary checkpoints. There are no schema, protocol, storage, config, docs, or changelog changes.

User Impact

Session repair and context rewriting no longer carry stale OpenAI Responses compaction checkpoints into a changed conversation. Valid route suppression state and checkpoints created after the rewrite boundary continue to work unchanged.

Release-note context: fixes stale OpenAI Responses compaction replay after transcript truncation, compaction, reset, or branch rewriting.

Evidence

  • Focused regression suite after rebasing onto current origin/main: 4 files, 111 tests passed across 2 Vitest shards.
    • node scripts/run-vitest.mjs packages/agent-core/src/harness/session/session-context.test.ts packages/ai/src/transports/openai-responses-compaction-replay.test.ts src/agents/embedded-agent-runner/tool-result-truncation.test.ts src/agents/embedded-agent-runner/transcript-rewrite.test.ts
  • Tests cover exact checkpoint stripping, structural sharing, suppression and unrelated replay preservation, real tool-result truncation, local/Pi compaction, reset, and transcript branch rewriting.
  • Full changed-file gate passed locally: formatting, Plugin SDK API contract, core and test typechecks, targeted lint, dead exports, plugin boundaries, import cycles, state/schema guards, and all other planned core/coreTests checks.
  • The configured remote backend was unavailable, so the trusted-source fallback policy was used for the full changed-file local gate.
  • Codex autoreview in --mode uncommitted exited clean with no accepted/actionable findings.
  • git diff --check passed before commit and again after rebase.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 00:15
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 93f3d17ddda0a33115e1422dfc8c19d3addfb9fd.

The provider-owned repair removes only exact openai-responses-compaction checkpoints after a transcript prefix changes. Route-scoped suppression tombstones and unrelated replay state survive. Local/Pi compaction and reset strip retained pre-boundary checkpoints only; transcript branch rewrites strip checkpoints from every message re-appended at or after the changed boundary.

Exact commands run on the rebased head:

node scripts/run-vitest.mjs packages/agent-core/src/harness/session/session-context.test.ts packages/ai/src/transports/openai-responses-compaction-replay.test.ts src/agents/embedded-agent-runner/tool-result-truncation.test.ts src/agents/embedded-agent-runner/transcript-rewrite.test.ts
git diff --check origin/main...HEAD
node scripts/watch-pr-ci.mjs 120786 93f3d17ddda0a33115e1422dfc8c19d3addfb9fd
scripts/pr review-init 120786
scripts/pr review-checkout-main 120786
scripts/pr review-checkout-pr 120786
scripts/pr review-artifacts-init 120786
scripts/pr review-guard 120786
scripts/pr review-validate-artifacts 120786

Results:

  • Focused regression proof: 4 files, 111 tests passed across 2 Vitest shards.
  • git diff --check: passed after rebase.
  • Native review artifacts: validated in PR-head mode with READY FOR /prepare-pr, issueValidation.status=valid, behavioral sweep passed, and 0 findings.
  • Production LOC: +49/-7 (net +42); tests: +152/-30 (net +122). Production growth establishes the canonical provider-owned invalidation helper and applies it at the two transcript-prefix rewrite owners.
  • Exact-head hosted CI: Actions run 31285794639, attempt 1, pull_request, success. Final openclaw/ci-gate job 93175108236 passed. The repository watcher emitted GREEN with zero pending checks.
  • Coordinator-reported full changed-file local fallback gate: passed formatting, Plugin SDK API contract, core/test typechecks, targeted lint, dead exports, plugin boundaries, import cycles, state/schema guards, and every planned core/coreTests check.
  • Coordinator-reported Codex autoreview --mode uncommitted: clean, with no accepted/actionable findings.
  • ClawSweeper disposition as of 2026-08-09T00:27:06Z: no durable PR comment or review has published, so no rating or Rank-up moves: exist to apply or skip. Repository policy says not to block landing on a queued or absent publisher when exact-head CI and the other gates are satisfied.

Known proof gaps:

  • The coordinator handoff did not preserve the literal changed-gate invocation, remote-backend error, or backend identifier. The configured remote backend was unavailable, so trusted-source policy used the complete local fallback reported above.
  • The coordinator handoff preserved autoreview mode and result but not the literal executable invocation.
  • No separate Testbox lease identifier was emitted; exact-head hosted CI run 31285794639 is the fresh hosted proof used by the landing workflow.
  • No live provider call was run. This is deterministic local replay-state projection, covered at the provider, session, real tool-result truncation, compaction/reset, and transcript-rewrite boundaries.
  • No schema, protocol, storage, config, docs, or changelog changes.

@steipete
steipete merged commit 56cdad5 into main Aug 9, 2026
180 checks passed
@steipete
steipete deleted the steipete/zealous-thompson-7671a1 branch August 9, 2026 00:29
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 9, 2026
Punchcard-Session: amber-workshop-workshop-36

* origin/main: (28 commits)
  perf(doctor): keep bundled doctor contract closures dependency-light (#120698)
  fix(elevenlabs): preserve repeated committed speech segments (#120792)
  fix(ai): fence Responses replay metadata (#120777)
  fix(ai): invalidate stale compaction replay (#120786)
  fix(telegram): clean up every failed webhook startup phase (#120788)
  fix(codex): preserve configured MCP tools in scheduled turns (#120366)
  fix(ui): show dev checkout commit lag in Updates (#120769)
  fix(agents): repair XML-polluted tool names (#113814)
  fix(discord): remove only the bot own reactions (#120785)
  fix(macos): complete ChatGPT subscription setup (#120782)
  fix(plugins): surface safe administrator install warnings (#120783)
  fix(release): keep upgrade survivor sessions fresh (#120778)
  fix(providers): preserve realtime tool-result delivery ownership (#120776)
  fix(plugins): retain incognito scope for embedded session ownership (#120215)
  fix(elevenlabs): surface realtime provider error events (#120772)
  fix(agents): preserve exact steering delivery ownership (#120770)
  fix(telegram): prevent session-count routing slowdown (#120774)
  fix(agents): preserve authoritative background process outcomes (#120754)
  test(process): make Linux adapter wiring portable (#120741)
  fix(diagnostics-prometheus): send Content-Length on metrics HEAD responses (#120212)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant