Skip to content

fix(ai): stop serializing runtime context as user turns and preserve prompt cache - #141585

Closed
salad-maker wants to merge 44 commits into
openclaw:mainfrom
salad-maker:fix/anthropic-runtime-context-carrier
Closed

salad-maker wants to merge 44 commits into
openclaw:mainfrom
salad-maker:fix/anthropic-runtime-context-carrier

Conversation

@salad-maker

Copy link
Copy Markdown
Contributor

Summary

Resolves multiple coupled issues where OpenClaw-generated runtime context (timestamps, channel metadata, session state) is serialized into provider conversation messages as a user turn.

Attributing runtime metadata to the user creates three distinct failure modes:

  1. Provenance / Role Confusion: The model is told the human typed the internal plumbing, causing hallucinated dialogues, metadata echoing, and prompt-injection defense false positives ([Bug]: role:"custom" runtime-context carrier with display:false is serialized as a trailing role:"user" message on every request #123265, [Bug]: Runtime context block injected into the user turn is phrased like a prompt injection and triggers model refusals (iMessage) #139022).
  2. Anthropic Prompt Cache Invalidation: Because volatile per-turn metadata lived inside messages, every turn perturbed the message prefix or captured the moving cache breakpoint, constantly busting the prompt cache ([Bug]: 2026.9.2 Anthropic cache_control can attach to relocating runtime-context carrier (opt-out removed in #136782) #140607).
  3. OpenAI Responses Cache Breakage: Injected user turns disrupted prompt cache lineage on OpenAI/Azure Responses ([Bug]: Azure/OpenAI Responses: runtimeContextCarrier tail relocation breaks GPT-5.6 prompt cache lineage #123652).

What This PR Changes

1. Anthropic: Partition carriers to uncached trailing system blocks

  • Added partitionAnthropicRuntimeContextCarriers to split carrier messages out of the conversation before conversion in both convertMessages and convertAnthropicMessages.
  • Genuine conversation messages remain strictly real user/assistant turns.
  • Carriers are appended as top-level Anthropic system text blocks placed after buildAnthropicSystemBlocks(...) / applyAnthropicPayloadPolicyToParams(...) with no cache_control.
  • Stable system blocks keep their cache breakpoints; the conversation cache anchor remains naturally on the last genuine user turn.

2. OpenAI Responses: Align carrier role with system prompt

  • Serializes runtime-context carriers using the resolved instruction role (developer where supported, otherwise system) instead of user.

3. Notice Cleanup & Stripping Parity

  • Simplified runtime notice to: This context is runtime-generated, not user-authored.
  • Kept LEGACY_OPENCLAW_RUNTIME_CONTEXT_NOTICE and OPENCLAW_RUNTIME_CONTEXT_NOTICES so stored session transcripts and legacy event headers continue to strip cleanly on display sanitization.
  • Replaced inline literals with shared constants so emitters and detection stay synchronized.

Fixes / References

Verification

  • Unit tests: All affected suites pass (427 tests across packages/ai and src/agents).
  • Code standards: oxlint (0 warnings, 0 errors), oxfmt, and tsgo:core clean.
  • Literal payload verification: Tested via live transport harness confirming:
    • System block 0: stable system prompt (cache_control: { type: "ephemeral" })
    • System block 1: dynamic suffix (cache_control: { type: "ephemeral" })
    • System block 2: runtime context carrier (cache_control: null)
    • Messages array contains only genuine turns, with the cache breakpoint anchored to the real user turn.
  • Live deployment: Verified on a running Gateway instance

github-actions Bot and others added 30 commits September 2, 2026 16:37
(cherry picked from commit a3c3c31)
Cut from main 37a5c5b with the native locale
refresh (openclaw#136680) cherry-picked. Aligns every version location and the
version-owned generated metadata via pnpm release:prepare and release:prep.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The generation fixture emitted index.js without its package.json. Since
696eb5d (openclaw#136399), bundled artifact selection follows emitted package
metadata so stale JS/CJS/MJS neighbors cannot replace the declared output.
The real build already writes this metadata; the fixture missed that contract.

Repair createSpeechFixture in the generation test by declaring ./index.js
beside the built entry. Preserve every built/source, generation isolation,
no-rediscovery, and no-re-registration assertion. Production LOC delta: 0.

Proof: CI=true NODE_OPTIONS=--max-old-space-size=8192 OPENCLAW_VITEST_MAX_WORKERS=2 OPENCLAW_VITEST_SHARD_NAME=agentic-plugins OPENCLAW_TEST_PROJECTS_PARALLEL=2 pnpm test -- test/vitest/vitest.plugins.config.ts --
Before: 5 capability failures, 4694 passed, 1 skipped. After: all 9 generation
cases pass; 4698 passed, 1 skipped, and one separate 120s native SDK bridge
timeout (that test took 108s before the patch).
pnpm test src/plugins/capability-provider-runtime: 75 passed.
pnpm check:changed passed; independent Codex review clean through P2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 58a94ab)
Windows release checks pass drive-qualified archive paths to GNU tar,
which treats their colon as a remote host. The shared fixture registry
then stalls before readiness or silently loses package dependencies.

Make the registry's manifest reader pass the archive basename with its
parent as cwd, matching the existing prerelease artifact validator. The
owning surface is release/E2E tooling, before installer or update dispatch.

Proof: the real registry regression fails on the old reader under GNU tar
1.35 and passes with the repair; 191 focused tests cover registry behavior,
artifact identity, and cross-OS harness contracts. All ten 2026.9.1 release
companions served exact metadata and tarball bytes in local GNU tar proof.
pnpm check:changed and independent Codex autoreview passed.
Native Windows end-to-end validation still needs the three CI lanes rerun.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 1fbd62d)
The binding source-test image installed only the root project. With pnpm's
isolated linker, private packages reached through source aliases had no
package-local dependency links, so all three suites failed to import
mdast-util-from-markdown from markdown-core.

Remove the root-only install filter in the owning E2E Dockerfile so pnpm
creates the complete workspace graph. Keep the frozen lockfile, isolated
linker, and disabled lifecycle scripts. Update the existing helper guard.

Proof: the unmodified Docker lane and native Markdown import reproduced
ERR_MODULE_NOT_FOUND. Rebuilding the corrected image passes the import,
workspace/plugin symlink probes, and all three focused binding tests.
pnpm test test/scripts/docker-build-helper.test.ts passes 273 tests with
two existing skips; pnpm check:changed and fresh Codex autoreview pass.
Other sampled release Docker failures have independent plugin/update
causes and are not covered by this image repair.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 1fa94d9)
The installed 2026.8.2 updater refuses the release smoke before package
mutation or candidate handoff. Current main has the same defect: strict
systemd command inspection cannot distinguish a missing manager from an
uninspectable existing service.

Let the native service-state owner record affirmative manager/unit absence,
then require strict Gateway lock inspection and a free configured port at
update preflight. Preserve unknown-state refusal and report skipped restart
when nothing is running. Lock discovery retains its existing contract.

Use the shipped baseline's documented --no-restart path only after proving
the dedicated smoke container idle, then repeat the candidate update with
default restart policy. Join the heartbeat timer exposed by that idle check.
Document the one-time 2026.8.2 upgrade workaround.

Proof: original baseline and packed-main Docker runs refused with exit 1;
managerless and strict-lock regressions fail before the fix. Final focused
suites pass 532 tests; the full update CLI suite passes 370 with 1 skipped.
Final Docker baseline/manual plus candidate/default updates and doctor
steps pass; pnpm check:changed passes. Independent review is clean through P2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 245e18edf13d084ef4d0ce4c6f3f1486b73f7b1f)
Prepared registry merging kept upstream latest tags during candidate upgrade,
so the survivor installed 2026.8.2 plugins despite serving 2026.9.1 artifacts.
The registry helper now distinguishes published baseline tags from candidate
package tags while retaining older dependency versions and fixture identities.

Owner: prepared npm registry harness. Product runtime is unchanged; this
repairs false stable-release upgrade failures for WhatsApp and Matrix.
Proof: stable registry regression failed twice before the repair; all 15
registry helper and 37 plugin selection tests pass. The original 2026.9.1
candidate now passes the published 2026.8.2 survivor in local Docker.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 13246c2)
The nested synthetic registry replaced only one npm environment spelling,
then setup discarded both instead of restoring the parent prepared registry.
This caused a synthetic-package 404 and, once repaired, an unpublished core
dependency ETARGET. Set both spellings and scope fixture setup to a subshell
whose cleanup owns only the temporary server; preserve parent artifact state.

Owner: npm fixture lifecycle and corrupt-plugin scenario. Product runtime is
unchanged; release validation now exercises real corrupt-plugin tolerance.
Proof: real npm regression fails before the repair and passes afterward.
Docker reproduces both failures, then passes the full 2026.8.2 to unchanged
2026.9.1 candidate upgrade while preserving the plugin policy assertions.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 023c6ed)
Companion provenance inspection ran after the harness restored deliberately
invalid legacy Discord configuration, so validation aborted before update.
Keep inspection within the existing parked-config lifetime and restore the
exact authored bytes after success or failure. Existing Doctor migrations
remain responsible for the actual upgrade.

Owner: upgrade-survivor fixture preparation. Product runtime is unchanged;
release validation can reach the migration it is intended to exercise.
Proof: the original candidate reproduces the pre-update Docker failure;
two new lifecycle cases fail before the repair and all three pass afterward,
with the existing registry-order helper case also passing. Full Docker
survivor now passes migration, state survival, and Gateway readiness/RPC
against the same original release candidate.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit db064aa)
Update reconciliation reused cached filesystem facts across package
installation. A repaired missing payload still appeared absent, causing
strict package-owner resolution to reject its runtime child list; replaced
metadata could likewise retain retired children.

Give cohort snapshots and post-install CLI reconciliation fresh operation
caches. Preserve the authoritative owner check and retained runtime cache
generations instead of invalidating a running gateway or adding fallbacks.

Proof: missing/replaced real-filesystem regressions fail before this change;
67 focused cohort, package-policy, and plugin CLI tests pass. The original
2026.9.1 package fails the plugin-update Docker lane at missing-payload-accepted;
the same release with this repair passes consent, repair, and unchanged checks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit e55f6cf0bd23dd206f7dd770cf7443cd35766f07)
The runtime-plugin sweep invoked demo-npm after uninstall --keep-files and
reinstall. Reinstall intentionally retains the explicit disabled marker,
so command registration was correctly absent on that second invocation.

Assert the reinstalled disabled state, then explicitly enable the fixture
through the existing capability-consent helper before checking its CLI.
Keep command registration and operator uninstall intent unchanged.

Proof: the full Docker plugins lane fails before and passes after this
harness change using the identical 2026.9.1 package and registry snapshot.
The stateful sweep regression rejects command execution until re-enabled;
all 23 package-consent compatibility tests pass.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 1c50920b3538b3f6a6a9d951262c2ebdef7fd503)
Root cause: the composed Gateway fixture bypassed required service methods
through a context cast after execution-mode projection became mandatory.
Owner: the App SDK E2E worker-service fixture now satisfies the complete
request-facing contract and asserts supported execution modes.
Proof: the original E2E failed 3/3 before and passed 3/3 after; environment
owner tests pass (33 tests).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 781d95537879194e83ccc58acd56234bdb6c3f4c)
Root cause: a reasonless skipped update is a failed update, so the old
fixture exited before reaching its intended database compatibility gate.
Owner: the schema-preflight fixture now declares the supported
already-current outcome and preserves the schema-refusal assertion.
Proof: the original E2E failed 3/3 before and passed 3/3 after; doctor-update
owner tests pass (35 tests). No schema or production behavior changes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit d39fa7bcc9dd03f6627dc6dcb6e72b8352dd31b8)
Root cause: requester and lifecycle fixtures returned text without the
terminal send receipt required for external completion delivery, and
observed RPC calls before their delivery state had committed.
Owner: Gateway-result fixtures now provide confirmed receipts; scenarios
wait on committed cleanup and release gated work even on assertion failure.
Proof: the rejected requester wake failed 3/3 before and passed 3/3 after.
Receipt repairs also resolved four sibling lifecycle failures.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit bd463c64e541527d694fcfab2e173053e776fffb)
Root cause: four retry-grace scenarios emitted 1970 timestamps under the
current fake clock, so the 30-minute delivery deadline had already expired.
Owner: each event producer now records Date.now(); grace advances and
observable delivery assertions remain unchanged.
Proof: all four failed 3/3 with stale timestamps; the corrected sibling
suite passes all 14 tests in the final 22-test Gateway E2E run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 6e611dc93c3a67c491d3fe3c5b004c437de79bd9)
Root cause: the wake read route metadata only from its scheduling child,
so a rerouted sibling disappeared from the parent's consolidated context.
Owner: the requester settle-wake formatter now reuses the current-child
selection, deduplicates and sorts route notices, and caps the aggregate at
1024 characters while preserving local and shared-channel visibility.
Proof: the original visible-wake assertion still failed after fixture-only
repairs and passes after this change. All four reported E2E failures pass
3/3; 39 wake owner tests cover sibling notices, stale owners and the bound.
Production growth is 17 lines for bounded, deterministic batch aggregation.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit cab74190c5d3ecfe529e586df05a312183c1ac9e)
The successful announce fixture supplied only aggregate message-tool evidence,
which no longer proves a committed final reply to the source conversation.
Supply the receipt owned by the embedded runner without changing delivery
policy or requester-wake sibling rerouting.

Proof: the format suite failed 21 of 87 tests at both c92d0ae and
a41af7e; all 87 pass with the corrected fixture.

(cherry picked from commit 8229b8fcb61fa3a4e5b0c80acff087547a7904d4)
Inventory callers forced full discovery on every browse while trying to
refresh auth-stale content. Give the prepared catalog owner a distinct stale
refresh intent, preserve explicit forced refresh, and leave ordinary turn
reads on their existing facts. Apply the policy to commands, CLI, and RPC.

Correct the Ollama fixture response contract and await full catalog readiness.
Verify discovered-only models survive callbacks and RPC while discovery is
unavailable, and verify explicit refresh still reaches the provider.

Proof: before the fix, the real Gateway made 8 discovery calls after a 3-call
warmup, and the owner policy regressions failed. Prepared catalog and auth
reload owner tests now pass (43 tests).

(cherry picked from commit 1dfddb6e8fa7f57fcc60c4f01384b679e88ad77a)
The Docker scenario treated workspaceAccess=none as a read-only private
workspace. The sandbox mount owner intentionally provides private writable
storage while hiding the host and agent workspaces.

Assert a private write/read succeeds and the same-named host sentinel stays
unchanged. Keep read-only write rejection and read-write host persistence.
Use a unique temporary workspace in the owner test so ambient /tmp skills
cannot add unexpected mounts.

Proof: OrbStack Docker reproduced the old assertion on successful exit zero;
the complete none/read-only/read-write scenario now passes.

(cherry picked from commit 85079b8ca7571f48537ef3b0ce5d393880b8b0c7)
The cancellation fixture hardcoded a root node_modules adapter path, but
acpx owns that dependency. This caused deterministic MODULE_NOT_FOUND startup
failures in both release validation runs, not an agent startup flake.

Remove the override so the canonical plugin launcher resolves its adapter;
retain the synthetic Codex app-server process through CODEX_PATH.

Proof: the real installed adapter process passes cancellation authorization,
rejects stale replacements without interrupting them, and preserves queued
successors when the preceding run is cancelled.

(cherry picked from commit 1e15a1d9ce4cb7ff9d1364ea8b4fe2528ef81c55)
Doctor imported the retained 10,000-row legacy host event tail through
10,000 standalone writes, each repeating expiry and retention scans.

Prepare bounded 500-row batches before synchronous transactions. Share the
canonical register path, maintain transaction-local retention counts, and
refresh them on expiry or clock rollback. Per-row savepoints preserve the
successful prefix on row failures; preparation failures flush their valid
prefix. Preserve source ages, TTLs, ordering, limits, sibling state, and
idempotent resume without changing the schema.

The oversized-log test fell from 53.508s to 2.274s on the first paired run;
subsequent runs took 1.447s and 1.647s. The full memory suite passed 1,422
tests; shared-store/database and Matrix doctor tests passed 95 and 20.

requires maintainer approval for the transaction-boundary change

(cherry picked from commit 7eccf12)
The catalog worker reconstructed an authoritative plugin registry with only
augmentation and harness owners, so runtime catalog discovery lost provider
names and reasoning metadata. Plan discovery through the canonical provider
scope and materialize its owners after auth refresh using captured metadata.

Keep the startup generation immutable and preserve lightweight and empty
discovery scopes. Shared planning absorbs the owner selection instead of
adding a registry fallback.

Proof: both original ClawRouter cases fail on release 730dc39 and
main eea96a3. All three repaired cases, including late durable auth,
and 116 owner/sibling tests pass. Combined catalog, retry, abort and Telegram release proof passes 13 tests.

(cherry picked from commit 608583c)
The fixtures still expected the retired 10s/20s backoff and advanced past
a model after one HTTP 500, although the retry owner allows three transient
retries with jittered 1s/2s/4s delays. Fix the random source and script
persistent errors that exhaust that existing budget.

Preserve exact delay, profile order, fallback winner and exhaustion prose
assertions. No runtime retry policy changes.

Proof: the same three tests fail on release 730dc39 and main
eea96a3; all eight repaired fault-sequence tests pass, including
the combined patched-release run.

(cherry picked from commit 3ca630b)
The cold Gateway fixture expected a failed/blocked result after Stop,
contradicting the existing authoritative cancellation repair. Assert the
exact timeout/rpc/aborted wire payload and the canonical cancelled task.
Keep provider connection closure and exactly one request checks.

Owner: Gateway agent execution and task lifecycle. No product changes.
Proof: the identical assertion fails on release 730dc39 and main
eea96a3. The strengthened built-Gateway test passes on both patched
main and release, including its first chat RPC and provider cancellation.

(cherry picked from commit 897187f)
Failure handling read error text from successful current-attempt assistants,
allowing stale text to replace an actual timeout or trigger a thinking retry
after a successful reply. Normalize the failed assistant once at the failure
owner for classification, retry decisions, profile health and failure copy.

Keep structured terminal replay-safety checks and provider-start evidence
independent of that text selection.

Proof: full-entry regressions reproduce misleading HTTP 500 timeout copy
and an unnecessary second attempt before the fix. Six context tests and
21 assistant-failure owner tests pass after the repair.

(cherry picked from commit d330e36)
The failover owner reconstructed HTTP status from its routing reason,
turning an observed 500 into 408 and mislabeling the final reply as a
timeout. Preserve the canonical assistant failure signal status before
using a synthesized status for failures without one.

Apply the same rule to profile-rotation exhaustion, model fallback and
surfaced failures. The Telegram proof expects the existing safe detailed
copy and rejects raw provider details. Document status versus retry reason.

Proof: six status cases fail before the fix; 82 owner tests pass after.
Both baseline Gateway runs reproduce 17 requests and the wrong 408 reply.
The patched release Telegram flow passes with exact 500 copy and the
raw-error privacy canary excluded.

(cherry picked from commit 32e2a90)
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • extensions/a2a/package.json
  • extensions/acpx/package.json
  • extensions/admin-http-rpc/package.json
  • extensions/alibaba/package.json
  • extensions/amazon-bedrock-mantle/package.json
  • extensions/amazon-bedrock/package.json
  • extensions/anthropic-vertex/package.json
  • extensions/anthropic/package.json
  • extensions/arcee/package.json
  • extensions/azure-speech/package.json
  • extensions/baseten/package.json
  • extensions/beam/package.json
  • extensions/bonjour/package.json
  • extensions/brave/package.json
  • extensions/browser/package.json
  • extensions/buzz/package.json
  • extensions/byteplus/package.json
  • extensions/canvas/package.json
  • extensions/cerebras/package.json
  • extensions/chutes/package.json
  • extensions/clawrouter/package.json
  • extensions/clickclack/package.json
  • extensions/cloudflare-ai-gateway/package.json
  • extensions/codex/package.json
  • extensions/cohere/package.json
  • 128 additional dependency-related files not shown

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfiles or workspace dependency policy changes are present.
  • Treat pnpm-lock.yaml and package-lock.json diffs as dependency security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Dependency graph changes are blocked

OpenClaw does not accept dependency graph changes through PRs unless a repository admin or security explicitly authorizes the current head SHA. Dependency updates are generated internally by maintainers so external PRs cannot change the resolved graph.

Detected dependency graph changes:

  • extensions/a2a/package.json changed peerDependencies, version.
  • extensions/acpx/package.json changed dependencies, version.
  • extensions/admin-http-rpc/package.json changed version.
  • extensions/alibaba/package.json changed version.
  • extensions/amazon-bedrock-mantle/package.json changed version.
  • extensions/amazon-bedrock/package.json changed dependencies, version.
  • extensions/anthropic-vertex/package.json changed dependencies, version.
  • extensions/anthropic/package.json changed dependencies, version.
  • extensions/arcee/package.json changed version.
  • extensions/azure-speech/package.json changed version.
  • extensions/baseten/package.json changed version.
  • extensions/beam/package.json changed version.
  • extensions/bonjour/package.json changed version.
  • extensions/brave/package.json changed version.
  • extensions/browser/package.json changed dependencies, devDependencies, version.
  • extensions/buzz/package.json changed dependencies, peerDependencies, version.
  • extensions/byteplus/package.json changed version.
  • extensions/canvas/package.json changed dependencies, version.
  • extensions/cerebras/package.json changed version.
  • extensions/chutes/package.json changed version.
  • extensions/clawrouter/package.json changed version.
  • extensions/clickclack/package.json changed peerDependencies, version.
  • extensions/cloudflare-ai-gateway/package.json changed version.
  • extensions/codex/package.json changed dependencies, version.
  • extensions/cohere/package.json changed version.
  • extensions/comfy/package.json changed version.
  • extensions/copilot-proxy/package.json changed version.
  • extensions/copilot/package.json changed version.
  • extensions/crabbox/package.json changed version.
  • extensions/cua-computer/package.json changed dependencies, version.
  • extensions/deepgram/package.json changed version.
  • extensions/deepinfra/package.json changed version.
  • extensions/deepseek/package.json changed version.
  • extensions/diagnostics-otel/package.json changed version.
  • extensions/diagnostics-prometheus/package.json changed version.
  • extensions/diffs-language-pack/package.json changed version.
  • extensions/diffs/package.json changed dependencies, version.
  • extensions/discord/package.json changed dependencies, peerDependencies, version.
  • extensions/document-extract/package.json changed version.
  • extensions/duckduckgo/package.json changed version.
  • extensions/elevenlabs/package.json changed version.
  • extensions/exa/package.json changed version.
  • extensions/fal/package.json changed version.
  • extensions/featherless/package.json changed version.
  • extensions/feishu/package.json changed dependencies, peerDependencies, version.
  • extensions/file-transfer/package.json changed dependencies, version.
  • extensions/firecrawl/package.json changed dependencies, version.
  • extensions/fireworks/package.json changed version.
  • extensions/fish-audio-speech/package.json changed version.
  • extensions/geolocation/package.json changed version.
  • extensions/github-copilot/package.json changed version.
  • extensions/gmi/package.json changed version.
  • extensions/google-meet/package.json changed dependencies, peerDependencies, version.
  • extensions/google/package.json changed dependencies, version.
  • extensions/googlechat/package.json changed peerDependencies, version.
  • extensions/gradium/package.json changed version.
  • extensions/groq/package.json changed version.
  • extensions/huggingface/package.json changed version.
  • extensions/image-generation-core/package.json changed version.
  • extensions/imap/package.json changed dependencies, version.
  • extensions/imessage/package.json changed dependencies, peerDependencies, version.
  • extensions/inworld/package.json changed version.
  • extensions/irc/package.json changed version.
  • extensions/kilocode/package.json changed version.
  • extensions/kimi-coding/package.json changed version.
  • extensions/line/package.json changed dependencies, peerDependencies, version.
  • extensions/linux-node/package.json changed version.
  • extensions/litellm/package.json changed version.
  • extensions/llama-cpp/package.json changed version.
  • extensions/llm-task/package.json changed dependencies, version.
  • extensions/lmstudio/package.json changed version.
  • extensions/lobster/package.json changed dependencies, version.
  • extensions/logbook/package.json changed peerDependencies, version.
  • extensions/longcat/package.json changed version.
  • extensions/matrix/package.json changed dependencies, peerDependencies, version.
  • extensions/mattermost/package.json changed peerDependencies, version.
  • extensions/memory-core/package.json changed dependencies, peerDependencies, version.
  • extensions/memory-lancedb/package.json changed dependencies, version.
  • extensions/memory-wiki/package.json changed dependencies, peerDependencies, version.
  • extensions/meta/package.json changed version.
  • extensions/microsoft-foundry/package.json changed version.
  • extensions/microsoft/package.json changed version.
  • extensions/migrate-claude/package.json changed peerDependencies, version.
  • extensions/migrate-hermes/package.json changed peerDependencies, version.
  • extensions/minimax/package.json changed version.
  • extensions/mistral/package.json changed version.
  • extensions/moonshot/package.json changed version.
  • extensions/msteams/package.json changed dependencies, peerDependencies, version.
  • extensions/mxc/package.json changed version.
  • extensions/nextcloud-talk/package.json changed peerDependencies, version.
  • extensions/nostr/package.json changed dependencies, peerDependencies, version.
  • extensions/novita/package.json changed version.
  • extensions/nvidia/package.json changed version.
  • extensions/oc-path/package.json changed dependencies, peerDependencies, version.
  • extensions/ollama/package.json changed dependencies, version.
  • extensions/onepassword/package.json changed dependencies, version.
  • extensions/openai/package.json changed version.
  • extensions/opencode-go/package.json changed version.
  • extensions/opencode/package.json changed version.
  • extensions/openrouter/package.json changed version.
  • extensions/openshell/package.json changed dependencies, version.
  • extensions/parallel/package.json changed version.
  • extensions/perplexity/package.json changed version.
  • extensions/pixverse/package.json changed peerDependencies, version.
  • extensions/policy/package.json changed peerDependencies, version.
  • extensions/qa-channel/package.json changed dependencies, peerDependencies, version.
  • extensions/qa-lab/package.json changed peerDependencies, version.
  • extensions/qianfan/package.json changed version.
  • extensions/qwen/package.json changed version.
  • extensions/raft/package.json changed peerDependencies, version.
  • extensions/reef/package.json changed dependencies, version.
  • extensions/runway/package.json changed version.
  • extensions/searxng/package.json changed version.
  • extensions/senseaudio/package.json changed version.
  • extensions/sglang/package.json changed version.
  • extensions/signal/package.json changed version.
  • extensions/slack/package.json changed dependencies, peerDependencies, version.
  • extensions/sms/package.json changed version.
  • extensions/stepfun/package.json changed version.
  • extensions/synology-chat/package.json changed version.
  • extensions/synthetic/package.json changed version.
  • extensions/tavily/package.json changed dependencies, version.
  • extensions/teams-meetings/package.json changed dependencies, peerDependencies, version.
  • extensions/telegram/package.json changed dependencies, version.
  • extensions/tencent/package.json changed version.
  • extensions/tlon/package.json changed dependencies, peerDependencies, version.
  • extensions/together/package.json changed version.
  • extensions/tokenjuice/package.json changed peerDependencies, version.
  • extensions/tts-local-cli/package.json changed version.
  • extensions/twitch/package.json changed version.
  • extensions/vault/package.json changed version.
  • extensions/venice/package.json changed version.
  • extensions/vercel-ai-gateway/package.json changed version.
  • extensions/visitor-access/package.json changed dependencies, version.
  • extensions/vllm/package.json changed version.
  • extensions/voice-call/package.json changed dependencies, peerDependencies, version.
  • extensions/volcengine/package.json changed version.
  • extensions/voyage/package.json changed version.
  • extensions/vydra/package.json changed version.
  • extensions/web-readability/package.json changed version.
  • extensions/webhooks/package.json changed version.
  • extensions/whatsapp/package.json changed dependencies, peerDependencies, version.
  • extensions/workboard/package.json changed dependencies, devDependencies, peerDependencies, version.
  • extensions/xai/package.json changed dependencies, version.
  • extensions/xiaomi/package.json changed version.
  • extensions/zai/package.json changed version.
  • extensions/zalo/package.json changed peerDependencies, version.
  • extensions/zalouser/package.json changed dependencies, peerDependencies, version.
  • extensions/zoom-meetings/package.json changed dependencies, peerDependencies, version.
  • package.json changed dependencies, devDependencies, packageManager, version, engines.
  • packages/ai/package.json changed dependencies, version.
  • packages/gateway-client/package.json changed version.
  • packages/gateway-protocol/package.json changed dependencies, version.

If this PR intentionally needs a dependency graph change, ask a repository admin or member of @openclaw/openclaw-secops to comment:

/allow-dependencies-change

The action will approve the current head SHA (65b80179b51a643cf07ce8c430da8b95773b4d4f) when it reruns. A later push requires a fresh approval.

@clawsweeper

clawsweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 7, 2026, 5:35 PM ET / 21:35 UTC.

ClawSweeper review

What this changes

The branch moves Anthropic runtime metadata into system blocks, changes OpenAI Responses metadata to instruction roles, updates notice stripping, and carries release-branch changes.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 9 items remain

Keep open: the branch contains useful, distinct work, but its Anthropic cache premise is incorrect and the provider-role change conflicts with a recently merged compatibility decision. The related cache PR covers only part of this proposal.

Priority: P2
Reviewed head: 65b80179b51a643cf07ce8c430da8b95773b4d4f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful intent and focused assertions are outweighed by the cache-prefix defect and unproven replay compatibility.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The supplied body reports Anthropic payload-shape inspection and a running Gateway verification, but gives no observable cache-usage sequence or retained-session result for the changed builders and Responses roles. Single-request marker placement cannot demonstrate the claimed cache preservation. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied body reports Anthropic payload-shape inspection and a running Gateway verification, but gives no observable cache-usage sequence or retained-session result for the changed builders and Responses roles. Single-request marker placement cannot demonstrate the claimed cache preservation. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 11 items Verified focused changes and ancestry: The original head is 65b8017. The three focused commits follow ad6fe23; their delta is 14 files, separate from the release-derived history included in the complete merge-base delta. Raw inspection confirms the first focused commit records that parent. No pinned test merge exists, so endpoint drift was not treated as removed main behavior.
Introduced cache-prefix regression: Both Anthropic builders remove carriers from conversation messages and append their text to top-level system blocks. Message cache markers remain enabled. Consequently, changing the carrier changes a prefix preceding every conversation marker, despite the carrier having no cache_control property.
Authoritative Anthropic cache contract: Anthropic documents that cache entries cover the complete ordered tools, system, and messages prefix through a breakpoint. An unmarked system block is therefore included in later message cache entries: https://platform.claude.com/docs/en/build-with-claude/prompt-caching.
Findings 1 actionable finding [P2] Keep volatile context outside the cached conversation prefix
Security None None.

How this fits together

OpenClaw adds runtime metadata to incoming requests before its provider adapters construct model messages. These adapters determine message roles, retained-history replay, and prompt-cache boundaries.

flowchart LR
  A[Incoming user request] --> C[Runtime context assembly]
  B[Conversation history] --> C
  C --> D[Provider message conversion]
  D --> E[Anthropic system and messages]
  D --> F[OpenAI Responses input]
  E --> G[Model response and cache usage]
  F --> G
Loading

Decision needed

Question Recommendation
Should this PR preserve the provider roles established by the merged provenance fix, or pursue a separately designed role migration? Preserve roles and narrow the repair: Keep the current provenance projection and coordinate the cache repair with the existing lifecycle-qualified Anthropic candidate.

Why: The proposed role change departs from an explicit recent compatibility decision; choosing a new retained-session contract requires maintainer intent.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied body reports Anthropic payload-shape inspection and a running Gateway verification, but gives no observable cache-usage sequence or retained-session result for the changed builders and Responses roles. Single-request marker placement cannot demonstrate the claimed cache preservation. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep volatile context outside the cached conversation prefix (P2) - When the next user turn changes its runtime carrier, placing that carrier in system changes the prefix before every message cache breakpoint. Anthropic caches the complete tools → system → messages prefix, so omitting cache_control from this block does not exclude it from later cached messages. This turns a tail-only change into a conversation-wide cache miss. The managed builder has the same problem at anthropic-transport-stream.ts:1073; preserve the stable history prefix and verify two user turns with different metadata, not only marker placement.
  • Resolve merge risk (P1) - Unconditionally changing carrier roles and placement may invalidate retained thinking prefixes or alter existing-session behavior; fresh-session and upgrade replay evidence is absent.
  • Resolve merge risk (P1) - The branch is reported conflicting and includes release-derived changes beyond the focused fix. Their final integration and ancillary runtime behavior have not been fully verified; no claim is made that merging would delete current-main work.
  • Resolve merge risk (P1) - The focused repair adds 120 production lines, including a new partitioning path, while current main already centralizes Anthropic conversion and provenance projection.
  • Complete next step (P2) - Resolve the provider-role direction, isolate the focused changes on current main, repair the Anthropic cache-prefix defect, and supply redacted cache and replay evidence before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P2] Keep volatile context outside the cached conversation prefix — packages/ai/src/providers/anthropic.ts:1088-1094
Agent review details

Security

None.

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Production versus validation growth Focused commits: production +170/-50, tests +252/-11; complete delta: production net +513, tooling +358, tests/support +2143 Separating the three focused commits from release-derived work exposes 120 new production lines whose partitioning approach should be absorbed into current shared conversion.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/worker-environments/skill-resource-transfer.ts, serialized state: src/infra/gateway-lock.ts, unknown-data-model-change: src/gateway/worker-environments/skill-resource-transfer.ts, unknown-data-model-change: src/infra/gateway-lock.ts, unknown-truncated-pull-files. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Keep the existing replay contract (recommended)
    Narrow the branch to a cache-safe repair using current shared conversion and preserve existing carrier roles.
  2. Pause the broader role change
    Hold the role migration until maintainers accept its retained-session contract and provider traces demonstrate compatibility.

Technical review

Best possible solution:

Reuse current provenance projection and shared provider conversion, preserving retained prefixes while fixing transient cache anchors without moving volatile context ahead of conversation history.

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

Yes, from source: consecutive Anthropic requests with unchanged history and different carrier text diverge inside the system prefix before every message cache marker. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

No. The proposed system-tail placement defeats cross-turn conversation caching; current provenance projection and lifecycle-qualified cache handling provide a safer foundation, while broader role migration remains unresolved.

Full review comments:

  • [P2] Keep volatile context outside the cached conversation prefix — packages/ai/src/providers/anthropic.ts:1088-1094
    When the next user turn changes its runtime carrier, placing that carrier in system changes the prefix before every message cache breakpoint. Anthropic caches the complete tools → system → messages prefix, so omitting cache_control from this block does not exclude it from later cached messages. This turns a tail-only change into a conversation-wide cache miss. The managed builder has the same problem at anthropic-transport-stream.ts:1073; preserve the stable history prefix and verify two user turns with different metadata, not only marker placement.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This addresses model-context correctness and provider-cache efficiency without evidence of an emergency outage.
  • add merge-risk: 🚨 compatibility: Carrier roles and placement change for existing histories despite the current decision to preserve prefix-sensitive replay.
  • add merge-risk: 🚨 other: Moving changing metadata into the system prefix can force conversation-cache rewrites and increase inference cost.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied body reports Anthropic payload-shape inspection and a running Gateway verification, but gives no observable cache-usage sequence or retained-session result for the changed builders and Responses roles. Single-request marker placement cannot demonstrate the claimed cache preservation. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This addresses model-context correctness and provider-cache efficiency without evidence of an emergency outage.
  • merge-risk: 🚨 compatibility: Carrier roles and placement change for existing histories despite the current decision to preserve prefix-sensitive replay.
  • merge-risk: 🚨 other: Moving changing metadata into the system prefix can force conversation-cache rewrites and increase inference cost.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied body reports Anthropic payload-shape inspection and a running Gateway verification, but gives no observable cache-usage sequence or retained-session result for the changed builders and Responses roles. Single-request marker placement cannot demonstrate the claimed cache preservation. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Verified focused changes and ancestry: The original head is 65b8017. The three focused commits follow ad6fe23; their delta is 14 files, separate from the release-derived history included in the complete merge-base delta. Raw inspection confirms the first focused commit records that parent. No pinned test merge exists, so endpoint drift was not treated as removed main behavior. (a8db58430370)
  • Introduced cache-prefix regression: Both Anthropic builders remove carriers from conversation messages and append their text to top-level system blocks. Message cache markers remain enabled. Consequently, changing the carrier changes a prefix preceding every conversation marker, despite the carrier having no cache_control property. (packages/ai/src/providers/anthropic.ts:1088, 65b80179b51a)
  • Authoritative Anthropic cache contract: Anthropic documents that cache entries cover the complete ordered tools, system, and messages prefix through a breakpoint. An unmarked system block is therefore included in later message cache entries: https://platform.claude.com/docs/en/build-with-claude/prompt-caching.
  • Producer, caller, and sibling behavior: runtime-context-prompt.ts builds hidden custom messages; attempt-session-prepare.ts relocates them at the model boundary; packages/agent-core/src/harness/messages.ts preserves the carrier marker while converting them to user messages. The changed Anthropic builders consume that marker. Responses already anchors carriers beside user/checkpoint input, while Chat Completions remains outside the proposed role change. (src/agents/embedded-agent-runner/run/attempt-session-prepare.ts:481, 65b80179b51a)
  • Tests establish payload shape, not cache reuse: The added provider and managed-transport assertions verify that carrier blocks lack cache_control and that genuine user messages retain markers. They do not compare complete cached prefixes across changing user-turn metadata. The PR body reports 427 passing tests, a transport-harness payload inspection, and a running Gateway verification, but supplies no request/response trace or cache-usage observations demonstrating the claimed improvement. (packages/ai/src/providers/anthropic.test.ts:2416, 65b80179b51a)
  • Current-main solution and explicit compatibility decision: GitHub verifies fix: distinguish inbound messages from runtime context #140859 as merged. Its rationale explicitly preserves provider roles because retained thinking can bind to preceding prefixes; it distinguishes producer-owned runtime instructions from conversation data through versioned projection. Current main retains user-role carrier serialization and uses a shared Anthropic converter. This is relevant partial implementation, not proof that all requested behavior is already implemented. (src/agents/internal-runtime-context.ts:24, 0994c66c963e)

Likely related people:

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

Rank-up moves

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

  • Isolate the focused changes on current main and repair both Anthropic builders using the shared conversion owner.
  • Resolve the provider-role direction and demonstrate fresh-session plus retained-session replay compatibility.
  • Add redacted production request/response traces showing cache reads across tool continuations and changing user turns; remove credentials, private endpoints, and user data. Updating the PR body should trigger review automatically; otherwise ask a maintainer for @clawsweeper re-review.

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.

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: android App: android app: macos App: macos channel: a2a channel: buzz channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: irc channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: qa-channel Channel integration: qa-channel channel: raft Channel integration: Raft channel: reef Channel integration: reef channel: signal Channel integration: signal channel: slack Channel integration: slack channel: sms Channel integration: sms channel: synology-chat channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: twitch Channel integration: twitch channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: acpx extensions: admin-http-rpc extensions: anthropic extensions: arcee extensions: baseten Extension: baseten extensions: byteplus extensions: cerebras extensions: clawrouter Extension: clawrouter extensions: clickclack extensions: cloudflare-ai-gateway extensions: cohere extensions: comfy extensions: copilot-proxy Extension: copilot-proxy extensions: crabbox extensions: deepgram extensions: deepinfra extensions: deepseek extensions: diagnostics-otel Extension: diagnostics-otel extensions: diagnostics-prometheus extensions: document-extract extensions: duckduckgo extensions: featherless extensions: fish-audio Extension: fish-audio extensions: gmi extensions: huggingface extensions: image-generation-core extensions: inworld Extension: inworld extensions: kilocode extensions: litellm extensions: llama-cpp extensions: llm-task Extension: llm-task extensions: lmstudio extensions: lobster Extension: lobster extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb extensions: memory-wiki extensions: oc-path extensions: onepassword 1Password plugin extensions: policy extensions: qa-lab extensions: stepfun extensions: tencent extensions: tokenjuice Changes to the bundled tokenjuice extension extensions: vault Extension: vault extensions: web-readability extensions: webhooks gateway Gateway runtime plugin: azure-speech Azure Speech plugin plugin: beam Beam session sharing plugin plugin: bonjour Plugin integration: bonjour plugin: cua-computer plugin: file-transfer plugin: geolocation Geolocation plugin (IP to coarse city) plugin: google-meet plugin: imap plugin: linux-node plugin: logbook Logbook automatic work journal plugin plugin: migrate-claude plugin: migrate-hermes plugin: mxc plugin: pixverse plugin: teams-meetings Teams Meetings plugin plugin: visitor-access plugin: workboard plugin: zoom Zoom plugin scripts Repository scripts

Projects

None yet

4 participants