dsh-client-auto-continue 0.20.0 → 0.20.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.20.1](https://github.com/HsiangNianian/dsh-auto-continue/releases/tag/v0.20.1) — 2026-11-16
4
+
5
+ ### Fixed
6
+
7
+ - The startup sweep of stored sessions could run the host out of memory on a large profile: it decoded the full log of every stored session before checking whether the last turn was recent, and the host then restarted and did the same again. One host start now reads at most 32 stored logs, most recently active first (from the projection checkpoint cache, falling back to creation time). The checkpoint only orders the reads, so freshness is still decided by the tail of the log. Each session counts once even when its read is retried ([#91](https://github.com/HsiangNianian/dsh-auto-continue/pull/91), thanks @anthonyhann)
8
+
9
+ [Upgrade instructions and validation](docs/releases/v0.20.1.md) · [Full changes](https://github.com/HsiangNianian/dsh-auto-continue/compare/v0.20.0...v0.20.1)
10
+
3
11
  ## [0.20.0](https://github.com/HsiangNianian/dsh-auto-continue/releases/tag/v0.20.0) — 2026-11-16
4
12
 
5
13
  ### Added
package/README.md CHANGED
@@ -73,7 +73,7 @@ To update, let running work finish, stop DSH, run the same command again, then r
73
73
 
74
74
  | DSH runtime | Plugin version | Settings location |
75
75
  | --- | --- | --- |
76
- | 0.2.2-rc.1, 0.2.1-rc.2, 0.2.1-alpha.1 | 0.20.0 verified | **Plugins → dsh-client-auto-continue** |
76
+ | 0.2.2-rc.1, 0.2.1-rc.2, 0.2.1-alpha.1 | 0.20.1 verified | **Plugins → dsh-client-auto-continue** |
77
77
  | 0.2.0-rc.1 | 0.12.1 or newer | **Plugins → dsh-client-auto-continue** |
78
78
  | 0.1.7-rc.2 | 0.11.9 or newer | **Plugins → dsh-client-auto-continue** |
79
79
  | Older hosts with the legacy settings API | legacy UI | **Settings → Plugins → Plugin configuration** |
@@ -323,6 +323,8 @@ Patterns are plain substrings, not regular expressions. Cooldown and **Max conse
323
323
 
324
324
  **Unreadable sessions.** If a session's history cannot be read during the startup scan, that session is skipped and an error is logged; other sessions still recover ([#58](https://github.com/HsiangNianian/dsh-auto-continue/issues/58)). Repair it and restart DSH within the scan window to try again.
325
325
 
326
+ **Cold-read budget.** A stored session is judged by its whole log, so the sweep decodes one full history per session. To keep a large profile from exhausting the host heap, one host instance reads at most 32 stored logs, most recently active first. The order comes from the projection checkpoint cache (`timeContext.lastMessageTime`, then `sessionListMetadata.lastPromptAt`), falling back to the session creation time. Each session counts once, even if its read is retried. The order is the same on every start, so sessions past the budget are skipped rather than queued; they are the least recently active ones, and the freshness window (15 minutes by default) has almost always passed for them. A checkpoint can lag behind a log but never lead it, so it only orders the reads: freshness is still decided by the events at the tail of the log.
327
+
326
328
  ## Troubleshooting
327
329
 
328
330
  | Symptom | What to check |
package/README.ru.md CHANGED
@@ -73,7 +73,7 @@ dsh web
73
73
 
74
74
  | Среда DSH | Версия плагина | Где настройки |
75
75
  | --- | --- | --- |
76
- | 0.2.2-rc.1, 0.2.1-rc.2, 0.2.1-alpha.1 | 0.20.0 проверена | **Plugins → dsh-client-auto-continue** |
76
+ | 0.2.2-rc.1, 0.2.1-rc.2, 0.2.1-alpha.1 | 0.20.1 проверена | **Plugins → dsh-client-auto-continue** |
77
77
  | 0.2.0-rc.1 | 0.12.1 и новее | **Plugins → dsh-client-auto-continue** |
78
78
  | 0.1.7-rc.2 | 0.11.9 и новее | **Plugins → dsh-client-auto-continue** |
79
79
  | Старые хосты с устаревшим API настроек | старый интерфейс | **Settings → Plugins → Plugin configuration** |
@@ -325,6 +325,8 @@ dsh plugin --profile web remove dsh-client-auto-continue
325
325
 
326
326
  **Нечитаемые сессии.** Если историю сессии не удаётся прочитать при стартовом сканировании, она пропускается с ошибкой в логе, а остальные сессии восстанавливаются ([#58](https://github.com/HsiangNianian/dsh-auto-continue/issues/58)). Исправьте её и перезапустите DSH в пределах окна сканирования, чтобы попробовать снова.
327
327
 
328
+ **Бюджет холодных чтений.** Хранимая сессия оценивается по всему журналу, поэтому сканирование раскодирует полную историю каждой сессии. Чтобы большой профиль не исчерпал кучу хоста, один экземпляр хоста читает не более 32 сохранённых журналов, начиная с самых недавно активных. Порядок берётся из кэша проекционных контрольных точек (`timeContext.lastMessageTime`, затем `sessionListMetadata.lastPromptAt`), а без них — из времени создания сессии. Каждая сессия учитывается один раз, даже если чтение повторяется. Порядок одинаков при каждом запуске, поэтому сессии за пределами бюджета пропускаются, а не откладываются: это самые давно активные сессии, и окно свежести (по умолчанию 15 минут) для них почти всегда уже прошло. Контрольная точка может отставать от журнала, но не опережать его, поэтому она задаёт только порядок: свежесть по-прежнему определяется событиями в хвосте журнала.
329
+
328
330
  ## Решение проблем
329
331
 
330
332
  | Симптом | Что проверить |
package/README.zh.md CHANGED
@@ -73,7 +73,7 @@ dsh web
73
73
 
74
74
  | DSH 内核 | 插件版本 | 设置入口 |
75
75
  | --- | --- | --- |
76
- | 0.2.2-rc.1、0.2.1-rc.2、0.2.1-alpha.1 | 0.20.0 已验证 | **插件 → dsh-client-auto-continue** |
76
+ | 0.2.2-rc.1、0.2.1-rc.2、0.2.1-alpha.1 | 0.20.1 已验证 | **插件 → dsh-client-auto-continue** |
77
77
  | 0.2.0-rc.1 | 0.12.1 及以上 | **插件 → dsh-client-auto-continue** |
78
78
  | 0.1.7-rc.2 | 0.11.9 及以上 | **插件 → dsh-client-auto-continue** |
79
79
  | 仅有旧版设置 API 的宿主 | 旧版界面 | **设置 → 插件 → 插件配置** |
@@ -323,6 +323,8 @@ dsh plugin --profile web remove dsh-client-auto-continue
323
323
 
324
324
  **无法读取的会话。** 启动扫描时如果某个会话的历史读不出来,会跳过它并记录错误,其他会话照常恢复([#58](https://github.com/HsiangNianian/dsh-auto-continue/issues/58))。修复后在扫描时间窗内重启 DSH 即可重试。
325
325
 
326
+ **冷读配额。** 已存储的会话要按整份日志裁决,所以扫描为每个会话解码一次完整历史。为了不让会话很多的环境把宿主堆打满,一个宿主实例最多冷读 32 个会话日志,最近活动过的优先。顺序取自投影检查点缓存(`timeContext.lastMessageTime`,其次 `sessionListMetadata.lastPromptAt`),没有检查点时按会话创建时间。每个会话只计一次,读取重试不重复扣配额。每次启动的顺序都一样,所以超出配额的会话是被跳过而不是排队等下次:它们是最久没有活动的那些,新鲜窗口(默认 15 分钟)对它们几乎总是早已过去。检查点只会落后于日志、不会超前,因此只用来排序:是否新鲜仍然由日志尾部的事件决定。
327
+
326
328
  ## 常见问题
327
329
 
328
330
  | 现象 | 排查 |
@@ -0,0 +1,39 @@
1
+ A fix for hosts that crash on startup when the profile has a lot of saved sessions
2
+
3
+ ## Startup no longer runs out of memory
4
+
5
+ Reported and fixed by @anthonyhann in [#91](https://github.com/HsiangNianian/dsh-auto-continue/pull/91)
6
+
7
+ When DSH starts, the plugin looks through saved sessions for ones that were cut off by the restart. To decide, it read each session's whole log, and only then checked whether the last turn was recent enough to resume (15 minutes by default). On a profile with a few hundred sessions that's gigabytes of decoding. On their machine the host ran out of memory, restarted, tried again, and never came up
8
+
9
+ Now one start reads at most 32 saved sessions, the most recently active first
10
+
11
+ - The order comes from DSH's session checkpoint cache, or the session's creation time if there's no cache
12
+ - The cache only decides the order. Whether a session gets resumed is still decided by what's at the end of its log, same as before
13
+ - A session whose read fails and is retried only counts once
14
+ - Sessions past the 32 are skipped. They're the ones that have been idle longest, so they're almost always outside the 15-minute window anyway
15
+
16
+ Live sessions and subagent sessions aren't affected
17
+
18
+ ## Upgrade
19
+
20
+ Let current work finish, stop DSH, then update the profile you use
21
+
22
+ ```bash
23
+ dsh plugin --profile web add dsh-client-auto-continue@0.20.1
24
+ dsh web
25
+ ```
26
+
27
+ Desktop app users should update through the app's Plugins page and restart the app, since it uses its own profile
28
+
29
+ No settings changed
30
+
31
+ ## Validation
32
+
33
+ - Typecheck, build (committed `lib/` reproduces byte for byte), the full regression suite and the DSH runtime compatibility tests
34
+ - New tests cover stopping at 32 reads with the most recently active sessions first, and a few broken logs being retried without pushing healthy sessions out of the budget
35
+ - @anthonyhann measured it against a real profile with 903 saved sessions: the 32 most recent hold 3.3 MB of compressed logs, and the six largest logs (7 to 23 MB each) have no checkpoint, sort last, and aren't read at startup
36
+
37
+ Thanks @anthonyhann for tracking this down with heap numbers instead of just a "it crashes" report
38
+
39
+ **Full changes:** https://github.com/HsiangNianian/dsh-auto-continue/compare/v0.20.0...v0.20.1
package/lib/index.js CHANGED
@@ -1784,6 +1784,7 @@ var MANUAL_NOTIFICATION_REASON = "manual:notification";
1784
1784
  var SWEEP_OBSERVE_BATCH = 16;
1785
1785
  var STORED_READ_TIMEOUT_MS = 5e3;
1786
1786
  var SWEEP_MAX_FAILURES = 3;
1787
+ var STORED_SWEEP_READ_LIMIT = 32;
1787
1788
  var RESTART_CANCEL_CAUSES = /* @__PURE__ */ new Set(["disposed", "legacy"]);
1788
1789
  var DECISION_CANCEL_CAUSES = /* @__PURE__ */ new Set(["user", "parent", "hook"]);
1789
1790
  var CHILD_SWEEP_LIMIT = 8;
@@ -1796,6 +1797,7 @@ var HANDOFF_COPY = {
1796
1797
  ru: (child, code) => `Дочерняя сессия ${child} прервалась из-за ${code} и больше не может быть продолжена напрямую. Проверь её состояние и продолжи или заверши.`
1797
1798
  };
1798
1799
  var GOALS_SERVICE_KEY = "goals";
1800
+ var PROJECTION_CACHE_SERVICE_KEY = "sessionProjectionCache";
1799
1801
  var CHILD_CAUSE_COPY = {
1800
1802
  zh: {
1801
1803
  "open-turn": "回合开始后中断",
@@ -1979,6 +1981,9 @@ var AutoContinueRunner = class {
1979
1981
  /** 存储会话的连续观察/物化失败次数, 触达 SWEEP_MAX_FAILURES 后不再重试。 */
1980
1982
  this.storedSweepFailures = /* @__PURE__ */ new Map();
1981
1983
  this.storedSweepAnnounced = false;
1984
+ /** 本次启动已花掉的存储会话冷读配额(跨轮累计, 启动扫描窗口内不再重置)。 */
1985
+ this.storedReadIds = /* @__PURE__ */ new Set();
1986
+ this.storedBudgetLogged = false;
1982
1987
  this.stopStoredSweep = new AbortController();
1983
1988
  this.disposeSessionEvents = ctx.on("session/event", (session, event) => {
1984
1989
  try {
@@ -3495,6 +3500,7 @@ var AutoContinueRunner = class {
3495
3500
  }
3496
3501
  }
3497
3502
  let observed = 0;
3503
+ const roots = [];
3498
3504
  for (const record2 of records) {
3499
3505
  if (this.disposed || Date.now() >= deadline || this.getConfig().paused || !this.getConfig().scanOnBoot) return;
3500
3506
  if (typeof record2?.header?.id !== "string" || record2.header.id === "") {
@@ -3510,6 +3516,24 @@ var AutoContinueRunner = class {
3510
3516
  continue;
3511
3517
  }
3512
3518
  if (record2.live || this.storedSwept.has(sessionId)) continue;
3519
+ roots.push({ sessionId, header: record2.header, recency: 0, index: roots.length });
3520
+ }
3521
+ if (roots.length > 0) {
3522
+ const cache = this.projectionCache();
3523
+ for (const root of roots) root.recency = this.storedRecency(cache, root.header);
3524
+ roots.sort((left, right) => right.recency - left.recency || left.index - right.index);
3525
+ }
3526
+ for (const root of roots) {
3527
+ if (this.disposed || Date.now() >= deadline || this.getConfig().paused || !this.getConfig().scanOnBoot) return;
3528
+ if (!this.storedReadIds.has(root.sessionId) && this.storedReadIds.size >= STORED_SWEEP_READ_LIMIT) {
3529
+ if (!this.storedBudgetLogged) {
3530
+ this.storedBudgetLogged = true;
3531
+ this.log(`存储扫描冷读已达上限 ${STORED_SWEEP_READ_LIMIT} 个会话, 其余会话本次启动跳过`);
3532
+ }
3533
+ return;
3534
+ }
3535
+ const sessionId = root.sessionId;
3536
+ this.storedReadIds.add(sessionId);
3513
3537
  this.storedSwept.add(sessionId);
3514
3538
  observed += 1;
3515
3539
  let observation;
@@ -3595,6 +3619,30 @@ var AutoContinueRunner = class {
3595
3619
  }
3596
3620
  }
3597
3621
  }
3622
+ /** The optional projection checkpoint cache; absent on hosts that do not ship it. */
3623
+ projectionCache() {
3624
+ try {
3625
+ return this.ctx.get(PROJECTION_CACHE_SERVICE_KEY);
3626
+ } catch {
3627
+ return void 0;
3628
+ }
3629
+ }
3630
+ /**
3631
+ * 冷读排序提示: 投影检查点里的最近活动时间, 没有检查点时回退到会话创建时间。
3632
+ * 检查点只会落后于日志、不会超前, 所以这个数只用来排序, 不用来跳过会话。
3633
+ */
3634
+ storedRecency(cache, header) {
3635
+ const created = typeof header.createdAt === "number" ? header.createdAt : 0;
3636
+ if (cache === void 0) return created;
3637
+ try {
3638
+ const block = cache.cachedSnapshot(header, ["timeContext", "sessionListMetadata"]);
3639
+ const values = block?.values;
3640
+ const at = values?.timeContext?.lastMessageTime ?? values?.sessionListMetadata?.lastPromptAt;
3641
+ return typeof at === "number" && Number.isFinite(at) ? at : created;
3642
+ } catch {
3643
+ return created;
3644
+ }
3645
+ }
3598
3646
  /**
3599
3647
  * 子会话裁决。子会话本身永不直接续跑(父代理权威, 见 README), 但启动扫描要
3600
3648
  * 知道它是否在重启时被打断, 才能在自己的 root 会话上补一次带清单的唤醒。
@@ -69,6 +69,9 @@ export declare class AutoContinueRunner {
69
69
  /** 存储会话的连续观察/物化失败次数, 触达 SWEEP_MAX_FAILURES 后不再重试。 */
70
70
  private readonly storedSweepFailures;
71
71
  private storedSweepAnnounced;
72
+ /** 本次启动已花掉的存储会话冷读配额(跨轮累计, 启动扫描窗口内不再重置)。 */
73
+ private readonly storedReadIds;
74
+ private storedBudgetLogged;
72
75
  private bootScanTimer;
73
76
  private wakeBootScan;
74
77
  private storedSweep;
@@ -264,6 +267,13 @@ export declare class AutoContinueRunner {
264
267
  * 则启动扫描永远看不到它们; 谓词与上方扫描一致, 仅失败类原因。
265
268
  */
266
269
  private sweepStoredSessions;
270
+ /** The optional projection checkpoint cache; absent on hosts that do not ship it. */
271
+ private projectionCache;
272
+ /**
273
+ * 冷读排序提示: 投影检查点里的最近活动时间, 没有检查点时回退到会话创建时间。
274
+ * 检查点只会落后于日志、不会超前, 所以这个数只用来排序, 不用来跳过会话。
275
+ */
276
+ private storedRecency;
267
277
  /**
268
278
  * 子会话裁决。子会话本身永不直接续跑(父代理权威, 见 README), 但启动扫描要
269
279
  * 知道它是否在重启时被打断, 才能在自己的 root 会话上补一次带清单的唤醒。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-client-auto-continue",
3
3
  "description": "Automatically resume interrupted DSH conversations, with an optional autonomous loop.",
4
- "version": "0.20.0",
4
+ "version": "0.20.1",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -129,6 +129,13 @@ const SWEEP_OBSERVE_BATCH = 16;
129
129
  const STORED_READ_TIMEOUT_MS = 5000;
130
130
  /** 单个存储会话连续观察/物化失败达此数后放弃, 避免坏日志反复占满每轮观察配额。 */
131
131
  const SWEEP_MAX_FAILURES = 3;
132
+ /**
133
+ * 一次启动最多冷读多少个存储会话。冷读要整份解码日志(zstd → 逐行 JSON.parse),
134
+ * 几百个会话连着读完足以把宿主堆(默认约 3.4GB)打满; 配额把启动期的内存和耗时
135
+ * 都封住。每个会话只计一次(失败重试、暂停后重读不再扣配额)。排序每次启动都一样,
136
+ * 配额之外的会话等于被跳过——它们最近活动最早, 在 freshMs 窗口内几乎不可能还新鲜。
137
+ */
138
+ const STORED_SWEEP_READ_LIMIT = 32;
132
139
 
133
140
  /** Why a child session needs its root session woken after a restart. */
134
141
  type ChildInterruptCause = 'open-turn' | 'disposed' | 'interrupted' | 'max-tokens' | 'error';
@@ -148,6 +155,14 @@ interface SessionHeaderLike {
148
155
  readonly parentSession?: SessionId;
149
156
  }
150
157
 
158
+ /** The projection cache's zero-I/O listing read, as far as this module uses it. */
159
+ interface ProjectionCacheLike {
160
+ cachedSnapshot(
161
+ meta: SessionHeaderLike,
162
+ keys?: readonly string[],
163
+ ): { readonly values: Record<string, unknown> } | undefined;
164
+ }
165
+
151
166
  /** Cancel causes a host shutdown or a restart produces; only these justify a wake-up. */
152
167
  const RESTART_CANCEL_CAUSES: ReadonlySet<string> = new Set(['disposed', 'legacy']);
153
168
  /** Cancel causes that record an explicit human or parent decision; never recover these. */
@@ -173,6 +188,8 @@ const HANDOFF_COPY = {
173
188
 
174
189
  /** Host service key for goals (0.2.x); older hosts simply do not register it. */
175
190
  const GOALS_SERVICE_KEY = 'goals';
191
+ /** Host service key for the projection checkpoint cache; older hosts do not register it. */
192
+ const PROJECTION_CACHE_SERVICE_KEY = 'sessionProjectionCache';
176
193
 
177
194
  /** Copy for each child interruption cause, keyed by UI locale. */
178
195
  const CHILD_CAUSE_COPY = {
@@ -499,6 +516,9 @@ export class AutoContinueRunner {
499
516
  /** 存储会话的连续观察/物化失败次数, 触达 SWEEP_MAX_FAILURES 后不再重试。 */
500
517
  private readonly storedSweepFailures = new Map<SessionId, number>();
501
518
  private storedSweepAnnounced = false;
519
+ /** 本次启动已花掉的存储会话冷读配额(跨轮累计, 启动扫描窗口内不再重置)。 */
520
+ private readonly storedReadIds = new Set<SessionId>();
521
+ private storedBudgetLogged = false;
502
522
  private bootScanTimer: ReturnType<typeof setTimeout> | undefined;
503
523
  private wakeBootScan: (() => void) | undefined;
504
524
  private storedSweep: Promise<void> | undefined;
@@ -2315,6 +2335,13 @@ export class AutoContinueRunner {
2315
2335
  }
2316
2336
  }
2317
2337
  let observed = 0;
2338
+ // 先只做零成本的筛除, 把要花冷读的根会话收进候选集, 再统一排序、按配额读。
2339
+ const roots: {
2340
+ sessionId: SessionId;
2341
+ header: SessionHeaderLike & { createdAt?: number };
2342
+ recency: number;
2343
+ index: number;
2344
+ }[] = [];
2318
2345
  for (const record of records) {
2319
2346
  if (this.disposed || Date.now() >= deadline || this.getConfig().paused || !this.getConfig().scanOnBoot) return;
2320
2347
  if (typeof record?.header?.id !== 'string' || record.header.id === '') {
@@ -2333,6 +2360,24 @@ export class AutoContinueRunner {
2333
2360
  continue;
2334
2361
  }
2335
2362
  if (record.live || this.storedSwept.has(sessionId)) continue;
2363
+ roots.push({ sessionId, header: record.header, recency: 0, index: roots.length });
2364
+ }
2365
+ if (roots.length > 0) {
2366
+ const cache = this.projectionCache();
2367
+ for (const root of roots) root.recency = this.storedRecency(cache, root.header);
2368
+ roots.sort((left, right) => right.recency - left.recency || left.index - right.index);
2369
+ }
2370
+ for (const root of roots) {
2371
+ if (this.disposed || Date.now() >= deadline || this.getConfig().paused || !this.getConfig().scanOnBoot) return;
2372
+ if (!this.storedReadIds.has(root.sessionId) && this.storedReadIds.size >= STORED_SWEEP_READ_LIMIT) {
2373
+ if (!this.storedBudgetLogged) {
2374
+ this.storedBudgetLogged = true;
2375
+ this.log(`存储扫描冷读已达上限 ${STORED_SWEEP_READ_LIMIT} 个会话, 其余会话本次启动跳过`);
2376
+ }
2377
+ return;
2378
+ }
2379
+ const sessionId = root.sessionId;
2380
+ this.storedReadIds.add(sessionId);
2336
2381
  this.storedSwept.add(sessionId);
2337
2382
  observed += 1;
2338
2383
  let observation: StoredObservation | undefined;
@@ -2430,6 +2475,40 @@ export class AutoContinueRunner {
2430
2475
  }
2431
2476
  }
2432
2477
 
2478
+ /** The optional projection checkpoint cache; absent on hosts that do not ship it. */
2479
+ private projectionCache(): ProjectionCacheLike | undefined {
2480
+ try {
2481
+ return this.ctx.get(PROJECTION_CACHE_SERVICE_KEY) as ProjectionCacheLike | undefined;
2482
+ } catch {
2483
+ // 排序提示拿不到时回退到创建时间, 不能影响裁决。
2484
+ return undefined;
2485
+ }
2486
+ }
2487
+
2488
+ /**
2489
+ * 冷读排序提示: 投影检查点里的最近活动时间, 没有检查点时回退到会话创建时间。
2490
+ * 检查点只会落后于日志、不会超前, 所以这个数只用来排序, 不用来跳过会话。
2491
+ */
2492
+ private storedRecency(
2493
+ cache: ProjectionCacheLike | undefined,
2494
+ header: SessionHeaderLike & { createdAt?: number },
2495
+ ): number {
2496
+ const created = typeof header.createdAt === 'number' ? header.createdAt : 0;
2497
+ if (cache === undefined) return created;
2498
+ try {
2499
+ const block = cache.cachedSnapshot(header, ['timeContext', 'sessionListMetadata']);
2500
+ const values = block?.values as {
2501
+ timeContext?: { lastMessageTime?: number };
2502
+ sessionListMetadata?: { lastPromptAt?: number };
2503
+ } | undefined;
2504
+ const at = values?.timeContext?.lastMessageTime ?? values?.sessionListMetadata?.lastPromptAt;
2505
+ return typeof at === 'number' && Number.isFinite(at) ? at : created;
2506
+ } catch {
2507
+ // 缓存读失败只影响排序, 不影响裁决。
2508
+ return created;
2509
+ }
2510
+ }
2511
+
2433
2512
  /**
2434
2513
  * 子会话裁决。子会话本身永不直接续跑(父代理权威, 见 README), 但启动扫描要
2435
2514
  * 知道它是否在重启时被打断, 才能在自己的 root 会话上补一次带清单的唤醒。