paseo-follow-up 2.1.0-beta.2 → 2.1.0-beta.3

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/index.server.ts CHANGED
@@ -97,7 +97,7 @@ import type { LoadSignals } from "./shared/agent-load";
97
97
  import { OnboardingStore, ReadinessChecks, nativeAgentCount } from "./server/onboarding";
98
98
  import { updatesConsent } from "./shared/onboarding";
99
99
  import { execFile, spawn } from "node:child_process";
100
- import { compactHeap } from "./server/memory";
100
+ import { compactHeap, watchMemory } from "./server/memory";
101
101
  import { UpdatesStore } from "./server/updates";
102
102
  import { Updater } from "./server/updater";
103
103
  import { RegistryChecker, registryUrl, type RegistrySnapshot } from "./server/update-registry";
@@ -454,14 +454,15 @@ export default function contribute(server: PluginServerContext) {
454
454
  }
455
455
  return withSessionMcp({ ...request, env: { ...request.env, FOLLOW_UP_TOOLS: "stdio", FOLLOW_UP_PROVIDER: request.provider } }, directory, clientEntry(), paseoHome, recovery, process.env, brief, root, overseer, providers) as R;
456
456
  };
457
- let compacted = false;
457
+ let compacted = false; let memoryWatch: { stop(): void } | null = null;
458
458
  const loop = async () => {
459
459
  await ready;
460
460
  if (stopped || loadError) return;
461
461
  await engine.tick({ background: true });
462
462
  feeds.workspaces();
463
- // Startup is done once the first tick is: release what it grew (see server/memory.ts).
464
- if (!compacted) { compacted = true; compactHeap(); }
463
+ // Startup is done once the first tick is: release what it grew, then return what each later burst grows
464
+ // (memory-returns-after-a-burst, server/memory.ts) and report the worker's memory in heartbeat.json.
465
+ if (!compacted) { compacted = true; compactHeap(); if (!stopped) memoryWatch = watchMemory({ heartbeatFile: join(directory, "heartbeat.json") }); }
465
466
  if (!stopped) timer = setTimeout(() => void loop(), TICK_MS);
466
467
  };
467
468
  void loop();
@@ -1474,7 +1475,7 @@ export default function contribute(server: PluginServerContext) {
1474
1475
  ];
1475
1476
  return async () => {
1476
1477
  restoreConsole();
1477
- stopped = true; wait.close(); updater.stop(); pluginMove.stop(); governor.stop(); if (timer) clearTimeout(timer); if (aboutTimer) clearTimeout(aboutTimer); if (linkedTimer) clearTimeout(linkedTimer); aiJobs.stop(); ranker = null; if (inboxTimer) clearTimeout(inboxTimer); inbox.stop(); rpcTiming.stop(); if (hookTimer) clearInterval(hookTimer); displayOff?.(); usageWatch?.close(); removers.forEach(remove => remove());
1478
+ stopped = true; wait.close(); updater.stop(); pluginMove.stop(); governor.stop(); if (timer) clearTimeout(timer); if (aboutTimer) clearTimeout(aboutTimer); if (linkedTimer) clearTimeout(linkedTimer); aiJobs.stop(); ranker = null; if (inboxTimer) clearTimeout(inboxTimer); inbox.stop(); rpcTiming.stop(); if (hookTimer) clearInterval(hookTimer); memoryWatch?.stop(); displayOff?.(); usageWatch?.close(); removers.forEach(remove => remove());
1478
1479
  // One deadline for every wait (worker-stop-never-waits-on-a-stuck-pass, server/teardown.ts): start-up and the work
1479
1480
  // in flight may be stuck on a daemon or CLI that never answers. Work that ends inside the deadline is saved; what
1480
1481
  // outlives it can't write, because the store closes before the lock is released.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "paseo-follow-up",
3
3
  "private": false,
4
- "version": "2.1.0-beta.2",
4
+ "version": "2.1.0-beta.3",
5
5
  "description": "A Paseo plugin that follows every workspace until the work is done: one Home for what needs you, questions you answer anywhere, and repairs that send themselves.",
6
6
  "type": "module",
7
7
  "files": [
@@ -35,7 +35,7 @@
35
35
  "test:native": "node scripts/check-native-tools.mjs --agents 10",
36
36
  "prepare": "node scripts/build.mjs",
37
37
  "test:scale": "node scripts/scale-check.mjs --workspaces 140 --awake 5 --idle 90 --realistic --rss-budget 300 --idle-rss-budget realistic --cpu-budget 3 --request-budget 2",
38
- "test:scale:live": "node scripts/scale-check.mjs --workspaces 140 --awake 5 --live-sized --busy 180 --idle 90 --rss-budget 300 --idle-rss-budget 240 --cpu-budget 3 --request-budget 2 --budgets-report-only",
38
+ "test:scale:live": "node scripts/scale-check.mjs --workspaces 140 --awake 5 --live-sized --busy 180 --cycles 2,120,180 --idle 90 --rss-budget 300 --idle-rss-budget 240 --cpu-budget 3 --request-budget 2 --budgets-report-only",
39
39
  "check:notes": "node scripts/release-notes.mjs --check",
40
40
  "release:version": "node scripts/release-notes.mjs --next-version",
41
41
  "release:notes": "node scripts/release-notes.mjs",
package/server/engine.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { followUpObligations } from "../shared/follow-up";
2
+ import { taskSchedule } from "../shared/task-trigger";
1
3
  import { STOP_WAIT_MS, settleWithin, type Deadline } from "./teardown";
2
4
  import { DEVELOPER, type Actor } from "../shared/actor";
3
5
  import { randomUUID } from "node:crypto";
@@ -153,7 +155,7 @@ export class Engine {
153
155
  /** Per workspace: the state object its last tick left, that tick's runtime (JSON) and when it last observed in full. */
154
156
  /** The discovery rows (JSON) the last tick applied, and the state that write left. */
155
157
  private lastDiscovery: { rows: string; state: State; at: number } | null = null;
156
- private observedPass = new Map<string, { w: Workspace; runtime: string; at: number }>();
158
+ private observedPass = new Map<string, { w: Workspace; runtime: string; at: number; dueAt: number }>();
157
159
  /** How many full per-workspace observation writes ran (tests). */
158
160
  observationWrites = 0;
159
161
  /**
@@ -248,8 +250,9 @@ export class Engine {
248
250
  // rules, like the 120 s acknowledgement, run on that pass). The checks cost a ~200-byte JSON and a shallow compare per PR.
249
251
  const runtimeKey = JSON.stringify(runtime);
250
252
  const last = this.observedPass.get(original.id);
251
- const untouched = !!last && last.w === original && last.runtime === runtimeKey && this.now() - last.at < OBSERVE_FULL_MS && o.workspaceId !== original.id &&
252
- original.prs.every(p => { const seen = observations.get(p.key); return !seen || seen.error === p.error && sameSnapshot(seen.snapshot, p.snapshot, !isHot(original)); });
253
+ // A scheduled task due since the last pass makes it a full pass, so a trigger fires at its time, not up to a minute late.
254
+ const untouched = !!last && last.w === original && last.runtime === runtimeKey && this.now() - last.at < OBSERVE_FULL_MS && this.now() < last.dueAt && o.workspaceId !== original.id &&
255
+ original.prs.every(p => { const seen = observations.get(p.key); return !seen || seen.error === p.error && sameSnapshot(seen.snapshot, p.snapshot, !isHot(original) && !awaitsRead(original)); });
253
256
  if (!untouched) this.observationWrites++;
254
257
  if (!untouched) await this.store.mutateWorkspace(original.id, w => {
255
258
  w.runtimeBusy = runtime.busy; w.runtimeReason = runtime.reason; w.taskAgents = runtime.taskAgents;
@@ -340,7 +343,7 @@ export class Engine {
340
343
  if (!done) await this.store.mutateWorkspace(current.id, w => { w.managedDoneLabel = false; });
341
344
  }
342
345
  const after = findWorkspace(await this.store.snapshot(), original.id);
343
- this.observedPass.set(original.id, { w: after, runtime: runtimeKey, at: untouched ? last!.at : this.now() });
346
+ this.observedPass.set(original.id, { w: after, runtime: runtimeKey, at: untouched ? last!.at : this.now(), dueAt: nextDue(after, this.now()) });
344
347
  await this.statusCheck(after, this.now(), runtimeKey).catch(() => undefined);
345
348
  }
346
349
  this.error = null;
@@ -646,6 +649,25 @@ export class Engine {
646
649
  async stop(within?: Deadline): Promise<void> { this.stopped = true; if (this.nudgeTimer) clearTimeout(this.nudgeTimer); this.nudgeTimer = null; this.nudgeWaiters.splice(0).forEach(w => w()); await settleWithin(Promise.allSettled([this.running, ...this.recoveryOperations]), within ?? this.stopWaitMs); }
647
650
  }
648
651
 
652
+ /**
653
+ * An acknowledged repair waits for a GitHub read newer than its acknowledgment (readSince, One cap). Until that read
654
+ * lands, a read that only moves observedAt is a change: it is what lets the condition go out again.
655
+ */
656
+ function awaitsRead(w: Workspace): boolean {
657
+ return w.batches.some(b => b.state === "completed" && !b.unacknowledged && !!b.settledAt &&
658
+ b.tasks.some(t => isRepair(t) && !!w.prs.find(p => p.key === t.target)?.snapshot && !readSince(w, t, b.settledAt)));
659
+ }
660
+ /** The earliest scheduled task due after `now` (Infinity when none): the untouched-pass skip ends there. */
661
+ function nextDue(w: Workspace, now: number): number {
662
+ let next = Infinity;
663
+ for (const o of followUpObligations(w)) {
664
+ const due = o.trigger && o.enable_follow_up ? taskSchedule(o, w, now).dueAt : null;
665
+ const at = due ? Date.parse(due) : NaN;
666
+ if (at > now && at < next) next = at;
667
+ }
668
+ return next;
669
+ }
670
+
649
671
  export type DoneResult = { workspace: Workspace; blockers: string[]; unconfirmed: string[]; alreadyDone: boolean; next: string };
650
672
  /** The declare_done reply in words: what's missing, who can move it, and whether calling again could help. */
651
673
  /** Done answers every open Done check: a queued one is cancelled, a sent one counts as acknowledged. */
package/server/memory.ts CHANGED
@@ -1,20 +1,120 @@
1
- import { setFlagsFromString } from "node:v8";
1
+ import { getHeapSpaceStatistics, setFlagsFromString } from "node:v8";
2
+ import { readFile, rename, writeFile } from "node:fs/promises";
3
+ import { performance } from "node:perf_hooks";
2
4
  import { runInNewContext } from "node:vm";
3
5
 
4
- /**
5
- * One full, compacting garbage collection, for the worker once its startup work is done (load, migrations, the first
6
- * engine tick). That work grows V8's young generation and touches pages V8 then keeps pooled, so without it the worker
7
- * idled at its startup peak: 216-239 MB in the 120-workspace scale check against 152-184 MB with it (1.4.0-beta.23).
8
- * Paseo starts plugin processes itself, so there's no --expose-gc: the flag is set for one fresh context only, which
9
- * leaves no `gc` global behind. Returns false where the runtime refuses; the worker carries on either way.
10
- */
11
- export function compactHeap(): boolean {
6
+ type Gc = (options?: { type?: "major" | "minor"; execution?: "sync" | "async"; flavor?: "regular" | "last-resort" }) => void;
7
+ let cached: Gc | null | undefined;
8
+ function gcFunction(): Gc | null {
9
+ if (cached !== undefined) return cached;
12
10
  try {
13
11
  setFlagsFromString("--expose-gc");
14
12
  const gc = runInNewContext("gc") as unknown;
15
13
  setFlagsFromString("--no-expose-gc");
16
- if (typeof gc !== "function") return false;
17
- gc();
18
- return true;
19
- } catch { return false; }
14
+ cached = typeof gc === "function" ? gc as Gc : null;
15
+ } catch { cached = null; }
16
+ return cached;
17
+ }
18
+
19
+ /**
20
+ * One memory-reducing garbage collection: a full, compacting collection that also shrinks V8's young generation and
21
+ * releases the pages V8 keeps pooled. A plain `gc()` does neither (Node 24: RSS 108 → 108 MB after a burst; the
22
+ * memory-reducing flavor: 108 → 54). Paseo starts plugin processes itself, so there's no --expose-gc: the flag is set
23
+ * for one fresh context only, which leaves no `gc` global behind. Returns false where the runtime refuses.
24
+ */
25
+ export function compactHeap(): boolean {
26
+ const gc = gcFunction();
27
+ if (!gc) return false;
28
+ try { gc({ type: "major", execution: "sync", flavor: "last-resort" }); } catch { try { gc(); } catch { return false; } }
29
+ return true;
30
+ }
31
+
32
+ /** One settle: `forced` when the 10-minute fallback ran it, not a quiet minute. */
33
+ export type Settle = { at: number; beforeMb: number; afterMb: number; ms: number; cpuMs: number; forced: boolean };
34
+ export type SettlerOptions = { growthMb?: number; minGapMs?: number; quietSamples?: number; quietUtilization?: number; maxWaitMs?: number; now?: () => number; rssMb?: () => number; compact?: () => boolean; cpuMs?: () => number };
35
+ /**
36
+ * Memory a burst grows comes back when the burst ends (memory-returns-after-a-burst). Under a burst of work V8 grows its
37
+ * young generation to its cap (128 MB on Node 24) and keeps it, or its pages pooled, for as long as anything
38
+ * allocates; the worker always does, so RSS stepped up with every busy period and never came down. `observe` gets the
39
+ * worker's RSS and event-loop utilization every 5 s. One memory-reducing collection (60-100 ms, the event loop
40
+ * blocked) runs when RSS is `growthMb` over where the last one left it, `minGapMs` has passed, and the worker is quiet:
41
+ * mean utilization under 1 % over the last 12 samples (a minute). Mid-burst the young generation would grow straight
42
+ * back, and a burst's utilization is low too (median 3 %, harness 2026-11-16), so the gate is the minute's mean, which
43
+ * was quiet in 2 of 109 burst samples and 95 of 158 gap samples. Busy for `maxWaitMs` past the threshold, it runs anyway. A collection that gives back under 8 MB (a runtime that ignores the memory-reducing flavor,
44
+ * or growth outside V8) doubles the gap, up to an hour, so a futile one doesn't repeat.
45
+ */
46
+ export class HeapSettler {
47
+ private baseline: number | null = null;
48
+ private last = -Infinity;
49
+ private gap: number;
50
+ private recent: number[] = [];
51
+ private overSince: number | null = null;
52
+ readonly settles: Settle[] = [];
53
+ /** Settles since start, by what let them run: a quiet minute, or the fallback (live verification, heartbeat.json). */
54
+ quietSettles = 0;
55
+ forcedSettles = 0;
56
+ /** The mean event-loop utilization over the last minute's samples, or null before the first. */
57
+ utilization(): number | null { return this.recent.length ? this.recent.reduce((a, b) => a + b, 0) / this.recent.length : null; }
58
+ constructor(private o: SettlerOptions = {}) { this.gap = o.minGapMs ?? 120_000; }
59
+ observe(rssMb: number, utilization = 0): Settle | null {
60
+ const now = (this.o.now ?? Date.now)();
61
+ const window = this.o.quietSamples ?? 12;
62
+ this.recent.push(utilization); if (this.recent.length > window) this.recent.shift();
63
+ if (this.baseline === null || rssMb < this.baseline) { this.baseline = rssMb; this.overSince = null; return null; }
64
+ if (rssMb < this.baseline + (this.o.growthMb ?? 48)) { this.overSince = null; return null; }
65
+ this.overSince ??= now;
66
+ if (now - this.last < this.gap) return null;
67
+ const quiet = this.recent.length >= window && this.recent.reduce((a, b) => a + b, 0) / window < (this.o.quietUtilization ?? 0.01);
68
+ if (!quiet && now - this.overSince < (this.o.maxWaitMs ?? 600_000)) return null;
69
+ const cpu = this.o.cpuMs ?? (() => { const u = process.cpuUsage(); return (u.user + u.system) / 1000; });
70
+ const t0 = performance.now(); const c0 = cpu();
71
+ const ran = (this.o.compact ?? compactHeap)();
72
+ const ms = Math.round(performance.now() - t0); const cpuMs = Math.round(cpu() - c0);
73
+ this.last = now; this.overSince = null;
74
+ if (!ran) return null;
75
+ const after = (this.o.rssMb ?? (() => process.memoryUsage().rss / 1048576))();
76
+ const settle = { at: now, beforeMb: Math.round(rssMb), afterMb: Math.round(after), ms, cpuMs, forced: !quiet };
77
+ if (quiet) this.quietSettles++; else this.forcedSettles++;
78
+ this.gap = rssMb - after < 8 ? Math.min(this.gap * 2, 3_600_000) : (this.o.minGapMs ?? 120_000);
79
+ this.baseline = after; this.settles.push(settle); if (this.settles.length > 20) this.settles.shift();
80
+ console.error(`[follow-up] memory settled: ${settle.beforeMb} → ${settle.afterMb} MB, ${ms} ms (cpu ${cpuMs} ms)`);
81
+ return settle;
82
+ }
83
+ }
84
+
85
+ export type MemoryBeat = { at: number; rssMb: number; heapUsedMb: number; heapTotalMb: number; externalMb: number; arrayBuffersMb: number; youngMb: number | null; utilization: number | null; quietSettles: number; forcedSettles: number; settles: Settle[] };
86
+ const mb = (n: number) => Math.round(n / 1048576 * 10) / 10;
87
+ const round = (u: number | null) => u === null ? null : Math.round(u * 10000) / 10000;
88
+ /**
89
+ * The worker's memory as heartbeat.json reports it: process.memoryUsage(), V8's young generation, the last minute's mean
90
+ * event-loop utilization (is the 1 % quiet gate reachable on this host?), and the settles, quiet and forced counted.
91
+ */
92
+ export function memoryBeat(settler: HeapSettler): MemoryBeat {
93
+ const m = process.memoryUsage();
94
+ const young = getHeapSpaceStatistics().find(x => x.space_name === "new_space");
95
+ return { at: Date.now(), rssMb: mb(m.rss), heapUsedMb: mb(m.heapUsed), heapTotalMb: mb(m.heapTotal), externalMb: mb(m.external), arrayBuffersMb: mb(m.arrayBuffers), youngMb: young ? mb(young.space_size) : null, utilization: round(settler.utilization()), quietSettles: settler.quietSettles, forcedSettles: settler.forcedSettles, settles: settler.settles.slice(-5) };
96
+ }
97
+
98
+ /**
99
+ * The worker's memory watch, from the end of startup: the settler gets RSS and event-loop utilization every 5 s, and
100
+ * heartbeat.json gets a `memory` field every minute, so live numbers need no /proc. The rest of the heartbeat
101
+ * (`version`, `at`, `error`: the installer's probation) is kept as written.
102
+ */
103
+ export function watchMemory(o: { heartbeatFile: string; settler?: HeapSettler; sampleMs?: number; beatMs?: number }): { settler: HeapSettler; stop(): void } {
104
+ const settler = o.settler ?? new HeapSettler();
105
+ let elu = performance.eventLoopUtilization();
106
+ settler.observe(process.memoryUsage().rss / 1048576);
107
+ const sample = setInterval(() => {
108
+ const next = performance.eventLoopUtilization();
109
+ settler.observe(process.memoryUsage().rss / 1048576, performance.eventLoopUtilization(next, elu).utilization);
110
+ elu = next;
111
+ }, o.sampleMs ?? 5_000);
112
+ const beat = setInterval(() => void (async () => {
113
+ const current = JSON.parse(await readFile(o.heartbeatFile, "utf8").catch(() => "{}")) as Record<string, unknown>;
114
+ const temporary = `${o.heartbeatFile}.${process.pid}.tmp`;
115
+ await writeFile(temporary, JSON.stringify({ ...current, memory: memoryBeat(settler) }), { mode: 0o600 });
116
+ await rename(temporary, o.heartbeatFile);
117
+ })().catch(() => undefined), o.beatMs ?? 60_000);
118
+ sample.unref?.(); beat.unref?.();
119
+ return { settler, stop: () => { clearInterval(sample); clearInterval(beat); } };
20
120
  }
package/server/store.ts CHANGED
@@ -47,6 +47,8 @@ export class Store {
47
47
  */
48
48
  private holds = 0;
49
49
  private held: { volatile: boolean } | null = null;
50
+ /** Workspaces the store owns: validated copies, frozen, never a caller's object (committed-workspaces-are-owned). */
51
+ private owned = new WeakSet<Workspace>();
50
52
  private holdTimer: ReturnType<typeof setTimeout> | null = null;
51
53
  /**
52
54
  * an-ack-never-waits-on-the-disk, for state.json's own write: a batched write that fails keeps the state in memory,
@@ -72,7 +74,7 @@ export class Store {
72
74
  try { state = text === null ? { version: 1, workspaces: [] } : stateSchema.parse(JSON.parse(text)); }
73
75
  catch { throw new Error("Saved follow-up state could not be read. Restore state.json before continuing."); }
74
76
  // Loaded state is validated whole; it is also what the next write's per-workspace validation compares against.
75
- if (!this.state) { this.state = deepFreeze(state); this.saved = this.state; }
77
+ if (!this.state) { this.state = deepFreeze(state); this.saved = this.state; for (const w of state.workspaces) this.owned.add(w); }
76
78
  return this.state;
77
79
  }
78
80
  /** A private, mutable copy of the saved state (the old per-call read). */
@@ -109,7 +111,8 @@ export class Store {
109
111
  if (this.closing) return Promise.reject(stopping());
110
112
  const next = this.tail.then(async () => {
111
113
  if (this.sealed) throw stopping();
112
- const { value, next, volatile } = await work(await this.load());
114
+ const { value, next: draft, volatile } = await work(await this.load());
115
+ const next = draft && this.own(draft);
113
116
  // Accepted before the worker stopped: it commits if it finished before the stop's deadline, and is dropped if
114
117
  // it finished after (its work awaited a daemon that answered late).
115
118
  if (this.sealed) throw stopping();
@@ -120,8 +123,8 @@ export class Store {
120
123
  this.holdTimer ??= setTimeout(() => { this.holdTimer = null; void this.commitHeld(); }, MAX_HOLD_MS);
121
124
  (this.holdTimer as { unref?: () => void }).unref?.();
122
125
  } else if (next) {
123
- // Write-through keeps the old contract: a failed write leaves the saved state as it was. The draft may hold
124
- // objects owned by callers (observations), so only the validated copy the write returns is frozen.
126
+ // Write-through keeps the old contract: a failed write leaves the saved state as it was. Changed workspaces are
127
+ // already the store's own frozen copies (own, above); a workspace that fails validation rejects the commit.
125
128
  if (this.writeMs <= 0) this.state = await this.write(next);
126
129
  else { this.state = next; this.schedule(!!volatile); }
127
130
  await this.onChanged(this.state).catch(() => undefined);
@@ -243,7 +246,7 @@ export class Store {
243
246
  * Under FOLLOW_UP_STORE_FULL_VALIDATION (tests) every write is also parsed whole and must read the same.
244
247
  */
245
248
  private validate(state: State): State {
246
- const valid = new Set<Workspace>(this.saved?.workspaces ?? []);
249
+ const valid = this.owned;
247
250
  const { workspaces, ...top } = state;
248
251
  const head = topSchema.parse(top) as Record<string, unknown>;
249
252
  const checked = workspaces.map(w => valid.has(w) ? w : workspaceSchema.parse(w) as Workspace);
@@ -253,6 +256,26 @@ export class Store {
253
256
  if (process.env.FOLLOW_UP_STORE_FULL_VALIDATION && JSON.stringify(stateSchema.parse(state)) !== JSON.stringify(parsed)) throw new Error("Store: per-workspace validation disagrees with a full parse");
254
257
  return parsed;
255
258
  }
259
+ /**
260
+ * committed-workspaces-are-owned: a workspace a commit changed becomes the store's own validated, frozen copy here,
261
+ * at the commit, not at the next save. A draft may hold objects its caller still owns (an observation's snapshot);
262
+ * the copy is never one of them, so a later change by the caller can't reach the store, a write to a committed
263
+ * workspace throws (strict code), and an unchanged workspace keeps its object across commits, which is what
264
+ * ListCache and perSnapshot key on. The save's validation skips owned workspaces: they were parsed here.
265
+ * In production that write is silently ignored, not thrown: Paseo's wrapper (compiler-build.js wrapCommonJsBundle)
266
+ * evaluates the server bundle in sloppy mode, so only tests (strict) throw. Candidate upstream fix, one line: the
267
+ * wrapper's body starts with "use strict".
268
+ */
269
+ private own(next: State): State {
270
+ let changed = false;
271
+ const workspaces = next.workspaces.map(w => {
272
+ if (this.owned.has(w)) return w;
273
+ changed = true;
274
+ const copy = deepFreeze(workspaceSchema.parse(w) as Workspace);
275
+ this.owned.add(copy); return copy;
276
+ });
277
+ return changed ? { ...next, workspaces } : next;
278
+ }
256
279
  async lock(): Promise<() => Promise<void>> {
257
280
  await mkdir(this.directory, { recursive: true, mode: 0o700 });
258
281
  const path = join(this.directory, "worker.lock");