local-operator-ui 0.52.8 → 0.52.9

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 (2) hide show
  1. package/out/main/index.js +210 -8
  2. package/package.json +1 -1
package/out/main/index.js CHANGED
@@ -90003,6 +90003,9 @@ const UNANSWERED_BEFORE_DETACHED = 9;
90003
90003
  const TRANSPORT_EVIDENCE_MS = 3e4;
90004
90004
  const PROBE_INTERVAL_MS = 1e4;
90005
90005
  const PROBE_TIMEOUT_MS = 2e3;
90006
+ const PROBE_ATTEMPTS$1 = 3;
90007
+ const PROBE_RETRY_TIMEOUT_MS = 2500;
90008
+ const PROBE_RETRY_GAP_MS = 150;
90006
90009
  const DETACHED_AFTER_MS = 9e4;
90007
90010
  const REATTACH_BACKOFF_MS = 3e4;
90008
90011
  const REATTACH_BACKOFF_CEILING_MS = 3e5;
@@ -90032,6 +90035,18 @@ class DaemonStateMachine {
90032
90035
  unanswered = 0;
90033
90036
  /** When a desktop request was last answered, or null. */
90034
90037
  lastTransportAt = null;
90038
+ /**
90039
+ * This machine's clock, for a caller that logs a duration it measured AGAINST
90040
+ * the state it folded here.
90041
+ *
90042
+ * WHY an accessor rather than `Date.now()` at the caller: `now` is injectable,
90043
+ * so a reader comparing a logged age with a stamp this class wrote would be
90044
+ * comparing two clocks the moment one of them is pinned (review round 1, N4).
90045
+ * Production passes nothing and both are `Date.now()`.
90046
+ */
90047
+ nowMs() {
90048
+ return this.now();
90049
+ }
90035
90050
  /** Adopt a validated daemon (`owned` says whether this app spawned it). */
90036
90051
  attach(identity2, options) {
90037
90052
  this.identity = identity2;
@@ -90277,6 +90292,23 @@ class DaemonStateMachine {
90277
90292
  this.backoffMs = Math.min(this.backoffMs * 2, REATTACH_BACKOFF_CEILING_MS);
90278
90293
  return current;
90279
90294
  }
90295
+ /**
90296
+ * True while this connection has no usable daemon and only a RE-PROVED
90297
+ * IDENTITY can clear it.
90298
+ *
90299
+ * `detached` and `wedged` are the two states a surface renders as
90300
+ * "unreachable" (`isServerReachable` is their inverse in
90301
+ * `shared/backend-status.ts`), and they are the two a successful desktop
90302
+ * request may NOT clear on its own: an answer proves the transport, never that
90303
+ * the process answering is the one this app holds a credential for (see
90304
+ * `recordTransportSuccess`). So a caller holding that answer uses this
90305
+ * predicate to reach `recoverFromDetachment`, the only path that re-proves
90306
+ * identity - which is what makes an answered request end a detach instead of
90307
+ * waiting out `REATTACH_BACKOFF_CEILING_MS`.
90308
+ */
90309
+ needsRecovery() {
90310
+ return this.state === "detached" || this.state === "wedged";
90311
+ }
90280
90312
  /** True once a detach has lasted long enough to be reported as gone. */
90281
90313
  isReportablyGone() {
90282
90314
  return this.state === "detached" && this.detachedSince !== null && this.now() - this.detachedSince >= DETACHED_AFTER_MS;
@@ -91423,6 +91455,7 @@ const SHUTDOWN_TIMEOUT_DEFAULTS = {
91423
91455
  const OWNED_STOP_WORST_MS = SHUTDOWN_TIMEOUT_DEFAULTS.normal + SHUTDOWN_TIMEOUT_DEFAULTS.force;
91424
91456
  const READINESS_POLL_INTERVAL_MS = 1e3;
91425
91457
  const READINESS_BUDGET_MS = 3e4;
91458
+ const AUTO_RECOVERY_FLOOR_MS = 1e3;
91426
91459
  function readinessPollDelayMs(elapsedMs) {
91427
91460
  if (elapsedMs < 5e3) return 100;
91428
91461
  if (elapsedMs < 1e4) return 250;
@@ -91709,6 +91742,18 @@ class BackendServiceManager {
91709
91742
  */
91710
91743
  discoveryWedged = [];
91711
91744
  recoveryInFlight = false;
91745
+ /**
91746
+ * The attempt `recoveryInFlight` says is running, and how to release a joiner.
91747
+ *
91748
+ * `recoveryInFlight` alone tells a caller to DROP its request, which is right for
91749
+ * the tick and for an answer-triggered nudge (both only want an attempt to happen)
91750
+ * and wrong for the banner's Retry: `reconnectNow()` renders whatever snapshot it
91751
+ * gets back, so a dropped call printed "Still unreachable" over an attempt that was
91752
+ * about to re-attach (design review round 1, D1). A joiner awaits this promise and
91753
+ * reads the state the running attempt produced.
91754
+ */
91755
+ recoveryDone = null;
91756
+ finishRecovery = null;
91712
91757
  nextRecoveryAt = 0;
91713
91758
  appDataPath = electron.app.getPath("userData");
91714
91759
  venvPath;
@@ -91721,6 +91766,20 @@ class BackendServiceManager {
91721
91766
  lastHealthFailure = null;
91722
91767
  /** The one probe loop's interval handle. */
91723
91768
  healthCheckInterval = null;
91769
+ /**
91770
+ * Whether a tick's own work is still running.
91771
+ *
91772
+ * THE TICK CAN OUTLIVE ITS INTERVAL: the probe alone spans up to 7.3 s, and a tick
91773
+ * that moves the state then runs `recoverFromDetachment`, whose observation spends
91774
+ * up to another 7.3 s - ~14.6 s of work against a 10 s interval (see
91775
+ * `daemon-status.ts`'s `PROBE_ATTEMPTS` note). `setInterval` does not serialise its
91776
+ * callback, so without this flag two ticks overlap and ONE physical stall is
91777
+ * sampled twice and counted twice, reaching the nine-miss detach in half the
91778
+ * wall-clock silence it is meant to represent. A tick that arrives while one runs
91779
+ * is DROPPED rather than queued: the running tick is asking the same question about
91780
+ * the same daemon, and the next interval asks it again.
91781
+ */
91782
+ healthCheckInFlight = false;
91724
91783
  /** The only process this manager may terminate. Null means it owns nothing,
91725
91784
  * which is a reason to report "nothing to stop" - never to go looking. */
91726
91785
  ownedServe = null;
@@ -92162,7 +92221,40 @@ class BackendServiceManager {
92162
92221
  return;
92163
92222
  }
92164
92223
  if (this.daemonState.recordTransportSuccess()) this.notifyStatus();
92224
+ if (this.daemonState.needsRecovery()) this.recoverFromAnsweredRequest();
92225
+ }
92226
+ /**
92227
+ * Start recovery because THIS APP'S OWN request was answered while the
92228
+ * connection had no usable daemon.
92229
+ *
92230
+ * WHY the answer does not simply run `recoverFromDetachment()` per call: this
92231
+ * runs on every admitted desktop request, and the renderer's presence beat plus
92232
+ * its session reads arrive several times a second while a turn is streaming. The
92233
+ * gate is the attempt itself - `recoveryInFlight` makes every concurrent request
92234
+ * join the attempt already running - with one extra floor so that a burst of
92235
+ * answers arriving as an attempt ENDS does not queue an attempt each. One second
92236
+ * is below the tick's own ten, so the operator-visible latency of a heal stays
92237
+ * "the next request", and above the beat's spacing, so the retries stay bounded.
92238
+ */
92239
+ recoverFromAnsweredRequest() {
92240
+ const now = Date.now();
92241
+ if (now < this.autoRecoveryFloor) return;
92242
+ this.autoRecoveryFloor = now + AUTO_RECOVERY_FLOOR_MS;
92243
+ this.nextRecoveryAt = 0;
92244
+ void this.recoverFromDetachment().catch((error) => {
92245
+ logger.error(
92246
+ "Recovery triggered by an answered request threw:",
92247
+ LogFileType.BACKEND,
92248
+ error
92249
+ );
92250
+ });
92165
92251
  }
92252
+ /**
92253
+ * Earliest time the next answer-triggered recovery may run (`Date.now()` ms).
92254
+ *
92255
+ * A floor rather than a queue: see `recoverFromAnsweredRequest`.
92256
+ */
92257
+ autoRecoveryFloor = 0;
92166
92258
  isAppClosing = false;
92167
92259
  // Flag to track when the app is being closed
92168
92260
  isAutoUpdating = false;
@@ -94101,9 +94193,13 @@ class BackendServiceManager {
94101
94193
  detail: failure2 === null ? `${this.backendUrl}${HEALTH_PATH$1} answered a status this app does not accept` : `No answer from ${this.backendUrl}${HEALTH_PATH$1}`
94102
94194
  };
94103
94195
  }
94104
- const probe = await probeIdentity(this.backendUrl, expected, {
94105
- timeoutMs: PROBE_TIMEOUT_MS
94106
- });
94196
+ const { probe, attempts } = await this.probeIdentityWithRetries(expected);
94197
+ if (attempts > 1) {
94198
+ logger.info(
94199
+ `${this.backendUrl}${HEALTH_PATH$1} answered on probe attempt ${attempts} of ${PROBE_ATTEMPTS$1}: the first sample gave no answer (an expired budget, an unresolved name or an unexplained reset) and the retry inside the same stall found the daemon serving.`,
94200
+ LogFileType.BACKEND
94201
+ );
94202
+ }
94107
94203
  const attachedPid = this.daemonState.snapshot().pid;
94108
94204
  const reanchored = probe.outcome === "identity-mismatch" && attachedPid !== null && probe.identity.pid === attachedPid && this.holdsLiveChildProcess(attachedPid) ? (
94109
94205
  // Spread rather than field by field: this value IS `probe.identity` plus the
@@ -94156,6 +94252,67 @@ class BackendServiceManager {
94156
94252
  };
94157
94253
  }
94158
94254
  }
94255
+ /**
94256
+ * One observation's samples of `/health`, with the retries a transient failure needs.
94257
+ *
94258
+ * WHY THIS EXISTS (2026-11-08). The observation was ONE request with a 2000 ms
94259
+ * budget, on a host that was swapping 12.3 GB of 13.3 GB at load 132: `/health`
94260
+ * costs this daemon ~1.3 ms to serve, this app's per-tick sample of it reached
94261
+ * 3982 ms, and the log shows it served nothing at all for 25-1021 s before each
94262
+ * detach - so a stall is folded as silence, one miss at a time. This app then
94263
+ * reports a daemon it is actively using as unreachable, and every five-minute
94264
+ * recovery attempt spends a single sample the same way, which is why a detach
94265
+ * could outlive the stall by hours.
94266
+ *
94267
+ * THE RETRIES SIT INSIDE THE SAME STALL, not after it: attempt 1 keeps the
94268
+ * ordinary `PROBE_TIMEOUT_MS`, so a healthy daemon costs exactly what it cost
94269
+ * before, and attempts 2-3 arrive 150 ms later with a slightly larger budget -
94270
+ * a 4 s stall that started before attempt 1 is therefore answered by attempt 2
94271
+ * near its own tail. The whole observation spans at most 7.3 s. That is NOT a
94272
+ * tick's bound: the tick that calls this also runs `recoverFromDetachment`, whose
94273
+ * own observation spends another 7.3 s (~14.6 s in total, against a 10 s
94274
+ * interval), which is why the tick refuses to overlap itself instead of relying
94275
+ * on `PROBE_INTERVAL_MS`.
94276
+ *
94277
+ * WHAT IS RETRIED IS DECIDED BY THE CAUSE, and the arbiter is the classifier the
94278
+ * state machine already uses (`discovery.ts::classifyUnreachable`): a budget that
94279
+ * expired (`timeout`), a name that did not resolve (`unresolved` - `EAI_AGAIN`),
94280
+ * and anything it cannot name (`other` - `ECONNRESET`, an unknown throw) get the
94281
+ * remaining samples, because it files those WITH the timeouts. A REFUSED socket
94282
+ * returns on its first sample: it is the one unreachable cause that is EVIDENCE
94283
+ * rather than a stall, and re-asking it would stop the "refused means gone" fast
94284
+ * path from being fast. A `200` naming another process, and a status this path
94285
+ * will not read, are ANSWERS with their own outcomes and never reach the retry.
94286
+ *
94287
+ * WHERE THIS DOES NOT APPLY, stated rather than implied (review round 1, N3): the
94288
+ * no-identity arm above still spends ONE `checkHealth` (its own 3 s budget). It
94289
+ * cannot detach on one miss - that arm reports `unanswered`, which needs
94290
+ * `UNANSWERED_BEFORE_DETACHED` of them - and it is reachable only where this app
94291
+ * never held an identity, so acceptance criterion 1 is a guarantee of the
94292
+ * WITH-identity path only. Extending the retry there is a separate change with
94293
+ * its own budget question.
94294
+ *
94295
+ * @returns the determining probe and how many samples it took, so the caller can
94296
+ * record a retry that answered (the one case worth a log line) and a reader can
94297
+ * tell "silent three times" from "silent once".
94298
+ */
94299
+ async probeIdentityWithRetries(expected) {
94300
+ for (let attempt = 1; attempt <= PROBE_ATTEMPTS$1; attempt += 1) {
94301
+ if (attempt > 1) {
94302
+ await new Promise((resolve) => setTimeout(resolve, PROBE_RETRY_GAP_MS));
94303
+ }
94304
+ const probe = await probeIdentity(this.backendUrl, expected, {
94305
+ timeoutMs: attempt === 1 ? PROBE_TIMEOUT_MS : PROBE_RETRY_TIMEOUT_MS
94306
+ });
94307
+ const transient = probe.outcome === "unreachable" && probe.cause !== "refused";
94308
+ if (!transient || attempt === PROBE_ATTEMPTS$1) {
94309
+ return { probe, attempts: attempt };
94310
+ }
94311
+ }
94312
+ throw new Error(
94313
+ "probeIdentityWithRetries reached its end without a verdict"
94314
+ );
94315
+ }
94159
94316
  /**
94160
94317
  * Start health check interval.
94161
94318
  *
@@ -94188,6 +94345,16 @@ class BackendServiceManager {
94188
94345
  * connection still reads `attached`.
94189
94346
  */
94190
94347
  async checkBackendHealth() {
94348
+ if (this.healthCheckInFlight) return;
94349
+ this.healthCheckInFlight = true;
94350
+ try {
94351
+ await this.runHealthCheck();
94352
+ } finally {
94353
+ this.healthCheckInFlight = false;
94354
+ }
94355
+ }
94356
+ /** The tick's own work, without the overlap guard `checkBackendHealth` holds. */
94357
+ async runHealthCheck() {
94191
94358
  if (this.isAppClosing) return;
94192
94359
  const snapshot2 = this.daemonState.snapshot();
94193
94360
  const pid = this.remoteConfigured ? null : snapshot2.pid || this.process?.pid;
@@ -94280,8 +94447,11 @@ class BackendServiceManager {
94280
94447
  * replaced at all: if it is gone, the app says so.
94281
94448
  */
94282
94449
  async recoverFromDetachment() {
94283
- if (this.isAppClosing || this.isAutoUpdating || this.recoveryInFlight)
94450
+ if (this.isAppClosing || this.isAutoUpdating) return;
94451
+ if (this.recoveryInFlight) {
94452
+ if (this.recoveryDone) await this.recoveryDone;
94284
94453
  return;
94454
+ }
94285
94455
  if (this.daemonState.expectedInstanceId() !== null || this.pairingBreaksPacing()) {
94286
94456
  const now = Date.now();
94287
94457
  if (now < this.nextRecoveryAt) return;
@@ -94294,10 +94464,15 @@ class BackendServiceManager {
94294
94464
  );
94295
94465
  }
94296
94466
  this.recoveryInFlight = true;
94467
+ this.recoveryDone = new Promise((resolve) => {
94468
+ this.finishRecovery = () => resolve();
94469
+ });
94470
+ let verdict = "no identity and no repairable pairing";
94297
94471
  try {
94298
94472
  if (this.daemonState.expectedInstanceId()) {
94299
94473
  const observation = await this.probeAttachedDaemon();
94300
94474
  if (observation.kind === "identified" || observation.kind === "reanchored") {
94475
+ verdict = `probe=${observation.kind}: identity re-proved, re-attached`;
94301
94476
  this.daemonState.observe(observation);
94302
94477
  this.nextRecoveryAt = 0;
94303
94478
  this.notifyStatus();
@@ -94306,6 +94481,8 @@ class BackendServiceManager {
94306
94481
  }
94307
94482
  const selectedPid = this.daemonState.snapshot().pid;
94308
94483
  const processGone = selectedPid !== null && pidLiveness(selectedPid) === "dead";
94484
+ const probeClause = `probe=${observation.kind}${observation.kind === "unanswered" ? `(${observation.cause})` : ""}${processGone ? "+pid-dead" : ""}`;
94485
+ verdict = `${probeClause}: identity not re-proved by this probe`;
94309
94486
  const before = this.daemonState.snapshot();
94310
94487
  this.daemonState.observe(
94311
94488
  processGone ? { kind: "pid-dead" } : observation
@@ -94314,22 +94491,47 @@ class BackendServiceManager {
94314
94491
  if (after.state !== before.state || after.detail !== before.detail) {
94315
94492
  this.notifyStatus();
94316
94493
  }
94317
- if (!processGone && observation.kind !== "contradicted") return;
94494
+ if (!processGone && observation.kind !== "contradicted") {
94495
+ verdict = `${probeClause}: a live process is not this app's to replace on a failed probe, so re-discovery was held back`;
94496
+ return;
94497
+ }
94498
+ }
94499
+ if (this.process && this.process.exitCode === null && this.process.signalCode == null) {
94500
+ verdict = `${verdict}; this app's own child (pid ${this.process.pid}) is still live, so no discovery and no spawn`;
94501
+ return;
94318
94502
  }
94319
- if (this.process && this.process.exitCode === null && this.process.signalCode == null)
94503
+ if (await this.discoverAndAttach()) {
94504
+ verdict = `${verdict}; discovery re-attached`;
94320
94505
  return;
94321
- if (await this.discoverAndAttach()) return;
94506
+ }
94322
94507
  if (this.answeredRefused) {
94323
94508
  this.nextRecoveryAt = Date.now() + REATTACH_BACKOFF_MS;
94324
94509
  }
94325
94510
  if (!this.managerMaySpawn) {
94326
94511
  this.observeNoCandidate();
94512
+ verdict = `${verdict}; discovery found nothing attachable and this app may not spawn, so the absence was published`;
94513
+ return;
94514
+ }
94515
+ if (this.remoteConfigured || this.isExternalBackend) {
94516
+ verdict = `${verdict}; the daemon is ${this.remoteConfigured ? "remote" : "adopted"}, so it is not this app's to replace`;
94327
94517
  return;
94328
94518
  }
94329
- if (this.remoteConfigured || this.isExternalBackend) return;
94519
+ verdict = `${verdict}; starting a replacement daemon`;
94330
94520
  await this.start({ quiet: true });
94331
94521
  } finally {
94332
94522
  this.recoveryInFlight = false;
94523
+ const nowMs = this.daemonState.nowMs();
94524
+ const finalSnapshot = this.daemonState.snapshot();
94525
+ const evidenceAgeMs = finalSnapshot.lastTransportAt === null ? null : nowMs - finalSnapshot.lastTransportAt;
94526
+ const evidenceClause = evidenceAgeMs === null ? "none, this app made no answered request" : `${Math.round(evidenceAgeMs / 1e3)}s old${evidenceAgeMs <= TRANSPORT_EVIDENCE_MS ? " (fresh)" : " (stale)"}`;
94527
+ const nextWaitMs = Math.max(0, this.nextRecoveryAt - nowMs);
94528
+ logger.info(
94529
+ `Recovery attempt: ${verdict}; state=${finalSnapshot.state}; probes unanswered=${finalSnapshot.unanswered}; transport evidence ${evidenceClause}; next=${nextWaitMs === 0 ? "no wait" : `${Math.round(nextWaitMs / 1e3)}s`}.`,
94530
+ LogFileType.BACKEND
94531
+ );
94532
+ this.finishRecovery?.();
94533
+ this.finishRecovery = null;
94534
+ this.recoveryDone = null;
94333
94535
  }
94334
94536
  }
94335
94537
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-operator-ui",
3
- "version": "0.52.8",
3
+ "version": "0.52.9",
4
4
  "productName": "Local Operator",
5
5
  "description": "User interface for AI agent assistants that run Python code safely on your device through an intuitive chat interface. Supports local and cloud LLM models with built-in security features.",
6
6
  "main": "./out/main/index.js",