Skip to content

Commit 9f343df

Browse files
yetvalsteipete
andauthored
fix(queue): keep the owed source-drift review when a completion callback is lost (#1251)
The Complete exact-review queue lease callback is the only carrier of direct_lifecycle_requeue, and both fallbacks that engage when it cannot reach the durable queue ignore that metadata. After an accepted direct publication the run stays green by design, so the workflow_run reconciler heals the still-leased item from the bare run conclusion and deletes it, discarding the source-drift follow-up review the callback would have created and removing the lease-expiry backstop with it. The accepted receipt already rewrote the leased item's decision to a publication decision carrying its directLifecycle plan, so /reconcile now recognises an owed requeue and heals it through the same requeueDirectLifecyclePublicationSync the /complete handler calls, recording the same requeue terminal fact on the fenced projection. In the durable-queue lane the same callback loss reddens the run, and the fail gate's single hardcoded annotation blamed classification=codex_or_content_failure even when its own fields reported review_outcome=success, and also for held reservations whose review never ran. The gate now derives the classification by reusing its own review-lane clause, so a completion failure reports queue_completion_failure while a genuine review failure keeps codex_or_content_failure. The gate's if-expression is unchanged, so exactly the same runs go red. Adds regression coverage for the healed requeue, for an unchanged green-run completion with no owed requeue, and for the classification expression staying in sync with the gate clause it mirrors. Replaces the in-memory drift driver with a Docker-backed Crabbox local-container harness that runs the real Wrangler Worker and its ExactReviewQueue Durable Object, drives both scenarios over the real signed routes against real SQLite storage, and captures the Bay telemetry tables and the public /api/durable-lifecycle-bay snapshot on either side of the recovery. Fixes #1245 Co-authored-by: Peter Steinberger <[email protected]>
1 parent 0d07398 commit 9f343df

8 files changed

Lines changed: 304 additions & 12 deletions

File tree

‎.github/workflows/sweep.yml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,11 +1960,21 @@ jobs:
19601960
)
19611961
}}
19621962
env:
1963+
CLASSIFICATION: >-
1964+
${{
1965+
(
1966+
steps.exact-review-generation-result.outputs.outcome != 'success' &&
1967+
steps.exact-review-generation-result.outputs.retry_kind == '' &&
1968+
steps.reserve-exact-review-lease.outputs.status != 'held' &&
1969+
steps.reserve-exact-review-lease.outputs.status != 'superseded'
1970+
) && 'codex_or_content_failure' || 'queue_completion_failure'
1971+
}}
1972+
COMPLETION_OUTCOME: ${{ steps.complete-exact-review-queue.outcome || 'not_started' }}
19631973
RESERVATION_STATUS: ${{ steps.reserve-exact-review-lease.outputs.status || 'unknown' }}
19641974
REVIEW_EXIT_CODE: ${{ steps.review-exact-event-item.outputs.exit_code || 'unknown' }}
19651975
REVIEW_OUTCOME: ${{ steps.review-exact-event-item.outcome || 'not_started' }}
19661976
run: |
1967-
echo "::error::Exact review generation failed: classification=codex_or_content_failure reservation=$RESERVATION_STATUS review_outcome=$REVIEW_OUTCOME review_exit=$REVIEW_EXIT_CODE"
1977+
echo "::error::Exact review run failed: classification=$CLASSIFICATION reservation=$RESERVATION_STATUS review_outcome=$REVIEW_OUTCOME review_exit=$REVIEW_EXIT_CODE queue_completion=$COMPLETION_OUTCOME"
19681978
exit 1
19691979
19701980
event-review-publish:

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ checkpoint, and status-only commits are intentionally omitted.
7070

7171
### Fixed
7272

73+
- Preserved owed source-drift reviews when completion callbacks are lost, and distinguished queue-completion failures from review failures. Thanks @yetval. (#1251)
74+
7375
- Stopped retrying unchanged PR revisions after an incomplete-source scan refusal while preserving newer queued revisions. Thanks @sallyom. (#1311)
7476
- Stopped stored-data and SQLite warnings for colocated test-support files while preserving production persistence, rename, and incomplete-evidence warnings.
7577
- Aligned PR proof comments and status labels with the existing host requirement when a reviewer records proof as not applicable, while preserving recorded assessments and merge gates.

‎dashboard/exact-review-queue.ts‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,17 +3505,38 @@ export class ExactReviewQueue {
35053505
);
35063506
if (matches.length !== 1) continue;
35073507
const item = matches[0];
3508-
const { requeued: didRequeue, parked } = finishExactReviewQueueItem(
3509-
state,
3510-
item,
3511-
now,
3512-
run.outcome,
3513-
0,
3514-
false,
3515-
undefined,
3516-
undefined,
3517-
this.random,
3518-
);
3508+
const leaseRevision = Number(item.leaseRevision || 0);
3509+
const directLifecycle = item.decision.publication?.directLifecycle;
3510+
const owedDirectLifecycleRequeue =
3511+
run.outcome === "success" &&
3512+
item.revision <= leaseRevision &&
3513+
directLifecycle?.plan.kind === "requeue" &&
3514+
(directLifecycle.receiptOutcome === "accepted" ||
3515+
directLifecycle.receiptOutcome === "deduped");
3516+
if (owedDirectLifecycleRequeue) {
3517+
this.recordLifecycleTerminal(
3518+
{
3519+
canonicalTargetKey: `${item.decision.targetRepo}#${item.decision.itemNumber}`,
3520+
fenceKey: item.key,
3521+
revision: leaseRevision,
3522+
kind: "requeue",
3523+
},
3524+
now,
3525+
);
3526+
}
3527+
const { requeued: didRequeue, parked } = owedDirectLifecycleRequeue
3528+
? this.requeueDirectLifecyclePublicationSync(state, item, now)
3529+
: finishExactReviewQueueItem(
3530+
state,
3531+
item,
3532+
now,
3533+
run.outcome,
3534+
0,
3535+
false,
3536+
undefined,
3537+
undefined,
3538+
this.random,
3539+
);
35193540
reconciled += 1;
35203541
if (parked) continue;
35213542
if (didRequeue) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Lost completion callback proof
2+
3+
The production Worker and ExactReviewQueue were exercised on AWS Crabbox with
4+
Node 24 and local Wrangler/workerd SQLite. Only initial lease setup and state
5+
inspection use proof seams; publication, completion, reconciliation, signatures,
6+
and lifecycle transitions use the production paths.
7+
8+
The same three scenarios run before and after the fix:
9+
10+
| Scenario | Main at `0d07398d4fab` | Fixed branch |
11+
| --- | --- | --- |
12+
| Completion delivered | One fresh source-drift revision | Same |
13+
| Completion lost, accepted receipt | Owed review deleted | One fresh source-drift revision |
14+
| Completion lost, superseded receipt | Completes without another review | Same |
15+
16+
Requeue disposition leaves Bay outcome tables and its public snapshot unchanged.
17+
A separate workflow replay executes the real failure-annotation shell: a lost
18+
queue callback is reported as `queue_completion_failure`; a failed review remains
19+
`codex_or_content_failure`.
20+
21+
## Reproduce
22+
23+
The immutable drivers remain in the contributor's original commit, keeping
24+
one-off proof scaffolding out of the maintained runtime and test tree. From a
25+
checkout with dependencies installed:
26+
27+
```sh
28+
mkdir -p .artifacts/completion-proof
29+
proof_ref=138eacf9b30ced7465be928d9d6022f5647fa7d9
30+
proof_path=docs/proof/exact-review-completion-metadata
31+
git fetch origin "$proof_ref"
32+
git show "$proof_ref:$proof_path/run-proof.sh" > .artifacts/completion-proof/run.sh
33+
git show "$proof_ref:$proof_path/annotation-proof.mjs" > .artifacts/completion-proof/annotation.mjs
34+
COMPLETION_METADATA_PROOF_SKIP_INSTALL=1 bash .artifacts/completion-proof/run.sh
35+
node .artifacts/completion-proof/annotation.mjs
36+
```
37+
38+
The runtime driver writes `proof-summary.json` and `transcript.md` under
39+
`.artifacts/exact-review-completion-metadata`. Run it from the baseline and
40+
candidate checkouts separately. It uses disposable SQLite and synthetic items,
41+
with no production credentials or state mutations.
42+
43+
## Limits and evidence
44+
45+
The proof supplies the same terminal-run payload as the GitHub reconciler;
46+
it does not exercise GitHub's run lookup or induce a production queue outage.
47+
Local workerd proves the storage and HTTP behavior, not Cloudflare edge
48+
availability. The annotation replay evaluates the workflow expressions locally.
49+
50+
Provider, lease, image, exact revision, commands, results, and subsequent
51+
production deployment are recorded in the [PR proof](https://github.com/openclaw/clawsweeper/pull/1251).
52+
The regression matrix additionally covers deduplicated receipts and repeat
53+
reconciliation, asserting that the latter does not create another revision.

‎docs/scheduler.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ Manual exact-item `workflow_dispatch` reviews use an exact-item concurrency
7474
group with the same single-pending policy, so newer revisions replace stale
7575
pending work instead of building a duplicate queue. Durable exact-review leases
7676
use lease-scoped workflow groups and remain owned by the Worker admission lane.
77+
If a successful exact-review run loses its completion callback, reconciliation
78+
uses the accepted or deduplicated direct-publication receipt to preserve an
79+
owed source-drift review. A superseded receipt or a newer queued revision does
80+
not create another review. Queue-completion failures remain visible separately
81+
from Codex or content failures.
82+
7783
Recoverable parked reviews use the nominal 5/10/20-minute retry ladder, but
7884
each item persists a schedule-time uniform jitter of 0.75-1.5x for every rung.
7985
After the third automatic recovery, operator-only HMAC-signed routes provide a

‎test/dashboard-worker-harness.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import {
3737
triageRoutingGroupsForLabels,
3838
} from "../dashboard/triage-routing-groups.ts";
3939
import { ExactReviewPublicationBatchStore } from "../dashboard/exact-review-publication-batches.ts";
40+
import {
41+
ExactReviewDirectPublicationStore,
42+
validateDirectPublicationPlan,
43+
} from "../dashboard/exact-review-direct-publication.ts";
4044
import type { ExactReviewQueueItem } from "../dashboard/exact-review-queue.ts";
4145
import {
4246
commandAcknowledgementState,
@@ -1058,6 +1062,8 @@ export {
10581062
TRIAGE_ROUTING_GROUPS,
10591063
triageRoutingGroupsForLabels,
10601064
ExactReviewPublicationBatchStore,
1065+
ExactReviewDirectPublicationStore,
1066+
validateDirectPublicationPlan,
10611067
commandAcknowledgementState,
10621068
EXACT_REVIEW_ACKNOWLEDGEMENT_ATTEMPT_LEASE_MS,
10631069
ExactReviewLifecycleProjectionStore,

‎test/dashboard-worker-publication-lifecycle.test.ts‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
ExactReviewQueue,
88
mergeBayJourneyState,
99
ExactReviewPublicationBatchStore,
10+
ExactReviewDirectPublicationStore,
11+
validateDirectPublicationPlan,
1012
commandAcknowledgementState,
1113
ExactReviewLifecycleProjectionStore,
1214
lifecycleState,
@@ -969,6 +971,149 @@ test("direct lifecycle requeue becomes a fresh fenced source-drift revision", as
969971
);
970972
});
971973

974+
for (const scenario of [
975+
{ receipt: "accepted", lifecycle: "requeue", requeued: true },
976+
{ receipt: "deduped", lifecycle: "requeue", requeued: true },
977+
{ receipt: "superseded", lifecycle: "requeue", requeued: false },
978+
{ receipt: "accepted", lifecycle: undefined, requeued: false },
979+
] as const) {
980+
test(`lost completion reconciles ${scenario.receipt} receipt with ${scenario.lifecycle ?? "no"} plan`, async () => {
981+
const storage = new MemoryDurableStorage();
982+
const leased = leasedExactReviewQueueItem(705, "7050");
983+
leased.revision = 4;
984+
leased.leaseRevision = 4;
985+
leased.claimGeneration = 2;
986+
await storage.put("exact-review-queue", { deliveries: {}, items: { [leased.key]: leased } });
987+
const queue = new ExactReviewQueue({ storage }, {});
988+
const env = {
989+
CLAWSWEEPER_WEBHOOK_SECRET: "test-secret",
990+
EXACT_REVIEW_QUEUE: new MemoryDurableNamespace(queue),
991+
};
992+
const post = (route: string, value: unknown) => {
993+
const body = JSON.stringify(value);
994+
return worker.fetch(
995+
new Request(`https://clawsweeper.openclaw.ai/internal/exact-review/${route}`, {
996+
method: "POST",
997+
headers: {
998+
"x-clawsweeper-exact-review-signature": `sha256=${createHmac("sha256", "test-secret").update(body).digest("hex")}`,
999+
},
1000+
body,
1001+
}),
1002+
env,
1003+
);
1004+
};
1005+
const publication = {
1006+
canonicalTargetKey: leased.key,
1007+
fenceKey: leased.key,
1008+
revision: 4,
1009+
sourceSha: "e".repeat(40),
1010+
identity: {
1011+
canonicalTargetKey: leased.key,
1012+
fenceKey: leased.key,
1013+
revision: 4,
1014+
claimGeneration: 2,
1015+
},
1016+
operations: [
1017+
{
1018+
path: "records/openclaw-openclaw/items/705.md",
1019+
deleted: false,
1020+
mode: "100644",
1021+
bytes: 1,
1022+
contentBase64: "eA==",
1023+
},
1024+
],
1025+
totalBytes: 1,
1026+
...(scenario.lifecycle ? { lifecycle: { kind: scenario.lifecycle } } : {}),
1027+
};
1028+
if (scenario.receipt === "superseded") {
1029+
const newerPublisher = new ExactReviewDirectPublicationStore(storage);
1030+
newerPublisher.ensureSchemaSync();
1031+
const newer = await validateDirectPublicationPlan({
1032+
...publication,
1033+
revision: 5,
1034+
identity: { ...publication.identity, revision: 5 },
1035+
lifecycle: { kind: "policy_noop" },
1036+
});
1037+
assert.equal(newerPublisher.accept(newer, Date.now()).outcome, "accepted");
1038+
}
1039+
if (scenario.receipt === "deduped") {
1040+
const first = await post("publication-results", publication);
1041+
assert.equal(first.status, 202);
1042+
assert.equal((await first.json()).accepted, true);
1043+
}
1044+
const receipt = await post("publication-results", publication);
1045+
assert.equal(receipt.status, 202);
1046+
assert.equal((await receipt.json())[scenario.receipt], true);
1047+
const readState = async () =>
1048+
(await storage.get("exact-review-queue")) as {
1049+
items: Record<
1050+
string,
1051+
{
1052+
state: string;
1053+
revision: number;
1054+
leaseId?: string;
1055+
admissionDeliveryId?: string;
1056+
decision: {
1057+
sourceAction: string;
1058+
publication?: {
1059+
directLifecycle?: { plan: { kind: string }; receiptOutcome: string };
1060+
};
1061+
};
1062+
}
1063+
>;
1064+
};
1065+
if (scenario.lifecycle) {
1066+
assert.deepEqual(
1067+
(await readState()).items[leased.key]?.decision.publication?.directLifecycle,
1068+
{
1069+
plan: { kind: scenario.lifecycle },
1070+
receiptOutcome: scenario.receipt === "deduped" ? "accepted" : scenario.receipt,
1071+
},
1072+
);
1073+
}
1074+
const terminalRun = {
1075+
terminal_runs: [
1076+
{
1077+
run_id: leased.claimedRunId,
1078+
run_attempt: leased.claimedRunAttempt,
1079+
claimed_run_attempt: leased.claimedRunAttempt,
1080+
claim_generation: 2,
1081+
outcome: "success",
1082+
},
1083+
],
1084+
};
1085+
const reconciled = await post("reconcile", terminalRun);
1086+
assert.equal(reconciled.status, 200);
1087+
assert.deepEqual(await reconciled.json(), {
1088+
ok: true,
1089+
reconciled: 1,
1090+
requeued: Number(scenario.requeued),
1091+
completed: Number(!scenario.requeued),
1092+
});
1093+
const item = (await readState()).items[leased.key];
1094+
if (scenario.requeued) {
1095+
assert.equal(item?.state, "pending");
1096+
assert.equal(item?.revision, 5);
1097+
assert.equal(item?.leaseId, undefined);
1098+
assert.equal(item?.decision.sourceAction, "source_drift_requeue");
1099+
assert.equal(item?.decision.publication, undefined);
1100+
assert.equal(item?.admissionDeliveryId, `direct-lifecycle-requeue:${leased.key}:4`);
1101+
} else {
1102+
assert.equal(item, undefined);
1103+
}
1104+
if (scenario.lifecycle) {
1105+
assert.equal(
1106+
new ExactReviewLifecycleProjectionStore(storage).read(leased.key, leased.key, 4)
1107+
?.terminalDisposition?.kind,
1108+
scenario.requeued ? "requeue" : "superseded",
1109+
);
1110+
}
1111+
const repeated = await post("reconcile", terminalRun);
1112+
assert.deepEqual(await repeated.json(), { ok: true, reconciled: 0, requeued: 0, completed: 0 });
1113+
assert.deepEqual((await readState()).items[leased.key], item);
1114+
});
1115+
}
1116+
9721117
test("direct lifecycle requeue preserves a newer command follow-up revision", async () => {
9731118
const storage = new MemoryDurableStorage();
9741119
const leased = leasedExactReviewQueueItem(704, "7040");

‎test/sweep-workflow.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,55 @@ test("exact event review publishes directly with a queue-bounded canonical fallb
12371237
failureGateCase.name,
12381238
);
12391239
}
1240+
const evaluateClassification = (values: Record<string, string>): string => {
1241+
const expression = (failGeneration.env?.CLASSIFICATION ?? "")
1242+
.replace(/^\s*\$\{\{\s*|\s*\}\}\s*$/g, "")
1243+
.replace(
1244+
/steps\.([a-z0-9-]+)\.(outputs\.([a-z0-9_]+)|outcome)/g,
1245+
(_match, stepId: string, access: string, outputName?: string) =>
1246+
JSON.stringify(values[`${stepId}.${outputName ?? access}`] ?? ""),
1247+
);
1248+
return String(Function(`"use strict"; return (${expression});`)());
1249+
};
1250+
const classificationCases = [
1251+
{
1252+
name: "completion failure after a successful review",
1253+
values: {
1254+
"complete-exact-review-queue.outcome": "failure",
1255+
"reserve-exact-review-lease.status": "posted",
1256+
"exact-review-generation-result.outcome": "success",
1257+
"exact-review-generation-result.retry_kind": "",
1258+
},
1259+
expected: "queue_completion_failure",
1260+
},
1261+
{
1262+
name: "completion failure after a held deferral",
1263+
values: {
1264+
"complete-exact-review-queue.outcome": "failure",
1265+
"reserve-exact-review-lease.status": "held",
1266+
"exact-review-generation-result.outcome": "failure",
1267+
"exact-review-generation-result.retry_kind": "coordination",
1268+
},
1269+
expected: "queue_completion_failure",
1270+
},
1271+
{
1272+
name: "review lane failure after a durable completion",
1273+
values: {
1274+
"complete-exact-review-queue.outcome": "success",
1275+
"reserve-exact-review-lease.status": "posted",
1276+
"exact-review-generation-result.outcome": "failure",
1277+
"exact-review-generation-result.retry_kind": "",
1278+
},
1279+
expected: "codex_or_content_failure",
1280+
},
1281+
] as const;
1282+
for (const classificationCase of classificationCases) {
1283+
assert.equal(
1284+
evaluateClassification(classificationCase.values),
1285+
classificationCase.expected,
1286+
classificationCase.name,
1287+
);
1288+
}
12401289
assert.match(releaseGeneration.if ?? "", /reserve-exact-review-lease\.outputs\.status != 'held'/);
12411290
assert.match(releaseGeneration.run ?? "", /content == "eyes"/);
12421291
for (const cleanup of [releaseGeneration, step(reviewer, "Mark unsuccessful re-review")]) {

0 commit comments

Comments
 (0)