Skip to content

fix(bedrock): keep prompt cache checkpoints on conversation history - #140797

Merged
steipete merged 2 commits into
mainfrom
kv/bedrock-prompt-cache-checkpoints
Sep 7, 2026
Merged

steipete merged 2 commits into
mainfrom
kv/bedrock-prompt-cache-checkpoints

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

Maintainers can update this branch in the repository.

What Problem This Solves

Fixes an issue where users running Claude through Amazon Bedrock Converse would lose conversation prompt caching after retained runtime context was merged into the first user message. Conversation history, including subsequent tool loops, received no cache checkpoint.

Bedrock and Bedrock Mantle also cached the entire system prompt as one block, so a date rollover or other dynamic runtime change invalidated the stable workspace prefix.

Why This Change Was Made

Retained, append-only runtime-context carriers now remain stable conversation anchors; only transient carriers impose the checkpoint cutoff, and checkpoints advance through tool results. Provider registrations can opt into supportsSystemPromptCacheBoundary, allowing Bedrock and Mantle to consume the existing system boundary and checkpoint the stable prefix separately from dynamic additions. Other custom transports retain boundary stripping by default.

Application-profile fallback injection respects the split and preserves runtime-owned checkpoints. Opaque profiles with transient carriers conservatively retain only the system checkpoint. No operator configuration, schema, persistent-store, or dependency changes are introduced.

User Impact

Bedrock Claude conversations can reuse retained history across turns and tool loops. Bedrock and Mantle can preserve the stable system prefix when dynamic runtime facts change. Disabled caching, transient-context exclusion, thinking signatures, and role merging retain their existing behavior.

The SDK opt-in is documented in docs/plugins/sdk-provider-plugins.md; provider behavior is documented in docs/reference/prompt-caching.md.

Evidence

  • Focused proof: node scripts/run-vitest.mjs extensions/amazon-bedrock extensions/amazon-bedrock-mantle src/agents/embedded-agent-runner/stream-resolution.test.ts src/agents/embedded-agent-runner/run/attempt.test.ts src/plugins/provider-runtime.test.ts — 18 files, 590 tests passed across four shards in the implementation run. The fresh publication sanity run also passed all 590 tests in 18 files across four shards (148.22 seconds).
  • After the final test-fixture type correction, stream-resolution.test.ts passed all 47 tests; all four typecheck lanes subsequently passed. Production code did not change after the successful build.
  • pnpm build passed, including runtime, package/SDK declarations, export checks, and UI build.
  • Codex autoreview of the exact staged patch: scoped-clean, 0 accepted/actionable P0/P1 findings. Publication verified byte-for-byte equality with the reviewed patch.
  • Before the fix, payload/profile coverage produced seven expected regression failures; registered-stream coverage produced three expected failures. They exercised missing conversation checkpoints, stripped system boundaries, and profile injection.
  • Local check:changed passed every gate through core lint: formatting, ratchets, imports and SDK guards, declaration checks, all four typecheck lanes, and three dead-export scans (zero findings). It stopped at extension-lint artifact preparation with Declaration input escapes checkout ... qrcode, caused by this nested worktree's ancestor installation. The declaration-boundary guard is unchanged. Fresh-checkout CI's extension lint lane is the authoritative remaining proof; later local gates were not reached.
  • Payload coverage exercises the actual Converse and Anthropic Messages builders, both plugin registrations, retained/transient carriers, advancing tool-loop checkpoints, stable-prefix bytes, marker removal, disabled caching, and one-hour TTL. No authenticated live AWS requests or cache-hit billing measurements were made.
  • git diff --cached --check passed.
  • Diff: 16 files, +532/-119; production +91/-57, tests +432/-62, docs +9/-0.

CI follow-up: the first ready-state run reached extension lint and found two missing-brace errors in the changed checkpoint test. A follow-up commit adds those braces; targeted lint, formatting, all 20 tests in that file, and fresh Codex autoreview (0 actionable P0/P1 findings) passed. The same run's check-guards failed independently during Matrix native dependency installation (ECONNRESET, followed by an installer ReferenceError), before guards executed. No dependency or guard changes were made. The follow-up exact-head CI result is recorded below.

Final CI: run 34084194236 completed successfully for 9f51c58878faf022d81cd497f62109240a52f924: 108 successful jobs, 16 intentional skips, zero failed jobs. check-lint (including extension lint) and check-guards both passed. The bounded exact-head watcher terminated GREEN (exit 0), reconciling superseded checks, including the stale cancelled Labeler status. The earlier watcher terminated FAILING checks=check-guards (exit 15); its source-related lint findings were fixed as described above.

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review September 7, 2026 04:38
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: amazon-bedrock extensions: amazon-bedrock-mantle size: L maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 12:58 AM ET / 04:58 UTC.

ClawSweeper review

What this changes

Restore Bedrock conversation cache checkpoints and let Bedrock and Mantle cache stable system instructions separately from changing runtime context.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: inspected main still has the reported checkpoint behavior, and no introduced correctness defect was found. The earlier unmeasured AWS billing observation does not establish an additional merge blocker.

Priority: P2
Reviewed head: 9f51c58878faf022d81cd497f62109240a52f924

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful boundary coverage, reported successful validation, and no actionable correctness findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER association exempts this maintainer-authored PR from the external-contributor proof gate. Inspected tests exercise registered Bedrock/Mantle payload builders, but stop or mock network I/O; live AWS cache acceptance and billing remain unmeasured.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER association exempts this maintainer-authored PR from the external-contributor proof gate. Inspected tests exercise registered Bedrock/Mantle payload builders, but stop or mock network I/O; live AWS cache acceptance and billing remain unmeasured.
Evidence reviewed 9 items Pinned change and review continuity: Reviewed the merge-base-to-head changes at 9f51c58. The previous completed review used this same head and recorded no findings. The supplied test merge has stale parents and was not used to infer removal of main-branch behavior.
Main still contains the reported mechanism: At fetched main, every runtime-context carrier establishes the volatile cutoff, including retained carriers; the system builder still emits one system text block. The requested repair therefore remains relevant.
Retained-context ownership: The new checkpoint predicate uses the same model-contract helper that existing replay policy uses to select append-only runtime context. Prompt submission already queues that context with the user turn; this patch changes request checkpoint placement rather than persisted transcript semantics.
Findings None None.
Security None None.

How this fits together

The agent runner supplies system instructions and conversation history to provider plugins. Bedrock and Mantle convert that context into provider requests, placing checkpoints that determine which prompt prefixes can be reused.

flowchart TD
  A[System instructions] --> C[Provider stream registration]
  B[Conversation history] --> C
  C --> D{Boundary support enabled}
  D -->|No| E[Strip internal marker]
  D -->|Yes| F[Separate stable and dynamic context]
  F --> G[Place eligible cache checkpoints]
  E --> H[Provider request]
  G --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +34, Tests +370, Docs +9. Total +413 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 8 91 57 +34
Tests 6 432 62 +370
Docs 2 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 532 119 +413

Review metrics

Metric Value Why it matters
Provider SDK contract 1 optional capability flag and 1 shared helper export The documented opt-in preserves default stripping and avoids a user configuration or migration requirement.

Technical review

Best possible solution:

Keep checkpoint placement in the provider transport, reuse the existing replay classification, and preserve default marker stripping for custom plugins.

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

Yes, from source: retained runtime-context carriers trigger main's volatile cutoff and prevent later conversation checkpoints. The regression fixtures exercise that path; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. The patch repairs the existing transport and registration boundaries, reuses shared cache helpers, and preserves the compatibility default instead of adding a competing caching mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Repairs bounded Bedrock prompt-cache efficiency without evidence of a core outage or lost conversation data.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER association exempts this maintainer-authored PR from the external-contributor proof gate. Inspected tests exercise registered Bedrock/Mantle payload builders, but stop or mock network I/O; live AWS cache acceptance and billing remain unmeasured.

Evidence

What I checked:

  • Pinned change and review continuity: Reviewed the merge-base-to-head changes at 9f51c58. The previous completed review used this same head and recorded no findings. The supplied test merge has stale parents and was not used to infer removal of main-branch behavior. (9f51c58878fa)
  • Main still contains the reported mechanism: At fetched main, every runtime-context carrier establishes the volatile cutoff, including retained carriers; the system builder still emits one system text block. The requested repair therefore remains relevant. (extensions/amazon-bedrock/stream.runtime.ts:1017, abc35e08c1a2)
  • Retained-context ownership: The new checkpoint predicate uses the same model-contract helper that existing replay policy uses to select append-only runtime context. Prompt submission already queues that context with the user turn; this patch changes request checkpoint placement rather than persisted transcript semantics. (src/plugins/provider-replay-helpers.ts:127, 9f51c58878fa)
  • Provider API compatibility: The optional provider capability and shared splitter are explicitly described in the maintainer-authored PR body and SDK docs. Unset and false retain marker stripping; tests exercise both alongside true through registered streams. (src/agents/embedded-agent-runner/stream-resolution.test.ts:274, 9f51c58878fa)
  • Existing transport implementation reused: Mantle delegates to the repository-owned Anthropic transport, which already splits stable and dynamic system blocks. The Bedrock builder reuses the existing boundary helper; this path does not depend on the Codex harness or protocol. (packages/ai/src/providers/anthropic.ts:734, 9f51c58878fa)
  • Behavioral regression coverage: Inspected tests cover advancing retained-history checkpoints through tool results, direct and application-profile routes, stable-prefix bytes, short/long/disabled caching, and exclusion of transient context. Registered transport tests capture actual builders before network I/O; AWS send is mocked in accounting/replay coverage. (extensions/amazon-bedrock/stream.runtime.accounting-replay.test.ts:306, 9f51c58878fa)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • lucascmg-vx: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-07T04:50:55.719Z sha 9f51c58 :: blocked before merge. :: none

@steipete
steipete merged commit 331d6b7 into main Sep 7, 2026
191 of 192 checks passed
@steipete
steipete deleted the kv/bedrock-prompt-cache-checkpoints branch September 7, 2026 05:13
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…penclaw#140797)

* fix(bedrock): keep prompt cache checkpoints on conversation history

* test(bedrock): satisfy checkpoint fixture brace lint
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 20, 2026
…penclaw#140797)

* fix(bedrock): keep prompt cache checkpoints on conversation history

* test(bedrock): satisfy checkpoint fixture brace lint

(cherry picked from commit 331d6b7)
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 extensions: amazon-bedrock extensions: amazon-bedrock-mantle maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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