@hearsay-tools/squawk 0.18.0-dev.7788 → 0.18.0-dev.7796

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 (108) hide show
  1. package/dist/autosave-cleanup.js +2 -1
  2. package/dist/autosave-cleanup.js.map +1 -1
  3. package/dist/autosave-git.js +1 -1
  4. package/dist/autosave-git.js.map +1 -1
  5. package/dist/autosave-holders.d.ts +1 -1
  6. package/dist/autosave-holders.js +2 -1
  7. package/dist/autosave-holders.js.map +1 -1
  8. package/dist/core/process-stat.d.ts +15 -0
  9. package/dist/core/process-stat.js +41 -1
  10. package/dist/core/process-stat.js.map +1 -1
  11. package/dist/delegation/process-liveness.d.ts +0 -15
  12. package/dist/delegation/process-liveness.js +5 -43
  13. package/dist/delegation/process-liveness.js.map +1 -1
  14. package/dist/delegation/routes.d.ts +10 -10
  15. package/dist/delegation/service.js +2 -1
  16. package/dist/delegation/service.js.map +1 -1
  17. package/dist/delegation/transport.d.ts +15 -15
  18. package/dist/delegation/worker-cleanup.js +1 -1
  19. package/dist/delegation/worker-cleanup.js.map +1 -1
  20. package/dist/jobs/job.js +2 -1
  21. package/dist/jobs/job.js.map +1 -1
  22. package/dist/preview/chromium.js +1 -1
  23. package/dist/preview/chromium.js.map +1 -1
  24. package/dist/preview/dev-server.js +1 -1
  25. package/dist/preview/dev-server.js.map +1 -1
  26. package/dist/process-wait/supervisor.js +1 -1
  27. package/dist/process-wait/supervisor.js.map +1 -1
  28. package/dist/project-commands.js +2 -1
  29. package/dist/project-commands.js.map +1 -1
  30. package/dist/runs/arm-repo-handle.d.ts +17 -2
  31. package/dist/runs/arm-repo-handle.js +2 -3
  32. package/dist/runs/arm-repo-handle.js.map +1 -1
  33. package/dist/runs/auto-name.d.ts +6 -1
  34. package/dist/runs/auto-name.js +1 -2
  35. package/dist/runs/auto-name.js.map +1 -1
  36. package/dist/runs/owned-run-create.d.ts +4 -1
  37. package/dist/runs/owned-run-create.js +1 -2
  38. package/dist/runs/owned-run-create.js.map +1 -1
  39. package/dist/runs/ports.d.ts +6 -5
  40. package/dist/runs/run-claims.js +1 -1
  41. package/dist/runs/run-claims.js.map +1 -1
  42. package/dist/runs/run-row.d.ts +2 -0
  43. package/dist/runs/run-row.js +8 -0
  44. package/dist/runs/run-row.js.map +1 -1
  45. package/dist/runs/store.d.ts +6 -22
  46. package/dist/runs/store.js +28 -113
  47. package/dist/runs/store.js.map +1 -1
  48. package/dist/runs/transcript-facts-topic.d.ts +45 -0
  49. package/dist/runs/transcript-facts-topic.js +101 -0
  50. package/dist/runs/transcript-facts-topic.js.map +1 -0
  51. package/dist/runs/worker-execution.d.ts +1 -1
  52. package/dist/runs/worker-execution.js +1 -1
  53. package/dist/runs/worker-execution.js.map +1 -1
  54. package/dist/runs/worker-resource-holders.d.ts +1 -1
  55. package/dist/runs/worker-resource-holders.js +1 -1
  56. package/dist/runs/worker-resource-holders.js.map +1 -1
  57. package/dist/server/live-routes.d.ts +6 -6
  58. package/dist/server/models-routes.d.ts +13 -13
  59. package/dist/server/project-context.d.ts +1 -1
  60. package/dist/server/project-context.js +2 -1
  61. package/dist/server/project-context.js.map +1 -1
  62. package/dist/server/reports-api.d.ts +2 -2
  63. package/dist/server/workspace-live-routes.d.ts +6 -6
  64. package/dist/worker-scope/worker-scopes.d.ts +1 -1
  65. package/dist/workflows/run/continuation-acceptance.js +1 -1
  66. package/dist/workflows/run/continuation-acceptance.js.map +1 -1
  67. package/dist/workflows/run/continuation-session.js +2 -2
  68. package/dist/workflows/run/continuation-session.js.map +1 -1
  69. package/dist/workflows/run/family-reconciler.js +2 -2
  70. package/dist/workflows/run/family-reconciler.js.map +1 -1
  71. package/dist/workflows/run/human-waits.js +4 -4
  72. package/dist/workflows/run/human-waits.js.map +1 -1
  73. package/dist/workflows/run/input-delivery.js +3 -3
  74. package/dist/workflows/run/input-delivery.js.map +1 -1
  75. package/dist/workflows/run/launch-read-resolver.d.ts +3 -0
  76. package/dist/workflows/run/launch-read-resolver.js +2 -0
  77. package/dist/workflows/run/launch-read-resolver.js.map +1 -1
  78. package/dist/workflows/run/run-finish.js +3 -3
  79. package/dist/workflows/run/run-finish.js.map +1 -1
  80. package/dist/workflows/run/run-recovery.js +6 -6
  81. package/dist/workflows/run/run-recovery.js.map +1 -1
  82. package/dist/workflows/run/run-settlement.js +3 -3
  83. package/dist/workflows/run/run-settlement.js.map +1 -1
  84. package/dist/workflows/run/session-events.js +1 -1
  85. package/dist/workflows/run/session-events.js.map +1 -1
  86. package/dist/workflows/run/turn-bookkeeping.js +2 -2
  87. package/dist/workflows/run/turn-bookkeeping.js.map +1 -1
  88. package/dist/workflows/run/turn-nudges.js +2 -2
  89. package/dist/workflows/run/turn-nudges.js.map +1 -1
  90. package/dist/workflows/run/turn-settler.js +1 -1
  91. package/dist/workflows/run/turn-settler.js.map +1 -1
  92. package/dist/workflows/run/wait-registry.js +1 -1
  93. package/dist/workflows/run/wait-registry.js.map +1 -1
  94. package/dist/workflows/run/worker-orphans.d.ts +1 -1
  95. package/dist/workflows/run/worker-orphans.js +1 -1
  96. package/dist/workflows/run/worker-orphans.js.map +1 -1
  97. package/dist/workflows/run/worker-questions.js +16 -16
  98. package/dist/workflows/run/worker-questions.js.map +1 -1
  99. package/dist/workflows/run.js +1 -1
  100. package/dist/workflows/run.js.map +1 -1
  101. package/package.json +4 -4
  102. package/scripts/benchmark-family-reconcile.ts +2 -1
  103. package/scripts/benchmark-stuck-destroys.ts +2 -1
  104. package/scripts/benchmark-worker-lifecycle.ts +2 -1
  105. package/scripts/measure-transcript-facts-health.mjs +2 -2
  106. package/scripts/measure-transcript-facts-lag.mjs +1 -1
  107. package/scripts/seed-archive-profile.ts +2 -0
  108. package/scripts/transcript-facts-fixture.mjs +1 -1
@@ -9,9 +9,9 @@ import { queuedMessageSchema } from '../contract/index.js';
9
9
  import { type WaitRegistrationReceipt } from '../contract/index.js';
10
10
  import type { ArchiveFinishedScope, ArchivedRunsResponse, ArchivePullRequestIdentity, ConversationState, AgentInput, InboxClaim, DelegationState, MergedPullRequest, RunSummary, Wait, WorkerCollectedResult, WorkerDestroyRetry } from '../contract/index.js';
11
11
  import { type AutomationNames } from '../contract/index.js';
12
- import { type TranscriptFacts } from './transcript-facts.ts';
12
+ import { RunTranscriptFacts } from './transcript-facts-topic.ts';
13
13
  import { type WorkerExecutionIdentity } from '../delegation/execution-identity.ts';
14
- import { type WorkerProcessRecord } from '../delegation/process-liveness.ts';
14
+ import { type WorkerProcessRecord } from '../core/process-stat.ts';
15
15
  import { workflowDefSchema } from '../workflows/types.ts';
16
16
  import { type OutcomeDependencies, type OutcomeReceipt, type RunOutcome } from './outcome-commit.ts';
17
17
  import { type ExitCall, type RunExitId, type RunPatch } from './run-exits.ts';
@@ -22,6 +22,7 @@ import { type BranchOwner } from './branch-owners.ts';
22
22
  export { ciWaitEntry, holdsWorkerWait, upgradeLegacyWaits, workerWaitEntry } from './legacy-waits.ts';
23
23
  import { type RawExtras } from './raw-record.ts';
24
24
  import { RunStoreOpenError } from './store-open-error.ts';
25
+ import { type SpawnCapacityRefusal } from './owned-run-create.ts';
25
26
  /** Per-store persistence adapter; the second argument is the normal fenced transaction. */
26
27
  export type RunStorePersistence = (changes: RunDatabaseChanges, transaction: RunDatabase['transaction']) => RunDatabaseCommit;
27
28
  export type RunStatus = 'queued' | 'running' | 'waiting' | 'review' | 'done' | 'failed' | 'cancelled';
@@ -3307,11 +3308,9 @@ export declare class RunStore {
3307
3308
  private readonly unreadable;
3308
3309
  /** Background one-at-a-time compressor for archived transcripts (#818). */
3309
3310
  private readonly compressor;
3310
- /** Transcript facts the delegation paths ask about, so they never re-read a transcript (#880). */
3311
- private readonly facts;
3311
+ /** What the transcript says about a run (hearsay-tools/squawk#4036). */
3312
+ readonly transcriptFacts: RunTranscriptFacts;
3312
3313
  private readonly liveItems;
3313
- private fallbackFacts;
3314
- private factsFor;
3315
3314
  /** Capture both sources on the same synchronous sequence boundary before history IO. */
3316
3315
  liveReadSnapshot(runId: string): {
3317
3316
  events: {
@@ -3756,7 +3755,7 @@ export declare class RunStore {
3756
3755
  ignoreCleanup?: boolean;
3757
3756
  }): WorkerCollectedResult;
3758
3757
  /** Create an owned worker run and its parent receipt; `createStoreOwnedRun` holds the checks. */
3759
- createOwnedRun(input: Parameters<RunStore['createRun']>[0], parentId: string, requestId: string, worker: DelegationState, requestHash: string, executionIdentity?: WorkerExecutionIdentity): RunRecord;
3758
+ createOwnedRun(input: Parameters<RunStore['createRun']>[0], parentId: string, requestId: string, worker: DelegationState, requestHash: string, spawnCapacityRefusal: SpawnCapacityRefusal, executionIdentity?: WorkerExecutionIdentity): RunRecord;
3760
3759
  /**
3761
3760
  * Durably replace or delete staged rows together with pending dirty rows. Persist before
3762
3761
  * changing held objects or notifying subscribers. On failure retain all pending state; flush()
@@ -3934,24 +3933,9 @@ export declare class RunStore {
3934
3933
  * the `CEZ_REDACT_SECRETS=0` opt-out itself so every caller inherits it. */
3935
3934
  redactText(text: string): string;
3936
3935
  private hostSecrets;
3937
- /** The run's indexed transcript facts (#880): a read-only view, never a transcript read once
3938
- * the run's index is loaded. An unreadable transcript answers as empty, as readEvents does. */
3939
- transcriptFacts(runId: string): Readonly<TranscriptFacts>;
3940
- /** The run's transcript facts when they are known: undefined when the transcript exists but its
3941
- * facts are not current or cannot be read, so a caller can tell "no ask" from "no evidence". */
3942
- knownTranscriptFacts(runId: string): Readonly<TranscriptFacts> | undefined;
3943
3936
  hasProjection(runId: string, projectionId: string): boolean;
3944
- private factsWarming;
3945
3937
  /** Indexed family enumeration, including members not yet flushed to SQLite. */
3946
3938
  listFamilyRunIds(rootId: string): string[];
3947
- private recoveryFactIds;
3948
- /** Readiness owns no run snapshot across an await: refresh only the currently held owner. */
3949
- prepareTranscriptFacts(runIds: Iterable<string>): Promise<void>;
3950
- prepareRecoveryFacts(familyRootId?: string): Promise<void>;
3951
- /** Register IDs only here; the index yields between cache reads and off-loop rebuilds. */
3952
- private warmTranscriptFacts;
3953
- /** Resolves when the open-time warm-up is done (tests). */
3954
- factsWarmIdle(): Promise<void>;
3955
3939
  /** `readEvents` off the event loop (async read and async brotli), for collection paths. */
3956
3940
  readEventsAsync(runId: string): Promise<RunEvent[]>;
3957
3941
  readEvents(runId: string): RunEvent[];
@@ -33,10 +33,11 @@ import { matchesRunSearch, sqlPrefilterTokens } from '../contract/index.js';
33
33
  import { storedDelegationStateSchema } from './delegation-state.js';
34
34
  import { HistoryCompressor } from './history-compressor.js';
35
35
  import { LiveItemSnapshots } from './live-item-snapshots.js';
36
- import { emptyFacts, stampOf, TranscriptFactsIndex } from './transcript-facts.js';
36
+ import { stampOf } from './transcript-facts.js';
37
+ import { RunTranscriptFacts } from './transcript-facts-topic.js';
37
38
  import { hasPlainHistory, historyPaths, readHistoryText, readHistoryTextAsync, removeHistory, restoreHistory } from './history-file.js';
38
39
  import { workerExecutionIdentitySchema } from '../delegation/execution-identity.js';
39
- import { processStartToken } from '../delegation/process-liveness.js';
40
+ import { startToken } from '../core/process-stat.js';
40
41
  import { collectSecretValues, redactDeep } from '../core/secret-redaction.js';
41
42
  // Pure, dependency-free reference helpers — the same sanity bound the marker parser applies.
42
43
  import { archivePullRequests, pullRequestKey } from './pull-requests.js';
@@ -57,7 +58,7 @@ import { failLoadedInterruptedRun, restoreLoadedUsageLimitHold, settleLoadedStop
57
58
  import { hasLegacyWaitFields, UNREADABLE_WAIT } from './legacy-waits.js';
58
59
  export { ciWaitEntry, holdsWorkerWait, upgradeLegacyWaits, workerWaitEntry } from './legacy-waits.js';
59
60
  import { ExitEvents } from './exit-events.js';
60
- import { encodeRunRow, isLiveRecord, isLiveStatus, materializedWorktreePath } from './run-row.js';
61
+ import { encodeRunRow, familyRootOf, isLiveRecord, isLiveStatus, materializedWorktreePath } from './run-row.js';
61
62
  import { collectRawExtras, encodeRawRecord } from './raw-record.js';
62
63
  import { ColdReadCache, storedRow } from './cold-reads.js';
63
64
  import { assertNoLegacyCockpit, assertNoLegacyWriter, backUpLegacyIndex, LEGACY_INDEX_FILE, LegacyWriterError, readLegacyIndex } from './legacy-index.js';
@@ -198,9 +199,6 @@ const OPEN_RETRY_DELAYS_MS = [50, 100, 200, 400, 800, 1600];
198
199
  function sleepSync(ms) {
199
200
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
200
201
  }
201
- /** Runs (and conversation roots, one family query each) the open-time facts warm-up enumerates
202
- * per event-loop turn (hearsay-tools/cezarion#949), so each slice stays a few milliseconds. */
203
- const WARM_IDS_PER_SLICE = 100;
204
202
  const MAX_RUNS_KEPT = 300;
205
203
  /** How many archived root runs the run lists carry per project (#864): `GET /run-summaries?archived=recent`
206
204
  * and `GET /workspace/runs-index`. Unarchived runs are never cut; older archived runs page in
@@ -400,14 +398,6 @@ function decodeArchivedCursor(cursor) {
400
398
  function sortNewestFirst(entries) {
401
399
  return [...entries].sort(([, a], [, b]) => newestFirst(a, b)).map(([item]) => item);
402
400
  }
403
- /** The family a run belongs to, by its root's id. A worker a worker started is filed under the root too. */
404
- function familyRootOf(run) {
405
- if (run.delegation?.role === 'root')
406
- return run.id;
407
- if (run.delegation?.role === 'worker')
408
- return run.delegation.parentRunId;
409
- return undefined;
410
- }
411
401
  /** Tests freeze the copies of cold runs, so an in-place write to one throws instead of vanishing. */
412
402
  function deepFreeze(value) {
413
403
  if (value && typeof value === 'object' && !Object.isFrozen(value)) {
@@ -422,7 +412,6 @@ const recordedProcessSchema = z.object({ pid: z.number().int().positive(), start
422
412
  pgid: z.number().int().positive().optional() }).strict();
423
413
  const workerProcessRecordSchema = z.object({ generation: z.string().uuid(), controller: recordedProcessSchema,
424
414
  processes: z.array(recordedProcessSchema).max(WORKER_PROCESS_CAP) }).strict();
425
- const startToken = (pid) => { const token = processStartToken(pid); return token === undefined ? {} : { startToken: token }; };
426
415
  /**
427
416
  * Run rows in runs.db plus append-only NDJSON events and an in-process event bus. Hold live,
428
417
  * pinned, related and unsettled records only. Optimistic writes debounce; durable commits
@@ -491,19 +480,25 @@ export class RunStore {
491
480
  unreadable = new Set();
492
481
  /** Background one-at-a-time compressor for archived transcripts (#818). */
493
482
  compressor;
494
- /** Transcript facts the delegation paths ask about, so they never re-read a transcript (#880). */
495
- facts;
483
+ /** What the transcript says about a run (hearsay-tools/squawk#4036). */
484
+ transcriptFacts;
496
485
  liveItems = new LiveItemSnapshots();
497
- fallbackFacts;
498
- factsFor(id) { return this.isFallbackRun(id) ? this.fallbackFacts ??= new TranscriptFactsIndex(this.sourceDataDir(id), true) : this.facts; }
499
486
  /** Capture both sources on the same synchronous sequence boundary before history IO. */
500
487
  liveReadSnapshot(runId) {
501
488
  return { events: this.liveItems.read(runId), throughSeq: this.seqs.get(runId) ?? Infinity };
502
489
  }
503
490
  constructor(dataDir) {
504
491
  this.dataDir = dataDir;
505
- this.facts = new TranscriptFactsIndex(dataDir);
506
- this.compressor = new HistoryCompressor(dataDir, (id) => this.isHistoryCompressEligible(id), (id, plain, archive) => this.facts.adoptArchive(id, plain, stampOf(archive)));
492
+ this.transcriptFacts = new RunTranscriptFacts(dataDir, {
493
+ isFallbackRun: (id) => this.isFallbackRun(id),
494
+ sourceDataDir: (id) => this.sourceDataDir(id),
495
+ isOpen: () => this.db !== null,
496
+ held: this.held,
497
+ listFamilyRunIds: (rootId) => this.listFamilyRunIds(rootId),
498
+ listConversationRootIds: () => this.listConversationRootIds(),
499
+ listRunIds: () => this.listRunIds(),
500
+ });
501
+ this.compressor = new HistoryCompressor(dataDir, (id) => this.isHistoryCompressEligible(id), (id, plain, archive) => this.transcriptFacts.index.adoptArchive(id, plain, stampOf(archive)));
507
502
  }
508
503
  /**
509
504
  * Open the project's run store. See `reconcileLoadedRun` for what `keepLive` (#367) decides
@@ -559,7 +554,7 @@ export class RunStore {
559
554
  store.owner = openClaimSession();
560
555
  if (!maintenance) {
561
556
  store.loadHeldRows();
562
- store.warmTranscriptFacts();
557
+ store.transcriptFacts.warmTranscriptFacts();
563
558
  store.exitEvents.writeLoaded();
564
559
  }
565
560
  }
@@ -1781,7 +1776,7 @@ export class RunStore {
1781
1776
  throw new Error('missing worker continuation target');
1782
1777
  const delegation = delegationStateSchema.parse({ ...run.delegation,
1783
1778
  executionRevision: (run.delegation.executionRevision ?? 0) + 1,
1784
- executionStartSeq: this.transcriptFacts(id).lastSeq,
1779
+ executionStartSeq: this.transcriptFacts.transcriptFacts(id).lastSeq,
1785
1780
  });
1786
1781
  const staged = new Map();
1787
1782
  this.exitEvents.started(id);
@@ -1855,7 +1850,7 @@ export class RunStore {
1855
1850
  }, parentId, value, diffSnapshot, opts);
1856
1851
  }
1857
1852
  /** Create an owned worker run and its parent receipt; `createStoreOwnedRun` holds the checks. */
1858
- createOwnedRun(input, parentId, requestId, worker, requestHash, executionIdentity = { kind: 'internal' }) {
1853
+ createOwnedRun(input, parentId, requestId, worker, requestHash, spawnCapacityRefusal, executionIdentity = { kind: 'internal' }) {
1859
1854
  return createStoreOwnedRun({
1860
1855
  peek: (id) => this.peek(id),
1861
1856
  hasRun: (id) => this.hasRun(id),
@@ -1864,7 +1859,7 @@ export class RunStore {
1864
1859
  writeWorkerIdentity: (id, identity) => this.writeWorkerIdentity(id, identity),
1865
1860
  writeWorkerExecution: (id, proof, fresh) => this.writeWorkerExecution(id, proof, fresh),
1866
1861
  commitIndex: (owned) => this.commitIndex(owned),
1867
- }, input, parentId, requestId, worker, requestHash, executionIdentity);
1862
+ }, input, parentId, requestId, worker, requestHash, spawnCapacityRefusal, executionIdentity);
1868
1863
  }
1869
1864
  /**
1870
1865
  * Durably replace or delete staged rows together with pending dirty rows. Persist before
@@ -1919,7 +1914,7 @@ export class RunStore {
1919
1914
  completionArchiveBlocker(root) {
1920
1915
  const family = [root, ...this.listWorkersOf(root.id)];
1921
1916
  for (const run of family) {
1922
- const facts = this.factsFor(run.id).peek(run.id);
1917
+ const facts = this.transcriptFacts.factsFor(run.id).peek(run.id);
1923
1918
  if (!facts || !['done', 'review', 'failed', 'cancelled'].includes(run.status) || run.waits?.some(wait => wait.phase === 'open') ||
1924
1919
  run.hasPendingPermission || facts.pendingAsk !== undefined)
1925
1920
  return 'Task or worker work still needs attention. Open the task or archive manually.';
@@ -2126,7 +2121,7 @@ export class RunStore {
2126
2121
  decodeRunRow,
2127
2122
  decodeCold: (row) => this.decodeCold(row),
2128
2123
  writeRefusal: (memberId) => this.writeRefusal(memberId),
2129
- factsPeek: (memberId) => this.factsFor(memberId).peek(memberId),
2124
+ factsPeek: (memberId) => this.transcriptFacts.factsFor(memberId).peek(memberId),
2130
2125
  readWorkerExecution: (memberId) => this.readWorkerExecution(memberId),
2131
2126
  }, id, isActive);
2132
2127
  }
@@ -2155,7 +2150,7 @@ export class RunStore {
2155
2150
  if (ids.length > 1025)
2156
2151
  return;
2157
2152
  for (const memberId of ids)
2158
- await this.factsFor(memberId).ready(memberId);
2153
+ await this.transcriptFacts.factsFor(memberId).ready(memberId);
2159
2154
  }
2160
2155
  archiveOnMergeSnapshot(id, repoBase, isActive = () => false) {
2161
2156
  const family = this.archiveFamily(id, isActive);
@@ -2435,7 +2430,7 @@ export class RunStore {
2435
2430
  restoreHistory(this.dataDir, runId);
2436
2431
  const line = `${JSON.stringify(full)}\n`;
2437
2432
  appendFileSync(this.eventsPath(runId), line, 'utf8');
2438
- this.facts.append(runId, full, Buffer.byteLength(line));
2433
+ this.transcriptFacts.index.append(runId, full, Buffer.byteLength(line));
2439
2434
  this.maybeEnqueueHistoryCompress(run);
2440
2435
  this.liveItems.observe(runId, full, false);
2441
2436
  this.published.publish('run.event', { runId, event: full });
@@ -2555,20 +2550,9 @@ export class RunStore {
2555
2550
  this.secretValues = collectSecretValues();
2556
2551
  return this.secretValues;
2557
2552
  }
2558
- /** The run's indexed transcript facts (#880): a read-only view, never a transcript read once
2559
- * the run's index is loaded. An unreadable transcript answers as empty, as readEvents does. */
2560
- transcriptFacts(runId) {
2561
- return this.factsFor(runId).get(runId) ?? emptyFacts();
2562
- }
2563
- /** The run's transcript facts when they are known: undefined when the transcript exists but its
2564
- * facts are not current or cannot be read, so a caller can tell "no ask" from "no evidence". */
2565
- knownTranscriptFacts(runId) {
2566
- return this.factsFor(runId).peek(runId);
2567
- }
2568
2553
  hasProjection(runId, projectionId) {
2569
- return this.transcriptFacts(runId).projectionIds.includes(projectionId);
2554
+ return this.transcriptFacts.transcriptFacts(runId).projectionIds.includes(projectionId);
2570
2555
  }
2571
- factsWarming = Promise.resolve();
2572
2556
  /** Indexed family enumeration, including members not yet flushed to SQLite. */
2573
2557
  listFamilyRunIds(rootId) {
2574
2558
  const ids = new Set([rootId, ...(this.db?.listIdsByParent(rootId) ?? [])]);
@@ -2582,73 +2566,6 @@ export class RunStore {
2582
2566
  ids.delete(id);
2583
2567
  return [...ids];
2584
2568
  }
2585
- recoveryFactIds(familyRootId) {
2586
- if (familyRootId !== undefined)
2587
- return this.listFamilyRunIds(familyRootId);
2588
- const ids = new Set();
2589
- for (const [id, run] of this.held) {
2590
- if (!isLiveRecord(run))
2591
- continue;
2592
- const root = familyRootOf(run);
2593
- for (const member of root === undefined ? [id] : this.listFamilyRunIds(root))
2594
- ids.add(member);
2595
- }
2596
- return [...ids];
2597
- }
2598
- /** Readiness owns no run snapshot across an await: refresh only the currently held owner. */
2599
- async prepareTranscriptFacts(runIds) {
2600
- for (const id of new Set(runIds)) {
2601
- // Exact sidecars resolve immediately too: recovery must yield to timers/I/O between IDs.
2602
- await new Promise(resolve => setImmediate(resolve));
2603
- await this.factsFor(id).ready(id);
2604
- }
2605
- }
2606
- prepareRecoveryFacts(familyRootId) {
2607
- return this.prepareTranscriptFacts(this.recoveryFactIds(familyRootId));
2608
- }
2609
- /** Register IDs only here; the index yields between cache reads and off-loop rebuilds. */
2610
- warmTranscriptFacts() {
2611
- this.factsWarming = Promise.resolve().then(async () => {
2612
- if (!this.db)
2613
- return;
2614
- const ids = new Set(this.recoveryFactIds());
2615
- // hearsay-tools/cezarion#949: this microtask ends open()'s synchronous slice, and on a
2616
- // large history the JSON scan for conversation roots plus one family query per root cost
2617
- // as much again. Past one slice's worth of runs, yield before the scan and between root
2618
- // batches; a small store (every unit test) still registers in this one microtask.
2619
- const large = this.listRunIds().length > WARM_IDS_PER_SLICE;
2620
- const turn = async () => {
2621
- await new Promise(resolve => setImmediate(resolve));
2622
- return this.db !== null;
2623
- };
2624
- if (large && !await turn())
2625
- return;
2626
- const roots = this.listConversationRootIds();
2627
- for (let i = 0; i < roots.length; i++) {
2628
- if (large && i > 0 && i % WARM_IDS_PER_SLICE === 0 && !await turn())
2629
- return;
2630
- for (const id of this.listFamilyRunIds(roots[i]))
2631
- ids.add(id);
2632
- }
2633
- if (large && !await turn())
2634
- return;
2635
- // Re-list after the yields: a run deleted meanwhile must not be registered again.
2636
- const present = this.listRunIds();
2637
- if (large) {
2638
- const live = new Set(present);
2639
- for (const id of ids)
2640
- if (!live.has(id))
2641
- ids.delete(id);
2642
- }
2643
- for (const id of present)
2644
- ids.add(id);
2645
- await this.facts.warm(ids);
2646
- }).catch(() => undefined);
2647
- }
2648
- /** Resolves when the open-time warm-up is done (tests). */
2649
- factsWarmIdle() {
2650
- return this.factsWarming;
2651
- }
2652
2569
  /** `readEvents` off the event loop (async read and async brotli), for collection paths. */
2653
2570
  async readEventsAsync(runId) {
2654
2571
  try {
@@ -3007,7 +2924,7 @@ export class RunStore {
3007
2924
  }
3008
2925
  /** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
3009
2926
  removeHistoryFiles(id) {
3010
- this.facts.forget(id);
2927
+ this.transcriptFacts.index.forget(id);
3011
2928
  removeHistory(this.dataDir, id);
3012
2929
  rmSync(this.handoffPath(id), { force: true });
3013
2930
  rmSync(this.imagesDir(id), { recursive: true, force: true });
@@ -3056,7 +2973,7 @@ export class RunStore {
3056
2973
  * resumed event, even across a reload (the frozen-transcript symptom class
3057
2974
  * of #424). One file read on the first post-restart append per run. */
3058
2975
  rehydrateSeq(runId) {
3059
- return this.transcriptFacts(runId).lastSeq;
2976
+ return this.transcriptFacts.transcriptFacts(runId).lastSeq;
3060
2977
  }
3061
2978
  eventsPath(runId) {
3062
2979
  return historyPaths(this.sourceDataDir(runId), runId).plain;
@@ -3383,9 +3300,7 @@ export class RunStore {
3383
3300
  // Demand-bound feeds stop before storage disappears during project removal/shutdown.
3384
3301
  this.published.publish('store.closed', {});
3385
3302
  this.compressor.stop();
3386
- this.fallbackFacts?.stop();
3387
- this.facts.stop();
3388
- this.facts.flush();
3303
+ this.transcriptFacts.stop();
3389
3304
  if (this.saveTimer) {
3390
3305
  clearTimeout(this.saveTimer);
3391
3306
  this.saveTimer = null;