@north-light/api 0.3.728 → 0.3.729

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.
@@ -41,6 +41,7 @@ import { clearFinalReportIfMatches, getFinalReport, getNode, updateNode } from '
41
41
  import { subscribersOf } from '../canvas/tree.js';
42
42
  import { InputError } from '../io.js';
43
43
  import { transition } from './lifecycle.js';
44
+ import { assertCheckoutNotRemoved } from './revive.js';
44
45
  import { noticeChangedWhileDone } from './ledger.js';
45
46
  async function currentFinalReport(nodeId) {
46
47
  return await getFinalReport(nodeId);
@@ -123,6 +124,10 @@ async function isManagerOf(callerNodeId, nodeId) {
123
124
  * Writing lifecycle first leaves a failed latch CAS with the canonical-final
124
125
  * pointer intact. Both writes finish before either delivery channel begins. */
125
126
  export async function commitReopenResident(nodeId, expectedFinalReport, callerNodeId) {
127
+ // A node whose managed checkout was removed can never run again: refuse before any reopen write.
128
+ const before = await getNode(nodeId);
129
+ if (before !== null)
130
+ assertCheckoutNotRemoved(nodeId, before);
126
131
  const finalReport = await currentFinalReport(nodeId);
127
132
  if (!(await isManagerOf(callerNodeId, nodeId)))
128
133
  await updateNode(nodeId, { lifecycle: 'resident' });
@@ -111,7 +111,8 @@ export declare function assertRecordedCwdExists(nodeId: string, meta: NodeMeta):
111
111
  blaxelEnvironment: string | null;
112
112
  remoteMachine: boolean;
113
113
  }>;
114
- /** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them: refuse on any host, before a caller changes state. */
114
+ /** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them; its cwd now names the shared repository
115
+ * root, so a launch would edit the base checkout. Refuse on any host, before a caller changes state. */
115
116
  export declare function assertCheckoutNotRemoved(nodeId: string, meta: NodeMeta): void;
116
117
  /** The `node:start` lifecycle hooks for a node coming up: a launch, or a cycle started in a running process. */
117
118
  export declare function runNodeStartHooks(nodeId: string, meta: NodeMeta, isBirth: boolean): Promise<void>;
@@ -228,6 +228,10 @@ async function decideReviveAsCaller(nodeId, opts, wakeParked) {
228
228
  if (meta.final_report !== null) {
229
229
  throw new Error(`reviveNode: refusing to revive ${nodeId} — its finalization latch is set (final_report=${meta.final_report}). A final landed between the caller's reopen-gate check and this revive; re-run with --reopen if this retask is still wanted.`);
230
230
  }
231
+ // A removed managed checkout refuses every start, before the start checks so its reason is the one recorded. An attach that only
232
+ // looks at a parked node starts nothing; cleanup completes only after the engine exits, so no live broker is refused.
233
+ if (wakeParked || !(meta.lifecycle === 'resident' && isParked(meta)))
234
+ await refuseRemovedCheckout(nodeId, meta);
231
235
  assertProfileActive(meta.profile_id);
232
236
  // An unsandboxed machine runs terminal agents only: refuse before any lifecycle hook or other prelaunch executable runs as the app.
233
237
  assertGranteeRunsHere(meta.grantee);
@@ -368,7 +372,8 @@ export async function assertRecordedCwdExists(nodeId, meta) {
368
372
  }
369
373
  return { blaxelEnvironment, remoteMachine };
370
374
  }
371
- /** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them: refuse on any host, before a caller changes state. */
375
+ /** Cleanup deleted this node's managed checkout and its branch, and nothing rebuilds them; its cwd now names the shared repository
376
+ * root, so a launch would edit the base checkout. Refuse on any host, before a caller changes state. */
372
377
  export function assertCheckoutNotRemoved(nodeId, meta) {
373
378
  const worktree = meta.managed_worktree;
374
379
  if (worktree?.state !== 'closed' || worktree.cleanup !== 'complete')
@@ -379,6 +384,21 @@ export function assertCheckoutNotRemoved(nodeId, meta) {
379
384
  next: `Start a new node in ${worktree.repo_root}.`,
380
385
  });
381
386
  }
387
+ /** Every start path goes through reviveNode, so this is where a removed checkout is refused. A wake that has no caller to report
388
+ * to (a tick reopen of a parked resident, a stranded or idle-released launch) leaves the row live; it is settled dead with the
389
+ * reason as its outcome, which `crtr node inspect show` prints, so the tick does not select it again. */
390
+ async function refuseRemovedCheckout(nodeId, meta) {
391
+ try {
392
+ assertCheckoutNotRemoved(nodeId, meta);
393
+ }
394
+ catch (error) {
395
+ if (meta.status === 'active' || meta.status === 'idle') {
396
+ await transition(nodeId, 'crash', { reason: 'launch_failed', outcome: { detail: { schema: 'crtr.node-outcome-detail/v1', message: error.message } } });
397
+ await clearFrozen(nodeId);
398
+ }
399
+ throw error;
400
+ }
401
+ }
382
402
  /** The `node:start` lifecycle hooks for a node coming up: a launch, or a cycle started in a running process. */
383
403
  export async function runNodeStartHooks(nodeId, meta, isBirth) {
384
404
  const lifecycleHooks = discoverLifecycleHookRegistry(meta.cwd, meta.profile_id).plans.get('node:start') ?? [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.728",
3
+ "version": "0.3.729",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",