@nanobpm/nano-workforce 0.206.4 → 0.207.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.207.0](https://github.com/nanobpm/nano-workforce/compare/v0.206.4...v0.207.0) (2026-11-09)
2
+
3
+ ### Features
4
+
5
+ * **status:** surface engine incidents on loop and delivery rows with a retry action ([#938](https://github.com/nanobpm/nano-workforce/issues/938)) ([e3955c8](https://github.com/nanobpm/nano-workforce/commit/e3955c8145a966a29806400872b7a9c362d1d992)), closes [#931](https://github.com/nanobpm/nano-workforce/issues/931) [#931](https://github.com/nanobpm/nano-workforce/issues/931)
6
+
1
7
  ## [0.206.4](https://github.com/nanobpm/nano-workforce/compare/v0.206.3...v0.206.4) (2026-11-09)
2
8
 
3
9
  ### Bug Fixes
@@ -39,7 +39,7 @@ import { applyMigrationSet, readMigrationSetFromDisk } from "../test/migrations.
39
39
  const MIG = (name: string) => readFileSync(fileURLToPath(new URL(`../db/migrations/${name}`, import.meta.url)), "utf8");
40
40
  const PAGE = (name: string) => JSON.parse(readFileSync(fileURLToPath(new URL(`../pages/${name}`, import.meta.url)), "utf8"));
41
41
 
42
- const READ_MODEL_MIGRATION = "121_delivery_graph_read_model_auto_resolve.sql";
42
+ const READ_MODEL_MIGRATION = "129_delivery_graph_read_model_incidents.sql";
43
43
 
44
44
  // A minimal in-memory DB carrying the base `delivery_graph_runs` / `pull_requests` shapes the VIEW
45
45
  // reads, plus stand-ins for the managed `<table>__tracking` derived VIEWs urban provisions at mount
@@ -53,7 +53,9 @@ function viewDb(): DatabaseSync {
53
53
  run_key TEXT PRIMARY KEY, process_key TEXT, process_definition_id TEXT, digest TEXT,
54
54
  status TEXT, side_effecting INTEGER, node_count INTEGER, human_node_count INTEGER,
55
55
  side_effect_count INTEGER, title TEXT, phase TEXT, phase_node_id TEXT, human_labels TEXT,
56
- created_at TEXT, updated_at TEXT, acknowledged_at TEXT, auto_resolve_escalations INTEGER, derived_status_override TEXT);
56
+ created_at TEXT, updated_at TEXT, acknowledged_at TEXT, auto_resolve_escalations INTEGER,
57
+ incident_key TEXT, incident_type TEXT, incident_message TEXT, incident_since TEXT,
58
+ derived_status_override TEXT);
57
59
  CREATE TABLE pull_requests (pr_key TEXT PRIMARY KEY, root_request_key TEXT, status TEXT,
58
60
  derived_status_override TEXT);`,
59
61
  );
@@ -56,6 +56,14 @@ export interface DeliveryGraphRun {
56
56
  /** Opt-in escalation steward (120_escalation_auto_resolutions.sql, issue #889): 1 ⇒ this run's
57
57
  * escalations are eligible for steward auto-resolution. Default 0. */
58
58
  auto_resolve_escalations: number;
59
+ /** Technical-incident mirror (127_delivery_graph_run_incidents.sql, issue #931), written by the
60
+ * poller's `pollIncidents` pass — the delivery-side twin of the PR incident columns (017/126).
61
+ * All NULL when the run's instance has no active incident; `/status` derives the `incident`
62
+ * overlay from these columns (see `activeDeliveries` in app/service.ts). */
63
+ incident_key: string | null;
64
+ incident_type: string | null;
65
+ incident_message: string | null;
66
+ incident_since: string | null;
59
67
  }
60
68
 
61
69
  /** The run lifecycle. `awaiting-approval` is RESERVED but no longer produced (issue #460 moved dispatch
@@ -530,5 +538,9 @@ export function buildDeliveryGraphRunRow(input: {
530
538
  created_at: input.createdAt ?? at,
531
539
  updated_at: at,
532
540
  acknowledged_at: null,
541
+ incident_key: null,
542
+ incident_type: null,
543
+ incident_message: null,
544
+ incident_since: null,
533
545
  };
534
546
  }
@@ -0,0 +1,175 @@
1
+ // Red/green for issue #931 — an engine incident parked on a convergence loop's job must be VISIBLE
2
+ // on the `/status` row, not hide behind a healthy-looking `status: "converging"`.
3
+ //
4
+ // The defect (observed on merlin, 2026-11-09): a loop whose `senior:pr-review` job exhausted its
5
+ // retries (`JOB_NO_RETRIES`, the agent idle-timeout) sat dead for hours while `/status` reported
6
+ // `status: "converging"`, `openEscalation: null`, `activeWorker: null` — indistinguishable from a
7
+ // healthy queued run. `pollIncidents` mirrored the incident onto `incident_key`/`incident_message`
8
+ // (issue #94), but the `/status` projection never READ those columns, so the only discovery path
9
+ // was a hand-run `POST /v2/incidents/search`.
10
+ //
11
+ // The fix surfaces the mirrored incident on every ActivePr/ActiveDelivery row:
12
+ // status — overlaid to "incident" while the row carries an ACTIVE incident (the base
13
+ // `pull_requests.status` workflow transient is untouched; the overlay is derived at
14
+ // read time so it can never wedge the status machine), and
15
+ // incident — { key, type, message, since }: the engine incidentKey, errorType, errorMessage and
16
+ // creationTime the poller mirrored, so an operator sees WHAT broke and WHEN without
17
+ // opening the engine.
18
+ import { test } from "node:test";
19
+ import { assertEquals } from "#test-assert";
20
+ import { withTrackingViews } from "../test/trackingViews.ts";
21
+ import { activeDeliveries, activePrs } from "./service.ts";
22
+
23
+ function memTable(rows: any[], key: string) {
24
+ return {
25
+ get: (k: any) => Promise.resolve(rows.find((r) => r[key] === k) ?? null),
26
+ all: () => Promise.resolve([...rows]),
27
+ find: (q: any) =>
28
+ Promise.resolve(rows.filter((r) => Object.entries(q).every(([f, v]) => r[f] === v))),
29
+ findOne: (q: any) =>
30
+ Promise.resolve(rows.find((r) => Object.entries(q).every(([f, v]) => r[f] === v)) ?? null),
31
+ insert: (r: any) => {
32
+ rows.push(r);
33
+ return Promise.resolve(r);
34
+ },
35
+ update: (k: any, patch: any) => {
36
+ const r = rows.find((x) => x[key] === k);
37
+ if (r) Object.assign(r, patch);
38
+ return Promise.resolve(r);
39
+ },
40
+ delete: (k: any) => {
41
+ for (let i = rows.length - 1; i >= 0; i--) if (rows[i][key] === k) rows.splice(i, 1);
42
+ return Promise.resolve();
43
+ },
44
+ };
45
+ }
46
+
47
+ type Stores = Record<string, { rows: any[]; key: string }>;
48
+
49
+ function memData(stores: Stores) {
50
+ return {
51
+ table: withTrackingViews((name: string, key: string) => memTable(stores[name]?.rows ?? [], stores[name]?.key ?? key)),
52
+ } as any;
53
+ }
54
+
55
+ /** A fake engine whose `searchVariables` serves the given per-instance variables (none here — the
56
+ * merge policy degrades to its historical default, which these tests do not exercise). */
57
+ function fakeEngine() {
58
+ return {
59
+ searchVariables: () => Promise.resolve([]),
60
+ } as any;
61
+ }
62
+
63
+ function prRow(over: Record<string, unknown>) {
64
+ return {
65
+ pr_key: "owner/repo#1",
66
+ repo: "owner/repo",
67
+ number: 1,
68
+ url: "https://github.com/owner/repo/pull/1",
69
+ title: "t",
70
+ status: "converging",
71
+ current_round: 1,
72
+ process_key: "PI-1",
73
+ updated_at: "2024-01-01",
74
+ ...over,
75
+ };
76
+ }
77
+
78
+ async function statusOf(rowOver: Record<string, unknown> = {}) {
79
+ const stores: Stores = {
80
+ pull_requests: { rows: [prRow(rowOver)], key: "pr_key" },
81
+ user_tasks: { rows: [], key: "id" },
82
+ };
83
+ const [pr] = await activePrs(memData(stores), fakeEngine());
84
+ return pr;
85
+ }
86
+
87
+ test("incident surfacing: a PR row carrying an ACTIVE incident reads status 'incident', not 'converging' (the #931 defect)", async () => {
88
+ const pr = await statusOf({
89
+ incident_key: "598235",
90
+ incident_type: "JOB_NO_RETRIES",
91
+ incident_message: 'agent "nano-coder" failed: no output and no subtree progress for >= 300000ms (idle)',
92
+ incident_since: "2026-11-09T01:00:00.000Z",
93
+ });
94
+ assertEquals(pr.status, "incident");
95
+ assertEquals(pr.incident, {
96
+ key: "598235",
97
+ type: "JOB_NO_RETRIES",
98
+ message: 'agent "nano-coder" failed: no output and no subtree progress for >= 300000ms (idle)',
99
+ since: "2026-11-09T01:00:00.000Z",
100
+ });
101
+ });
102
+
103
+ test("incident surfacing: a healthy PR row keeps its workflow status and a null incident", async () => {
104
+ const pr = await statusOf({
105
+ incident_key: null,
106
+ incident_type: null,
107
+ incident_message: null,
108
+ incident_since: null,
109
+ });
110
+ assertEquals(pr.status, "converging");
111
+ assertEquals(pr.incident, null);
112
+ });
113
+
114
+ test("incident surfacing: the overlay applies to any live workflow status (e.g. waiting_merge), never just converging", async () => {
115
+ const pr = await statusOf({
116
+ status: "waiting_merge",
117
+ incident_key: "INC-9",
118
+ incident_type: "EXTRACT_VALUE_ERROR",
119
+ incident_message: "failed to evaluate expression",
120
+ incident_since: "2026-11-09T02:00:00.000Z",
121
+ });
122
+ assertEquals(pr.status, "incident");
123
+ assertEquals(pr.incident?.key, "INC-9");
124
+ });
125
+
126
+ test("incident surfacing: a delivery run carrying an ACTIVE incident reads status 'incident' with the incident block", async () => {
127
+ const run = {
128
+ run_key: "dg-1",
129
+ title: "ship it",
130
+ status: "running",
131
+ phase: "Running",
132
+ process_key: "PI-DG-1",
133
+ updated_at: "2024-01-01",
134
+ auto_resolve_escalations: 0,
135
+ incident_key: "INC-DG-1",
136
+ incident_type: "JOB_NO_RETRIES",
137
+ incident_message: "delivery node job exhausted retries",
138
+ incident_since: "2026-11-09T03:00:00.000Z",
139
+ };
140
+ const stores: Stores = {
141
+ delivery_graph_runs: { rows: [run], key: "run_key" },
142
+ user_tasks: { rows: [], key: "id" },
143
+ };
144
+ const [delivery] = await activeDeliveries(memData(stores));
145
+ assertEquals(delivery.status, "incident");
146
+ assertEquals(delivery.incident, {
147
+ key: "INC-DG-1",
148
+ type: "JOB_NO_RETRIES",
149
+ message: "delivery node job exhausted retries",
150
+ since: "2026-11-09T03:00:00.000Z",
151
+ });
152
+ });
153
+
154
+ test("incident surfacing: a healthy delivery run keeps its status and a null incident", async () => {
155
+ const run = {
156
+ run_key: "dg-2",
157
+ title: "ship it",
158
+ status: "running",
159
+ phase: "Running",
160
+ process_key: "PI-DG-2",
161
+ updated_at: "2024-01-01",
162
+ auto_resolve_escalations: 0,
163
+ incident_key: null,
164
+ incident_type: null,
165
+ incident_message: null,
166
+ incident_since: null,
167
+ };
168
+ const stores: Stores = {
169
+ delivery_graph_runs: { rows: [run], key: "run_key" },
170
+ user_tasks: { rows: [], key: "id" },
171
+ };
172
+ const [delivery] = await activeDeliveries(memData(stores));
173
+ assertEquals(delivery.status, "running");
174
+ assertEquals(delivery.incident, null);
175
+ });
@@ -31,9 +31,10 @@ function projectedOperations() {
31
31
  }
32
32
 
33
33
  // The operator-only cockpit doors: the staged delivery-graph lifecycle (stage -> dispatch ->
34
- // dismiss) whose approval is a human click in the cockpit (ADR 0005 Decision 7). These — and ONLY
35
- // these — must be excluded from the projected MCP tool surface.
36
- const EXPECTED_EXCLUDED = ["stageDeliveryGraph", "dispatchDeliveryGraph", "dismissProposal"];
34
+ // dismiss) whose approval is a human click in the cockpit (ADR 0005 Decision 7), plus the
35
+ // incident-retry remediation door (issue #931) — the human unstick action on an incident-parked
36
+ // run. These — and ONLY these — must be excluded from the projected MCP tool surface.
37
+ const EXPECTED_EXCLUDED = ["stageDeliveryGraph", "dispatchDeliveryGraph", "dismissProposal", "retryIncident"];
37
38
 
38
39
  // A representative set of agent-facing operations that MUST stay exposed as tools — the drive doors
39
40
  // (submit PR / epic / delivery-graph set), the pure compile/preview doors, and the read/orientation
@@ -87,8 +87,12 @@ export const FRAMEWORK_TOOL_PREFIX = "urban_debug_";
87
87
  * regression guard, not the reduction itself: the reduction an agent actually experiences comes from
88
88
  * importing {@link CURATED_MCP_TOOLS} rather than `["*"]`, and the transport-level shrink of the
89
89
  * framework tool family is tracked upstream (nano-ide#488).
90
+ *
91
+ * RAISE PROVENANCE — 60 → 61 (#931): the read-only `listIncidents` door (sibling of
92
+ * `listEscalations`) stays on the surface per the `x-mcp` convention that read/orient doors are
93
+ * exposed; its operator-only remedy `retryIncident` is excluded. Deliberate, documented growth.
90
94
  */
91
- export const MCP_TOOL_COUNT_BUDGET = 60;
95
+ export const MCP_TOOL_COUNT_BUDGET = 61;
92
96
 
93
97
  /**
94
98
  * Hard CEILING on the serialized byte size of the full `tools/list` payload (the schema bytes a
@@ -138,8 +142,13 @@ export const MCP_TOOL_COUNT_BUDGET = 60;
138
142
  * intended description text (a correctness fix, not new surface). Measured 90,420 bytes serialized
139
143
  * (over the old ceiling's 920-byte headroom). Deliberate, documented growth of restored description
140
144
  * text — not schema fat.
145
+ *
146
+ * RAISE PROVENANCE — 91_000 → 92_000 (#931): the read-only `listIncidents` tool (engine-incident
147
+ * liveness sibling of `listEscalations`) plus the `incident` field on the status row schemas.
148
+ * Measured 91,069 bytes serialized (over the old ceiling's headroom). Deliberate, documented growth
149
+ * of a real new read surface — not schema fat.
141
150
  */
142
- export const MCP_SURFACE_BYTES_BUDGET = 91_000;
151
+ export const MCP_SURFACE_BYTES_BUDGET = 92_000;
143
152
 
144
153
  /**
145
154
  * The eagerly-loaded curated subset MUST stay materially smaller than the full surface — otherwise it
@@ -33,7 +33,7 @@ import {
33
33
  const MIG = (name: string) => readFileSync(fileURLToPath(new URL(`../db/migrations/${name}`, import.meta.url)), "utf8");
34
34
  const PAGE = (name: string) => JSON.parse(readFileSync(fileURLToPath(new URL(`../pages/${name}`, import.meta.url)), "utf8"));
35
35
 
36
- const READ_MODEL_MIGRATION = "122_pull_requests_read_model_auto_resolve.sql";
36
+ const READ_MODEL_MIGRATION = "128_pull_requests_read_model_incidents.sql";
37
37
 
38
38
  // The real base `pull_requests` columns, in schema order — DERIVED from the migration chain (not a
39
39
  // hand-kept list that could silently omit one), used by both the drift guard and the e2e stand-in.
@@ -675,6 +675,123 @@ test("pollIncidents picks the oldest incident by creationTime, sorting a missing
675
675
  assertEquals(row.incident_message, "the first fault");
676
676
  });
677
677
 
678
+ // Issue #931: the mirror must carry the incident's `errorType` and `creationTime` (not just key +
679
+ // message) so `/status` can show WHAT broke and SINCE WHEN, and it must cover a delivery-graph
680
+ // run's instance too — a delivery parked on an engine incident was just as invisible as a PR.
681
+ test("pollIncidents mirrors errorType + creationTime alongside the key/message, and clears them with the incident", async () => {
682
+ const row = {
683
+ pr_key: "owner/repo#12",
684
+ status: "converging",
685
+ process_key: "PI-12",
686
+ incident_key: null as string | null,
687
+ incident_type: null as string | null,
688
+ incident_message: null as string | null,
689
+ incident_since: null as string | null,
690
+ updated_at: "t0",
691
+ };
692
+ const stores: Record<string, { rows: unknown[]; key: string }> = {
693
+ pull_requests: { rows: [row], key: "pr_key" },
694
+ };
695
+ const data = {
696
+ table: withTrackingViews((name: string, key: string) => memTable(stores[name]?.rows ?? [], stores[name]?.key ?? key)),
697
+ open: () => memOpen(stores),
698
+ } as any;
699
+ const headers = { "content-type": "application/json" };
700
+
701
+ const prevFetch = globalThis.fetch;
702
+ globalThis.fetch = incidentFetch({
703
+ "PI-12": [{
704
+ incidentKey: "598235",
705
+ errorType: "JOB_NO_RETRIES",
706
+ errorMessage: 'agent "nano-coder" failed: no output and no subtree progress for >= 300000ms (idle)',
707
+ state: "ACTIVE",
708
+ creationTime: "2026-11-09T01:00:00.000Z",
709
+ }],
710
+ }) as typeof fetch;
711
+ try {
712
+ await pollIncidentsImpl(data, "http://engine/v2", headers);
713
+ } finally {
714
+ globalThis.fetch = prevFetch;
715
+ }
716
+ assertEquals(row.incident_key, "598235");
717
+ assertEquals(row.incident_type, "JOB_NO_RETRIES");
718
+ assertEquals(row.incident_message, 'agent "nano-coder" failed: no output and no subtree progress for >= 300000ms (idle)');
719
+ assertEquals(row.incident_since, "2026-11-09T01:00:00.000Z");
720
+ assertEquals(row.status, "converging"); // orthogonal: the workflow transient is never touched
721
+
722
+ // Once resolved, ALL FOUR columns clear idempotently — a stale `incident_since` must not linger.
723
+ globalThis.fetch = incidentFetch({ "PI-12": [] }) as typeof fetch;
724
+ try {
725
+ await pollIncidentsImpl(data, "http://engine/v2", headers);
726
+ } finally {
727
+ globalThis.fetch = prevFetch;
728
+ }
729
+ assertEquals(row.incident_key, null);
730
+ assertEquals(row.incident_type, null);
731
+ assertEquals(row.incident_message, null);
732
+ assertEquals(row.incident_since, null);
733
+ });
734
+
735
+ test("pollIncidents mirrors an ACTIVE incident onto a delivery-graph run row, and skips a terminal run", async () => {
736
+ const running = {
737
+ run_key: "dg-1",
738
+ status: "running",
739
+ process_key: "PI-DG-1",
740
+ incident_key: null as string | null,
741
+ incident_type: null as string | null,
742
+ incident_message: null as string | null,
743
+ incident_since: null as string | null,
744
+ updated_at: "t0",
745
+ };
746
+ const done = {
747
+ run_key: "dg-2",
748
+ status: "done",
749
+ process_key: "PI-DG-2",
750
+ incident_key: "STALE-DG",
751
+ incident_type: "JOB_NO_RETRIES",
752
+ incident_message: "left over",
753
+ incident_since: "2026-11-08T00:00:00.000Z",
754
+ updated_at: "t0",
755
+ };
756
+ const stores: Record<string, { rows: unknown[]; key: string }> = {
757
+ delivery_graph_runs: { rows: [running, done], key: "run_key" },
758
+ };
759
+ const data = {
760
+ table: withTrackingViews((name: string, key: string) => memTable(stores[name]?.rows ?? [], stores[name]?.key ?? key)),
761
+ open: () => memOpen(stores),
762
+ } as any;
763
+ const headers = { "content-type": "application/json" };
764
+
765
+ const prevFetch = globalThis.fetch;
766
+ globalThis.fetch = incidentFetch({
767
+ "PI-DG-1": [{
768
+ incidentKey: "INC-DG-1",
769
+ errorType: "JOB_NO_RETRIES",
770
+ errorMessage: "delivery node job exhausted retries",
771
+ state: "ACTIVE",
772
+ creationTime: "2026-11-09T03:00:00.000Z",
773
+ }],
774
+ // A terminal run's instance is gone — the pass must never query it (the stub would serve an
775
+ // incident, so a query would wrongly overwrite the clearing below).
776
+ "PI-DG-2": [{ incidentKey: "INC-DG-2", errorMessage: "ghost", state: "ACTIVE", creationTime: "2026-11-09T04:00:00.000Z" }],
777
+ }) as typeof fetch;
778
+ try {
779
+ await pollIncidentsImpl(data, "http://engine/v2", headers);
780
+ } finally {
781
+ globalThis.fetch = prevFetch;
782
+ }
783
+ assertEquals(running.incident_key, "INC-DG-1");
784
+ assertEquals(running.incident_type, "JOB_NO_RETRIES");
785
+ assertEquals(running.incident_message, "delivery node job exhausted retries");
786
+ assertEquals(running.incident_since, "2026-11-09T03:00:00.000Z");
787
+ assertEquals(running.status, "running"); // orthogonal: status untouched
788
+ // Terminal run: the stale incident is cleared without ever consulting the engine.
789
+ assertEquals(done.incident_key, null);
790
+ assertEquals(done.incident_type, null);
791
+ assertEquals(done.incident_message, null);
792
+ assertEquals(done.incident_since, null);
793
+ });
794
+
678
795
 
679
796
  // Red/green regression (nano-workforce#845 Copilot review): the convergence loop runs TWO external
680
797
  // agent task types while the PR reads `converging` — `review-round` (`senior:pr-review`) and, since