Skip to content

perf(anthropic): preserve conversation cache checkpoints - #168042

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-prompt-cache-anthropic-20260919
Oct 10, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-prompt-cache-anthropic-20260919

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Anthropic conversation caching could fall back to the system prefix when a new user turn added at least 20 content blocks. Bedrock also omitted supported Haiku 5.5 checkpoints and could request an unsupported one-hour TTL on older Claude models or opaque application profiles.

User Impact

Large document/image turns retain a preceding conversation checkpoint. Bedrock uses the supported retention window of the selected model and resolved profile targets. The five-minute default and existing configuration remain unchanged; no migration is required.

Change

Messages, including Vertex's shared builder, retain recent conversation checkpoints within the four-marker budget. Bedrock carries one resolved cache policy through request construction and profile injection. The rebase preserves main's one-hour model allowlist; forced cache eligibility alone uses five-minute checkpoints. Consolidated overlapping TTL tests without dropping distinct model cases or payload-boundary assertions.

Production LOC delta: -12 (120 additions, 132 deletions, excluding tests and docs). No new dependency, configuration option, schema, or persistent cache.

Evidence and Measurement

  • Synthetic ten-turn conversation reuse: 5/10 → 8/10 on Messages, Vertex and Bedrock; 6/10 → 9/10 on the pinned in-history route. Bedrock modeled writes: 224 → 135 content blocks (-39.7%). Fixtures include paired tools, steering, skill refresh, unchanged MCP tools, and large content batches. These are captured-payload simulations, not live token counters.
  • Blacksmith Testbox tbx_01m4h90vpj5nx96psdfhrzx21t proved the original Messages and Bedrock regressions fail before the fix. During conflict repair, tbx_01m4ka56xrvv7yaeqszw2hcbf5 reproduced the forced-TTL defect, then passed all 34 accounting/replay tests after correction (6.05s Vitest).
  • Rebased final tree c72b109fcf8808e356174642ee9b6fb96aa5fa14 passed 338 focused tests on the isolated Linux rig: 12 core payload, 41 cache parity, and 285 Bedrock/Vertex siblings (59.69s wrapper). This includes every touched test file and the cloud-provider sibling suites.
  • Prior broader proof: 2,367 AI package tests, 5 MCP recovery tests, 20 instruction/history tests, 10 image-cleanup tests, export-collision and both closure guards. The core payload file also passed under Node and Bun 1.4.2.
  • Testbox sync timed out; authorized AWS and Hetzner fallbacks also stalled in sync and were released. Final proof uses the authorized rig with isolated state and exact-tree verification.
  • node scripts/check-changed.mjs --staged --timed completed all typechecks and early guards, then reported one inherited unused export: ui/src/test-helpers/solid-application-context.tsx:hiddenScopeUpgradeCapability. Unchanged base c7a0bc9a9713 reproduces that same finding. The remaining planned lint and boundary commands were run separately and passed; export-collision and both import-closure guards passed (20 tests). A concurrent lint/test setup initially tripped the compiler snapshot guard; serialized reruns passed without source changes. No guard was skipped or weakened.
  • Fresh independent reviews are clean at P0–P2 after the forced-TTL correction and test consolidation. The final rebase preserves all three reviewed patches byte-for-byte (git range-diff).

Live gap: no live cache-probe request executed. Actual cache_creation_input_tokens, cache_read_input_tokens, and cloud hit rates remain unmeasured: 0 provider requests, 0 probe tokens, $0 probe inference cost.

Lane 720's transient-context cache-marker follow-up remains separate.

Provider contracts: Anthropic prefix lookup, AWS cache model/TTL limits.

Current published candidate: d0ad75eb36f96d8403c9d6a175b906f7b40b1b7f. CI run 38080723680 completed successfully on this exact head; required CI gates pass.

@clawsweeper

clawsweeper Bot commented Oct 10, 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 extensions: amazon-bedrock size: L labels Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 00:31
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves two recent conversation cache checkpoints and selects cache lifetimes supported by Bedrock models and resolved application profiles.

Example: A Claude conversation appends a user message containing 21 document blocks after a tool-result checkpoint.

  • Before: The previous tool-result checkpoint disappears, leaving it outside the newest checkpoint’s lookup window.
  • After: Both the previous tool-result checkpoint and the new message’s final block remain marked.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is coherent and source-reviewed without actionable defects, but synthetic payload proof does not establish the changed external provider behavior.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large document or image turns can re-write reusable conversation history, while some Bedrock models and profiles receive missing or unsupported cache checkpoints.
Reason: The source-backed repair has clear billing and reuse value, shrinks production code, and has owner direction under the supplied maintainer-authored-item rule.

Merge readiness

✅ Ready for maintainer review

Keep this PR: current main still lacks its large-append checkpoint repair, and the reviewed patch has no actionable correctness or security findings.

Priority: P2
Reviewed head: d0ad75eb36f96d8403c9d6a175b906f7b40b1b7f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise live large-append cache reuse or Bedrock model/profile TTL acceptance; baseline failures are reported in the body but were not independently rerun.
Agent review details

How this fits together

Anthropic request builders and the Bedrock plugin convert conversation history, model metadata, and retention settings into provider payloads containing cache checkpoints.

flowchart TD
  A[Conversation and retention settings] --> B[Provider request builder]
  B --> C[Anthropic checkpoint allocator]
  B --> D[Bedrock cache policy]
  E[Resolved profile targets] --> D
  C --> F[Serialized provider request]
  D --> F
Loading

Technical review

Best possible solution:

Retain the focused checkpoint and TTL repair, preserving existing retention settings and provider-owned policy.

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

Current-main source removes the previous tool-result checkpoint after a 21-block user append, and the added request-builder regression captures that exact shape; no target code was executed during this review.

Is this the best way to solve the issue?

The repair uses existing request owners, preserves the four-marker budget and Nova opt-in, and carries model-specific TTL policy into profile injection without adding configuration or persistent state.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 89c01cd adds packages/ai/src/transports/anthropic-payload-policy.ts:344 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 89c01cd979ef; files: packages/ai/src/transports/anthropic-payload-policy.ts)
  • Peter Lindsey: Raw commit ca9ab97 adds src/agents/anthropic-payload-policy.ts:163 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ca9ab974270b; files: src/agents/anthropic-payload-policy.ts)
  • Ayaan Zaidi: Raw commit c718afe adds src/agents/anthropic-payload-policy.ts:148 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c718afe24706; files: src/agents/anthropic-payload-policy.ts)
  • anirudhmarc: Raw commit 24266af adds extensions/amazon-bedrock/register.sync.runtime.ts:172 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 24266af1ce1b; files: extensions/amazon-bedrock/register.sync.runtime.ts)

PR surface

Source -12, Tests +83, Docs +8, Other 0. Total +79 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 119 131 -12
Tests 6 292 209 +83
Docs 1 9 1 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 12 421 342 +79

Review metrics

Metric Value Why it matters
Production versus test LOC Production +119/-131; tests +292/-209 Production shrinks by reusing one Bedrock policy; test growth covers large-append reuse, transient boundaries, and distinct model/profile TTL cases.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: The repair reduces avoidable cache writes and fixes limited Bedrock cache eligibility and TTL behavior without changing defaults or stored state.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Capture redacted provider usage and request acceptance for the large-append sequence and Bedrock model/profile TTL cases.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T00:30:59.465Z sha edc7ab4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T00:37:41.911Z sha edc7ab4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T01:26:42.760Z sha 986548c :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T01:52:42.446Z sha 986548c :: needs maintainer review before merge. :: none

Reviewed October 10, 2026, 3:49 PM ET / 19:49 UTC (Revision 5).

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 10, 2026
@steipete
steipete force-pushed the steipete/perf-micro-prompt-cache-anthropic-20260919 branch from 986548c to d0ad75e Compare October 10, 2026 19:40
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 10, 2026
@steipete
steipete merged commit 4895fbb into main Oct 10, 2026
136 checks passed
@steipete
steipete deleted the steipete/perf-micro-prompt-cache-anthropic-20260919 branch October 10, 2026 19:51
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…8042)

Preserve a prior Anthropic conversation checkpoint when a new turn exceeds the provider lookup window. Resolve Bedrock model and application-profile cache eligibility and supported TTL through one policy owner, retaining five-minute defaults and avoiding unsupported one-hour requests.

Synthetic ten-turn conversation reuse improves from 5/10 to 8/10, with modeled Bedrock writes falling 39.7%. Production code is 12 lines smaller. Focused provider tests and required CI pass; actual provider cache-token counters remain unmeasured.
RomneyDa added a commit that referenced this pull request Oct 11, 2026
Keep up to two Anthropic conversation checkpoints so a prior write stays
reachable when a new turn exceeds the provider's 20-block lookback, and
place every conversation checkpoint before transient runtime context
(steering and tool loops after an unretained carrier).

Backport of 4895fbb (#168042) adapted for 2026.10.2:
Anthropic Messages payload policy only; the Bedrock cache-policy
consolidation from that PR is not included.
Also includes the Anthropic checkpoint part of
d13db41 (#168392)
("keep cache checkpoints before transient context").
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
…8392)

Share live and persisted tool-result preparation so the text first sent
to the model is capped and redacted once and replayed byte-identically
after persistence, replay, and reopen (including oversized results and
late listener redaction changes). Preserve canonical tool-result
projection identity through replay normalization, keep the browser
conversation cache key for internal child completions, and disambiguate
repeated native OpenAI Chat Completions tool-call IDs deterministically.

Backport of d13db41 (#168392) adapted for 2026.10.2:
- the Anthropic checkpoint part ships in the #168042 port commit
- live-cache release-gate, workflow, and release-docs changes are not included;
  the offline prefix-stability helper is kept for the new regression tests
- the attempt auth-selection extraction (no behavior change) is not included
- the admitted-turn regression test declares this line's image retention
  (rolling three-turn window), its trailing transient Chat Completions
  carrier, and keeps one instruction revision because in-history instruction
  updates for those routes are not on 2026.10.2
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 P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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