instar 1.3.805 → 1.3.807

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 (33) hide show
  1. package/dist/commands/server.d.ts.map +1 -1
  2. package/dist/commands/server.js +21 -0
  3. package/dist/commands/server.js.map +1 -1
  4. package/dist/config/ConfigDefaults.d.ts.map +1 -1
  5. package/dist/config/ConfigDefaults.js +6 -1
  6. package/dist/config/ConfigDefaults.js.map +1 -1
  7. package/dist/core/CoherenceJournal.d.ts +14 -0
  8. package/dist/core/CoherenceJournal.d.ts.map +1 -1
  9. package/dist/core/CoherenceJournal.js +33 -0
  10. package/dist/core/CoherenceJournal.js.map +1 -1
  11. package/dist/core/JournalSyncApplier.d.ts +14 -0
  12. package/dist/core/JournalSyncApplier.d.ts.map +1 -1
  13. package/dist/core/JournalSyncApplier.js +33 -0
  14. package/dist/core/JournalSyncApplier.js.map +1 -1
  15. package/dist/core/ReplicatedJournalCompactor.d.ts +36 -0
  16. package/dist/core/ReplicatedJournalCompactor.d.ts.map +1 -0
  17. package/dist/core/ReplicatedJournalCompactor.js +234 -0
  18. package/dist/core/ReplicatedJournalCompactor.js.map +1 -0
  19. package/dist/core/ReplicatedPeerStreamReader.d.ts +29 -1
  20. package/dist/core/ReplicatedPeerStreamReader.d.ts.map +1 -1
  21. package/dist/core/ReplicatedPeerStreamReader.js +175 -0
  22. package/dist/core/ReplicatedPeerStreamReader.js.map +1 -1
  23. package/dist/core/types.d.ts +6 -0
  24. package/dist/core/types.d.ts.map +1 -1
  25. package/dist/core/types.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/data/builtin-manifest.json +2 -2
  28. package/upgrades/1.3.806.md +30 -0
  29. package/upgrades/1.3.807.md +27 -0
  30. package/upgrades/eli16/replicated-journal-compaction.md +19 -0
  31. package/upgrades/eli16/replicated-witness-index.md +19 -0
  32. package/upgrades/side-effects/replicated-journal-compaction.md +38 -0
  33. package/upgrades/side-effects/replicated-witness-index.md +83 -0
@@ -0,0 +1,38 @@
1
+ # Side-Effects Review — Replicated journal compaction
2
+
3
+ ## Summary
4
+
5
+ Adds a store-agnostic, one-shot compactor for registered replicated-record JSONL streams. It streams the source, keeps the HLC-max row per `(origin, recordKey)`, preserves invalid rows, writes a temporary stream, syncs it, rebuilds the compacted witness map, and atomically renames only after parity.
6
+
7
+ ## Decision points
8
+
9
+ - The path is explicit opt-in and dry-run-first; it never runs merely because replication is enabled.
10
+ - Rename is the only commit point. Temp write, fdatasync, compacted-byte witness rebuild, and parity all precede it.
11
+ - Parity is checked twice: once for the planned winners and again after parsing the persisted temporary stream.
12
+ - A parity mismatch throws, deletes only the temporary file, and keeps the source.
13
+ - Memory scales with live keys, not historical journal rows; the full source is never materialized.
14
+
15
+ ## Interactions and risks
16
+
17
+ - The compactor runs during server wiring before replicated emitters and pull loops attach, avoiding concurrent record appends during replacement.
18
+ - Sequence numbers on retained rows are preserved. Readers already tolerate sparse history and fold by HLC.
19
+ - Invalid/torn parseable rows are not candidates for supersession and are carried through.
20
+ - After a real rename, the shared reader rebuilds its derived index from committed files.
21
+ - PII record kinds use the same registry/schema validation and gain no new fields or egress.
22
+ - Missing journal or peers directories mean no streams exist yet and are handled as an explicit no-op.
23
+ - ConfigDefaults gains no new `enabled` gate; the hand-authored dark-gate attribution map is advanced by the five inserted lines and retains the same path set.
24
+
25
+ ## Rollback
26
+
27
+ Turning the run flag off disables the path. Reverting code requires no schema migration. Already-compacted streams remain valid journals containing the same live witnesses; dead intermediate versions are intentionally unrecoverable after a successful parity-checked commit.
28
+
29
+ ## Evidence
30
+
31
+ - Unit: superseded rows collapse and latest witness survives.
32
+ - Integration: default dry-run reports `3 -> 1` without writing; real run shrinks bytes and preserves reader witness.
33
+ - E2E/crash: injected interruption after temp fsync and before rename leaves the original byte-for-byte intact and cleans the temp.
34
+ - Full lint, TypeScript, build, and the existing witness-index integration test pass.
35
+
36
+ ## Class closure
37
+
38
+ The disk-bloat class is closed structurally: future controlled compaction uses coded streaming, a derived-witness correctness oracle, and an atomic commit point rather than manual journal editing or in-place mutation.
@@ -0,0 +1,83 @@
1
+ # Side-Effects Review — Replicated witness index
2
+
3
+ **Version / slug:** `replicated-witness-index`
4
+ **Date:** `2026-07-10`
5
+ **Author:** `instar-codey`
6
+ **Second-pass reviewer:** `not required`
7
+
8
+ ## Summary of the change
9
+
10
+ This change makes the replicated-store `loadWitness(store, recordKey)` path use a derived in-memory index instead of rematerializing journal streams on every emit. The index is built by `ReplicatedPeerStreamReader` from the authoritative own and peer journal streams, then incrementally updated from two post-durability observers: `CoherenceJournal` notifies after a replicated local batch is written and `fdatasync` has returned, and `JournalSyncApplier` notifies after a peer replica batch is written and `fdatasync` has returned.
11
+
12
+ The journal and replica files remain the only authority. The index is process memory only, can be rebuilt at any time, and is parity-checked against the legacy full-scan witness answer before it is trusted. If parity fails, `loadWitness` falls back to the legacy scan and logs a loud witness-index warning.
13
+
14
+ ## Decision-point inventory
15
+
16
+ - `ReplicatedPeerStreamReader.rebuildWitnessIndex` — add — streams registered replicated journal files to build the derived `(store, recordKey) -> max HLC` map.
17
+ - `ReplicatedPeerStreamReader.loadWitness` — modify — serves the derived map when parity is trusted; falls back to the old scan if parity is not trusted.
18
+ - `ReplicatedPeerStreamReader.observeCommittedEntries` — add — folds durable local/peer append notifications into the derived map.
19
+ - `CoherenceJournal.setReplicatedRecordCommitObserver` / notification — add — notifies only after local replicated records have crossed the flush/fdatasync boundary.
20
+ - `JournalSyncApplier.setReplicatedRecordCommitObserver` / notification — add — notifies only after peer replica records have crossed the append/fdatasync boundary.
21
+ - `server.ts` WS2 wiring — modify — attaches the two observers to the one `ReplicatedPeerStreamReader`.
22
+
23
+ ## 1. Over-block
24
+
25
+ No user operation is newly blocked. The witness index is a read optimization for the replicated-store send path. If the index is wrong, the parity guard disables trust in it and serves the old scan result. If an observer callback throws, journal/apply durability is preserved and the index remains rebuildable from disk.
26
+
27
+ ## 2. Under-block
28
+
29
+ The main under-detection risk is a stale derived index missing a witness. That would make a later emit omit `observed`, which is the safe merge direction: peers flag possible concurrency instead of silently clobbering. Production wiring reduces that risk by updating the index after every local and peer durable append. Restart/loss rebuilds from the journal streams.
30
+
31
+ ## 3. Level-of-abstraction fit
32
+
33
+ Correct layer. `ReplicatedPeerStreamReader` already owns the witness seam and knows the registry, own streams, peer streams, schema validation, and HLC ordering. The journal and applier only expose post-fsync observations; they do not own witness semantics and do not persist an index. This keeps the optimization store-agnostic and avoids per-store caches.
34
+
35
+ Claim-check note: `src/commands/server.ts` has several unrelated open PR claims in dashboard/update/messaging layers. This change touches only the WS2 replicated-store wiring block to attach observer callbacks. No sibling appears to own the witness-index layer.
36
+
37
+ ## 4. Signal vs authority compliance
38
+
39
+ - [x] No new gate or authority surface.
40
+
41
+ The new callbacks are informational derived-index updates. They cannot approve, block, mutate user-visible state, or make the journal authoritative in a new way. The existing journal/applier durability contracts remain the authority.
42
+
43
+ ## 5. Interactions
44
+
45
+ - **Local journal flush:** the observer fires after the replicated batch is written and synced, so queued in-memory emits are never witnessed as durable.
46
+ - **Peer replica apply:** the observer fires after durable replica append, matching the applier's ack-after-fsync contract.
47
+ - **Parity mode:** rebuild compares the index answer with the legacy full-scan witness answer. A mismatch logs once and falls back to the scan.
48
+ - **Crash/restart:** there is no persisted index to corrupt. A new reader rebuilds from own and peer streams.
49
+ - **Existing union reads:** `loadOriginRecords`, `listRecordKeys`, and `loadOwnEntries` keep their existing behavior. This PR narrows the optimization to the hot witness lookup.
50
+
51
+ ## 6. External surfaces
52
+
53
+ No new API route, config key, dashboard control, CLI, or persistent schema. Runtime logs may include a new `[ws2-witness-index]` parity mismatch line if the derived index ever disagrees with the legacy scan.
54
+
55
+ ## 6b. Operator-surface quality
56
+
57
+ No operator surface. The only operator-visible change should be reduced synchronous work during replicated-store emission.
58
+
59
+ ## 7. Multi-machine posture
60
+
61
+ This is explicitly multi-machine shared infrastructure and affects every replicated store, including PII replicated stores. The index is store-agnostic and uses the same `ReplicatedKindRegistry` and `validateReplicatedEnvelope` path as the existing reader. It does not replicate additional fields, does not write a new file, and does not expose more data to peers. It only changes how the local machine finds the max HLC it has already durably observed.
62
+
63
+ ## 8. Rollback cost
64
+
65
+ Low to moderate. Reverting restores the legacy scan path and removes the observer callbacks. Because the index is not persisted, rollback has no data migration and cannot strand state. The cost is performance regression back to synchronous scan-per-witness on large journals.
66
+
67
+ ## Conclusion
68
+
69
+ The change closes the performance residual without changing merge semantics: same witness answer, derived in memory, built from streamed journal reads, updated only after durable appends, and backed by parity fallback. The blast radius is shared infra, so coverage includes unit, integration, and e2e lifecycle tests.
70
+
71
+ ## Second-pass review (if required)
72
+
73
+ **Reviewer:** not required
74
+ **Independent read of the artifact:** not required for this Tier-1 performance optimization with no new authority, no schema migration, and parity fallback.
75
+
76
+ ## Evidence pointers
77
+
78
+ - `npx tsc --noEmit`
79
+ - `npx vitest run tests/unit/ReplicatedPeerStreamReader.test.ts tests/unit/ReplicatedRecordEmitter.test.ts tests/unit/evolution-manager-emit-wedge.test.ts tests/integration/replicated-witness-index.integration.test.ts tests/e2e/replicated-witness-index-lifecycle.test.ts`
80
+
81
+ ## Class-Closure Declaration
82
+
83
+ No agent-authored-artifact defect. The recurring class was synchronous scan-per-emit after the #1414 emit-count fix. The closure is structural: witness lookup reads an O(1) derived map in the hot path, local/peer append sites update the map after fsync, and rebuild/parity keeps the journal authoritative.