Skip to content

Commit e699e83

Browse files
authored
fix(publication): surface the sanitized reason behind invalid_direct_publication_plan (#1091)
The direct-publication plan handler wrapped acceptance in a catch-all that returned one opaque invalid_direct_publication_plan for every thrown validation error, sending the real message only to a server-side console.warn that is unreadable without Cloudflare Worker log access. That made the only still-growing publication dead-letter class undiagnosable: 178 of 189 tuple_protocol_invalid rows shared a single fingerprint, exactly sha256("Error:invalid_direct_publication_plan"), with 170 of them from one target repository. The reviews themselves succeed and reach GitHub; only the canonical record write fails, so the item is re-reviewed and fails identically -- one item reached batch revision 14. The 400 body now carries a sanitized detail alongside the unchanged error and fallback_required fields, and the publisher folds that detail into the reason it surfaces and fingerprints, so distinct validation failures stop collapsing into one dead-letter row. Diagnosability only: no change to which plans are accepted or rejected, to the 400 classification, or to retry and permanence handling. Proof: docs/proof/direct-publication-reject-detail drives a real local Worker and Durable Object over HTTP, asserts the preserved 400 classification, and shows two structurally different invalid plans producing two distinct sanitized details. Verified on the reviewed head in a Docker-backed Crabbox local-container.
1 parent 621b297 commit e699e83

8 files changed

Lines changed: 411 additions & 2 deletions

File tree

‎dashboard/exact-review-queue.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2631,11 +2631,13 @@ export class ExactReviewQueue {
26312631
202,
26322632
);
26332633
} catch (error) {
2634-
console.warn(`direct publication plan rejected: ${sanitizedServerError(error)}`);
2634+
const detail = sanitizedServerError(error);
2635+
console.warn(`direct publication plan rejected: ${detail}`);
26352636
return json(
26362637
{
26372638
error: "invalid_direct_publication_plan",
26382639
fallback_required: true,
2640+
detail,
26392641
},
26402642
400,
26412643
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Direct publication rejection detail proof
2+
3+
This proof exercises the built dashboard Worker and `ExactReviewQueue` Durable Object through real
4+
HTTP using local Wrangler persistence. It verifies the diagnosability-only response change for
5+
invalid direct publication plans.
6+
7+
The behavior contract is:
8+
9+
- the real Durable Object initializes before any rejection claim is made;
10+
- a deliberately invalid revision returns HTTP 400 with
11+
`error: "invalid_direct_publication_plan"`, `fallback_required: true`, and a non-empty `detail`
12+
naming the invalid revision;
13+
- a structurally different plan whose operation targets the wrong item returns the same unchanged
14+
error classification with a non-empty path-specific `detail`;
15+
- the two validation failures produce different detail values.
16+
17+
The script boots the Worker, drives `/api/exact-review-queue`, terminates the full Wrangler process
18+
tree, and inspects Wrangler's persisted SQLite database for the direct-publication table. Only that
19+
schema observation allows the proof to restart the Worker and make the signed HTTP assertions. The
20+
restart check waits for the health endpoint to stop answering so a surviving `workerd` child cannot
21+
turn the second boot into a false positive.
22+
23+
Run from the repository root on Node 24 or newer:
24+
25+
```bash
26+
bash docs/proof/direct-publication-reject-detail/run-proof.sh
27+
```
28+
29+
Set `DIRECT_PUBLICATION_REJECT_DETAIL_PROOF_OUTPUT` to keep generated artifacts outside the
30+
repository. The default ignored artifact directory contains the captured HTTP responses, runtime
31+
transcript, build/install logs, and a redacted Wrangler log.
32+
33+
This proof does not change or test retry/permanence policy, does not identify or fix the underlying
34+
CodexBar rejection, and does not deploy or mutate production. OpenClaw Bay is unaffected: the
35+
change enriches an internal publication rejection and its downstream diagnostic fingerprint, with
36+
no Bay observer data or control surface change.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { DatabaseSync } from "node:sqlite";
2+
3+
const [databasePath] = process.argv.slice(2);
4+
if (!databasePath) throw new Error("usage: assert-durable-object.mjs <database-path>");
5+
6+
const database = new DatabaseSync(databasePath);
7+
try {
8+
const row = database
9+
.prepare(
10+
"SELECT COUNT(*) AS count FROM sqlite_master WHERE type = 'table' AND name = 'exact_review_direct_publication_plans'",
11+
)
12+
.get();
13+
console.log(row.count);
14+
} finally {
15+
database.close();
16+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
export CI=1
5+
export WRANGLER_SEND_METRICS=false
6+
7+
output_dir="${DIRECT_PUBLICATION_REJECT_DETAIL_PROOF_OUTPUT:-docs/proof/direct-publication-reject-detail/artifacts}"
8+
worker_port="${DIRECT_PUBLICATION_REJECT_DETAIL_PROOF_PORT:-8797}"
9+
proof_secret="direct-publication-reject-detail-disposable-local-secret"
10+
sqlite_helper="docs/proof/direct-publication-reject-detail/assert-durable-object.mjs"
11+
state_dir="$(mktemp -d /tmp/direct-publication-reject-detail-state.XXXXXX)"
12+
wrangler_raw_log="$(mktemp /tmp/direct-publication-reject-detail-wrangler.XXXXXX)"
13+
wrangler_pid=""
14+
queue_db=""
15+
16+
mkdir -p "$output_dir"
17+
18+
stop_worker() {
19+
if test -n "$wrangler_pid"; then
20+
local -a worker_pids=("$wrangler_pid")
21+
local child_pid
22+
while IFS= read -r child_pid; do
23+
worker_pids+=("$child_pid")
24+
done < <(
25+
ps -eo pid=,ppid= | awk -v root="$wrangler_pid" '
26+
{ parent[$1] = $2 }
27+
END {
28+
for (pid in parent) {
29+
current = pid
30+
for (depth = 0; depth < 100 && current in parent; depth++) {
31+
current = parent[current]
32+
if (current == root) {
33+
print pid
34+
break
35+
}
36+
}
37+
}
38+
}
39+
'
40+
)
41+
kill "${worker_pids[@]}" >/dev/null 2>&1 || true
42+
wait "$wrangler_pid" >/dev/null 2>&1 || true
43+
wrangler_pid=""
44+
45+
local stopped=false
46+
for _ in $(seq 1 50); do
47+
if ! curl --silent --max-time 1 "http://127.0.0.1:${worker_port}/api/health" \
48+
>/dev/null 2>&1; then
49+
stopped=true
50+
break
51+
fi
52+
sleep 0.1
53+
done
54+
if test "$stopped" != true; then
55+
echo "failed to stop the Wrangler process tree before restart" >&2
56+
exit 1
57+
fi
58+
fi
59+
}
60+
61+
cleanup() {
62+
stop_worker
63+
sed "s/${proof_secret}/[redacted-local-proof-secret]/g" "$wrangler_raw_log" \
64+
>"${output_dir}/wrangler.log"
65+
rm -f -- "$wrangler_raw_log"
66+
rm -rf -- "$state_dir"
67+
}
68+
trap cleanup EXIT
69+
70+
start_worker() {
71+
npm_config_ignore_scripts=true npx --yes [email protected] dev \
72+
--config dashboard/wrangler.toml \
73+
--local \
74+
--persist-to "$state_dir" \
75+
--ip 127.0.0.1 \
76+
--port "$worker_port" \
77+
--var "CLAWSWEEPER_WEBHOOK_SECRET:${proof_secret}" \
78+
>>"$wrangler_raw_log" 2>&1 &
79+
wrangler_pid=$!
80+
81+
local ready=false
82+
for _ in $(seq 1 90); do
83+
if curl --fail --silent "http://127.0.0.1:${worker_port}/api/health" >/dev/null 2>&1; then
84+
ready=true
85+
break
86+
fi
87+
if ! kill -0 "$wrangler_pid" >/dev/null 2>&1; then
88+
sed -n '1,240p' "$wrangler_raw_log" >&2
89+
exit 1
90+
fi
91+
sleep 1
92+
done
93+
test "$ready" = true
94+
}
95+
96+
http_status() {
97+
local output_file="$1"
98+
shift
99+
curl --silent --show-error --max-time 90 --output "$output_file" --write-out '%{http_code}' "$@"
100+
}
101+
102+
signed_post() {
103+
local body_file="$1"
104+
local output_file="$2"
105+
local signature
106+
signature="$(openssl dgst -sha256 -hmac "$proof_secret" -hex <"$body_file" | awk '{print $NF}')"
107+
http_status "$output_file" \
108+
-X POST \
109+
-H "content-type: application/json" \
110+
-H "x-clawsweeper-exact-review-signature: sha256=${signature}" \
111+
--data-binary "@${body_file}" \
112+
"http://127.0.0.1:${worker_port}/internal/exact-review/publication-results"
113+
}
114+
115+
pnpm install --frozen-lockfile >"${output_dir}/dependencies-install.log" 2>&1
116+
pnpm run build:dashboard >"${output_dir}/build-dashboard.log" 2>&1
117+
118+
# Force the real Durable Object to initialize, then stop the entire Wrangler
119+
# process tree before inspecting its persisted schema.
120+
start_worker
121+
initial_queue_status="$(http_status "${output_dir}/initial-queue.json" \
122+
"http://127.0.0.1:${worker_port}/api/exact-review-queue")"
123+
test "$initial_queue_status" = "200"
124+
stop_worker
125+
126+
while IFS= read -r candidate; do
127+
if test "$(node "$sqlite_helper" "$candidate")" = "1"; then
128+
queue_db="$candidate"
129+
break
130+
fi
131+
done < <(find "$state_dir" -type f -name '*.sqlite' -print)
132+
if test -z "$queue_db"; then
133+
echo "Durable Object did not initialize: direct publication table is absent" >&2
134+
exit 1
135+
fi
136+
137+
node -e '
138+
const fs = require("node:fs");
139+
const base = {
140+
canonicalTargetKey: "steipete/CodexBar#2797",
141+
fenceKey: "steipete/CodexBar#2797",
142+
sourceSha: "a".repeat(40),
143+
operations: [{
144+
path: "records/steipete-CodexBar/items/2797.md",
145+
deleted: false,
146+
mode: "100644",
147+
bytes: 1,
148+
contentBase64: "eA==",
149+
}],
150+
totalBytes: 1,
151+
lifecycle: { kind: "policy_noop" },
152+
};
153+
const invalidRevision = {
154+
...base,
155+
revision: 0,
156+
identity: {
157+
canonicalTargetKey: base.canonicalTargetKey,
158+
fenceKey: base.fenceKey,
159+
revision: 0,
160+
claimGeneration: 1,
161+
},
162+
};
163+
const outsidePath = {
164+
...base,
165+
revision: 1,
166+
identity: {
167+
canonicalTargetKey: base.canonicalTargetKey,
168+
fenceKey: base.fenceKey,
169+
revision: 1,
170+
claimGeneration: 1,
171+
},
172+
operations: [{ ...base.operations[0], path: "records/steipete-CodexBar/items/2798.md" }],
173+
};
174+
fs.writeFileSync(process.argv[1], JSON.stringify(invalidRevision));
175+
fs.writeFileSync(process.argv[2], JSON.stringify(outsidePath));
176+
' "${output_dir}/invalid-revision-request.json" "${output_dir}/outside-path-request.json"
177+
178+
start_worker
179+
revision_status="$(signed_post \
180+
"${output_dir}/invalid-revision-request.json" \
181+
"${output_dir}/invalid-revision-response.json")"
182+
path_status="$(signed_post \
183+
"${output_dir}/outside-path-request.json" \
184+
"${output_dir}/outside-path-response.json")"
185+
test "$revision_status" = "400"
186+
test "$path_status" = "400"
187+
188+
REVISION_STATUS="$revision_status" PATH_STATUS="$path_status" node -e '
189+
const assert = require("node:assert/strict");
190+
const fs = require("node:fs");
191+
const revision = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
192+
const outsidePath = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
193+
for (const body of [revision, outsidePath]) {
194+
assert.equal(body.error, "invalid_direct_publication_plan");
195+
assert.equal(body.fallback_required, true);
196+
assert.equal(typeof body.detail, "string");
197+
assert.ok(body.detail.length > 0);
198+
}
199+
assert.match(revision.detail, /invalid direct publication revision/);
200+
assert.match(outsidePath.detail, /direct publication path is outside steipete-CodexBar#2797/);
201+
assert.notEqual(revision.detail, outsidePath.detail);
202+
const lines = [
203+
"Durable Object initialized: exact_review_direct_publication_plans table present",
204+
"invalid revision: HTTP " + process.env.REVISION_STATUS + "; error=" + revision.error + "; fallback_required=" + revision.fallback_required + "; detail=" + revision.detail,
205+
"outside path: HTTP " + process.env.PATH_STATUS + "; error=" + outsidePath.error + "; fallback_required=" + outsidePath.fallback_required + "; detail=" + outsidePath.detail,
206+
"distinct validation details: true",
207+
];
208+
fs.writeFileSync(process.argv[3], lines.join("\n") + "\n");
209+
' \
210+
"${output_dir}/invalid-revision-response.json" \
211+
"${output_dir}/outside-path-response.json" \
212+
"${output_dir}/runtime-transcript.txt"
213+
214+
test -s "${output_dir}/runtime-transcript.txt"
215+
cat "${output_dir}/runtime-transcript.txt"

‎src/repair/exact-review-direct-publication.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ export async function postDirectPublicationResult(options: {
122122
) {
123123
return { kind: "accepted", attempts: attempt, response: payload };
124124
}
125-
lastReason = String(payload.error || `http_${response.status}`);
125+
const reason = String(payload.error || `http_${response.status}`);
126+
const detail = typeof payload.detail === "string" ? payload.detail.trim() : "";
127+
lastReason = detail ? `${reason}: ${detail}` : reason;
126128
if (
127129
response.status === 413 ||
128130
(response.status >= 400 && response.status < 500 && response.status !== 429)

‎test/dashboard-worker.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,6 +3753,32 @@ test("direct publication endpoint authenticates, dedupes, and returns a structur
37533753
error: "direct_publication_source_sha_required",
37543754
fallback_required: true,
37553755
});
3756+
const urlCredentials = ["alice", "hunter2"].join(":");
3757+
const credentialPath = `https://${urlCredentials}@example.invalid/GITHUB_TOKEN=ghp_${"a".repeat(24)}`;
3758+
const invalidPlanBody = JSON.stringify({
3759+
...payload,
3760+
operations: [{ ...payload.operations[0], path: credentialPath }],
3761+
});
3762+
const invalidPlanSignature = `sha256=${createHmac("sha256", "test-secret").update(invalidPlanBody).digest("hex")}`;
3763+
const invalidPlan = await worker.fetch(
3764+
new Request(url, {
3765+
method: "POST",
3766+
headers: { "x-clawsweeper-exact-review-signature": invalidPlanSignature },
3767+
body: invalidPlanBody,
3768+
}),
3769+
env,
3770+
);
3771+
assert.equal(invalidPlan.status, 400);
3772+
const invalidPlanResponse = (await invalidPlan.json()) as {
3773+
error: string;
3774+
fallback_required: boolean;
3775+
detail: string;
3776+
};
3777+
assert.equal(invalidPlanResponse.error, "invalid_direct_publication_plan");
3778+
assert.equal(invalidPlanResponse.fallback_required, true);
3779+
assert.match(invalidPlanResponse.detail, /^invalid bounded state mutation path: /);
3780+
assert.match(invalidPlanResponse.detail, /\[REDACTED\]/);
3781+
assert.doesNotMatch(invalidPlanResponse.detail, /alice|hunter2|ghp_[A-Za-z0-9_]+/);
37563782
for (const expected of [
37573783
{ accepted: true, deduped: false },
37583784
{ accepted: false, deduped: true },

0 commit comments

Comments
 (0)