Skip to content

[NO-JIRA] Cache-miss breaker for Gemini delegates on the state machine (R22) - #28

Merged
johnnymo87 merged 2 commits into
patched/v1.60.2from
r22-cache-miss-breaker
Nov 22, 2026
Merged

johnnymo87 merged 2 commits into
patched/v1.60.2from
r22-cache-miss-breaker

Conversation

@johnnymo87

Copy link
Copy Markdown
Owner

Description

This ports patch 22 (fork #17) onto v1.60.2. It is bead workstation-6w7i.26.4.9 (R22). It should land after the cutover.

Vertex sometimes stops serving one session from its prompt cache, so every call re-reads the whole context at full price. The breaker stops a Gemini delegate when that happens, and its lead re-dispatches the work once as a new delegate.

  • The rule is unchanged: a delegate trips after 10 consecutive calls at 50K or more prompt tokens with zero cache reads. It only applies to a Gemini model that has already reported a cache hit in this process. A final answer on the trip step is let through. GOOSE_CACHE_MISS_BREAKER=off turns it off.
  • The breaker module carries over as the fork-only agents/cache_miss_breaker.rs. Only its state-machine hook remains: ForegroundSubagentRunner::run_to_end watches the delegate's event stream using a child cancel token. A trip stops the delegate without cancelling its parent and reports the delegate's last output. The legacy-loop half went away with the legacy loop.
  • This loop always sends a step's message before its usage, so that order is now set when the breaker starts instead of being learned from the stream. Before, an empty first response, which sends only usage, made the breaker learn the wrong order and let one more full-price call through.
  • After a text-only trip, the breaker waits for the next step's usage before deciding. If the cache has recovered, the delegate keeps running.

Tests: 16 exact tests, added to patched-test.yml. Three of them are end-to-end through the real state machine with a pinned fake gcp_vertex_ai provider: it stops, it lets a final answer through, and it does nothing when off. The stop test fails without the hook. Clippy (-p goose --all-targets -D warnings) is clean.

This PR also edits run_to_end, as R16 (#26) does. It will be rebased after that merges.

References

johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from 0a6b40a to dbaade8 Compare November 22, 2026 06:16
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from dbaade8 to 7f7dd4f Compare November 22, 2026 08:18
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from 7f7dd4f to 4357c93 Compare November 22, 2026 09:06
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from 4357c93 to 7a66a91 Compare November 22, 2026 10:16
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from 7a66a91 to c670ae6 Compare November 22, 2026 11:06
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from c670ae6 to 72cdf0a Compare November 22, 2026 11:56
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
…ont and rearm a text-only trip when the next step's cache hits

An empty first response sends only usage, which latched the learned order
to usage-first and let one more full-price call through. After a text-only
trip, the next step's tool request no longer commits to stopping before its
usage says whether the cache recovered. The stop outcome mapping moves into
the fork module.

X-Shepherd-Wake: #28
@johnnymo87
johnnymo87 force-pushed the r22-cache-miss-breaker branch from 72cdf0a to b781b8f Compare November 22, 2026 12:36
@johnnymo87
johnnymo87 merged commit d21fa7b into patched/v1.60.2 Nov 22, 2026
12 checks passed
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…che stopped hitting

Port of patch 22 (fork #17) onto v1.60.2. The breaker module carries
(fork-only agents/cache_miss_breaker.rs; usage fields are i64 now). Only
the state-machine hook survives: ForegroundSubagentRunner::run_to_end
observes the delegate's AgentEvent stream with a child cancel token, so a
trip stops the delegate without touching its parent, and a breaker stop is
reported with the delegate's last output. The legacy get_agent_messages
half is gone with the legacy loop.

Rule unchanged: 10 consecutive calls at >=50K prompt tokens with zero
cache reads, on a Gemini model that has reported a hit in this process;
a final answer on the trip step is let through.
GOOSE_CACHE_MISS_BREAKER=off disables it.

X-Shepherd-Wake: #28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant