@rightkit/release 0.6.47 → 0.6.49

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.
@@ -470,7 +470,21 @@ export const PINNED_SCAN_TOOLS = Object.freeze({ shellcheck: "0.11.0", oxlint: "
470
470
  * and a red caused by one is never deterministic. Ids are `<prefix>` or `<prefix>:<root>`; rustright's REMOTE_SCANS mirrors this list. */
471
471
  export const LIVE_SCAN_IDS = Object.freeze(["pnpm-audit", "ghsa-audit"]);
472
472
  /** Internal rules whose verdict is a function of the files they read and the rule code only (GC-A24): reused by input key. */
473
- export const CACHEABLE_INTERNAL = new Set(["secret-scan", "json-parse", "toml-parse", "yaml-parse", "license", "changelog-version", "ownership-catalog", "swift-lock", "gradle-lock", "python-lock"]);
473
+ // ghsa-audit and advisory-exceptions are keyed by lock, files and UTC day (GATE-CONTRACT GC-A24 table, GC-A19 keys), so only a same-day pass is reused.
474
+ export const CACHEABLE_INTERNAL = new Set(["ghsa-audit", "advisory-exceptions", "feature-coverage", "secret-scan", "json-parse", "toml-parse", "yaml-parse", "license", "changelog-version", "ownership-catalog", "swift-lock", "gradle-lock", "python-lock"]);
475
+ /** NN41: internal rules whose failure is never reused: their answer depends on the UTC day or a remote service, not only on their inputs. */
476
+ export const FAILURE_UNCACHEABLE_INTERNAL = new Set(["ghsa-audit", "advisory-exceptions"]);
477
+ /** NN41: the key namespace of a cached failure, so a failure never shares a key with a pass of the same scan. */
478
+ export const FAILURE_KEY_SCHEMA = "deterministic-failure/1";
479
+ /** NN41: the compile scans whose failure can be deterministic: check, clippy and doc rows (single or batched, native or cross). Test runs are never among them. */
480
+ export const isFailureCacheableCompileId = (id) => /^(?:check|check-features|check-dependent|clippy|doc)(?::|$)/.test(String(id));
481
+ /** NN41: a plain (non-broker) compile exit whose output carries compiler error diagnostics and no sign of the environment failing (network, disk, signal, internal compiler error). */
482
+ export function isDeterministicCompileDiagnostics(text) {
483
+ const t = String(text ?? "");
484
+ const diagnostics = /(?:^|\n)\s*error(?:\[[A-Za-z]\d+\])?: /.test(t) || /could not compile|aborting due to/.test(t);
485
+ const environmental = /failed to (?:download|fetch|get|update|load source|create|write|open|remove)|network|spurious|timed out|No space left|Too many open files|Permission denied|Resource temporarily|Text file busy|internal compiler error|panicked at|signal: |SIGKILL|SIGSEGV|Killed/i.test(t);
486
+ return diagnostics && !environmental;
487
+ }
474
488
  export const isLiveScan = (id) => LIVE_SCAN_IDS.some((p) => id === p || String(id).startsWith(`${p}:`));
475
489
  /** Scans whose FAILURE may come from the registry rather than their inputs: `pnpm-lockfile` (`install --frozen-lockfile --lockfile-only`)
476
490
  * re-verifies lockfile entries against the registry when pnpm's cache is cold, so an outage fails it. Their pass is deterministic, but a
@@ -1460,10 +1474,12 @@ export function planScans({
1460
1474
  add({ id, class: B, batchUnit: name, ...scan, env: { ...(scan.env ?? {}), ...crossEnv } });
1461
1475
  });
1462
1476
  }
1463
- // rustdoc flags go after `--` for this crate's library only: the broker owns RUSTDOCFLAGS and refuses
1464
- // a request that sets it. A crate with no library has no API docs to check.
1477
+ // NN40 (GC-A27): docs build as one command per workspace and configuration. The row is the doc subcommand with --no-deps, --lib, one `-p <crate>`,
1478
+ // the lint set and --locked, with a batchUnit, so class B batching groups the doc rows of one workspace and configuration into one invocation
1479
+ // naming every crate. The request never sets RUSTDOCFLAGS: the broker sets "-D warnings" itself on doc and refuses any other value.
1480
+ // A crate with no library has no API docs to check.
1465
1481
  if (exists(path.join(contentRoot, rustDir(name), "src", "lib.rs"))) {
1466
- add({ id: rustScanId.doc(name), class: B, ...cargoIn(ws, "rustdoc", "-p", crate, "--lib", ...lintSets[0], "--locked", "--", ...DOC_RUSTDOC_ARGS) });
1482
+ add({ id: rustScanId.doc(name), class: B, batchUnit: name, ...cargoIn(ws, "doc", "--no-deps", "--lib", "-p", crate, ...lintSets[0], "--locked") });
1467
1483
  }
1468
1484
  }
1469
1485
  // Class A, file-only (rightkit#1231): no feature of a crate's Cargo.toml may be left out of every planned feature set, so feature-gated code is never
@@ -2008,6 +2024,46 @@ export function parseTestListing(text) {
2008
2024
  return out;
2009
2025
  }
2010
2026
 
2027
+ /** What a cargo `--message-format=json` stream says per package (NN40): the error diagnostics and whether a build artifact was reported. `{ records, errors: {name: {count, rendered[]}}, artifacts: {name: count} }`. */
2028
+ export function summarizeCargoJson(text) {
2029
+ const out = { records: 0, errors: {}, artifacts: {} };
2030
+ for (const raw of String(text ?? "").split(/\r?\n/)) {
2031
+ const line = raw.trimStart();
2032
+ if (!line.startsWith("{")) continue;
2033
+ let v; try { v = JSON.parse(line); } catch { continue; }
2034
+ if (!v || typeof v.reason !== "string") continue;
2035
+ out.records += 1;
2036
+ const name = packageOfId(v.package_id).name;
2037
+ if (!name) continue;
2038
+ if (v.reason === "compiler-message") {
2039
+ const level = String(v.message?.level ?? "");
2040
+ if (level !== "error" && !level.startsWith("error: internal")) continue;
2041
+ const e = (out.errors[name] ??= { count: 0, rendered: [] });
2042
+ e.count += 1;
2043
+ if (e.rendered.length < 4 && typeof v.message?.rendered === "string") e.rendered.push(v.message.rendered.trimEnd().slice(0, 700));
2044
+ } else if (v.reason === "compiler-artifact") {
2045
+ if ((Array.isArray(v.target?.kind) ? v.target.kind : []).includes("custom-build")) continue;
2046
+ out.artifacts[name] = (out.artifacts[name] ?? 0) + 1;
2047
+ }
2048
+ }
2049
+ return out;
2050
+ }
2051
+
2052
+ /**
2053
+ * The per-crate verdicts of a failed grouped doc invocation, from its JSON summary: `[{ unit, fail, detail }]` in member order, or null when the messages
2054
+ * cannot attribute (no records, or no member reported an artifact, so "no artifact" would prove nothing): the caller then bisects as for any grouped failure.
2055
+ */
2056
+ export function docVerdicts(summary, units, crates) {
2057
+ if (!summary || !(summary.records > 0) || !Array.isArray(units) || units.length !== crates.length) return null;
2058
+ if (!crates.some((c) => summary.artifacts?.[c] > 0)) return null;
2059
+ return units.map((unit, k) => {
2060
+ const err = summary.errors?.[crates[k]];
2061
+ if (err?.count) return { unit, fail: true, detail: `${err.count} error(s) in ${crates[k]}: ${err.rendered.join(" | ")}` };
2062
+ if (!(summary.artifacts?.[crates[k]] > 0)) return { unit, fail: true, detail: `no documentation artifact for ${crates[k]}: it did not build (a dependency or build script failed before it; see the invocation's output)` };
2063
+ return { unit, fail: false, detail: "" };
2064
+ });
2065
+ }
2066
+
2011
2067
  /** The text a failed compile leaves for a reader: the rendered error diagnostics of the JSON listing plus every non-JSON line (a broker refusal). */
2012
2068
  export function listingFailureText(text, limit = 8000) {
2013
2069
  const out = [];
@@ -2912,7 +2968,7 @@ export async function runScans(plan, options = {}) {
2912
2968
  const groupOf = new Map();
2913
2969
  if (options.classBBatching === true) {
2914
2970
  const byKey = new Map();
2915
- bScans.forEach((s, i) => { if (s.batchable && !s.deferred && laneOf(s) === "compile") { if (!byKey.has(s.batchable.key)) byKey.set(s.batchable.key, []); byKey.get(s.batchable.key).push(i); } });
2971
+ bScans.forEach((s, i) => { if (s.batchable && !s.deferred && (laneOf(s) === "compile" || laneOf(s) === "doc")) { if (!byKey.has(s.batchable.key)) byKey.set(s.batchable.key, []); byKey.get(s.batchable.key).push(i); } });
2916
2972
  for (const members of byKey.values()) if (members.length > 1) { const group = { members, promise: null }; for (const i of members) groupOf.set(i, group); }
2917
2973
  }
2918
2974
  const batchScanOf = (idx) => {
@@ -2920,7 +2976,10 @@ export async function runScans(plan, options = {}) {
2920
2976
  const { batchable: _batchable, ...plain } = lead; void _batchable;
2921
2977
  const args = [...lead.args.slice(0, lead.batchable.at), ...idx.flatMap((i) => ["-p", bScans[i].batchable.crate]), ...lead.args.slice(lead.batchable.at + 2)];
2922
2978
  const units = idx.map((i) => bScans[i].batchable.unit);
2923
- const id = `${/^clippy/.test(lead.id) ? "clippy" : "check"}:batch:${sha256(`${lead.batchable.key}\0${units.join("\0")}`).slice(0, 8)}`;
2979
+ const stage = /^clippy/.test(lead.id) ? "clippy" : /^doc:/.test(lead.id) ? "doc" : "check";
2980
+ const id = `${stage}:batch:${sha256(`${lead.batchable.key}\0${units.join("\0")}`).slice(0, 8)}`;
2981
+ // A doc group asks for cargo's JSON messages (NN40): each crate's verdict is read from them (docVerdicts), never found by bisection.
2982
+ if (stage === "doc") { const jargs = [...args, "--message-format=json"]; return { ...plain, id, args: jargs, captureJson: true, command: commandText({ ...plain, env: {}, args: jargs }), batch: { units, members: idx.map((i) => bScans[i].id) } }; }
2924
2983
  return { ...plain, id, args, command: commandText({ ...plain, env: {}, args }), batch: { units, members: idx.map((i) => bScans[i].id) } };
2925
2984
  };
2926
2985
  const runGroup = async (idx, extraEnv, budget = { remaining: Math.min(2 * idx.length - 1, 31) }) => {
@@ -2934,7 +2993,21 @@ export async function runScans(plan, options = {}) {
2934
2993
  const bs = batchScanOf(idx);
2935
2994
  let row;
2936
2995
  try { row = await scanRow(bs, extraEnv); } catch (error) { row = { id: bs.id, status: "fail", code: "SCAN_ERROR", detail: String(error?.message ?? error) }; }
2937
- const attributable = (row.code === "EXIT" && !row.snapshotEvidence) || (row.code === "BROKER_COMPILE_FAILURE" && row.authenticatedFailure?.retryable === true && row.authenticatedFailure?.failureClass === "compile" && row.snapshotEvidence?.receiptSha256);
2996
+ // A failure reused from the result cache (NN41) was authenticated or diagnosed when it was written, so it attributes the same way.
2997
+ const attributable = (row.code === "EXIT" && !row.snapshotEvidence) || (row.code === "BROKER_COMPILE_FAILURE" && row.authenticatedFailure?.retryable === true && row.authenticatedFailure?.failureClass === "compile" && row.snapshotEvidence?.receiptSha256) || (row.failureCached === true && (row.code === "EXIT" || row.code === "BROKER_COMPILE_FAILURE"));
2998
+ // NN40: a failed doc invocation is attributed from its own JSON messages: a crate with an error message fails, a crate with no artifact while
2999
+ // another member has one fails, the rest pass. Without usable messages (none, or no artifact for any member) it falls back to bisection below.
3000
+ const verdicts = row.status === "fail" && attributable && bs.captureJson ? docVerdicts(row.jsonSummary, bs.batch.units, idx.map((i) => bScans[i].batchable.crate)) : null;
3001
+ if (verdicts && !signal?.aborted) {
3002
+ batchFailureNotes.push(`class B batching: grouped doc invocation ${bs.id} (${idx.length} crates: ${bs.batch.units.join(", ")}) failed (EXIT) and was attributed per crate from its --message-format=json output, not bisected; failing: ${verdicts.filter((v) => v.fail).map((v) => v.unit).join(", ") || "none named"}`);
3003
+ idx.forEach((i, k) => {
3004
+ const m = bScans[i]; const v = verdicts[k];
3005
+ const own = { id: m.id, class: m.class, command: m.command, batchCommand: row.command, tool: m.tool ?? null, toolVersion: row.toolVersion ?? null, status: v.fail ? "fail" : "pass", ...(v.fail ? { code: "EXIT", detail: `${row.id} (${idx.length} crates: ${bs.batch.units.join(", ")}): ${v.detail}` } : {}), ...(row.cached ? { cached: true } : {}), timing: row.timing ?? null, batchedWith: { id: row.id, units: bs.batch.units }, batchFailure: { id: bs.id, units: bs.batch.units, command: row.command, ...(row.authenticatedFailure ? { authenticatedFailure: row.authenticatedFailure } : {}), ...(row.snapshotEvidence ? { snapshotEvidence: row.snapshotEvidence } : {}), detail: "the grouped doc invocation failed; this row's verdict is its own, read from the invocation's JSON messages" }, ...(row.identities ? { identities: row.identities } : {}) };
3006
+ slots[i] = own; done += 1;
3007
+ try { onResult(own, { done, total, seconds: Math.round((Date.now() - started) / 1000) }); } catch { /* reporting never fails a scan */ }
3008
+ });
3009
+ return;
3010
+ }
2938
3011
  if (row.status === "fail" && attributable && !signal?.aborted) {
2939
3012
  // Bisect for attribution, but keep the grouped failure itself as evidence (rightkit#1458, reconciled scope
2940
3013
  // 2026-11-04): the splits below prove each member's own required scan; they do not erase that the combined
@@ -3096,17 +3169,28 @@ export async function runScans(plan, options = {}) {
3096
3169
  try {
3097
3170
  // GC-A24: a deterministic internal rule (its verdict a function of the files it reads and the rule code) is reused by its input key,
3098
3171
  // with the rule code's identity (CHECKER_IDENTITY) as its tool version. Network and advice rules are never reused this way.
3099
- let internalKey = null;
3172
+ let internalKey = null; let internalFailKey = null;
3100
3173
  if (s.internal && cache && CACHEABLE_INTERNAL.has(s.internal) && typeof CHECKER_IDENTITY === "string") {
3101
3174
  try {
3102
3175
  const digest = cache.digest(s, {});
3103
- if (digest) internalKey = scanCacheKey({ id: s.id, command: s.command ?? `internal:${s.internal}`, toolVersion: CHECKER_IDENTITY, env: {}, inheritedEnv: inheritedEnvDigest({}), digest });
3104
- } catch (error) { internalKey = null; row.cacheKeyError = String(error?.message ?? error).slice(0, 300); }
3176
+ if (digest) {
3177
+ internalKey = scanCacheKey({ id: s.id, command: s.command ?? `internal:${s.internal}`, toolVersion: CHECKER_IDENTITY, env: {}, inheritedEnv: inheritedEnvDigest({}), digest });
3178
+ // NN41: a file-only rule's violation list is a function of the same inputs, so it is keyed like its pass plus the rule code (CHECKER_IDENTITY);
3179
+ // a rule whose answer depends on the day or a remote service (FAILURE_UNCACHEABLE_INTERNAL) never has its failure reused.
3180
+ if (!FAILURE_UNCACHEABLE_INTERNAL.has(s.internal)) internalFailKey = scanCacheKey({ id: s.id, command: `${s.command ?? `internal:${s.internal}`} ;; ${FAILURE_KEY_SCHEMA}`, toolVersion: CHECKER_IDENTITY, env: {}, inheritedEnv: inheritedEnvDigest({}), digest });
3181
+ }
3182
+ } catch (error) { internalKey = null; internalFailKey = null; row.cacheKeyError = String(error?.message ?? error).slice(0, 300); }
3105
3183
  const hit = internalKey ? cache.read(internalKey) : null;
3106
3184
  if (hit && hit.key === internalKey && hit.row?.status === "pass" && hit.row.id === s.id) {
3107
3185
  cacheHits.push(s.id);
3108
3186
  return { ...row, status: "pass", cached: true, detail: `cached ${String(hit.at ?? "").slice(0, 10) || "earlier"}` };
3109
3187
  }
3188
+ const failHit = internalFailKey ? cache.read(internalFailKey) : null;
3189
+ if (failHit && failHit.key === internalFailKey && failHit.row?.status === "fail" && failHit.row.id === s.id && typeof failHit.row.detail === "string" && failHit.row.detail !== "") {
3190
+ cacheHits.push(s.id);
3191
+ if (s.class === SCAN_CLASS.A) classAFailed = true;
3192
+ return { ...row, status: "fail", cached: true, failureCached: true, detail: failHit.row.detail };
3193
+ }
3110
3194
  }
3111
3195
  if (s.internal) {
3112
3196
  const out = await INTERNAL[s.internal](s, ctx);
@@ -3115,6 +3199,8 @@ export async function runScans(plan, options = {}) {
3115
3199
  else if (out && !Array.isArray(out) && typeof out.advice === "string") { advice = out.advice; }
3116
3200
  else if (out.length) { status = "fail"; detail = out.join("; "); }
3117
3201
  if (status === "pass" && internalKey && !advice && !signal?.aborted) cache.write(internalKey, { id: s.id, class: s.class, command: s.command ?? `internal:${s.internal}`, tool: null, toolVersion: CHECKER_IDENTITY, status: "pass" });
3202
+ // NN41: only a violation list (the rule ran and named what is wrong) is a deterministic failure; a missing tool or a coded refusal is the environment's.
3203
+ else if (status === "fail" && !code && internalFailKey && Array.isArray(out) && out.length && !signal?.aborted) cache.write(internalFailKey, { id: s.id, class: s.class, command: s.command ?? `internal:${s.internal}`, tool: null, toolVersion: CHECKER_IDENTITY, status: "fail", detail });
3118
3204
  } else {
3119
3205
  const scanDir = path.join(rootDir(s.root), s.cwd ?? "");
3120
3206
  // The RustRight client's version probe starts in a Cargo workspace of the primary checkout; a class A cargo scan's own directory is
@@ -3149,7 +3235,7 @@ export async function runScans(plan, options = {}) {
3149
3235
  else if (missingDep) { status = "fail"; code = "TOOL_MISSING"; detail = `${s.tool} needs ${missingDep}, which is missing or not runnable; without it the scan would pass unchecked, so it fails`; }
3150
3236
  else if (depVersionProblem) { status = "fail"; code = "TOOL_VERSION"; detail = `TOOL_VERSION: ${s.tool} runs ${depVersionProblem}`; }
3151
3237
  else {
3152
- let cacheKey = null;
3238
+ let cacheKey = null; let failKey = null; let ledgerProblem = false;
3153
3239
  // GATE-CONTRACT GC-T14: every unchanged scan result is reused by its full input key, a broker-carried compile included (measured
3154
3240
  // 2026-11-02: HR class B re-ran 92 broker jobs, most with no dirty unit, because carried compiles were never cached). The key covers the
3155
3241
  // crate's closure, its lock entries, the toolchain files, the tool version and the build environment; a miss runs the compile and
@@ -3171,7 +3257,13 @@ export async function runScans(plan, options = {}) {
3171
3257
  // The narrow node-check digest already binds the complete actual
3172
3258
  // child environment (with its one explicit ownership exception).
3173
3259
  const inherited = cache.narrowNodeCheck && /^node-check:/.test(s.id) ? sha256('node-check-child-env-in-digest/1') : inheritedEnvDigest({ ...deps.env, ...s.env });
3174
- if (digest) cacheKey = scanCacheKey({ id: s.id, command: s.runOutside ? `${s.command} ;; run ${canonicalJson(s.runOutside)}` : s.command, toolVersion, env: s.env ?? {}, inheritedEnv: inherited, digest });
3260
+ if (digest) {
3261
+ cacheKey = scanCacheKey({ id: s.id, command: s.runOutside ? `${s.command} ;; run ${canonicalJson(s.runOutside)}` : s.command, toolVersion, env: s.env ?? {}, inheritedEnv: inherited, digest });
3262
+ // NN41: a deterministic compile failure is keyed like the pass plus the tool version (the client's, its identity digest), the installed broker runtime
3263
+ // identity (options.failureIdentity: version, clientDigest, brokerDigest) and the failure namespace; the digest already binds the unit closure, lock entries and toolchain files.
3264
+ // No identity from the caller means no failure is ever stored or reused.
3265
+ if (typeof options.failureIdentity === "string" && options.failureIdentity !== "" && isFailureCacheableCompileId(s.id) && !s.runOutside && s.kind !== "test" && !s.publisherRustTest && (s.tool === "rustright" || s.tool === "cargo")) failKey = scanCacheKey({ id: s.id, command: `${s.command} ;; ${FAILURE_KEY_SCHEMA}`, toolVersion: `${toolVersion} ;; broker-runtime ${options.failureIdentity}`, env: s.env ?? {}, inheritedEnv: inherited, digest });
3266
+ }
3175
3267
  } catch (error) { cacheKey = null; row.cacheKeyError = String(error?.message ?? error).slice(0, 300); }
3176
3268
  const hit = cacheKey ? cache.read(cacheKey) : null;
3177
3269
  timing.cacheLookupMs = performance.now() - cacheStarted;
@@ -3183,6 +3275,12 @@ export async function runScans(plan, options = {}) {
3183
3275
  cacheHits.push(s.id);
3184
3276
  return { ...row, status: "pass", cached: true, detail: `cached ${String(hit.at ?? "").slice(0, 10) || "earlier"}`, ...(s.kind === "test" ? { results: hit.row.results } : {}) };
3185
3277
  }
3278
+ // NN41: the same inputs, toolchain and broker runtime already failed this compile deterministically: report that failure, marked cached, without running it.
3279
+ const failHit = failKey ? cache.read(failKey) : null;
3280
+ if (failHit && failHit.key === failKey && failHit.row?.status === "fail" && failHit.row.id === s.id && failHit.row.command === s.command && failHit.row.failureIdentity === options.failureIdentity && (failHit.row.code === "EXIT" || failHit.row.code === "BROKER_COMPILE_FAILURE") && typeof failHit.row.detail === "string" && failHit.row.detail !== "") {
3281
+ cacheHits.push(s.id);
3282
+ return { ...row, status: "fail", code: failHit.row.code, cached: true, failureCached: true, detail: `cached failure ${String(failHit.at ?? "").slice(0, 10) || "earlier"} (same inputs, toolchain and broker runtime): ${failHit.row.detail}`, ...(failHit.row.authenticatedFailure ? { authenticatedFailure: failHit.row.authenticatedFailure } : {}), ...(failHit.row.jsonSummary ? { jsonSummary: failHit.row.jsonSummary } : {}) };
3283
+ }
3186
3284
  }
3187
3285
  // Every cargo call the wrapper decides during this scan is filed under this token in the gate's ledger: the scan's own call AND the
3188
3286
  // calls the scan itself makes before it (the cargo-deny row's prefetch and its full metadata), so none is filed "unscoped" and fails the run.
@@ -3318,7 +3416,7 @@ export async function runScans(plan, options = {}) {
3318
3416
  // A Rust test scan's JSON listing (every compiler-artifact record) streams whole to a file of its own: the kept tail of a spawn would lose the early artifact records of a noisy compile.
3319
3417
  let listingDir = null; let listingFile = null; let listingText = ""; let listingCut = false;
3320
3418
  let testOutputs = null;
3321
- if (s.runOutside) { listingDir = fs.mkdtempSync(path.join(tmpRoot, "rk-testlist-")); listingFile = path.join(listingDir, "listing.jsonl"); }
3419
+ if (s.runOutside || s.captureJson) { listingDir =fs.mkdtempSync(path.join(tmpRoot, "rk-testlist-")); listingFile = path.join(listingDir, "listing.jsonl"); }
3322
3420
  try {
3323
3421
  // The ownership records this request's sub-handle immediately before it is sent (the reclaim proof reads broker.submitted): a
3324
3422
  // missing hook or a mark that did not land sends nothing.
@@ -3373,11 +3471,13 @@ export async function runScans(plan, options = {}) {
3373
3471
  admission.start();
3374
3472
  }
3375
3473
  try { r = await deps.spawn(p.command, spawnArgs, { cwd: path.join(rootDir(s.root), s.cwd ?? ""), env: { ...deps.env, ...sentinelEnv, ...readTargetEnv, ...s.env, ...(extraEnv ?? {}), ...guardEnv, ...ledgerEnv, ...(carrier ? carrier.made.env : {}), ...refEnv, ...(carriedScan && !watched ? scanOperationEnv({ ...deps.env, ...s.env }, limitMs) : {}), ...trustEnv }, signal: scanSignal, ...(listingFile ? { stdoutFile: listingFile } : {}), ...(watched ? {} : { timeout: limitMs }) }); } finally { stopClock(); advisory?.cleanup?.(); }
3376
- if (s.runOutside && r && !r.error) {
3474
+ if ((s.runOutside || s.captureJson) && r && !r.error) {
3377
3475
  // The whole listing: the file the spawn streamed, else (a spawn that does not know stdoutFile) its stdout. What a reader sees of a failed compile is the rendered errors.
3378
3476
  let fromFile = false;
3379
3477
  try { if (fs.existsSync(listingFile) && fs.statSync(listingFile).size > 0) { listingText = fs.readFileSync(listingFile, "utf8"); fromFile = true; } } catch { /* falls back to stdout */ }
3380
3478
  if (!fromFile) { listingText = String(r.stdout ?? ""); listingCut = r.truncated === true; }
3479
+ // A grouped doc invocation's per-crate verdicts come from this stream (NN40); a cut stream proves nothing per crate, so it is not summarized.
3480
+ if (s.captureJson && !listingCut) row.jsonSummary = summarizeCargoJson(listingText);
3381
3481
  r = { ...r, stdout: listingFailureText(listingText) };
3382
3482
  }
3383
3483
  }
@@ -3406,6 +3506,7 @@ export async function runScans(plan, options = {}) {
3406
3506
  problems = [...ledger.problems, ...(deps.snapshotBroker ? await verifyBrokerLedger(ledger.entries, deps.snapshotBroker, { seen: ledgerSeen }) : [])];
3407
3507
  } catch (e) { problems = [`the cargo ledger cannot be read (${e.message})`]; }
3408
3508
  if (problems.length) {
3509
+ ledgerProblem = true;
3409
3510
  const text = `${s.id}: the gate's cargo ledger records ${problems.length} cargo call(s) that did not complete as a verified success: ${problems.slice(0, 5).join("; ")}`;
3410
3511
  if (status === "pass") { status = "fail"; code = "RK_CARGO_LEDGER"; detail = text; } else detail = `${detail ? `${detail}; ` : ""}${text}`;
3411
3512
  }
@@ -3518,6 +3619,11 @@ export async function runScans(plan, options = {}) {
3518
3619
  const problem = status === "pass" && row.results ? testResultsProblem(row.results) : null;
3519
3620
  if (problem) { status = "fail"; code = problem.code; detail = problem.detail; }
3520
3621
  }
3622
+ // NN41: store a deterministic compile failure only: the broker's authenticated compile failure, or a plain exit of a compile with compiler error diagnostics and no sign of
3623
+ // the environment failing. Never a timeout, abort, SCAN_ERROR, refusal, unverified receipt, ledger problem, test run or infrastructure error (those return or carry another code).
3624
+ if (status === "fail" && failKey && !signal?.aborted && !ledgerProblem && typeof detail === "string" && detail !== "" && ((code === "BROKER_COMPILE_FAILURE" && row.authenticatedFailure?.failureClass === "compile") || (code === "EXIT" && !carriedScan && !carrier && isDeterministicCompileDiagnostics(`${r?.stdout ?? ""}\n${r?.stderr ?? ""}`)))) {
3625
+ cache.write(failKey, { id: s.id, class: s.class, command: s.command, tool: s.tool ?? null, toolVersion: row.toolVersion, status: "fail", code, detail: detail.slice(0, 6000), failureIdentity: options.failureIdentity, ...(row.authenticatedFailure ? { authenticatedFailure: row.authenticatedFailure } : {}), ...(row.jsonSummary ? { jsonSummary: row.jsonSummary } : {}) });
3626
+ }
3521
3627
  if (status === "pass" && cacheKey && !signal?.aborted) cache.write(cacheKey, { id: s.id, class: s.class, command: s.command, tool: s.tool ?? null, toolVersion: row.toolVersion, status: "pass", ...(row.results ? { results: row.results } : {}) });
3522
3628
  }
3523
3629
  }