@bastani/atomic 0.9.72-alpha.1 → 0.9.73-alpha.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.
@@ -51,13 +51,7 @@ export function resolveBrokerEntrypoint(packageRoot: string): string {
51
51
  }
52
52
 
53
53
 
54
- const INTERCOM_DIR = getIntercomDirPath();
55
54
  const EXTENSION_DIR = resolveIntercomPackageRoot(import.meta.url);
56
- const BROKER_SOCKET = getBrokerSocketPath();
57
- const BROKER_PID = getBrokerPidPath();
58
- const BROKER_SPAWN_LOCK = getBrokerSpawnLockPath();
59
- const BROKER_LOG = getBrokerLogPath();
60
- const BROKER_START_ANNOUNCEMENT = getBrokerStartAnnouncementPath();
61
55
 
62
56
  function ensurePrivateDirectory(path: string): void {
63
57
  mkdirSync(path, { recursive: true, mode: 0o700 });
@@ -155,7 +149,7 @@ function quoteWindowsArg(value: string): string {
155
149
  return `"${value.replace(/"/g, '""')}"`;
156
150
  }
157
151
 
158
- export function getWindowsHiddenLauncherPath(intercomDir: string = INTERCOM_DIR): string {
152
+ export function getWindowsHiddenLauncherPath(intercomDir: string = getIntercomDirPath()): string {
159
153
  return join(intercomDir, "broker-launch.vbs");
160
154
  }
161
155
 
@@ -231,10 +225,10 @@ export function getBrokerLaunchSpec(
231
225
  brokerArgs: string[],
232
226
  extensionDir: string = EXTENSION_DIR,
233
227
  platform: NodeJS.Platform = process.platform,
234
- intercomDir: string = INTERCOM_DIR,
228
+ intercomDir: string = getIntercomDirPath(),
235
229
  nodePath: string = process.execPath,
236
230
  runtime: BrokerRuntime = getCurrentBrokerRuntime(),
237
- logPath: string = BROKER_LOG,
231
+ logPath: string = getBrokerLogPath(),
238
232
  ): BrokerLaunchSpec {
239
233
  if (platform === "win32") {
240
234
  const launcherPath = getWindowsHiddenLauncherPath(intercomDir);
@@ -312,7 +306,7 @@ export const BROKER_LOG_RELEASE_WAIT_MS = 1_000;
312
306
  * Preserve a bounded previous log across truncation. Returns false when a
313
307
  * Windows launcher holds the log through its stderr redirect.
314
308
  */
315
- function resetBrokerLog(logPath: string = BROKER_LOG): boolean {
309
+ function resetBrokerLog(logPath: string = getBrokerLogPath()): boolean {
316
310
  ensurePrivateDirectory(dirname(logPath));
317
311
  try {
318
312
  const previous = readBrokerLogTail(logPath);
@@ -347,7 +341,7 @@ async function resetBrokerLogOnceReleased(): Promise<boolean> {
347
341
  }
348
342
 
349
343
  /** Read at most {@link BROKER_LOG_TAIL_BYTES} trailing bytes of the broker log. */
350
- export function readBrokerLogTail(logPath: string = BROKER_LOG, maxBytes: number = BROKER_LOG_TAIL_BYTES): string {
344
+ export function readBrokerLogTail(logPath: string = getBrokerLogPath(), maxBytes: number = BROKER_LOG_TAIL_BYTES): string {
351
345
  let fd: number | undefined;
352
346
  try {
353
347
  fd = openSync(logPath, "r");
@@ -372,7 +366,7 @@ export function readBrokerLogTail(logPath: string = BROKER_LOG, maxBytes: number
372
366
  }
373
367
 
374
368
  /** Path plus bounded stderr tail, appended to every broker startup failure. */
375
- export function describeBrokerLog(logPath: string = BROKER_LOG): string {
369
+ export function describeBrokerLog(logPath: string = getBrokerLogPath()): string {
376
370
  const tail = readBrokerLogTail(logPath);
377
371
  if (tail.length === 0) return `Broker log: ${logPath} (empty)`;
378
372
  return `Broker log: ${logPath}\n--- broker stderr (last ${Buffer.byteLength(tail)} bytes) ---\n${tail}`;
@@ -388,7 +382,7 @@ export async function spawnBrokerIfNeeded(
388
382
  readyTimeoutMs: number = BROKER_READY_TIMEOUT_MS,
389
383
  extensionDir: string = EXTENSION_DIR,
390
384
  ): Promise<void> {
391
- ensurePrivateDirectory(INTERCOM_DIR);
385
+ ensurePrivateDirectory(getIntercomDirPath());
392
386
 
393
387
  if (await isBrokerRunning()) {
394
388
  return;
@@ -425,7 +419,7 @@ async function spawnBrokerHoldingLock(
425
419
  // The Windows launcher hides the broker's pid and exit, so there the broker announces its pid, which this watches.
426
420
  // Elsewhere the child is the broker and its exit event says how it ended.
427
421
  const announcement: BrokerStartAnnouncement | undefined =
428
- launch.kind === "windows-launcher" ? { path: BROKER_START_ANNOUNCEMENT, token: randomUUID() } : undefined;
422
+ launch.kind === "windows-launcher" ? { path: getBrokerStartAnnouncementPath(), token: randomUUID() } : undefined;
429
423
  if (announcement !== undefined) {
430
424
  try {
431
425
  unlinkSync(announcement.path);
@@ -444,7 +438,7 @@ async function spawnBrokerHoldingLock(
444
438
  // The Windows launcher redirects the broker's own stderr, so only the direct spawn
445
439
  // needs the descriptor. Node duplicates it during spawn, so the parent copy is closed
446
440
  // immediately afterwards rather than being held open for the broker's lifetime.
447
- const logFd = launch.kind === "direct" ? openSync(BROKER_LOG, "a") : undefined;
441
+ const logFd = launch.kind === "direct" ? openSync(getBrokerLogPath(), "a") : undefined;
448
442
  let child: ReturnType<typeof spawn>;
449
443
  try {
450
444
  child = spawn(launch.command, launch.args, getBrokerSpawnOptions(extensionDir, logFd ?? "ignore", announcement));
@@ -554,7 +548,7 @@ export async function upgradeBroker(
554
548
  own: BrokerProtocolRange = BROKER_PROTOCOL,
555
549
  stopTimeoutMs: number = BROKER_UPGRADE_STOP_TIMEOUT_MS,
556
550
  ): Promise<BrokerUpgradeOutcome> {
557
- ensurePrivateDirectory(INTERCOM_DIR);
551
+ ensurePrivateDirectory(getIntercomDirPath());
558
552
  const acquired = await acquireSpawnLockWithin(readyTimeoutMs + stopTimeoutMs);
559
553
  if (acquired === undefined) return "busy";
560
554
  let lockOwner = acquired;
@@ -564,7 +558,7 @@ export async function upgradeBroker(
564
558
  return spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, readyTimeoutMs, extensionDir, false);
565
559
  };
566
560
  try {
567
- const answer = await controlRequest(BROKER_SOCKET, "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
561
+ const answer = await controlRequest(getBrokerSocketPath(), "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
568
562
  if (!answer.connected) {
569
563
  await spawnHoldingLock();
570
564
  return "started";
@@ -580,7 +574,7 @@ export async function upgradeBroker(
580
574
  if (report.storage?.digest !== successorStorageDigest()) return "storage-differs";
581
575
  const failed = (phase: "stop" | "start", cause?: Error): IntercomBrokerUpgradeError =>
582
576
  new IntercomBrokerUpgradeError({ phase, previousPid: report.pid, previousProtocolMax: running.max }, { cause });
583
- if ((await requestBrokerShutdown(BROKER_SOCKET)) === "unanswered") throw failed("stop");
577
+ if ((await requestBrokerShutdown(getBrokerSocketPath())) === "unanswered") throw failed("stop");
584
578
  try {
585
579
  await waitForBrokerExit(report.pid, stopTimeoutMs, () => {
586
580
  lockOwner = renewSpawnLock(lockOwner);
@@ -605,7 +599,7 @@ export async function upgradeBroker(
605
599
 
606
600
  /** The digest of the shared storage selection a broker started from this process reads, as its `broker_status` reports it. */
607
601
  function successorStorageDigest(): string | undefined {
608
- const setting = readSharedStorageSetting(dirname(INTERCOM_DIR), {
602
+ const setting = readSharedStorageSetting(dirname(getIntercomDirPath()), {
609
603
  [BROKER_STORAGE_ENV]: processSharedStorageSelection() ?? "",
610
604
  });
611
605
  return setting === undefined ? undefined : sharedStorageDigest(setting);
@@ -626,10 +620,10 @@ async function isBrokerRunning(): Promise<boolean> {
626
620
  return true;
627
621
  }
628
622
 
629
- if (!existsSync(BROKER_PID)) return false;
623
+ if (!existsSync(getBrokerPidPath())) return false;
630
624
 
631
625
  try {
632
- const pid = parseInt(readFileSync(BROKER_PID, "utf-8").trim(), 10);
626
+ const pid = parseInt(readFileSync(getBrokerPidPath(), "utf-8").trim(), 10);
633
627
  if (!Number.isFinite(pid)) return false;
634
628
  process.kill(pid, 0);
635
629
  return checkSocketConnectable();
@@ -640,14 +634,14 @@ async function isBrokerRunning(): Promise<boolean> {
640
634
  }
641
635
 
642
636
  function checkSocketConnectable(): Promise<boolean> {
643
- return isSocketAnswering(BROKER_SOCKET);
637
+ return isSocketAnswering(getBrokerSocketPath());
644
638
  }
645
639
 
646
640
  /** Records the still-starting broker on the lock so staleness follows that process instead of the spawner. */
647
641
  function handSpawnLockToBroker(pid: number | undefined, owner: string): boolean {
648
642
  if (pid === undefined || !ownsSpawnLock(owner)) return false;
649
643
  try {
650
- appendFileSync(BROKER_SPAWN_LOCK, `${pid}\n`);
644
+ appendFileSync(getBrokerSpawnLockPath(), `${pid}\n`);
651
645
  return true;
652
646
  } catch {
653
647
  // The startup error must still reach the caller; an unrecorded lock is released like any other.
@@ -667,17 +661,17 @@ function renewSpawnLock(owner: string, nowMs: number = Date.now()): string {
667
661
  const writtenAt = Number.parseInt(owner.split("\n")[1] ?? "", 10);
668
662
  if (nowMs - writtenAt < SPAWN_LOCK_RENEW_AFTER_MS || !ownsSpawnLock(owner)) return owner;
669
663
  const renewed = `${process.pid}\n${nowMs}\n`;
670
- const staged = `${BROKER_SPAWN_LOCK}.${process.pid}.renew`;
664
+ const staged = `${getBrokerSpawnLockPath()}.${process.pid}.renew`;
671
665
  try {
672
666
  writeFileSync(staged, renewed);
673
- renameSync(staged, BROKER_SPAWN_LOCK);
667
+ renameSync(staged, getBrokerSpawnLockPath());
674
668
  return renewed;
675
669
  } catch {
676
670
  return owner;
677
671
  }
678
672
  }
679
673
 
680
- function ownsSpawnLock(owner: string, lockPath: string = BROKER_SPAWN_LOCK): boolean {
674
+ function ownsSpawnLock(owner: string, lockPath: string = getBrokerSpawnLockPath()): boolean {
681
675
  try {
682
676
  return readFileSync(lockPath, "utf-8").startsWith(owner);
683
677
  } catch {
@@ -691,7 +685,7 @@ function acquireSpawnLock(): string | undefined {
691
685
  for (let attempt = 0; attempt < maxRetries; attempt++) {
692
686
  const owner = `${process.pid}\n${Date.now()}\n`;
693
687
  try {
694
- writeFileSync(BROKER_SPAWN_LOCK, owner, { flag: "wx" });
688
+ writeFileSync(getBrokerSpawnLockPath(), owner, { flag: "wx" });
695
689
  return owner;
696
690
  } catch (error) {
697
691
  if (!(error instanceof Error) || (error as NodeJS.ErrnoException).code !== "EEXIST") {
@@ -699,7 +693,7 @@ function acquireSpawnLock(): string | undefined {
699
693
  }
700
694
  if (isSpawnLockStale()) {
701
695
  try {
702
- unlinkSync(BROKER_SPAWN_LOCK);
696
+ unlinkSync(getBrokerSpawnLockPath());
703
697
  } catch {
704
698
  // If we can't delete the stale lock, retry a few times before giving up
705
699
  }
@@ -724,7 +718,7 @@ function isProcessAlive(pid: number): boolean {
724
718
  * A lock is stale once the broker it recorded is gone, or, while no broker is recorded, once its
725
719
  * spawner is gone. A live broker keeps the lock even if its spawner died, until the age backstop.
726
720
  */
727
- export function isSpawnLockStale(lockPath: string = BROKER_SPAWN_LOCK, nowMs: number = Date.now()): boolean {
721
+ export function isSpawnLockStale(lockPath: string = getBrokerSpawnLockPath(), nowMs: number = Date.now()): boolean {
728
722
  if (!existsSync(lockPath)) {
729
723
  return false;
730
724
  }
@@ -745,7 +739,7 @@ export function isSpawnLockStale(lockPath: string = BROKER_SPAWN_LOCK, nowMs: nu
745
739
  }
746
740
 
747
741
  /** Removes the lock only while it is still the one `owner` wrote; a spawner that replaced a stale lock keeps its own. */
748
- export function releaseSpawnLock(owner: string, lockPath: string = BROKER_SPAWN_LOCK): void {
742
+ export function releaseSpawnLock(owner: string, lockPath: string = getBrokerSpawnLockPath()): void {
749
743
  if (!ownsSpawnLock(owner, lockPath)) return;
750
744
  try {
751
745
  unlinkSync(lockPath);
@@ -1835,8 +1835,8 @@ function isLostBrokerSignature(error) {
1835
1835
  const code = error.code;
1836
1836
  return code === "ENOENT" || code === "ECONNRESET" || code === "EPIPE";
1837
1837
  }
1838
- async function classifyRegistrationFailure(error) {
1839
- if (!isLostBrokerSignature(error) || await isSocketAnswering(BROKER_SOCKET))
1838
+ async function classifyRegistrationFailure(error, socketPath) {
1839
+ if (!isLostBrokerSignature(error) || await isSocketAnswering(socketPath))
1840
1840
  return error;
1841
1841
  return new IntercomBrokerRetiringError(`Intercom broker went away before it registered this session: ${error.message}`, {
1842
1842
  cause: error
@@ -1861,7 +1861,7 @@ function isWorkflowFutureStageRosterEntries(value) {
1861
1861
  function isWorkflowStageRosterEntries(value) {
1862
1862
  return Array.isArray(value) && value.every((entry) => typeof entry === "object" && entry !== null && entry.kind === "workflow-stage" && typeof entry.runId === "string" && typeof entry.stageId === "string" && typeof entry.stageName === "string" && typeof entry.target === "string" && (entry.lifecycle === "pending" || entry.lifecycle === "running") && typeof entry.group === "string" && (entry.sessionId === undefined || typeof entry.sessionId === "string"));
1863
1863
  }
1864
- var BROKER_SOCKET, BROKER_CONNECT_TIMEOUT_MS = 1e4, PENDING_STAGE_ROUTE_ACK_TIMEOUT_MS = 1e4, GROUP_REQUEST_TIMEOUT_MS = 5000, PRESENCE_ACK_TIMEOUT_MS = 5000, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS = 5000, BROKER_BACKLOG_RETRIES = 6, BROKER_BACKLOG_RETRY_BASE_MS = 25, ConnectionClosedBeforeRegistrationError, HELD_SEND_GRACE_MS = 5000, IntercomPendingStageRouteRefusedError, PENDING_STAGE_ROUTE_REFUSAL_CODES, IntercomClient;
1864
+ var BROKER_CONNECT_TIMEOUT_MS = 1e4, PENDING_STAGE_ROUTE_ACK_TIMEOUT_MS = 1e4, GROUP_REQUEST_TIMEOUT_MS = 5000, PRESENCE_ACK_TIMEOUT_MS = 5000, RESTORING_RECIPIENT_REQUEST_TIMEOUT_MS = 5000, BROKER_BACKLOG_RETRIES = 6, BROKER_BACKLOG_RETRY_BASE_MS = 25, ConnectionClosedBeforeRegistrationError, HELD_SEND_GRACE_MS = 5000, IntercomPendingStageRouteRefusedError, PENDING_STAGE_ROUTE_REFUSAL_CODES, IntercomClient;
1865
1865
  var init_client = __esm(() => {
1866
1866
  init_broker_status();
1867
1867
  init_paths();
@@ -1880,7 +1880,6 @@ var init_client = __esm(() => {
1880
1880
  init_workflow_prediction_fields();
1881
1881
  init_released_child_errors();
1882
1882
  init_released_reply_errors();
1883
- BROKER_SOCKET = getBrokerSocketPath();
1884
1883
  ConnectionClosedBeforeRegistrationError = class ConnectionClosedBeforeRegistrationError extends Error {
1885
1884
  constructor() {
1886
1885
  super("Connection closed before registration");
@@ -1907,6 +1906,7 @@ var init_client = __esm(() => {
1907
1906
  preferredSessionId;
1908
1907
  acknowledgesReceipt;
1909
1908
  connectTimeoutMs;
1909
+ brokerSocketPath;
1910
1910
  brokerAcknowledgesReceipt = false;
1911
1911
  brokerAcknowledgesPendingStageRoutes = false;
1912
1912
  multiplexesPendingStageRoutes;
@@ -1983,6 +1983,7 @@ var init_client = __esm(() => {
1983
1983
  this.acknowledgesReceipt = options.acknowledgesReceipt === true;
1984
1984
  this.connectTimeoutMs = options.connectTimeoutMs ?? BROKER_CONNECT_TIMEOUT_MS;
1985
1985
  this.multiplexesPendingStageRoutes = options.multiplexesPendingStageRoutes === true;
1986
+ this.brokerSocketPath = options.brokerSocketPath ?? getBrokerSocketPath();
1986
1987
  }
1987
1988
  failPending(error) {
1988
1989
  this.pendingSends.rejectAll(error);
@@ -2065,7 +2066,7 @@ var init_client = __esm(() => {
2065
2066
  if (!(error instanceof Error))
2066
2067
  throw error;
2067
2068
  if (!isBacklogRefusal(error) || retry >= BROKER_BACKLOG_RETRIES) {
2068
- const classified = await classifyRegistrationFailure(error);
2069
+ const classified = await classifyRegistrationFailure(error, this.brokerSocketPath);
2069
2070
  if (attempt.signal.aborted)
2070
2071
  throw connectAborted();
2071
2072
  if (expectedRouting?.verify === true && classified instanceof ConnectionClosedBeforeRegistrationError) {
@@ -2090,7 +2091,7 @@ var init_client = __esm(() => {
2090
2091
  this._groups = normalizeGroups(session.groups, session.group);
2091
2092
  this.registrationExpectedRouting = expectedRouting;
2092
2093
  return new Promise((resolve, reject) => {
2093
- const socket = net2.connect(BROKER_SOCKET);
2094
+ const socket = net2.connect(this.brokerSocketPath);
2094
2095
  this.socket = socket;
2095
2096
  this.disconnectError = null;
2096
2097
  let settled = false;
@@ -3465,7 +3466,7 @@ function getDefaultBrokerCommandParts(brokerPath, extensionDir, runtimePath, run
3465
3466
  function quoteWindowsArg(value) {
3466
3467
  return `"${value.replace(/"/g, '""')}"`;
3467
3468
  }
3468
- function getWindowsHiddenLauncherPath(intercomDir = INTERCOM_DIR) {
3469
+ function getWindowsHiddenLauncherPath(intercomDir = getIntercomDirPath()) {
3469
3470
  return join3(intercomDir, "broker-launch.vbs");
3470
3471
  }
3471
3472
  function usesDefaultBrokerCommand(brokerCommand, brokerArgs) {
@@ -3497,7 +3498,7 @@ function writeWindowsHiddenLauncher(commandLine, launcherPath = getWindowsHidden
3497
3498
  writeFileSync2(launcherPath, getWindowsHiddenLauncherScript(commandLine), "utf-8");
3498
3499
  return launcherPath;
3499
3500
  }
3500
- function getBrokerLaunchSpec(brokerPath, brokerCommand, brokerArgs, extensionDir = EXTENSION_DIR, platform = process.platform, intercomDir = INTERCOM_DIR, nodePath = process.execPath, runtime = getCurrentBrokerRuntime(), logPath = BROKER_LOG) {
3501
+ function getBrokerLaunchSpec(brokerPath, brokerCommand, brokerArgs, extensionDir = EXTENSION_DIR, platform = process.platform, intercomDir = getIntercomDirPath(), nodePath = process.execPath, runtime = getCurrentBrokerRuntime(), logPath = getBrokerLogPath()) {
3501
3502
  if (platform === "win32") {
3502
3503
  const launcherPath = getWindowsHiddenLauncherPath(intercomDir);
3503
3504
  return {
@@ -3536,7 +3537,7 @@ function getBrokerSpawnOptions(extensionDir = EXTENSION_DIR, stderr = "ignore",
3536
3537
  windowsHide: true
3537
3538
  };
3538
3539
  }
3539
- function resetBrokerLog(logPath = BROKER_LOG) {
3540
+ function resetBrokerLog(logPath = getBrokerLogPath()) {
3540
3541
  ensurePrivateDirectory(dirname(logPath));
3541
3542
  try {
3542
3543
  const previous = readBrokerLogTail(logPath);
@@ -3566,7 +3567,7 @@ async function resetBrokerLogOnceReleased() {
3566
3567
  }
3567
3568
  return true;
3568
3569
  }
3569
- function readBrokerLogTail(logPath = BROKER_LOG, maxBytes = BROKER_LOG_TAIL_BYTES) {
3570
+ function readBrokerLogTail(logPath = getBrokerLogPath(), maxBytes = BROKER_LOG_TAIL_BYTES) {
3570
3571
  let fd;
3571
3572
  try {
3572
3573
  fd = openSync(logPath, "r");
@@ -3587,7 +3588,7 @@ function readBrokerLogTail(logPath = BROKER_LOG, maxBytes = BROKER_LOG_TAIL_BYTE
3587
3588
  }
3588
3589
  }
3589
3590
  }
3590
- function describeBrokerLog(logPath = BROKER_LOG) {
3591
+ function describeBrokerLog(logPath = getBrokerLogPath()) {
3591
3592
  const tail = readBrokerLogTail(logPath);
3592
3593
  if (tail.length === 0)
3593
3594
  return `Broker log: ${logPath} (empty)`;
@@ -3599,7 +3600,7 @@ function toError3(error) {
3599
3600
  return error instanceof Error ? error : new Error(String(error));
3600
3601
  }
3601
3602
  async function spawnBrokerIfNeeded(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_READY_TIMEOUT_MS, extensionDir = EXTENSION_DIR) {
3602
- ensurePrivateDirectory(INTERCOM_DIR);
3603
+ ensurePrivateDirectory(getIntercomDirPath());
3603
3604
  if (await isBrokerRunning()) {
3604
3605
  return;
3605
3606
  }
@@ -3618,7 +3619,7 @@ async function spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, read
3618
3619
  }
3619
3620
  const brokerPath = resolveBrokerEntrypoint(extensionDir);
3620
3621
  const launch = getBrokerLaunchSpec(brokerPath, brokerCommand, brokerArgs, extensionDir);
3621
- const announcement = launch.kind === "windows-launcher" ? { path: BROKER_START_ANNOUNCEMENT, token: randomUUID4() } : undefined;
3622
+ const announcement = launch.kind === "windows-launcher" ? { path: getBrokerStartAnnouncementPath(), token: randomUUID4() } : undefined;
3622
3623
  if (announcement !== undefined) {
3623
3624
  try {
3624
3625
  unlinkSync2(announcement.path);
@@ -3631,7 +3632,7 @@ async function spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, read
3631
3632
  await waitForBroker(readyTimeoutMs);
3632
3633
  return;
3633
3634
  }
3634
- const logFd = launch.kind === "direct" ? openSync(BROKER_LOG, "a") : undefined;
3635
+ const logFd = launch.kind === "direct" ? openSync(getBrokerLogPath(), "a") : undefined;
3635
3636
  let child;
3636
3637
  try {
3637
3638
  child = spawn(launch.command, launch.args, getBrokerSpawnOptions(extensionDir, logFd ?? "ignore", announcement));
@@ -3685,7 +3686,7 @@ ${describeBrokerLog()}`);
3685
3686
  }
3686
3687
  }
3687
3688
  async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_READY_TIMEOUT_MS, extensionDir = EXTENSION_DIR, own = BROKER_PROTOCOL, stopTimeoutMs = BROKER_UPGRADE_STOP_TIMEOUT_MS) {
3688
- ensurePrivateDirectory(INTERCOM_DIR);
3689
+ ensurePrivateDirectory(getIntercomDirPath());
3689
3690
  const acquired = await acquireSpawnLockWithin(readyTimeoutMs + stopTimeoutMs);
3690
3691
  if (acquired === undefined)
3691
3692
  return "busy";
@@ -3696,7 +3697,7 @@ async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_
3696
3697
  return spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, readyTimeoutMs, extensionDir, false);
3697
3698
  };
3698
3699
  try {
3699
- const answer = await controlRequest(BROKER_SOCKET2, "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
3700
+ const answer = await controlRequest(getBrokerSocketPath(), "broker_status", "broker_status", BROKER_CONTROL_TIMEOUT_MS);
3700
3701
  if (!answer.connected) {
3701
3702
  await spawnHoldingLock();
3702
3703
  return "started";
@@ -3711,7 +3712,7 @@ async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_
3711
3712
  if (report.storage?.digest !== successorStorageDigest())
3712
3713
  return "storage-differs";
3713
3714
  const failed = (phase, cause) => new IntercomBrokerUpgradeError({ phase, previousPid: report.pid, previousProtocolMax: running.max }, { cause });
3714
- if (await requestBrokerShutdown(BROKER_SOCKET2) === "unanswered")
3715
+ if (await requestBrokerShutdown(getBrokerSocketPath()) === "unanswered")
3715
3716
  throw failed("stop");
3716
3717
  try {
3717
3718
  await waitForBrokerExit(report.pid, stopTimeoutMs, () => {
@@ -3736,7 +3737,7 @@ async function upgradeBroker(brokerCommand, brokerArgs, readyTimeoutMs = BROKER_
3736
3737
  }
3737
3738
  }
3738
3739
  function successorStorageDigest() {
3739
- const setting = readSharedStorageSetting(dirname(INTERCOM_DIR), {
3740
+ const setting = readSharedStorageSetting(dirname(getIntercomDirPath()), {
3740
3741
  [BROKER_STORAGE_ENV]: processSharedStorageSelection() ?? ""
3741
3742
  });
3742
3743
  return setting === undefined ? undefined : sharedStorageDigest(setting);
@@ -3754,10 +3755,10 @@ async function isBrokerRunning() {
3754
3755
  if (await checkSocketConnectable()) {
3755
3756
  return true;
3756
3757
  }
3757
- if (!existsSync(BROKER_PID))
3758
+ if (!existsSync(getBrokerPidPath()))
3758
3759
  return false;
3759
3760
  try {
3760
- const pid = parseInt(readFileSync3(BROKER_PID, "utf-8").trim(), 10);
3761
+ const pid = parseInt(readFileSync3(getBrokerPidPath(), "utf-8").trim(), 10);
3761
3762
  if (!Number.isFinite(pid))
3762
3763
  return false;
3763
3764
  process.kill(pid, 0);
@@ -3767,13 +3768,13 @@ async function isBrokerRunning() {
3767
3768
  }
3768
3769
  }
3769
3770
  function checkSocketConnectable() {
3770
- return isSocketAnswering(BROKER_SOCKET2);
3771
+ return isSocketAnswering(getBrokerSocketPath());
3771
3772
  }
3772
3773
  function handSpawnLockToBroker(pid, owner) {
3773
3774
  if (pid === undefined || !ownsSpawnLock(owner))
3774
3775
  return false;
3775
3776
  try {
3776
- appendFileSync(BROKER_SPAWN_LOCK, `${pid}
3777
+ appendFileSync(getBrokerSpawnLockPath(), `${pid}
3777
3778
  `);
3778
3779
  return true;
3779
3780
  } catch {
@@ -3788,16 +3789,16 @@ function renewSpawnLock(owner, nowMs = Date.now()) {
3788
3789
  const renewed = `${process.pid}
3789
3790
  ${nowMs}
3790
3791
  `;
3791
- const staged = `${BROKER_SPAWN_LOCK}.${process.pid}.renew`;
3792
+ const staged = `${getBrokerSpawnLockPath()}.${process.pid}.renew`;
3792
3793
  try {
3793
3794
  writeFileSync2(staged, renewed);
3794
- renameSync(staged, BROKER_SPAWN_LOCK);
3795
+ renameSync(staged, getBrokerSpawnLockPath());
3795
3796
  return renewed;
3796
3797
  } catch {
3797
3798
  return owner;
3798
3799
  }
3799
3800
  }
3800
- function ownsSpawnLock(owner, lockPath = BROKER_SPAWN_LOCK) {
3801
+ function ownsSpawnLock(owner, lockPath = getBrokerSpawnLockPath()) {
3801
3802
  try {
3802
3803
  return readFileSync3(lockPath, "utf-8").startsWith(owner);
3803
3804
  } catch {
@@ -3811,7 +3812,7 @@ function acquireSpawnLock() {
3811
3812
  ${Date.now()}
3812
3813
  `;
3813
3814
  try {
3814
- writeFileSync2(BROKER_SPAWN_LOCK, owner, { flag: "wx" });
3815
+ writeFileSync2(getBrokerSpawnLockPath(), owner, { flag: "wx" });
3815
3816
  return owner;
3816
3817
  } catch (error) {
3817
3818
  if (!(error instanceof Error) || error.code !== "EEXIST") {
@@ -3819,7 +3820,7 @@ ${Date.now()}
3819
3820
  }
3820
3821
  if (isSpawnLockStale()) {
3821
3822
  try {
3822
- unlinkSync2(BROKER_SPAWN_LOCK);
3823
+ unlinkSync2(getBrokerSpawnLockPath());
3823
3824
  } catch {}
3824
3825
  continue;
3825
3826
  }
@@ -3836,7 +3837,7 @@ function isProcessAlive2(pid) {
3836
3837
  return error.code === "EPERM";
3837
3838
  }
3838
3839
  }
3839
- function isSpawnLockStale(lockPath = BROKER_SPAWN_LOCK, nowMs = Date.now()) {
3840
+ function isSpawnLockStale(lockPath = getBrokerSpawnLockPath(), nowMs = Date.now()) {
3840
3841
  if (!existsSync(lockPath)) {
3841
3842
  return false;
3842
3843
  }
@@ -3855,7 +3856,7 @@ function isSpawnLockStale(lockPath = BROKER_SPAWN_LOCK, nowMs = Date.now()) {
3855
3856
  return true;
3856
3857
  }
3857
3858
  }
3858
- function releaseSpawnLock(owner, lockPath = BROKER_SPAWN_LOCK) {
3859
+ function releaseSpawnLock(owner, lockPath = getBrokerSpawnLockPath()) {
3859
3860
  if (!ownsSpawnLock(owner, lockPath))
3860
3861
  return;
3861
3862
  try {
@@ -3883,7 +3884,7 @@ ${describeBrokerLog()}`);
3883
3884
  ` + "The broker did not answer on its socket in time; it may still be starting, which a busy machine or an empty jiti " + "cache slows. Try again, or raise `brokerStartupTimeoutMs` in the Intercom config.json (default " + `${BROKER_READY_TIMEOUT_MS} ms).
3884
3885
  ${describeBrokerLog()}`);
3885
3886
  }
3886
- var INTERCOM_DIR, EXTENSION_DIR, BROKER_SOCKET2, BROKER_PID, BROKER_SPAWN_LOCK, BROKER_LOG, BROKER_START_ANNOUNCEMENT, BROKER_LOG_TAIL_BYTES, BROKER_POLL_INITIAL_INTERVAL_MS = 10, BROKER_POLL_MAX_INTERVAL_MS = 100, BROKER_SPAWN_LOCK_MAX_AGE_MS = 60000, INTERNAL_INTERCOM_BROKER_ARG = "--atomic-internal-intercom-broker", BROKER_LOG_RELEASE_WAIT_MS = 1000, UPGRADE_LOCK_POLL_MS = 50, SPAWN_LOCK_RENEW_AFTER_MS = 1e4;
3887
+ var EXTENSION_DIR, BROKER_LOG_TAIL_BYTES, BROKER_POLL_INITIAL_INTERVAL_MS = 10, BROKER_POLL_MAX_INTERVAL_MS = 100, BROKER_SPAWN_LOCK_MAX_AGE_MS = 60000, INTERNAL_INTERCOM_BROKER_ARG = "--atomic-internal-intercom-broker", BROKER_LOG_RELEASE_WAIT_MS = 1000, UPGRADE_LOCK_POLL_MS = 50, SPAWN_LOCK_RENEW_AFTER_MS = 1e4;
3887
3888
  var init_spawn = __esm(() => {
3888
3889
  init_socket_liveness();
3889
3890
  init_start_announcement();
@@ -3893,13 +3894,7 @@ var init_spawn = __esm(() => {
3893
3894
  init_protocol_version();
3894
3895
  init_shared_storage_setting();
3895
3896
  init_paths();
3896
- INTERCOM_DIR = getIntercomDirPath();
3897
3897
  EXTENSION_DIR = resolveIntercomPackageRoot(import.meta.url);
3898
- BROKER_SOCKET2 = getBrokerSocketPath();
3899
- BROKER_PID = getBrokerPidPath();
3900
- BROKER_SPAWN_LOCK = getBrokerSpawnLockPath();
3901
- BROKER_LOG = getBrokerLogPath();
3902
- BROKER_START_ANNOUNCEMENT = getBrokerStartAnnouncementPath();
3903
3898
  BROKER_LOG_TAIL_BYTES = 8 * 1024;
3904
3899
  });
3905
3900
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/intercom",
3
- "version": "0.9.72-alpha.1",
3
+ "version": "0.9.73-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension providing a private coordination channel between parent and child agent sessions. Fork of: https://github.com/nicobailon/pi-intercom",
6
6
  "contributors": [
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.72] - 2026-11-08
11
+
12
+ ### Fixed
13
+
14
+ - Streamable HTTP SSE streams framed with a lone CR line ending are now split into events. Lines end at CR, LF or CRLF, a CRLF split across chunks counts once, and a CR-terminated event is delivered while the stream stays open. Before, such a stream was parsed as one line at EOF and a tool call answered this way failed with "stream ended without a response" (upstream [#11775](https://github.com/earendil-works/pi/pull/11775))
15
+ - stdio MCP servers that send a large message in many chunks no longer slow down quadratically: the transport keeps an incomplete message as a list of chunks and joins it once when its newline arrives, instead of copying and rescanning the whole buffer on every chunk. A 1 MiB message in 4 KiB chunks now takes one `Buffer.concat` instead of 257 (upstream [#11791](https://github.com/earendil-works/pi/pull/11791))
16
+ - `OAuthCallbackServer.close()` no longer waits for minutes when the browser keeps an unused connection open to the callback port, for example a preconnect. It now closes the remaining connections (upstream [#11311](https://github.com/earendil-works/pi/issues/11311))
17
+
10
18
  ## [0.9.72-alpha.1] - 2026-11-08
11
19
 
12
20
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/mcp",
3
- "version": "0.9.72-alpha.1",
3
+ "version": "0.9.73-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic's pi-compatible MCP integration for server connections, OAuth, tools, resources, and terminal management.",
6
6
  "contributors": [
@@ -2,6 +2,37 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.9.72] - 2026-11-08
6
+
7
+ Background subagents that wait let go of their sessions.
8
+
9
+ - **Released while waiting.** A background subagent waiting on a long tool call, a question or a shell task releases its session and memory, and wakes with the result, also after a restart of its owner or on another machine ([#4326](https://github.com/bastani-inc/atomic/issues/4326), [#4329](https://github.com/bastani-inc/atomic/issues/4329), [#4502](https://github.com/bastani-inc/atomic/issues/4502)).
10
+ - **Clear start failures.** A child that does not start in time fails with a `SessionStartTimeoutError` naming what blocked it, and `sessionStartTimeoutMs` sets the budget ([#4319](https://github.com/bastani-inc/atomic/issues/4319)).
11
+ - **Message running children.** Type into a child's `/tasks` transcript to message it ([#4521](https://github.com/bastani-inc/atomic/issues/4521)).
12
+
13
+ ### Added
14
+
15
+ - A released background subagent is woken in the restores of the session or run that launched it, and in those its owner recorded since. When it is woken on another machine, its recorded directory is mapped through them before anything checks that it exists, and its own session is prepared as a woken session is: each checkout it worked in on this machine stays, and the others are restored from its snapshots into worktrees there. A child that still cannot be restored stays the typed unrestorable outcome. See [Resume on any machine](../coding-agent/docs/guides/resume-on-any-machine.md) ([#4329](https://github.com/bastani-inc/atomic/issues/4329))
16
+ - `sessionStartTimeoutMs` in the subagent `config.json` sets how long a child may take to start (default 5 minutes). An invalid value is reported when the config loads and the default applies ([#4319](https://github.com/bastani-inc/atomic/issues/4319))
17
+ - A background subagent waiting on a long-running detachable tool call is released instead of holding a live session: after a minute its task stops as a resumable stop, its record says `released` and what it waits on, and it holds no session, task or connection. The call's result, an Intercom message or ask sent to it, or `subagent({ action: "resume" })` wakes it from its saved session; `pause` and `quit` keep it stopped and keep arriving results for its resume, and `status` lists it as released ([#4326](https://github.com/bastani-inc/atomic/issues/4326))
18
+ - A released subagent stays addressable across Intercom reconnects and restarts of its owner: the owner reserves its released children again whenever Intercom connects and parks them while they are paused or quit. A wake that cannot find, restore or record a child fails with a typed `ReleasedChildError` (`child-record-missing`, `child-unrestorable`, `record-append-failed` or `hold-failed`) whose hint names the fix, and a result that arrives while a child is being released is recorded first, so the wake never finds the child still running ([#4326](https://github.com/bastani-inc/atomic/issues/4326))
19
+ - Only background subagents are released; a foreground subagent stays live while its parent's turn waits for it. A released subagent keeps the steering and follow-up messages it had queued and not read, and reads them once, in order, when it wakes; a result that arrives while a woken subagent runs is kept and wakes it again when that run ends; results held for a woken subagent stay saved until its session has them; and a wake reopens the subagent's session only after its previous run has closed it. While it waits, a released subagent keeps nothing in its owner's process but its latest record ([#4326](https://github.com/bastani-inc/atomic/issues/4326))
20
+ - A shell task a released subagent started that finishes while it is released wakes it with the task's completion notice, which is kept for its `resume` while it is paused or quit, instead of going to the session that launched it ([#4326](https://github.com/bastani-inc/atomic/issues/4326))
21
+ - A released subagent survives a failed wake and a restart of its owner. A wake that fails keeps every result it carried in the subagent's record with a typed failure (`ReleasedChildError` code, reason and hint, a new `wake-failed` code for untyped failures) that `status` shows; the launching session gets one notice, and `resume` delivers the kept results. When the launching session is reopened after Atomic restarts, each detachable call a released subagent still waited on starts again under its call id and the subagent is released again without a model turn, so the new result wakes it; one already holding its call's result is woken with it instead. Released subagents of one session are woken at most `parallel.runningCapacity` at a time ([#4326](https://github.com/bastani-inc/atomic/issues/4326))
22
+ - A `resume` or a result that arrives while a released subagent is being restored is delivered after that wake, in order, instead of being lost, and a child record that could not be saved is reported once to the launching session in `status` ([#4326](https://github.com/bastani-inc/atomic/issues/4326))
23
+ - A child with an Intercom target accepts messages typed into its `/tasks` transcript, delivered through the parent's Intercom relay, and its transcript shows when it is compacting ([#4521](https://github.com/bastani-inc/atomic/issues/4521))
24
+
25
+ ### Changed
26
+
27
+ - A released subagent keeps one small entry of a fixed size in the session that launched it, instead of a copy of its whole latest record, so its task, held messages and held results no longer stay in memory while it waits; they are read from the session's history when it wakes. Each record a subagent saves is now complete, and a session saved by an older Atomic gets one complete record per subagent the first time it is opened. A released subagent launched in a parallel run no longer keeps that run's scheduler in memory; when it wakes, it is limited by `parallel.runningCapacity` like any other released subagent. A record that cannot be read fails with the new `ReleasedChildError` code `child-record-unreadable` ([#4395](https://github.com/bastani-inc/atomic/issues/4395))
28
+ - A released background subagent whose session is in an in-memory session store, such as a forked child's, no longer keeps its history in memory while it waits: its history moves to a file under the agent directory and its wake reads it back. A wake or resume whose read of that history fails in a way that passes (a retryable storage error, such as running out of file descriptors) no longer reports the subagent gone: the wake fails with the retryable `ReleasedChildError` code `wake-failed`, the subagent stays released with its results kept, and a later wake or resume restores it ([#4502](https://github.com/bastani-inc/atomic/issues/4502))
29
+ - A child that does not start within its start budget fails with a `SessionStartTimeoutError` whose `phase` names what blocked it (`admission`, `setup`, `dispatch` or `event-loop`), instead of a message that always blamed session creation and a resource-admission wait. The child's result carries it as `startError`, and the budget now also covers dispatching the child's task ([#4319](https://github.com/bastani-inc/atomic/issues/4319))
30
+
31
+ ### Fixed
32
+
33
+ - SDK subagent launches return their start timeout even when an extension's `input` or `before_agent_start` handler never settles. Session cleanup continues separately instead of holding the timeout result ([#4319](https://github.com/bastani-inc/atomic/issues/4319))
34
+ - A background subagent that was woken when its owner's process died is released again when the reopened session restores it, instead of ending with an error at its next release. The message Intercom had saved for it just before the crash is read once, after the call it was waiting on gets its result, instead of starting a turn on top of that call ([#4488](https://github.com/bastani-inc/atomic/issues/4488))
35
+
5
36
  ## [0.9.72-alpha.1] - 2026-11-08
6
37
 
7
38
  ### Added
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/subagents",
3
- "version": "0.9.72-alpha.1",
3
+ "version": "0.9.73-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for delegating tasks to subagents with parallel execution. Fork of: https://github.com/nicobailon/pi-subagents",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/web-access",
3
- "version": "0.9.72-alpha.1",
3
+ "version": "0.9.73-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for web search, URL fetching, GitHub repo cloning, PDF/video extraction. Fork of: https://github.com/nicobailon/pi-web-access",
6
6
  "contributors": [