Skip to content

Commit 44cddc1

Browse files
fluffy314cursoragent
authored andcommitted
fix(agents): accept exact remote KV hits in gate
Treat a complete allens cache restore as a valid warmup without requiring redundant remote recomputation before the Primary hot-hit inference pass. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b4be50a commit 44cddc1

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

scripts/agent_gan_inference_demo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818

1919
def _agent_cache_gate(warm_delta: dict, actual_delta: dict) -> bool:
2020
return (
21-
warm_delta["remote_jobs"] >= 1
22-
and warm_delta["remote_hits"] >= 1
21+
warm_delta["remote_hits"] >= 1
22+
and warm_delta["tokens_reused"] >= 1
23+
and warm_delta["tokens_computed"] == 0
24+
and warm_delta["fallbacks"] == 0
25+
and warm_delta["remote_job_failures"] == 0
2326
and actual_delta["local_hits"] >= 1
2427
and actual_delta["remote_jobs"] == 0
2528
and actual_delta["tokens_computed"] == 0

tests/inference_engine/bridge/test_agent_gan_demo.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@
66
)
77

88

9-
def test_agent_gate_requires_remote_warmup_and_primary_hot_inference():
10-
warm = {"remote_jobs": 1, "remote_hits": 1}
9+
def test_agent_gate_accepts_remote_compute_or_exact_remote_cache_hit():
10+
warm = {
11+
"remote_jobs": 1,
12+
"remote_hits": 1,
13+
"tokens_reused": 10,
14+
"tokens_computed": 0,
15+
"fallbacks": 0,
16+
"remote_job_failures": 0,
17+
}
1118
actual = {
1219
"local_hits": 1,
1320
"remote_jobs": 0,
1421
"tokens_computed": 0,
1522
"fallbacks": 0,
1623
}
1724
assert _agent_cache_gate(warm, actual)
18-
assert not _agent_cache_gate({**warm, "remote_jobs": 0}, actual)
25+
assert _agent_cache_gate({**warm, "remote_jobs": 0}, actual)
26+
assert not _agent_cache_gate({**warm, "remote_hits": 0}, actual)
27+
assert not _agent_cache_gate({**warm, "tokens_reused": 0}, actual)
28+
assert not _agent_cache_gate({**warm, "fallbacks": 1}, actual)
29+
assert not _agent_cache_gate({**warm, "remote_job_failures": 1}, actual)
1930
assert not _agent_cache_gate(warm, {**actual, "local_hits": 0})
2031
assert not _agent_cache_gate(warm, {**actual, "fallbacks": 1})
2132

tests/inference_engine/bridge/test_agent_gan_repl.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def test_repl_stage_is_redacted_and_passes_cache_gate():
3434
"remote_jobs": 1,
3535
"remote_hits": 1,
3636
"tokens_reused": 10,
37+
"tokens_computed": 0,
38+
"fallbacks": 0,
39+
"remote_job_failures": 0,
3740
},
3841
}
3942
actual = {
@@ -101,7 +104,14 @@ def test_stage_includes_full_context_metrics():
101104
warm = {
102105
"prefix_tokens": 10,
103106
"e2e_s": 1,
104-
"delta": {"remote_jobs": 1, "remote_hits": 1, "tokens_reused": 10},
107+
"delta": {
108+
"remote_jobs": 1,
109+
"remote_hits": 1,
110+
"tokens_reused": 10,
111+
"tokens_computed": 0,
112+
"fallbacks": 0,
113+
"remote_job_failures": 0,
114+
},
105115
}
106116
actual = {
107117
"prefix_tokens": 10,

0 commit comments

Comments
 (0)