the headroom session in pi that I'm working on added headroom to do some testing, but…
- User
the headroom session in pi that I'm working on added headroom to do some testing, but then caused these errors, can we resolve this: Error: {"type":"error","error":{"details":null,"type":"invalid_request_error","message":"
cache_control.scope: \"global\"
is only valid when every preceding block is also globally scoped. A block withscope: \"global\"was found after content
with a narrower cache scope. Note that tool definitions render beforesystemblocks, soscope: \"global\"onsystem[0]is not a true prefix when tools are present. Removescope: \"global\"from the non-prefix block, or ensure all preceding
content also usesscope: \"global\"."},"request_id":"req_011Cc92yw44p3gwrXHmi8CGx" } - User
the opensync session in pi that I'm working on added headroom to do some testing, but then caused these errors, can we resolve this: Error: {"type":"error","error":{"details":null,"type":"invalid_request_error","message":"
cache_control.scope: \"global\"
is only valid when every preceding block is also globally scoped. A block withscope: \"global\"was found after content
with a narrower cache scope. Note that tool definitions render beforesystemblocks, soscope: \"global\"onsystem[0]is not a true prefix when tools are present. Removescope: \"global\"from the non-prefix block, or ensure all preceding
content also usesscope: \"global\"."},"request_id":"req_011Cc92yw44p3gwrXHmi8CGx" } Assistant· claude-opus-4-8
I'll investigate where this
scope: "global"cache_control is being set in the headroom feature.Assistant· claude-opus-4-8
Let me use codedb for searching as the hook directs.
Assistant· claude-opus-4-8
The error is from the headroom feature injecting
scope: "global"cache markers. Let me read the key files.Assistant· claude-opus-4-8
The harness doc says Pi/bridge normally uses no
scope:"global"— so headroom (a cache optimizer proxy) is the new variable injecting it. Let me confirm with hard evidence: the captured failing request and wherescope:"global"actually gets added.Assistant· claude-opus-4-8
Two headroom procs running — the dogfood
:8791and a separate:8790. The user says the culprit is "opensync". Let me find out what opensync is in headroom and whether it adds the global cache scope.Assistant· claude-opus-4-8
The codedb search overflowed. Let me grep the full headroom help for sync/global/scope flags and env vars directly.
Assistant· claude-opus-4-8
Tokenjuice is compacting the help output. Let me dump it to a file and search there directly.
Assistant· claude-opus-4-8
No
opensync/scope/globalcache flag in headroom — so headroom isn't the injector. "opensync" + "env variable" points at the claude-bridge global-cache feature. Let me locate the bridge and find wherescope:"global"is gated by an env var.Assistant· claude-opus-4-8
Let me get the exact command line for the process on :9100 (PID 27964) and find the claude-bridge source.
Assistant· claude-opus-4-8
Found it: the bridge is
/Users/luke/Projects/personal/pi-claude-bridge/index.jswith--env-file=.env. The user's "env variable" lives here. Let me inspect the bridge's global-scope logic and its.env.Assistant· claude-opus-4-8
There's a
test-global-cache-scope.jsmodified today. Let me read the.envand the global-scope logic inindex.js.Assistant· claude-opus-4-8
Found it. The env var the user means is
BRIDGE_GLOBAL_CACHE=1(.env:50, "Enabled 2026-06-17 for rollout issue #5: global cache pre/post measurement"). That's the bridge feature emittingscope:"global"— not headroom. Let me read the bridge's global-scope implementation.Assistant· claude-opus-4-8
Now let me read where the bridge applies the global marker to the real request body (and how it handles tools' cache_control).
Assistant· claude-opus-4-8
Now I understand the OAuth path. The
scope:"global"marker lands onmessages[0].content[0](the moved<system-context>stable core), and the tools get a separate org-scoped (ephemeral) breakpoint. Let me confirm the tools breakpoint and read the boot probe that's giving a false-positive confirmation.Assistant· claude-opus-4-8
Diagnosis confirmed from the code. Let me grab the live bridge log to confirm the boot probe flipped global scope ON in the currently-running process.
Assistant· claude-opus-4-8
Confirmed live:
[GLOBAL-CACHE] enabled— the no-tools probe passed and global scope is ON. Let me confirm the actual 400s are landing in the bridge log, then I'll have the full chain nailed.Assistant· claude-opus-4-8
Let me pinpoint the actual error text in the bridge log (not request-ID noise).
Assistant· claude-opus-4-8
Root cause nailed — and it's not headroom. Here's the chain:
What's happening
BRIDGE_GLOBAL_CACHE=1(your.env:50, enabled today for "rollout issue #5: global cache pre/post measurement") makes the claude-bridge stampcache_control.scope:"global"on the byte-stable<system-context>core. The live bridge confirms it's active:[GLOBAL-CACHE] enabled: scope:"global" accepted on the static system prefixAssistant· claude-opus-4-8
Patch + restart it is. Let me check the bridge repo state and read the existing global-cache test before I touch the critical path.
Assistant· claude-opus-4-8
On
fix/global-cache-runtime-followups(clean tree) — already the global-cache fix branch, exactly the right place. Let me read the test scripts and the existing global-cache test.Assistant· claude-opus-4-8
Now I see why the bug slipped through: the test's
piPayload()(line 73) and the boot probe both omit tools, exactly like production's blind spot. Let me check two more functions that run afteraddCacheBreakpoints—clampCacheControlsandapplyExtendedCacheTtl— so my fix can't be undone downstream.Assistant· claude-opus-4-8
Both
applyExtendedCacheTtlandclampCacheControlspreservescope(spread) and in the OAuth global path the marker count is exactly 4, so clamp is a no-op there — my fix is safe downstream. Now let me read the exact source regions I'll edit (need byte-exact text).- User
[Request interrupted by user]
- User
continue
Assistant· claude-opus-4-8
Now I have exact source. Per the bugfix discipline I'll add the regression guard to the test first, prove it fails on the current (unfixed) bridge, then apply the production fix and prove it passes.
Let me start with the test + mock changes.
Assistant· claude-opus-4-8
Now add tools to the fixture payload so the real-session shape is exercised:
Assistant· claude-opus-4-8
Now add assertions to the happy-path scenario for the tools breakpoint scope and the probe's tools shape:
Assistant· claude-opus-4-8
Now run the test against the unfixed bridge to prove the regression guard fails on baseline:
Assistant· claude-opus-4-8
Baseline fails with 9 assertions — the mock now rejects the exact production shape (org tools breakpoint before the global core), reproducing the 400. Now the production fix.
Assistant· claude-opus-4-8
Now fix the boot probe so it sends tools (matching the live shape) — closing the false-positive gate:
Assistant· claude-opus-4-8
All green on the fix. Let me run the full bridge test suite to confirm no regressions elsewhere.
Assistant· claude-opus-4-8
Full suite green. Now the restart so the running bridge picks up the fix — and crucially, the boot probe will tell us live whether Anthropic accepts the corrected
tools-global → core-globalprefix shape.Assistant· claude-opus-4-8
Bridge restarted. Let me wait for it to come healthy and run its boot probe, then read the fresh
[GLOBAL-CACHE]verdict from the log (using node to poll, avoiding a foreground sleep).Assistant· claude-opus-4-8
Live confirmation: the restarted bridge ran the corrected probe (now carrying tools with a global breakpoint) and real Anthropic accepted it —
enabled: scope:"global" accepted on the static system+tools prefix. The fixed prefix shape is valid upstream.Now the definitive end-to-end check: push one real tool-bearing, stable-core-marked request through the bridge (the full production marker path) and confirm it returns 200, not the scope 400.
Assistant· claude-opus-4-8
End-to-end verified: HTTP 200,
cache_creation_input_tokens: 3687written to the 1h cache — the full production marker path (global tools breakpoint → global core, org tail) is accepted by Anthropic. No scope:global 400.Let me show the diff that's now live on the bridge.
Assistant· claude-opus-4-8
- User
ok commit and push
Assistant· claude-opus-4-8
I'll commit on the branch and push. Let me verify remote/upstream first (never want to push to a repo I don't own).
Assistant· claude-opus-4-8
originis your ownvalkyriweb/pi-claude-bridge, trackingorigin/fix/global-cache-runtime-followups. Safe to push. Committing the two files and pushing.Assistant· claude-opus-4-8
Pushed:
c0d644e..bdea494→origin/fix/global-cache-runtime-followups(yourvalkyriweb/pi-claude-bridge).- Commit
bdea494—fix(bridge): global-scope the tools breakpoint so the cache prefix is valid. - Tree is clean; bridge is patched, restarted, and verified live (probe 200 + real request 200 with cache write).
- Note: there's also a
macminiremote (server mirror) — I only pushed toorigin. Say the word if you want it mirrored there too.
Still open (your call, untouched): the stale claim in
my-pi/docs/headroom-dogfood.mdthat blames the 400 on the "old sandbox."State: complete — committed and pushed to origin.
- Commit
- User
fix the stale claim
Assistant· claude-opus-4-8
Fixed.
my-pi/docs/headroom-dogfood.mdnow states the truth: thescope:"global"400 was a real bridge bug (global core rendering behind an org-scoped tools breakpoint; toolless probe false-confirming), not an old-sandbox or Headroom artifact — and points at thebdea494fix with the live verification. It also keeps the still-true point that Headroom is never in the marker path.I left it uncommitted —
my-piis onlue/fuse-failure-reportingwith a pile of your unrelated WIP dirty in the tree, so I didn't want to presume a commit or sweep in other files. Want me to commit just this one doc file?State: complete — stale claim corrected; awaiting your call on committing the doc.