Skip to content

Commit 2f2d4fc

Browse files
committed
fix(queue): parked reconciliation skips command-context records
1 parent 0ded7ef commit 2f2d4fc

9 files changed

Lines changed: 260 additions & 22 deletions

File tree

‎dashboard/exact-review-queue.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,6 +4585,7 @@ export class ExactReviewQueue {
45854585
target_repo: item.decision.targetRepo,
45864586
item_number: item.decision.itemNumber,
45874587
item_kind: item.decision.itemKind,
4588+
...(exactReviewQueueHasCommandContext(item) ? { excluded_reason: "command_context" } : {}),
45884589
parked_reason: item.parkedReason || null,
45894590
parked_recovery_attempts: exactReviewParkedRecoveryAttempts(item.parkedRecoveryAttempts),
45904591
first_failed_at: item.firstFailureAt
@@ -4618,6 +4619,7 @@ export class ExactReviewQueue {
46184619
if (
46194620
!item ||
46204621
!exactReviewParkedOperatorEligible(item) ||
4622+
exactReviewQueueHasCommandContext(item) ||
46214623
item.revision !== expected.revision
46224624
) {
46234625
skipped += 1;
@@ -4677,6 +4679,7 @@ export class ExactReviewQueue {
46774679
if (
46784680
!item ||
46794681
!exactReviewParkedOperatorEligible(item) ||
4682+
exactReviewQueueHasCommandContext(item) ||
46804683
item.revision !== expected.revision ||
46814684
exactReviewQueueActiveReviewCount(state) >= exactReviewQueueCapacity(this.env)
46824685
) {

‎docs/proof/parked-review-reconcile/README.md‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
The real local dashboard Worker and `ExactReviewQueue` Durable Object expose a bounded, signed
66
inventory for parked reviews. After the existing automatic recovery budget is genuinely exhausted,
77
the parked-review operator resolves a terminal target and re-enqueues an open target as a fresh
8-
pending review with a reset recovery budget.
8+
pending review with a reset recovery budget, while leaving a command-context target parked for its
9+
maintainer-command obligations.
910

1011
## Exercised surface
1112

@@ -20,18 +21,26 @@ pending review with a reset recovery budget.
2021

2122
## Controlled scenario
2223

23-
Two synthetic open issues are enqueued through the signed Worker route. The loopback GitHub stub
24+
Two ordinary open issues and one command-context review are enqueued through the signed Worker
25+
route. The command uses the real legacy command intake shape: a pull-request item with
26+
`sourceAction: "legacy_dispatch"`, command status marker, status comment id, and additional prompt.
27+
`exactReviewQueueHasCommandContext` recognizes that stored decision. The loopback GitHub stub
2428
returns the single-field HTTP 422 validation response that the production dispatcher classifies as
2529
`permanent_rejection`, parking each item as `dispatch_rejected`. Wrangler alarms perform all three
2630
automatic recoveries; every recovered item reaches the same real dispatch path and parks again.
27-
The proof waits until both inventory rows report `parked_recovery_attempts: 3`.
31+
The proof waits until all three inventory rows report `parked_recovery_attempts: 3` and the command
32+
row reports `excluded_reason: "command_context"`.
2833

2934
The Worker process tree is then stopped. The proof opens Wrangler's disposable SQLite database only
3035
to assert that the `exact_review_queue_parked_actions` table was instantiated; it never inserts,
3136
updates, or deletes queue state. The Worker restarts against the same persistence with its normal
32-
90-second enqueue debounce. The stub marks one target closed and accepts dispatches. The real
37+
90-second enqueue debounce. The stub marks the ordinary terminal target and the command-context
38+
target closed, then accepts dispatches. The real
3339
operator classifies the targets, resolves the closed row with an audit note, fresh-recovers the open
34-
row, and the proof observes that row as `pending` with `parked_recovery_attempts: 0`.
40+
ordinary row, and skips the command-context row before GitHub inspection. Direct signed resolve and
41+
recover requests for that command row both report one skipped mutation. The proof observes the
42+
ordinary recovered row as `pending` with `parked_recovery_attempts: 0` and the command-context row
43+
unchanged as `parked` with `parked_recovery_attempts: 3`.
3544

3645
## Command and timing
3746

@@ -49,16 +58,22 @@ take 26.25-52.5 minutes; the script has a 60-minute hard deadline. Generated evi
4958
## Required observations
5059

5160
- The Durable Object is instantiated and the parked action-receipt table exists.
52-
- Both rows are visible through the signed list route after exactly three automatic recoveries.
61+
- All three rows are visible through the signed list route after exactly three automatic recoveries.
62+
- The command-context row is flagged with `excluded_reason: "command_context"`.
5363
- The operator inspects two targets, resolves one terminal target, and recovers one open target.
64+
- The operator counts the excluded command-context target as skipped without inspecting it.
65+
- Signed resolve and fresh-recover requests both refuse the command-context row.
5466
- The terminal target has no queue item after reconciliation.
5567
- The open target is pending with attempts and parked recovery attempts reset to zero.
56-
- The final parked inventory is empty.
68+
- The final parked inventory contains only the unchanged command-context target.
5769

5870
## Limits and Bay impact
5971

6072
The GitHub service is a loopback behavioral stub; no production GitHub repository, Worker, secret,
6173
comment, or workflow is contacted or mutated. The proof covers the real Worker/DO state machine,
6274
HTTP signing, alarms, operator process, and persistence boundary, not GitHub's hosted implementation.
75+
It exercises the initial command-review dispatch-rejection route. Terminal-finalization command
76+
acknowledgements use their separate pending retry path and are intentionally outside this parking
77+
scenario.
6378
OpenClaw Bay is unaffected: it remains a public observer-only surface and gains no recovery, DLQ,
6479
queue, workflow, deploy, or rollback action.

‎docs/proof/parked-review-reconcile/run-proof.mjs‎

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ if (phase === "exhaust") await exhaustRecoveryBudget();
2222
else await reconcileParkedReviews();
2323

2424
async function exhaustRecoveryBudget() {
25-
for (const number of [114100, 114101]) {
25+
for (const number of [114100, 114101, 114102]) {
26+
const commandContext = number === 114102;
2627
const result = await signedPost(
2728
"/internal/exact-review/enqueue",
2829
{
@@ -31,10 +32,18 @@ async function exhaustRecoveryBudget() {
3132
targetRepo: "openclaw/openclaw",
3233
targetBranch: "main",
3334
itemNumber: number,
34-
itemKind: "issue",
35+
itemKind: commandContext ? "pull_request" : "issue",
3536
sourceEvent: "issues",
36-
sourceAction: "opened",
37+
sourceAction: commandContext ? "legacy_dispatch" : "opened",
3738
supersedesInProgress: false,
39+
...(commandContext
40+
? {
41+
commandStatusMarker:
42+
"<!-- clawsweeper-command-status:114102:re_review:0123456789abcdef0123456789abcdef01234567 -->",
43+
statusCommentId: 114102,
44+
additionalPrompt: "Check the maintainer-requested regression path.",
45+
}
46+
: {}),
3847
},
3948
},
4049
webhookSecret,
@@ -64,10 +73,12 @@ async function exhaustRecoveryBudget() {
6473
prior = progress;
6574
}
6675
if (
67-
rows.length === 2 &&
76+
rows.length === 3 &&
6877
rows.every(
6978
(row) => row.parked_reason === "dispatch_rejected" && row.parked_recovery_attempts === 3,
70-
)
79+
) &&
80+
rows.find((row) => row.item_key === "openclaw/openclaw#114102")?.excluded_reason ===
81+
"command_context"
7182
) {
7283
await writeJson("parked-inventory-exhausted.json", inventory.body);
7384
await writeJson("exhaustion-summary.json", {
@@ -89,7 +100,11 @@ async function reconcileParkedReviews() {
89100
const control = await fetch(`${githubOrigin}/__proof/control`, {
90101
method: "POST",
91102
headers: { "content-type": "application/json" },
92-
body: JSON.stringify({ reject_dispatch: false, issue_114101_state: "closed" }),
103+
body: JSON.stringify({
104+
reject_dispatch: false,
105+
issue_114101_state: "closed",
106+
issue_114102_state: "closed",
107+
}),
93108
});
94109
assert.equal(control.status, 200);
95110

@@ -117,7 +132,7 @@ async function reconcileParkedReviews() {
117132
resolved_targets: 1,
118133
open_targets: 1,
119134
recovered_targets: 1,
120-
skipped_targets: 0,
135+
skipped_targets: 1,
121136
},
122137
);
123138

@@ -127,13 +142,17 @@ async function reconcileParkedReviews() {
127142
const terminal = await getJson(
128143
"/api/exact-review-queue/item?target_repo=openclaw%2Fopenclaw&item_number=114101",
129144
);
145+
const commandContext = await getJson(
146+
"/api/exact-review-queue/item?target_repo=openclaw%2Fopenclaw&item_number=114102",
147+
);
130148
const finalInventory = await signedPost(
131149
"/internal/exact-review/parked-reviews/list",
132150
{ limit: 50 },
133151
operatorSecret,
134152
);
135153
await writeJson("open-target-after.json", open.body);
136154
await writeJson("terminal-target-after.json", terminal.body);
155+
await writeJson("command-context-target-after.json", commandContext.body);
137156
await writeJson("parked-inventory-final.json", finalInventory.body);
138157
assert.equal(open.status, 200);
139158
assert.equal(open.body.items.length, 1);
@@ -142,8 +161,52 @@ async function reconcileParkedReviews() {
142161
assert.equal(open.body.items[0].parked_recovery_attempts, 0);
143162
assert.equal(terminal.status, 200);
144163
assert.equal(terminal.body.items.length, 0);
164+
assert.equal(commandContext.status, 200);
165+
assert.equal(commandContext.body.items.length, 1);
166+
assert.equal(commandContext.body.items[0].state, "parked");
167+
assert.equal(commandContext.body.items[0].attempts, 0);
168+
assert.equal(commandContext.body.items[0].parked_recovery_attempts, 3);
145169
assert.equal(finalInventory.status, 200);
146-
assert.deepEqual(finalInventory.body.parked_reviews, []);
170+
assert.equal(finalInventory.body.parked_reviews.length, 1);
171+
const commandRow = finalInventory.body.parked_reviews[0];
172+
assert.equal(commandRow.item_key, "openclaw/openclaw#114102");
173+
assert.equal(commandRow.excluded_reason, "command_context");
174+
const commandMutation = {
175+
item_key: commandRow.item_key,
176+
revision: commandRow.revision,
177+
updated_at_ms: commandRow.updated_at_ms,
178+
};
179+
const refusedResolve = await signedPost(
180+
"/internal/exact-review/parked-reviews/resolve",
181+
{
182+
items: [commandMutation],
183+
note: "proof: command-context record must retain its acknowledgement obligation",
184+
},
185+
operatorSecret,
186+
);
187+
const refusedRecover = await signedPost(
188+
"/internal/exact-review/parked-reviews/recover-fresh",
189+
{
190+
items: [commandMutation],
191+
idempotency_key: "parked-proof:command-context-refusal",
192+
},
193+
operatorSecret,
194+
);
195+
await writeJson("command-context-resolve-refusal.json", refusedResolve.body);
196+
await writeJson("command-context-recover-refusal.json", refusedRecover.body);
197+
assert.equal(refusedResolve.status, 200);
198+
assert.deepEqual(refusedResolve.body, { ok: true, resolved: 0, skipped: 1 });
199+
assert.equal(refusedRecover.status, 200);
200+
assert.deepEqual(refusedRecover.body, {
201+
ok: true,
202+
recovered: 0,
203+
deduped: 0,
204+
skipped: 1,
205+
});
206+
const commandAfterRefusals = await getJson(
207+
"/api/exact-review-queue/item?target_repo=openclaw%2Fopenclaw&item_number=114102",
208+
);
209+
assert.deepEqual(commandAfterRefusals.body, commandContext.body);
147210

148211
const proofSummary = {
149212
proof: "parked review inventory and reconcile",
@@ -154,7 +217,9 @@ async function reconcileParkedReviews() {
154217
automatic_recovery_attempts_exhausted: 3,
155218
terminal_target_resolved: true,
156219
open_target_recovered_pending: true,
157-
final_parked_inventory_rows: 0,
220+
command_context_target_untouched: true,
221+
command_context_mutations_refused: true,
222+
final_parked_inventory_rows: 1,
158223
},
159224
operator: result,
160225
};

‎docs/proof/parked-review-reconcile/run-proof.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,8 @@ node docs/proof/parked-review-reconcile/run-proof.mjs reconcile \
168168
test -s "${output_dir}/proof-summary.json"
169169
test -s "${output_dir}/parked-inventory-exhausted.json"
170170
test -s "${output_dir}/parked-operator-inventory.json"
171+
test -s "${output_dir}/command-context-target-after.json"
172+
test -s "${output_dir}/command-context-resolve-refusal.json"
173+
test -s "${output_dir}/command-context-recover-refusal.json"
171174
test -s "${output_dir}/durable-object-assertion.txt"
172175
echo "PROOF_RC=0"

‎docs/proof/parked-review-reconcile/stub-github.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ await writeFile(tracePath, "");
1616
const issueStates = new Map([
1717
[114100, "open"],
1818
[114101, "open"],
19+
[114102, "open"],
1920
]);
2021
let rejectDispatch = true;
2122
let dispatches = 0;
@@ -47,6 +48,9 @@ const server = http.createServer(async (request, response) => {
4748
if (command.issue_114101_state) {
4849
issueStates.set(114101, String(command.issue_114101_state));
4950
}
51+
if (command.issue_114102_state) {
52+
issueStates.set(114102, String(command.issue_114102_state));
53+
}
5054
return json(response, 200, { ok: true });
5155
}
5256
if (/^\/repos\/openclaw\/(?:openclaw|clawsweeper)\/installation$/.test(url.pathname)) {
@@ -58,7 +62,7 @@ const server = http.createServer(async (request, response) => {
5862
if (url.pathname === "/repos/openclaw/clawsweeper/actions/workflows/sweep.yml") {
5963
return json(response, 200, { state: "active" });
6064
}
61-
const issueMatch = /^\/repos\/openclaw\/openclaw\/issues\/(11410[01])$/.exec(url.pathname);
65+
const issueMatch = /^\/repos\/openclaw\/openclaw\/issues\/(11410[0-2])$/.exec(url.pathname);
6266
if (issueMatch) {
6367
const number = Number(issueMatch[1]);
6468
return json(response, 200, {

‎docs/scheduler.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ resolves terminal or repository-gone targets with an audit note, and can queue
8383
at most five fresh reviews with replay-safe recovery keys. Manual runs remain
8484
read-only unless `execute` is enabled; scheduled runs execute. Their sanitized
8585
parked inventory is uploaded beside the publication dead-letter inventory.
86+
Parked records carrying maintainer-command context remain visible with an
87+
exclusion reason but cannot be resolved or fresh-recovered by this background
88+
reconciliation path.
8689
This drains the existing queue state and does not add a dashboard health input
8790
or an OpenClaw Bay action: Bay remains observer-only.
8891
GitHub throttle deferrals use the same per-item jitter band when the queue turns

‎scripts/exact-review-dead-letter-operator.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ async function reconcileParkedReviews({ inventory, queueUrl, secret, args, deadl
702702
return;
703703
}
704704
for (const [index, row] of selectedRows.entries()) {
705+
if (row.excluded_reason) {
706+
summary.skipped_targets += 1;
707+
continue;
708+
}
705709
if (parkedReconcileDeadlineReached(deadlineAt)) {
706710
stopForDeadline(selectedRows.length - index + terminal.length + recoverable.length);
707711
return;
@@ -902,6 +906,8 @@ function sanitizeParkedReviewRow(row) {
902906
const targetRepo = String(value.target_repo || "");
903907
const itemNumber = Number(value.item_number);
904908
const updatedAtMs = Number(value.updated_at_ms);
909+
const excludedReason =
910+
value.excluded_reason === undefined ? null : String(value.excluded_reason || "");
905911
if (
906912
!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+#[1-9]\d*$/.test(itemKey) ||
907913
!Number.isSafeInteger(revision) ||
@@ -910,7 +916,8 @@ function sanitizeParkedReviewRow(row) {
910916
!Number.isSafeInteger(itemNumber) ||
911917
itemNumber < 1 ||
912918
!Number.isSafeInteger(updatedAtMs) ||
913-
updatedAtMs < 1
919+
updatedAtMs < 1 ||
920+
(excludedReason !== null && excludedReason !== "command_context")
914921
) {
915922
throw new Error("parked review inventory returned an invalid row");
916923
}
@@ -920,6 +927,7 @@ function sanitizeParkedReviewRow(row) {
920927
target_repo: targetRepo,
921928
item_number: itemNumber,
922929
item_kind: String(value.item_kind || ""),
930+
excluded_reason: excludedReason,
923931
parked_reason: String(value.parked_reason || "") || null,
924932
parked_recovery_attempts: Number(value.parked_recovery_attempts || 0),
925933
first_failed_at: value.first_failed_at ? String(value.first_failed_at) : null,

0 commit comments

Comments
 (0)