@hearsay-tools/squawk 0.18.0-dev.6807 → 0.18.0-dev.6810

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.
Files changed (152) hide show
  1. package/dist/ci-wait/controller.d.ts +4 -4
  2. package/dist/contract/delegation.d.ts +20 -0
  3. package/dist/contract/index.js +4 -1
  4. package/dist/core/agent-runner.d.ts +16 -0
  5. package/dist/core/agent-runner.js +7 -0
  6. package/dist/core/agent-runner.js.map +1 -1
  7. package/dist/core/claude-cli-runner.js +3 -2
  8. package/dist/core/claude-cli-runner.js.map +1 -1
  9. package/dist/core/codex-app-server-runner.js +3 -3
  10. package/dist/core/codex-app-server-runner.js.map +1 -1
  11. package/dist/core/codex-app-server-transport.d.ts +2 -0
  12. package/dist/core/codex-app-server-transport.js +1 -1
  13. package/dist/core/codex-app-server-transport.js.map +1 -1
  14. package/dist/core/cursor-print-process.d.ts +3 -0
  15. package/dist/core/cursor-print-process.js +1 -1
  16. package/dist/core/cursor-print-process.js.map +1 -1
  17. package/dist/core/cursor-print-runner.js +3 -2
  18. package/dist/core/cursor-print-runner.js.map +1 -1
  19. package/dist/core/omp-runner.js +3 -1
  20. package/dist/core/omp-runner.js.map +1 -1
  21. package/dist/core/opencode-server-runner.js +3 -3
  22. package/dist/core/opencode-server-runner.js.map +1 -1
  23. package/dist/core/pi-runner.js +3 -2
  24. package/dist/core/pi-runner.js.map +1 -1
  25. package/dist/core/session-process.d.ts +6 -0
  26. package/dist/core/session-process.js +53 -2
  27. package/dist/core/session-process.js.map +1 -1
  28. package/dist/delegation/family-end.js +2 -4
  29. package/dist/delegation/family-end.js.map +1 -1
  30. package/dist/delegation/owned-workspace-release.d.ts +1 -2
  31. package/dist/delegation/owned-workspace-release.js +2 -2
  32. package/dist/delegation/owned-workspace-release.js.map +1 -1
  33. package/dist/delegation/process-liveness.d.ts +8 -58
  34. package/dist/delegation/process-liveness.js +9 -86
  35. package/dist/delegation/process-liveness.js.map +1 -1
  36. package/dist/delegation/routes.d.ts +87 -83
  37. package/dist/delegation/scratch-cleanup.d.ts +1 -1
  38. package/dist/delegation/scratch-cleanup.js +7 -10
  39. package/dist/delegation/scratch-cleanup.js.map +1 -1
  40. package/dist/delegation/service.js +2 -1
  41. package/dist/delegation/service.js.map +1 -1
  42. package/dist/delegation/transport.d.ts +20 -16
  43. package/dist/delegation/worker-cleanup.d.ts +2 -9
  44. package/dist/delegation/worker-cleanup.js +44 -86
  45. package/dist/delegation/worker-cleanup.js.map +1 -1
  46. package/dist/delegation/workspace-removal.d.ts +4 -12
  47. package/dist/delegation/workspace-removal.js +18 -51
  48. package/dist/delegation/workspace-removal.js.map +1 -1
  49. package/dist/git-worktree.js +2 -6
  50. package/dist/git-worktree.js.map +1 -1
  51. package/dist/preview/dev-server.d.ts +3 -0
  52. package/dist/preview/dev-server.js +40 -1
  53. package/dist/preview/dev-server.js.map +1 -1
  54. package/dist/preview/host.d.ts +3 -1
  55. package/dist/preview/host.js +2 -1
  56. package/dist/preview/host.js.map +1 -1
  57. package/dist/runs/private-record-file.d.ts +7 -0
  58. package/dist/runs/private-record-file.js +55 -0
  59. package/dist/runs/private-record-file.js.map +1 -0
  60. package/dist/runs/store.d.ts +18 -6
  61. package/dist/runs/store.js +43 -99
  62. package/dist/runs/store.js.map +1 -1
  63. package/dist/runs/worker-execution.d.ts +1 -0
  64. package/dist/runs/worker-execution.js +4 -1
  65. package/dist/runs/worker-execution.js.map +1 -1
  66. package/dist/runs/worker-resource-holders.d.ts +10 -7
  67. package/dist/runs/worker-resource-holders.js +9 -25
  68. package/dist/runs/worker-resource-holders.js.map +1 -1
  69. package/dist/server/server.d.ts +8 -0
  70. package/dist/server/workspace-live-routes.d.ts +6 -6
  71. package/dist/worker-scope/cgroup.d.ts +41 -0
  72. package/dist/worker-scope/cgroup.js +173 -0
  73. package/dist/worker-scope/cgroup.js.map +1 -0
  74. package/dist/worker-scope/groups.d.ts +24 -0
  75. package/dist/worker-scope/groups.js +60 -0
  76. package/dist/worker-scope/groups.js.map +1 -0
  77. package/dist/worker-scope/scope.d.ts +32 -0
  78. package/dist/worker-scope/scope.js +18 -0
  79. package/dist/worker-scope/scope.js.map +1 -0
  80. package/dist/worker-scope/worker-scopes.d.ts +63 -0
  81. package/dist/worker-scope/worker-scopes.js +181 -0
  82. package/dist/worker-scope/worker-scopes.js.map +1 -0
  83. package/dist/workflows/grouped-command.d.ts +3 -0
  84. package/dist/workflows/grouped-command.js +28 -2
  85. package/dist/workflows/grouped-command.js.map +1 -1
  86. package/dist/workflows/run/compose.d.ts +0 -2
  87. package/dist/workflows/run/compose.js.map +1 -1
  88. package/dist/workflows/run/continuation-session.js +1 -0
  89. package/dist/workflows/run/continuation-session.js.map +1 -1
  90. package/dist/workflows/run/step-loop.d.ts +1 -1
  91. package/dist/workflows/run/step-loop.js +4 -2
  92. package/dist/workflows/run/step-loop.js.map +1 -1
  93. package/dist/workflows/run/step-session.js +1 -0
  94. package/dist/workflows/run/step-session.js.map +1 -1
  95. package/dist/workflows/run/worker-executions.d.ts +2 -1
  96. package/dist/workflows/run/worker-executions.js +8 -4
  97. package/dist/workflows/run/worker-executions.js.map +1 -1
  98. package/dist/workflows/run/worker-orphans.d.ts +16 -31
  99. package/dist/workflows/run/worker-orphans.js +71 -123
  100. package/dist/workflows/run/worker-orphans.js.map +1 -1
  101. package/dist/workflows/run.d.ts +0 -2
  102. package/dist/workflows/run.js +1 -4
  103. package/dist/workflows/run.js.map +1 -1
  104. package/dist/worktree-setup.d.ts +3 -0
  105. package/dist/worktree-setup.js +2 -1
  106. package/dist/worktree-setup.js.map +1 -1
  107. package/package.json +4 -4
  108. package/web/dist/assets/{activity-motion-ankV4z_y.js → activity-motion-AuQA350-.js} +1 -1
  109. package/web/dist/assets/{activity-route-C7Lo4d_1.js → activity-route-BNZ9bOOZ.js} +1 -1
  110. package/web/dist/assets/{agent-accounts-BAUPVmTO.js → agent-accounts-D2uZHuiM.js} +1 -1
  111. package/web/dist/assets/attention-B7icDSLh.js +1 -0
  112. package/web/dist/assets/{cez-idle-TVRD1sce.js → cez-idle-MToU9Wv_.js} +1 -1
  113. package/web/dist/assets/{commit-diff-panel-Cmqi-EvU.js → commit-diff-panel-DBW7us79.js} +1 -1
  114. package/web/dist/assets/{diff-BawymO3F.js → diff-C3Cms5Ep.js} +2 -2
  115. package/web/dist/assets/{diff-view-DHx_pu8b.js → diff-view-D5zTYOKV.js} +1 -1
  116. package/web/dist/assets/{file-preview-DV7f2pOk.js → file-preview-FhzIdXZ3.js} +1 -1
  117. package/web/dist/assets/{git-toolbar-BrVfyYBr.js → git-toolbar-MFjkjDDG.js} +1 -1
  118. package/web/dist/assets/{github-DVXWmfeu.js → github-CYmdc5Dh.js} +1 -1
  119. package/web/dist/assets/{global-activity-route-ybR1xgLf.js → global-activity-route-C41ofuHV.js} +1 -1
  120. package/web/dist/assets/{index-Dc_KmL4Z.js → index-e1OpsDKN.js} +4 -4
  121. package/web/dist/assets/{live-protocol-aMLJJ0MQ.js → live-protocol-B8boP96Z.js} +1 -1
  122. package/web/dist/assets/{preview-pane-connected-CT7tXifI.js → preview-pane-connected-Ds209_UZ.js} +1 -1
  123. package/web/dist/assets/{project-router-CbWELZZ9.js → project-router-F1inY-EB.js} +1 -1
  124. package/web/dist/assets/{project-scope-context-p1OpXpSJ.js → project-scope-context-0Z0nsheq.js} +1 -1
  125. package/web/dist/assets/{prompt-template-menu-Ct3m86h1.js → prompt-template-menu-uUjg9v98.js} +1 -1
  126. package/web/dist/assets/{queries-BAUtqJph.js → queries-7W9tOZsg.js} +1 -1
  127. package/web/dist/assets/{reference-chip-B2B-Ky7w.js → reference-chip-BqRpnpaI.js} +1 -1
  128. package/web/dist/assets/{repo-git-DRONt4_i.js → repo-git-BZcRanYE.js} +1 -1
  129. package/web/dist/assets/{report-reader-BF8rmJRD.js → report-reader-BLlV3dPF.js} +1 -1
  130. package/web/dist/assets/{reports-Bv91XlcP.js → reports-C--EXqf1.js} +1 -1
  131. package/web/dist/assets/{run-header-CvJ84kr2.js → run-header-CJg8dyfz.js} +1 -1
  132. package/web/dist/assets/{skills-Ceg2Y9LM.js → skills-CHWVejdV.js} +1 -1
  133. package/web/dist/assets/{tab-link-CT5gqdai.js → tab-link-XI9xWLwR.js} +1 -1
  134. package/web/dist/assets/{task-changes-BplRsiSs.js → task-changes-DFm_EHnj.js} +1 -1
  135. package/web/dist/assets/{task-commits-CYLy-lg-.js → task-commits-BX-GVdXG.js} +1 -1
  136. package/web/dist/assets/{task-files-COYxL8mg.js → task-files-Dsn11PYu.js} +1 -1
  137. package/web/dist/assets/{task-github-item-DAD__wEa.js → task-github-item-3N6jEijR.js} +1 -1
  138. package/web/dist/assets/{task-thread-CTEobEyX.js → task-thread-VNPhkI8i.js} +1 -1
  139. package/web/dist/assets/{thread-state-CpdUCQVd.js → thread-state-D1XLo7ab.js} +1 -1
  140. package/web/dist/assets/{use-desktop-Bok38AjX.js → use-desktop-DdcA0Atl.js} +1 -1
  141. package/web/dist/assets/{use-hand-to-agent-state-DiBEjj2Y.js → use-hand-to-agent-state-2tzEmCDo.js} +1 -1
  142. package/web/dist/assets/{useInfiniteQuery-DD7iZHIJ.js → useInfiniteQuery-BmmIZbVY.js} +1 -1
  143. package/web/dist/assets/useQuery-CBKC2lBX.js +1 -0
  144. package/web/dist/assets/{workflows-Cq6Fg1ZT.js → workflows-CqqdPBFr.js} +1 -1
  145. package/web/dist/assets/{ws-CqtLOaJ8.js → ws-BvDSfSVH.js} +1 -1
  146. package/web/dist/index.html +14 -14
  147. package/web/dist/live-worker.js +1 -1
  148. package/dist/delegation/destroy-observation.d.ts +0 -44
  149. package/dist/delegation/destroy-observation.js +0 -116
  150. package/dist/delegation/destroy-observation.js.map +0 -1
  151. package/web/dist/assets/attention-C6XIgMqB.js +0 -1
  152. package/web/dist/assets/useQuery-DVAeyc_X.js +0 -1
@@ -6,7 +6,7 @@ import { productEnv } from '../core/product-env.js';
6
6
  import { registeredWaitRecord, registeredReceiptRecord } from './wait-registration-write.js';
7
7
  import { stageCommit, stageLoaded, stageDurableUpdate, stageDebouncedUpdate, stageConversation, stageArchiveFields, stagePullRequests, stageStepUpdate, redactPatch, redactText, clearPin } from './record-write-rules.js';
8
8
  import { workerDeletionProof } from './worker-deletion-proof.js';
9
- import { workerResourceAbsentHolders, workerResourceAuthorized, workerResourceLiveHolders, workerResourcePathsGone } from './worker-resource-holders.js';
9
+ import { recordedHolders, workerResourceAuthorized } from './worker-resource-holders.js';
10
10
  import { listPeerTaskSummaries, parseStoredSummary } from './run-summary-page.js';
11
11
  export { parseStoredSummary } from './run-summary-page.js';
12
12
  import { defined } from '../core/defined.js';
@@ -18,9 +18,12 @@ import { jobRunsIn } from '../jobs/job.js';
18
18
  import { removeArtifacts } from '../artifacts/lifecycle.js';
19
19
  import { randomUUID, createHash } from 'node:crypto';
20
20
  import { isDeepStrictEqual } from 'node:util';
21
- import { appendFileSync, closeSync, constants, fstatSync, fsyncSync, lstatSync, openSync, readSync, realpathSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
21
+ import { appendFileSync, closeSync, constants, fstatSync, fsyncSync, lstatSync, openSync, readSync, realpathSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
22
22
  import { join, resolve } from 'node:path';
23
23
  import { z } from 'zod';
24
+ import { scopeRecordSchema } from '../worker-scope/scope.js';
25
+ import { WorkerScopes } from '../worker-scope/worker-scopes.js';
26
+ import { readPrivateRecord, writePrivateRecord } from './private-record-file.js';
24
27
  import { agentInputSchema, inboxClaimSchema, delegationStateSchema, workerResultFileSchema, workerDestroyRetrySchema, } from '../contract/index.js';
25
28
  import { automationIdOf, stepStateSchema as contractStepStateSchema, queuedMessageSchema, toRunSummary, runRecordSchema as contractRunRecordSchema, runPullRequestSchema, mergedPullRequestSchema, } from '../contract/index.js';
26
29
  import { previewServerSchema } from '../contract/index.js';
@@ -33,7 +36,7 @@ import { LiveItemSnapshots } from './live-item-snapshots.js';
33
36
  import { emptyFacts, stampOf, TranscriptFactsIndex } from './transcript-facts.js';
34
37
  import { hasPlainHistory, historyPaths, readHistoryText, readHistoryTextAsync, removeHistory, restoreHistory } from './history-file.js';
35
38
  import { workerExecutionIdentitySchema } from '../delegation/execution-identity.js';
36
- import { inspectGeneration, processStartToken } from '../delegation/process-liveness.js';
39
+ import { processStartToken } from '../delegation/process-liveness.js';
37
40
  import { collectSecretValues, redactDeep } from '../core/secret-redaction.js';
38
41
  // Pure, dependency-free reference helpers — the same sanity bound the marker parser applies.
39
42
  import { archivePullRequests, pullRequestKey } from './pull-requests.js';
@@ -447,6 +450,8 @@ export class RunStore extends EventEmitter {
447
450
  dirty = new Set();
448
451
  /** The lifecycle events run exits write (B12). */
449
452
  exitEvents = new ExitEvents((id, event) => this.appendEvent(id, event));
453
+ /** Every worker's process scope (ADR 0032): spawn sites, Continue and destroy reach it here. */
454
+ scopes = new WorkerScopes(this);
450
455
  /** Runs gone from memory whose rows the next save or commit deletes. */
451
456
  deleted = new Set();
452
457
  /** Deleted runs whose history files (events, handoff, images, artifacts) go once the delete of
@@ -2728,55 +2733,21 @@ export class RunStore extends EventEmitter {
2728
2733
  }
2729
2734
  readWorkerExecution(id) {
2730
2735
  try {
2731
- const path = this.executionPath(id);
2732
- const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
2733
- try {
2734
- const info = fstatSync(fd);
2735
- if (!info.isFile() || info.size > 16384 || (info.mode & 0o077))
2736
- return undefined;
2737
- const buffer = Buffer.alloc(16385);
2738
- const count = readSync(fd, buffer, 0, buffer.length, 0);
2739
- return workerExecutionSchema.parse(JSON.parse(buffer.subarray(0, count).toString('utf8')));
2740
- }
2741
- finally {
2742
- closeSync(fd);
2743
- }
2736
+ const proof = readPrivateRecord(this.executionPath(id), 16384, value => workerExecutionSchema.parse(value));
2737
+ return typeof proof === 'string' ? undefined : proof;
2744
2738
  }
2745
2739
  catch {
2746
2740
  return undefined;
2747
2741
  }
2748
2742
  }
2749
2743
  writeWorkerExecution(id, proof, fresh = false) {
2750
- const path = this.executionPath(id, true);
2751
- try {
2752
- const existing = lstatSync(path);
2753
- if (fresh || !existing.isFile() || existing.isSymbolicLink())
2754
- throw new Error('Unsafe execution checkpoint');
2755
- }
2756
- catch (error) {
2757
- if (error.code !== 'ENOENT')
2758
- throw error;
2759
- }
2760
- const temporary = `${path}.${randomUUID()}.tmp`;
2761
- const fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
2762
- try {
2763
- writeFileSync(fd, JSON.stringify(proof));
2764
- fsyncSync(fd);
2765
- }
2766
- finally {
2767
- closeSync(fd);
2768
- }
2769
- try {
2770
- renameSync(temporary, path);
2771
- }
2772
- finally {
2773
- rmSync(temporary, { force: true });
2774
- }
2744
+ writePrivateRecord(this.executionPath(id, true), proof, { fresh });
2775
2745
  }
2776
2746
  /** Complete execution is not permission to reuse/delete persistent resources (#738).
2777
2747
  * Synchronous, fresh and generation/resource fenced; callers hold admission off across awaits. */
2778
2748
  workerResourcesSafe(id, generation, resourceId) {
2779
- return this.workerResourceHolders(id, generation, resourceId) === 'safe';
2749
+ // Reclaim and history deletion also need an empty scope; admission does not (ADR 0032).
2750
+ return this.workerResourceHolders(id, generation, resourceId) === 'safe' && this.scopes.empty(id);
2780
2751
  }
2781
2752
  /** `workerResourcesSafe` with the refusal's live PIDs (empty when no PID explains it). */
2782
2753
  workerResourceHolders(id, generation, resourceId, opts = {}) {
@@ -2789,13 +2760,8 @@ export class RunStore extends EventEmitter {
2789
2760
  const record = this.readWorkerProcesses(id, generation);
2790
2761
  if (record === 'unknown' || !agentTmpDirOwnershipProven(this.dataDir, id))
2791
2762
  return [];
2792
- const paths = [run.delegation.workspace.path, ...agentTmpDirLocations(this.dataDir, id)];
2793
- // Nothing can be deleted/reused at an absent path. This lets explicit history deletion
2794
- // retire completed cleanup despite ambient denial, while recorded survivors/unknown evidence
2795
- // still block. Only ENOENT proves absence; existsSync would also hide access errors.
2796
- if (workerResourcePathsGone(paths))
2797
- return workerResourceAbsentHolders(record);
2798
- return workerResourceLiveHolders(inspectGeneration({ ...(record === 'absent' ? {} : { record }), paths, cwds: opts.cwds }));
2763
+ // Only the generation's recorded processes count; an outside process blocks nothing (ADR 0032).
2764
+ return recordedHolders(record);
2799
2765
  }
2800
2766
  /** Upgrade a legacy completed checkpoint while terminal task ownership is still known.
2801
2767
  * No holder scan here: settlement and scheduling must never wait on cleanup proof. */
@@ -2808,18 +2774,18 @@ export class RunStore extends EventEmitter {
2808
2774
  return;
2809
2775
  this.writeWorkerExecution(id, { ...proof, scratchCleanup: { resourceId, path } });
2810
2776
  }
2811
- /** Cleanup can outlive its index row, but never its generation or terminal task intent.
2812
- * `cwds` is the scratch reprobe tick's shared `/proc` snapshot (hearsay-tools/cezarion#879). */
2813
- workerScratchResourcesSafe(id, generation, resourceId, cwds) {
2777
+ /** Cleanup can outlive its index row, but never its generation or terminal task intent. */
2778
+ workerScratchResourcesSafe(id, generation, resourceId) {
2814
2779
  if (autosaveCleanupBlocker(this.dataDir, id))
2815
2780
  return false;
2816
2781
  const run = this.peek(id), proof = this.readWorkerExecution(id);
2817
2782
  if (proof?.phase !== 'complete' || proof.generation !== generation || proof.scratchCleanup?.resourceId !== resourceId ||
2818
2783
  (run && ['queued', 'running', 'waiting'].includes(run.status)))
2819
2784
  return false;
2785
+ // A process still in the worker's scope may use its scratch; one outside it is not the worker's.
2820
2786
  if (run?.delegation?.role === 'worker')
2821
2787
  return run.delegation.workspace.path === proof.scratchCleanup.path &&
2822
- this.workerResourceHolders(id, generation, resourceId, { cwds }) === 'safe';
2788
+ this.workerResourceHolders(id, generation, resourceId) === 'safe' && this.scopes.empty(id);
2823
2789
  // A valid different role contradicts the retained intent. Quarantined/missing metadata
2824
2790
  // supplies no new authority; only the private terminal checkpoint authorizes scratch.
2825
2791
  if (run && run.delegation?.role !== 'invalid')
@@ -2827,8 +2793,7 @@ export class RunStore extends EventEmitter {
2827
2793
  const record = this.readWorkerProcesses(id, generation);
2828
2794
  if (record === 'unknown' || !agentTmpDirOwnershipProven(this.dataDir, id))
2829
2795
  return false;
2830
- return inspectGeneration({ ...(record === 'absent' ? {} : { record }),
2831
- paths: [proof.scratchCleanup.path, ...agentTmpDirLocations(this.dataDir, id)], cwds }).liveness === 'gone';
2796
+ return recordedHolders(record) === 'safe' && this.scopes.empty(id);
2832
2797
  }
2833
2798
  commitWorkerExecutionStart(id) {
2834
2799
  const run = this.peek(id);
@@ -2851,51 +2816,28 @@ export class RunStore extends EventEmitter {
2851
2816
  /** Tri-state: only ENOENT is `absent` (legacy, scan-only). A present record that is unreadable,
2852
2817
  * wrongly permissioned, malformed or of another generation is `unknown`: never finalized or reaped. */
2853
2818
  readWorkerProcesses(id, generation) {
2854
- try {
2855
- const fd = openSync(this.processesPath(id), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
2856
- try {
2857
- const info = fstatSync(fd);
2858
- if (!info.isFile() || info.size > 8192 || (info.mode & 0o077))
2859
- return 'unknown';
2860
- const buffer = Buffer.alloc(8193);
2861
- const count = readSync(fd, buffer, 0, buffer.length, 0);
2862
- const record = workerProcessRecordSchema.parse(JSON.parse(buffer.subarray(0, count).toString('utf8')));
2863
- return record.generation === generation ? record : 'unknown';
2864
- }
2865
- finally {
2866
- closeSync(fd);
2867
- }
2868
- }
2869
- catch (error) {
2870
- return error.code === 'ENOENT' ? 'absent' : 'unknown';
2871
- }
2819
+ const record = readPrivateRecord(() => this.processesPath(id), 8192, value => workerProcessRecordSchema.parse(value));
2820
+ return typeof record === 'string' || record.generation === generation ? record : 'unknown';
2872
2821
  }
2873
2822
  writeWorkerProcesses(id, record) {
2874
- const path = this.processesPath(id, true);
2875
- try {
2876
- const existing = lstatSync(path);
2877
- if (!existing.isFile() || existing.isSymbolicLink())
2878
- throw new Error('Unsafe process record');
2879
- }
2880
- catch (error) {
2881
- if (error.code !== 'ENOENT')
2882
- throw error;
2883
- }
2884
- const temporary = `${path}.${randomUUID()}.tmp`;
2885
- const fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
2886
- try {
2887
- writeFileSync(fd, JSON.stringify(workerProcessRecordSchema.parse(record)));
2888
- fsyncSync(fd);
2889
- }
2890
- finally {
2891
- closeSync(fd);
2892
- }
2893
- try {
2894
- renameSync(temporary, path);
2895
- }
2896
- finally {
2897
- rmSync(temporary, { force: true });
2898
- }
2823
+ writePrivateRecord(this.processesPath(id, true), workerProcessRecordSchema.parse(record));
2824
+ }
2825
+ /** Private scope record: the cgroups and process groups the worker owns (ADR 0032). */
2826
+ scopePath(id, write = false) {
2827
+ return this.executionPath(id, write).replace(/\.execution\.json$/, '.scope.json');
2828
+ }
2829
+ /** Tri-state like the process record: only ENOENT is `absent`. */
2830
+ readWorkerScope(id) {
2831
+ const record = readPrivateRecord(() => this.scopePath(id), 65_536, value => scopeRecordSchema.parse(value));
2832
+ return typeof record === 'string' || record.workerId === id ? record : 'unknown';
2833
+ }
2834
+ /** Durable before the caller acts on it. */
2835
+ writeWorkerScope(id, record) {
2836
+ writePrivateRecord(this.scopePath(id, true), scopeRecordSchema.parse(record));
2837
+ }
2838
+ /** The scope a run's processes start in: a worker's own, none for any other run (ADR 0032). */
2839
+ spawnScope(id) {
2840
+ return this.peek(id)?.delegation?.role === 'worker' ? this.scopes.spawnScope(id) : undefined;
2899
2841
  }
2900
2842
  /** Bound to the current generation. Past the cap the record never drops an entry: the
2901
2843
  * working-directory scan is the remaining evidence. */
@@ -2911,7 +2853,7 @@ export class RunStore extends EventEmitter {
2911
2853
  this.writeWorkerProcesses(id, { ...record, processes: [...record.processes, entry] });
2912
2854
  return true;
2913
2855
  }
2914
- commitWorkerExecutionComplete(id, generation) {
2856
+ commitWorkerExecutionComplete(id, generation, opts = {}) {
2915
2857
  const proof = this.readWorkerExecution(id);
2916
2858
  if (!proof || proof.generation !== generation)
2917
2859
  return false;
@@ -2927,6 +2869,7 @@ export class RunStore extends EventEmitter {
2927
2869
  this.writeWorkerExecution(id, { generation, phase: 'complete',
2928
2870
  // Nothing abandons an execution any more (hearsay-tools/cezarion#889); keep a checkpoint that already was.
2929
2871
  ...(proof.abandoned ? { abandoned: true } : {}),
2872
+ ...(proof.interrupted || (opts.interrupted && proof.phase === 'starting') ? { interrupted: true } : {}),
2930
2873
  ...(proof.phase === 'queued' || proof.neverMaterialized ? { neverMaterialized: true } : {}),
2931
2874
  ...(!['queued', 'running', 'waiting'].includes(run.status) ? { scratchCleanup: {
2932
2875
  resourceId: run.delegation.workspace.resourceId, path: run.delegation.workspace.path
@@ -3042,6 +2985,7 @@ export class RunStore extends EventEmitter {
3042
2985
  // Private process/account evidence is now replaced by the exact parent receipt.
3043
2986
  rmSync(this.identityPath(id), { force: true });
3044
2987
  rmSync(this.processesPath(id), { force: true });
2988
+ rmSync(this.scopePath(id), { force: true });
3045
2989
  rmSync(this.executionPath(id), { force: true });
3046
2990
  const retained = this.readWorkerResult(parent.id, id);
3047
2991
  this.commitWorkerResult(parent.id, { ...retained, observedAt: new Date().toISOString(),