@remnic/core 10.0.115 → 10.0.117

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 (51) hide show
  1. package/dist/access-admin-ops-surface.js +5 -5
  2. package/dist/access-cli.js +5 -5
  3. package/dist/access-extraction-force-flush.js +5 -5
  4. package/dist/access-http-briefing.js +5 -5
  5. package/dist/access-http-query.js +5 -5
  6. package/dist/access-http.js +5 -5
  7. package/dist/access-identity-continuity-surface.js +5 -5
  8. package/dist/access-lcm-surface.js +5 -5
  9. package/dist/access-mcp.js +5 -5
  10. package/dist/access-observe-write-surface.js +5 -5
  11. package/dist/access-operations-batch.js +5 -5
  12. package/dist/access-operations.js +5 -5
  13. package/dist/access-recall-concurrency.js +5 -5
  14. package/dist/access-recall-response.js +5 -5
  15. package/dist/access-recall-surface.js +5 -5
  16. package/dist/access-service.js +5 -5
  17. package/dist/buffer.js +2 -2
  18. package/dist/{chunk-U7LMXR2W.js → chunk-CAE7ALRH.js} +2 -2
  19. package/dist/{chunk-BTXK3JBP.js → chunk-N56BTEXA.js} +5 -5
  20. package/dist/{chunk-JSDKE6UY.js → chunk-N7WTIHT2.js} +4 -4
  21. package/dist/{chunk-MYXJCR3E.js → chunk-TWPQVPD4.js} +2 -2
  22. package/dist/{chunk-WOXO4HE6.js → chunk-URXJ4CDO.js} +35 -8
  23. package/dist/chunk-URXJ4CDO.js.map +1 -0
  24. package/dist/{chunk-KBUFYKUN.js → chunk-ZPPKBURE.js} +2 -2
  25. package/dist/cli.js +5 -5
  26. package/dist/explicit-capture.js +5 -5
  27. package/dist/extraction.js +3 -3
  28. package/dist/index.js +5 -5
  29. package/dist/orchestration/backlog-scheduler.js +6 -6
  30. package/dist/orchestration/buffer-drain-runner.js +6 -6
  31. package/dist/orchestration/extraction-run.d.ts +3 -0
  32. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  33. package/dist/orchestration/probe-deadline.d.ts +13 -0
  34. package/dist/orchestration/probe-deadline.d.ts.map +1 -0
  35. package/dist/orchestration/provider-breaker.d.ts +9 -0
  36. package/dist/orchestration/provider-breaker.d.ts.map +1 -1
  37. package/dist/orchestrator.js +5 -5
  38. package/dist/recall-navigation.js +5 -5
  39. package/dist/source-agent-qualifier.js +2 -2
  40. package/package.json +2 -2
  41. package/src/orchestration/extraction-run.test.ts +110 -0
  42. package/src/orchestration/extraction-run.ts +19 -7
  43. package/src/orchestration/probe-deadline.ts +38 -0
  44. package/src/orchestration/provider-breaker.ts +10 -0
  45. package/src/storage/buffer-drain-claims.test.ts +55 -1
  46. package/dist/chunk-WOXO4HE6.js.map +0 -1
  47. /package/dist/{chunk-U7LMXR2W.js.map → chunk-CAE7ALRH.js.map} +0 -0
  48. /package/dist/{chunk-BTXK3JBP.js.map → chunk-N56BTEXA.js.map} +0 -0
  49. /package/dist/{chunk-JSDKE6UY.js.map → chunk-N7WTIHT2.js.map} +0 -0
  50. /package/dist/{chunk-MYXJCR3E.js.map → chunk-TWPQVPD4.js.map} +0 -0
  51. /package/dist/{chunk-KBUFYKUN.js.map → chunk-ZPPKBURE.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"provider-breaker.d.ts","sourceRoot":"","sources":["../../src/orchestration/provider-breaker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IAChD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B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ectionChecksWithTimeout,
8
8
  resolveEffectiveIdentityInjectionMode
9
- } from "./chunk-BTXK3JBP.js";
9
+ } from "./chunk-N56BTEXA.js";
10
10
  import "./chunk-6P7U3HWG.js";
11
11
  import "./chunk-PQM3B54K.js";
12
12
  import "./chunk-B3DR2JBZ.js";
@@ -196,9 +196,9 @@ import "./chunk-IHCXMYSE.js";
196
196
  import "./chunk-D6IGZYTN.js";
197
197
  import "./chunk-W7K5BP3M.js";
198
198
  import "./chunk-LZIOY7ZU.js";
199
- import "./chunk-U7LMXR2W.js";
199
+ import "./chunk-CAE7ALRH.js";
200
200
  import "./chunk-EI6V5UXY.js";
201
- import "./chunk-MYXJCR3E.js";
201
+ import "./chunk-TWPQVPD4.js";
202
202
  import "./chunk-UA2NDTIU.js";
203
203
  import "./chunk-6XTUZKCZ.js";
204
204
  import "./chunk-54V4BZWP.js";
@@ -296,10 +296,10 @@ import "./chunk-GKCXTSFF.js";
296
296
  import "./chunk-2LSZVONP.js";
297
297
  import "./chunk-DEUNUKTD.js";
298
298
  import "./chunk-LXY5VVGM.js";
299
- import "./chunk-KBUFYKUN.js";
299
+ import "./chunk-ZPPKBURE.js";
300
300
  import {
301
301
  deriveTopicsFromExtraction
302
- } from "./chunk-WOXO4HE6.js";
302
+ } from "./chunk-URXJ4CDO.js";
303
303
  import {
304
304
  BulkImportBatchPartialFailureError,
305
305
  COMPACTION_SIGNAL_MAX_AGE_MS,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runRecallNavigation
3
- } from "./chunk-BTXK3JBP.js";
3
+ } from "./chunk-N56BTEXA.js";
4
4
  import "./chunk-6P7U3HWG.js";
5
5
  import "./chunk-PQM3B54K.js";
6
6
  import "./chunk-B3DR2JBZ.js";
@@ -186,9 +186,9 @@ import "./chunk-IHCXMYSE.js";
186
186
  import "./chunk-D6IGZYTN.js";
187
187
  import "./chunk-W7K5BP3M.js";
188
188
  import "./chunk-LZIOY7ZU.js";
189
- import "./chunk-U7LMXR2W.js";
189
+ import "./chunk-CAE7ALRH.js";
190
190
  import "./chunk-EI6V5UXY.js";
191
- import "./chunk-MYXJCR3E.js";
191
+ import "./chunk-TWPQVPD4.js";
192
192
  import "./chunk-UA2NDTIU.js";
193
193
  import "./chunk-6XTUZKCZ.js";
194
194
  import "./chunk-54V4BZWP.js";
@@ -286,8 +286,8 @@ import "./chunk-GKCXTSFF.js";
286
286
  import "./chunk-2LSZVONP.js";
287
287
  import "./chunk-DEUNUKTD.js";
288
288
  import "./chunk-LXY5VVGM.js";
289
- import "./chunk-KBUFYKUN.js";
290
- import "./chunk-WOXO4HE6.js";
289
+ import "./chunk-ZPPKBURE.js";
290
+ import "./chunk-URXJ4CDO.js";
291
291
  import "./chunk-THV6PZ7V.js";
292
292
  import "./chunk-CSAKJVXW.js";
293
293
  import "./chunk-K2XUWZBM.js";
@@ -3,7 +3,7 @@ import {
3
3
  headerConnector,
4
4
  renderExtractionConversation,
5
5
  resolveSourceConnector
6
- } from "./chunk-MYXJCR3E.js";
6
+ } from "./chunk-TWPQVPD4.js";
7
7
  import "./chunk-UA2NDTIU.js";
8
8
  import "./chunk-6XTUZKCZ.js";
9
9
  import "./chunk-D3ZKHLN2.js";
@@ -14,7 +14,7 @@ import "./chunk-VEWZZM3H.js";
14
14
  import "./chunk-BCMB7GJQ.js";
15
15
  import "./chunk-3UXOZBHV.js";
16
16
  import "./chunk-AL3TCNSJ.js";
17
- import "./chunk-WOXO4HE6.js";
17
+ import "./chunk-URXJ4CDO.js";
18
18
  import "./chunk-THV6PZ7V.js";
19
19
  import "./chunk-CSAKJVXW.js";
20
20
  import "./chunk-K2XUWZBM.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.115",
3
+ "version": "10.0.117",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3386,7 +3386,7 @@
3386
3386
  "core"
3387
3387
  ],
3388
3388
  "peerDependencies": {
3389
- "@remnic/coding-graph": "^10.0.115"
3389
+ "@remnic/coding-graph": "^10.0.117"
3390
3390
  },
3391
3391
  "peerDependenciesMeta": {
3392
3392
  "@remnic/coding-graph": {
@@ -1593,3 +1593,113 @@ test("#3227: a failed reflection-only persist stays retryable instead of an empt
1593
1593
  await h.cleanup();
1594
1594
  }
1595
1595
  });
1596
+
1597
+ test("half-open probe: a probe that cannot answer in time re-opens the breaker instead of holding every attempt", async () => {
1598
+ const h = await makeHarness({
1599
+ extractionRetryScheduleMs: [3_600_000],
1600
+ extractionBreakerFailureThreshold: 1,
1601
+ extractionBreakerCooldownMs: 0, // the next call flips open to half_open and probes
1602
+ });
1603
+ try {
1604
+ let calls = 0;
1605
+ const abortedWhenStopped: boolean[] = [];
1606
+ const coord = new ExtractionRunCoordinator({
1607
+ ...h.makeDeps(),
1608
+ halfOpenProbeTimeoutMs: 40,
1609
+ getExtraction: () => ({
1610
+ extract: async (_turns, _entities, signal) => {
1611
+ calls += 1;
1612
+ if (calls === 1) return failureResult("provider_retryable");
1613
+ // The probe: no answer until the caller gives up.
1614
+ const stopped = Promise.withResolvers<void>();
1615
+ signal?.addEventListener("abort", () => stopped.resolve(), { once: true });
1616
+ await stopped.promise;
1617
+ abortedWhenStopped.push(signal?.aborted === true);
1618
+ return successResult();
1619
+ },
1620
+ }),
1621
+ });
1622
+ await h.run(coord, "fp-1"); // one failure opens the breaker
1623
+ assert.equal(coord.getExtractionResilienceStatus().breaker.state, "open");
1624
+
1625
+ const guard = Promise.withResolvers<null>();
1626
+ const guardTimer = setTimeout(() => guard.resolve(null), 1_500);
1627
+ const outcome = await Promise.race([h.run(coord, "fp-2"), guard.promise]);
1628
+ clearTimeout(guardTimer);
1629
+ assert.ok(outcome !== null, "the probe is bounded, not held until the provider answers");
1630
+ assert.deepEqual(abortedWhenStopped, [true], "the in-flight request was cancelled");
1631
+ assert.equal(coord.getExtractionResilienceStatus().breaker.state, "open", "a timed-out probe re-opens the breaker");
1632
+ assert.equal(outcome.retainedBuffer, true, "the turns are kept for a retry");
1633
+ } finally {
1634
+ await h.cleanup();
1635
+ }
1636
+ });
1637
+
1638
+ test("half-open probe timeout bounds only the probe: a normal attempt may run longer", async () => {
1639
+ const h = await makeHarness({ extractionRetryScheduleMs: [3_600_000] });
1640
+ try {
1641
+ const coord = new ExtractionRunCoordinator({
1642
+ ...h.makeDeps(),
1643
+ halfOpenProbeTimeoutMs: 20,
1644
+ getExtraction: () => ({
1645
+ extract: async () => {
1646
+ const slow = Promise.withResolvers<void>();
1647
+ setTimeout(() => slow.resolve(), 150);
1648
+ await slow.promise;
1649
+ return successResult();
1650
+ },
1651
+ }),
1652
+ });
1653
+ const outcome = await h.run(coord, "fp-1"); // breaker closed: no probe, no bound
1654
+ assert.equal(outcome.status, "completed");
1655
+ } finally {
1656
+ await h.cleanup();
1657
+ }
1658
+ });
1659
+
1660
+ test("half-open probe timeout keeps the caller deadline enforced while the failure is recorded", async () => {
1661
+ const h = await makeHarness({
1662
+ extractionRetryScheduleMs: [3_600_000],
1663
+ extractionBreakerFailureThreshold: 1,
1664
+ extractionBreakerCooldownMs: 0,
1665
+ });
1666
+ try {
1667
+ let calls = 0;
1668
+ const coord = new ExtractionRunCoordinator({
1669
+ ...h.makeDeps(),
1670
+ halfOpenProbeTimeoutMs: 20,
1671
+ getExtraction: () => ({
1672
+ extract: async (_turns, _entities, signal) => {
1673
+ calls += 1;
1674
+ if (calls === 1) return failureResult("provider_retryable");
1675
+ const stopped = Promise.withResolvers<void>();
1676
+ signal?.addEventListener("abort", () => stopped.resolve(), { once: true });
1677
+ await stopped.promise;
1678
+ return successResult();
1679
+ },
1680
+ }),
1681
+ });
1682
+ await h.run(coord, "fp-1"); // opens the breaker
1683
+ // Recording the probe failure must not outlive the caller deadline.
1684
+ const storage = await h.storageForNs("default");
1685
+ storage.updateMeta = () => new Promise<never>(() => {});
1686
+ const guard = Promise.withResolvers<"hung">();
1687
+ const guardTimer = setTimeout(() => guard.resolve("hung"), 2_000);
1688
+ const outcome = await Promise.race([
1689
+ coord
1690
+ .runExtraction(makeTurns("fp-2"), {
1691
+ skipCharThreshold: true,
1692
+ skipUserTurnThreshold: true,
1693
+ clearBufferAfterExtraction: false,
1694
+ bufferKey: "fp-2",
1695
+ deadlineMs: Date.now() + 300,
1696
+ })
1697
+ .then(() => "returned", () => "rejected"),
1698
+ guard.promise,
1699
+ ]);
1700
+ clearTimeout(guardTimer);
1701
+ assert.notEqual(outcome, "hung", "the caller deadline cut the hung metadata write");
1702
+ } finally {
1703
+ await h.cleanup();
1704
+ }
1705
+ });
@@ -117,6 +117,9 @@ export interface ExtractionRunCoordinatorDeps {
117
117
  * abort signal: queued tasks never start and in-flight runs abort the
118
118
  * moment destroy() begins. Absent for standalone coordinators (tests). */
119
119
  shutdownSignal?: AbortSignal;
120
+ /** Test seam: how long a half-open probe may run before it counts as a
121
+ * provider failure. Defaults to HALF_OPEN_PROBE_TIMEOUT_MS (provider-breaker.ts). */
122
+ halfOpenProbeTimeoutMs?: number;
120
123
  }
121
124
 
122
125
  // Recall/extraction abort helpers live in orchestrator-helpers.ts since
@@ -138,6 +141,7 @@ import {
138
141
  import type { ExtractionResilienceStatus, ExtractionRetryStateEntry } from "./extraction-run-helpers.js";
139
142
  import type { ExtractionPersistResult } from "./extraction-persist.js";
140
143
  import { ProviderCircuitBreaker, type ProbeOwnerToken } from "./provider-breaker.js";
144
+ import { probeTimedOutResult, startProbeDeadline } from "./probe-deadline.js";
141
145
 
142
146
  export {
143
147
  capExtractionRetryStateEntries,
@@ -852,18 +856,26 @@ export class ExtractionRunCoordinator {
852
856
  "during_list_entity_names",
853
857
  );
854
858
  let result: ExtractionResult;
859
+ // The half-open probe is bounded: one that gets no answer in time counts as
860
+ // a provider failure (re-opens the breaker) instead of holding every other
861
+ // attempt until the provider answers or times out.
862
+ const probe = startProbeDeadline(extractionProbeOwned, extractionAbortSignal, this.deps.halfOpenProbeTimeoutMs);
855
863
  try {
856
864
  result = await raceRecallAbort(
857
- this.deps.getExtraction().extract(normalizedTurns, existingEntities, extractionAbortSignal),
858
- extractionAbortSignal,
865
+ this.deps.getExtraction().extract(normalizedTurns, existingEntities, probe.signal),
866
+ probe.signal,
859
867
  "extraction aborted (during_extract)",
860
868
  );
861
869
  } catch (error) {
862
- clearExtractionDeadlineTimer();
863
- if (deadlineMs !== undefined && Date.now() >= deadlineMs) {
864
- throw new ExtractionDeadlineError("during_extract");
865
- }
866
- throw error;
870
+ const pastDeadline = deadlineMs !== undefined && Date.now() >= deadlineMs;
871
+ // Keep the caller deadline timer running while a probe timeout is turned into a failure result.
872
+ if (pastDeadline || !probe.timedOut()) clearExtractionDeadlineTimer();
873
+ if (pastDeadline) throw new ExtractionDeadlineError("during_extract");
874
+ if (!probe.timedOut()) throw error;
875
+ log.warn("runExtraction: half-open probe got no answer in time; treating it as a provider failure");
876
+ result = probeTimedOutResult();
877
+ } finally {
878
+ probe.stop();
867
879
  }
868
880
  try {
869
881
  throwIfDeadlineExceeded("before_persist");
@@ -0,0 +1,38 @@
1
+ import type { ExtractionResult } from "../types.js";
2
+ import { HALF_OPEN_PROBE_TIMEOUT_MS } from "./provider-breaker.js";
3
+
4
+ export interface ProbeDeadline {
5
+ /** The caller's signal, plus the probe timer's when this attempt owns the probe. */
6
+ readonly signal: AbortSignal | undefined;
7
+ /** True only when the probe timer fired (not when the caller aborted). */
8
+ timedOut(): boolean;
9
+ stop(): void;
10
+ }
11
+
12
+ /** Bounds the single half-open probe; any other attempt keeps the caller's signal and no timer. */
13
+ export function startProbeDeadline(
14
+ probeOwned: boolean,
15
+ callerSignal: AbortSignal | undefined,
16
+ timeoutMs: number = HALF_OPEN_PROBE_TIMEOUT_MS,
17
+ ): ProbeDeadline {
18
+ if (!probeOwned) return { signal: callerSignal, timedOut: () => false, stop: () => undefined };
19
+ const timeout = new AbortController();
20
+ const timer = setTimeout(() => timeout.abort(), timeoutMs);
21
+ return {
22
+ signal: callerSignal ? AbortSignal.any([callerSignal, timeout.signal]) : timeout.signal,
23
+ timedOut: () => timeout.signal.aborted,
24
+ stop: () => clearTimeout(timer),
25
+ };
26
+ }
27
+
28
+ /** What a probe that got no answer in time reports: the ordinary retryable provider failure. */
29
+ export function probeTimedOutResult(): ExtractionResult {
30
+ return {
31
+ facts: [],
32
+ profileUpdates: [],
33
+ entities: [],
34
+ questions: [],
35
+ extractionFailure: "local_llm_unavailable",
36
+ extractionFailureClass: "provider_retryable",
37
+ };
38
+ }
@@ -7,6 +7,16 @@ export interface ProviderBreakerConfig {
7
7
  readonly authCooldownMs: number;
8
8
  }
9
9
 
10
+ /**
11
+ * How long the single half-open probe may run before it counts as a provider
12
+ * failure and re-opens the breaker. Before this bound, a probe waiting in the
13
+ * local LLM queue and then timing out twice held every drain for up to 55 min.
14
+ * 15 min covers the slowest probe that did succeed in a 24 h production log
15
+ * (10 min) and caps a failed one at 15 min plus the cooldown.
16
+ * shortcut: a constant, not config; make it a config key if hosts need to tune it.
17
+ */
18
+ export const HALF_OPEN_PROBE_TIMEOUT_MS = 900_000;
19
+
10
20
  export interface ProbeOwnerToken {
11
21
  readonly __probeOwner: true;
12
22
  }
@@ -1,5 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
- import { mkdtempSync, readdirSync, existsSync, readFileSync, writeFileSync, appendFileSync, mkdirSync, rmSync, statSync, truncateSync, utimesSync } from "node:fs";
2
+ import { mkdtempSync, readdirSync, existsSync, readFileSync, writeFileSync, appendFileSync, mkdirSync, rmSync, statSync, truncateSync, utimesSync, renameSync } from "node:fs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import os from "node:os";
5
5
  import { hostname } from "node:os";
@@ -1375,3 +1375,57 @@ test("a listing skips an unreadably long inbox beside a drained body without rea
1375
1375
  s.cleanup();
1376
1376
  }
1377
1377
  });
1378
+
1379
+ const PINNED_MTIME_S = 1_700_000_000;
1380
+
1381
+ /** Plain io, except every append leaves the inbox mtime at a known whole second, so a test can
1382
+ * change exactly one of inode, size and mtime afterwards. */
1383
+ function pinnedMtimeIo() {
1384
+ const io = plainIo();
1385
+ return {
1386
+ ...io,
1387
+ append: async (filePath: string, content: string) => {
1388
+ await io.append(filePath, content);
1389
+ utimesSync(filePath, PINNED_MTIME_S, PINNED_MTIME_S);
1390
+ },
1391
+ };
1392
+ }
1393
+
1394
+ /** Hand "a","b" in, change the inbox so "b" is gone and only `changed` differs, hand "a","b","c" in. */
1395
+ async function handInAfterInboxChangedOnlyIn(changed: "inode" | "size" | "mtime"): Promise<string[]> {
1396
+ const s = setup();
1397
+ try {
1398
+ const claims = new BufferDrainClaims(s.stateDir, pinnedMtimeIo());
1399
+ s.seedSession("sess-1", entry([turn("a", at(0))]));
1400
+ await claims.claimFromSessionFile("sess-1", makeLease());
1401
+ await claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1))]));
1402
+ const file = inboxFile(s.stateDir, "sess-1");
1403
+ const before = statSync(file);
1404
+ const text = readFileSync(file, "utf8");
1405
+ // "z" keeps the byte length; "zz" grows it by one.
1406
+ const replaced = text.replace('"content":"b"', changed === "size" ? '"content":"zz"' : '"content":"z"');
1407
+ assert.notEqual(replaced, text, "fixture: b was in the inbox");
1408
+ if (changed === "inode") {
1409
+ writeFileSync(`${file}.new`, replaced);
1410
+ renameSync(`${file}.new`, file);
1411
+ } else {
1412
+ writeFileSync(file, replaced);
1413
+ }
1414
+ utimesSync(file, changed === "mtime" ? PINNED_MTIME_S + 100 : PINNED_MTIME_S, changed === "mtime" ? PINNED_MTIME_S + 100 : PINNED_MTIME_S);
1415
+ const after = statSync(file);
1416
+ assert.equal(after.ino === before.ino, changed !== "inode", "fixture: inode");
1417
+ assert.equal(after.size === before.size, changed !== "size", "fixture: size");
1418
+ assert.equal(after.mtimeMs === before.mtimeMs, changed !== "mtime", "fixture: mtime");
1419
+ await claims.mergeIntoClaim("sess-1", entry([turn("a", at(0)), turn("b", at(1)), turn("c", at(2))]));
1420
+ return (await claims.load("sess-1"))?.entry.turns.map((t) => t.content) ?? [];
1421
+ } finally {
1422
+ s.cleanup();
1423
+ }
1424
+ }
1425
+
1426
+ for (const changed of ["inode", "size", "mtime"] as const) {
1427
+ test(`a hand-in sends the whole entry again when only the inbox ${changed} changed`, async () => {
1428
+ const contents = await handInAfterInboxChangedOnlyIn(changed);
1429
+ assert.ok(contents.includes("b") && contents.includes("c"), `b is handed in again, not lost: ${contents.join(",")}`);
1430
+ });
1431
+ }