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.
- package/docs/publish-verification.md +45 -22
- package/lib/AGENTS.md +4 -1
- package/lib/compose-evidence-caption.js +57 -14
- package/lib/verify-publish.js +51 -13
- package/package.json +1 -1
- package/workflows/bugfix.js +368 -397
- package/workflows/chore.js +370 -397
- package/workflows/standard.js +378 -404
package/workflows/chore.js
CHANGED
|
@@ -499,48 +499,6 @@ function parseUnifiedDiff(diffText) {
|
|
|
499
499
|
return files;
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
// Compare the artifact builder's reported applied-changes against the diff's
|
|
503
|
-
// expected changes. Every added/removed line must match exactly per path,
|
|
504
|
-
// and the file counts must match — the builder applies exactly the carried
|
|
505
|
-
// change, nothing more, nothing less. Pure function — no I/O, no clock.
|
|
506
|
-
// OBSERVATION INPUT ONLY (2026-09-12, task 23ca8f3f): the applied report
|
|
507
|
-
// has a demonstrated false-negative mode (applied:[] for a diff the builder
|
|
508
|
-
// had actually applied), and it is derived from the carried diff, so a match
|
|
509
|
-
// certifies nothing either. A mismatch is logged as observation; it never
|
|
510
|
-
// parks and never blocks the stamp. The verification is the independent
|
|
511
|
-
// read-back (docs/publish-verification.md).
|
|
512
|
-
function verifyAppliedChanges(expected, applied) {
|
|
513
|
-
if (!Array.isArray(applied)) {
|
|
514
|
-
return { ok: false, reason: "builder returned no applied-changes list" };
|
|
515
|
-
}
|
|
516
|
-
function sorted(a) { return (a || []).slice().sort(); }
|
|
517
|
-
function eq(a, b) {
|
|
518
|
-
a = sorted(a); b = sorted(b);
|
|
519
|
-
if (a.length !== b.length) return false;
|
|
520
|
-
for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
for (var i = 0; i < expected.length; i++) {
|
|
524
|
-
var exp = expected[i];
|
|
525
|
-
var got = null;
|
|
526
|
-
for (var j = 0; j < applied.length; j++) {
|
|
527
|
-
if (applied[j] && applied[j].path === exp.path) { got = applied[j]; break; }
|
|
528
|
-
}
|
|
529
|
-
if (!got) {
|
|
530
|
-
return { ok: false, reason: "builder did not report changing '" + exp.path + "'" };
|
|
531
|
-
}
|
|
532
|
-
if (!eq(exp.added, got.added)) {
|
|
533
|
-
return { ok: false, reason: "added lines for '" + exp.path + "' do not match the carried diff" };
|
|
534
|
-
}
|
|
535
|
-
if (!eq(exp.removed, got.removed)) {
|
|
536
|
-
return { ok: false, reason: "removed lines for '" + exp.path + "' do not match the carried diff" };
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
if (applied.length !== expected.length) {
|
|
540
|
-
return { ok: false, reason: "builder reported changing " + applied.length + " file(s), diff carries " + expected.length };
|
|
541
|
-
}
|
|
542
|
-
return { ok: true };
|
|
543
|
-
}
|
|
544
502
|
|
|
545
503
|
// Publish read-back request (currently unavailable): the verbatim_request
|
|
546
504
|
// the parent protocol (docs/publish-verification.md) would hand to an
|
|
@@ -554,35 +512,12 @@ function verifyAppliedChanges(expected, applied) {
|
|
|
554
512
|
// finding. Until a read-back path exists, the parent cannot independently
|
|
555
513
|
// confirm content and verification parks at "publish: verification-requested"
|
|
556
514
|
// (see docs/publish-verification.md). This preserves the circularity break
|
|
557
|
-
// that hollowed canary run 8 (2026-09-11):
|
|
558
|
-
// builder's applied-report against the diff the report was
|
|
559
|
-
// fabricated report
|
|
515
|
+
// that hollowed canary run 8 (2026-09-11): the old verifyAppliedChanges
|
|
516
|
+
// compared the builder's applied-report against the diff the report was
|
|
517
|
+
// derived from — a fabricated report passed by construction. The report
|
|
518
|
+
// itself is gone now (2026-09-16 fire-and-forget trigger). Independent
|
|
519
|
+
// read-back cannot be
|
|
560
520
|
// fabricated from the diff; it must match the artifact's real content.
|
|
561
|
-
// Pre-publish base observation (diagnostic, 2026-09-12): instruction fragment
|
|
562
|
-
// for the builder's edit request, asking it to report the sha256 of each
|
|
563
|
-
// touched file's CURRENT content BEFORE applying the diff. Pure function —
|
|
564
|
-
// no I/O, no clock.
|
|
565
|
-
//
|
|
566
|
-
// Why: the builder applies the carried diff to its own source tree, whose
|
|
567
|
-
// base state is unrecorded. The post-hoc read-back only checks the changed
|
|
568
|
-
// regions AFTER the edit; it cannot tell us what base the diff landed on.
|
|
569
|
-
// If the tree was dirty or drifted before the edit, the read-back still
|
|
570
|
-
// passes (the diff's lines are present) while the artifact silently carries
|
|
571
|
-
// uncommitted content — the production validateRepoPath incident
|
|
572
|
-
// (2026-09-12), where the live artifact contained code absent from every git
|
|
573
|
-
// ref. These pre-hashes, compared against the workflow-computed expected
|
|
574
|
-
// base hashes (merge parent), reveal what the publish actually read.
|
|
575
|
-
// Observation only — the workflow logs mismatches but never parks on them.
|
|
576
|
-
function buildPreHashInstruction(files) {
|
|
577
|
-
var paths = files.map(function(f) { return f.path; }).join(", ");
|
|
578
|
-
return (
|
|
579
|
-
"- 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" +
|
|
580
|
-
"- Report these hashes in the \"pre_hashes\" field of your return JSON, as { \"<path>\": \"<sha256 hex>\" }.\n" +
|
|
581
|
-
"- If a file does not exist in your tree, report its hash as the string \"MISSING\".\n" +
|
|
582
|
-
"- Do this BEFORE applying the diff — the hashes must reflect the pre-edit state.\n" +
|
|
583
|
-
" Files: " + paths + "\n"
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
521
|
|
|
587
522
|
// Durable publish-attempt ledger (2026-09-12): every artifact publish
|
|
588
523
|
// attempt is recorded append-only at $CREW_HOME/.publish-ledger/<slug>.jsonl
|
|
@@ -1412,9 +1347,10 @@ while (i < STEPS.length) {
|
|
|
1412
1347
|
// 2026-09-11), so the stamp moved to the parent — after the build
|
|
1413
1348
|
// lands, the workflow records the session completed and parks with
|
|
1414
1349
|
// "publish: verification-requested". The parent owns verification
|
|
1415
|
-
// (docs/publish-verification.md); the
|
|
1416
|
-
//
|
|
1417
|
-
// artifact_inspect was removed by the platform
|
|
1350
|
+
// (docs/publish-verification.md); the primary sensor is the
|
|
1351
|
+
// deterministic lib/readback-disk.js (the agent-callable read-back
|
|
1352
|
+
// tool is unavailable — artifact_inspect was removed by the platform
|
|
1353
|
+
// 2026-09-14 — so the LLM-inspector path is manual-fallback only).
|
|
1418
1354
|
// Chore has no QA: the parent's verification is the final gate.
|
|
1419
1355
|
var artifactPublish = null;
|
|
1420
1356
|
var publishLockRefreshed = false;
|
|
@@ -1524,38 +1460,8 @@ while (i < STEPS.length) {
|
|
|
1524
1460
|
if (expectedChanges.length === 0) {
|
|
1525
1461
|
return await parkTask("Publish diff parsed to zero files for commit " + (mergeCommitForPublish || "unknown") + " — cannot verify application. Human attention needed.");
|
|
1526
1462
|
}
|
|
1527
|
-
// Pre-publish base observation (diagnostic, 2026-09-12): the builder
|
|
1528
|
-
// applies the diff to its own source tree, whose base state is
|
|
1529
|
-
// unrecorded. Compute the trustworthy expected base — the sha256 of
|
|
1530
|
-
// each touched file at the merge parent commit — so the builder's
|
|
1531
|
-
// self-reported pre-edit hashes (see buildPreHashInstruction) can be
|
|
1532
|
-
// compared against it. Observation only: a mismatch is logged loudly
|
|
1533
|
-
// but never parks. The observation tells us what the publish actually
|
|
1534
|
-
// reads, so the subsequent fix can require the right base.
|
|
1535
|
-
var expectedBaseHashes = {};
|
|
1536
|
-
if (publishBase === EMPTY_TREE_SHA) {
|
|
1537
|
-
// First publish: every file in the diff is new to the artifact.
|
|
1538
|
-
expectedChanges.forEach(function (f) { expectedBaseHashes[f.path] = "NEW-FILE"; });
|
|
1539
|
-
log("Publish expected base hashes for task " + taskId + ": empty tree (first publish) — all " + expectedChanges.length + " file(s) new");
|
|
1540
|
-
} else try {
|
|
1541
|
-
// Shell-quote helper (no regex-with-quote: the test parser does not
|
|
1542
|
-
// understand regex literals containing quotes).
|
|
1543
|
-
var sq = function(s) { return "'" + String(s).split("'").join("'\\''") + "'"; };
|
|
1544
|
-
var baseHashResult = await agent(
|
|
1545
|
-
"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" +
|
|
1546
|
-
"Return JSON { \"hashes\": \"<newline-separated <path>:<sha256> lines, empty hash means the file is new in this diff>\" } and nothing else.",
|
|
1547
|
-
{ key: attemptKey("publish-base-hashes-" + taskId, reworkCount), label: "Computing expected base content hashes",
|
|
1548
|
-
schema: { type: "object", properties: { hashes: { type: "string" } }, required: ["hashes"] } }
|
|
1549
|
-
);
|
|
1550
|
-
(baseHashResult.hashes || "").split("\n").forEach(function(line) {
|
|
1551
|
-
var m = /^([^:]+):([0-9a-f]*)$/.exec(line.trim());
|
|
1552
|
-
if (m) expectedBaseHashes[m[1]] = m[2] || "NEW-FILE";
|
|
1553
|
-
});
|
|
1554
|
-
log("Publish expected base hashes for task " + taskId + " (stamped base " + publishBase.slice(0, 12) + "): " + JSON.stringify(expectedBaseHashes));
|
|
1555
|
-
} catch (e) {
|
|
1556
|
-
log("Publish expected base hash computation failed for task " + taskId + " (non-fatal, observation degraded): " + (e && e.message ? e.message : e));
|
|
1557
|
-
}
|
|
1558
1463
|
var rebuildPrompt =
|
|
1464
|
+
ARTIFACT_LOAD_PREAMBLE +
|
|
1559
1465
|
"Call artifact_edit with slug \"" + PUBLISH_SLUG + "\" and verbatim_request:\n" +
|
|
1560
1466
|
"'Apply the following change to your source tree, then rebuild and deploy.\n" +
|
|
1561
1467
|
"\n" +
|
|
@@ -1568,79 +1474,50 @@ while (i < STEPS.length) {
|
|
|
1568
1474
|
"- For a deleted file (+++ /dev/null), delete it.\n" +
|
|
1569
1475
|
"- If any hunk does not apply cleanly, STOP and report the failure — do not improvise or skip hunks.\n" +
|
|
1570
1476
|
"- Do not make any other source changes.\n" +
|
|
1571
|
-
"- After applying, rebuild and deploy
|
|
1572
|
-
"-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
"
|
|
1576
|
-
"
|
|
1577
|
-
"- 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" +
|
|
1578
|
-
"- Call artifact_edit as instructed above.\n" +
|
|
1579
|
-
"- 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" +
|
|
1580
|
-
"- 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" +
|
|
1581
|
-
"- 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" +
|
|
1582
|
-
"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.";
|
|
1583
|
-
var rebuildSchema =
|
|
1584
|
-
{ type: "object",
|
|
1585
|
-
properties: {
|
|
1586
|
-
edit_started: { type: "boolean" },
|
|
1587
|
-
build_agent_id: {
|
|
1588
|
-
type: ["string", "null"],
|
|
1589
|
-
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."
|
|
1590
|
-
},
|
|
1591
|
-
error: { type: "string" },
|
|
1592
|
-
applied: {
|
|
1593
|
-
type: "array",
|
|
1594
|
-
items: {
|
|
1595
|
-
type: "object",
|
|
1596
|
-
properties: {
|
|
1597
|
-
path: { type: "string" },
|
|
1598
|
-
added: { type: "array", items: { type: "string" } },
|
|
1599
|
-
removed: { type: "array", items: { type: "string" } }
|
|
1600
|
-
},
|
|
1601
|
-
required: ["path", "added", "removed"]
|
|
1602
|
-
}
|
|
1603
|
-
},
|
|
1604
|
-
pre_hashes: {
|
|
1605
|
-
type: "object",
|
|
1606
|
-
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."
|
|
1607
|
-
}
|
|
1608
|
-
},
|
|
1609
|
-
required: ["edit_started", "build_agent_id", "applied"] };
|
|
1610
|
-
var rebuildTrigger = null;
|
|
1611
|
-
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
|
|
1612
|
-
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
|
|
1477
|
+
"- After applying, rebuild and deploy.'\n" +
|
|
1478
|
+
"Edit-request contract (read carefully):\n" +
|
|
1479
|
+
"- 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" +
|
|
1480
|
+
"- If artifact_edit is not available after the load, do NOT improvise — end your turn.\n" +
|
|
1481
|
+
"- You do NOT call setprovenance, artifact_inspect, or post-deploy yourself.\n" +
|
|
1482
|
+
"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";
|
|
1613
1483
|
// The trigger key of the attempt that last ran, for the publish ledger.
|
|
1614
1484
|
// Minted once here (not re-minted per use site) so the ledger always
|
|
1615
1485
|
// records the exact key that was issued — and so a re-minted duplicate
|
|
1616
1486
|
// can never drift from it.
|
|
1617
1487
|
var rebuildAttemptKey = attemptKey("publish-artifact-rebuild-" + taskId, reworkCount);
|
|
1618
|
-
// The artifact build's agent_id,
|
|
1619
|
-
//
|
|
1620
|
-
//
|
|
1621
|
-
//
|
|
1622
|
-
//
|
|
1623
|
-
//
|
|
1624
|
-
//
|
|
1625
|
-
//
|
|
1488
|
+
// The artifact build's agent_id, attributed to this edit by the
|
|
1489
|
+
// workflow-owned observation below. The agent_id is the artifact
|
|
1490
|
+
// system's in-flight correlation ID (research 2026-09-12):
|
|
1491
|
+
// artifact.edit returns pending_init with NO agent_id, but
|
|
1492
|
+
// artifact_status exposes build.agent_id immediately after
|
|
1493
|
+
// acceptance, stable across polls. Recorded in the ledger so an
|
|
1494
|
+
// attempt correlates to the exact builder run; null when no build
|
|
1495
|
+
// was ever observed.
|
|
1626
1496
|
var rebuildAgentId = null;
|
|
1627
|
-
// The builder's applied
|
|
1628
|
-
//
|
|
1629
|
-
//
|
|
1630
|
-
|
|
1631
|
-
//
|
|
1632
|
-
//
|
|
1633
|
-
//
|
|
1634
|
-
|
|
1497
|
+
// The builder's applied report is gone (2026-09-16): it rode on the
|
|
1498
|
+
// trigger's JSON closeout contract, which is removed below. The
|
|
1499
|
+
// parent's independent read-back (docs/publish-verification.md) is
|
|
1500
|
+
// the verification — this field stays "missing-report" on ledger
|
|
1501
|
+
// lines for issued triggers; pre-trigger parks (toolcheck
|
|
1502
|
+
// rejected/inconclusive) and unattributed-unknown parks write null
|
|
1503
|
+
// (no trigger was observed, so there is nothing to report).
|
|
1504
|
+
var publishAppliedObservation = "missing-report";
|
|
1505
|
+
// Durable-evidence snapshot (2026-09-14): the observation below only
|
|
1506
|
+
// detects IN-FLIGHT builds. A build that finished before the
|
|
1507
|
+
// observation leaves no in-flight trace — but the platform's audit
|
|
1508
|
+
// harness leaves a durable one:
|
|
1635
1509
|
// ~/workspace/ts-spaces/<slug>/audits/<timestamp>-<id>/ per
|
|
1636
1510
|
// completed build. Snapshot the listing BEFORE the trigger so the
|
|
1637
1511
|
// fallback can diff before/after: a directory appearing during the
|
|
1638
1512
|
// trigger window is positive evidence the edit went through and
|
|
1639
1513
|
// the build completed. Best-effort and non-gating: if the snapshot
|
|
1640
|
-
// fails,
|
|
1641
|
-
//
|
|
1514
|
+
// fails, auditBeforeOk stays false and BOTH fallback comparisons
|
|
1515
|
+
// are disabled (2026-09-16, critic finding 4) — without a baseline,
|
|
1516
|
+
// an empty before-list would make every historical audit dir look
|
|
1517
|
+
// "new". No wall-clock in-script (deterministic replay) — the
|
|
1642
1518
|
// comparison is a pure before/after set diff.
|
|
1643
1519
|
var auditDirsBeforeTrigger = [];
|
|
1520
|
+
var auditBeforeOk = false;
|
|
1644
1521
|
try {
|
|
1645
1522
|
var auditBefore = await agent(
|
|
1646
1523
|
"List the artifact audit directories for slug \"" + PUBLISH_SLUG + "\" (best-effort snapshot, never a gate).\n" +
|
|
@@ -1650,242 +1527,342 @@ while (i < STEPS.length) {
|
|
|
1650
1527
|
schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
|
|
1651
1528
|
);
|
|
1652
1529
|
auditDirsBeforeTrigger = String((auditBefore && auditBefore.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
|
|
1530
|
+
auditBeforeOk = true;
|
|
1653
1531
|
log("Publish audit-dir snapshot before trigger for task " + taskId + ": " + auditDirsBeforeTrigger.length + " entries");
|
|
1654
1532
|
} catch (auditBeforeErr) {
|
|
1655
|
-
log("Publish audit-dir snapshot before trigger failed for task " + taskId + " (non-fatal,
|
|
1533
|
+
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));
|
|
1656
1534
|
}
|
|
1535
|
+
// Fire-and-forget trigger + workflow-owned observation (2026-09-16,
|
|
1536
|
+
// clean-room task e2a8d9f8): the trigger's JSON closeout contract
|
|
1537
|
+
// traveled over the stochastic text channel, and the runtime's
|
|
1538
|
+
// JSON-candidate heuristic misfired on it ("workflow agent output
|
|
1539
|
+
// was not JSON: no JSON object or array found in final response"),
|
|
1540
|
+
// parking a task whose edit may have gone through. The contract's
|
|
1541
|
+
// content was already observation-only (the applied report never
|
|
1542
|
+
// gated; the pre_hashes were diagnostic-only), so the contract is
|
|
1543
|
+
// removed: the trigger carries NO schema and its return value is
|
|
1544
|
+
// never consumed, which takes the extraction heuristic out of this
|
|
1545
|
+
// call entirely. The workflow attributes the edit itself through
|
|
1546
|
+
// the tiny schema'd reads below — no prose is parsed for the
|
|
1547
|
+
// trigger outcome.
|
|
1548
|
+
// (Probe, 2026-09-16: the workflow scope exposes only agent() —
|
|
1549
|
+
// tool_search, artifact_edit and artifact_status are undefined
|
|
1550
|
+
// there — so the workflow cannot call the artifact tools directly;
|
|
1551
|
+
// observation still goes through minimal child calls with tiny
|
|
1552
|
+
// schemas, never a broad JSON contract.)
|
|
1553
|
+
//
|
|
1554
|
+
// Pre-trigger toolcheck (tiny, schema'd): the artifact namespace is
|
|
1555
|
+
// deferred for workflow children — the child self-loads it and emits
|
|
1556
|
+
// one exact signal line, read mechanically (never English prose).
|
|
1557
|
+
// Only a parsed ARTIFACT_TOOLS: missing signal is explicit negative
|
|
1558
|
+
// evidence: it gets one bounded retry with a fresh key, then parks
|
|
1559
|
+
// rejected — without the tools the edit provably did NOT go through,
|
|
1560
|
+
// so this is the one safe retry on the publish path. A throw (or an
|
|
1561
|
+
// unparseable signal) is INCONCLUSIVE transport noise, never
|
|
1562
|
+
// evidence of missing tools (2026-09-16, critic finding 3): it is
|
|
1563
|
+
// recorded, it retries once in case the flake clears, but it can
|
|
1564
|
+
// never take the rejected path.
|
|
1565
|
+
var publishToolsOk = false;
|
|
1566
|
+
var publishToolsMissing = false;
|
|
1567
|
+
for (var toolcheckAttempt = 1; toolcheckAttempt <= 2 && !publishToolsOk; toolcheckAttempt++) {
|
|
1568
|
+
try {
|
|
1569
|
+
var toolcheckResult = await agent(
|
|
1570
|
+
"Check whether the artifact tool namespace is available.\n" +
|
|
1571
|
+
"Call tool_search.load_tool_namespace with paths [\"artifact\"].\n" +
|
|
1572
|
+
"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" +
|
|
1573
|
+
"Return JSON { \"signal\": \"<the exact ARTIFACT_TOOLS line>\" } and nothing else.",
|
|
1574
|
+
{ key: attemptKey("publish-artifact-toolcheck-" + taskId + (toolcheckAttempt === 1 ? "" : "-retry2"), reworkCount),
|
|
1575
|
+
label: "Checking artifact tool availability" + (toolcheckAttempt === 1 ? "" : " (retry)"),
|
|
1576
|
+
schema: { type: "object", properties: { signal: { type: "string" } }, required: ["signal"] } }
|
|
1577
|
+
);
|
|
1578
|
+
var toolSignal = String((toolcheckResult && toolcheckResult.signal) || "");
|
|
1579
|
+
if (/ARTIFACT_TOOLS:\s*ok/.test(toolSignal)) {
|
|
1580
|
+
publishToolsOk = true;
|
|
1581
|
+
} else if (/ARTIFACT_TOOLS:\s*missing/.test(toolSignal)) {
|
|
1582
|
+
publishToolsMissing = true;
|
|
1583
|
+
}
|
|
1584
|
+
log("Publish artifact toolcheck for task " + taskId + " (attempt " + toolcheckAttempt + " of 2): " +
|
|
1585
|
+
(publishToolsOk ? "tools ok" : publishToolsMissing ? "tools missing (explicit parsed signal)" : "inconclusive (no ARTIFACT_TOOLS signal parsed)"));
|
|
1586
|
+
} catch (toolcheckErr) {
|
|
1587
|
+
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");
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
if (!publishToolsOk && !publishToolsMissing) {
|
|
1591
|
+
await recordPublishLedger({
|
|
1592
|
+
commit: mergeCommitForPublish,
|
|
1593
|
+
attempt: rebuildAttemptKey,
|
|
1594
|
+
agent_id: null,
|
|
1595
|
+
applied_report: null,
|
|
1596
|
+
outcome: "unknown",
|
|
1597
|
+
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"
|
|
1598
|
+
}, reworkCount);
|
|
1599
|
+
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.");
|
|
1600
|
+
}
|
|
1601
|
+
if (!publishToolsOk) {
|
|
1602
|
+
await recordPublishLedger({
|
|
1603
|
+
commit: mergeCommitForPublish,
|
|
1604
|
+
attempt: rebuildAttemptKey,
|
|
1605
|
+
agent_id: null,
|
|
1606
|
+
applied_report: null,
|
|
1607
|
+
outcome: "rejected",
|
|
1608
|
+
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"
|
|
1609
|
+
}, reworkCount);
|
|
1610
|
+
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.");
|
|
1611
|
+
}
|
|
1612
|
+
// Pre-trigger build-state baseline (tiny, schema'd): one read of
|
|
1613
|
+
// artifact_status. The post-trigger observation diffs against this
|
|
1614
|
+
// baseline — a build whose agent_id was absent from (or differs
|
|
1615
|
+
// from) the baseline is attributed to our edit; a build already in
|
|
1616
|
+
// flight at baseline predates the trigger and is never attributed
|
|
1617
|
+
// to it. If the baseline read itself fails, receipt attribution is
|
|
1618
|
+
// skipped and the durable audit-dir evidence below is the only
|
|
1619
|
+
// positive signal.
|
|
1620
|
+
var baselineAgentId = null;
|
|
1621
|
+
var baselineFailed = false;
|
|
1622
|
+
try {
|
|
1623
|
+
var publishBaseline = await agent(
|
|
1624
|
+
ARTIFACT_LOAD_PREAMBLE +
|
|
1625
|
+
"Call artifact_status with slug \"" + PUBLISH_SLUG + "\" once.\n" +
|
|
1626
|
+
"Return JSON { \"build\": <the raw \"build\" value exactly as returned, or null when there is none> } and nothing else.",
|
|
1627
|
+
{ key: attemptKey("publish-artifact-baseline-" + taskId, reworkCount), label: "Reading pre-trigger build state",
|
|
1628
|
+
schema: { type: "object", properties: { build: { type: ["object", "null"] } }, required: ["build"] } }
|
|
1629
|
+
);
|
|
1630
|
+
baselineAgentId = (publishBaseline && publishBaseline.build && typeof publishBaseline.build.agent_id === "string" && publishBaseline.build.agent_id) || null;
|
|
1631
|
+
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"));
|
|
1632
|
+
} catch (baselineErr) {
|
|
1633
|
+
baselineFailed = true;
|
|
1634
|
+
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");
|
|
1635
|
+
}
|
|
1636
|
+
// The trigger itself: the artifact_edit call is AWAITED (the workflow
|
|
1637
|
+
// waits for it to complete) but its return value is intentionally
|
|
1638
|
+
// UNCONSUMED — NO schema, so no schema validation can fail this
|
|
1639
|
+
// call: a schema-less call resolves to the child's raw response as
|
|
1640
|
+
// a plain string (probed live 2026-09-16 — never parsed, never
|
|
1641
|
+
// throws on content). One caveat, also probed: the runtime still
|
|
1642
|
+
// scans the response for a JSON candidate, and an unparseable
|
|
1643
|
+
// {...}-looking substring in the child's prose throws ("response
|
|
1644
|
+
// JSON candidate", probe P6). The prompt tells the child to end its
|
|
1645
|
+
// turn with no prose at all, which keeps the common case clean —
|
|
1646
|
+
// but the channel is stochastic, so any throw is possible and
|
|
1647
|
+
// inconclusive: the edit may still have gone through, so the
|
|
1648
|
+
// outcome stays unknown until the observation below confirms it —
|
|
1649
|
+
// never inferred from the throw, and never blind-retried (a blind
|
|
1650
|
+
// re-trigger duplicated the edit on 2026-09-12).
|
|
1651
|
+
var rebuildTrigger = null;
|
|
1657
1652
|
try {
|
|
1658
|
-
|
|
1659
|
-
{ key: rebuildAttemptKey, label: "Triggering artifact rebuild"
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1653
|
+
var triggerResultLength = String(await agent(rebuildPrompt,
|
|
1654
|
+
{ key: rebuildAttemptKey, label: "Triggering artifact rebuild" }) || "").length;
|
|
1655
|
+
log("Publish rebuild trigger for task " + taskId + " returned (" + triggerResultLength + " chars; awaited but return intentionally unconsumed)");
|
|
1656
|
+
} catch (triggerErr) {
|
|
1657
|
+
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");
|
|
1658
|
+
}
|
|
1659
|
+
// Post-trigger observation (primary, not fallback): the workflow
|
|
1660
|
+
// attributes the edit itself. First the in-flight build state — a
|
|
1661
|
+
// build whose agent_id is new relative to the pre-trigger baseline
|
|
1662
|
+
// is this edit's receipt. Then the durable audit-dir diff — a
|
|
1663
|
+
// timestamped directory appearing during the trigger window proves
|
|
1664
|
+
// the edit went through and the build completed even when no
|
|
1665
|
+
// in-flight build was ever observed (the 2026-09-14 attempt-7 gap).
|
|
1666
|
+
// Absence of both signals proves nothing: the outcome is UNKNOWN,
|
|
1667
|
+
// never "did not go through". No blind retry — record the attempt
|
|
1668
|
+
// and park fail-closed; correlate via the ledger, never by
|
|
1669
|
+
// re-issuing.
|
|
1670
|
+
log("Publish rebuild trigger issued for task " + taskId + " — observing build state to attribute the edit");
|
|
1671
|
+
var buildState = null;
|
|
1672
|
+
var buildStateFailed = false;
|
|
1673
|
+
try {
|
|
1674
|
+
buildState = await agent(
|
|
1675
|
+
ARTIFACT_LOAD_PREAMBLE +
|
|
1676
|
+
"Call artifact_status with slug \"" + PUBLISH_SLUG + "\".\n" +
|
|
1677
|
+
"Poll up to 3 times, about 20 seconds apart, until the response shows a build (the \"build\" value is an object, not null). " +
|
|
1678
|
+
"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. " +
|
|
1679
|
+
"Do not summarize, interpret, or derive booleans from it. " +
|
|
1680
|
+
"If no build appears after 3 polls, return null. " +
|
|
1681
|
+
"Return JSON { \"build\": <the raw build object or null> } and nothing else.",
|
|
1682
|
+
{ key: attemptKey("publish-artifact-buildcheck-" + taskId, reworkCount), label: "Reading artifact build state after trigger",
|
|
1683
|
+
schema: { type: "object", properties: { build: { type: ["object", "null"] } }, required: ["build"] } }
|
|
1684
|
+
);
|
|
1685
|
+
} catch (buildCheckErr) {
|
|
1686
|
+
buildStateFailed = true;
|
|
1687
|
+
log("Publish post-trigger build-state check failed for task " + taskId + " (" + (buildCheckErr && buildCheckErr.message ? buildCheckErr.message : buildCheckErr) + ") — this signal is unknown, not negative");
|
|
1688
|
+
}
|
|
1689
|
+
var observedAgentId = (buildState && buildState.build && typeof buildState.build.agent_id === "string" && buildState.build.agent_id) || null;
|
|
1690
|
+
// Known limitation (failure-mode audit 2026-09-16): attribution
|
|
1691
|
+
// is timing-based — any agent_id new relative to the baseline is
|
|
1692
|
+
// treated as this edit's receipt. A stranger's build starting inside
|
|
1693
|
+
// the trigger window is indistinguishable by timing and would be
|
|
1694
|
+
// misattributed here. The consequence is bounded: the completion
|
|
1695
|
+
// poll below tracks the recorded id, and the parent's mechanical
|
|
1696
|
+
// content read-back (docs/publish-verification.md) certifies the
|
|
1697
|
+
// exact commit's content — a wrong build's content fails closed as
|
|
1698
|
+
// verification-failed, never stamped. Timing narrows the candidate;
|
|
1699
|
+
// content decides.
|
|
1700
|
+
var receiptAgentId = (!buildStateFailed && !baselineFailed && observedAgentId && observedAgentId !== baselineAgentId) ? observedAgentId : null;
|
|
1701
|
+
if (receiptAgentId) {
|
|
1702
|
+
// The edit went through — a build with a new agent_id appeared
|
|
1703
|
+
// after the trigger. The parent's independent read-back
|
|
1704
|
+
// (docs/publish-verification.md) is the verification, not any
|
|
1705
|
+
// builder report.
|
|
1706
|
+
rebuildTrigger = { edit_started: true };
|
|
1707
|
+
rebuildAgentId = receiptAgentId;
|
|
1708
|
+
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.");
|
|
1709
|
+
await recordPublishLedger({
|
|
1710
|
+
commit: mergeCommitForPublish,
|
|
1711
|
+
attempt: rebuildAttemptKey,
|
|
1712
|
+
agent_id: rebuildAgentId,
|
|
1713
|
+
applied_report: publishAppliedObservation,
|
|
1714
|
+
outcome: "submitted",
|
|
1715
|
+
detail: "fire-and-forget trigger; build receipt captured by workflow-owned build-state observation (pre/post-trigger diff)"
|
|
1716
|
+
}, reworkCount);
|
|
1717
|
+
} else {
|
|
1718
|
+
var newAuditDirs = [];
|
|
1719
|
+
// auditReportOk: pure tri-state read of a report.json body —
|
|
1720
|
+
// true (build ok), false (build failed), null (missing or
|
|
1721
|
+
// unreadable — not evidence either way). The child returns the
|
|
1722
|
+
// raw body verbatim; interpretation lives here, never in prose.
|
|
1723
|
+
// Defined here so both the immediate and post-poll audit
|
|
1724
|
+
// fallbacks share it.
|
|
1725
|
+
var auditReportOk = function (raw) {
|
|
1726
|
+
if (typeof raw !== "string") return null;
|
|
1727
|
+
var trimmed = raw.trim();
|
|
1728
|
+
if (trimmed === "" || trimmed === "MISSING") return null;
|
|
1729
|
+
var parsed;
|
|
1730
|
+
try { parsed = JSON.parse(trimmed); } catch (e) { return null; }
|
|
1731
|
+
if (parsed && typeof parsed.ok === "boolean") return parsed.ok;
|
|
1732
|
+
return null;
|
|
1733
|
+
};
|
|
1734
|
+
// (2026-09-16, critic finding 2) When durable audit evidence
|
|
1735
|
+
// confirms (or refutes) the build, there is no receipt agent_id
|
|
1736
|
+
// to chain the completion poll to — skipReceiptPoll bypasses the
|
|
1737
|
+
// poll below, which with a null receipt could only observe
|
|
1738
|
+
// strangers or nothing.
|
|
1739
|
+
var skipReceiptPoll = false;
|
|
1740
|
+
// publishFailure is declared here (moved up from below) so the
|
|
1741
|
+
// immediate audit fallback can record an explicit build failure
|
|
1742
|
+
// without the later declaration resetting it.
|
|
1743
|
+
var publishFailure = null;
|
|
1684
1744
|
try {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
"
|
|
1688
|
-
"
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
"If no build appears after 3 polls, return null. " +
|
|
1692
|
-
"Return JSON { \"build\": <the raw build object or null> } and nothing else.",
|
|
1693
|
-
{ key: attemptKey("publish-artifact-buildcheck-" + taskId, reworkCount), label: "Reading artifact build state after trigger failure",
|
|
1694
|
-
schema: { type: "object", properties: { build: { type: ["object", "null"] } }, required: ["build"] } }
|
|
1745
|
+
var auditAfter = await agent(
|
|
1746
|
+
"List the artifact audit directories for slug \"" + PUBLISH_SLUG + "\" (best-effort, never a gate).\n" +
|
|
1747
|
+
"Run: ls -1 ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/ 2>/dev/null\n" +
|
|
1748
|
+
"Return JSON { \"dirs\": \"<newline-separated names, empty string when the audits directory does not exist or is empty>\" } and nothing else.",
|
|
1749
|
+
{ key: attemptKey("publish-audit-after-" + taskId, reworkCount), label: "Re-listing audit dirs after trigger",
|
|
1750
|
+
schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
|
|
1695
1751
|
);
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1752
|
+
var auditDirsAfterTrigger = String((auditAfter && auditAfter.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
|
|
1753
|
+
// Only timestamped build dirs count — the "latest" symlink
|
|
1754
|
+
// and anything else are not builds. Gated on auditBeforeOk:
|
|
1755
|
+
// without a baseline every historical dir would look new.
|
|
1756
|
+
newAuditDirs = auditBeforeOk ? auditDirsAfterTrigger.filter(function (d) {
|
|
1757
|
+
return auditDirsBeforeTrigger.indexOf(d) === -1 && /^20\d\d-\d\d-\d\dT\d\d-\d\d-\d\dZ-/.test(d);
|
|
1758
|
+
}) : [];
|
|
1759
|
+
} catch (auditAfterErr) {
|
|
1760
|
+
log("Publish audit-dir re-list after trigger failed for task " + taskId + " (non-fatal, durable-evidence check degraded): " + (auditAfterErr && auditAfterErr.message ? auditAfterErr.message : auditAfterErr));
|
|
1699
1761
|
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
//
|
|
1707
|
-
//
|
|
1708
|
-
//
|
|
1709
|
-
//
|
|
1710
|
-
//
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
rebuildEvidenceNote = "edit confirmed via build-state poll after structured-output failure (build " + acceptedAgentId + "); builder applied-report missing";
|
|
1716
|
-
} else {
|
|
1717
|
-
// Durable completion check (2026-09-14): the in-flight poll
|
|
1718
|
-
// above only sees RUNNING builds. Attempt 7 (2026-09-14) proved
|
|
1719
|
-
// the gap: the trigger child applied the edit, the build ran
|
|
1720
|
-
// and completed — the platform's audit harness captured it
|
|
1721
|
-
// mid-window — then the child failed to return JSON. The
|
|
1722
|
-
// fallback poll saw no in-flight build, so a successful publish
|
|
1723
|
-
// parked as "unknown". Diff the audit-dir listing against the
|
|
1724
|
-
// pre-trigger snapshot: a timestamped directory that appeared
|
|
1725
|
-
// during the trigger window is positive evidence the edit went
|
|
1726
|
-
// through and the build completed. This never re-issues the
|
|
1727
|
-
// edit and never stamps provenance — it only routes to the
|
|
1728
|
-
// parent's independent content read-back, which remains the
|
|
1729
|
-
// real verification.
|
|
1730
|
-
var newAuditDirs = [];
|
|
1762
|
+
if (newAuditDirs.length > 0) {
|
|
1763
|
+
rebuildTrigger = { edit_started: true };
|
|
1764
|
+
rebuildAgentId = null;
|
|
1765
|
+
newAuditDirs.sort();
|
|
1766
|
+
var newestImmediateDir = newAuditDirs[newAuditDirs.length - 1];
|
|
1767
|
+
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.");
|
|
1768
|
+
// (2026-09-16, critic finding 2) Durable audit evidence exists,
|
|
1769
|
+
// but there is no receipt agent_id to chain the completion poll
|
|
1770
|
+
// to — polling with a null receipt can only observe strangers
|
|
1771
|
+
// (any running build differs from "null") or nothing, burning
|
|
1772
|
+
// 10.5 minutes to park unknown. Read the build report now
|
|
1773
|
+
// instead of polling: ok=true confirms completion and routes
|
|
1774
|
+
// directly to parent verification (the poll is skipped);
|
|
1775
|
+
// ok=false is explicit failure; unreadable is unknown.
|
|
1776
|
+
var immediateReportOk = null;
|
|
1731
1777
|
try {
|
|
1732
|
-
var
|
|
1733
|
-
"
|
|
1734
|
-
"Run:
|
|
1735
|
-
"Return JSON { \"
|
|
1736
|
-
{ key: attemptKey("publish-audit-
|
|
1737
|
-
schema: { type: "object", properties: {
|
|
1778
|
+
var immediateOkRead = await agent(
|
|
1779
|
+
"Read the artifact build report for slug \"" + PUBLISH_SLUG + "\".\n" +
|
|
1780
|
+
"Run: cat ~/workspace/ts-spaces/" + PUBLISH_SLUG + "/audits/" + newestImmediateDir + "/report.json 2>/dev/null || echo MISSING\n" +
|
|
1781
|
+
"Return JSON { \"raw\": \"<verbatim file contents, or the literal string MISSING when the file does not exist>\" } and nothing else.",
|
|
1782
|
+
{ key: attemptKey("publish-audit-ok-immediate-" + taskId, reworkCount), label: "Reading build report for audit-confirmed build",
|
|
1783
|
+
schema: { type: "object", properties: { raw: { type: "string" } }, required: ["raw"] } }
|
|
1738
1784
|
);
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
return auditDirsBeforeTrigger.indexOf(d) === -1 && /^20\d\d-\d\d-\d\dT\d\d-\d\d-\d\dZ-/.test(d);
|
|
1744
|
-
});
|
|
1745
|
-
} catch (auditAfterErr) {
|
|
1746
|
-
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));
|
|
1785
|
+
immediateReportOk = auditReportOk(immediateOkRead && immediateOkRead.raw);
|
|
1786
|
+
} catch (immediateOkErr) {
|
|
1787
|
+
log("Publish build-report read for audit-confirmed dir failed for task " + taskId + " (treated as unknown): " + (immediateOkErr && immediateOkErr.message ? immediateOkErr.message : immediateOkErr));
|
|
1788
|
+
immediateReportOk = null;
|
|
1747
1789
|
}
|
|
1748
|
-
if (
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1790
|
+
if (immediateReportOk === true) {
|
|
1791
|
+
publishBuildLanded = true;
|
|
1792
|
+
artifactPublish = { source_commit: mergeCommitForPublish, pending_parent_verification: true };
|
|
1793
|
+
skipReceiptPoll = true;
|
|
1794
|
+
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");
|
|
1795
|
+
await recordPublishLedger({
|
|
1796
|
+
commit: mergeCommitForPublish,
|
|
1797
|
+
attempt: rebuildAttemptKey,
|
|
1798
|
+
agent_id: null,
|
|
1799
|
+
applied_report: publishAppliedObservation,
|
|
1800
|
+
outcome: "submitted",
|
|
1801
|
+
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"
|
|
1802
|
+
}, reworkCount);
|
|
1803
|
+
} else if (immediateReportOk === false) {
|
|
1804
|
+
skipReceiptPoll = true;
|
|
1805
|
+
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.";
|
|
1806
|
+
await recordPublishLedger({
|
|
1807
|
+
commit: mergeCommitForPublish,
|
|
1808
|
+
attempt: rebuildAttemptKey,
|
|
1809
|
+
agent_id: null,
|
|
1810
|
+
applied_report: publishAppliedObservation,
|
|
1811
|
+
outcome: "failed",
|
|
1812
|
+
detail: "a build ran and failed: audit dir " + newestImmediateDir + " report ok=false (immediate audit evidence, no receipt)"
|
|
1813
|
+
}, reworkCount);
|
|
1754
1814
|
} else {
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1815
|
+
await recordPublishLedger({
|
|
1816
|
+
commit: mergeCommitForPublish,
|
|
1817
|
+
attempt: rebuildAttemptKey,
|
|
1818
|
+
agent_id: null,
|
|
1819
|
+
applied_report: null,
|
|
1820
|
+
outcome: "unknown",
|
|
1821
|
+
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"
|
|
1822
|
+
}, reworkCount);
|
|
1823
|
+
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.");
|
|
1824
|
+
}
|
|
1825
|
+
} else {
|
|
1826
|
+
// No attributable build and no durable evidence — but that
|
|
1827
|
+
// proves nothing (a fast-completing build can finish between
|
|
1828
|
+
// polls, or the checks themselves failed). The outcome is
|
|
1829
|
+
// UNKNOWN. No retry: re-issuing the edit here duplicated it on
|
|
1830
|
+
// 2026-09-12. Record the attempt durably and park fail-closed;
|
|
1759
1831
|
// correlate via the ledger, never by guessing from a blind poll.
|
|
1760
|
-
log("Publish rebuild trigger: no build observed
|
|
1832
|
+
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.");
|
|
1761
1833
|
await recordPublishLedger({
|
|
1762
1834
|
commit: mergeCommitForPublish,
|
|
1763
1835
|
attempt: rebuildAttemptKey,
|
|
1764
1836
|
agent_id: null,
|
|
1765
1837
|
applied_report: null,
|
|
1766
1838
|
outcome: "unknown",
|
|
1767
|
-
detail: "
|
|
1839
|
+
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"
|
|
1768
1840
|
}, reworkCount);
|
|
1769
|
-
return await parkTask("Publish outcome unknown: the rebuild trigger
|
|
1770
|
-
}
|
|
1841
|
+
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.");
|
|
1771
1842
|
}
|
|
1772
1843
|
}
|
|
1773
|
-
|
|
1774
|
-
log("Publish rebuild trigger: artifact_tools missing after load — one bounded retry with a fresh key");
|
|
1775
|
-
rebuildTrigger = await agent(rebuildPrompt,
|
|
1776
|
-
{ key: attemptKey("publish-artifact-rebuild-" + taskId + "-retry2", reworkCount), label: "Triggering artifact rebuild (retry)", schema: rebuildSchema });
|
|
1777
|
-
rebuildAttemptKey = attemptKey("publish-artifact-rebuild-" + taskId + "-retry2", reworkCount);
|
|
1778
|
-
}
|
|
1779
|
-
// Receipt chaining (2026-09-13): adopt the trigger's build receipt,
|
|
1780
|
-
// or park on an uncorrelated acceptance. The trigger's closeout schema
|
|
1781
|
-
// requires build_agent_id — the platform build's in-flight correlation
|
|
1782
|
-
// ID captured immediately after the edit was accepted.
|
|
1783
|
-
// An accepted edit (edit_started=true) with a null receipt is UNKNOWN,
|
|
1784
|
-
// not "did not go through": the build may be pending_init-invisible,
|
|
1785
|
-
// may have finished before the capture window, or may be queued behind
|
|
1786
|
-
// a still-running earlier build. No re-trigger is issued on unknown —
|
|
1787
|
-
// a blind re-trigger duplicated the edit on 2026-09-12, and the platform
|
|
1788
|
-
// offers no idempotency proof that would make re-issue safe.
|
|
1789
|
-
// (Retry-semantics reconciliation, 2026-09-13: the "no receipt → safe
|
|
1790
|
-
// re-trigger" sketch assumed the edit command idempotently publishes
|
|
1791
|
-
// what's on git; the duplicate-edit incident disproves the assumption,
|
|
1792
|
-
// and the standing rule retries only on explicit negative evidence.
|
|
1793
|
-
// Re-trigger stays exactly where it was: the edit_started=false
|
|
1794
|
-
// explicit-rejection path above.) Record the attempt and park
|
|
1795
|
-
// fail-closed; correlate via the ledger and the parent's content
|
|
1796
|
-
// read-back before re-driving Publish.
|
|
1797
|
-
if (rebuildTrigger && rebuildTrigger.edit_started && !rebuildReportMissing) {
|
|
1798
|
-
var triggerAgentId = (typeof rebuildTrigger.build_agent_id === "string" && rebuildTrigger.build_agent_id.length > 0) ? rebuildTrigger.build_agent_id : null;
|
|
1799
|
-
if (!triggerAgentId) {
|
|
1800
|
-
var uncorrelatedObservation = (function () { var c = verifyAppliedChanges(expectedChanges, rebuildTrigger.applied); return c.ok ? "match" : "mismatch: " + c.reason; })();
|
|
1801
|
-
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.");
|
|
1802
|
-
await recordPublishLedger({
|
|
1803
|
-
commit: mergeCommitForPublish,
|
|
1804
|
-
attempt: rebuildAttemptKey,
|
|
1805
|
-
agent_id: null,
|
|
1806
|
-
applied_report: uncorrelatedObservation,
|
|
1807
|
-
outcome: "unknown",
|
|
1808
|
-
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."
|
|
1809
|
-
}, reworkCount);
|
|
1810
|
-
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.");
|
|
1811
|
-
}
|
|
1812
|
-
rebuildAgentId = triggerAgentId;
|
|
1813
|
-
log("Publish receipt chained for task " + taskId + ": build " + triggerAgentId + " — the follow-up poll waits on this build only.");
|
|
1814
|
-
}
|
|
1844
|
+
|
|
1815
1845
|
// Durable publish-attempt ledger: record the trigger outcome while the
|
|
1816
1846
|
// attempt key and commit are in scope. Every attempt lands here with
|
|
1817
1847
|
// its outcome — submitted, rejected, or unknown (unknown is recorded
|
|
1818
1848
|
// at the park site above). A later run or human matches commit hash +
|
|
1819
1849
|
// attempt key against the builder's eventual completion.
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
//
|
|
1828
|
-
//
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
agent_id: rebuildAgentId,
|
|
1837
|
-
applied_report: publishAppliedObservation,
|
|
1838
|
-
outcome: "submitted",
|
|
1839
|
-
detail: rebuildReportMissing
|
|
1840
|
-
? (rebuildEvidenceNote || "edit confirmed via build-state poll after structured-output failure (build " + (rebuildAgentId || "agent_id unknown") + "); builder applied-report missing")
|
|
1841
|
-
: "edit accepted; builder applied-report received"
|
|
1842
|
-
}, reworkCount);
|
|
1843
|
-
} else if (rebuildTrigger) {
|
|
1844
|
-
await recordPublishLedger({
|
|
1845
|
-
commit: mergeCommitForPublish,
|
|
1846
|
-
attempt: rebuildAttemptKey,
|
|
1847
|
-
applied_report: null,
|
|
1848
|
-
outcome: "rejected",
|
|
1849
|
-
detail: "edit not accepted: " + (rebuildTrigger.error || "no error detail")
|
|
1850
|
-
}, reworkCount);
|
|
1851
|
-
}
|
|
1852
|
-
var publishFailure = null;
|
|
1853
|
-
if (rebuildTrigger.edit_started) {
|
|
1854
|
-
// STEP 1b (observation only): publishAppliedObservation was
|
|
1855
|
-
// computed and logged above, inside the ledger block — the
|
|
1856
|
-
// builder's applied-report never parks and never blocks the stamp.
|
|
1857
|
-
// Task 23ca8f3f (2026-09-12) proved its false-negative mode:
|
|
1858
|
-
// applied:[] for a diff the builder had actually applied, which
|
|
1859
|
-
// parked a successful publish as unverified. A "match" certifies
|
|
1860
|
-
// nothing either — the report is derived from the carried diff
|
|
1861
|
-
// (canary run 8). The flow proceeds to the build poll and the
|
|
1862
|
-
// independent read-back trigger regardless of what the report
|
|
1863
|
-
// claimed; real verification is the parent's read-back
|
|
1864
|
-
// (docs/publish-verification.md) before the provenance stamp.
|
|
1865
|
-
// Pre-publish base observation (diagnostic, 2026-09-12): compare
|
|
1866
|
-
// the builder's self-reported pre-edit hashes against the
|
|
1867
|
-
// workflow-computed expected base (merge parent). This tells us
|
|
1868
|
-
// what base state the publish actually read. OBSERVATION ONLY —
|
|
1869
|
-
// a mismatch is logged loudly but never parks and never blocks
|
|
1870
|
-
// the stamp. If the tree was dirty or drifted, the evidence is
|
|
1871
|
-
// here; the fix (requiring the right base) comes after we see it.
|
|
1872
|
-
try {
|
|
1873
|
-
var preHashes = (rebuildTrigger && rebuildTrigger.pre_hashes) || {};
|
|
1874
|
-
var baseLines = expectedChanges.map(function(f) {
|
|
1875
|
-
var expected = expectedBaseHashes[f.path];
|
|
1876
|
-
var actual = preHashes[f.path];
|
|
1877
|
-
var expShort = (expected || "UNKNOWN").slice(0, 12);
|
|
1878
|
-
var actShort = String(actual || "NOT-REPORTED").slice(0, 12);
|
|
1879
|
-
var match = (expected !== undefined && actual !== undefined) ? (expected === actual) : "unknown";
|
|
1880
|
-
return " " + f.path + ": expected_base=" + expShort + " builder_pre=" + actShort + " match=" + match;
|
|
1881
|
-
});
|
|
1882
|
-
var anyMismatch = expectedChanges.some(function(f) {
|
|
1883
|
-
return expectedBaseHashes[f.path] !== undefined && preHashes[f.path] !== undefined && expectedBaseHashes[f.path] !== preHashes[f.path];
|
|
1884
|
-
});
|
|
1885
|
-
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"));
|
|
1886
|
-
} catch (e) {
|
|
1887
|
-
log("Publish pre-tree base observation failed for task " + taskId + " (non-fatal): " + (e && e.message ? e.message : e));
|
|
1888
|
-
}
|
|
1850
|
+
// (2026-09-16) The trigger is fire-and-forget: the observation above
|
|
1851
|
+
// already recorded the ledger's submitted line on both positive paths
|
|
1852
|
+
// and parked on unknown — there is no applied report to observe and
|
|
1853
|
+
// no rejection signal to record.
|
|
1854
|
+
// (publishFailure is declared with the immediate audit fallback
|
|
1855
|
+
// above so an explicit build failure there survives to here.)
|
|
1856
|
+
if (rebuildTrigger.edit_started && !skipReceiptPoll) {
|
|
1857
|
+
// (2026-09-16) There is no builder report: the fire-and-forget
|
|
1858
|
+
// trigger carries no JSON contract, so there is nothing to
|
|
1859
|
+
// compare and no pre-hash diagnostic. The builder's old
|
|
1860
|
+
// self-report was circular by construction (canary run 8) with a
|
|
1861
|
+
// demonstrated false-negative mode (task 23ca8f3f, 2026-09-12:
|
|
1862
|
+
// applied:[] for a diff the builder had applied). The flow
|
|
1863
|
+
// proceeds to the build poll regardless; real verification is the
|
|
1864
|
+
// parent's independent read-back (docs/publish-verification.md)
|
|
1865
|
+
// before the provenance stamp.
|
|
1889
1866
|
// STEP 1b (mechanical): bounded poll for build completion, chunked so
|
|
1890
1867
|
// the merge-lock lease is refreshed before it can expire. The 600s
|
|
1891
1868
|
// lease is shorter than the worst-case 10-minute build poll, so the
|
|
@@ -1973,15 +1950,18 @@ while (i < STEPS.length) {
|
|
|
1973
1950
|
if (buildPoll.build_done && pollSawOurBuild) {
|
|
1974
1951
|
// STEP 1c (mechanical): NO provenance stamp here. Canary run 8
|
|
1975
1952
|
// (2026-09-11) proved the stamp cannot certify content: the
|
|
1976
|
-
// builder's applied-report
|
|
1977
|
-
//
|
|
1978
|
-
//
|
|
1953
|
+
// builder's applied-report was derived from the carried diff, so
|
|
1954
|
+
// the old report check was circular — a fabricated report
|
|
1955
|
+
// passed by construction, and every phase went green on a hollow
|
|
1979
1956
|
// build. The stamp moves to the parent (docs/publish-verification.md);
|
|
1980
|
-
// the
|
|
1981
|
-
// agent-callable read-back tool
|
|
1982
|
-
// removed by the platform 2026-09-14
|
|
1983
|
-
//
|
|
1957
|
+
// the deterministic lib/readback-disk.js is the primary sensor
|
|
1958
|
+
// (the agent-callable read-back tool is unavailable —
|
|
1959
|
+
// artifact_inspect was removed by the platform 2026-09-14 — so
|
|
1960
|
+
// the LLM-inspector path is manual-fallback only), and the task
|
|
1961
|
+
// parks for parent verification.
|
|
1984
1962
|
// Chore has no QA: the parent's verification is the final gate.
|
|
1963
|
+
// An unverified publish fails loudly in QA instead of passing
|
|
1964
|
+
// silently here.
|
|
1985
1965
|
publishBuildLanded = true;
|
|
1986
1966
|
artifactPublish = { source_commit: mergeCommitForPublish, pending_parent_verification: true };
|
|
1987
1967
|
log("Publish build landed for task " + taskId + " — provenance stamp deferred to parent content verification");
|
|
@@ -2021,26 +2001,17 @@ while (i < STEPS.length) {
|
|
|
2021
2001
|
schema: { type: "object", properties: { dirs: { type: "string" } }, required: ["dirs"] } }
|
|
2022
2002
|
);
|
|
2023
2003
|
var auditDirsAfterPollList = String((auditAfterPoll && auditAfterPoll.dirs) || "").split("\n").map(function (s) { return s.trim(); }).filter(function (s) { return s.length > 0; });
|
|
2024
|
-
|
|
2004
|
+
// Gated on auditBeforeOk (critic finding 4): without a baseline
|
|
2005
|
+
// every historical dir would look new.
|
|
2006
|
+
newAuditDirsAfterPoll = auditBeforeOk ? auditDirsAfterPollList.filter(function (d) {
|
|
2025
2007
|
return auditDirsBeforeTrigger.indexOf(d) === -1 && /^20\d\d-\d\d-\d\dT\d\d-\d\d-\d\dZ-/.test(d);
|
|
2026
|
-
});
|
|
2008
|
+
}) : [];
|
|
2027
2009
|
log("Publish audit-dir re-list after build poll for task " + taskId + ": " + newAuditDirsAfterPoll.length + " new timestamped dir(s)");
|
|
2028
2010
|
} catch (auditAfterPollErr) {
|
|
2029
2011
|
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));
|
|
2030
2012
|
}
|
|
2031
|
-
//
|
|
2032
|
-
//
|
|
2033
|
-
// unreadable — not evidence either way). The child returns the
|
|
2034
|
-
// raw body verbatim; interpretation lives here, never in prose.
|
|
2035
|
-
var auditReportOk = function (raw) {
|
|
2036
|
-
if (typeof raw !== "string") return null;
|
|
2037
|
-
var trimmed = raw.trim();
|
|
2038
|
-
if (trimmed === "" || trimmed === "MISSING") return null;
|
|
2039
|
-
var parsed;
|
|
2040
|
-
try { parsed = JSON.parse(trimmed); } catch (e) { return null; }
|
|
2041
|
-
if (parsed && typeof parsed.ok === "boolean") return parsed.ok;
|
|
2042
|
-
return null;
|
|
2043
|
-
};
|
|
2013
|
+
// The shared auditReportOk (defined with the immediate fallback
|
|
2014
|
+
// above) interprets the raw body here too.
|
|
2044
2015
|
var auditOkAfterPoll = null;
|
|
2045
2016
|
var newestAuditDirAfterPoll = null;
|
|
2046
2017
|
if (newAuditDirsAfterPoll.length > 0 && !strangerObserved) {
|
|
@@ -2099,7 +2070,9 @@ while (i < STEPS.length) {
|
|
|
2099
2070
|
}
|
|
2100
2071
|
}
|
|
2101
2072
|
} else {
|
|
2102
|
-
|
|
2073
|
+
// Unreachable: the observation above either attributes the edit
|
|
2074
|
+
// (edit_started) or parks. Defensive only — never a silent pass.
|
|
2075
|
+
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.";
|
|
2103
2076
|
}
|
|
2104
2077
|
} // end: publishSkippedNoLock — no rebuild, no stamp, nothing to ship
|
|
2105
2078
|
// STEP 2 (mechanical, always — skip path included): post-deploy
|