@threadbase-sh/streamer 1.52.4 → 1.52.5

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/dist/index.js CHANGED
@@ -13239,6 +13239,7 @@ function autoResumeSkipReason(row, opts) {
13239
13239
  if (opts.now - row.status_updated_at > AUTO_RESUME_WINDOW_MS) return "too_old";
13240
13240
  if (!opts.projectExists(row.project_path)) return "project_missing";
13241
13241
  if (resumeIdForRow(row) == null) return "resume_identity_missing";
13242
+ if (!opts.historyExists(row)) return "history_missing";
13242
13243
  return null;
13243
13244
  }
13244
13245
  function planAutoResume(rows, opts) {
@@ -13500,7 +13501,34 @@ var SessionRegistryBoot = class {
13500
13501
  /** Resume only the recent sessions the user explicitly allowed us to start at boot. */
13501
13502
  async autoResumePreviousSessions(rows) {
13502
13503
  if (!this.autoResumeOnBoot) return;
13503
- const plan = planAutoResume(rows, { now: Date.now(), projectExists: existsSync14 });
13504
+ const now = Date.now();
13505
+ const baseOptions = { now, projectExists: existsSync14, historyExists: () => true };
13506
+ const historyExists = /* @__PURE__ */ new Map();
13507
+ const preflights = /* @__PURE__ */ new Set();
13508
+ for (const row of rows) {
13509
+ if (autoResumeSkipReason(row, baseOptions) != null) {
13510
+ historyExists.set(row.session_id, false);
13511
+ continue;
13512
+ }
13513
+ while (preflights.size >= AUTO_RESUME_CONCURRENCY) {
13514
+ await Promise.race(preflights);
13515
+ }
13516
+ const preflight = (async () => {
13517
+ try {
13518
+ const target = await this.deps.resolveConversationTarget(row.session_id);
13519
+ historyExists.set(row.session_id, target.ok || target.reason !== "history_file_missing");
13520
+ } catch {
13521
+ historyExists.set(row.session_id, true);
13522
+ }
13523
+ })();
13524
+ preflights.add(preflight);
13525
+ void preflight.then(() => preflights.delete(preflight));
13526
+ }
13527
+ await Promise.all(preflights);
13528
+ const plan = planAutoResume(rows, {
13529
+ ...baseOptions,
13530
+ historyExists: (row) => historyExists.get(row.session_id) ?? false
13531
+ });
13504
13532
  const skippedBy = {};
13505
13533
  for (const { row, reason } of plan.skipped) {
13506
13534
  skippedBy[reason] = (skippedBy[reason] ?? 0) + 1;
@@ -14632,7 +14660,8 @@ var StreamerServer = class {
14632
14660
  selfPtyEndedAt: this.selfPtyEndedAt,
14633
14661
  resumeSession: (opts) => this.sessionHandlers.resumeSession(opts),
14634
14662
  watchConversationFile: (sessionId, historyId) => this.sessionWatchers.watchConversationFile(sessionId, historyId),
14635
- broadcastSessionList: () => this.wsHub.broadcast(this.sessionListPayload())
14663
+ broadcastSessionList: () => this.wsHub.broadcast(this.sessionListPayload()),
14664
+ resolveConversationTarget: (sessionId) => this.resolveConversationTarget(sessionId)
14636
14665
  });
14637
14666
  this.includeAgents = parseIncludeAgentsEnv(process.env.THREADBASE_INCLUDE_AGENTS);
14638
14667
  this.agentEntrypoints = parseAgentEntrypointsEnv(process.env.THREADBASE_AGENT_ENTRYPOINTS);
@@ -15841,13 +15870,17 @@ var StreamerServer = class {
15841
15870
  conv = await this.conversationHandlers.findConversationByUuid(boundId);
15842
15871
  }
15843
15872
  }
15873
+ const cachedConvMeta = this.cache?.getMetaById(historyId);
15874
+ const cachedPath = cachedConvMeta?.filePath ? toNativeFilePath(cachedConvMeta.filePath) : null;
15875
+ const cachedCodexPath = (registryProvider === CODEX_CLI_PROVIDER || cachedConvMeta?.provider === CODEX_CLI_PROVIDER) && cachedPath != null && existsSync16(cachedPath) ? cachedPath : null;
15844
15876
  const jsonlCwd = jsonlPath ? await this.conversationHandlers.readCwdFromJsonl(jsonlPath) : null;
15845
- const projectPath = jsonlCwd ?? conv?.projectPath;
15877
+ const projectPath = jsonlCwd ?? conv?.projectPath ?? (cachedCodexPath ? cachedConvMeta?.projectPath : null);
15846
15878
  if (!projectPath) {
15847
- if (!conv && !jsonlPath) return { ok: false, reason: "history_file_missing" };
15879
+ if (!conv && !jsonlPath && !cachedCodexPath) {
15880
+ return { ok: false, reason: "history_file_missing" };
15881
+ }
15848
15882
  return { ok: false, reason: "no_project_path" };
15849
15883
  }
15850
- const cachedConvMeta = this.cache?.getMetaById(historyId);
15851
15884
  const provider = coerceProviderForRunner(
15852
15885
  conv?.provider ?? cachedConvMeta?.provider ?? registryProvider
15853
15886
  );
@@ -15861,7 +15894,7 @@ var StreamerServer = class {
15861
15894
  // conversation. Kept separate from `jsonlPath` deliberately: feeding it to
15862
15895
  // conversationBusy() would newly arm the mtime heuristic for Codex, which
15863
15896
  // is exactly the over-broad signal the report ruled out.
15864
- historyPath: jsonlPath ?? conv?.filePath ?? null,
15897
+ historyPath: jsonlPath ?? conv?.filePath ?? cachedCodexPath ?? null,
15865
15898
  conv,
15866
15899
  projectPath,
15867
15900
  provider