viber-channel 0.8.48 → 0.8.50

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.
@@ -136,7 +136,8 @@ export function capabilitiesText(channelVersion: string | null = null): string {
136
136
  "",
137
137
  "DISSOLVE (stops the processes, then revokes the proven-stopped instances):",
138
138
  " viber-gateway dissolve --team <t> | --agent <launch-id> --dir <registry>",
139
- " [--auth <auth.json>] [--base-url <url>]",
139
+ " [--auth <auth.json>] [--base-url <url>] [--legacy-age-bound]",
140
+ " --legacy-age-bound: for a pre-guard launch never anchored, accepts an AGE BOUND (over 1 h) WITHOUT any proof of stop.",
140
141
  " --dir is REQUIRED, no default (exit 2 without it; refused under %TEMP%). For agents",
141
142
  " launched by the app or launch-team, pass it in full:",
142
143
  " PowerShell: --dir \"$env:LOCALAPPDATA\\Viber\\.viber\\gateway-registry\"",
@@ -41,9 +41,6 @@ export const REGISTRY_SCHEMA_VERSION = 1;
41
41
  /** Closed entries older than this are dropped, so the file cannot grow forever. */
42
42
  export const CLOSED_ENTRY_TTL_MS = 30 * 24 * 60 * 60 * 1000;
43
43
 
44
- /** #737 (JP): an active entry whose agent has been seen nowhere for this long is closed. */
45
- export const ABSENT_CLOSE_AFTER_MS = 7 * 24 * 60 * 60 * 1000;
46
-
47
44
  /**
48
45
  * The gateway's launch id of one member of one command — a COPY of
49
46
  * `attemptLaunchId` (`viber-gateway/lib/team_derivation.ts`): `launch-` + the first 32
@@ -328,9 +325,19 @@ export function recordSpawn(registry: Registry, spawn: SpawnForRegistry, now: nu
328
325
  }
329
326
  }
330
327
 
331
- /** Drop closed entries past `CLOSED_ENTRY_TTL_MS`. */
328
+ /**
329
+ * Drop closed entries past `CLOSED_ENTRY_TTL_MS`.
330
+ *
331
+ * #755: NOT an entry still carrying `absent_since`. Every close this release makes clears it
332
+ * (`markClosed`, `closeAbsent`), so a closed entry that keeps one was closed by an OLDER release's
333
+ * 7-day absence rule — the server may still show that agent, and its settings are what a relaunch
334
+ * needs. It stays until the server confirms the agent is over (`closeAbsent` then clears the clock).
335
+ * ⚠ Such an entry with no `instance_id` can never be asked about, so it is kept for good: a few
336
+ * hundred bytes, against losing an agent the browser still offers to relaunch.
337
+ */
332
338
  export function pruneClosed(registry: Registry, now: number): void {
333
339
  for (const [key, entry] of Object.entries(registry.entries)) {
340
+ if (entry.absent_since !== undefined && entry.absent_since !== null) continue;
334
341
  if (entry.state === "closed" && entry.closed_at !== null && now - entry.closed_at > CLOSED_ENTRY_TTL_MS) {
335
342
  delete registry.entries[key];
336
343
  }
@@ -431,6 +438,8 @@ export function markClosed(registry: Registry, instanceIds: readonly string[], n
431
438
  if (entry.state === "active" && entry.instance_id !== null && ids.has(entry.instance_id)) {
432
439
  entry.state = "closed";
433
440
  entry.closed_at = now;
441
+ // #755: a close the server acknowledged is final — no absence clock keeps it from pruning.
442
+ entry.absent_since = null;
434
443
  changed = true;
435
444
  }
436
445
  }
@@ -464,31 +473,56 @@ export function markAbsence(registry: Registry, alive: ReadonlySet<string>, now:
464
473
  return changed;
465
474
  }
466
475
 
467
- /** Active entries whose agent is absent: the ids worth asking the server about. */
476
+ /**
477
+ * Entries whose agent is absent: the ids worth asking the server about. #755: a CLOSED entry that
478
+ * still carries `absent_since` (closed by an older release's 7-day rule) is asked about too — the
479
+ * server's answer is what lets `pruneClosed` drop it.
480
+ */
468
481
  export function absentInstanceIds(registry: Registry): string[] {
469
482
  return Object.values(registry.entries)
470
- .filter((e) => e.state === "active" && e.instance_id !== null && e.absent_since !== undefined && e.absent_since !== null)
483
+ .filter((e) => e.instance_id !== null && e.absent_since !== undefined && e.absent_since !== null)
471
484
  .map((e) => e.instance_id as string);
472
485
  }
473
486
 
474
487
  /**
475
- * #737 (JP): close an ABSENT entry at once when the server says its instance is over (revoked, or no
476
- * row at all), and after `ABSENT_CLOSE_AFTER_MS` otherwise. Never an entry whose agent runs:
477
- * `absent_since` is only set by `markAbsence` from an observed machine.
488
+ * #737 (JP): close an ABSENT entry when the server says its instance is over (revoked, or no row at
489
+ * all). Never an entry whose agent runs: `absent_since` is only set by `markAbsence` from an observed
490
+ * machine.
491
+ *
492
+ * #755 (JP): NEVER on absence alone. An agent the browser still shows is relaunchable — its terminal
493
+ * closed to free memory, or the machine rebooted — however long ago. The 7-day close this replaced
494
+ * left the server offering a Relaunch the runner then refused.
478
495
  */
479
496
  export function closeAbsent(registry: Registry, overOnServer: ReadonlySet<string>, now: number): string[] {
480
497
  const closed: string[] = [];
481
498
  for (const [key, entry] of Object.entries(registry.entries)) {
482
499
  if (entry.state !== "active" || entry.absent_since === undefined || entry.absent_since === null) continue;
483
500
  const over = entry.instance_id !== null && overOnServer.has(entry.instance_id);
484
- if (!over && now - entry.absent_since < ABSENT_CLOSE_AFTER_MS) continue;
501
+ if (!over) continue;
485
502
  entry.state = "closed";
486
503
  entry.closed_at = now;
504
+ // #755: the server confirmed the end — no absence clock keeps it from pruning.
505
+ entry.absent_since = null;
487
506
  closed.push(key);
488
507
  }
489
508
  return closed;
490
509
  }
491
510
 
511
+ /**
512
+ * #755: an entry an OLDER release closed after 7 days of absence (closed, `absent_since` still set)
513
+ * becomes prunable only once the server says its instance is over. Returns whether anything changed.
514
+ */
515
+ export function confirmLegacyClosed(registry: Registry, overOnServer: ReadonlySet<string>): boolean {
516
+ let changed = false;
517
+ for (const entry of Object.values(registry.entries)) {
518
+ if (entry.state !== "closed" || entry.absent_since === undefined || entry.absent_since === null) continue;
519
+ if (entry.instance_id === null || !overOnServer.has(entry.instance_id)) continue;
520
+ entry.absent_since = null;
521
+ changed = true;
522
+ }
523
+ return changed;
524
+ }
525
+
492
526
  // ── #687: close requests — the runner stays the ONLY writer of its registry ──────────────────
493
527
  //
494
528
  // A dissolve kills, THEN revokes: by then the runner has reported the agent `down` (ambiguous:
@@ -119,7 +119,11 @@ export async function relaunchInstance(requestedId: string, deps: RelaunchDeps):
119
119
  return { kind: "refused", error: "this runner has no saved settings for that agent — only an agent it launched can be relaunched" };
120
120
  }
121
121
  const [key, entry] = found;
122
- if (entry.state === "closed") return { kind: "refused", error: "that agent was closed on purpose" };
122
+ // #755 (JP: "as long as it is not revoked, it must be relaunchable"): a LOCAL `closed` does not
123
+ // refuse — WHATEVER closed it: an older release's 7-day absence rule, or even a revocation the
124
+ // server acknowledged. By design the server is the only judge: `createRelaunchCommand` refuses a
125
+ // revoked or closed instance BEFORE any command reaches a runner (its test pins that refusal), so
126
+ // a command arriving here is one the server holds relaunchable. The entry is reopened below.
123
127
 
124
128
  // Alive? The record, when it still exists, is checked like the roster checks it.
125
129
  const rec = readPresenceRecord(presenceRecordPath(deps.identity, instanceId, deps.lockDir));
@@ -163,6 +167,7 @@ export async function relaunchInstance(requestedId: string, deps: RelaunchDeps):
163
167
  e.instance_id = null;
164
168
  e.launched_at = now;
165
169
  e.state = "active";
170
+ e.closed_at = null;
166
171
  // #737: the absence clock belongs to the OLD agent; the new one starts with none.
167
172
  e.absent_since = null;
168
173
  // This relaunch has no gateway job name: the old launch id must not let an old
@@ -576,11 +576,13 @@ async function rosterBeatOnce(auth: RosterBeatAuth, deps: RosterBeatDeps): Promi
576
576
  // #737: only from a machine the runner SAW — a failed enumeration starts no absence clock.
577
577
  const absence = collected.observed && reg.markAbsence(r, alive, now());
578
578
  const closedAbsent = collected.observed ? reg.closeAbsent(r, overOnServer, now()) : [];
579
- if (closedAbsent.length > 0) log(`[runner] registry: closed ${closedAbsent.length} absent agent(s) (revoked on the server, or absent for 7 days)`);
579
+ if (closedAbsent.length > 0) log(`[runner] registry: closed ${closedAbsent.length} absent agent(s) (revoked on the server)`);
580
+ // #755: an older release's 7-day close is released for pruning only once the server confirms.
581
+ const confirmed = collected.observed && reg.confirmLegacyClosed(r, overOnServer);
580
582
  const before = Object.keys(r.entries).length;
581
583
  reg.pruneClosed(r, now());
582
584
  const pruned = Object.keys(r.entries).length !== before;
583
- let cleared = absence || closedAbsent.length > 0 || pruned;
585
+ let cleared = absence || closedAbsent.length > 0 || confirmed || pruned;
584
586
  if (ack.presence_applied) {
585
587
  for (const e of Object.values(r.entries)) {
586
588
  // An older predecessor (handover_from) is done once the server no longer
@@ -660,7 +662,7 @@ export async function fetchEndedInstances(
660
662
  } catch (err) {
661
663
  return { error: String(err) };
662
664
  }
663
- // A server older than #737 answers 404: nothing closes early, the 7-day rule still holds.
665
+ // A server older than #737 answers 404: nothing is closed, every absent entry is kept (#755).
664
666
  if (!resp.ok) return { error: `HTTP ${resp.status}` };
665
667
  const body = (await resp.json().catch(() => null)) as { revoked?: unknown; missing?: unknown } | null;
666
668
  if (body === null || !Array.isArray(body.revoked) || !Array.isArray(body.missing)) return { error: "malformed answer" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viber-channel",
3
- "version": "0.8.48",
3
+ "version": "0.8.50",
4
4
  "description": "Voice + text MCP channel between a Claude Code session and the Viber UI (https://viber.dgypx.dev). Push transcripts to Claude; send_message tool delivers text back to the UI.",
5
5
  "type": "module",
6
6
  "bin": {