@nanobpm/nano-workforce 0.82.0 → 0.82.1

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,10 @@
1
+ ## [0.82.1](https://github.com/nanobpm/nano-workforce/compare/v0.82.0...v0.82.1) (2026-08-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **plan-fanout:** make the wave-merge barrier level-triggered ([#262](https://github.com/nanobpm/nano-workforce/issues/262)) ([#264](https://github.com/nanobpm/nano-workforce/issues/264)) ([ae939d8](https://github.com/nanobpm/nano-workforce/commit/ae939d8e96f136f820fcae9149c120806ddc6f1b))
7
+
1
8
  # [0.82.0](https://github.com/nanobpm/nano-workforce/compare/v0.81.0...v0.82.0) (2026-08-17)
2
9
 
3
10
 
package/SPEC.md CHANGED
@@ -565,11 +565,14 @@ the loop runs one parallel `implement` MI fan-out per wave:
565
565
  `dependsOn`), and advances `currentWave`.
566
566
  - **Wave-merge barrier** (`wait-wave-merged`): when a wave has a successor,
567
567
  `record-wave` sets `plans.gate_wave` to that wave's index and the process parks at
568
- the `wait-wave-merged` catch event. The poller's `pollWaveGates` pass publishes the
569
- `wave-merged` message (correlated on `planKey`) once **every opened PR in that wave
570
- has merged** (`app/waves.ts` `waveMergeTargets` selects the PRs to wait on;
571
- `blocked`/`skipped`/keyless tasks clear vacuously), then clears `gate_wave`
572
- single-shot. So a `dependsOn` means the dependent wave is not **implemented** until
568
+ the `wait-wave-merged` catch event. The poller's `pollWaveGatesImpl` pass is
569
+ **level-triggered**: it publishes the `wave-merged` message (correlated on `planKey`)
570
+ once **every opened PR in that wave has merged** (`app/waves.ts` `waveMergeTargets`
571
+ selects the PRs to wait on; `blocked`/`skipped`/keyless tasks clear vacuously) **and**
572
+ it observes an OPEN `wait-wave-merged` subscription for the plan so a merge that
573
+ lands while the token is still upstream can't drop the signal. The poller **never**
574
+ clears `gate_wave`; `record-wave` owns the marker's lifecycle (re-arming it to the next
575
+ wave, or clearing it to NULL on the final wave). So a `dependsOn` means the dependent wave is not **implemented** until
573
576
  its prerequisites have **landed on the base branch** — not merely opened. This lets
574
577
  a blocking prerequisite (e.g. app scaffolding) fully converge and merge before the
575
578
  next wave builds on it. `gate_wave` lives in `db/migrations/007_wave_gate.sql`.
@@ -7,7 +7,7 @@
7
7
  // GitHub transport forced off so it is hermetic.
8
8
  import { test } from "node:test";
9
9
  import { assertEquals } from "#test-assert";
10
- import { parsePr, pollIncidentsImpl, repoEnvelopeVars, startMerge, submitPr } from "./service.ts";
10
+ import { parsePr, pollIncidentsImpl, pollWaveGatesImpl, repoEnvelopeVars, startMerge, submitPr } from "./service.ts";
11
11
 
12
12
  function memTable(rows: any[], key: string) {
13
13
  return {
@@ -502,3 +502,190 @@ test("parsePr still resolves a well-formed prKey and PR URL", () => {
502
502
  assertEquals(parsePr(" owner/repo#42 ")?.number, 42);
503
503
  assertEquals(parsePr("https://github.com/owner/repo/pull/7")?.repo, "owner/repo");
504
504
  });
505
+
506
+ // Red/green regression for the level-triggered wave-merge barrier (issue #262). The barrier is
507
+ // armed (`plans.gate_wave = W`) at wave handoff, long BEFORE the token traverses the slow
508
+ // `trial-merge` agent job and finally opens the `wait-wave-merged` subscription. The old
509
+ // `pollWaveGates` was edge-triggered: the first pass that saw wave W's PRs merged cleared
510
+ // `gate_wave` and published `wave-merged` EXACTLY ONCE. If that happened while the token was still
511
+ // upstream (no open subscription), the message was dropped and — with `gate_wave` now null — never
512
+ // republished, so the epic wedged forever once the token arrived. The fix reconciles the merged
513
+ // state against the engine's OPEN-subscription state every pass, publishing only into an open
514
+ // subscription and never clearing `gate_wave` optimistically.
515
+ //
516
+ // Stubs `/message-subscriptions/search` (keyed by processInstanceKey) so the subscription can be
517
+ // toggled open between passes, and forces the GitHub transport off — the wave's PRs are tracked
518
+ // `merged` rows, so `isDepMerged` resolves them from the DB with no network.
519
+ function subscriptionFetch(open: Set<string>) {
520
+ return (url: string | URL | Request, init?: RequestInit): Promise<Response> => {
521
+ const u = typeof url === "string" ? url : url.toString();
522
+ if (!u.endsWith("/message-subscriptions/search")) {
523
+ throw new Error(`unexpected fetch: ${u}`);
524
+ }
525
+ const body = JSON.parse(String(init?.body ?? "{}")) as {
526
+ filter?: { processInstanceKey?: string };
527
+ };
528
+ const pik = body.filter?.processInstanceKey ?? "";
529
+ const items = open.has(pik)
530
+ ? [{ messageName: "wave-merged", correlationKey: "owner/repo#67", messageSubscriptionState: "CREATED" }]
531
+ : [];
532
+ return Promise.resolve(
533
+ new Response(JSON.stringify({ items }), { status: 200, headers: { "content-type": "application/json" } }),
534
+ );
535
+ };
536
+ }
537
+
538
+ test("pollWaveGatesImpl is level-triggered: PRs merged before the token arrives never lose the wave-merged signal (#262)", async () => {
539
+ await withGithubOff(async () => {
540
+ const PLAN_KEY = "owner/repo#67";
541
+ const PI = "PI-13794";
542
+ // Wave 1 opened two PRs; both are already MERGED (tracked rows → isDepMerged resolves from DB).
543
+ const plan = {
544
+ plan_key: PLAN_KEY,
545
+ process_key: PI,
546
+ gate_wave: 1 as number | null,
547
+ updated_at: "t0",
548
+ };
549
+ const stores: Record<string, { rows: unknown[]; key: string }> = {
550
+ plans: { rows: [plan], key: "plan_key" },
551
+ plan_tasks: {
552
+ rows: [
553
+ { id: "owner/repo#67:a", plan_key: PLAN_KEY, wave: 1, status: "opened", pr_key: "owner/repo#68" },
554
+ { id: "owner/repo#67:b", plan_key: PLAN_KEY, wave: 1, status: "opened", pr_key: "owner/repo#69" },
555
+ ],
556
+ key: "id",
557
+ },
558
+ pull_requests: {
559
+ rows: [
560
+ { pr_key: "owner/repo#68", status: "merged" },
561
+ { pr_key: "owner/repo#69", status: "merged" },
562
+ ],
563
+ key: "pr_key",
564
+ },
565
+ };
566
+ const data = {
567
+ table: (name: string, key: string) => memTable(stores[name]?.rows ?? [], stores[name]?.key ?? key),
568
+ } as any;
569
+
570
+ const published: { name: string; correlationKey?: string }[] = [];
571
+ const engine = {
572
+ publishMessage: (input: { name: string; correlationKey?: string }) => {
573
+ published.push(input);
574
+ return Promise.resolve();
575
+ },
576
+ } as any;
577
+ const headers = { "content-type": "application/json" };
578
+
579
+ const openSubs = new Set<string>(); // token still upstream of wait-wave-merged → NO open subscription
580
+ const prevFetch = globalThis.fetch;
581
+
582
+ // Pass 1 — the losing ordering: wave 1's PRs are all merged, but the token is parked upstream on
583
+ // the slow `trial-merge` job, so there is no open `wait-wave-merged` subscription yet. The old
584
+ // single-shot barrier would publish-into-the-void and CLEAR `gate_wave`, stranding the epic.
585
+ globalThis.fetch = subscriptionFetch(openSubs) as typeof fetch;
586
+ try {
587
+ await pollWaveGatesImpl(data, engine, "", "http://engine/v2", headers);
588
+ } finally {
589
+ globalThis.fetch = prevFetch;
590
+ }
591
+ // The signal must NOT have been fired into the void, and the gate must remain armed (not stranded).
592
+ assertEquals(published.length, 0, "must not publish wave-merged with no open subscription");
593
+ assertEquals(plan.gate_wave, 1, "gate_wave must stay armed until the barrier is actually released");
594
+
595
+ // Pass 2 — the token has now advanced to `wait-wave-merged`, opening the subscription. The
596
+ // level-triggered barrier re-publishes and correlates, releasing the token into wave 2.
597
+ openSubs.add(PI);
598
+ globalThis.fetch = subscriptionFetch(openSubs) as typeof fetch;
599
+ try {
600
+ await pollWaveGatesImpl(data, engine, "", "http://engine/v2", headers);
601
+ } finally {
602
+ globalThis.fetch = prevFetch;
603
+ }
604
+ assertEquals(published.length, 1, "must publish wave-merged once the subscription is open");
605
+ assertEquals(published[0]?.name, "wave-merged");
606
+ assertEquals(published[0]?.correlationKey, PLAN_KEY);
607
+ });
608
+ });
609
+
610
+ // Guards the false-positive failure class flagged in review: `waveMergedSubscriptionOpen` must treat
611
+ // a search item with a missing/null/mismatched `messageName`, `correlationKey`, or
612
+ // `messageSubscriptionState` as NOT-open. Defaulting an unverifiable field to its expected value
613
+ // would publish `wave-merged` into a subscription we never confirmed open — buffering a message that
614
+ // trips a LATER wave's barrier, i.e. re-introducing the exact #262 wedge this change prevents. A
615
+ // false negative only costs a retry next pass; a false positive is a wedge, so unknown ⇒ don't match.
616
+ function ambiguousSubscriptionFetch(items: unknown[]) {
617
+ return (url: string | URL | Request, _init?: RequestInit): Promise<Response> => {
618
+ const u = typeof url === "string" ? url : url.toString();
619
+ if (!u.endsWith("/message-subscriptions/search")) {
620
+ throw new Error(`unexpected fetch: ${u}`);
621
+ }
622
+ return Promise.resolve(
623
+ new Response(JSON.stringify({ items }), { status: 200, headers: { "content-type": "application/json" } }),
624
+ );
625
+ };
626
+ }
627
+
628
+ test("pollWaveGatesImpl never releases the barrier on an unverifiable subscription item (missing/null/mismatched fields)", async () => {
629
+ await withGithubOff(async () => {
630
+ const PLAN_KEY = "owner/repo#67";
631
+ const PI = "PI-13794";
632
+ const plan = {
633
+ plan_key: PLAN_KEY,
634
+ process_key: PI,
635
+ gate_wave: 1 as number | null,
636
+ updated_at: "t0",
637
+ };
638
+ const stores: Record<string, { rows: unknown[]; key: string }> = {
639
+ plans: { rows: [plan], key: "plan_key" },
640
+ plan_tasks: {
641
+ rows: [
642
+ { id: "owner/repo#67:a", plan_key: PLAN_KEY, wave: 1, status: "opened", pr_key: "owner/repo#68" },
643
+ { id: "owner/repo#67:b", plan_key: PLAN_KEY, wave: 1, status: "opened", pr_key: "owner/repo#69" },
644
+ ],
645
+ key: "id",
646
+ },
647
+ pull_requests: {
648
+ rows: [
649
+ { pr_key: "owner/repo#68", status: "merged" },
650
+ { pr_key: "owner/repo#69", status: "merged" },
651
+ ],
652
+ key: "pr_key",
653
+ },
654
+ };
655
+ const data = {
656
+ table: (name: string, key: string) => memTable(stores[name]?.rows ?? [], stores[name]?.key ?? key),
657
+ } as any;
658
+
659
+ const published: { name: string; correlationKey?: string }[] = [];
660
+ const engine = {
661
+ publishMessage: (input: { name: string; correlationKey?: string }) => {
662
+ published.push(input);
663
+ return Promise.resolve();
664
+ },
665
+ } as any;
666
+ const headers = { "content-type": "application/json" };
667
+ const prevFetch = globalThis.fetch;
668
+
669
+ // Each of these items is ambiguous — it omits or mismatches a field the barrier requires. None
670
+ // may be treated as an OPEN subscription for THIS plan, so none may release wave 1's gate.
671
+ const ambiguousItems: unknown[][] = [
672
+ [{}], // empty item — no fields at all
673
+ [{ messageName: "wave-merged", correlationKey: PLAN_KEY }], // missing state
674
+ [{ messageName: "wave-merged", correlationKey: PLAN_KEY, messageSubscriptionState: null }], // null state
675
+ [{ correlationKey: PLAN_KEY, messageSubscriptionState: "CREATED" }], // missing messageName
676
+ [{ messageName: "some-other-message", correlationKey: PLAN_KEY, messageSubscriptionState: "CREATED" }],
677
+ [{ messageName: "wave-merged", messageSubscriptionState: "CREATED" }], // missing correlationKey
678
+ [{ messageName: "wave-merged", correlationKey: "owner/repo#999", messageSubscriptionState: "CREATED" }],
679
+ ];
680
+ for (const items of ambiguousItems) {
681
+ globalThis.fetch = ambiguousSubscriptionFetch(items) as typeof fetch;
682
+ try {
683
+ await pollWaveGatesImpl(data, engine, "", "http://engine/v2", headers);
684
+ } finally {
685
+ globalThis.fetch = prevFetch;
686
+ }
687
+ }
688
+ assertEquals(published.length, 0, "must not publish wave-merged on an unverifiable subscription item");
689
+ assertEquals(plan.gate_wave, 1, "gate_wave must stay armed while no OPEN subscription is confirmed");
690
+ });
691
+ });
package/app/service.ts CHANGED
@@ -1141,17 +1141,104 @@ export async function pollIncidentsImpl(
1141
1141
  }
1142
1142
  }
1143
1143
 
1144
- /** Wave-merge barrier poll pass. After `record-wave` hands off a wave that has a successor, the
1145
- * plan-fanout instance parks at the `wait-wave-merged` catch event and `plans.gate_wave` records
1146
- * that wave's index. Here we check whether every OPENED PR in that wave has MERGED and, if so,
1147
- * publish `wave-merged` (correlated on the plan key) to release the next wave's implementation.
1144
+ /** The `wave-merged` message name (`resources/processes/plan-fanout.bpmn`): the `wait-wave-merged`
1145
+ * catch event opens a subscription for it (correlated on `=planKey`) once the token arrives, and
1146
+ * the poller publishes it to release the next wave. Single source of truth for the string shared by
1147
+ * the publish and the subscription probe. */
1148
+ const WAVE_MERGED_MESSAGE = "wave-merged";
1149
+
1150
+ /** The subset of a Camunda-8 `/v2/message-subscriptions/search` result item this app reads to tell
1151
+ * whether the plan-fanout instance is *currently parked* at `wait-wave-merged`. `messageName` is the
1152
+ * awaited message; `correlationKey` is the plan key the catch event binds; `messageSubscriptionState`
1153
+ * is `CREATED` while the subscription is open (waiting) and `CORRELATED`/`DELETED` once consumed. */
1154
+ interface MessageSubscriptionSearchItem {
1155
+ messageName?: string;
1156
+ correlationKey?: string | null;
1157
+ messageSubscriptionState?: string;
1158
+ }
1159
+
1160
+ /** Is the plan-fanout instance `processKey` right now parked at `wait-wave-merged` with an OPEN
1161
+ * (`CREATED`) subscription correlated on `planKey`? Reads the engine's Camunda-8
1162
+ * `/v2/message-subscriptions/search` (the same raw-REST search surface `pollIncidents`/
1163
+ * `pollJobActivation` use). Returns `true` (open — safe to release), `false` (no open subscription —
1164
+ * the token is either upstream of the wait or has already passed through it), or `null` (transport
1165
+ * unhappy / unparseable body — "unknown", so the caller neither publishes nor acts on a guess and
1166
+ * simply retries next tick). This is the load-bearing check that makes the barrier level-triggered:
1167
+ * we only ever publish `wave-merged` into a subscription we've observed OPEN, so a signal can never
1168
+ * be dropped into the void (the #262 wedge) nor buffered to trip a *later* wave's barrier. */
1169
+ async function waveMergedSubscriptionOpen(
1170
+ base: string,
1171
+ headers: Record<string, string>,
1172
+ processKey: string,
1173
+ planKey: string,
1174
+ ): Promise<boolean | null> {
1175
+ try {
1176
+ const res = await fetch(`${base}/message-subscriptions/search`, {
1177
+ method: "POST",
1178
+ headers,
1179
+ body: JSON.stringify({
1180
+ filter: {
1181
+ processInstanceKey: processKey,
1182
+ messageName: WAVE_MERGED_MESSAGE,
1183
+ messageSubscriptionState: "CREATED",
1184
+ },
1185
+ page: { limit: 20 },
1186
+ }),
1187
+ });
1188
+ if (!res.ok) return null; // engine unhappy → "unknown", retry next pass
1189
+ // biome-ignore lint/plugin: runtime/framework contract boundary for external data shape
1190
+ const body = (await res.json()) as { items?: MessageSubscriptionSearchItem[] };
1191
+ // Re-filter defensively in case the engine ignores a filter field: an OPEN (`CREATED`)
1192
+ // subscription for the `wave-merged` message, correlated on THIS plan key, is the barrier we may
1193
+ // publish into. Every field must be PRESENT and match explicitly — we never default a
1194
+ // missing/null `messageName`, `correlationKey`, or `messageSubscriptionState` to its expected
1195
+ // value. Doing so would treat an unverifiable item as OPEN and re-introduce the exact #262
1196
+ // failure class (publishing into a subscription we never confirmed open, buffering a message that
1197
+ // trips a later wave's barrier). An item that omits a field is "unknown", so we simply don't
1198
+ // match it: a false negative only costs a retry next pass, whereas a false positive is a wedge.
1199
+ // State is compared case-insensitively so a future casing tweak can't silently drop the match.
1200
+ return (body.items ?? []).some(
1201
+ (it) =>
1202
+ it.messageName === WAVE_MERGED_MESSAGE &&
1203
+ it.correlationKey === planKey &&
1204
+ typeof it.messageSubscriptionState === "string" &&
1205
+ it.messageSubscriptionState.toUpperCase() === "CREATED",
1206
+ );
1207
+ } catch (err) {
1208
+ console.error(`[poller] wave-merged subscription ${planKey}: ${err}`);
1209
+ return null; // transport threw → "unknown", retry next pass
1210
+ }
1211
+ }
1212
+
1213
+ /** Wave-merge barrier poll pass (issue #262). After `record-wave` hands off a wave that has a
1214
+ * successor, the plan-fanout instance eventually parks at the `wait-wave-merged` catch event and
1215
+ * `plans.gate_wave` records that wave's index. Here we reconcile, on EVERY pass and idempotently,
1216
+ * the external GitHub fact "every OPENED PR in that wave has MERGED" against the engine fact "is
1217
+ * there an OPEN `wait-wave-merged` subscription for this plan right now?", publishing `wave-merged`
1218
+ * (correlated on the plan key) to release the next wave's implementation whenever BOTH hold.
1148
1219
  *
1149
- * `gate_wave` is cleared single-shot BEFORE publishing (and restored if the publish fails —
1150
- * mirroring `flipToMergingThenPublish`) so a slow pass can't double-signal and a later wave's
1151
- * barrier can't be tripped by a stale message reusing the same plan-key correlation. A wave whose
1152
- * tasks all ended `blocked`/`skipped` (no opened PR to wait on) clears vacuously there is
1153
- * nothing to merge, and that failure has already cascaded to dependents in `select-wave`. */
1154
- async function pollWaveGates(data: DataLayer, engine: EngineClient, token: string) {
1220
+ * This is deliberately LEVEL-triggered, not the old single-shot edge trigger. The gate is armed at
1221
+ * wave handoff long before the token traverses `select-wave trial-merge (a slow agent job) →
1222
+ * wait-wave-merged` and opens the subscription. If the wave's PRs merged while the token was
1223
+ * still upstream, the old code published its one `wave-merged` into NO open subscription (dropped)
1224
+ * AND cleared `gate_wave`, so it never republished and the epic wedged forever once the token
1225
+ * finally arrived (#262). We fix the class:
1226
+ * • We publish ONLY when {@link waveMergedSubscriptionOpen} confirms the token is parked at the
1227
+ * wait — never into the void — so a merged-before-arrival wave simply waits, and a later pass
1228
+ * (once the token arrives) republishes and correlates.
1229
+ * • We NEVER clear `gate_wave` here. `record-wave` owns its lifecycle (it re-arms it to the next
1230
+ * wave, or clears it to `null` on the final wave), so a signal published into the void can't
1231
+ * strand the gate, and double-advance is guarded by the open-subscription check — which, by the
1232
+ * handoff ordering, always matches the wave whose wait is currently open — not by a premature
1233
+ * clear. A wave whose tasks all ended `blocked`/`skipped` (no opened PR to wait on) has an empty
1234
+ * merge-target set and so is treated as merged; `record-wave` advances it on the next pass. */
1235
+ export async function pollWaveGatesImpl(
1236
+ data: DataLayer,
1237
+ engine: EngineClient,
1238
+ token: string,
1239
+ base: string,
1240
+ headers: Record<string, string>,
1241
+ ) {
1155
1242
  for (const plan of await plans(data).all()) {
1156
1243
  const gateWave = plan.gate_wave;
1157
1244
  if (gateWave == null) continue;
@@ -1165,18 +1252,14 @@ async function pollWaveGates(data: DataLayer, engine: EngineClient, token: strin
1165
1252
  break;
1166
1253
  }
1167
1254
  }
1168
- if (!allMerged) continue;
1169
- await plans(data).update(planKey, { gate_wave: null, updated_at: now() });
1170
- try {
1171
- await engine.publishMessage({ name: "wave-merged", correlationKey: planKey, variables: {} });
1172
- } catch (err) {
1173
- try {
1174
- await plans(data).update(planKey, { gate_wave: gateWave, updated_at: now() });
1175
- } catch (revertErr) {
1176
- console.error(`[poller] revert wave-gate ${planKey} -> ${gateWave} failed: ${revertErr}`);
1177
- }
1178
- throw err;
1179
- }
1255
+ if (!allMerged) continue; // wave not landed yet → leave the gate armed, retry next pass
1256
+ // The wave has landed on GitHub. Release the barrier ONLY if the token is actually parked at
1257
+ // `wait-wave-merged` (an OPEN subscription for this plan): otherwise publishing would be a
1258
+ // silent no-op that the old code paired with a gate clear — the edge-triggered wedge (#262).
1259
+ if (!plan.process_key) continue; // no instance key to correlate against yet
1260
+ const open = await waveMergedSubscriptionOpen(base, headers, plan.process_key, planKey);
1261
+ if (open !== true) continue; // not parked here yet / already released / unknown → NEVER clear the gate; retry next pass
1262
+ await engine.publishMessage({ name: WAVE_MERGED_MESSAGE, correlationKey: planKey, variables: {} });
1180
1263
  console.log(`[poller] wave ${gateWave} merged -> ${planKey}`);
1181
1264
  } catch (err) {
1182
1265
  console.error(`[poller] wave-gate ${planKey}: ${err}`);
@@ -1559,7 +1642,11 @@ export async function pollUserTasks(data: DataLayer, engine: EngineClient) {
1559
1642
 
1560
1643
  /** One full poll pass: advance the review stage, the merge stage, the wave-merge barrier, and
1561
1644
  * (when the engine REST endpoint is supplied) the job-activation visibility pass and the
1562
- * technical-incident surfacing pass. Called on the self-scheduling loop in `main.ts`. */
1645
+ * technical-incident surfacing pass. Called on the self-scheduling loop in `main.ts`.
1646
+ *
1647
+ * The wave-merge barrier is now level-triggered and probes the engine's message-subscription state
1648
+ * over the same raw-REST search surface, so it runs only when `engineRest` is supplied (as in
1649
+ * production — `main.ts` always passes it). */
1563
1650
  export async function pollOnce(
1564
1651
  data: DataLayer,
1565
1652
  engine: EngineClient,
@@ -1568,7 +1655,6 @@ export async function pollOnce(
1568
1655
  ) {
1569
1656
  await pollReviews(data, engine, token);
1570
1657
  await pollMerges(data, engine, token);
1571
- await pollWaveGates(data, engine, token);
1572
1658
  await pollDelivery(data);
1573
1659
  await pollFeatureDelivery(data);
1574
1660
  await pollLineage(data);
@@ -1576,6 +1662,10 @@ export async function pollOnce(
1576
1662
  await pollFeatureBlocked(data, engine);
1577
1663
  await pollUserTasks(data, engine);
1578
1664
  if (engineRest) {
1665
+ const base = engineRest.restAddress.replace(/\/+$/, "");
1666
+ const headers: Record<string, string> = { "content-type": "application/json" };
1667
+ if (engineRest.token) headers.authorization = `Bearer ${engineRest.token}`;
1668
+ await pollWaveGatesImpl(data, engine, token, base, headers);
1579
1669
  await pollJobActivation(data, engineRest.restAddress, engineRest.token);
1580
1670
  await pollIncidents(data, engineRest.restAddress, engineRest.token);
1581
1671
  }
@@ -10,7 +10,10 @@
10
10
  --
11
11
  -- `plans.gate_wave` is the durable marker for the barrier: when `record-wave` hands
12
12
  -- off a wave that has a successor, it records that wave's index here and the process
13
- -- parks at the `wait-wave-merged` catch event. The poller (`pollWaveGates`) clears it
14
- -- and publishes `wave-merged` once every opened PR in that wave has merged. NULL means
15
- -- the plan is not currently parked at the wave barrier.
13
+ -- parks at the `wait-wave-merged` catch event. The poller (`pollWaveGatesImpl`) is
14
+ -- level-triggered: it publishes `wave-merged` once every opened PR in that wave has
15
+ -- merged AND it observes an OPEN `wait-wave-merged` subscription for the plan, and it
16
+ -- NEVER clears `gate_wave` — `record-wave` owns the marker's lifecycle (re-arming it to
17
+ -- the next wave, or clearing it to NULL on the final wave). NULL means the plan is not
18
+ -- currently parked at the wave barrier.
16
19
  ALTER TABLE plans ADD COLUMN gate_wave INTEGER;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanobpm/nano-workforce",
3
- "version": "0.82.0",
3
+ "version": "0.82.1",
4
4
  "description": "Nano Workforce — an Agent Graph Orchestration application for Agentic SDLC: durable BPMN processes that coordinate a graph of AI agents across the software delivery lifecycle.",
5
5
  "type": "module",
6
6
  "main": "main.ts",
@@ -293,9 +293,11 @@ const handler: AppJobHandler<In, Out> = async (job, app) => {
293
293
 
294
294
  // Wave-merge barrier: when another wave follows, park the plan-fanout instance at the
295
295
  // `wait-wave-merged` catch event until THIS wave's opened PRs have MERGED (not merely opened).
296
- // `gate_wave` is that durable marker; the poller (`pollWaveGates`) clears it and publishes
297
- // `wave-merged` once the wave has landed. Clear it on the final wave so a re-planned issue can't
298
- // inherit a stale gate. Best-effort: a failed marker write must not fail the wave (the poller
296
+ // `gate_wave` is that durable marker; the level-triggered poller (`pollWaveGatesImpl`) publishes
297
+ // `wave-merged` once the wave has landed AND it observes an OPEN subscription, but NEVER clears
298
+ // `gate_wave` record-wave owns the marker's lifecycle. Re-arm it to the next wave here, or
299
+ // clear it on the final wave so a re-planned issue can't inherit a stale gate. Best-effort: a
300
+ // failed marker write must not fail the wave (the poller
299
301
  // reconciles from `plan_tasks`/`pull_requests`), but the loop still relies on it to know which
300
302
  // wave to watch, so we log a failure loudly.
301
303
  try {