@hearsay-tools/squawk 0.18.0-pr4074.7790 → 0.18.0-pr4075.7794

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 (47) hide show
  1. package/dist/ci-wait/controller.d.ts +46 -46
  2. package/dist/delegation/routes.d.ts +10 -10
  3. package/dist/delegation/transport.d.ts +15 -15
  4. package/dist/runs/ports.d.ts +6 -5
  5. package/dist/runs/run-row.d.ts +2 -0
  6. package/dist/runs/run-row.js +8 -0
  7. package/dist/runs/run-row.js.map +1 -1
  8. package/dist/runs/store.d.ts +3 -20
  9. package/dist/runs/store.js +25 -109
  10. package/dist/runs/store.js.map +1 -1
  11. package/dist/runs/transcript-facts-topic.d.ts +45 -0
  12. package/dist/runs/transcript-facts-topic.js +101 -0
  13. package/dist/runs/transcript-facts-topic.js.map +1 -0
  14. package/dist/server/live-routes.d.ts +6 -6
  15. package/dist/server/models-routes.d.ts +13 -13
  16. package/dist/server/reports-api.d.ts +2 -2
  17. package/dist/server/workspace-live-routes.d.ts +6 -6
  18. package/dist/workflows/run/continuation-acceptance.js +1 -1
  19. package/dist/workflows/run/continuation-acceptance.js.map +1 -1
  20. package/dist/workflows/run/continuation-session.js +2 -2
  21. package/dist/workflows/run/continuation-session.js.map +1 -1
  22. package/dist/workflows/run/family-reconciler.js +2 -2
  23. package/dist/workflows/run/family-reconciler.js.map +1 -1
  24. package/dist/workflows/run/human-waits.js +4 -4
  25. package/dist/workflows/run/human-waits.js.map +1 -1
  26. package/dist/workflows/run/input-delivery.js +3 -3
  27. package/dist/workflows/run/input-delivery.js.map +1 -1
  28. package/dist/workflows/run/run-finish.js +3 -3
  29. package/dist/workflows/run/run-finish.js.map +1 -1
  30. package/dist/workflows/run/run-recovery.js +6 -6
  31. package/dist/workflows/run/run-recovery.js.map +1 -1
  32. package/dist/workflows/run/run-settlement.js +3 -3
  33. package/dist/workflows/run/run-settlement.js.map +1 -1
  34. package/dist/workflows/run/session-events.js +1 -1
  35. package/dist/workflows/run/session-events.js.map +1 -1
  36. package/dist/workflows/run/turn-nudges.js +2 -2
  37. package/dist/workflows/run/turn-nudges.js.map +1 -1
  38. package/dist/workflows/run/turn-settler.js +1 -1
  39. package/dist/workflows/run/turn-settler.js.map +1 -1
  40. package/dist/workflows/run/worker-questions.js +16 -16
  41. package/dist/workflows/run/worker-questions.js.map +1 -1
  42. package/dist/workflows/run.js +1 -1
  43. package/dist/workflows/run.js.map +1 -1
  44. package/package.json +4 -4
  45. package/scripts/measure-transcript-facts-health.mjs +2 -2
  46. package/scripts/measure-transcript-facts-lag.mjs +1 -1
  47. package/scripts/transcript-facts-fixture.mjs +1 -1
@@ -33,7 +33,8 @@ 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
40
  import { startToken } from '../core/process-stat.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)) {
@@ -490,19 +480,25 @@ export class RunStore {
490
480
  unreadable = new Set();
491
481
  /** Background one-at-a-time compressor for archived transcripts (#818). */
492
482
  compressor;
493
- /** Transcript facts the delegation paths ask about, so they never re-read a transcript (#880). */
494
- facts;
483
+ /** What the transcript says about a run (hearsay-tools/squawk#4036). */
484
+ transcriptFacts;
495
485
  liveItems = new LiveItemSnapshots();
496
- fallbackFacts;
497
- factsFor(id) { return this.isFallbackRun(id) ? this.fallbackFacts ??= new TranscriptFactsIndex(this.sourceDataDir(id), true) : this.facts; }
498
486
  /** Capture both sources on the same synchronous sequence boundary before history IO. */
499
487
  liveReadSnapshot(runId) {
500
488
  return { events: this.liveItems.read(runId), throughSeq: this.seqs.get(runId) ?? Infinity };
501
489
  }
502
490
  constructor(dataDir) {
503
491
  this.dataDir = dataDir;
504
- this.facts = new TranscriptFactsIndex(dataDir);
505
- 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)));
506
502
  }
507
503
  /**
508
504
  * Open the project's run store. See `reconcileLoadedRun` for what `keepLive` (#367) decides
@@ -558,7 +554,7 @@ export class RunStore {
558
554
  store.owner = openClaimSession();
559
555
  if (!maintenance) {
560
556
  store.loadHeldRows();
561
- store.warmTranscriptFacts();
557
+ store.transcriptFacts.warmTranscriptFacts();
562
558
  store.exitEvents.writeLoaded();
563
559
  }
564
560
  }
@@ -1780,7 +1776,7 @@ export class RunStore {
1780
1776
  throw new Error('missing worker continuation target');
1781
1777
  const delegation = delegationStateSchema.parse({ ...run.delegation,
1782
1778
  executionRevision: (run.delegation.executionRevision ?? 0) + 1,
1783
- executionStartSeq: this.transcriptFacts(id).lastSeq,
1779
+ executionStartSeq: this.transcriptFacts.transcriptFacts(id).lastSeq,
1784
1780
  });
1785
1781
  const staged = new Map();
1786
1782
  this.exitEvents.started(id);
@@ -1918,7 +1914,7 @@ export class RunStore {
1918
1914
  completionArchiveBlocker(root) {
1919
1915
  const family = [root, ...this.listWorkersOf(root.id)];
1920
1916
  for (const run of family) {
1921
- const facts = this.factsFor(run.id).peek(run.id);
1917
+ const facts = this.transcriptFacts.factsFor(run.id).peek(run.id);
1922
1918
  if (!facts || !['done', 'review', 'failed', 'cancelled'].includes(run.status) || run.waits?.some(wait => wait.phase === 'open') ||
1923
1919
  run.hasPendingPermission || facts.pendingAsk !== undefined)
1924
1920
  return 'Task or worker work still needs attention. Open the task or archive manually.';
@@ -2125,7 +2121,7 @@ export class RunStore {
2125
2121
  decodeRunRow,
2126
2122
  decodeCold: (row) => this.decodeCold(row),
2127
2123
  writeRefusal: (memberId) => this.writeRefusal(memberId),
2128
- factsPeek: (memberId) => this.factsFor(memberId).peek(memberId),
2124
+ factsPeek: (memberId) => this.transcriptFacts.factsFor(memberId).peek(memberId),
2129
2125
  readWorkerExecution: (memberId) => this.readWorkerExecution(memberId),
2130
2126
  }, id, isActive);
2131
2127
  }
@@ -2154,7 +2150,7 @@ export class RunStore {
2154
2150
  if (ids.length > 1025)
2155
2151
  return;
2156
2152
  for (const memberId of ids)
2157
- await this.factsFor(memberId).ready(memberId);
2153
+ await this.transcriptFacts.factsFor(memberId).ready(memberId);
2158
2154
  }
2159
2155
  archiveOnMergeSnapshot(id, repoBase, isActive = () => false) {
2160
2156
  const family = this.archiveFamily(id, isActive);
@@ -2434,7 +2430,7 @@ export class RunStore {
2434
2430
  restoreHistory(this.dataDir, runId);
2435
2431
  const line = `${JSON.stringify(full)}\n`;
2436
2432
  appendFileSync(this.eventsPath(runId), line, 'utf8');
2437
- this.facts.append(runId, full, Buffer.byteLength(line));
2433
+ this.transcriptFacts.index.append(runId, full, Buffer.byteLength(line));
2438
2434
  this.maybeEnqueueHistoryCompress(run);
2439
2435
  this.liveItems.observe(runId, full, false);
2440
2436
  this.published.publish('run.event', { runId, event: full });
@@ -2554,20 +2550,9 @@ export class RunStore {
2554
2550
  this.secretValues = collectSecretValues();
2555
2551
  return this.secretValues;
2556
2552
  }
2557
- /** The run's indexed transcript facts (#880): a read-only view, never a transcript read once
2558
- * the run's index is loaded. An unreadable transcript answers as empty, as readEvents does. */
2559
- transcriptFacts(runId) {
2560
- return this.factsFor(runId).get(runId) ?? emptyFacts();
2561
- }
2562
- /** The run's transcript facts when they are known: undefined when the transcript exists but its
2563
- * facts are not current or cannot be read, so a caller can tell "no ask" from "no evidence". */
2564
- knownTranscriptFacts(runId) {
2565
- return this.factsFor(runId).peek(runId);
2566
- }
2567
2553
  hasProjection(runId, projectionId) {
2568
- return this.transcriptFacts(runId).projectionIds.includes(projectionId);
2554
+ return this.transcriptFacts.transcriptFacts(runId).projectionIds.includes(projectionId);
2569
2555
  }
2570
- factsWarming = Promise.resolve();
2571
2556
  /** Indexed family enumeration, including members not yet flushed to SQLite. */
2572
2557
  listFamilyRunIds(rootId) {
2573
2558
  const ids = new Set([rootId, ...(this.db?.listIdsByParent(rootId) ?? [])]);
@@ -2581,73 +2566,6 @@ export class RunStore {
2581
2566
  ids.delete(id);
2582
2567
  return [...ids];
2583
2568
  }
2584
- recoveryFactIds(familyRootId) {
2585
- if (familyRootId !== undefined)
2586
- return this.listFamilyRunIds(familyRootId);
2587
- const ids = new Set();
2588
- for (const [id, run] of this.held) {
2589
- if (!isLiveRecord(run))
2590
- continue;
2591
- const root = familyRootOf(run);
2592
- for (const member of root === undefined ? [id] : this.listFamilyRunIds(root))
2593
- ids.add(member);
2594
- }
2595
- return [...ids];
2596
- }
2597
- /** Readiness owns no run snapshot across an await: refresh only the currently held owner. */
2598
- async prepareTranscriptFacts(runIds) {
2599
- for (const id of new Set(runIds)) {
2600
- // Exact sidecars resolve immediately too: recovery must yield to timers/I/O between IDs.
2601
- await new Promise(resolve => setImmediate(resolve));
2602
- await this.factsFor(id).ready(id);
2603
- }
2604
- }
2605
- prepareRecoveryFacts(familyRootId) {
2606
- return this.prepareTranscriptFacts(this.recoveryFactIds(familyRootId));
2607
- }
2608
- /** Register IDs only here; the index yields between cache reads and off-loop rebuilds. */
2609
- warmTranscriptFacts() {
2610
- this.factsWarming = Promise.resolve().then(async () => {
2611
- if (!this.db)
2612
- return;
2613
- const ids = new Set(this.recoveryFactIds());
2614
- // hearsay-tools/cezarion#949: this microtask ends open()'s synchronous slice, and on a
2615
- // large history the JSON scan for conversation roots plus one family query per root cost
2616
- // as much again. Past one slice's worth of runs, yield before the scan and between root
2617
- // batches; a small store (every unit test) still registers in this one microtask.
2618
- const large = this.listRunIds().length > WARM_IDS_PER_SLICE;
2619
- const turn = async () => {
2620
- await new Promise(resolve => setImmediate(resolve));
2621
- return this.db !== null;
2622
- };
2623
- if (large && !await turn())
2624
- return;
2625
- const roots = this.listConversationRootIds();
2626
- for (let i = 0; i < roots.length; i++) {
2627
- if (large && i > 0 && i % WARM_IDS_PER_SLICE === 0 && !await turn())
2628
- return;
2629
- for (const id of this.listFamilyRunIds(roots[i]))
2630
- ids.add(id);
2631
- }
2632
- if (large && !await turn())
2633
- return;
2634
- // Re-list after the yields: a run deleted meanwhile must not be registered again.
2635
- const present = this.listRunIds();
2636
- if (large) {
2637
- const live = new Set(present);
2638
- for (const id of ids)
2639
- if (!live.has(id))
2640
- ids.delete(id);
2641
- }
2642
- for (const id of present)
2643
- ids.add(id);
2644
- await this.facts.warm(ids);
2645
- }).catch(() => undefined);
2646
- }
2647
- /** Resolves when the open-time warm-up is done (tests). */
2648
- factsWarmIdle() {
2649
- return this.factsWarming;
2650
- }
2651
2569
  /** `readEvents` off the event loop (async read and async brotli), for collection paths. */
2652
2570
  async readEventsAsync(runId) {
2653
2571
  try {
@@ -3006,7 +2924,7 @@ export class RunStore {
3006
2924
  }
3007
2925
  /** The run's history, handoff and images, then the removal cleanups (`runs/removal-slots.ts`). */
3008
2926
  removeHistoryFiles(id) {
3009
- this.facts.forget(id);
2927
+ this.transcriptFacts.index.forget(id);
3010
2928
  removeHistory(this.dataDir, id);
3011
2929
  rmSync(this.handoffPath(id), { force: true });
3012
2930
  rmSync(this.imagesDir(id), { recursive: true, force: true });
@@ -3055,7 +2973,7 @@ export class RunStore {
3055
2973
  * resumed event, even across a reload (the frozen-transcript symptom class
3056
2974
  * of #424). One file read on the first post-restart append per run. */
3057
2975
  rehydrateSeq(runId) {
3058
- return this.transcriptFacts(runId).lastSeq;
2976
+ return this.transcriptFacts.transcriptFacts(runId).lastSeq;
3059
2977
  }
3060
2978
  eventsPath(runId) {
3061
2979
  return historyPaths(this.sourceDataDir(runId), runId).plain;
@@ -3382,9 +3300,7 @@ export class RunStore {
3382
3300
  // Demand-bound feeds stop before storage disappears during project removal/shutdown.
3383
3301
  this.published.publish('store.closed', {});
3384
3302
  this.compressor.stop();
3385
- this.fallbackFacts?.stop();
3386
- this.facts.stop();
3387
- this.facts.flush();
3303
+ this.transcriptFacts.stop();
3388
3304
  if (this.saveTimer) {
3389
3305
  clearTimeout(this.saveTimer);
3390
3306
  this.saveTimer = null;