Skip to content

Commit 435a924

Browse files
authored
fix: keep exact-review health live across stale fleet cache (#534)
1 parent 20ef7f5 commit 435a924

4 files changed

Lines changed: 55 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ checkpoint, and status-only commits are intentionally omitted.
104104

105105
### Fixed
106106

107+
- Kept exact-review handoff health live when the dashboard serves a stale fleet snapshot, so recovered claims no longer leave the operator rail stuck in a delayed or stalled state.
107108
- Restored exact-review intake by deriving cancellation from `job.status`, avoiding an unsupported status-check function in step environment expressions that made GitHub reject the sweep workflow, and added checksum-pinned workflow-semantic linting to CI.
108109
- Made comment-router ledger updates retain refreshed claims at the bounded
109110
history limit, publish through fsynced atomic replacement, and fail closed on

‎dashboard/worker.ts‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,32 +1518,32 @@ export default {
15181518
async function statusJson(request, env, ctx) {
15191519
const cache = caches.default;
15201520
const cached = await cache.match(statusCacheRequest(request, "fresh"));
1521-
if (cached) return cachedStatusResponse(cached, "fresh");
1521+
if (cached) return cachedStatusResponse(cached, "fresh", env);
15221522

15231523
const stale = await cache.match(statusCacheRequest(request, "stale"));
15241524
if (stale && ctx?.waitUntil) {
15251525
ctx.waitUntil(refreshStatus(request, env).catch(() => undefined));
1526-
return cachedStatusResponse(stale, "stale");
1526+
return cachedStatusResponse(stale, "stale", env);
15271527
}
15281528

15291529
const refreshed = await refreshStatus(request, env);
1530-
if (refreshed.looksEmpty && stale) return cachedStatusResponse(stale, "stale");
1531-
return cors(
1532-
new Response(refreshed.body, {
1533-
headers: {
1534-
"content-type": "application/json; charset=utf-8",
1535-
"cache-control": "no-store",
1536-
"x-clawsweeper-cache": "miss",
1537-
},
1538-
}),
1539-
);
1530+
if (refreshed.looksEmpty && stale) return cachedStatusResponse(stale, "stale", env);
1531+
return statusSnapshotResponse(refreshed.snapshot, "miss", env);
15401532
}
15411533

1542-
function cachedStatusResponse(cached, cacheState) {
1534+
async function cachedStatusResponse(cached, cacheState, env) {
1535+
const snapshot = await cached.json();
15431536
const headers = new Headers(cached.headers);
1544-
headers.set("x-clawsweeper-cache", cacheState);
1545-
if (cacheState === "stale") headers.set("cache-control", "no-store");
1546-
return cors(new Response(cached.body, { status: cached.status, headers }));
1537+
return statusSnapshotResponse(snapshot, cacheState, env, cached.status, headers);
1538+
}
1539+
1540+
async function statusSnapshotResponse(snapshot, cacheState, env, status = 200, headers?) {
1541+
const current = await attachExactReviewQueueStatus(snapshot, env);
1542+
const responseHeaders = new Headers(headers);
1543+
responseHeaders.set("content-type", "application/json; charset=utf-8");
1544+
responseHeaders.set("cache-control", "no-store");
1545+
responseHeaders.set("x-clawsweeper-cache", cacheState);
1546+
return cors(new Response(JSON.stringify(current, null, 2), { status, headers: responseHeaders }));
15471547
}
15481548

15491549
function refreshStatus(request, env) {
@@ -3208,7 +3208,7 @@ async function statusSnapshot(env) {
32083208
const ttl = numberFrom(env.CACHE_TTL_SECONDS, 20);
32093209
const cached = await readCachedSnapshot(env, ttl);
32103210
if (cached?.bay?.timings?.sample_kind === "latest_completed_jobs") {
3211-
return attachExactReviewQueueStatus(cached, env);
3211+
return cached;
32123212
}
32133213

32143214
const github = createGithubJsonCache(env);
@@ -3368,7 +3368,7 @@ async function statusSnapshot(env) {
33683368
errors: errors.slice(0, 20),
33693369
},
33703370
};
3371-
return attachExactReviewQueueStatus(snapshot, env);
3371+
return snapshot;
33723372
}
33733373

33743374
async function attachExactReviewQueueStatus(snapshot, env) {

‎docs/live-dashboard.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ requeues. A blocked dispatcher with pending work is stalled; an intentionally
230230
paused dispatcher is degraded. `/api/status` includes this snapshot and the live
231231
dashboard renders the three phases, oldest age, available exact-review slots,
232232
and the current classification without changing queue capacity or storage
233-
schema. If the optional queue read fails, `/api/status` reports
233+
schema. Fleet snapshots may use the longer stale fallback during a GitHub API
234+
outage, but `/api/status` attaches queue telemetry after selecting that snapshot
235+
so handoff recovery stays live. If the optional queue read fails, it reports
234236
`exact_review_queue: null` and `diagnostics.exact_review_queue_error` without
235237
making the otherwise-current fleet snapshot eligible for stale fallback.
236238

‎test/dashboard-worker.test.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,10 +4770,35 @@ test("dashboard serves stale status while coalescing one background refresh", as
47704770
fleet: { active_workflow_runs: 1 },
47714771
workers: [],
47724772
pipeline: [{ id: "stale-row" }],
4773-
diagnostics: { errors: [] },
4773+
exact_review_queue: {
4774+
pending: 1,
4775+
dispatching: 1,
4776+
leased: 0,
4777+
handoff_health: { status: "stalled" },
4778+
},
4779+
diagnostics: { errors: [], exact_review_queue_error: null },
47744780
}),
47754781
);
47764782

4783+
const currentQueue = {
4784+
pending: 7,
4785+
dispatching: 0,
4786+
leased: 28,
4787+
storage_schema_version: 1,
4788+
handoff_health: {
4789+
status: "healthy",
4790+
reason: "handoff_current",
4791+
phases: {
4792+
pending: { count: 7 },
4793+
dispatching: { count: 0 },
4794+
leased: { count: 28 },
4795+
},
4796+
},
4797+
};
4798+
const exactReviewQueue = new MemoryDurableNamespace({
4799+
fetch: async () => jsonResponse(currentQueue),
4800+
});
4801+
47774802
let releaseFetch!: () => void;
47784803
const fetchGate = new Promise<void>((resolve) => {
47794804
releaseFetch = resolve;
@@ -4799,6 +4824,7 @@ test("dashboard serves stale status while coalescing one background refresh", as
47994824
CLAWSWEEPER_REPO: "openclaw/clawsweeper",
48004825
TARGET_REPOS: "openclaw/openclaw",
48014826
CACHE_TTL_SECONDS: "20",
4827+
EXACT_REVIEW_QUEUE: exactReviewQueue,
48024828
};
48034829
const context = {
48044830
waitUntil(promise: Promise<unknown>) {
@@ -4813,7 +4839,12 @@ test("dashboard serves stale status while coalescing one background refresh", as
48134839

48144840
assert.equal(first.headers.get("x-clawsweeper-cache"), "stale");
48154841
assert.equal(second.headers.get("x-clawsweeper-cache"), "stale");
4816-
assert.equal((await first.json()).pipeline[0].id, "stale-row");
4842+
const firstStatus = await first.json();
4843+
const secondStatus = await second.json();
4844+
assert.equal(firstStatus.pipeline[0].id, "stale-row");
4845+
assert.equal(firstStatus.exact_review_queue.pending, 7);
4846+
assert.equal(firstStatus.exact_review_queue.handoff_health.status, "healthy");
4847+
assert.equal(secondStatus.exact_review_queue.handoff_health.status, "healthy");
48174848
assert.equal(waitUntilPromises.length, 2);
48184849

48194850
releaseFetch();

0 commit comments

Comments
 (0)