muse-crew 0.7.18 → 0.7.20

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.
@@ -442,48 +442,6 @@ function parseUnifiedDiff(diffText) {
442
442
  return files;
443
443
  }
444
444
 
445
- // Compare the artifact builder's reported applied-changes against the diff's
446
- // expected changes. Every added/removed line must match exactly per path,
447
- // and the file counts must match — the builder applies exactly the carried
448
- // change, nothing more, nothing less. Pure function — no I/O, no clock.
449
- // OBSERVATION INPUT ONLY (2026-09-12, task 23ca8f3f): the applied report
450
- // has a demonstrated false-negative mode (applied:[] for a diff the builder
451
- // had actually applied), and it is derived from the carried diff, so a match
452
- // certifies nothing either. A mismatch is logged as observation; it never
453
- // parks and never blocks the stamp. The verification is the independent
454
- // read-back (docs/publish-verification.md).
455
- function verifyAppliedChanges(expected, applied) {
456
- if (!Array.isArray(applied)) {
457
- return { ok: false, reason: "builder returned no applied-changes list" };
458
- }
459
- function sorted(a) { return (a || []).slice().sort(); }
460
- function eq(a, b) {
461
- a = sorted(a); b = sorted(b);
462
- if (a.length !== b.length) return false;
463
- for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
464
- return true;
465
- }
466
- for (var i = 0; i < expected.length; i++) {
467
- var exp = expected[i];
468
- var got = null;
469
- for (var j = 0; j < applied.length; j++) {
470
- if (applied[j] && applied[j].path === exp.path) { got = applied[j]; break; }
471
- }
472
- if (!got) {
473
- return { ok: false, reason: "builder did not report changing '" + exp.path + "'" };
474
- }
475
- if (!eq(exp.added, got.added)) {
476
- return { ok: false, reason: "added lines for '" + exp.path + "' do not match the carried diff" };
477
- }
478
- if (!eq(exp.removed, got.removed)) {
479
- return { ok: false, reason: "removed lines for '" + exp.path + "' do not match the carried diff" };
480
- }
481
- }
482
- if (applied.length !== expected.length) {
483
- return { ok: false, reason: "builder reported changing " + applied.length + " file(s), diff carries " + expected.length };
484
- }
485
- return { ok: true };
486
- }
487
445
 
488
446
  // Publish read-back request (currently unavailable): the verbatim_request
489
447
  // the parent protocol (docs/publish-verification.md) would hand to an
@@ -497,35 +455,12 @@ function verifyAppliedChanges(expected, applied) {
497
455
  // finding. Until a read-back path exists, the parent cannot independently
498
456
  // confirm content and verification parks at "publish: verification-requested"
499
457
  // (see docs/publish-verification.md). This preserves the circularity break
500
- // that hollowed canary run 8 (2026-09-11): verifyAppliedChanges compares the
501
- // builder's applied-report against the diff the report was derived from — a
502
- // fabricated report passes by construction. Independent read-back cannot be
458
+ // that hollowed canary run 8 (2026-09-11): the old verifyAppliedChanges
459
+ // compared the builder's applied-report against the diff the report was
460
+ // derived from — a fabricated report passed by construction. The report
461
+ // itself is gone now (2026-09-16 fire-and-forget trigger). Independent
462
+ // read-back cannot be
503
463
  // fabricated from the diff; it must match the artifact's real content.
504
- // Pre-publish base observation (diagnostic, 2026-09-12): instruction fragment
505
- // for the builder's edit request, asking it to report the sha256 of each
506
- // touched file's CURRENT content BEFORE applying the diff. Pure function —
507
- // no I/O, no clock.
508
- //
509
- // Why: the builder applies the carried diff to its own source tree, whose
510
- // base state is unrecorded. The post-hoc read-back only checks the changed
511
- // regions AFTER the edit; it cannot tell us what base the diff landed on.
512
- // If the tree was dirty or drifted before the edit, the read-back still
513
- // passes (the diff's lines are present) while the artifact silently carries
514
- // uncommitted content — the production validateRepoPath incident
515
- // (2026-09-12), where the live artifact contained code absent from every git
516
- // ref. These pre-hashes, compared against the workflow-computed expected
517
- // base hashes (merge parent), reveal what the publish actually read.
518
- // Observation only — the workflow logs mismatches but never parks on them.
519
- function buildPreHashInstruction(files) {
520
- var paths = files.map(function(f) { return f.path; }).join(", ");
521
- return (
522
- "- BEFORE applying anything, compute the sha256 hash of each file below as it CURRENTLY exists in your source tree (before your changes). Use the exact bytes of the current file content.\n" +
523
- "- Report these hashes in the \"pre_hashes\" field of your return JSON, as { \"<path>\": \"<sha256 hex>\" }.\n" +
524
- "- If a file does not exist in your tree, report its hash as the string \"MISSING\".\n" +
525
- "- Do this BEFORE applying the diff — the hashes must reflect the pre-edit state.\n" +
526
- " Files: " + paths + "\n"
527
- );
528
- }
529
464
 
530
465
  // Durable publish-attempt ledger (2026-09-12): every artifact publish
531
466
  // attempt is recorded append-only at $CREW_HOME/.publish-ledger/<slug>.jsonl
@@ -1399,9 +1334,10 @@ while (i < STEPS.length) {
1399
1334
  // 2026-09-11), so the stamp moved to the parent — after the build
1400
1335
  // lands, the workflow records the session completed and parks with
1401
1336
  // "publish: verification-requested". The parent owns verification
1402
- // (docs/publish-verification.md); the independent read-back step is
1403
- // currently unavailable (no agent-callable read-back tool exists —
1404
- // artifact_inspect was removed by the platform 2026-09-14).
1337
+ // (docs/publish-verification.md); the primary sensor is the
1338
+ // deterministic lib/readback-disk.js (the agent-callable read-back
1339
+ // tool is unavailable — artifact_inspect was removed by the platform
1340
+ // 2026-09-14 — so the LLM-inspector path is manual-fallback only).
1405
1341
  // QA's provenance check enforces the stamp mechanically.
1406
1342
  var artifactPublish = null;
1407
1343
  var publishLockRefreshed = false;
@@ -1511,38 +1447,8 @@ while (i < STEPS.length) {
1511
1447
  if (expectedChanges.length === 0) {
1512
1448
  return await parkTask("Publish diff parsed to zero files for commit " + (mergeCommitForPublish || "unknown") + " — cannot verify application. Human attention needed.");
1513
1449
  }
1514
- // Pre-publish base observation (diagnostic, 2026-09-12): the builder
1515
- // applies the diff to its own source tree, whose base state is
1516
- // unrecorded. Compute the trustworthy expected base — the sha256 of
1517
- // each touched file at the merge parent commit — so the builder's
1518
- // self-reported pre-edit hashes (see buildPreHashInstruction) can be
1519
- // compared against it. Observation only: a mismatch is logged loudly
1520
- // but never parks. The observation tells us what the publish actually
1521
- // reads, so the subsequent fix can require the right base.
1522
- var expectedBaseHashes = {};
1523
- if (publishBase === EMPTY_TREE_SHA) {
1524
- // First publish: every file in the diff is new to the artifact.
1525
- expectedChanges.forEach(function (f) { expectedBaseHashes[f.path] = "NEW-FILE"; });
1526
- log("Publish expected base hashes for task " + taskId + ": empty tree (first publish) — all " + expectedChanges.length + " file(s) new");
1527
- } else try {
1528
- // Shell-quote helper (no regex-with-quote: the test parser does not
1529
- // understand regex literals containing quotes).
1530
- var sq = function(s) { return "'" + String(s).split("'").join("'\\''") + "'"; };
1531
- var baseHashResult = await agent(
1532
- "Run: cd " + REPO_PATH + " && parent=" + sq(publishBase) + " && for f in " + expectedChanges.map(function(f) { return sq(f.path); }).join(" ") + "; do printf '%s:' \"$f\"; git show \"$parent:$f\" 2>/dev/null | sha256sum | cut -d' ' -f1; done\n" +
1533
- "Return JSON { \"hashes\": \"<newline-separated <path>:<sha256> lines, empty hash means the file is new in this diff>\" } and nothing else.",
1534
- { key: attemptKey("publish-base-hashes-" + taskId, totalReworkCount), label: "Computing expected base content hashes",
1535
- schema: { type: "object", properties: { hashes: { type: "string" } }, required: ["hashes"] } }
1536
- );
1537
- (baseHashResult.hashes || "").split("\n").forEach(function(line) {
1538
- var m = /^([^:]+):([0-9a-f]*)$/.exec(line.trim());
1539
- if (m) expectedBaseHashes[m[1]] = m[2] || "NEW-FILE";
1540
- });
1541
- log("Publish expected base hashes for task " + taskId + " (stamped base " + publishBase.slice(0, 12) + "): " + JSON.stringify(expectedBaseHashes));
1542
- } catch (e) {
1543
- log("Publish expected base hash computation failed for task " + taskId + " (non-fatal, observation degraded): " + (e && e.message ? e.message : e));
1544
- }
1545
1450
  var rebuildPrompt =
1451
+ ARTIFACT_LOAD_PREAMBLE +
1546
1452
  "Call artifact_edit with slug \"" + PUBLISH_SLUG + "\" and verbatim_request:\n" +
1547
1453
  "'Apply the following change to your source tree, then rebuild and deploy.\n" +
1548
1454
  "\n" +
@@ -1555,79 +1461,50 @@ while (i < STEPS.length) {
1555
1461
  "- For a deleted file (+++ /dev/null), delete it.\n" +
1556
1462
  "- If any hunk does not apply cleanly, STOP and report the failure — do not improvise or skip hunks.\n" +
1557
1463
  "- Do not make any other source changes.\n" +
1558
- "- After applying, rebuild and deploy.\n" +
1559
- "- Report, for each file you changed: its path, the exact lines you added, and the exact lines you removed.\n" +
1560
- buildPreHashInstruction(expectedChanges) + "'\n" +
1561
- ARTIFACT_LOAD_PREAMBLE +
1562
- "If artifact_edit is still not available after the load, do NOT improvise — return { \"edit_started\": false, \"build_agent_id\": null, \"error\": \"artifact_tools missing after load\", \"applied\": [] }.\n" +
1563
- "RECEIPT CAPTURE (receipt-chained publish, 2026-09-13): the edit is only half the contract you must also capture the platform build's receipt, the in-flight correlation ID the follow-up poll chains to.\n" +
1564
- "- The artifact namespace is already loaded (see below). BEFORE calling artifact_edit, call artifact_status with slug \"" + PUBLISH_SLUG + "\" and note the running build's agent_id (or null when no build is running). This is the pre-edit baseline.\n" +
1565
- "- Call artifact_edit as instructed above.\n" +
1566
- "- IMMEDIATELY after artifact_edit returns, call artifact_status again. If a build is running whose agent_id DIFFERS from the pre-edit baseline (or the baseline was null), that build is this edit's — its agent_id is the receipt.\n" +
1567
- "- If the post-edit status shows the SAME agent_id as the baseline, or no build at all, wait about 15 seconds and check artifact_status again, up to 4 more times. If a build with a NEW agent_id appears, that is the receipt.\n" +
1568
- "- If no new build appears, the receipt is null: the build may be pending_init-invisible, may have finished before the capture, or may be queued behind the earlier build. Return null — do NOT guess, and do NOT substitute the baseline build's agent_id.\n" +
1569
- "Make no other calls. Return JSON { \"edit_started\": <true if the edit was accepted, false otherwise>, \"build_agent_id\": <the receipt agent_id string, or null when no build could be attributed to this edit>, \"error\": \"<details or empty string>\", \"applied\": [{\"path\": \"<file path>\", \"added\": [\"<added lines>\"], \"removed\": [\"<removed lines>\"]}], \"pre_hashes\": {\"<file path>\": \"<sha256 of that file's content BEFORE you applied the diff, or \"MISSING\">\"} } and nothing else.";
1570
- var rebuildSchema =
1571
- { type: "object",
1572
- properties: {
1573
- edit_started: { type: "boolean" },
1574
- build_agent_id: {
1575
- type: ["string", "null"],
1576
- description: "Receipt-chained publish (2026-09-13): the platform build's in-flight correlation ID (build.agent_id from artifact_status) captured immediately after the edit was accepted — the receipt the follow-up poll chains to. Null when no build could be attributed to this edit. Required: an accepted edit with a null receipt parks fail-closed as unknown."
1577
- },
1578
- error: { type: "string" },
1579
- applied: {
1580
- type: "array",
1581
- items: {
1582
- type: "object",
1583
- properties: {
1584
- path: { type: "string" },
1585
- added: { type: "array", items: { type: "string" } },
1586
- removed: { type: "array", items: { type: "string" } }
1587
- },
1588
- required: ["path", "added", "removed"]
1589
- }
1590
- },
1591
- pre_hashes: {
1592
- type: "object",
1593
- description: "Diagnostic (2026-09-12): sha256 of each touched file's content BEFORE the builder applied the diff, as reported by the builder. Compared against the workflow-computed expected base hashes (merge parent) — observation only, never gating."
1594
- }
1595
- },
1596
- required: ["edit_started", "build_agent_id", "applied"] };
1597
- var rebuildTrigger = null;
1598
- var rebuildReportMissing = false; // true if the edit went through but the agent returned no applied report (structured-output failure) — the smoke-check is skipped; the parent's independent read-back is the verification
1599
- var rebuildEvidenceNote = null; // human-readable evidence line for the ledger when the edit is confirmed via fallback evidence (in-flight poll or durable audit dir) rather than the trigger's own report
1464
+ "- After applying, rebuild and deploy.'\n" +
1465
+ "Edit-request contract (read carefully):\n" +
1466
+ "- Call artifact_edit exactly once with the slug and verbatim_request above. Never retry the edit yourself: if the edit is not accepted, do NOT call artifact_edit again — end your turn.\n" +
1467
+ "- If artifact_edit is not available after the load, do NOT improvise — end your turn.\n" +
1468
+ "- You do NOT call setprovenance, artifact_inspect, or post-deploy yourself.\n" +
1469
+ "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";
1600
1470
  // The trigger key of the attempt that last ran, for the publish ledger.
1601
1471
  // Minted once here (not re-minted per use site) so the ledger always
1602
1472
  // records the exact key that was issued — and so a re-minted duplicate
1603
1473
  // can never drift from it.
1604
1474
  var rebuildAttemptKey = attemptKey("publish-artifact-rebuild-" + taskId, totalReworkCount);
1605
- // The artifact build's agent_id, captured from artifact_status when the
1606
- // trigger's outcome is ambiguous (structured-output failure). The
1607
- // agent_id is the artifact system's in-flight correlation ID (not durable post-completion)
1608
- // (research 2026-09-12): artifact.edit returns pending_init with NO
1609
- // agent_id, but artifact_status exposes build.agent_id immediately
1610
- // after acceptance, stable across polls. Recorded in the ledger so an
1611
- // ambiguous attempt correlates to the exact builder run; null when no
1612
- // build was ever observed.
1475
+ // The artifact build's agent_id, attributed to this edit by the
1476
+ // workflow-owned observation below. The agent_id is the artifact
1477
+ // system's in-flight correlation ID (research 2026-09-12):
1478
+ // artifact.edit returns pending_init with NO agent_id, but
1479
+ // artifact_status exposes build.agent_id immediately after
1480
+ // acceptance, stable across polls. Recorded in the ledger so an
1481
+ // attempt correlates to the exact builder run; null when no build
1482
+ // was ever observed.
1613
1483
  var rebuildAgentId = null;
1614
- // The builder's applied-report is an observation, not a gate
1615
- // (2026-09-12, task 23ca8f3f): computed once the trigger outcome is
1616
- // known, logged loudly, never a park.
1617
- var publishAppliedObservation = null; // "match" | "mismatch: <reason>" | "missing-report" observation only, never a park
1618
- // Durable-evidence snapshot (2026-09-14): the structured-output
1619
- // fallback below only observes IN-FLIGHT builds. A build that
1620
- // finished before the poll leaves no in-flight trace but the
1621
- // platform's audit harness leaves a durable one:
1484
+ // The builder's applied report is gone (2026-09-16): it rode on the
1485
+ // trigger's JSON closeout contract, which is removed below. The
1486
+ // parent's independent read-back (docs/publish-verification.md) is
1487
+ // the verification this field stays "missing-report" on ledger
1488
+ // lines for issued triggers; pre-trigger parks (toolcheck
1489
+ // rejected/inconclusive) and unattributed-unknown parks write null
1490
+ // (no trigger was observed, so there is nothing to report).
1491
+ var publishAppliedObservation = "missing-report";
1492
+ // Durable-evidence snapshot (2026-09-14): the observation below only
1493
+ // detects IN-FLIGHT builds. A build that finished before the
1494
+ // observation leaves no in-flight trace — but the platform's audit
1495
+ // harness leaves a durable one:
1622
1496
  // ~/workspace/ts-spaces/<slug>/audits/<timestamp>-<id>/ per
1623
1497
  // completed build. Snapshot the listing BEFORE the trigger so the
1624
1498
  // fallback can diff before/after: a directory appearing during the
1625
1499
  // trigger window is positive evidence the edit went through and
1626
1500
  // the build completed. Best-effort and non-gating: if the snapshot
1627
- // fails, the durable check is skipped and the fallback behaves as
1628
- // before. No wall-clock in-script (deterministic replay) — the
1501
+ // fails, auditBeforeOk stays false and BOTH fallback comparisons
1502
+ // are disabled (2026-09-16, critic finding 4) — without a baseline,
1503
+ // an empty before-list would make every historical audit dir look
1504
+ // "new". No wall-clock in-script (deterministic replay) — the
1629
1505
  // comparison is a pure before/after set diff.
1630
1506
  var auditDirsBeforeTrigger = [];
1507
+ var auditBeforeOk = false;
1631
1508
  try {
1632
1509
  var auditBefore = await agent(
1633
1510
  "List the artifact audit directories for slug \"" + PUBLISH_SLUG + "\" (best-effort snapshot, never a gate).\n" +
@@ -1637,242 +1514,342 @@ while (i < STEPS.length) {
1637
1514
  schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
1638
1515
  );
1639
1516
  auditDirsBeforeTrigger = String((auditBefore && auditBefore.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
1517
+ auditBeforeOk = true;
1640
1518
  log("Publish audit-dir snapshot before trigger for task " + taskId + ": " + auditDirsBeforeTrigger.length + " entries");
1641
1519
  } catch (auditBeforeErr) {
1642
- log("Publish audit-dir snapshot before trigger failed for task " + taskId + " (non-fatal, durable-evidence check degraded): " + (auditBeforeErr && auditBeforeErr.message ? auditBeforeErr.message : auditBeforeErr));
1520
+ log("Publish audit-dir snapshot before trigger 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));
1643
1521
  }
1522
+ // Fire-and-forget trigger + workflow-owned observation (2026-09-16,
1523
+ // clean-room task e2a8d9f8): the trigger's JSON closeout contract
1524
+ // traveled over the stochastic text channel, and the runtime's
1525
+ // JSON-candidate heuristic misfired on it ("workflow agent output
1526
+ // was not JSON: no JSON object or array found in final response"),
1527
+ // parking a task whose edit may have gone through. The contract's
1528
+ // content was already observation-only (the applied report never
1529
+ // gated; the pre_hashes were diagnostic-only), so the contract is
1530
+ // removed: the trigger carries NO schema and its return value is
1531
+ // never consumed, which takes the extraction heuristic out of this
1532
+ // call entirely. The workflow attributes the edit itself through
1533
+ // the tiny schema'd reads below — no prose is parsed for the
1534
+ // trigger outcome.
1535
+ // (Probe, 2026-09-16: the workflow scope exposes only agent() —
1536
+ // tool_search, artifact_edit and artifact_status are undefined
1537
+ // there — so the workflow cannot call the artifact tools directly;
1538
+ // observation still goes through minimal child calls with tiny
1539
+ // schemas, never a broad JSON contract.)
1540
+ //
1541
+ // Pre-trigger toolcheck (tiny, schema'd): the artifact namespace is
1542
+ // deferred for workflow children — the child self-loads it and emits
1543
+ // one exact signal line, read mechanically (never English prose).
1544
+ // Only a parsed ARTIFACT_TOOLS: missing signal is explicit negative
1545
+ // evidence: it gets one bounded retry with a fresh key, then parks
1546
+ // rejected — without the tools the edit provably did NOT go through,
1547
+ // so this is the one safe retry on the publish path. A throw (or an
1548
+ // unparseable signal) is INCONCLUSIVE transport noise, never
1549
+ // evidence of missing tools (2026-09-16, critic finding 3): it is
1550
+ // recorded, it retries once in case the flake clears, but it can
1551
+ // never take the rejected path.
1552
+ var publishToolsOk = false;
1553
+ var publishToolsMissing = false;
1554
+ for (var toolcheckAttempt = 1; toolcheckAttempt <= 2 && !publishToolsOk; toolcheckAttempt++) {
1555
+ try {
1556
+ var toolcheckResult = await agent(
1557
+ "Check whether the artifact tool namespace is available.\n" +
1558
+ "Call tool_search.load_tool_namespace with paths [\"artifact\"].\n" +
1559
+ "Then emit exactly one line and nothing else: ARTIFACT_TOOLS: <ok if the load succeeded and artifact_edit and artifact_status are now functions, missing otherwise>.\n" +
1560
+ "Return JSON { \"signal\": \"<the exact ARTIFACT_TOOLS line>\" } and nothing else.",
1561
+ { key: attemptKey("publish-artifact-toolcheck-" + taskId + (toolcheckAttempt === 1 ? "" : "-retry2"), totalReworkCount),
1562
+ label: "Checking artifact tool availability" + (toolcheckAttempt === 1 ? "" : " (retry)"),
1563
+ schema: { type: "object", properties: { signal: { type: "string" } }, required: ["signal"] } }
1564
+ );
1565
+ var toolSignal = String((toolcheckResult && toolcheckResult.signal) || "");
1566
+ if (/ARTIFACT_TOOLS:\s*ok/.test(toolSignal)) {
1567
+ publishToolsOk = true;
1568
+ } else if (/ARTIFACT_TOOLS:\s*missing/.test(toolSignal)) {
1569
+ publishToolsMissing = true;
1570
+ }
1571
+ log("Publish artifact toolcheck for task " + taskId + " (attempt " + toolcheckAttempt + " of 2): " +
1572
+ (publishToolsOk ? "tools ok" : publishToolsMissing ? "tools missing (explicit parsed signal)" : "inconclusive (no ARTIFACT_TOOLS signal parsed)"));
1573
+ } catch (toolcheckErr) {
1574
+ log("Publish artifact toolcheck for task " + taskId + " (attempt " + toolcheckAttempt + " of 2) threw (" + (toolcheckErr && toolcheckErr.message ? toolcheckErr.message : toolcheckErr) + ") — inconclusive: a throw proves nothing about tool availability, never counted as missing");
1575
+ }
1576
+ }
1577
+ if (!publishToolsOk && !publishToolsMissing) {
1578
+ await recordPublishLedger({
1579
+ commit: mergeCommitForPublish,
1580
+ attempt: rebuildAttemptKey,
1581
+ agent_id: null,
1582
+ applied_report: null,
1583
+ outcome: "unknown",
1584
+ detail: "artifact toolcheck inconclusive after two attempts (throws or unparseable signals — never an explicit ARTIFACT_TOOLS: missing): tool availability unproven, so the trigger was NOT issued; unknown parks fail closed with no blind retry"
1585
+ }, totalReworkCount);
1586
+ return await parkTask("Publish cannot proceed for task " + taskId + ": the artifact toolcheck was inconclusive after two attempts (no explicit ARTIFACT_TOOLS signal parsed — a throw is transport noise, not evidence). Tool availability is unproven, so no edit was issued and nothing was retried blindly. Human attention needed.");
1587
+ }
1588
+ if (!publishToolsOk) {
1589
+ await recordPublishLedger({
1590
+ commit: mergeCommitForPublish,
1591
+ attempt: rebuildAttemptKey,
1592
+ agent_id: null,
1593
+ applied_report: null,
1594
+ outcome: "rejected",
1595
+ detail: "artifact tool namespace explicitly missing (parsed ARTIFACT_TOOLS: missing signal, one bounded retry spent): the edit provably did not go through — no trigger issued, no blind retry"
1596
+ }, totalReworkCount);
1597
+ 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.");
1598
+ }
1599
+ // Pre-trigger build-state baseline (tiny, schema'd): one read of
1600
+ // artifact_status. The post-trigger observation diffs against this
1601
+ // baseline — a build whose agent_id was absent from (or differs
1602
+ // from) the baseline is attributed to our edit; a build already in
1603
+ // flight at baseline predates the trigger and is never attributed
1604
+ // to it. If the baseline read itself fails, receipt attribution is
1605
+ // skipped and the durable audit-dir evidence below is the only
1606
+ // positive signal.
1607
+ var baselineAgentId = null;
1608
+ var baselineFailed = false;
1609
+ try {
1610
+ var publishBaseline = await agent(
1611
+ ARTIFACT_LOAD_PREAMBLE +
1612
+ "Call artifact_status with slug \"" + PUBLISH_SLUG + "\" once.\n" +
1613
+ "Return JSON { \"build\": <the raw \"build\" value exactly as returned, or null when there is none> } and nothing else.",
1614
+ { key: attemptKey("publish-artifact-baseline-" + taskId, totalReworkCount), label: "Reading pre-trigger build state",
1615
+ schema: { type: "object", properties: { build: { type: ["object", "null"] } }, required: ["build"] } }
1616
+ );
1617
+ baselineAgentId = (publishBaseline && publishBaseline.build && typeof publishBaseline.build.agent_id === "string" && publishBaseline.build.agent_id) || null;
1618
+ log("Publish pre-trigger baseline for task " + taskId + ": " + (baselineAgentId ? "build " + baselineAgentId + " already in flight (predates the trigger — never attributed to this edit)" : "no build in flight"));
1619
+ } catch (baselineErr) {
1620
+ baselineFailed = true;
1621
+ 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");
1622
+ }
1623
+ // The trigger itself: the artifact_edit call is AWAITED (the workflow
1624
+ // waits for it to complete) but its return value is intentionally
1625
+ // UNCONSUMED — NO schema, so no schema validation can fail this
1626
+ // call: a schema-less call resolves to the child's raw response as
1627
+ // a plain string (probed live 2026-09-16 — never parsed, never
1628
+ // throws on content). One caveat, also probed: the runtime still
1629
+ // scans the response for a JSON candidate, and an unparseable
1630
+ // {...}-looking substring in the child's prose throws ("response
1631
+ // JSON candidate", probe P6). The prompt tells the child to end its
1632
+ // turn with no prose at all, which keeps the common case clean —
1633
+ // but the channel is stochastic, so any throw is possible and
1634
+ // inconclusive: the edit may still have gone through, so the
1635
+ // outcome stays unknown until the observation below confirms it —
1636
+ // never inferred from the throw, and never blind-retried (a blind
1637
+ // re-trigger duplicated the edit on 2026-09-12).
1638
+ var rebuildTrigger = null;
1639
+ try {
1640
+ var triggerResultLength = String(await agent(rebuildPrompt,
1641
+ { key: rebuildAttemptKey, label: "Triggering artifact rebuild" }) || "").length;
1642
+ log("Publish rebuild trigger for task " + taskId + " returned (" + triggerResultLength + " chars; awaited but return intentionally unconsumed)");
1643
+ } catch (triggerErr) {
1644
+ log("Publish rebuild trigger for task " + taskId + " threw (" + (triggerErr && triggerErr.message ? triggerErr.message : triggerErr) + ") — outcome unknown until observation confirms it; the edit may have gone through");
1645
+ }
1646
+ // Post-trigger observation (primary, not fallback): the workflow
1647
+ // attributes the edit itself. First the in-flight build state — a
1648
+ // build whose agent_id is new relative to the pre-trigger baseline
1649
+ // is this edit's receipt. Then the durable audit-dir diff — a
1650
+ // timestamped directory appearing during the trigger window proves
1651
+ // the edit went through and the build completed even when no
1652
+ // in-flight build was ever observed (the 2026-09-14 attempt-7 gap).
1653
+ // Absence of both signals proves nothing: the outcome is UNKNOWN,
1654
+ // never "did not go through". No blind retry — record the attempt
1655
+ // and park fail-closed; correlate via the ledger, never by
1656
+ // re-issuing.
1657
+ log("Publish rebuild trigger issued for task " + taskId + " — observing build state to attribute the edit");
1658
+ var buildState = null;
1659
+ var buildStateFailed = false;
1644
1660
  try {
1645
- rebuildTrigger = await agent(rebuildPrompt,
1646
- { key: rebuildAttemptKey, label: "Triggering artifact rebuild", schema: rebuildSchema });
1647
- } catch (rebuildErr) {
1648
- // Structured-output failure (canary run 9, 2026-09-11): the agent
1649
- // called artifact_edit (tool_call_count > 0) but returned prose
1650
- // instead of JSON. The side effect may have happened — the outcome
1651
- // is UNKNOWN, not "did not go through". The old code asked a child
1652
- // for derived booleans and retried on all-false; that check issued
1653
- // the DUPLICATE artifact_edit on 2026-09-12.
1654
- //
1655
- // Build-ID research (2026-09-12) corrected the model: artifact.edit
1656
- // returns pending_init with NO agent_id, but artifact_status exposes
1657
- // the build's agent_id (the artifact system's in-flight build
1658
- // correlation ID, stable across polls while the build runs)
1659
- // immediately after acceptance.
1660
- // So the recovery no longer asks the child to derive booleans
1661
- // the layer where the 2026-09-12 signal was lost. It reads the RAW
1662
- // build object and extracts build.agent_id mechanically in the
1663
- // workflow script. An observed agent_id is positive evidence the
1664
- // edit went through; no build after a bounded poll is still
1665
- // inconclusive (unknown), never proof the edit failed. Mechanical
1666
- // rule: never blind-retry on unknown record the attempt and park
1667
- // fail-closed; correlate via the ledger, never by re-issuing.
1668
- log("Publish rebuild trigger: structured-output failure (" + (rebuildErr && rebuildErr.message ? rebuildErr.message : rebuildErr) + ") — checking build state before deciding; outcome unknown until state confirms it");
1669
- var buildState = null;
1670
- var buildStateFailed = false;
1661
+ buildState = await agent(
1662
+ ARTIFACT_LOAD_PREAMBLE +
1663
+ "Call artifact_status with slug \"" + PUBLISH_SLUG + "\".\n" +
1664
+ "Poll up to 3 times, about 20 seconds apart, until the response shows a build (the \"build\" value is an object, not null). " +
1665
+ "Return the raw \"build\" value verbatim as JSON — the build object exactly as returned, with its agent_id, operation, status, and any other fields untouched. " +
1666
+ "Do not summarize, interpret, or derive booleans from it. " +
1667
+ "If no build appears after 3 polls, return null. " +
1668
+ "Return JSON { \"build\": <the raw build object or null> } and nothing else.",
1669
+ { key: attemptKey("publish-artifact-buildcheck-" + taskId, totalReworkCount), label: "Reading artifact build state after trigger",
1670
+ schema: { type: "object", properties: { build: { type: ["object", "null"] } }, required: ["build"] } }
1671
+ );
1672
+ } catch (buildCheckErr) {
1673
+ buildStateFailed = true;
1674
+ log("Publish post-trigger build-state check failed for task " + taskId + " (" + (buildCheckErr && buildCheckErr.message ? buildCheckErr.message : buildCheckErr) + ") — this signal is unknown, not negative");
1675
+ }
1676
+ var observedAgentId = (buildState && buildState.build && typeof buildState.build.agent_id === "string" && buildState.build.agent_id) || null;
1677
+ // Known limitation (failure-mode audit 2026-09-16): attribution
1678
+ // is timing-based any agent_id new relative to the baseline is
1679
+ // treated as this edit's receipt. A stranger's build starting inside
1680
+ // the trigger window is indistinguishable by timing and would be
1681
+ // misattributed here. The consequence is bounded: the completion
1682
+ // poll below tracks the recorded id, and the parent's mechanical
1683
+ // content read-back (docs/publish-verification.md) certifies the
1684
+ // exact commit's content a wrong build's content fails closed as
1685
+ // verification-failed, never stamped. Timing narrows the candidate;
1686
+ // content decides.
1687
+ var receiptAgentId = (!buildStateFailed && !baselineFailed && observedAgentId && observedAgentId !== baselineAgentId) ? observedAgentId : null;
1688
+ if (receiptAgentId) {
1689
+ // The edit went through — a build with a new agent_id appeared
1690
+ // after the trigger. The parent's independent read-back
1691
+ // (docs/publish-verification.md) is the verification, not any
1692
+ // builder report.
1693
+ rebuildTrigger = { edit_started: true };
1694
+ rebuildAgentId = receiptAgentId;
1695
+ log("Publish rebuild trigger for task " + taskId + ": artifact_status shows build " + receiptAgentId + " for slug " + PUBLISH_SLUG + " (new relative to the pre-trigger baseline) — the edit went through.");
1696
+ await recordPublishLedger({
1697
+ commit: mergeCommitForPublish,
1698
+ attempt: rebuildAttemptKey,
1699
+ agent_id: rebuildAgentId,
1700
+ applied_report: publishAppliedObservation,
1701
+ outcome: "submitted",
1702
+ detail: "fire-and-forget trigger; build receipt captured by workflow-owned build-state observation (pre/post-trigger diff)"
1703
+ }, totalReworkCount);
1704
+ } else {
1705
+ var newAuditDirs = [];
1706
+ // auditReportOk: pure tri-state read of a report.json body —
1707
+ // true (build ok), false (build failed), null (missing or
1708
+ // unreadable — not evidence either way). The child returns the
1709
+ // raw body verbatim; interpretation lives here, never in prose.
1710
+ // Defined here so both the immediate and post-poll audit
1711
+ // fallbacks share it.
1712
+ var auditReportOk = function (raw) {
1713
+ if (typeof raw !== "string") return null;
1714
+ var trimmed = raw.trim();
1715
+ if (trimmed === "" || trimmed === "MISSING") return null;
1716
+ var parsed;
1717
+ try { parsed = JSON.parse(trimmed); } catch (e) { return null; }
1718
+ if (parsed && typeof parsed.ok === "boolean") return parsed.ok;
1719
+ return null;
1720
+ };
1721
+ // (2026-09-16, critic finding 2) When durable audit evidence
1722
+ // confirms (or refutes) the build, there is no receipt agent_id
1723
+ // to chain the completion poll to — skipReceiptPoll bypasses the
1724
+ // poll below, which with a null receipt could only observe
1725
+ // strangers or nothing.
1726
+ var skipReceiptPoll = false;
1727
+ // publishFailure is declared here (moved up from below) so the
1728
+ // immediate audit fallback can record an explicit build failure
1729
+ // without the later declaration resetting it.
1730
+ var publishFailure = null;
1671
1731
  try {
1672
- buildState = await agent(
1673
- ARTIFACT_LOAD_PREAMBLE +
1674
- "Call artifact_status with slug \"" + PUBLISH_SLUG + "\".\n" +
1675
- "Poll up to 3 times, about 20 seconds apart, until the response shows a build (the \"build\" value is an object, not null). " +
1676
- "Return the raw \"build\" value verbatim as JSON — the build object exactly as returned, with its agent_id, operation, status, and any other fields untouched. " +
1677
- "Do not summarize, interpret, or derive booleans from it. " +
1678
- "If no build appears after 3 polls, return null. " +
1679
- "Return JSON { \"build\": <the raw build object or null> } and nothing else.",
1680
- { key: attemptKey("publish-artifact-buildcheck-" + taskId, totalReworkCount), label: "Reading artifact build state after trigger failure",
1681
- schema: { type: "object", properties: { build: { type: ["object", "null"] } }, required: ["build"] } }
1732
+ var auditAfter = await agent(
1733
+ "List the artifact audit directories for slug \"" + PUBLISH_SLUG + "\" (best-effort, never a gate).\n" +
1734
+ "Run: ls -1 ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/ 2>/dev/null\n" +
1735
+ "Return JSON { \"dirs\": \"<newline-separated names, empty string when the audits directory does not exist or is empty>\" } and nothing else.",
1736
+ { key: attemptKey("publish-audit-after-" + taskId, totalReworkCount), label: "Re-listing audit dirs after trigger",
1737
+ schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
1682
1738
  );
1683
- } catch (buildCheckErr) {
1684
- buildStateFailed = true;
1685
- log("Publish rebuild trigger: build-state check itself failed (" + (buildCheckErr && buildCheckErr.message ? buildCheckErr.message : buildCheckErr) + ") — treating the outcome as unknown");
1739
+ var auditDirsAfterTrigger = String((auditAfter && auditAfter.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
1740
+ // Only timestamped build dirs count — the "latest" symlink
1741
+ // and anything else are not builds. Gated on auditBeforeOk:
1742
+ // without a baseline every historical dir would look new.
1743
+ newAuditDirs = auditBeforeOk ? auditDirsAfterTrigger.filter(function (d) {
1744
+ return auditDirsBeforeTrigger.indexOf(d) === -1 && /^20\d\d-\d\d-\d\dT\d\d-\d\d-\d\dZ-/.test(d);
1745
+ }) : [];
1746
+ } catch (auditAfterErr) {
1747
+ log("Publish audit-dir re-list after trigger failed for task " + taskId + " (non-fatal, durable-evidence check degraded): " + (auditAfterErr && auditAfterErr.message ? auditAfterErr.message : auditAfterErr));
1686
1748
  }
1687
- var acceptedAgentId = (buildState && buildState.build && typeof buildState.build.agent_id === "string" && buildState.build.agent_id) || null;
1688
- if (!buildStateFailed && acceptedAgentId) {
1689
- // The edit went through — the agent just failed to return JSON.
1690
- // The build's agent_id is positive evidence: it appears in
1691
- // artifact_status immediately after our accepted edit (pending_init
1692
- // acceptance is followed by a visible build with a stable agent_id,
1693
- // per the 2026-09-12 research). No applied report to smoke-check;
1694
- // the parent's independent read-back (docs/publish-verification.md)
1695
- // is the real verification, not the circular applied-report. The
1696
- // agent_id is recorded in the ledger so this attempt correlates to
1697
- // the exact builder run, not just commit + attempt key.
1698
- log("Publish rebuild trigger: artifact_status shows build " + acceptedAgentId + " for slug " + PUBLISH_SLUG + " — the edit went through despite the structured-output failure. Skipping applied-report smoke-check; parent read-back is the verification.");
1699
- rebuildTrigger = { edit_started: true, error: "", applied: null };
1700
- rebuildReportMissing = true;
1701
- rebuildAgentId = acceptedAgentId;
1702
- rebuildEvidenceNote = "edit confirmed via build-state poll after structured-output failure (build " + acceptedAgentId + "); builder applied-report missing";
1703
- } else {
1704
- // Durable completion check (2026-09-14): the in-flight poll
1705
- // above only sees RUNNING builds. Attempt 7 (2026-09-14) proved
1706
- // the gap: the trigger child applied the edit, the build ran
1707
- // and completed — the platform's audit harness captured it
1708
- // mid-window — then the child failed to return JSON. The
1709
- // fallback poll saw no in-flight build, so a successful publish
1710
- // parked as "unknown". Diff the audit-dir listing against the
1711
- // pre-trigger snapshot: a timestamped directory that appeared
1712
- // during the trigger window is positive evidence the edit went
1713
- // through and the build completed. This never re-issues the
1714
- // edit and never stamps provenance — it only routes to the
1715
- // parent's independent content read-back, which remains the
1716
- // real verification.
1717
- var newAuditDirs = [];
1749
+ if (newAuditDirs.length > 0) {
1750
+ rebuildTrigger = { edit_started: true };
1751
+ rebuildAgentId = null;
1752
+ newAuditDirs.sort();
1753
+ var newestImmediateDir = newAuditDirs[newAuditDirs.length - 1];
1754
+ 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.");
1755
+ // (2026-09-16, critic finding 2) Durable audit evidence exists,
1756
+ // but there is no receipt agent_id to chain the completion poll
1757
+ // to polling with a null receipt can only observe strangers
1758
+ // (any running build differs from "null") or nothing, burning
1759
+ // 10.5 minutes to park unknown. Read the build report now
1760
+ // instead of polling: ok=true confirms completion and routes
1761
+ // directly to parent verification (the poll is skipped);
1762
+ // ok=false is explicit failure; unreadable is unknown.
1763
+ var immediateReportOk = null;
1718
1764
  try {
1719
- var auditAfter = await agent(
1720
- "List the artifact audit directories for slug \"" + PUBLISH_SLUG + "\" (best-effort, never a gate).\n" +
1721
- "Run: ls -1 ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/ 2>/dev/null\n" +
1722
- "Return JSON { \"dirs\": \"<newline-separated names, empty string when the audits directory does not exist or is empty>\" } and nothing else.",
1723
- { key: attemptKey("publish-audit-after-" + taskId, totalReworkCount), label: "Re-listing audit dirs after trigger failure",
1724
- schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
1765
+ var immediateOkRead = await agent(
1766
+ "Read the artifact build report for slug \"" + PUBLISH_SLUG + "\".\n" +
1767
+ "Run: cat ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/" + newestImmediateDir + "/report.json 2>/dev/null || echo MISSING\n" +
1768
+ "Return JSON { \"raw\": \"<verbatim file contents, or the literal string MISSING when the file does not exist>\" } and nothing else.",
1769
+ { key: attemptKey("publish-audit-ok-immediate-" + taskId, totalReworkCount), label: "Reading build report for audit-confirmed build",
1770
+ schema: { type: "object", properties: { raw: { type: "string" } }, required: ["raw"] } }
1725
1771
  );
1726
- var auditDirsAfterTrigger = String((auditAfter && auditAfter.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
1727
- // Only timestamped build dirs count — the "latest" symlink
1728
- // and anything else are not builds.
1729
- newAuditDirs = auditDirsAfterTrigger.filter(function (d) {
1730
- return auditDirsBeforeTrigger.indexOf(d) === -1 && /^20\d\d-\d\d-\d\dT\d\d-\d\d-\d\dZ-/.test(d);
1731
- });
1732
- } catch (auditAfterErr) {
1733
- log("Publish audit-dir re-list after trigger failure failed for task " + taskId + " (non-fatal, durable-evidence check degraded): " + (auditAfterErr && auditAfterErr.message ? auditAfterErr.message : auditAfterErr));
1772
+ immediateReportOk = auditReportOk(immediateOkRead && immediateOkRead.raw);
1773
+ } catch (immediateOkErr) {
1774
+ log("Publish build-report read for audit-confirmed dir failed for task " + taskId + " (treated as unknown): " + (immediateOkErr && immediateOkErr.message ? immediateOkErr.message : immediateOkErr));
1775
+ immediateReportOk = null;
1734
1776
  }
1735
- if (newAuditDirs.length > 0) {
1736
- log("Publish rebuild trigger: new audit dir(s) during the trigger window (" + newAuditDirs.join(", ") + ") — the edit went through and the build completed despite the structured-output failure. Skipping applied-report smoke-check; parent read-back is the verification.");
1737
- rebuildTrigger = { edit_started: true, error: "", applied: null };
1738
- rebuildReportMissing = true;
1739
- rebuildAgentId = null;
1740
- rebuildEvidenceNote = "edit confirmed via durable audit evidence after structured-output failure (new audit dir " + newAuditDirs[0] + "); builder applied-report missing";
1777
+ if (immediateReportOk === true) {
1778
+ publishBuildLanded = true;
1779
+ artifactPublish = { source_commit: mergeCommitForPublish, pending_parent_verification: true };
1780
+ skipReceiptPoll = true;
1781
+ 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");
1782
+ await recordPublishLedger({
1783
+ commit: mergeCommitForPublish,
1784
+ attempt: rebuildAttemptKey,
1785
+ agent_id: null,
1786
+ applied_report: publishAppliedObservation,
1787
+ outcome: "submitted",
1788
+ detail: "durable audit evidence shows a build completed during the attempt window (audit dir " + newestImmediateDir + ", report ok=true); receipt poll skipped (no receipt agent_id), routed to parent verification"
1789
+ }, totalReworkCount);
1790
+ } else if (immediateReportOk === false) {
1791
+ skipReceiptPoll = true;
1792
+ 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.";
1793
+ await recordPublishLedger({
1794
+ commit: mergeCommitForPublish,
1795
+ attempt: rebuildAttemptKey,
1796
+ agent_id: null,
1797
+ applied_report: publishAppliedObservation,
1798
+ outcome: "failed",
1799
+ detail: "a build ran and failed: audit dir " + newestImmediateDir + " report ok=false (immediate audit evidence, no receipt)"
1800
+ }, totalReworkCount);
1741
1801
  } else {
1742
- // No build observed — but that proves nothing (a fast-completing
1743
- // build can finish between polls, or the check itself failed). The
1744
- // outcome is UNKNOWN. No retry: re-issuing the edit here duplicated
1745
- // it on 2026-09-12. Record the attempt durably and park fail-closed;
1802
+ await recordPublishLedger({
1803
+ commit: mergeCommitForPublish,
1804
+ attempt: rebuildAttemptKey,
1805
+ agent_id: null,
1806
+ applied_report: null,
1807
+ outcome: "unknown",
1808
+ detail: "new audit dir " + newestImmediateDir + " appeared during the trigger window but its build report is unreadable/missing; no receipt agent_id to poll — outcome unknown, fail-closed with no blind retry"
1809
+ }, totalReworkCount);
1810
+ return await parkTask("Publish outcome unknown for task " + taskId + ": a new audit dir (" + newestImmediateDir + ") appeared during the trigger window but its build report is unreadable, and no in-flight receipt was observed to poll. The edit may have completed. Correlate the accepted edit via the publish ledger at " + crewHome + "/.publish-ledger/" + PUBLISH_SLUG + ".jsonl — do NOT reissue the edit blindly: if the trigger was accepted, a retry duplicates it (2026-09-12). Verify independently whether the build completed (audit dir + report, or the parent's content read-back) before deciding the next step. Fail-closed.");
1811
+ }
1812
+ } else {
1813
+ // No attributable build and no durable evidence — but that
1814
+ // proves nothing (a fast-completing build can finish between
1815
+ // polls, or the checks themselves failed). The outcome is
1816
+ // UNKNOWN. No retry: re-issuing the edit here duplicated it on
1817
+ // 2026-09-12. Record the attempt durably and park fail-closed;
1746
1818
  // correlate via the ledger, never by guessing from a blind poll.
1747
- log("Publish rebuild trigger: no build observed after structured-output failure — outcome UNKNOWN. Recording the attempt and parking fail-closed; no blind retry.");
1819
+ log("Publish rebuild trigger for task " + taskId + ": no attributable build observed and no new audit dir — outcome UNKNOWN. Recording the attempt and parking fail-closed; no blind retry.");
1748
1820
  await recordPublishLedger({
1749
1821
  commit: mergeCommitForPublish,
1750
1822
  attempt: rebuildAttemptKey,
1751
1823
  agent_id: null,
1752
1824
  applied_report: null,
1753
1825
  outcome: "unknown",
1754
- detail: "structured-output failure on rebuild trigger; build-state poll saw no build (or the check itself failed); edit may have been accepted as pending_init"
1755
- }, totalReworkCount);
1756
- return await parkTask("Publish outcome unknown: the rebuild trigger's child did not return JSON, and the follow-up build-state poll could not observe a build for slug " + PUBLISH_SLUG + ". The edit may have been accepted as pending_init, so no retry was issued — a blind retry duplicated the edit on 2026-09-12. The attempt is recorded in the publish ledger at " + crewHome + "/.publish-ledger/" + PUBLISH_SLUG + ".jsonl (commit " + String(mergeCommitForPublish || "unknown").slice(0, 12) + "). Correlate the accepted edit via the ledger and the builder's eventual completion before re-driving Publish. Fail-closed.");
1757
- }
1758
- }
1759
- }
1760
- if (!rebuildReportMissing && !rebuildTrigger.edit_started && rebuildTrigger.error === "artifact_tools missing after load") {
1761
- log("Publish rebuild trigger: artifact_tools missing after load — one bounded retry with a fresh key");
1762
- rebuildTrigger = await agent(rebuildPrompt,
1763
- { key: attemptKey("publish-artifact-rebuild-" + taskId + "-retry2", totalReworkCount), label: "Triggering artifact rebuild (retry)", schema: rebuildSchema });
1764
- rebuildAttemptKey = attemptKey("publish-artifact-rebuild-" + taskId + "-retry2", totalReworkCount);
1765
- }
1766
- // Receipt chaining (2026-09-13): adopt the trigger's build receipt,
1767
- // or park on an uncorrelated acceptance. The trigger's closeout schema
1768
- // requires build_agent_id — the platform build's in-flight correlation
1769
- // ID captured immediately after the edit was accepted.
1770
- // An accepted edit (edit_started=true) with a null receipt is UNKNOWN,
1771
- // not "did not go through": the build may be pending_init-invisible,
1772
- // may have finished before the capture window, or may be queued behind
1773
- // a still-running earlier build. No re-trigger is issued on unknown —
1774
- // a blind re-trigger duplicated the edit on 2026-09-12, and the platform
1775
- // offers no idempotency proof that would make re-issue safe.
1776
- // (Retry-semantics reconciliation, 2026-09-13: the "no receipt → safe
1777
- // re-trigger" sketch assumed the edit command idempotently publishes
1778
- // what's on git; the duplicate-edit incident disproves the assumption,
1779
- // and the standing rule retries only on explicit negative evidence.
1780
- // Re-trigger stays exactly where it was: the edit_started=false
1781
- // explicit-rejection path above.) Record the attempt and park
1782
- // fail-closed; correlate via the ledger and the parent's content
1783
- // read-back before re-driving Publish.
1784
- if (rebuildTrigger && rebuildTrigger.edit_started && !rebuildReportMissing) {
1785
- var triggerAgentId = (typeof rebuildTrigger.build_agent_id === "string" && rebuildTrigger.build_agent_id.length > 0) ? rebuildTrigger.build_agent_id : null;
1786
- if (!triggerAgentId) {
1787
- var uncorrelatedObservation = (function () { var c = verifyAppliedChanges(expectedChanges, rebuildTrigger.applied); return c.ok ? "match" : "mismatch: " + c.reason; })();
1788
- log("Publish receipt missing for task " + taskId + ": the trigger reported edit_started=true but captured no build receipt (build_agent_id null) — no build attributable to this edit. Parking fail-closed without re-triggering.");
1789
- await recordPublishLedger({
1790
- commit: mergeCommitForPublish,
1791
- attempt: rebuildAttemptKey,
1792
- agent_id: null,
1793
- applied_report: uncorrelatedObservation,
1794
- outcome: "unknown",
1795
- detail: "edit accepted (edit_started=true) but the trigger captured no build receipt in its capture window: no build attributable to this edit (pending_init-invisible, finished before capture, or queued behind an earlier build). No re-trigger issued — a blind re-trigger on an unknown outcome duplicated the edit on 2026-09-12 and the platform offers no idempotency proof."
1826
+ detail: "fire-and-forget trigger; post-trigger build-state poll saw no attributable build (or the check failed) and the audit-dir diff found no new dir; the edit may have been accepted as pending_init"
1796
1827
  }, totalReworkCount);
1797
- return await parkTask("Publish outcome unknown: the rebuild trigger reported the edit was accepted but captured no build receipt (build_agent_id null) no build could be attributed to this edit in the capture window. The edit may be pending_init-invisible, already finished, or queued behind an earlier build, so no re-trigger was issued: a blind retry duplicated the edit on 2026-09-12. The attempt is recorded in the publish ledger at " + crewHome + "/.publish-ledger/" + PUBLISH_SLUG + ".jsonl (commit " + String(mergeCommitForPublish || "unknown").slice(0, 12) + "). Correlate via the ledger and re-drive Publish only after the parent's content read-back resolves what actually landed. Fail-closed.");
1828
+ return await parkTask("Publish outcome unknown for task " + taskId + ": the rebuild trigger was issued fire-and-forget (no schema, so no validation failure mode; a candidate-parse throw stays possible and is inconclusive), and the follow-up observation could not attribute a build to the edit for slug " + PUBLISH_SLUG + " — no in-flight build with a new agent_id appeared in the poll window and no new audit dir landed. The edit may have been accepted as pending_init, so no retry was issued: a blind retry duplicated the edit on 2026-09-12. The attempt is recorded in the publish ledger at " + crewHome + "/.publish-ledger/" + PUBLISH_SLUG + ".jsonl (commit " + String(mergeCommitForPublish || "unknown").slice(0, 12) + "). Correlate the accepted edit via the ledger and the builder's eventual completion — do NOT reissue the edit blindly. Verify independently whether the build completed before deciding the next step. Fail-closed.");
1798
1829
  }
1799
- rebuildAgentId = triggerAgentId;
1800
- log("Publish receipt chained for task " + taskId + ": build " + triggerAgentId + " — the follow-up poll waits on this build only.");
1801
1830
  }
1831
+
1802
1832
  // Durable publish-attempt ledger: record the trigger outcome while the
1803
1833
  // attempt key and commit are in scope. Every attempt lands here with
1804
1834
  // its outcome — submitted, rejected, or unknown (unknown is recorded
1805
1835
  // at the park site above). A later run or human matches commit hash +
1806
1836
  // attempt key against the builder's eventual completion.
1807
- if (rebuildTrigger && rebuildTrigger.edit_started) {
1808
- // Applied-report observation (2026-09-12, task 23ca8f3f): the
1809
- // builder's applied-report is logged as observation only it
1810
- // never parks. The report is derived from the carried diff, so a
1811
- // "match" certifies nothing (canary run 8); and it has a
1812
- // demonstrated false-negative mode (applied:[] for a diff the
1813
- // builder had actually applied). The independent read-back below
1814
- // plus the parent protocol (docs/publish-verification.md) are the
1815
- // verification this block always proceeds to them.
1816
- publishAppliedObservation = rebuildReportMissing
1817
- ? "missing-report"
1818
- : (function () { var c = verifyAppliedChanges(expectedChanges, rebuildTrigger.applied); return c.ok ? "match" : "mismatch: " + c.reason; })();
1819
- log("Publish applied-report observation for task " + taskId + ": " + publishAppliedObservation + " — observation only, never a park: the applied report is derived from the carried diff and proved unreliable in the false-negative direction (task 23ca8f3f, 2026-09-12: applied:[] for a diff the builder had applied). The independent read-back below plus the parent protocol are the verification.");
1820
- await recordPublishLedger({
1821
- commit: mergeCommitForPublish,
1822
- attempt: rebuildAttemptKey,
1823
- agent_id: rebuildAgentId,
1824
- applied_report: publishAppliedObservation,
1825
- outcome: "submitted",
1826
- detail: rebuildReportMissing
1827
- ? (rebuildEvidenceNote || "edit confirmed via build-state poll after structured-output failure (build " + (rebuildAgentId || "agent_id unknown") + "); builder applied-report missing")
1828
- : "edit accepted; builder applied-report received"
1829
- }, totalReworkCount);
1830
- } else if (rebuildTrigger) {
1831
- await recordPublishLedger({
1832
- commit: mergeCommitForPublish,
1833
- attempt: rebuildAttemptKey,
1834
- applied_report: null,
1835
- outcome: "rejected",
1836
- detail: "edit not accepted: " + (rebuildTrigger.error || "no error detail")
1837
- }, totalReworkCount);
1838
- }
1839
- var publishFailure = null;
1840
- if (rebuildTrigger.edit_started) {
1841
- // STEP 1b (observation only): publishAppliedObservation was
1842
- // computed and logged above, inside the ledger block — the
1843
- // builder's applied-report never parks and never blocks the stamp.
1844
- // Task 23ca8f3f (2026-09-12) proved its false-negative mode:
1845
- // applied:[] for a diff the builder had actually applied, which
1846
- // parked a successful publish as unverified. A "match" certifies
1847
- // nothing either — the report is derived from the carried diff
1848
- // (canary run 8). The flow proceeds to the build poll and the
1849
- // independent read-back trigger regardless of what the report
1850
- // claimed; real verification is the parent's read-back
1851
- // (docs/publish-verification.md) before the provenance stamp.
1852
- // Pre-publish base observation (diagnostic, 2026-09-12): compare
1853
- // the builder's self-reported pre-edit hashes against the
1854
- // workflow-computed expected base (merge parent). This tells us
1855
- // what base state the publish actually read. OBSERVATION ONLY —
1856
- // a mismatch is logged loudly but never parks and never blocks
1857
- // the stamp. If the tree was dirty or drifted, the evidence is
1858
- // here; the fix (requiring the right base) comes after we see it.
1859
- try {
1860
- var preHashes = (rebuildTrigger && rebuildTrigger.pre_hashes) || {};
1861
- var baseLines = expectedChanges.map(function(f) {
1862
- var expected = expectedBaseHashes[f.path];
1863
- var actual = preHashes[f.path];
1864
- var expShort = (expected || "UNKNOWN").slice(0, 12);
1865
- var actShort = String(actual || "NOT-REPORTED").slice(0, 12);
1866
- var match = (expected !== undefined && actual !== undefined) ? (expected === actual) : "unknown";
1867
- return " " + f.path + ": expected_base=" + expShort + " builder_pre=" + actShort + " match=" + match;
1868
- });
1869
- var anyMismatch = expectedChanges.some(function(f) {
1870
- return expectedBaseHashes[f.path] !== undefined && preHashes[f.path] !== undefined && expectedBaseHashes[f.path] !== preHashes[f.path];
1871
- });
1872
- log("Publish pre-tree base observation for task " + taskId + (anyMismatch ? " — BASE MISMATCH DETECTED (tree was not at the expected merge-parent state when the diff was applied):" : " — base matches expected merge-parent state:") + "\n" + baseLines.join("\n"));
1873
- } catch (e) {
1874
- log("Publish pre-tree base observation failed for task " + taskId + " (non-fatal): " + (e && e.message ? e.message : e));
1875
- }
1837
+ // (2026-09-16) The trigger is fire-and-forget: the observation above
1838
+ // already recorded the ledger's submitted line on both positive paths
1839
+ // and parked on unknown — there is no applied report to observe and
1840
+ // no rejection signal to record.
1841
+ // (publishFailure is declared with the immediate audit fallback
1842
+ // above so an explicit build failure there survives to here.)
1843
+ if (rebuildTrigger.edit_started && !skipReceiptPoll) {
1844
+ // (2026-09-16) There is no builder report: the fire-and-forget
1845
+ // trigger carries no JSON contract, so there is nothing to
1846
+ // compare and no pre-hash diagnostic. The builder's old
1847
+ // self-report was circular by construction (canary run 8) with a
1848
+ // demonstrated false-negative mode (task 23ca8f3f, 2026-09-12:
1849
+ // applied:[] for a diff the builder had applied). The flow
1850
+ // proceeds to the build poll regardless; real verification is the
1851
+ // parent's independent read-back (docs/publish-verification.md)
1852
+ // before the provenance stamp.
1876
1853
  // STEP 1b (mechanical): bounded poll for build completion, chunked so
1877
1854
  // the merge-lock lease is refreshed before it can expire. The 600s
1878
1855
  // lease is shorter than the worst-case 10-minute build poll, so the
@@ -1960,14 +1937,15 @@ while (i < STEPS.length) {
1960
1937
  if (buildPoll.build_done && pollSawOurBuild) {
1961
1938
  // STEP 1c (mechanical): NO provenance stamp here. Canary run 8
1962
1939
  // (2026-09-11) proved the stamp cannot certify content: the
1963
- // builder's applied-report is derived from the carried diff, so
1964
- // verifyAppliedChanges above is circular — a fabricated report
1965
- // passes by construction, and every phase went green on a hollow
1940
+ // builder's applied-report was derived from the carried diff, so
1941
+ // the old report check was circular — a fabricated report
1942
+ // passed by construction, and every phase went green on a hollow
1966
1943
  // build. The stamp moves to the parent (docs/publish-verification.md);
1967
- // the independent read-back step is currently unavailable (no
1968
- // agent-callable read-back tool exists artifact_inspect was
1969
- // removed by the platform 2026-09-14), so the parent cannot
1970
- // confirm content and the task parks for verification.
1944
+ // the deterministic lib/readback-disk.js is the primary sensor
1945
+ // (the agent-callable read-back tool is unavailable
1946
+ // artifact_inspect was removed by the platform 2026-09-14 so
1947
+ // the LLM-inspector path is manual-fallback only), and the task
1948
+ // parks for parent verification.
1971
1949
  // QA's provenance check enforces the stamp mechanically.
1972
1950
  // An unverified publish fails loudly in QA instead of passing
1973
1951
  // silently here.
@@ -2010,26 +1988,17 @@ while (i < STEPS.length) {
2010
1988
  schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
2011
1989
  );
2012
1990
  var auditDirsAfterPollList = String((auditAfterPoll && auditAfterPoll.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
2013
- newAuditDirsAfterPoll = auditDirsAfterPollList.filter(function (d) {
1991
+ // Gated on auditBeforeOk (critic finding 4): without a baseline
1992
+ // every historical dir would look new.
1993
+ newAuditDirsAfterPoll = auditBeforeOk ? auditDirsAfterPollList.filter(function (d) {
2014
1994
  return auditDirsBeforeTrigger.indexOf(d) === -1 && /^20\d\d-\d\d-\d\dT\d\d-\d\d-\d\dZ-/.test(d);
2015
- });
1995
+ }) : [];
2016
1996
  log("Publish audit-dir re-list after build poll for task " + taskId + ": " + newAuditDirsAfterPoll.length + " new timestamped dir(s)");
2017
1997
  } catch (auditAfterPollErr) {
2018
1998
  log("Publish audit-dir re-list after build poll failed for task " + taskId + " (non-fatal, durable-evidence check degraded): " + (auditAfterPollErr && auditAfterPollErr.message ? auditAfterPollErr.message : auditAfterPollErr));
2019
1999
  }
2020
- // auditReportOk: pure tri-state read of a report.json body —
2021
- // true (build ok), false (build failed), null (missing or
2022
- // unreadable — not evidence either way). The child returns the
2023
- // raw body verbatim; interpretation lives here, never in prose.
2024
- var auditReportOk = function (raw) {
2025
- if (typeof raw !== "string") return null;
2026
- var trimmed = raw.trim();
2027
- if (trimmed === "" || trimmed === "MISSING") return null;
2028
- var parsed;
2029
- try { parsed = JSON.parse(trimmed); } catch (e) { return null; }
2030
- if (parsed && typeof parsed.ok === "boolean") return parsed.ok;
2031
- return null;
2032
- };
2000
+ // The shared auditReportOk (defined with the immediate fallback
2001
+ // above) interprets the raw body here too.
2033
2002
  var auditOkAfterPoll = null;
2034
2003
  var newestAuditDirAfterPoll = null;
2035
2004
  if (newAuditDirsAfterPoll.length > 0 && !strangerObserved) {
@@ -2088,7 +2057,9 @@ while (i < STEPS.length) {
2088
2057
  }
2089
2058
  }
2090
2059
  } else {
2091
- publishFailure = "Artifact rebuild trigger failed: " + (rebuildTrigger.error || "artifact_edit not accepted") + ". The publish did not land.";
2060
+ // Unreachable: the observation above either attributes the edit
2061
+ // (edit_started) or parks. Defensive only — never a silent pass.
2062
+ 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.";
2092
2063
  }
2093
2064
  } // end: publishSkippedNoLock — no rebuild, no stamp, nothing to ship
2094
2065
  // STEP 2 (mechanical, always — skip path included): post-deploy