muse-crew 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/decisions/AGENTS.md +94 -0
- package/docs/decisions/publish-path.md +1280 -0
- package/docs/decisions/qa-reproduce.md +486 -0
- package/docs/decisions/workflow-core.md +234 -0
- package/docs/publish-unknown-recovery.md +113 -0
- package/docs/visual-verdict.md +6 -7
- package/lib/AGENTS.md +3 -1
- package/lib/classify-publish-absence.js +451 -0
- package/lib/compose-evidence-caption.js +36 -5
- package/lib/crew-api.js +584 -22
- package/lib/crew-release.sh +51 -9
- package/lib/publish-content.js +154 -0
- package/lib/retry-publish.js +370 -0
- package/lib/verify-publish.js +101 -84
- package/package.json +2 -2
- package/seed/cron-body-template.md +57 -2
- package/workflows/AGENTS.md +3 -1
- package/workflows/bugfix.js +301 -592
- package/workflows/chore.js +292 -526
- package/workflows/standard.js +294 -550
- package/workflows/upgrade.js +1 -1
package/workflows/chore.js
CHANGED
|
@@ -26,25 +26,10 @@ const startStepIndex = inputs.start_step_index || 0;
|
|
|
26
26
|
// resolution back via updatetask in the self-claim below.
|
|
27
27
|
const RESOLVED_WORKFLOW = inputs.resolved_workflow || null;
|
|
28
28
|
const WORKFLOW_WAS_NULL = inputs.workflow_was_null === true;
|
|
29
|
-
//
|
|
30
|
-
// routes this run via an explicit recover-task redirect. The value is
|
|
31
|
-
// consumed (cleared) atomically by the successful self-claim below:
|
|
32
|
-
// claim-task takes expected_next_phase and clears the matching next_phase in
|
|
33
|
-
// the same transaction as the winning session insert, so no platform death
|
|
34
|
-
// can slip between claim and consumption and replay the routing. A stale or
|
|
35
|
-
// superseded routing survives — only an exact match clears.
|
|
36
|
-
// what the dispatcher routed on.
|
|
29
|
+
// See docs/decisions/workflow-core.md#oneshot-recovery: the dispatcher sets input for one-shot recovery routing.
|
|
37
30
|
const NEXT_PHASE_ROUTED = (typeof inputs.next_phase === "string" && inputs.next_phase.length > 0) ? inputs.next_phase : null;
|
|
38
31
|
|
|
39
|
-
//
|
|
40
|
-
// baseline capture ONLY when the protocol is fully shipped. The protocol
|
|
41
|
-
// requires docs/visual-verdict.md in the release AND the parent-side
|
|
42
|
-
// capture tooling (task b309a97d, "QA owns the visual verdict"). Until both
|
|
43
|
-
// exist, the park would deadlock waiting for a parent who cannot fulfill
|
|
44
|
-
// it.
|
|
45
|
-
// Effective value for this run, resolved by the dispatcher from the
|
|
46
|
-
// project's visual_protocol setting (null=inherits crew default=off).
|
|
47
|
-
// Manual launches without the arg default to off (previous behavior).
|
|
32
|
+
// See docs/decisions/qa-reproduce.md#visual-protocol-avail: the workflow parks if the visual protocol is unavailable.
|
|
48
33
|
var VISUAL_PROTOCOL_AVAILABLE = inputs.visual_protocol === true;
|
|
49
34
|
|
|
50
35
|
// crewHome is required — the dispatcher always passes it (crew-dispatch.js
|
|
@@ -85,7 +70,7 @@ let telemetryBuffer = [];
|
|
|
85
70
|
async function telemetryStart(workflowName) {
|
|
86
71
|
try {
|
|
87
72
|
const out = await agent(crewCmd("record-run-start", {
|
|
88
|
-
task_id: taskId, workflow: workflowName, launched_by:
|
|
73
|
+
task_id: taskId, workflow: workflowName, launched_by: inputs.launched_by
|
|
89
74
|
}), { key: "telemetry-start", label: "Recording run start" });
|
|
90
75
|
const parsed = typeof out === "string" ? JSON.parse(out) : out;
|
|
91
76
|
if (parsed && parsed.run_id) telemetryRunId = parsed.run_id;
|
|
@@ -142,15 +127,7 @@ const COMPUTE_DIFF_SRC = crewHome + "/current/lib/compute-publish-diff.js";
|
|
|
142
127
|
const COMPUTE_DIFF = RUN_LIB + "/compute-publish-diff.js";
|
|
143
128
|
const CLASSIFY_SURFACE_SRC = crewHome + "/current/lib/classify-surface.js";
|
|
144
129
|
const CLASSIFY_SURFACE = RUN_LIB + "/classify-surface.js";
|
|
145
|
-
//
|
|
146
|
-
// by workflow code from the verbatim listing, never from agent prose.
|
|
147
|
-
// COMPUTE_DIFF is the deterministic publish-diff computer (room #14,
|
|
148
|
-
// 2026-09-17): the diff is computed by this script, never ferried as an
|
|
149
|
-
// agent JSON string. Pinned like the other publish-critical modules so a
|
|
150
|
-
// mid-run release swap cannot change it under the workflow.
|
|
151
|
-
// CLASSIFY_SURFACE is the surface classifier (room #15, 2026-09-18):
|
|
152
|
-
// crew-api.js statically imports it, so the pin must carry it — a pin
|
|
153
|
-
// without it kills every claim with ERR_MODULE_NOT_FOUND.
|
|
130
|
+
// See docs/decisions/qa-reproduce.md#pin-basenames: the pin step materializes the required scripts.
|
|
154
131
|
const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED, COMPUTE_DIFF, CLASSIFY_SURFACE].map(function (p) { return p.split("/").pop(); });
|
|
155
132
|
|
|
156
133
|
// Project config — passed by dispatcher, falls back to dashboard defaults
|
|
@@ -200,12 +177,7 @@ const SURFACE_TRIAGE_DESC = SURFACE_ARTIFACT
|
|
|
200
177
|
: SURFACE_TERMINAL
|
|
201
178
|
? "This project's user-facing surface is terminal: a command-line interface."
|
|
202
179
|
: "This project's user-facing surface is unclassified (environment_type not set): judge by what a user would directly observe.";
|
|
203
|
-
//
|
|
204
|
-
// mechanically — every phase prompt reads UX_DOCTRINE_PATH, never a
|
|
205
|
-
// hardcoded filename. Canonical map: lib/ux-doctrine.js (mirrored here as a
|
|
206
|
-
// one-liner because the workflow runtime's relative-import support is
|
|
207
|
-
// unverified; tests pin the mirror). Null on unclassified surfaces: no
|
|
208
|
-
// shared page, and prompts say so instead of naming the wrong one.
|
|
180
|
+
// See docs/decisions/qa-reproduce.md#ux-doctrine-page: the shared UX bar for this run's surface.
|
|
209
181
|
const UX_DOCTRINE_PAGE = SURFACE_TERMINAL ? "terminal-ux.md" : (SURFACE_ARTIFACT ? "artifact-ux.md" : null);
|
|
210
182
|
const UX_DOCTRINE_PATH = UX_DOCTRINE_PAGE ? crewHome + "/current/docs/" + UX_DOCTRINE_PAGE : null;
|
|
211
183
|
const PUBLISH_SLUG = projectConfig.deploy_slug || "";
|
|
@@ -216,21 +188,7 @@ if (!taskId) {
|
|
|
216
188
|
throw new Error("task_id is required in args");
|
|
217
189
|
}
|
|
218
190
|
|
|
219
|
-
//
|
|
220
|
-
// transport envelope {"status": "ok", "result": "<prose report>"} with no
|
|
221
|
-
// schema, so the workflow receives the report as a plain string. There is no
|
|
222
|
-
// {"report"} wrapper: that invented shape invited agents to improvise sibling
|
|
223
|
-
// keys (notably "status"), which the runtime duck-types as its own envelope
|
|
224
|
-
// and fatally misparses. The envelope is the runtime's own documented shape
|
|
225
|
-
// — not a demand for machine-structured reasoning.
|
|
226
|
-
// The verdict is extracted mechanically by extractVerdict below — never by an
|
|
227
|
-
// agent. The summary is the worker's report truncated. The release decision
|
|
228
|
-
// comes from extractReleaseDecision. No formatter agent: it added a failure
|
|
229
|
-
// mode while contributing nothing the workflow doesn't compute itself.
|
|
230
|
-
// Steps whose passed=false drives a control-flow branch (rework bounce,
|
|
231
|
-
// block) declare their verdict explicitly on a VERDICT: line. The verdict is
|
|
232
|
-
// extracted DETERMINISTICALLY by workflow code (extractVerdict) — never by
|
|
233
|
-
// an agent. Missing, malformed, or contradictory lines fail the phase (never silently pass).
|
|
191
|
+
// See docs/decisions/workflow-core.md#closeout-envelope: the work agent returns the runtime's native envelope; verdict extracted mechanically.
|
|
234
192
|
const VERDICT_STEPS = ["Build", "Review", "Integrate", "Publish"];
|
|
235
193
|
function extractVerdict(workerText) {
|
|
236
194
|
// The verdict is the LAST VERDICT: PASS/FAIL in the report (contract: end
|
|
@@ -254,16 +212,7 @@ function extractVerdict(workerText) {
|
|
|
254
212
|
if (uniq.length !== 1) return { ok: false, count: matches.length };
|
|
255
213
|
return { ok: true, passed: last.value === "PASS" };
|
|
256
214
|
}
|
|
257
|
-
//
|
|
258
|
-
// extractVerdict is not failed immediately. Stochastic verdict-line
|
|
259
|
-
// non-compliance (the agent did the work but omitted or garbled the VERDICT
|
|
260
|
-
// line) gets up to two bounded follow-up agent() calls whose only job is to
|
|
261
|
-
// read the preserved report and emit exactly one VERDICT line. The verdict
|
|
262
|
-
// is still extracted mechanically by extractVerdict — the re-ask agent
|
|
263
|
-
// transcribes, never decides the phase outcome. Each attempt uses a fresh
|
|
264
|
-
// stable-key suffix so a cached failure can never replay deterministically.
|
|
265
|
-
// Exhaustion keeps the existing fail-closed behavior. This is structure, not
|
|
266
|
-
// prompt hardening: no instruction text was stern-ified to get here.
|
|
215
|
+
// See docs/decisions/workflow-core.md#verdict-reask: a report that fails extractVerdict gets bounded re-ask calls.
|
|
267
216
|
function verdictReaskKey(stepName, reworkSuffix, attempt) {
|
|
268
217
|
return "verdict-reask-" + stepName + reworkSuffix + "-a" + attempt;
|
|
269
218
|
}
|
|
@@ -321,12 +270,7 @@ function workRetryKey(stepName, reworkSuffix, attempt) {
|
|
|
321
270
|
function attemptKey(base, reworkCount) {
|
|
322
271
|
return base + (reworkCount > 0 ? "-r" + reworkCount : "");
|
|
323
272
|
}
|
|
324
|
-
//
|
|
325
|
-
// the verbatim `ls -1` listing so WORKFLOW CODE asserts the six pinned
|
|
326
|
-
// basenames; the agent cannot self-certify. (The pin step was the one place
|
|
327
|
-
// the workflows trusted agent prose: task 24be1cd6 walked to Publish on an
|
|
328
|
-
// empty pin dir.) Byte-identical across standard/bugfix/chore — pinned by
|
|
329
|
-
// tests/pin-location.test.js.
|
|
273
|
+
// See docs/decisions/qa-reproduce.md#pin-lifecycle: snapshot the lifecycle scripts in the pin.
|
|
330
274
|
function pinLifecycle(key) {
|
|
331
275
|
return agent(
|
|
332
276
|
"Snapshot lifecycle scripts for version pinning.\n" +
|
|
@@ -530,24 +474,7 @@ function hydrateReleaseDecision(rec) {
|
|
|
530
474
|
// read-back cannot be
|
|
531
475
|
// fabricated from the diff; it must match the artifact's real content.
|
|
532
476
|
|
|
533
|
-
//
|
|
534
|
-
// attempt is recorded append-only at $CREW_HOME/.publish-ledger/<slug>.jsonl
|
|
535
|
-
// on persistent disk (NOT /tmp). The ledger is the correlation record for
|
|
536
|
-
// publish attempts whose outcome is UNKNOWN. When the rebuild trigger's
|
|
537
|
-
// child returns prose instead of JSON (structured-output failure), the edit
|
|
538
|
-
// may already have been accepted as pending_init — and artifact_status
|
|
539
|
-
// cannot see pending_init (diagnostic canary 2026-09-12: an edit accepted
|
|
540
|
-
// as pending_init was immediately followed by an all-false status check,
|
|
541
|
-
// and the old retry issued a DUPLICATE edit). "No build visible" is NOT
|
|
542
|
-
// evidence the edit did not go through, so the workflow never blind-retries
|
|
543
|
-
// on an unknown outcome: it records the attempt and parks fail-closed. A
|
|
544
|
-
// human or a later run correlates the accepted edit via the ledger (commit
|
|
545
|
-
// hash + attempt key + the artifact build's agent_id when one was observed)
|
|
546
|
-
// instead of guessing from a blind status poll.
|
|
547
|
-
// Best-effort observability: a failed write is logged loudly but never
|
|
548
|
-
// throws — the caller's park/proceed decision never depends on the ledger.
|
|
549
|
-
// Byte-identical across standard/bugfix/chore — pinned by
|
|
550
|
-
// tests/publish-ledger.test.js.
|
|
477
|
+
// See docs/decisions/publish-path.md#publish-attempt-ledger: every trigger outcome is recorded in the durable ledger.
|
|
551
478
|
async function recordPublishLedger(entry, rework) {
|
|
552
479
|
try {
|
|
553
480
|
var ledgerDir = crewHome + "/.publish-ledger";
|
|
@@ -560,6 +487,7 @@ async function recordPublishLedger(entry, rework) {
|
|
|
560
487
|
attempt: entry.attempt || null,
|
|
561
488
|
agent_id: entry.agent_id || null,
|
|
562
489
|
applied_report: entry.applied_report || null,
|
|
490
|
+
manifest_before: entry.manifest_before || null,
|
|
563
491
|
outcome: entry.outcome,
|
|
564
492
|
detail: entry.detail || ""
|
|
565
493
|
});
|
|
@@ -597,45 +525,19 @@ function extractMarkerLines(workerText) {
|
|
|
597
525
|
return markers.join("\n");
|
|
598
526
|
}
|
|
599
527
|
|
|
600
|
-
//
|
|
601
|
-
// builder correctly makes no commit because the deliverable is already on
|
|
602
|
-
// main (a prior merge or hand-repair landed it), it declares
|
|
603
|
-
// `repo_diff: none (already-merged: <sha>)` naming the main commit that
|
|
604
|
-
// carries the work. Room #16 blocker 11 (2026-09-18): the line anchor
|
|
605
|
-
// missed Wren's mid-paragraph declaration, and the persisted notes truncated
|
|
606
|
-
// the tail — so the anchor is gone and a sha followed by `)`, whitespace, or
|
|
607
|
-
// end-of-string (truncation) is accepted. The sha is hex-only (7-40 chars)
|
|
608
|
-
// so the workflow can interpolate it into the mechanical ancestor check
|
|
609
|
-
// without injection risk; a over-long hex run never matches (the lookahead
|
|
610
|
-
// fails on the extra hex char). Pure — pinned byte-identical across
|
|
611
|
-
// standard/bugfix/chore.
|
|
528
|
+
// See docs/decisions/publish-path.md#already-merged-idem2: idempotency for already-merged tasks.
|
|
612
529
|
function extractAlreadyMerged(workerText) {
|
|
613
530
|
var m = /repo_diff:\s*none\s*\(already-merged:\s*([0-9a-f]{7,40})(?=[\s)]|$)/i.exec(workerText || "");
|
|
614
531
|
return m ? { sha: m[1].toLowerCase() } : { sha: null };
|
|
615
532
|
}
|
|
616
533
|
|
|
617
|
-
//
|
|
618
|
-
// trigger child ends its turn with `ARTIFACT_EDIT_REFUSED: <text>` when
|
|
619
|
-
// artifact_edit explicitly refuses the edit (e.g. the artifact does not
|
|
620
|
-
// exist). A refusal is conclusive negative evidence — the edit provably did
|
|
621
|
-
// NOT go through — distinct from an unconsumed trigger return (unknown).
|
|
622
|
-
// Pure — pinned byte-identical across standard/bugfix/chore.
|
|
623
|
-
// The signal must be the ENTIRE trimmed turn output (not a line within prose):
|
|
624
|
-
// the trigger child is instructed to end its turn with exactly this line and
|
|
625
|
-
// nothing else. A confused child quoting the instructions back in prose must
|
|
626
|
-
// NOT produce a conclusive negative — that degrades to unknown (fail-closed).
|
|
534
|
+
// See docs/decisions/publish-path.md#refusal-signal: the refusal signal must be the ENTIRE trimmed turn output.
|
|
627
535
|
function extractRefusal(workerText) {
|
|
628
536
|
var m = /^ARTIFACT_EDIT_REFUSED:\s*(.+?)\s*$/.exec(String(workerText || "").trim());
|
|
629
537
|
return m ? m[1].slice(0, 300) : null;
|
|
630
538
|
}
|
|
631
539
|
|
|
632
|
-
//
|
|
633
|
-
// path it built in on a `worktree:` marker line. The workflow compares it
|
|
634
|
-
// against WORKTREE_HINT mechanically (exact string match) — never by
|
|
635
|
-
// reading agent prose. This closes the hole where a builder whose prepare
|
|
636
|
-
// failed freelanced into a different checkout (canary, 2026-09-11): the
|
|
637
|
-
// honest-but-confused case fails here, and a fabricated path is caught one
|
|
638
|
-
// phase later when Review's inspect finds no commits in the configured repo.
|
|
540
|
+
// See docs/decisions/qa-reproduce.md#worktree-confinement: the Build agent must declare its worktree.
|
|
639
541
|
function extractWorktree(workerText) {
|
|
640
542
|
var lines = (workerText || "").split("\n");
|
|
641
543
|
var found = null;
|
|
@@ -665,26 +567,7 @@ function extractExperiential(workerText) {
|
|
|
665
567
|
if (!r) return null;
|
|
666
568
|
return r[1].toLowerCase() === "yes";
|
|
667
569
|
}
|
|
668
|
-
|
|
669
|
-
// Deterministic visual-capture frame. kind: "baseline" | "postchange".
|
|
670
|
-
// This string IS the capture script: fixed viewport matrix, scroll
|
|
671
|
-
// positions, and interaction states — the inspection agent executes it
|
|
672
|
-
// verbatim, nothing is improvised. Task-specific targets fill the slots.
|
|
673
|
-
var title = String(taskTitle || "").replace(/"/g, "'").slice(0, 120);
|
|
674
|
-
var targets = String(captureTargets || "").trim() ||
|
|
675
|
-
String(taskDescription || "").replace(/"/g, "'").slice(0, 300);
|
|
676
|
-
return "VISUAL CAPTURE — " + kind.toUpperCase() + " — task: " + title + ". " +
|
|
677
|
-
"Target views/controls: " + targets + ". " +
|
|
678
|
-
"For EACH target, capture exactly: " +
|
|
679
|
-
"(1) desktop 1440x900, full view, scrolled to top; " +
|
|
680
|
-
"(2) desktop 1440x900, scrolled so the target is vertically centered; " +
|
|
681
|
-
"(3) mobile 390x844, scrolled so the target is vertically centered; " +
|
|
682
|
-
"(4) desktop 1440x900, hover state on the target control; " +
|
|
683
|
-
"(5) desktop 1440x900, keyboard-focus state on the target control; " +
|
|
684
|
-
"(6) desktop 1440x900, active/pressed state if the target is a button or control. " +
|
|
685
|
-
"Also record: console error count, the ARIA tree of the target region, any horizontal overflow. " +
|
|
686
|
-
"Name captures " + kind + "-<n>-<viewport>-<state>. Return the captures, not a summary.";
|
|
687
|
-
}
|
|
570
|
+
|
|
688
571
|
// Experiential flag resolution: the task is experiential when Sage's Triage
|
|
689
572
|
// report ends with the machine-read marker "experiential: yes". The flag is
|
|
690
573
|
// opt-in — a missing or garbled line degrades to "unknown", which callers
|
|
@@ -825,23 +708,9 @@ function releaseDecisionText() {
|
|
|
825
708
|
if (!releaseDecision) return "no machine-readable release decision from the Build report";
|
|
826
709
|
return "release: " + releaseDecision.release + (releaseDecision.version_bump ? ", version_bump: " + releaseDecision.version_bump : " (no version_bump line)");
|
|
827
710
|
}
|
|
828
|
-
//
|
|
829
|
-
//
|
|
830
|
-
//
|
|
831
|
-
// instead. Parking is one atomic dashboard action (parktask): the parked
|
|
832
|
-
// state and the explanatory note land in one transaction, never half.
|
|
833
|
-
// The dispatcher skips parked tasks; a human moving parked→todo
|
|
834
|
-
// mechanically resets the retry counters. Returns the workflow result
|
|
835
|
-
// envelope the launcher sees. If the park call itself fails, the run
|
|
836
|
-
// reports "failed" (retryable) so the next tick re-attempts the park —
|
|
837
|
-
// a lost park is never reported as parked.
|
|
838
|
-
// Terminal cleanup: the run's last act at every park/fail boundary. A run
|
|
839
|
-
// that parks or fails must not leak its worktree, branch, or merge lock.
|
|
840
|
-
// The lifecycle's terminal-cleanup releases the lock unconditionally and
|
|
841
|
-
// reclaims the worktree+branch ONLY when the task branch is fully merged
|
|
842
|
-
// into main (then it is redundant); unmerged work is preserved for the
|
|
843
|
-
// human by design. Fire-and-forget with one bounded retry — the merge-lock
|
|
844
|
-
// lease expiry and the orphan sweep are the backstop for a dead transport.
|
|
711
|
+
// Terminal cleanup: the run's last act — release the lock unconditionally;
|
|
712
|
+
// reclaim worktree+branch only when fully merged (unmerged work is preserved
|
|
713
|
+
// for the human by design). See `docs/decisions/workflow-core.md#park-contract`.
|
|
845
714
|
async function terminalCleanup() {
|
|
846
715
|
for (var attempt = 1; attempt <= 2; attempt++) {
|
|
847
716
|
try {
|
|
@@ -1104,14 +973,7 @@ while (i < STEPS.length) {
|
|
|
1104
973
|
lockHolder = taskId + "/" + activeSessionId;
|
|
1105
974
|
}
|
|
1106
975
|
|
|
1107
|
-
//
|
|
1108
|
-
// Hazel's QA capture pass runs right after Triage, before Map, for tasks
|
|
1109
|
-
// Sage flagged experiential. The capture itself is parent-driven (the
|
|
1110
|
-
// inspection handoff arrives at the root agent, outside this script), so
|
|
1111
|
-
// when no baseline evidence is recorded yet the script logs a note event
|
|
1112
|
-
// and parks with the exact parent protocol + resume path. Never fails the
|
|
1113
|
-
// task over missing evidence: after two requests, baseline:none is
|
|
1114
|
-
// recorded and the task continues without baseline comparison.
|
|
976
|
+
// See docs/decisions/qa-reproduce.md#capture-baseline: baseline evidence for experiential tasks is captured before work begins.
|
|
1115
977
|
if (step.name === "Capture") {
|
|
1116
978
|
var capExp = await resolveExperiential();
|
|
1117
979
|
var bounceSuffix = (mapGateBounceCount > 0 ? "-g" + mapGateBounceCount : "");
|
|
@@ -1133,12 +995,7 @@ while (i < STEPS.length) {
|
|
|
1133
995
|
continue;
|
|
1134
996
|
}
|
|
1135
997
|
var capStatus = await baselineStatus();
|
|
1136
|
-
//
|
|
1137
|
-
// note is only durable while the protocol is unavailable. When
|
|
1138
|
-
// VISUAL_PROTOCOL_AVAILABLE is true, that old decision no longer
|
|
1139
|
-
// stands — fall through to the request path for a fresh capture
|
|
1140
|
-
// attempt. Exact-string trim comparison against the workflow's own
|
|
1141
|
-
// written message (explicit state, never English matching).
|
|
998
|
+
// See docs/decisions/qa-reproduce.md#stale-decision-guard: a stale baseline decision parks fail-closed.
|
|
1142
999
|
var baselineLatestMessage = ("baseline: " + capStatus.baseline_kind + capStatus.baseline_refs).trim();
|
|
1143
1000
|
var baselineStale = VISUAL_PROTOCOL_AVAILABLE && baselineLatestMessage === "baseline: none (visual protocol unavailable)";
|
|
1144
1001
|
if (capStatus.baseline_found && !baselineStale) {
|
|
@@ -1283,17 +1140,7 @@ while (i < STEPS.length) {
|
|
|
1283
1140
|
(PUBLISH_TYPE === "npm" ? " End your report with the release: and version_bump: lines exactly as specified above — keep them on their own lines, lowercase, unrephrased — then a line `worktree: ` followed by the exact working directory path from above (copy it verbatim \u2014 it must match character-for-character), then a final line with exactly: VERDICT: PASS if the build is complete, VERDICT: FAIL if it is not." : " End your report with a line `worktree: ` followed by the exact working directory path from above (copy it verbatim \u2014 it must match character-for-character), then exactly one line: VERDICT: PASS if the build is complete, VERDICT: FAIL if it is not.");
|
|
1284
1141
|
|
|
1285
1142
|
} else if (step.name === "Review") {
|
|
1286
|
-
//
|
|
1287
|
-
// (dispatcher resume at Review after a platform death between phases),
|
|
1288
|
-
// recover the workflow-verified sha. Room #16 blocker 11: the structured
|
|
1289
|
-
// session field is read FIRST — the `already_merged_verified:` notes line
|
|
1290
|
-
// is only a fallback, because session notes are hard-capped at 3000
|
|
1291
|
-
// chars and a truthful declaration at the report's tail was silently
|
|
1292
|
-
// truncated. The structured value was written by the workflow after a
|
|
1293
|
-
// mechanical ancestor check — it is trusted; the builder's bare
|
|
1294
|
-
// declaration never is. Absent both, the mechanical fact below reads
|
|
1295
|
-
// "none declared" and Cass fails closed. The hydration read is best-effort:
|
|
1296
|
-
// a transport throw degrades to "none declared" rather than crashing Review.
|
|
1143
|
+
// See docs/decisions/publish-path.md#already-merged-hydra: when this run did not execute, hydration uses the existing merge.
|
|
1297
1144
|
if (!alreadyMergedSha) {
|
|
1298
1145
|
var hydResult = null;
|
|
1299
1146
|
try {
|
|
@@ -1401,25 +1248,7 @@ while (i < STEPS.length) {
|
|
|
1401
1248
|
"published: muse-crew@" + publishTarget.target + "\n" +
|
|
1402
1249
|
"VERDICT: PASS\n\n";
|
|
1403
1250
|
} else if (PUBLISH_TYPE === "artifact") {
|
|
1404
|
-
//
|
|
1405
|
-
// agent claimed "Rebuilt and deployed" while no build ran and no
|
|
1406
|
-
// provenance was stamped — prose-trusted side effects, the same failure
|
|
1407
|
-
// class as the npm double-skip (bb739316). The npm path already runs one
|
|
1408
|
-
// deterministic script; the artifact path now has the same shape. Lock
|
|
1409
|
-
// refresh, rebuild trigger, build-completion poll, and post-deploy are
|
|
1410
|
-
// narrow schema'd bookkeeping calls owned by the workflow — the work
|
|
1411
|
-
// agent reports on the mechanical outcome and cannot skip what it never
|
|
1412
|
-
// owned. Any step failing parks with an honest, step-specific reason
|
|
1413
|
-
// (fail-closed). There is deliberately NO workflow-side provenance
|
|
1414
|
-
// stamp: the builder's applied-report is circular (canary run 8,
|
|
1415
|
-
// 2026-09-11), so the stamp moved to the parent — after the build
|
|
1416
|
-
// lands, the workflow records the session completed and parks with
|
|
1417
|
-
// "publish: verification-requested". The parent owns verification
|
|
1418
|
-
// (docs/publish-verification.md); the primary sensor is the
|
|
1419
|
-
// deterministic lib/readback-disk.js (the agent-callable read-back
|
|
1420
|
-
// tool is unavailable — artifact_inspect was removed by the platform
|
|
1421
|
-
// 2026-09-14 — so the LLM-inspector path is manual-fallback only).
|
|
1422
|
-
// Chore has no QA: the parent's verification is the final gate.
|
|
1251
|
+
// See docs/decisions/publish-path.md#deterministic-artifact-publish: the work agent never publishes; the parent runs the deterministic publish script.
|
|
1423
1252
|
var artifactPublish = null;
|
|
1424
1253
|
var publishLockRefreshed = false;
|
|
1425
1254
|
var publishSkippedNoLock = false;
|
|
@@ -1446,20 +1275,7 @@ while (i < STEPS.length) {
|
|
|
1446
1275
|
}
|
|
1447
1276
|
publishLockRefreshed = true;
|
|
1448
1277
|
}
|
|
1449
|
-
//
|
|
1450
|
-
// builder. The builder's source tree is NOT the crew's repo —
|
|
1451
|
-
// canary run 4 (2026-09-11) proved it: Publish asked for "rebuild
|
|
1452
|
-
// from current source. Do not modify any source files" and the
|
|
1453
|
-
// builder rebuilt a stale copy predating the canary's changes, then
|
|
1454
|
-
// the workflow stamped the new commit hash on the stale build.
|
|
1455
|
-
// Provenance fiction; all eight phases passed. The merge diff is
|
|
1456
|
-
// embedded in the edit request; the builder applies it to its own
|
|
1457
|
-
// tree and reports the applied changes; the workflow verifies the
|
|
1458
|
-
// report matches the diff BEFORE stamping provenance. A mismatch
|
|
1459
|
-
// parks without stamping — the stamp must never certify a build
|
|
1460
|
-
// whose content was not verified.
|
|
1461
|
-
// Skipped entirely when no lock was held — nothing merged, nothing
|
|
1462
|
-
// to ship.
|
|
1278
|
+
// See docs/decisions/publish-path.md#step1-builder-source: the builder's source tree is NOT the crew's repo; verify report before stamping.
|
|
1463
1279
|
if (!publishSkippedNoLock) {
|
|
1464
1280
|
// The trigger key of the attempt that last ran, for the publish ledger.
|
|
1465
1281
|
// Minted once here (not re-minted per use site) so the ledger always
|
|
@@ -1540,20 +1356,7 @@ while (i < STEPS.length) {
|
|
|
1540
1356
|
return await parkTask("Publish cannot proceed for task " + taskId + ": the artifact target preflight was inconclusive (no parsable signal). Target existence is unproven, so no edit was issued and nothing was retried blindly. Human attention needed.");
|
|
1541
1357
|
}
|
|
1542
1358
|
log("Publish artifact preflight for task " + taskId + ": target " + artifactTargetDir + " present");
|
|
1543
|
-
//
|
|
1544
|
-
// verification, bounded poll, and provenance stamp. The builder
|
|
1545
|
-
// only makes the artifact_edit call and reports the applied
|
|
1546
|
-
// changes — no prose claim to trust. If the artifact tool namespace
|
|
1547
|
-
// is missing from this child it reports honestly and the workflow
|
|
1548
|
-
// retries once with a fresh key (bounded); anything else parks.
|
|
1549
|
-
// Publish diff base (2026-09-14, task 0c53af4e): the carried diff is
|
|
1550
|
-
// BASE..HEAD where BASE is the previously-stamped provenance
|
|
1551
|
-
// source_commit — NOT HEAD^1. A push-time reconcile merge puts the
|
|
1552
|
-
// task's own changes behind an intermediate merge, so HEAD^1..HEAD
|
|
1553
|
-
// silently drops the task's fix while the artifact builds without
|
|
1554
|
-
// it. The stamped base is the artifact's actual content; BASE..HEAD
|
|
1555
|
-
// is the complete unpublished delta. Empty tree only for a genuine
|
|
1556
|
-
// first publish (no provenance stamped yet).
|
|
1359
|
+
// See docs/decisions/publish-path.md#diff-computation: the diff is computed, the rebuild is triggered, and the report is verified.
|
|
1557
1360
|
var EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
1558
1361
|
var provResult = await agent(
|
|
1559
1362
|
crewCmd("get-provenance", { project_id: LAUNCH_PROJECT_ID }) + "\n" +
|
|
@@ -1569,16 +1372,7 @@ while (i < STEPS.length) {
|
|
|
1569
1372
|
} else if (!/^[0-9a-f]{40}$/.test(publishBase)) {
|
|
1570
1373
|
return await parkTask("Publish base '" + publishBase + "' is not a valid commit SHA — cannot compute the publish diff. Human attention needed.");
|
|
1571
1374
|
}
|
|
1572
|
-
//
|
|
1573
|
-
// ferried as a JSON string field in the agent's response — the agent
|
|
1574
|
-
// produced a valid 700-line diff on disk but the JSON ferry dropped
|
|
1575
|
-
// it, and the parse saw zero files ("Publish diff parsed to zero
|
|
1576
|
-
// files"). The diff now travels git -> file -> deterministic script
|
|
1577
|
-
// summary; the LLM never carries diff bytes. The agent is pure hands:
|
|
1578
|
-
// it runs exactly one command (the PINNED compute-publish-diff.js —
|
|
1579
|
-
// a mid-run release swap cannot change it under the workflow) and
|
|
1580
|
-
// returns the small JSON summary verbatim. All fail-closed parks
|
|
1581
|
-
// below are unchanged in meaning.
|
|
1375
|
+
// See docs/decisions/publish-path.md#diff-transport: the diff travels via file, not the LLM.
|
|
1582
1376
|
var publishDiffFile = crewHome + "/.publish-diffs/" + taskId + (reworkCount > 0 ? "-r" + reworkCount : "") + ".diff";
|
|
1583
1377
|
var diffResult = await agent(
|
|
1584
1378
|
"Run exactly one command and nothing else:\n" +
|
|
@@ -1603,6 +1397,7 @@ while (i < STEPS.length) {
|
|
|
1603
1397
|
return await parkTask("Publish diff base mismatch: script reported '" + String(diffSummary.base || "").slice(0, 12) + "' but the stamped base is '" + publishBase.slice(0, 12) + "'. Human attention needed.");
|
|
1604
1398
|
}
|
|
1605
1399
|
var mergeCommitForPublish = String(diffSummary.commit || "").trim();
|
|
1400
|
+
var mergeCommitShortForPublish = String(mergeCommitForPublish).substring(0, 7) || "unknown";
|
|
1606
1401
|
var publishDiffSha256 = String(diffSummary.sha256 || "");
|
|
1607
1402
|
if (!diffSummary.bytes) {
|
|
1608
1403
|
return await parkTask("Publish diff is empty for commit " + (mergeCommitForPublish || "unknown") + " — a merge lock was held but there is no change to carry. Human attention needed.");
|
|
@@ -1654,83 +1449,44 @@ while (i < STEPS.length) {
|
|
|
1654
1449
|
"- If artifact_edit is not available after the load, do NOT improvise — end your turn.\n" +
|
|
1655
1450
|
"- You do NOT call setprovenance, artifact_inspect, or post-deploy yourself.\n" +
|
|
1656
1451
|
"No report is needed: do not return JSON, do not summarize what you did, do not echo the diff. End your turn after the artifact_edit call.\n";
|
|
1657
|
-
//
|
|
1658
|
-
// workflow-owned observation below. The agent_id is the artifact
|
|
1659
|
-
// system's in-flight correlation ID (research 2026-09-12):
|
|
1660
|
-
// artifact.edit returns pending_init with NO agent_id, but
|
|
1661
|
-
// artifact_status exposes build.agent_id immediately after
|
|
1662
|
-
// acceptance, stable across polls. Recorded in the ledger so an
|
|
1663
|
-
// attempt correlates to the exact builder run; null when no build
|
|
1664
|
-
// was ever observed.
|
|
1452
|
+
// See docs/decisions/publish-path.md#agent-id-attribution: the artifact build's agent_id is attributed to the edit call.
|
|
1665
1453
|
var rebuildAgentId = null;
|
|
1666
|
-
//
|
|
1667
|
-
// trigger's JSON closeout contract, which is removed below. The
|
|
1668
|
-
// parent's independent read-back (docs/publish-verification.md) is
|
|
1669
|
-
// the verification — this field stays "missing-report" on ledger
|
|
1670
|
-
// lines for issued triggers; pre-trigger parks (toolcheck
|
|
1671
|
-
// rejected/inconclusive) and unattributed-unknown parks write null
|
|
1672
|
-
// (no trigger was observed, so there is nothing to report).
|
|
1454
|
+
// See docs/decisions/publish-path.md#applied-report-gone: the builder's applied report is gone; the workflow verifies differently.
|
|
1673
1455
|
var publishAppliedObservation = "missing-report";
|
|
1674
|
-
//
|
|
1675
|
-
// detects IN-FLIGHT builds. A build that finished before the
|
|
1676
|
-
// observation leaves no in-flight trace — but the platform's audit
|
|
1677
|
-
// harness leaves a durable one:
|
|
1678
|
-
// ~/workspace/ts-spaces/<slug>/audits/<timestamp>-<id>/ per
|
|
1679
|
-
// completed build. Snapshot the listing BEFORE the trigger so the
|
|
1680
|
-
// fallback can diff before/after: a directory appearing during the
|
|
1681
|
-
// trigger window is positive evidence the edit went through and
|
|
1682
|
-
// the build completed. Best-effort and non-gating: if the snapshot
|
|
1683
|
-
// fails, auditBeforeOk stays false and BOTH fallback comparisons
|
|
1684
|
-
// are disabled (2026-09-16, critic finding 4) — without a baseline,
|
|
1685
|
-
// an empty before-list would make every historical audit dir look
|
|
1686
|
-
// "new". No wall-clock in-script (deterministic replay) — the
|
|
1687
|
-
// comparison is a pure before/after set diff.
|
|
1456
|
+
// See docs/decisions/publish-path.md#durable-evidence-snapshot: snapshot the audit-dir listing BEFORE the trigger; fallback diffs before/after.
|
|
1688
1457
|
var auditDirsBeforeTrigger = [];
|
|
1689
1458
|
var auditBeforeOk = false;
|
|
1459
|
+
// Pre-trigger baselines (design §1.9): the audit-dir listing and the
|
|
1460
|
+
// manifest snapshot. The verified-path freshness check compares the
|
|
1461
|
+
// post-trigger manifest against the baseline (built_at advance +
|
|
1462
|
+
// content_sha256 change). Best-effort, never gates — a missing
|
|
1463
|
+
// manifest baseline fails the verified path closed.
|
|
1464
|
+
var preTriggerManifest = null;
|
|
1690
1465
|
try {
|
|
1691
1466
|
var auditBefore = await agent(
|
|
1692
|
-
"
|
|
1693
|
-
"Run: ls -1 ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/ 2>/dev/null\n" +
|
|
1694
|
-
"Return JSON { \"dirs\": \"<newline-separated names, empty string when
|
|
1695
|
-
{ key: attemptKey("publish-
|
|
1696
|
-
schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
|
|
1467
|
+
"Capture pre-trigger baselines for slug \"" + PUBLISH_SLUG + "\" (best-effort snapshots, never gates).\n" +
|
|
1468
|
+
"Run: ls -1 ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/ 2>/dev/null; echo ---MANIFEST---; cat ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/.space-build/manifest.json 2>/dev/null\n" +
|
|
1469
|
+
"Return JSON { \"dirs\": \"<newline-separated names, empty string when missing>\", \"manifest\": \"<the manifest's full text, or empty string when missing/unreadable>\" } and nothing else.",
|
|
1470
|
+
{ key: attemptKey("publish-baseline-before-" + taskId, reworkCount), label: "Snapshotting baselines before rebuild trigger",
|
|
1471
|
+
schema: { type: "object", properties: { dirs: { type: "string" }, manifest: { type: "string" } }, required: ["dirs", "manifest"] } }
|
|
1697
1472
|
);
|
|
1698
1473
|
auditDirsBeforeTrigger = String((auditBefore && auditBefore.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
|
|
1474
|
+
var manifestText = String((auditBefore && auditBefore.manifest) || "").trim();
|
|
1475
|
+
if (manifestText) {
|
|
1476
|
+
var manifestJson = JSON.parse(manifestText);
|
|
1477
|
+
preTriggerManifest = {
|
|
1478
|
+
built_at: typeof manifestJson.built_at === "string" ? manifestJson.built_at : null,
|
|
1479
|
+
content_sha256: typeof manifestJson.content_sha256 === "string" ? manifestJson.content_sha256 : null,
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
// Arm only after both baselines parse.
|
|
1699
1483
|
auditBeforeOk = true;
|
|
1700
|
-
log("Publish
|
|
1484
|
+
log("Publish pre-trigger baselines for task " + taskId + ": " + auditDirsBeforeTrigger.length + " audit dirs, manifest " + (preTriggerManifest ? "built_at=" + preTriggerManifest.built_at : "none"));
|
|
1701
1485
|
} catch (auditBeforeErr) {
|
|
1702
|
-
log("Publish
|
|
1486
|
+
log("Publish pre-trigger baselines failed for task " + taskId + " (non-fatal): audit fallback DISABLED for this attempt — without a baseline, historical dirs would look new: " + (auditBeforeErr && auditBeforeErr.message ? auditBeforeErr.message : auditBeforeErr));
|
|
1703
1487
|
}
|
|
1704
|
-
|
|
1705
|
-
//
|
|
1706
|
-
// traveled over the stochastic text channel, and the runtime's
|
|
1707
|
-
// JSON-candidate heuristic misfired on it ("workflow agent output
|
|
1708
|
-
// was not JSON: no JSON object or array found in final response"),
|
|
1709
|
-
// parking a task whose edit may have gone through. The contract's
|
|
1710
|
-
// content was already observation-only (the applied report never
|
|
1711
|
-
// gated; the pre_hashes were diagnostic-only), so the contract is
|
|
1712
|
-
// removed: the trigger carries NO schema and its return value is
|
|
1713
|
-
// never consumed, which takes the extraction heuristic out of this
|
|
1714
|
-
// call entirely. The workflow attributes the edit itself through
|
|
1715
|
-
// the tiny schema'd reads below — no prose is parsed for the
|
|
1716
|
-
// trigger outcome.
|
|
1717
|
-
// (Probe, 2026-09-16: the workflow scope exposes only agent() —
|
|
1718
|
-
// tool_search, artifact_edit and artifact_status are undefined
|
|
1719
|
-
// there — so the workflow cannot call the artifact tools directly;
|
|
1720
|
-
// observation still goes through minimal child calls with tiny
|
|
1721
|
-
// schemas, never a broad JSON contract.)
|
|
1722
|
-
//
|
|
1723
|
-
// Pre-trigger toolcheck (tiny, schema'd): the artifact namespace is
|
|
1724
|
-
// deferred for workflow children — the child self-loads it and emits
|
|
1725
|
-
// one exact signal line, read mechanically (never English prose).
|
|
1726
|
-
// Only a parsed ARTIFACT_TOOLS: missing signal is explicit negative
|
|
1727
|
-
// evidence: it gets one bounded retry with a fresh key, then parks
|
|
1728
|
-
// rejected — without the tools the edit provably did NOT go through,
|
|
1729
|
-
// so this is the one safe retry on the publish path. A throw (or an
|
|
1730
|
-
// unparseable signal) is INCONCLUSIVE transport noise, never
|
|
1731
|
-
// evidence of missing tools (2026-09-16, critic finding 3): it is
|
|
1732
|
-
// recorded, it retries once in case the flake clears, but it can
|
|
1733
|
-
// never take the rejected path.
|
|
1488
|
+
|
|
1489
|
+
// See docs/decisions/publish-path.md#fire-and-forget-trigger: the trigger child returns immediately; the workflow owns observation and verdict.
|
|
1734
1490
|
var publishToolsOk = false;
|
|
1735
1491
|
var publishToolsMissing = false;
|
|
1736
1492
|
for (var toolcheckAttempt = 1; toolcheckAttempt <= 2 && !publishToolsOk; toolcheckAttempt++) {
|
|
@@ -1778,14 +1534,7 @@ while (i < STEPS.length) {
|
|
|
1778
1534
|
}, reworkCount);
|
|
1779
1535
|
return await parkTask("Publish cannot proceed for task " + taskId + ": the artifact tool namespace was explicitly missing (parsed signal — the edit provably did not go through, so no trigger was issued and nothing was retried blindly). Human attention needed.");
|
|
1780
1536
|
}
|
|
1781
|
-
//
|
|
1782
|
-
// artifact_status. The post-trigger observation diffs against this
|
|
1783
|
-
// baseline — a build whose agent_id was absent from (or differs
|
|
1784
|
-
// from) the baseline is attributed to our edit; a build already in
|
|
1785
|
-
// flight at baseline predates the trigger and is never attributed
|
|
1786
|
-
// to it. If the baseline read itself fails, receipt attribution is
|
|
1787
|
-
// skipped and the durable audit-dir evidence below is the only
|
|
1788
|
-
// positive signal.
|
|
1537
|
+
// See docs/decisions/publish-path.md#pretrigger-baseline: a tiny schema'd baseline is captured before the trigger.
|
|
1789
1538
|
var baselineAgentId = null;
|
|
1790
1539
|
var baselineFailed = false;
|
|
1791
1540
|
try {
|
|
@@ -1802,32 +1551,13 @@ while (i < STEPS.length) {
|
|
|
1802
1551
|
baselineFailed = true;
|
|
1803
1552
|
log("Publish pre-trigger baseline read failed for task " + taskId + " (" + (baselineErr && baselineErr.message ? baselineErr.message : baselineErr) + ") — receipt attribution skipped; durable audit-dir evidence is the only positive signal");
|
|
1804
1553
|
}
|
|
1805
|
-
//
|
|
1806
|
-
// waits for it to complete) but its return value is intentionally
|
|
1807
|
-
// UNCONSUMED — NO schema, so no schema validation can fail this
|
|
1808
|
-
// call: a schema-less call resolves to the child's raw response as
|
|
1809
|
-
// a plain string (probed live 2026-09-16 — never parsed, never
|
|
1810
|
-
// throws on content). One caveat, also probed: the runtime still
|
|
1811
|
-
// scans the response for a JSON candidate, and an unparseable
|
|
1812
|
-
// {...}-looking substring in the child's prose throws ("response
|
|
1813
|
-
// JSON candidate", probe P6). The prompt tells the child to end its
|
|
1814
|
-
// turn with no prose at all, which keeps the common case clean —
|
|
1815
|
-
// but the channel is stochastic, so any throw is possible and
|
|
1816
|
-
// inconclusive: the edit may still have gone through, so the
|
|
1817
|
-
// outcome stays unknown until the observation below confirms it —
|
|
1818
|
-
// never inferred from the throw, and never blind-retried (a blind
|
|
1819
|
-
// re-trigger duplicated the edit on 2026-09-12).
|
|
1554
|
+
// See docs/decisions/publish-path.md#trigger-await: the artifact_edit call is awaited.
|
|
1820
1555
|
var rebuildTrigger = null;
|
|
1821
1556
|
try {
|
|
1822
1557
|
var triggerText = String(await agent(rebuildPrompt,
|
|
1823
1558
|
{ key: rebuildAttemptKey, label: "Triggering artifact rebuild" }) || "");
|
|
1824
1559
|
log("Publish rebuild trigger for task " + taskId + " returned (" + triggerText.length + " chars; awaited; scanned only for the explicit refusal signal)");
|
|
1825
|
-
//
|
|
1826
|
-
// with ARTIFACT_EDIT_REFUSED when artifact_edit explicitly refused.
|
|
1827
|
-
// Conclusive negative evidence — the edit provably did NOT go
|
|
1828
|
-
// through — so this parks rejected and skips observation polling.
|
|
1829
|
-
// A missing/unparseable signal is NOT a refusal: it stays unknown
|
|
1830
|
-
// and fail-closed below.
|
|
1560
|
+
// See docs/decisions/publish-path.md#explicit-refusal-16: the child must explicitly refuse artifact work.
|
|
1831
1561
|
var refusalText = extractRefusal(triggerText);
|
|
1832
1562
|
if (refusalText) {
|
|
1833
1563
|
await recordPublishLedger({
|
|
@@ -1874,17 +1604,79 @@ while (i < STEPS.length) {
|
|
|
1874
1604
|
log("Publish post-trigger build-state check failed for task " + taskId + " (" + (buildCheckErr && buildCheckErr.message ? buildCheckErr.message : buildCheckErr) + ") — this signal is unknown, not negative");
|
|
1875
1605
|
}
|
|
1876
1606
|
var observedAgentId = (buildState && buildState.build && typeof buildState.build.agent_id === "string" && buildState.build.agent_id) || null;
|
|
1877
|
-
//
|
|
1878
|
-
// is timing-based — any agent_id new relative to the baseline is
|
|
1879
|
-
// treated as this edit's receipt. A stranger's build starting inside
|
|
1880
|
-
// the trigger window is indistinguishable by timing and would be
|
|
1881
|
-
// misattributed here. The consequence is bounded: the completion
|
|
1882
|
-
// poll below tracks the recorded id, and the parent's mechanical
|
|
1883
|
-
// content read-back (docs/publish-verification.md) certifies the
|
|
1884
|
-
// exact commit's content — a wrong build's content fails closed as
|
|
1885
|
-
// verification-failed, never stamped. Timing narrows the candidate;
|
|
1886
|
-
// content decides.
|
|
1607
|
+
// See docs/decisions/publish-path.md#attribution-limitation: attribution is timing-based; content verification bounds the risk.
|
|
1887
1608
|
var receiptAgentId = (!buildStateFailed && !baselineFailed && observedAgentId && observedAgentId !== baselineAgentId) ? observedAgentId : null;
|
|
1609
|
+
// auditReportOk: pure tri-state read of a report.json body —
|
|
1610
|
+
// true (build ok), false (build failed), null (missing or
|
|
1611
|
+
// unreadable — not evidence either way). The child returns the
|
|
1612
|
+
// raw body verbatim; interpretation lives here, never in prose.
|
|
1613
|
+
// Hoisted to Publish-step scope (before the receipt branch) so both
|
|
1614
|
+
// the immediate and post-poll audit fallbacks share it on every path —
|
|
1615
|
+
// the receipt path skips the else below, which must not leave these
|
|
1616
|
+
// undefined.
|
|
1617
|
+
var auditReportOk = function (raw) {
|
|
1618
|
+
if (typeof raw !== "string") return null;
|
|
1619
|
+
var trimmed = raw.trim();
|
|
1620
|
+
if (trimmed === "" || trimmed === "MISSING") return null;
|
|
1621
|
+
var parsed;
|
|
1622
|
+
try { parsed = JSON.parse(trimmed); } catch (e) { return null; }
|
|
1623
|
+
if (parsed && typeof parsed.ok === "boolean") return parsed.ok;
|
|
1624
|
+
return null;
|
|
1625
|
+
};
|
|
1626
|
+
// (2026-09-18, H2 verdict-first) Publish-verdict vocabulary. The
|
|
1627
|
+
// verdict is one of "landed" | "unknown". Decided once,
|
|
1628
|
+
// before the receipt poll, and dispatched on — never re-derived.
|
|
1629
|
+
// Pure and self-contained: unit-tested by
|
|
1630
|
+
// tests/publish-verdict-first.test.js.
|
|
1631
|
+
// See docs/decisions/publish-path.md#h2-verdict-dispatch.
|
|
1632
|
+
var decidePublishVerdict = function (opts) {
|
|
1633
|
+
var immediateReport = (opts && "immediateReport" in opts) ? opts.immediateReport : null;
|
|
1634
|
+
var newDirCount = (opts && typeof opts.newDirCount === "number") ? opts.newDirCount : 0;
|
|
1635
|
+
if (newDirCount === 1 && immediateReport === true) return { verdict: "landed", unattributableReason: null };
|
|
1636
|
+
if (newDirCount === 1 && immediateReport === false) return { verdict: "unknown", unattributableReason: "audit-report-ok-false" };
|
|
1637
|
+
if (newDirCount === 1) return { verdict: "unknown", unattributableReason: "audit-report-unreadable-or-missing" };
|
|
1638
|
+
if (newDirCount === 0) return { verdict: "unknown", unattributableReason: "no-new-audit-dir-in-window" };
|
|
1639
|
+
return { verdict: "unknown", unattributableReason: "audit-dir-ambiguity", ambiguousDirCount: newDirCount };
|
|
1640
|
+
};
|
|
1641
|
+
// (2026-09-18, H2 message contract, design §1.5) The human line is
|
|
1642
|
+
// the output of a mechanical field→template mapping: the trigger
|
|
1643
|
+
// commit short-sha, one plain clause per unattributable reason, the
|
|
1644
|
+
// no-republish warning, the ledger path with (outcome: unknown), and
|
|
1645
|
+
// the unknown-recovery clause. The appendix carries every machine
|
|
1646
|
+
// field. Pure and self-contained: unit-tested by
|
|
1647
|
+
// tests/publish-verdict-first.test.js.
|
|
1648
|
+
var composeUnattributedParkReason = function (fields) {
|
|
1649
|
+
var f = fields || {};
|
|
1650
|
+
var task = f.taskId || taskId;
|
|
1651
|
+
var reason = f.unattributableReason || "unknown-outcome";
|
|
1652
|
+
var shortSha = String(f.commitShortSha || "").substring(0, 7) || "unknown";
|
|
1653
|
+
var reasonClauses = {
|
|
1654
|
+
"no-new-audit-dir-in-window": "no build could be tied to this attempt",
|
|
1655
|
+
"audit-report-unreadable-or-missing": "the build's report is unreadable",
|
|
1656
|
+
"audit-dir-ambiguity": "more than one build appeared in the check window",
|
|
1657
|
+
"stranger-build-observed-during-poll": "a different build was running during the check",
|
|
1658
|
+
"status-read-errors-during-poll": "status reads kept failing"
|
|
1659
|
+
};
|
|
1660
|
+
var clause = reasonClauses[reason] || "no build could be tied to this attempt";
|
|
1661
|
+
return "Publish outcome unknown for task " + task +
|
|
1662
|
+
": the trigger was sent for commit " + shortSha + " but the outcome could not be confirmed — " + clause + ". " +
|
|
1663
|
+
"Do NOT republish: if the trigger was accepted, a retry duplicates the build (2026-09-12). " +
|
|
1664
|
+
"The attempt is in the ledger at " + crewHome + "/.publish-ledger/" + PUBLISH_SLUG + ".jsonl (outcome: unknown) " +
|
|
1665
|
+
"and the crew's unknown-recovery will re-examine it. " +
|
|
1666
|
+
"Appendix: unattributable_reason=" + reason +
|
|
1667
|
+
"; poll_end_state=" + (f.pollEndState || "not-polled") +
|
|
1668
|
+
"; saw_our_build=" + (f.sawOurBuild ? "true" : "false") +
|
|
1669
|
+
"; new_audit_dirs=" + (f.newAuditDirCount == null ? 0 : f.newAuditDirCount) +
|
|
1670
|
+
"; poll_chunks_failed=" + (f.chunkFailures == null ? 0 : f.chunkFailures) +
|
|
1671
|
+
"; poll_status_errors=" + (f.pollStatusErrors == null ? 0 : f.pollStatusErrors) + ".";
|
|
1672
|
+
};
|
|
1673
|
+
// publishFailure is declared here (per-Publish-pass scope) so the
|
|
1674
|
+
// post-poll explicit build failure survives to the final routing
|
|
1675
|
+
// below; publishUnknownFields carries the structured unknown fields
|
|
1676
|
+
// for the single composed fail-closed park. Both re-initialize on
|
|
1677
|
+
// every pass — a rework re-entry never leaks a stale verdict.
|
|
1678
|
+
var publishFailure = null;
|
|
1679
|
+
var publishUnknownFields = null;
|
|
1888
1680
|
if (receiptAgentId) {
|
|
1889
1681
|
// The edit went through — a build with a new agent_id appeared
|
|
1890
1682
|
// after the trigger. The parent's independent read-back
|
|
@@ -1898,36 +1690,12 @@ while (i < STEPS.length) {
|
|
|
1898
1690
|
attempt: rebuildAttemptKey,
|
|
1899
1691
|
agent_id: rebuildAgentId,
|
|
1900
1692
|
applied_report: publishAppliedObservation,
|
|
1693
|
+
manifest_before: preTriggerManifest,
|
|
1901
1694
|
outcome: "submitted",
|
|
1902
1695
|
detail: "fire-and-forget trigger; build receipt captured by workflow-owned build-state observation (pre/post-trigger diff)"
|
|
1903
1696
|
}, reworkCount);
|
|
1904
1697
|
} else {
|
|
1905
1698
|
var newAuditDirs = [];
|
|
1906
|
-
// auditReportOk: pure tri-state read of a report.json body —
|
|
1907
|
-
// true (build ok), false (build failed), null (missing or
|
|
1908
|
-
// unreadable — not evidence either way). The child returns the
|
|
1909
|
-
// raw body verbatim; interpretation lives here, never in prose.
|
|
1910
|
-
// Defined here so both the immediate and post-poll audit
|
|
1911
|
-
// fallbacks share it.
|
|
1912
|
-
var auditReportOk = function (raw) {
|
|
1913
|
-
if (typeof raw !== "string") return null;
|
|
1914
|
-
var trimmed = raw.trim();
|
|
1915
|
-
if (trimmed === "" || trimmed === "MISSING") return null;
|
|
1916
|
-
var parsed;
|
|
1917
|
-
try { parsed = JSON.parse(trimmed); } catch (e) { return null; }
|
|
1918
|
-
if (parsed && typeof parsed.ok === "boolean") return parsed.ok;
|
|
1919
|
-
return null;
|
|
1920
|
-
};
|
|
1921
|
-
// (2026-09-16, critic finding 2) When durable audit evidence
|
|
1922
|
-
// confirms (or refutes) the build, there is no receipt agent_id
|
|
1923
|
-
// to chain the completion poll to — skipReceiptPoll bypasses the
|
|
1924
|
-
// poll below, which with a null receipt could only observe
|
|
1925
|
-
// strangers or nothing.
|
|
1926
|
-
var skipReceiptPoll = false;
|
|
1927
|
-
// publishFailure is declared here (moved up from below) so the
|
|
1928
|
-
// immediate audit fallback can record an explicit build failure
|
|
1929
|
-
// without the later declaration resetting it.
|
|
1930
|
-
var publishFailure = null;
|
|
1931
1699
|
try {
|
|
1932
1700
|
var auditAfter = await agent(
|
|
1933
1701
|
"List the artifact audit directories for slug \"" + PUBLISH_SLUG + "\" (best-effort, never a gate).\n" +
|
|
@@ -1947,88 +1715,110 @@ while (i < STEPS.length) {
|
|
|
1947
1715
|
log("Publish audit-dir re-list after trigger failed for task " + taskId + " (non-fatal, durable-evidence check degraded): " + (auditAfterErr && auditAfterErr.message ? auditAfterErr.message : auditAfterErr));
|
|
1948
1716
|
}
|
|
1949
1717
|
if (newAuditDirs.length > 0) {
|
|
1950
|
-
rebuildTrigger = { edit_started: true };
|
|
1951
1718
|
rebuildAgentId = null;
|
|
1952
1719
|
newAuditDirs.sort();
|
|
1953
1720
|
var newestImmediateDir = newAuditDirs[newAuditDirs.length - 1];
|
|
1954
1721
|
log("Publish rebuild trigger for task " + taskId + ": new audit dir(s) during the trigger window (" + newAuditDirs.join(", ") + ") — the edit went through and a build completed; no in-flight receipt was observed.");
|
|
1955
|
-
// (2026-09-
|
|
1722
|
+
// (2026-09-18, H2 verdict-first) Durable audit evidence exists,
|
|
1956
1723
|
// but there is no receipt agent_id to chain the completion poll
|
|
1957
1724
|
// to — polling with a null receipt can only observe strangers
|
|
1958
1725
|
// (any running build differs from "null") or nothing, burning
|
|
1959
|
-
// 10.5 minutes to park unknown. Read the build report now
|
|
1960
|
-
//
|
|
1961
|
-
//
|
|
1962
|
-
//
|
|
1726
|
+
// 10.5 minutes to park unknown. Read the build report now instead
|
|
1727
|
+
// of polling, then decide the verdict ONCE via
|
|
1728
|
+
// decidePublishVerdict: exactly one new dir with ok=true lands
|
|
1729
|
+
// (attribution by window, not identity — never poll blind);
|
|
1730
|
+
// ok=false is UNKNOWN with the failure evidence preserved in the
|
|
1731
|
+
// ledger detail (the evidence is explicit, the attribution is
|
|
1732
|
+
// not); unreadable / zero / ambiguous dirs are UNKNOWN.
|
|
1733
|
+
// Verdict-first: landed bypasses the poll below, unknown falls
|
|
1734
|
+
// through to post-deploy. STEP 2 runs on every path.
|
|
1735
|
+
// See docs/decisions/publish-path.md#h2-verdict-dispatch.
|
|
1963
1736
|
var immediateReportOk = null;
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1737
|
+
// (N1) Read the report only when exactly one new dir exists:
|
|
1738
|
+
// ambiguity (>1) forces UNKNOWN regardless — don't shell out to
|
|
1739
|
+
// read a report that will be discarded.
|
|
1740
|
+
if (newAuditDirs.length === 1) {
|
|
1741
|
+
try {
|
|
1742
|
+
var immediateOkRead = await agent(
|
|
1743
|
+
"Read the artifact build report for slug \"" + PUBLISH_SLUG + "\".\n" +
|
|
1744
|
+
"Run: cat ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/" + newestImmediateDir + "/report.json 2>/dev/null || echo MISSING\n" +
|
|
1745
|
+
"Return JSON { \"raw\": \"<verbatim file contents, or the literal string MISSING when the file does not exist>\" } and nothing else.",
|
|
1746
|
+
{ key: attemptKey("publish-audit-ok-immediate-" + taskId, reworkCount), label: "Reading build report for audit-confirmed build",
|
|
1747
|
+
schema: { type: "object", properties: { raw: { type: "string" } }, required: ["raw"] } }
|
|
1748
|
+
);
|
|
1749
|
+
immediateReportOk = auditReportOk(immediateOkRead && immediateOkRead.raw);
|
|
1750
|
+
} catch (immediateOkErr) {
|
|
1751
|
+
log("Publish build-report read for audit-confirmed dir failed for task " + taskId + " (treated as unknown): " + (immediateOkErr && immediateOkErr.message ? immediateOkErr.message : immediateOkErr));
|
|
1752
|
+
immediateReportOk = null;
|
|
1753
|
+
}
|
|
1976
1754
|
}
|
|
1977
|
-
|
|
1755
|
+
var immediateVerdict = decidePublishVerdict({ editStarted: true, immediateReport: immediateReportOk, newDirCount: newAuditDirs.length });
|
|
1756
|
+
if (immediateVerdict.verdict === "landed") {
|
|
1978
1757
|
publishBuildLanded = true;
|
|
1979
1758
|
artifactPublish = { source_commit: mergeCommitForPublish, pending_parent_verification: true };
|
|
1980
|
-
skipReceiptPoll = true;
|
|
1981
|
-
log("Publish build landed for task " + taskId + " via immediate durable audit evidence (audit dir " + newestImmediateDir + ", report ok=true) — receipt poll skipped (no receipt to chain to), routing directly to parent verification");
|
|
1982
1759
|
await recordPublishLedger({
|
|
1983
1760
|
commit: mergeCommitForPublish,
|
|
1984
1761
|
attempt: rebuildAttemptKey,
|
|
1985
1762
|
agent_id: null,
|
|
1986
1763
|
applied_report: publishAppliedObservation,
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
} else if (immediateReportOk === false) {
|
|
1991
|
-
skipReceiptPoll = true;
|
|
1992
|
-
publishFailure = "Artifact build FAILED for slug " + PUBLISH_SLUG + " (audit dir " + newestImmediateDir + ", report ok=false — immediate audit evidence, no receipt observed). Explicit negative evidence: a build ran and failed. The publish did not land — provenance was not stamped. Fail-closed.";
|
|
1993
|
-
await recordPublishLedger({
|
|
1994
|
-
commit: mergeCommitForPublish,
|
|
1995
|
-
attempt: rebuildAttemptKey,
|
|
1996
|
-
agent_id: null,
|
|
1997
|
-
applied_report: publishAppliedObservation,
|
|
1998
|
-
outcome: "failed",
|
|
1999
|
-
detail: "a build ran and failed: audit dir " + newestImmediateDir + " report ok=false (immediate audit evidence, no receipt)"
|
|
1764
|
+
manifest_before: preTriggerManifest,
|
|
1765
|
+
outcome: "build-observed",
|
|
1766
|
+
detail: "durable audit evidence shows a build completed during the attempt window (no receipt agent_id — attribution by window, not identity; receipt poll bypassed (verdict decided), routed to parent verification)"
|
|
2000
1767
|
}, reworkCount);
|
|
1768
|
+
log("Publish verdict LANDED for task " + taskId + ": a completed build was observed during the attempt window — receipt poll bypassed (verdict decided, no receipt to chain to), routing directly to parent verification.");
|
|
2001
1769
|
} else {
|
|
1770
|
+
// Verdict UNKNOWN on the immediate path. ok=false is explicit
|
|
1771
|
+
// failure evidence but not an attributable failure — the ledger
|
|
1772
|
+
// records unknown with the evidence preserved in the detail,
|
|
1773
|
+
// and the flow continues to post-deploy (never parks early).
|
|
1774
|
+
publishUnknownFields = {
|
|
1775
|
+
taskId: taskId,
|
|
1776
|
+
unattributableReason: immediateVerdict.unattributableReason,
|
|
1777
|
+
pollEndState: "not-polled",
|
|
1778
|
+
sawOurBuild: false,
|
|
1779
|
+
newAuditDirCount: newAuditDirs.length,
|
|
1780
|
+
chunkFailures: 0,
|
|
1781
|
+
pollStatusErrors: 0
|
|
1782
|
+
};
|
|
1783
|
+
var immediateDetail = "durable audit-dir fallback could not prove a completed build for this attempt (unattributable_reason=" + immediateVerdict.unattributableReason + ", no receipt agent_id)";
|
|
1784
|
+
if (immediateReportOk === false) {
|
|
1785
|
+
immediateDetail += "; explicit failure evidence preserved: report ok=false for audit dir " + newestImmediateDir;
|
|
1786
|
+
}
|
|
1787
|
+
if (immediateVerdict.unattributableReason === "audit-dir-ambiguity") {
|
|
1788
|
+
immediateDetail += "; audit-dir ambiguity: " + newAuditDirs.length + " new dirs in window";
|
|
1789
|
+
}
|
|
2002
1790
|
await recordPublishLedger({
|
|
2003
1791
|
commit: mergeCommitForPublish,
|
|
2004
1792
|
attempt: rebuildAttemptKey,
|
|
2005
1793
|
agent_id: null,
|
|
2006
|
-
applied_report:
|
|
1794
|
+
applied_report: publishAppliedObservation,
|
|
2007
1795
|
outcome: "unknown",
|
|
2008
|
-
detail:
|
|
1796
|
+
detail: immediateDetail
|
|
2009
1797
|
}, reworkCount);
|
|
2010
|
-
|
|
1798
|
+
log("Publish verdict UNKNOWN for task " + taskId + ": " + immediateDetail + " — continuing to post-deploy; never polling blind and never parking early.");
|
|
2011
1799
|
}
|
|
2012
1800
|
} else {
|
|
2013
|
-
//
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
1801
|
+
// See docs/decisions/publish-path.md#no-attributable-build: no attributable build and no durable evidence means no publish.
|
|
1802
|
+
publishUnknownFields = {
|
|
1803
|
+
taskId: taskId,
|
|
1804
|
+
unattributableReason: decidePublishVerdict({ editStarted: true, immediateReport: null, newDirCount: 0 }).unattributableReason,
|
|
1805
|
+
pollEndState: "not-polled",
|
|
1806
|
+
sawOurBuild: false,
|
|
1807
|
+
newAuditDirCount: 0,
|
|
1808
|
+
chunkFailures: 0,
|
|
1809
|
+
pollStatusErrors: 0
|
|
1810
|
+
};
|
|
2020
1811
|
await recordPublishLedger({
|
|
2021
1812
|
commit: mergeCommitForPublish,
|
|
2022
1813
|
attempt: rebuildAttemptKey,
|
|
2023
1814
|
agent_id: null,
|
|
2024
|
-
applied_report:
|
|
1815
|
+
applied_report: publishAppliedObservation,
|
|
2025
1816
|
outcome: "unknown",
|
|
2026
|
-
detail: "
|
|
1817
|
+
detail: "no new audit dir appeared in the trigger window and no receipt agent_id was observed — the edit was issued fire-and-forget, so completion is unproven; never poll blind on a null receipt"
|
|
2027
1818
|
}, reworkCount);
|
|
2028
|
-
|
|
1819
|
+
log("Publish verdict UNKNOWN for task " + taskId + ": no new audit dir in window and no receipt — continuing to post-deploy; never polling blind and never parking early.");
|
|
2029
1820
|
}
|
|
2030
1821
|
}
|
|
2031
|
-
|
|
2032
1822
|
// Durable publish-attempt ledger: record the trigger outcome while the
|
|
2033
1823
|
// attempt key and commit are in scope. Every attempt lands here with
|
|
2034
1824
|
// its outcome — submitted, rejected, or unknown (unknown is recorded
|
|
@@ -2038,9 +1828,45 @@ while (i < STEPS.length) {
|
|
|
2038
1828
|
// already recorded the ledger's submitted line on both positive paths
|
|
2039
1829
|
// and parked on unknown — there is no applied report to observe and
|
|
2040
1830
|
// no rejection signal to record.
|
|
2041
|
-
// (
|
|
2042
|
-
// above
|
|
2043
|
-
|
|
1831
|
+
// (2026-09-18, H2 verdict-first) The verdict was decided exactly
|
|
1832
|
+
// once above; dispatch on it. landed bypasses the receipt poll
|
|
1833
|
+
// (the audit evidence already proved completion); an explicit
|
|
1834
|
+
// publishFailure is preserved verbatim through post-deploy.
|
|
1835
|
+
// Otherwise the verdict is open — but the poll below is only
|
|
1836
|
+
// legitimate against a real receipt: the null-safe assertion records
|
|
1837
|
+
// UNKNOWN and continues to STEP 2 instead of polling blind.
|
|
1838
|
+
// See docs/decisions/publish-path.md#h2-verdict-dispatch.
|
|
1839
|
+
if (publishBuildLanded) {
|
|
1840
|
+
log("Publish verdict already LANDED for task " + taskId + " — bypassing receipt poll.");
|
|
1841
|
+
} else if (publishFailure) {
|
|
1842
|
+
// design §1.2 pre-poll branch — currently unassigned; kept for the converged dispatch shape.
|
|
1843
|
+
log("Publish verdict already FAILED for task " + taskId + " — preserved verbatim through post-deploy.");
|
|
1844
|
+
} else if (!rebuildTrigger || !rebuildTrigger.edit_started) {
|
|
1845
|
+
// Loud defensive assertion (replaces the old lying "Unreachable"
|
|
1846
|
+
// else): with no receipt state the poll would observe strangers or
|
|
1847
|
+
// nothing — record UNKNOWN and continue to STEP 2. Never park
|
|
1848
|
+
// early here; never poll blind.
|
|
1849
|
+
if (!publishUnknownFields) {
|
|
1850
|
+
publishUnknownFields = {
|
|
1851
|
+
taskId: taskId,
|
|
1852
|
+
unattributableReason: "no-receipt-state",
|
|
1853
|
+
pollEndState: "not-polled",
|
|
1854
|
+
sawOurBuild: false,
|
|
1855
|
+
newAuditDirCount: 0,
|
|
1856
|
+
chunkFailures: 0,
|
|
1857
|
+
pollStatusErrors: 0
|
|
1858
|
+
};
|
|
1859
|
+
await recordPublishLedger({
|
|
1860
|
+
commit: mergeCommitForPublish,
|
|
1861
|
+
attempt: rebuildAttemptKey,
|
|
1862
|
+
agent_id: null,
|
|
1863
|
+
applied_report: publishAppliedObservation,
|
|
1864
|
+
outcome: "unknown",
|
|
1865
|
+
detail: "no receipt state was recorded for this attempt — never polling blind; continuing to post-deploy"
|
|
1866
|
+
}, reworkCount);
|
|
1867
|
+
}
|
|
1868
|
+
log("Publish verdict UNKNOWN for task " + taskId + ": no receipt state recorded — never polling blind, continuing to post-deploy.");
|
|
1869
|
+
} else {
|
|
2044
1870
|
// (2026-09-16) There is no builder report: the fire-and-forget
|
|
2045
1871
|
// trigger carries no JSON contract, so there is nothing to
|
|
2046
1872
|
// compare and no pre-hash diagnostic. The builder's old
|
|
@@ -2113,13 +1939,7 @@ while (i < STEPS.length) {
|
|
|
2113
1939
|
timeoutMs: 270000 }
|
|
2114
1940
|
);
|
|
2115
1941
|
} catch (chunkErr) {
|
|
2116
|
-
//
|
|
2117
|
-
// record it and continue to the next chunk. (2026-09-16,
|
|
2118
|
-
// clean-room task 1febe8eb: the platform's 270s agent
|
|
2119
|
-
// timeout killed chunk 2, which threw out of this loop —
|
|
2120
|
-
// skipping chunk 3 AND the STEP 1b audit-dir fallback and
|
|
2121
|
-
// parking on the exception path.) Fail-closed still applies
|
|
2122
|
-
// after chunk 3 and the fallback are exhausted.
|
|
1942
|
+
// See docs/decisions/publish-path.md#hung-chunk: a hung or failed chunk is inconclusive, never terminal.
|
|
2123
1943
|
chunkFailures.push("chunk " + chunk + ": " + (chunkErr && chunkErr.message ? chunkErr.message : chunkErr));
|
|
2124
1944
|
log("Artifact build poll chunk " + chunk + " of 3 failed (" + (chunkErr && chunkErr.message ? chunkErr.message : chunkErr) + ") \u2014 continuing to the next chunk; build completion still unproven.");
|
|
2125
1945
|
}
|
|
@@ -2135,20 +1955,7 @@ while (i < STEPS.length) {
|
|
|
2135
1955
|
buildPoll = { build_done: false, status: (buildPoll && buildPoll.status) || "build still running after the 10.5-minute bounded poll" };
|
|
2136
1956
|
}
|
|
2137
1957
|
if (buildPoll.build_done && pollSawOurBuild) {
|
|
2138
|
-
//
|
|
2139
|
-
// (2026-09-11) proved the stamp cannot certify content: the
|
|
2140
|
-
// builder's applied-report was derived from the carried diff, so
|
|
2141
|
-
// the old report check was circular — a fabricated report
|
|
2142
|
-
// passed by construction, and every phase went green on a hollow
|
|
2143
|
-
// build. The stamp moves to the parent (docs/publish-verification.md);
|
|
2144
|
-
// the deterministic lib/readback-disk.js is the primary sensor
|
|
2145
|
-
// (the agent-callable read-back tool is unavailable —
|
|
2146
|
-
// artifact_inspect was removed by the platform 2026-09-14 — so
|
|
2147
|
-
// the LLM-inspector path is manual-fallback only), and the task
|
|
2148
|
-
// parks for parent verification.
|
|
2149
|
-
// Chore has no QA: the parent's verification is the final gate.
|
|
2150
|
-
// An unverified publish fails loudly in QA instead of passing
|
|
2151
|
-
// silently here.
|
|
1958
|
+
// See docs/decisions/publish-path.md#step-1c-no-stamp: no provenance stamp in STEP 1c.
|
|
2152
1959
|
publishBuildLanded = true;
|
|
2153
1960
|
artifactPublish = { source_commit: mergeCommitForPublish, pending_parent_verification: true };
|
|
2154
1961
|
log("Publish build landed for task " + taskId + " — provenance stamp deferred to parent content verification");
|
|
@@ -2227,11 +2034,16 @@ while (i < STEPS.length) {
|
|
|
2227
2034
|
attempt: rebuildAttemptKey,
|
|
2228
2035
|
agent_id: rebuildAgentId,
|
|
2229
2036
|
applied_report: publishAppliedObservation,
|
|
2230
|
-
|
|
2037
|
+
manifest_before: preTriggerManifest,
|
|
2038
|
+
outcome: "build-observed",
|
|
2231
2039
|
detail: "durable audit evidence shows a build completed during the attempt window (audit dir " + newestAuditDirAfterPoll + ", report ok=true); routed to parent verification"
|
|
2232
2040
|
}, reworkCount);
|
|
2233
2041
|
} else if (auditOkAfterPoll === false) {
|
|
2234
|
-
|
|
2042
|
+
// Explicit negative evidence under the stranger guard: a build
|
|
2043
|
+
// ran and failed during the poll window with no stranger in
|
|
2044
|
+
// flight. This is an attributable failure — preserved verbatim
|
|
2045
|
+
// through post-deploy. Message contract unchanged.
|
|
2046
|
+
publishFailure = "Artifact build FAILED for slug " + PUBLISH_SLUG + " (audit dir " + newestAuditDirAfterPoll + ", report ok=false). Explicit negative evidence: a build ran and failed (attribution by window, not by build identity — no stranger build was observed in flight during the poll). The publish did not land — provenance was not stamped — your change was NOT published. Build log: ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/" + newestAuditDirAfterPoll + "/. This explicit failure is not auto-retried. Appendix: attribution=window; report=ok=false; provenance=unstamped.";
|
|
2235
2047
|
await recordPublishLedger({
|
|
2236
2048
|
commit: mergeCommitForPublish,
|
|
2237
2049
|
attempt: rebuildAttemptKey,
|
|
@@ -2245,7 +2057,19 @@ while (i < STEPS.length) {
|
|
|
2245
2057
|
: ((pollStatusErrors > 0 && !pollSawOurBuild) ? "status-read-errors-during-poll"
|
|
2246
2058
|
: (pollEndState === "build-still-running-at-poll-end" ? "build-still-running-at-poll-end"
|
|
2247
2059
|
: (newAuditDirsAfterPoll.length === 0 ? "no-new-audit-dir-in-window" : "audit-report-unreadable-or-missing")));
|
|
2248
|
-
|
|
2060
|
+
// Verdict UNKNOWN (poll path): the build cannot be attributed
|
|
2061
|
+
// to this attempt. The fields feed the single composed
|
|
2062
|
+
// fail-closed park reason after post-deploy — never a
|
|
2063
|
+
// fabricated verdict, never a silent pass.
|
|
2064
|
+
publishUnknownFields = {
|
|
2065
|
+
taskId: taskId,
|
|
2066
|
+
unattributableReason: unattributableReason,
|
|
2067
|
+
pollEndState: pollEndState,
|
|
2068
|
+
sawOurBuild: pollSawOurBuild,
|
|
2069
|
+
newAuditDirCount: newAuditDirsAfterPoll.length,
|
|
2070
|
+
chunkFailures: chunkFailures.length,
|
|
2071
|
+
pollStatusErrors: pollStatusErrors
|
|
2072
|
+
};
|
|
2249
2073
|
await recordPublishLedger({
|
|
2250
2074
|
commit: mergeCommitForPublish,
|
|
2251
2075
|
attempt: rebuildAttemptKey,
|
|
@@ -2256,11 +2080,8 @@ while (i < STEPS.length) {
|
|
|
2256
2080
|
}, reworkCount);
|
|
2257
2081
|
}
|
|
2258
2082
|
}
|
|
2259
|
-
} else {
|
|
2260
|
-
// Unreachable: the observation above either attributes the edit
|
|
2261
|
-
// (edit_started) or parks. Defensive only — never a silent pass.
|
|
2262
|
-
publishFailure = "Artifact rebuild trigger failed: the edit was not attributed to any observed build. The publish is unattributed (not proven landed, not proven failed) — provenance was not stamped. Fail-closed.";
|
|
2263
2083
|
}
|
|
2084
|
+
|
|
2264
2085
|
} // end: publishSkippedNoLock — no rebuild, no stamp, nothing to ship
|
|
2265
2086
|
// STEP 2 (mechanical, always — skip path included): post-deploy
|
|
2266
2087
|
// commits builder leftovers if any, removes the worktree, and releases
|
|
@@ -2284,6 +2105,19 @@ while (i < STEPS.length) {
|
|
|
2284
2105
|
? " Post-deploy finalized cleanup."
|
|
2285
2106
|
: " Post-deploy also failed (" + (postDeploy.output || "no output") + ") — worktree and lock state unknown."));
|
|
2286
2107
|
}
|
|
2108
|
+
if (!publishBuildLanded) {
|
|
2109
|
+
// Verdict UNKNOWN (single fail-closed park — post-deploy always
|
|
2110
|
+
// runs first; no early parks anywhere above). Machine contract:
|
|
2111
|
+
// "unattributable_reason=" and "poll_end_state=" are always
|
|
2112
|
+
// present; attribution is by window, not identity.
|
|
2113
|
+
// (2026-09-18, H2 message contract) Thread the commit short-sha
|
|
2114
|
+
// through the unknown fields so the human line names the trigger
|
|
2115
|
+
// commit (design §1.5: "the trigger was sent for commit <short-sha>").
|
|
2116
|
+
if (publishUnknownFields) publishUnknownFields.commitShortSha = mergeCommitShortForPublish;
|
|
2117
|
+
return await parkTask(composeUnattributedParkReason(publishUnknownFields) + (postDeploy.deployed
|
|
2118
|
+
? " Post-deploy finalized cleanup."
|
|
2119
|
+
: " Post-deploy also failed (" + (postDeploy.output || "no output") + ") — worktree and lock state unknown."));
|
|
2120
|
+
}
|
|
2287
2121
|
if (!postDeploy.deployed) {
|
|
2288
2122
|
return await parkTask("Post-deploy failed after the artifact build landed: " + (postDeploy.output || "no output") + ". The build may have landed but worktree cleanup and lock release are unknown — human attention needed.");
|
|
2289
2123
|
}
|
|
@@ -2508,18 +2342,7 @@ while (i < STEPS.length) {
|
|
|
2508
2342
|
}
|
|
2509
2343
|
log("Build worktree confinement passed: " + wt.path);
|
|
2510
2344
|
|
|
2511
|
-
//
|
|
2512
|
-
// <sha>)` declaration is verified mechanically — <sha> must resolve
|
|
2513
|
-
// and be an ancestor of main in the configured repo. A fabricated or
|
|
2514
|
-
// mistaken declaration fails the phase here (the dispatcher retries
|
|
2515
|
-
// Build under its consecutive-failure cap); a verified declaration is
|
|
2516
|
-
// recorded in alreadyMergedSha for Review's no-diff branch. Without
|
|
2517
|
-
// this guard, Build correctly doing nothing left Review with no
|
|
2518
|
-
// mechanical way to accept an empty diff, and Cass rejected for "no
|
|
2519
|
-
// commits ahead of main — the builder likely forgot to commit" while
|
|
2520
|
-
// the deliverable sat on main (canary 2026-09-15, task 1d692d91).
|
|
2521
|
-
// The sha is hex-only by construction (extractAlreadyMerged), so
|
|
2522
|
-
// interpolating it into the shell command cannot inject.
|
|
2345
|
+
// See docs/decisions/publish-path.md#already-merged-idem: an already-merged repo_diff is idempotent; no rebuild.
|
|
2523
2346
|
var am = extractAlreadyMerged(workerText);
|
|
2524
2347
|
if (am.sha) {
|
|
2525
2348
|
var amCheck = await agent(
|
|
@@ -2565,20 +2388,7 @@ while (i < STEPS.length) {
|
|
|
2565
2388
|
};
|
|
2566
2389
|
let passed = stepResult.passed === true;
|
|
2567
2390
|
|
|
2568
|
-
//
|
|
2569
|
-
// merge. After the Integrate agent claims success, the workflow confirms
|
|
2570
|
-
// mechanically that the task branch tip is an ancestor of main via the
|
|
2571
|
-
// lifecycle script's verify-merge command (which resolves the branch
|
|
2572
|
-
// through the crew registry — never by reconstructing "task/"+taskId — so
|
|
2573
|
-
// the check cannot verify the wrong branch). The VERIFIED marker is matched
|
|
2574
|
-
// by regex on the script's own stdout; agent prose is never read. This
|
|
2575
|
-
// closes the hole where an agent reported "merged empty" while approved
|
|
2576
|
-
// commits were still stranded on the task branch (bug b1b1f919). A genuine
|
|
2577
|
-
// empty-diff Integrate (MERGED_EMPTY: no commits ahead of main) verifies
|
|
2578
|
-
// vacuously — the tip is then an ancestor of main. Verification failure is
|
|
2579
|
-
// an operational step failure, not a park: the dispatcher retries Integrate
|
|
2580
|
-
// under its consecutive-failure cap, and the retry finds the commits still
|
|
2581
|
-
// on the branch and performs the real merge — self-healing.
|
|
2391
|
+
// See docs/decisions/publish-path.md#integrate-verify: the agent cannot verify integrate mechanically; the workflow checks the diff.
|
|
2582
2392
|
if (step.name === "Integrate" && passed) {
|
|
2583
2393
|
var integrateVerifyOut = "";
|
|
2584
2394
|
try {
|
|
@@ -2609,17 +2419,7 @@ while (i < STEPS.length) {
|
|
|
2609
2419
|
// retryable under the dispatcher's consecutive-failure cap.
|
|
2610
2420
|
const status = passed ? "completed" : (step.name === "Integrate" || step.name === "Publish" ? "failed" : "rejected");
|
|
2611
2421
|
|
|
2612
|
-
//
|
|
2613
|
-
// Skip-aware (park 2026-09-11): when the deterministic publish script found
|
|
2614
|
-
// no merge lock held (empty-diff Integrate), it skips the publish path
|
|
2615
|
-
// gracefully and emits the machine-readable PUBLISH_SKIPPED=no-lock-held
|
|
2616
|
-
// marker. The preflight (bugfix 2026-09-17) emits
|
|
2617
|
-
// PUBLISH_SKIPPED=no-npm-publish when npm publish is not configured on
|
|
2618
|
-
// this machine (helper or credential absent) — also before any mutation.
|
|
2619
|
-
// Verification is then vacuous — nothing was shipped, and the
|
|
2620
|
-
// registry must NOT have moved. The marker is script-emitted explicit state
|
|
2621
|
-
// (pasted verbatim per the Publish agent instructions), not agent prose; a
|
|
2622
|
-
// report without the marker still runs the full verification fail-closed.
|
|
2422
|
+
// See docs/decisions/publish-path.md#publish-verify: the agent cannot verify publish; the parent does.
|
|
2623
2423
|
var publishVerified = false;
|
|
2624
2424
|
var npmPublishSkipped = false;
|
|
2625
2425
|
if (step.name === "Publish" && PUBLISH_TYPE === "npm" && publishTarget) {
|
|
@@ -2645,15 +2445,7 @@ while (i < STEPS.length) {
|
|
|
2645
2445
|
publishTarget.target + " (" + publishTarget.base + " + " + publishTarget.scope + "). The publish did not land.");
|
|
2646
2446
|
}
|
|
2647
2447
|
publishVerified = true;
|
|
2648
|
-
//
|
|
2649
|
-
// installs and activates a new immutable release (crew-release.sh deploy
|
|
2650
|
-
// swaps the `current` symlink inside publish-npm.sh) but never stamped
|
|
2651
|
-
// the dashboard's provenance record — every crew release left
|
|
2652
|
-
// crew_release pointing at a pruned release. After a verified landed
|
|
2653
|
-
// publish, refresh the record's crew_release to the now-live release
|
|
2654
|
-
// identity, preserving the existing source_commit (the dashboard
|
|
2655
|
-
// artifact's build source — a crew-repo commit here would fail the
|
|
2656
|
-
// dashboard QA source check).
|
|
2448
|
+
// See docs/decisions/publish-path.md#provenance-refresh: refresh crew_release after landed publish, preserving source_commit.
|
|
2657
2449
|
try {
|
|
2658
2450
|
var provRefresh = await agent(
|
|
2659
2451
|
"Run in shell and return the stdout verbatim:\n" + crewCmd("get-provenance", { project_id: LAUNCH_PROJECT_ID }) + "\n" +
|
|
@@ -2683,31 +2475,10 @@ while (i < STEPS.length) {
|
|
|
2683
2475
|
} // end: !npmPublishSkipped — a skipped publish has nothing to verify
|
|
2684
2476
|
}
|
|
2685
2477
|
|
|
2686
|
-
//
|
|
2687
|
-
//
|
|
2688
|
-
//
|
|
2689
|
-
//
|
|
2690
|
-
// artifact was stale, all eight phases green. The stamp now moves to the
|
|
2691
|
-
// parent (docs/publish-verification.md); the independent read-back step
|
|
2692
|
-
// is currently unavailable (no agent-callable read-back tool exists —
|
|
2693
|
-
// artifact_inspect was removed by the platform 2026-09-14), so the parent
|
|
2694
|
-
// cannot confirm content and the task parks for verification.
|
|
2695
|
-
// Skip-aware (park 2026-09-11): an empty-diff Integrate takes no merge
|
|
2696
|
-
// lock, and the deterministic publish path skips rebuild/stamp entirely —
|
|
2697
|
-
// there is no new content to verify, so verification is vacuous.
|
|
2698
|
-
// publishSkippedNoLock is workflow-computed state from the explicit
|
|
2699
|
-
// lock-status read in STEP 0, not agent prose.
|
|
2700
|
-
// The parent (tick worker) triggers the ONE read-back inspection it can
|
|
2701
|
-
// actually receive (async results go to the root agent, never into a
|
|
2702
|
-
// workflow run — a workflow-side trigger would be an orphan). The workflow
|
|
2703
|
-
// only parks; the parent's scan builds the request deterministically via
|
|
2704
|
-
// lib/build-readback-request.js and ferries the inspection.
|
|
2705
|
-
// publishBuildLanded and publishSkippedNoLock are workflow-computed state;
|
|
2706
|
-
// a skipped or failed publish has nothing to verify.
|
|
2707
|
-
// Session notes. Machine-readable marker lines are extracted from the full
|
|
2708
|
-
// worker report and appended AFTER the slice so a long report can never
|
|
2709
|
-
// amputate them; later phases (Review reading repo_diff:, QA backstop
|
|
2710
|
-
// reading TARGET_VERSION=) depend on them.
|
|
2478
|
+
// Parent-owned verification (docs/publish-verification.md): the parent's
|
|
2479
|
+
// scan builds the request via lib/build-readback-request.js and ferries
|
|
2480
|
+
// the inspection; a skipped or failed publish has nothing to verify.
|
|
2481
|
+
// See docs/decisions/publish-path.md#parent-owned-verification for history.
|
|
2711
2482
|
let summary;
|
|
2712
2483
|
var workerMarkers = extractMarkerLines(workerText);
|
|
2713
2484
|
if (step.name === "Publish" && PUBLISH_TYPE === "npm" && publishTarget && (publishVerified || npmPublishSkipped)) {
|
|
@@ -2721,12 +2492,7 @@ while (i < STEPS.length) {
|
|
|
2721
2492
|
} else {
|
|
2722
2493
|
summary = (stepResult.summary || "Step completed").slice(0, 2000 - workerMarkers.length - 1) + (workerMarkers ? "\n" + workerMarkers : "");
|
|
2723
2494
|
}
|
|
2724
|
-
//
|
|
2725
|
-
// already-merged declaration, the workflow records its own marker line in
|
|
2726
|
-
// the session notes (like the builder markers above, it is appended after
|
|
2727
|
-
// the slice so it can never be amputated). A later run resumed at Review
|
|
2728
|
-
// hydrates alreadyMergedSha from this workflow-attested line — never from
|
|
2729
|
-
// the builder's declaration alone.
|
|
2495
|
+
// See docs/decisions/publish-path.md#already-merged: when the Build gate verifies already-merged, attestation is recorded.
|
|
2730
2496
|
if (step.name === "Build" && alreadyMergedSha) {
|
|
2731
2497
|
summary += "\nalready_merged_verified: " + alreadyMergedSha;
|
|
2732
2498
|
}
|
|
@@ -2798,18 +2564,18 @@ while (i < STEPS.length) {
|
|
|
2798
2564
|
return { status: "failed", task_id: taskId, reason: "Publish failed: " + summary };
|
|
2799
2565
|
}
|
|
2800
2566
|
|
|
2801
|
-
//
|
|
2802
|
-
// but provenance is UNSTAMPED until the parent's independent read-back
|
|
2803
|
-
// (docs/publish-verification.md) confirms the artifact's actual content
|
|
2804
|
-
// matches the merged diff. The parent stamps provenance, then re-queues;
|
|
2805
|
-
// the dispatcher resumes at QA, whose provenance check enforces the stamp
|
|
2806
|
-
// mechanically. A failed Publish never reaches this park — it returned
|
|
2807
|
-
// failed above and retries under the dispatcher's cap. The merge lock is
|
|
2808
|
-
// already released (post-deploy), so the parked task holds no resources.
|
|
2567
|
+
// See docs/decisions/publish-path.md#verification-park: the build landed but provenance is unstamped until parent verification.
|
|
2809
2568
|
if (passed && step.name === "Publish" && PUBLISH_TYPE === "artifact" && PUBLISH_SLUG && !publishSkippedNoLock && publishBuildLanded) {
|
|
2569
|
+
// Success contract (2026-09-18, H2): the parent asked for exactly
|
|
2570
|
+
// one build for this publish. The build landed — do NOT republish: a
|
|
2571
|
+
// duplicate build would re-publish the same change. content_check=pending
|
|
2572
|
+
// means the parent's independent read-back has not happened yet; this
|
|
2573
|
+
// park is NOT proof the content is correct.
|
|
2810
2574
|
return await parkTask("publish: verification-requested " + mergeCommitForPublish +
|
|
2811
|
-
"
|
|
2812
|
-
"
|
|
2575
|
+
" attempt=" + rebuildAttemptKey +
|
|
2576
|
+
" Do NOT republish: a duplicate build would re-publish the same change. " +
|
|
2577
|
+
"Artifact build landed, post-deploy finalized, provenance not stamped — the crew has not yet independently confirmed the live artifact contains exactly the change; waiting on the manual read-back in docs/publish-verification.md. " +
|
|
2578
|
+
"Appendix: build=" + (rebuildAgentId || "agent_id unobserved") + "; provenance=unstamped; content_check=pending.");
|
|
2813
2579
|
}
|
|
2814
2580
|
|
|
2815
2581
|
i++;
|