Skip to content

Commit ae36d60

Browse files
authored
feat(operator): evidence-gated superseded resolution for head-mismatch dead letters (#1148)
DLQ endgame: head-mismatch dead letters resolve as superseded when - and only when - the durable state record proves a newer-head review completed. Evidence baseline: reconcile run 31648987909, the first with the #1147 skip taxonomy, showed the stuck tail is 121/125 head_mismatch - stale review artifacts whose recorded source head no longer matches the live PR head and which must never republish as-is. The new bounded reconcile stage queries the authoritative HMAC state record (/internal/state/records/<repo>/items/<n>) and requires matching repository, number, PR type, review_status complete, digest, and live pull_head_sha before resolving; lifecycle lanes are corroboration only. Without that proof the row stays open under head_mismatch_unproven with samples. Caps: 10 targets/cycle, 20 rows/target; live node/head revalidated immediately before mutation; dry-run honored; tuple_protocol_invalid and workflow_cancelled out of scope; superseded metrics recorded honestly. Proof: Crabbox local-container receipt (docs/proof/head-mismatch-supersede/); red 4 operator contract failures + 1 Worker metric failure -> green 224/224 focused; full gate 3391/0. Verdict clean (no actionable findings) on the final head.
1 parent 9a25790 commit ae36d60

13 files changed

Lines changed: 1203 additions & 13 deletions

‎dashboard/exact-review-queue.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,9 +4678,17 @@ export class ExactReviewQueue {
46784678
const body = objectValue(value);
46794679
const ids = exactReviewDeadLetterIds(body.ids);
46804680
const note = String(body.note || "").trim();
4681+
const resolutionOutcome =
4682+
body.resolution_outcome === undefined ? null : String(body.resolution_outcome || "");
46814683
if (!ids) return json({ error: "invalid_dead_letter_ids" }, 400);
46824684
if (!note || note.length > 500) return json({ error: "invalid_resolution_note" }, 400);
4685+
if (resolutionOutcome !== null && resolutionOutcome !== "superseded") {
4686+
return json({ error: "invalid_resolution_outcome" }, 400);
4687+
}
46834688
const guarded = body.resolution_aliases !== undefined;
4689+
if (resolutionOutcome === "superseded" && !guarded) {
4690+
return json({ error: "invalid_resolution_guard" }, 400);
4691+
}
46844692
const resolutionAliases = exactReviewRecoveryAliases(body.resolution_aliases, ids, {
46854693
maxIds: 20,
46864694
allowEmpty: true,
@@ -4734,6 +4742,12 @@ export class ExactReviewQueue {
47344742
if (resolved) {
47354743
const state = this.readStateSync();
47364744
unparked = this.drainParkedDeadLettersSync(state, now);
4745+
if (resolutionOutcome === "superseded") {
4746+
this.incrementQueueMetricsSync({
4747+
publicationCompleted: resolved,
4748+
publicationSuperseded: resolved,
4749+
});
4750+
}
47374751
if (unparked) {
47384752
this.writeStateSync(state);
47394753
this.incrementQueueMetricsSync({
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Head-mismatch dead-letter supersession proof
2+
3+
Production reconcile run `31648987909` at `2026-08-12T22:56:00Z`, the first run with the skip taxonomy from [openclaw/clawsweeper#1147](https://github.com/openclaw/clawsweeper/pull/1147), inspected 125 skipped targets and reported `head_mismatch: 121`, `blocked_alias: 3`, and `active_work: 1`, with zero recoveries. The open DLQ tail held 191 rows: 158 `retry_exhausted`, 31 `tuple_protocol_invalid`, and two `workflow_cancelled`. Samples such as [openclaw/acpx#485](https://github.com/openclaw/acpx/pull/485) and [openclaw/crabpot#245](https://github.com/openclaw/crabpot/pull/245) showed the endgame: immutable publication artifacts for old pull-request heads must never be replayed as current work.
4+
5+
The existing HMAC-authenticated canonical record route is the authority needed to distinguish genuinely superseded work from unexplained drift: `GET /internal/state/records/<repo-slug>/items/<number>`. Its Durable Object envelope contains the canonical content, digest, monotonic revision, and update time. The report content binds `repository`, `number`, `type`, `review_status`, and `pull_head_sha`. A complete same-target report at the live GitHub head proves that a stale dead-letter artifact for another head has been replaced by a durable completed review/publication. No new endpoint is needed.
6+
7+
The authenticated lifecycle audit inventory is useful corroboration—it exposes completed and superseded lanes plus canonical receipt outcomes—but intentionally omits source heads, so it cannot independently prove newer-head supersession. Public queue lane totals are aggregate-only for the same reason.
8+
9+
The bounded stage checks at most ten head-mismatched targets per cycle and resolves at most 20 supported rows per proven target. After reading canonical evidence, it immediately rechecks GitHub and requires the same open node identity and head before mutation. Drift leaves the row open as `head_mismatch_revalidation_changed`. A successful path writes a note with the full newer head and canonical path, sends the Worker a guarded `resolution_outcome: superseded`, and increments publication completed/superseded metrics. Missing, invalid, incomplete, wrong-target, failed, or wrong-head records leave rows open as `head_mismatch_unproven`. `tuple_protocol_invalid` and `workflow_cancelled` rows never enter this resolution path. Dry-run reports the planned counts but performs no mutation.
10+
11+
The executable contract is in [`behavior-contract.md`](behavior-contract.md), RED/GREEN evidence is in [`red-green.md`](red-green.md), and [`run-proof.sh`](run-proof.sh) is the Docker-backed Crabbox launcher. [`behavior-report.json`](behavior-report.json) records the source-blind contract result. [`receipt.json`](receipt.json) binds committed implementation head `10b45760a0c0fe1adf156909e2df0d737d5fef6a`, `provider=local-container`, lease `cbx_a7a8d9e75f26` (`brisk-shrimp-3201`), Docker image `node:24-bookworm`, all 224 focused scenarios passing (including the mutation-time B→C race), the full `pnpm run check` gate, clean pre-commit Codex autoreview, content hashes, captured transcripts, a zero-finding secret scan, and automatic lease cleanup.
12+
13+
OpenClaw Bay needs no change because the behavior is queue-owned and observer-only: existing metrics and skip maps reflect it, while Bay gains no action surface.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Head-mismatch dead-letter supersession behavior contract
2+
3+
## User-visible goal
4+
5+
The exact-review dead-letter operator drains stale publication artifacts only when the operator can prove that the same pull request has a completed canonical review at its current, different head. Head drift by itself never authorizes resolution or replay.
6+
7+
## Target
8+
9+
- Type: operator CLI and HMAC-authenticated queue API.
10+
- Access: `node scripts/exact-review-dead-letter-operator.mjs --action reconcile` against loopback queue and GitHub stubs.
11+
- Fixtures: sanitized dead-letter rows, GitHub pull-request identities, canonical record envelopes, queue pressure, and guarded mutation responses. No production credential or endpoint is used.
12+
13+
## Operator tasks and expected behavior
14+
15+
1. Reconcile a `retry_exhausted` publication whose recorded source head differs from the live pull-request head and whose signed canonical `items/<number>` record identifies the same repository, item number, pull-request type, `review_status: complete`, and live `pull_head_sha`.
16+
- Resolve the stale row with `resolution_outcome: superseded`.
17+
- Record an audit note naming the full newer head and exact canonical-record endpoint.
18+
- Re-read GitHub immediately before resolution and require the same open node identity and head used by the canonical evidence.
19+
- Do not enqueue or recover a review.
20+
- Increment the queue publication completed and superseded totals without incrementing published.
21+
2. Reconcile the same mismatch when the canonical record is missing, malformed, incomplete, for another target, failed, or at another head.
22+
- Leave the row open.
23+
- Count the target as `head_mismatch_unproven` with the existing bounded sanitized sample shape.
24+
- Do not call the resolution or recovery mutation.
25+
3. Reconcile more work than one cycle permits.
26+
- Inspect at most ten head-mismatch targets for supersession.
27+
- Resolve at most `MAX_RESOLUTION_IDS` (20) rows for one proven target.
28+
- Leave excess work open with explicit target-cap or partial-row classifications.
29+
4. Run with `execute=false`.
30+
- Report the same planned superseded target and row counts.
31+
- Perform no queue mutation.
32+
5. Encounter `tuple_protocol_invalid` or `workflow_cancelled` head-mismatched rows.
33+
- Leave them open and do not query supersession evidence for an otherwise excluded-only target.
34+
35+
## Anti-cheat probes
36+
37+
- Change the canonical record head away from the live GitHub head; resolution must stop.
38+
- Advance the live pull-request head after canonical evidence is read but before resolution; resolution must stop.
39+
- Remove the canonical record; resolution must stop.
40+
- Cross the ten-target and 20-row boundaries; only the bounded prefix may resolve.
41+
- Repeat the positive fixture without `--execute`; the output may plan resolution but the stub must observe zero mutations.
42+
- Pass a typed superseded outcome without resolution aliases; the Worker must reject it.
43+
44+
## Evidence required
45+
46+
- RED results from fresh `origin/main` showing the new contract failures.
47+
- GREEN loopback results for the complete operator and queue-runtime test files.
48+
- Docker-backed Crabbox `local-container` transcript at the committed implementation head.
49+
- Full `pnpm run check`, clean Codex autoreview, content hashes, secret scan, provider/lease identity, and cleanup state.
50+
51+
## Limits
52+
53+
The loopback fixtures prove the real CLI process and Durable Object route behavior at their HTTP boundaries. They do not mutate the production queue, consume GitHub quota, or prove that a particular production dead letter currently has a matching canonical record. `tuple_protocol_invalid` and `workflow_cancelled` resolution policy remains out of scope.
54+
55+
OpenClaw Bay is unaffected. This change uses existing observer-only queue metrics and the dynamic skip-reason map; it adds no queue, workflow, GitHub, recovery, deploy, or rollback action to Bay.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"overall_behavior": "satisfies_contract",
3+
"overall_confidence": 0.98,
4+
"target": {
5+
"type": "operator CLI and HMAC-authenticated queue API",
6+
"access": "Docker-backed Crabbox local-container loopback fixtures"
7+
},
8+
"checks": [
9+
{
10+
"contract_clause": "Proven newer-head supersession",
11+
"status": "pass",
12+
"severity": null,
13+
"evidence": "The operator and queue-runtime suites observed one guarded superseded resolution with the full newer head and canonical items endpoint in its note, zero review recovery, publication completed/superseded increments, and no published increment.",
14+
"reproduction_steps": [
15+
"Serve one stale retry_exhausted publication row",
16+
"Serve a different live pull-request head",
17+
"Serve a digest-valid complete canonical record for the same target and live head",
18+
"Run reconcile with execute enabled and inspect stub mutations plus queue stats"
19+
],
20+
"confidence": 0.99
21+
},
22+
{
23+
"contract_clause": "Unproven mismatch remains open",
24+
"status": "pass",
25+
"severity": null,
26+
"evidence": "Missing and wrong-head canonical records produced head_mismatch_unproven with bounded diagnostics and zero resolution or recovery mutations.",
27+
"reproduction_steps": [
28+
"Return record_not_found for the signed canonical GET",
29+
"Repeat with a valid canonical envelope bound to a head other than the live head",
30+
"Verify both rows remain open and no mutation endpoint is called"
31+
],
32+
"confidence": 0.99
33+
},
34+
{
35+
"contract_clause": "Mutation-time head revalidation",
36+
"status": "pass",
37+
"severity": null,
38+
"evidence": "The race fixture served canonical evidence for head B and advanced GitHub to head C before resolution. The operator performed the second issue/pull read, emitted head_mismatch_revalidation_changed, and called neither resolution nor recovery.",
39+
"reproduction_steps": [
40+
"Serve stale dead-letter head A and initial live head B",
41+
"Serve a digest-valid complete canonical record for head B",
42+
"Return head C on the immediate pre-mutation GitHub recheck",
43+
"Verify the row remains open with zero mutation"
44+
],
45+
"confidence": 0.99
46+
},
47+
{
48+
"contract_clause": "Target and row caps",
49+
"status": "pass",
50+
"severity": null,
51+
"evidence": "Eleven proven targets yielded ten evidence reads/resolutions and one head_mismatch_resolution_cap; 21 rows for one target resolved 20 and reported head_mismatch_resolution_partial.",
52+
"reproduction_steps": [
53+
"Run eleven independent proven mismatch targets",
54+
"Run 21 proven stale rows for one target",
55+
"Inspect evidence-read counts, resolution batches, and summary classifications"
56+
],
57+
"confidence": 0.99
58+
},
59+
{
60+
"contract_clause": "Dry-run and excluded reasons",
61+
"status": "pass",
62+
"severity": null,
63+
"evidence": "Dry-run reported one planned superseded row while the stub observed zero mutations. workflow_cancelled and tuple_protocol_invalid rows remained open and triggered no canonical evidence read.",
64+
"reproduction_steps": [
65+
"Repeat the positive fixture without --execute",
66+
"Run an excluded-only target",
67+
"Verify no mutation and no excluded-target evidence request"
68+
],
69+
"confidence": 0.99
70+
},
71+
{
72+
"contract_clause": "Guarded metric classification",
73+
"status": "pass",
74+
"severity": null,
75+
"evidence": "The queue rejected an unsupported resolution outcome and rejected superseded without resolution aliases; a guarded superseded resolution retained its note and changed only the completed/superseded totals.",
76+
"reproduction_steps": [
77+
"POST unsupported and unguarded typed resolutions",
78+
"POST the guarded superseded resolution",
79+
"Read the resolved row and queue stats"
80+
],
81+
"confidence": 0.98
82+
}
83+
],
84+
"anti_cheat_probes": [
85+
{
86+
"probe": "Changed canonical head away from the live GitHub head",
87+
"result": "Resolution stopped and the target was classified head_mismatch_unproven"
88+
},
89+
{
90+
"probe": "Advanced GitHub from proven head B to head C after canonical evidence",
91+
"result": "The second live read detected drift and the operator performed zero mutation"
92+
},
93+
{
94+
"probe": "Removed the canonical record",
95+
"result": "Resolution stopped with zero mutation"
96+
},
97+
{
98+
"probe": "Crossed both bounded prefixes",
99+
"result": "Only ten targets and 20 rows were acted on"
100+
},
101+
{
102+
"probe": "Removed --execute",
103+
"result": "The plan remained visible but the queue stub observed zero mutations"
104+
},
105+
{
106+
"probe": "Removed resolution aliases from the typed Worker request",
107+
"result": "The Worker returned invalid_resolution_guard"
108+
}
109+
],
110+
"blockers": []
111+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
npm notice
2+
npm notice New major version of npm available! 11.17.0 -> 12.0.2
3+
npm notice Changelog: https://github.com/npm/cli/releases/tag/v12.0.2
4+
npm notice To update run: npm install -g [email protected]
5+
npm notice
6+
$ pnpm run build && pnpm run build:repair && pnpm run build:dashboard
7+
$ tsc -p tsconfig.json
8+
$ tsc -p tsconfig.repair.json
9+
$ tsc -p tsconfig.dashboard.json

0 commit comments

Comments
 (0)