@parall/daemon 1.45.0 → 1.46.0

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 (49) hide show
  1. package/bundle/manifest.json +15 -15
  2. package/bundle/parall-browser-pod.js +29726 -375
  3. package/bundle/parall-channel-exec.js +2 -0
  4. package/bundle/parall-claude-agent.js +26091 -273
  5. package/bundle/parall-codex-agent.js +26650 -331
  6. package/bundle/parall-daemon.js +31384 -1998
  7. package/bundle/parall-openclaw-agent.js +1 -0
  8. package/dist/browser-pod.d.ts +23 -1
  9. package/dist/browser-pod.d.ts.map +1 -1
  10. package/dist/browser-pod.js +104 -34
  11. package/dist/browser-profile-reconcile.d.ts +21 -0
  12. package/dist/browser-profile-reconcile.d.ts.map +1 -0
  13. package/dist/browser-profile-reconcile.js +188 -0
  14. package/dist/clip-runtime/browser-cdp.d.ts +40 -0
  15. package/dist/clip-runtime/browser-cdp.d.ts.map +1 -0
  16. package/dist/clip-runtime/browser-cdp.js +218 -0
  17. package/dist/clip-runtime/browser-profile-manager.d.ts +97 -24
  18. package/dist/clip-runtime/browser-profile-manager.d.ts.map +1 -1
  19. package/dist/clip-runtime/browser-profile-manager.js +316 -182
  20. package/dist/clip-runtime/browser-profile-pool.d.ts +3 -0
  21. package/dist/clip-runtime/browser-profile-pool.d.ts.map +1 -1
  22. package/dist/clip-runtime/browser-profile-pool.js +18 -1
  23. package/dist/clip-runtime/browser-proxy-reconcile.d.ts +77 -0
  24. package/dist/clip-runtime/browser-proxy-reconcile.d.ts.map +1 -0
  25. package/dist/clip-runtime/browser-proxy-reconcile.js +139 -0
  26. package/dist/clip-runtime/browser-proxy-state.d.ts +55 -0
  27. package/dist/clip-runtime/browser-proxy-state.d.ts.map +1 -0
  28. package/dist/clip-runtime/browser-proxy-state.js +149 -0
  29. package/dist/clip-runtime/browser-quiescence.d.ts +71 -0
  30. package/dist/clip-runtime/browser-quiescence.d.ts.map +1 -0
  31. package/dist/clip-runtime/browser-quiescence.js +136 -0
  32. package/dist/clip-runtime/browser-readiness.d.ts +64 -0
  33. package/dist/clip-runtime/browser-readiness.d.ts.map +1 -0
  34. package/dist/clip-runtime/browser-readiness.js +161 -0
  35. package/dist/clip-runtime/browser-state-store.d.ts +13 -2
  36. package/dist/clip-runtime/browser-state-store.d.ts.map +1 -1
  37. package/dist/clip-runtime/browser-state-store.js +15 -6
  38. package/dist/clip-runtime/browser-target-registry.d.ts +143 -0
  39. package/dist/clip-runtime/browser-target-registry.d.ts.map +1 -0
  40. package/dist/clip-runtime/browser-target-registry.js +297 -0
  41. package/dist/clip-runtime/browser-viewer-streamer.d.ts +13 -14
  42. package/dist/clip-runtime/browser-viewer-streamer.d.ts.map +1 -1
  43. package/dist/clip-runtime/browser-viewer-streamer.js +11 -63
  44. package/dist/daemon-main.d.ts.map +1 -1
  45. package/dist/daemon-main.js +3 -1
  46. package/dist/supervisor.d.ts +6 -0
  47. package/dist/supervisor.d.ts.map +1 -1
  48. package/dist/supervisor.js +48 -187
  49. package/package.json +8 -6
@@ -4,10 +4,12 @@ import * as os from 'node:os';
4
4
  import * as path from 'node:path';
5
5
  import { effectiveLLMSourceExplicit, llmSource } from '@parall/agent-core';
6
6
  import { ParallWs, } from '@parall/sdk';
7
+ import { PUBLIC_PROXY_PROBE_FALLBACK_URL } from './clip-runtime/browser-readiness.js';
7
8
  import { installClip, parseSource } from './clip-runtime/clip-installer.js';
8
9
  import { parseIpcCommands } from './clip-runtime/manifest.js';
9
10
  import { BrowserProfilePool, ClipProcessManager, ClipProvider, HubClient, } from './clip-runtime/index.js';
10
11
  import { agentClaudeHomeFor, agentHomeDirFor, agentStateDirFor, agentWorkspaceDirFor, } from './config.js';
12
+ import { reconcileBrowserProfiles as runBrowserProfileReconcile } from './browser-profile-reconcile.js';
11
13
  import { listDirectory } from './filesystem.js';
12
14
  import { ensureIsolatedHome, ensureSharedCredentialLink, } from './home-isolation.js';
13
15
  import { assertAgentKey, getRuntimeAdapter } from './runtimes.js';
@@ -178,6 +180,7 @@ export class DaemonSupervisor {
178
180
  .catch((err) => this.log.warn(`browser profile status report failed: ${String(err)}`));
179
181
  },
180
182
  resolveProxy: (profileId) => this.resolveBrowserProfileProxy(profileId),
183
+ proxyProbeUrl: this.resolveBrowserProxyProbeUrl(),
181
184
  });
182
185
  this.clipManager = new ClipProcessManager({
183
186
  clipsDir: path.join(this.config.rootStateDir, 'clips'),
@@ -517,195 +520,23 @@ export class DaemonSupervisor {
517
520
  throw err;
518
521
  }
519
522
  }
520
- async reconcileBrowserProfiles() {
523
+ reconcileBrowserProfiles() {
524
+ // Coordination body extracted move-only to browser-profile-reconcile.ts (this
525
+ // file crossed the 2000-line ceiling). The op queue / pool lifecycle / wipe
526
+ // helper are injected so the behavior is byte-for-byte identical.
521
527
  const pool = this.browserProfilePool;
522
528
  if (!pool)
523
- return;
524
- // Snapshot the locally-live set BEFORE the server fetch. A profile opened via a
525
- // WS lifecycle event DURING the fetch is NOT in this snapshot, so the negative
526
- // convergence below (which is stale w.r.t. that open) can never release it.
527
- // There is no periodic browser reconcile to re-open a wrongly-released profile —
528
- // it only runs on startup / WS-hello — so a stale release would strand it until
529
- // the next reconnect.
530
- const activeBeforeList = new Set(pool.activeProfileIds());
531
- // Also snapshot revives (open/ensure) queued but not yet a live manager: such a
532
- // stale open is invisible to activeProfileIds() and would otherwise drain after a
533
- // missed offline stop/delete and start a runtime the server no longer wants.
534
- const pendingReviveBeforeList = new Set(this.browserProfilePendingRevives.keys());
535
- // And ALL local profile state — per-profile homes AND legacy flat account files
536
- // (the pool owns that storage layout). State with NO server row is a
537
- // deleted/reassigned profile whose cookies/storage must be wiped from this host;
538
- // a pre-upgrade profile never reopened after migration exists only as a legacy flat
539
- // file, so home-only enumeration would miss it. Pre-fetch so state created during
540
- // the fetch is left alone.
541
- const localStateBeforeList = new Set(pool.localStateProfileIds());
542
- let profiles;
543
- try {
544
- profiles = await this.client.listMachineBrowserProfiles();
545
- }
546
- catch (err) {
547
- this.log.warn(`browser profile reconcile: list failed: ${String(err)}`);
548
- return;
549
- }
550
- // The pool must still be the same instance after the await — stop() may have
551
- // nulled/replaced it during a concurrent shutdown; bail rather than act on a
552
- // torn-down pool (also avoids NPE-ing through Promise.allSettled into warnings).
553
- if (this.browserProfilePool !== pool)
554
- return;
555
- // Converge local runtimes to the server's desired-live set (the server is the
556
- // SSOT). The supervisor is the desired-state coordinator; the pool is the
557
- // per-profile runtime registry. Every op here goes through
558
- // enqueueBrowserProfileOp so all supervisor-originated profile work shares one
559
- // ordering layer (the pool's own queue is the final per-profile mutex).
560
- const desiredLive = new Set();
561
- const serverIds = new Set(); // every byoc profile the server still lists (any status)
562
- const serverResetGen = new Map();
563
- const ops = [];
564
- // reset_generation (server) is the SSOT for reset intent; the daemon's per-profile
565
- // sidecar (read via pool.appliedResetGeneration) is only a local ack of "already
566
- // wiped up to this generation". A missed reset (server newer than the local ack) must
567
- // wipe local state BEFORE any open/ensure, so a reopen starts clean and never
568
- // resurrects the cookies the reset cleared. Returns the server reset_generation to
569
- // apply, or null if nothing is missed. Pure (no side effects).
570
- const missedResetGen = (profileId) => {
571
- const gen = serverResetGen.get(profileId) ?? 0;
572
- return gen > pool.appliedResetGeneration(profileId) ? gen : null;
573
- };
574
- // Negative-path helper (a stopped profile with a missed reset): fence synchronously
575
- // then enqueue a STANDALONE wipe. No revive follows, so a wipe failure simply leaves
576
- // the profile fenced and the sidecar unwritten → the next reconcile retries (the
577
- // SSOT reset_generation is still unapplied locally). Fail-closed by construction.
578
- const enqueueResetWipeIfMissed = (profileId) => {
579
- const gen = missedResetGen(profileId);
580
- if (gen === null)
581
- return false;
582
- // Fence SYNCHRONOUSLY before the async wipe — same contract as the WS stop/reset
583
- // path. On a machine-WS reconnect whose clip-provider stream stays live, a hub
584
- // invoke could otherwise run on the stale runtime in the gap before the wipe op
585
- // starts. (In the negative loop this re-asserts an already-set fence within the same
586
- // synchronous iteration — atomic, no revive can observe an intermediate generation.)
587
- pool.fence(profileId);
588
- ops.push(this.enqueueBrowserProfileOp(profileId, () => pool.applyResetWipe(profileId, gen)));
589
- return true;
590
- };
591
- for (const profile of profiles) {
592
- // The daemon supervises only machine-bound (byoc) profiles; hosted profiles
593
- // (null machine_id) run on the platform pool and are never owned by a daemon.
594
- if (!profile.machine_id)
595
- continue;
596
- serverIds.add(profile.id);
597
- serverResetGen.set(profile.id, profile.reset_generation ?? 0);
598
- if (profile.status !== 'running' && profile.status !== 'pending')
599
- continue;
600
- desiredLive.add(profile.id);
601
- // A missed reset must wipe SUCCESSFULLY before this profile is revived. Fence
602
- // synchronously now (reject hub invokes in the gap before the queued wipe runs).
603
- const wipeGen = missedResetGen(profile.id);
604
- if (wipeGen !== null)
605
- pool.fence(profile.id);
606
- // Capture the fence generation AFTER any fence bump so a stop arriving while the op
607
- // waits makes it skip as stale; carry the lifecycle generation so the daemon's
608
- // `running` report is fenced server-side. Drive desired state through the CAPTURED
609
- // pool (not enqueueBrowserProfileLifecycle, which re-reads this.browserProfilePool
610
- // and would negative-ACK `error` for a pending profile if stop() nulled the field).
611
- const sinceSeq = pool.stopSeqOf(profile.id);
612
- const generation = profile.lifecycle_generation;
613
- // forceStatusReport ONLY for a `pending` row: the daemon's last report may already be
614
- // `running` (Chromium survived the WS drop), so a deduped repeat would leave the
615
- // server stuck at `pending`. A `running` row keeps the normal dedup.
616
- const forceStatusReport = profile.status === 'pending';
617
- ops.push(this.enqueueBrowserProfileRevive(profile.id, async () => {
618
- // Reset-before-open, FAIL-CLOSED: a missed reset must wipe successfully BEFORE
619
- // the revive un-fences and reopens. If applyResetWipe throws, the await
620
- // propagates and ensureRuntime is SKIPPED — the profile stays fenced (the wipe
621
- // fenced it and the applied-reset sidecar was NOT written), so the next reconcile
622
- // retries because the SSOT reset_generation is still unapplied locally. This
623
- // ordering is expressed locally; the enqueueBrowserProfileOp queue contract (a
624
- // rejected op does not block later ops) is intentionally unchanged. A failed
625
- // wipe reports `error` (visible) and re-throws here, so ensureRuntime is skipped.
626
- if (wipeGen !== null)
627
- await this.wipeBeforeRevive(pool, profile.id, wipeGen, generation);
628
- // Reconnect recovery is liveness-only: ensure the runtime is live (account +
629
- // tab) for both pending and running. The original open's `start_url` is NOT
630
- // replayed (it rides only the live lifecycle event, not persisted); a `pending`
631
- // profile whose open event the daemon missed comes up at the default page rather
632
- // than a targetless `about:blank`. Persisting start_url is a separate follow-up.
633
- await pool.ensureRuntime(profile.id, sinceSeq, generation, { forceStatusReport });
634
- }));
635
- }
636
- // Negative convergence over everything locally known but NOT desired — active
637
- // runtimes, queued revives (open/ensure not yet a manager), and local state (homes +
638
- // legacy flat files) — all from the PRE-FETCH snapshots, so a profile that appeared
639
- // DURING the fetch is left alone (no periodic reconcile would undo a wrong teardown).
640
- const candidates = new Set([
641
- ...activeBeforeList,
642
- ...pendingReviveBeforeList,
643
- ...localStateBeforeList,
644
- ]);
645
- for (const profileId of candidates) {
646
- if (desiredLive.has(profileId))
647
- continue;
648
- const isActive = activeBeforeList.has(profileId);
649
- const hasLocalState = localStateBeforeList.has(profileId);
650
- // Pending-only revive (queued open/ensure, no runtime, no on-disk state at the
651
- // pre-fetch snapshot): the synchronous fence alone neutralizes the stale open (it
652
- // bumps stopSeq, so the queued revive skips as stale). Do NOT AWAIT a teardown — it
653
- // would block behind the possibly-stuck queue and stall the whole reconcile (the
654
- // queued-stale-open deadlock).
655
- if (!isActive && !hasLocalState) {
656
- pool.fence(profileId);
657
- // Race: a pending-only revive can COMPLETE during the list fetch (create a manager
658
- // + on-disk state) BEFORE this fence — the snapshot is then stale, so the fence
659
- // alone leaves an orphaned runtime/disk the negative loop never converged. Converge
660
- // it FIRE-AND-FORGET (NOT in `ops`: a still-stuck revive queue must not hang the
661
- // reconcile; it runs once the queue drains — after the fenced open skips or
662
- // completes — and is a no-op if nothing was created):
663
- // - deleted/reassigned → wipeAbsent: the old host must keep no session data.
664
- // - present + missed reset → applyResetWipe: the completed open may have applied
665
- // only its event's (older) reset_generation, not the current one.
666
- // - present + stopped → releaseRuntime: free the orphaned Chromium; a plain
667
- // stop keeps its cookies on disk.
668
- let cleanup;
669
- if (!serverIds.has(profileId)) {
670
- cleanup = pool.wipeAbsent(profileId);
671
- }
672
- else {
673
- const wipeGen = missedResetGen(profileId);
674
- cleanup =
675
- wipeGen !== null
676
- ? pool.applyResetWipe(profileId, wipeGen)
677
- : pool.releaseRuntime(profileId);
678
- }
679
- void cleanup.catch((err) => this.log.warn(`browser profile pending-revive cleanup failed for ${profileId}: ${String(err)}`));
680
- continue;
681
- }
682
- if (!serverIds.has(profileId)) {
683
- // Absent from the server list → deleted/reassigned → fence + wipe local state (the
684
- // old host must not keep cookies/storage). No status report — server is the SSOT.
685
- pool.fence(profileId);
686
- ops.push(this.enqueueBrowserProfileOp(profileId, () => pool.wipeAbsent(profileId)));
687
- }
688
- else if (enqueueResetWipeIfMissed(profileId)) {
689
- // Present (stopped) with a missed reset → fenced synchronously + wipe enqueued.
690
- }
691
- else if (isActive) {
692
- // Present (stopped) but the runtime is still live → fence + release the runtime
693
- // only; a plain stop keeps its cookies on disk.
694
- pool.fence(profileId);
695
- ops.push(this.enqueueBrowserProfileOp(profileId, () => pool.releaseRuntime(profileId)));
696
- }
697
- // else: present + stopped + on-disk state + no runtime + no missed reset → LEAVE
698
- // ALONE (do NOT fence). Its stopped-fence is already held — the start-sequence
699
- // pre-fence on a fresh daemon, or the persisted pool state on a WS reconnect — so a
700
- // hub invoke is still rejected. Re-fencing here would bump stopSeq and drop an `open`
701
- // that arrived during the list fetch (it captured an older sinceSeq, and the stale
702
- // `stopped` snapshot doesn't reflect it yet), stranding the server at `pending`.
703
- }
704
- for (const result of await Promise.allSettled(ops)) {
705
- if (result.status === 'rejected') {
706
- this.log.warn(`browser profile reconcile op failed: ${String(result.reason)}`);
707
- }
708
- }
529
+ return Promise.resolve();
530
+ return runBrowserProfileReconcile({
531
+ pool,
532
+ currentPool: () => this.browserProfilePool,
533
+ client: this.client,
534
+ log: this.log,
535
+ enqueueOp: (id, op) => this.enqueueBrowserProfileOp(id, op),
536
+ enqueueRevive: (id, op) => this.enqueueBrowserProfileRevive(id, op),
537
+ wipeBeforeRevive: (p, id, rg, g) => this.wipeBeforeRevive(p, id, rg, g),
538
+ pendingReviveIds: () => new Set(this.browserProfilePendingRevives.keys()),
539
+ });
709
540
  }
710
541
  /**
711
542
  * Resolve a profile's outbound proxy for bb-browser account creation (BYOC).
@@ -731,6 +562,22 @@ export class DaemonSupervisor {
731
562
  password: profile.proxy_password ?? undefined,
732
563
  };
733
564
  }
565
+ /** Proxy readiness probe endpoint for BYOC profiles (browser-readiness.ts): an
566
+ * explicit override, else the api-server's Parall-owned public `/generate_204`.
567
+ * The probe navigates a sacrificial tab THROUGH the profile's proxy, so the
568
+ * target must be public + proxy-resolvable — `config.apiUrl` is the public API
569
+ * host for BYOC. Falls back to a well-known public 204 if apiUrl is unusable. */
570
+ resolveBrowserProxyProbeUrl() {
571
+ const override = process.env.PRLL_BROWSER_PROXY_PROBE_URL?.trim();
572
+ if (override)
573
+ return override;
574
+ try {
575
+ return new URL('/generate_204', this.config.apiUrl).toString();
576
+ }
577
+ catch {
578
+ return PUBLIC_PROXY_PROBE_FALLBACK_URL;
579
+ }
580
+ }
734
581
  // ---- Flat layout migration (self-hosted → daemon) ----
735
582
  /**
736
583
  * Detects a legacy flat state layout (no agents/ subdir) and migrates it
@@ -913,6 +760,20 @@ export class DaemonSupervisor {
913
760
  }
914
761
  catch (err) {
915
762
  this.log.warn(`browser profile lifecycle failed (profile=${data.profile_id}, action=${data.action}): ${String(err)}`);
763
+ // Negative-ACK backstop for open/reset failures that never reached the
764
+ // manager's own error report (pool queue rejection, unsafe id, disposal
765
+ // failure): without it the server row is stranded at `pending` with no
766
+ // error_msg and the user sees a silent timeout. The manager-level report
767
+ // (same status, message may differ) already carries the structured cause
768
+ // when it fired — a second update is idempotent on status. Deliberately
769
+ // NOT for `stop`: its desired state is durable and reconcile converges it.
770
+ if ((data.action === 'open' || data.action === 'reset') && this.running) {
771
+ await this.client
772
+ .reportBrowserProfileStatus(data.profile_id, 'error', err instanceof Error ? err.message : String(err), data.generation)
773
+ .catch((reportErr) => {
774
+ this.log.warn(`browser profile lifecycle negative ACK failed for ${data.profile_id}: ${String(reportErr)}`);
775
+ });
776
+ }
916
777
  }
917
778
  }
918
779
  enqueueBrowserProfileLifecycle(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parall/daemon",
3
- "version": "1.45.0",
3
+ "version": "1.46.0",
4
4
  "description": "Parall local agent runtime — daemon supervisor + bridge runtimes, bundled as standalone JS files",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,14 +32,16 @@
32
32
  "dependencies": {
33
33
  "@aws-sdk/client-s3": "3.984.0",
34
34
  "@pinixai/bb-browser-pro": "0.15.0",
35
- "@parall/agent-core": "1.45.0",
36
- "@parall/sdk": "1.45.0",
37
- "@parall/codex-agent": "1.45.0",
38
- "@parall/claude-agent": "1.45.0",
39
- "@parall/openclaw-agent": "1.45.0"
35
+ "ws": "^8.18.0",
36
+ "@parall/agent-core": "1.46.0",
37
+ "@parall/sdk": "1.46.0",
38
+ "@parall/claude-agent": "1.46.0",
39
+ "@parall/codex-agent": "1.46.0",
40
+ "@parall/openclaw-agent": "1.46.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@types/node": "^22.0.0",
44
+ "@types/ws": "^8.18.0",
43
45
  "esbuild": "^0.25.0",
44
46
  "typescript": "^5.7.0"
45
47
  },