counterparts 0.1.0
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/CONSTITUTION.md +68 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/docs/ELI5.md +84 -0
- package/docs/QUICKSTART.md +1258 -0
- package/docs/module-map.md +81 -0
- package/package.json +63 -0
- package/src/adapters/claude-code/CONTRACT.md +606 -0
- package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
- package/src/adapters/claude-code/NOTES.md +1055 -0
- package/src/adapters/claude-code/bin/hook.ts +820 -0
- package/src/adapters/claude-code/bin/runner.ts +522 -0
- package/src/adapters/claude-code/config.ts +778 -0
- package/src/adapters/claude-code/credentials.ts +199 -0
- package/src/adapters/claude-code/doctor.ts +2557 -0
- package/src/adapters/claude-code/embed-client.ts +617 -0
- package/src/adapters/claude-code/hooks.ts +2240 -0
- package/src/adapters/claude-code/index.ts +224 -0
- package/src/adapters/claude-code/interpret-client.ts +395 -0
- package/src/adapters/claude-code/page-writer.ts +462 -0
- package/src/adapters/claude-code/primacy.ts +162 -0
- package/src/adapters/claude-code/spawn.ts +241 -0
- package/src/adapters/claude-code/standdown.ts +536 -0
- package/src/adapters/claude-code/transcript.ts +661 -0
- package/src/adapters/claude-code/vectors.ts +415 -0
- package/src/adapters/cli/CONTRACT.md +255 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
- package/src/adapters/cli/NOTES.md +936 -0
- package/src/adapters/cli/bin/counterparts.ts +74 -0
- package/src/adapters/cli/commands.ts +6095 -0
- package/src/adapters/cli/export.ts +766 -0
- package/src/adapters/cli/index.ts +103 -0
- package/src/adapters/cli/install.ts +670 -0
- package/src/adapters/cli/removal.ts +1186 -0
- package/src/adapters/cli/repair-dates.ts +659 -0
- package/src/adapters/cli/self-page.ts +229 -0
- package/src/adapters/cli/snapshot.ts +279 -0
- package/src/adapters/cli/start-fresh.ts +1228 -0
- package/src/adapters/config-path.ts +342 -0
- package/src/adapters/dashboard/CONTRACT.md +67 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
- package/src/adapters/dashboard/NOTES.md +474 -0
- package/src/adapters/dashboard/activity.ts +121 -0
- package/src/adapters/dashboard/ansi.ts +82 -0
- package/src/adapters/dashboard/bin/dashboard.ts +479 -0
- package/src/adapters/dashboard/browse.ts +298 -0
- package/src/adapters/dashboard/identity.ts +182 -0
- package/src/adapters/dashboard/index.ts +183 -0
- package/src/adapters/dashboard/layout.ts +149 -0
- package/src/adapters/dashboard/registries.ts +291 -0
- package/src/adapters/dashboard/resolve.ts +206 -0
- package/src/adapters/dashboard/source.ts +48 -0
- package/src/adapters/dashboard/status.ts +327 -0
- package/src/adapters/dashboard/stories.ts +194 -0
- package/src/adapters/dashboard/web/app.html +1731 -0
- package/src/adapters/dashboard/web/brain.html +463 -0
- package/src/adapters/dashboard/web/fired.ts +31 -0
- package/src/adapters/dashboard/web/flow.ts +457 -0
- package/src/adapters/dashboard/web/narrate.ts +1042 -0
- package/src/adapters/dashboard/web/reveal.ts +135 -0
- package/src/adapters/dashboard/web/server.ts +287 -0
- package/src/adapters/dashboard/web/views.ts +1744 -0
- package/src/adapters/expansions.ts +569 -0
- package/src/adapters/fired.ts +1580 -0
- package/src/adapters/mcp/CONTRACT.md +240 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
- package/src/adapters/mcp/NOTES.md +205 -0
- package/src/adapters/mcp/bin/serve.ts +349 -0
- package/src/adapters/mcp/deliberate.ts +619 -0
- package/src/adapters/mcp/index.ts +101 -0
- package/src/adapters/mcp/protocol.ts +170 -0
- package/src/adapters/mcp/server.ts +1740 -0
- package/src/adapters/mcp/stdio.ts +56 -0
- package/src/adapters/mcp/tools.ts +779 -0
- package/src/adapters/scopes.ts +657 -0
- package/src/adapters/sessions.ts +402 -0
- package/src/adapters/snapshots.ts +1069 -0
- package/src/adapters/stance-env.ts +137 -0
- package/src/core/associate/CONTRACT.md +118 -0
- package/src/core/associate/INTERFACE-GAPS.md +173 -0
- package/src/core/associate/NOTES.md +194 -0
- package/src/core/associate/buffer.ts +66 -0
- package/src/core/associate/edges.ts +188 -0
- package/src/core/associate/index.ts +570 -0
- package/src/core/associate/pending.ts +383 -0
- package/src/core/associate/spread.ts +149 -0
- package/src/core/associate/tunables.ts +123 -0
- package/src/core/bridge.ts +272 -0
- package/src/core/briefing.ts +67 -0
- package/src/core/counterpart.ts +3855 -0
- package/src/core/encode/CONTRACT.md +151 -0
- package/src/core/encode/INTERFACE-GAPS.md +135 -0
- package/src/core/encode/NOTES.md +146 -0
- package/src/core/encode/aliases.ts +71 -0
- package/src/core/encode/battery.ts +284 -0
- package/src/core/encode/chunk.ts +265 -0
- package/src/core/encode/emotion.ts +119 -0
- package/src/core/encode/floor.ts +76 -0
- package/src/core/encode/index.ts +100 -0
- package/src/core/encode/precision.ts +162 -0
- package/src/core/encode/preselect.ts +269 -0
- package/src/core/encode/salience.ts +108 -0
- package/src/core/encode/secrets.ts +265 -0
- package/src/core/encode/tunables.ts +99 -0
- package/src/core/encode/types.ts +286 -0
- package/src/core/encode/words.ts +75 -0
- package/src/core/handoff/CONTRACT.md +199 -0
- package/src/core/handoff/INTERFACE-GAPS.md +166 -0
- package/src/core/handoff/NOTES.md +206 -0
- package/src/core/handoff/index.ts +957 -0
- package/src/core/mint.ts +279 -0
- package/src/core/observer.ts +28 -0
- package/src/core/physics/CONTRACT.md +341 -0
- package/src/core/physics/NOTES.md +155 -0
- package/src/core/physics/clock.ts +51 -0
- package/src/core/physics/index.ts +1054 -0
- package/src/core/prospective/CONTRACT.md +137 -0
- package/src/core/prospective/INTERFACE-GAPS.md +112 -0
- package/src/core/prospective/NOTES.md +160 -0
- package/src/core/prospective/derive.ts +188 -0
- package/src/core/prospective/index.ts +1030 -0
- package/src/core/prospective/tunables.ts +72 -0
- package/src/core/prospective/windows.ts +187 -0
- package/src/core/recall/CONTRACT.md +326 -0
- package/src/core/recall/INTERFACE-GAPS.md +163 -0
- package/src/core/recall/NOTES.md +472 -0
- package/src/core/recall/activate.ts +521 -0
- package/src/core/recall/cues.ts +275 -0
- package/src/core/recall/gate.ts +441 -0
- package/src/core/recall/index.ts +692 -0
- package/src/core/recall/probe.ts +239 -0
- package/src/core/recall/reference.ts +201 -0
- package/src/core/recall/render.ts +285 -0
- package/src/core/recall/session.ts +403 -0
- package/src/core/recall/tunables.ts +329 -0
- package/src/core/remember/CONTRACT.md +293 -0
- package/src/core/remember/INTERFACE-GAPS.md +189 -0
- package/src/core/remember/NOTES.md +373 -0
- package/src/core/remember/fallback.ts +452 -0
- package/src/core/remember/index.ts +103 -0
- package/src/core/remember/owner-strike-seam.ts +479 -0
- package/src/core/remember/proposals.ts +609 -0
- package/src/core/remember/spans.ts +1310 -0
- package/src/core/remember/tunables.ts +111 -0
- package/src/core/remember/updates.ts +198 -0
- package/src/core/retrieval.ts +96 -0
- package/src/core/revision.ts +441 -0
- package/src/core/schemas/CONTRACT.md +190 -0
- package/src/core/schemas/INTERFACE-GAPS.md +172 -0
- package/src/core/schemas/NOTES.md +260 -0
- package/src/core/schemas/aliases.ts +160 -0
- package/src/core/schemas/index.ts +1459 -0
- package/src/core/schemas/tunables.ts +44 -0
- package/src/core/schemas/types.ts +387 -0
- package/src/core/self/CONTRACT.md +459 -0
- package/src/core/self/INTERFACE-GAPS.md +284 -0
- package/src/core/self/NOTES.md +1057 -0
- package/src/core/self/briefing.ts +980 -0
- package/src/core/self/episodes.ts +483 -0
- package/src/core/self/freeze.ts +103 -0
- package/src/core/self/identity.ts +604 -0
- package/src/core/self/index.ts +2130 -0
- package/src/core/self/journal-file.ts +760 -0
- package/src/core/self/page.ts +404 -0
- package/src/core/self/tunables.ts +244 -0
- package/src/core/self/writer.ts +714 -0
- package/src/core/sleep/CONTRACT.md +298 -0
- package/src/core/sleep/INTERFACE-GAPS.md +262 -0
- package/src/core/sleep/NOTES.md +770 -0
- package/src/core/sleep/briefing.ts +86 -0
- package/src/core/sleep/consolidate.ts +241 -0
- package/src/core/sleep/cycle.ts +598 -0
- package/src/core/sleep/decay.ts +237 -0
- package/src/core/sleep/dedup.ts +373 -0
- package/src/core/sleep/index.ts +112 -0
- package/src/core/sleep/log.ts +116 -0
- package/src/core/sleep/markers.ts +164 -0
- package/src/core/sleep/prune.ts +170 -0
- package/src/core/sleep/strength-cache.ts +176 -0
- package/src/core/sleep/tunables.ts +135 -0
- package/src/core/sleep/types.ts +542 -0
- package/src/core/store/CONTRACT.md +446 -0
- package/src/core/store/NOTES.md +1068 -0
- package/src/core/store/cache.ts +709 -0
- package/src/core/store/db.ts +275 -0
- package/src/core/store/errors.ts +134 -0
- package/src/core/store/index.ts +2450 -0
- package/src/core/store/operational.ts +610 -0
- package/src/core/store/owner-op-seam.ts +428 -0
- package/src/core/store/paths.ts +494 -0
- package/src/core/store/prose.ts +165 -0
- package/src/core/store/render.ts +87 -0
- package/src/core/store/walk-seam.ts +78 -0
- package/src/core/types.ts +68 -0
- package/tools/install-loop/run.sh +1063 -0
|
@@ -0,0 +1,1068 @@
|
|
|
1
|
+
# `store/` — implementation notes
|
|
2
|
+
|
|
3
|
+
*What the CONTRACT left open, and the simplest reading this implementation took.
|
|
4
|
+
The CONTRACT is the spec and is never edited from here; this file records choices,
|
|
5
|
+
their reason, and what would change them. Everything below is a working default
|
|
6
|
+
(CLAUDE.md), not law.*
|
|
7
|
+
|
|
8
|
+
*Rewritten in part on 2026-09-20 (F8), when the floor moved the memories into rows.
|
|
9
|
+
Sections **1** (the markdown format — it is `render.ts`'s documentation now, because
|
|
10
|
+
markdown is an export) and **5** (the stage → commit → rename crash window — there is no
|
|
11
|
+
stage) are GONE, and their numbers are left as gaps rather than closed up, so the one
|
|
12
|
+
citation that reaches into this file by number (`db.ts` → §9) keeps pointing where it
|
|
13
|
+
meant to. Sections 3, 6 and the 2026-09-05 self-contained note are rewritten; everything
|
|
14
|
+
dated stays as it was written, because a log corrected after the fact stops being one.*
|
|
15
|
+
|
|
16
|
+
## 2. Every field on the shared seam gets a column
|
|
17
|
+
|
|
18
|
+
`MemoryPhysics` and `Salience` (`src/core/types.ts`) are stored field-for-field,
|
|
19
|
+
including the two optional ones added while this module was being built:
|
|
20
|
+
`salience.claimed` (the author's claimed FLOOR → `claimed REAL`, null when absent,
|
|
21
|
+
never defaulted to a number) and `reinforcedDays` (distinct lived days that credited
|
|
22
|
+
a use → `reinforced_days INTEGER NOT NULL DEFAULT 0`). Both fail safe when dropped,
|
|
23
|
+
which is exactly why they are asserted in the round-trip test rather than trusted.
|
|
24
|
+
|
|
25
|
+
`uses` is `REAL`, not `INTEGER`: physics §5.5 credits weighted uses, and an integer
|
|
26
|
+
column would silently truncate a 0.5. `reinforce(id, day, weight)` persists one
|
|
27
|
+
credit and bumps `reinforced_days` only when the day differs from `last_used_day` —
|
|
28
|
+
the one derived thing the store computes, because a weighted sum cannot reconstruct
|
|
29
|
+
a distinct-day count and identity promotion is gated on it. `updatePhysics()` sets
|
|
30
|
+
absolute values and remains authoritative over both.
|
|
31
|
+
|
|
32
|
+
## 3. Bounded versioning: the prune deletes ROWS, and since the floor those rows hold words
|
|
33
|
+
|
|
34
|
+
*Rewritten at the floor (F8). It used to say the archived prose FILE a pruned row
|
|
35
|
+
pointed at was left on disk — this module exports no way to delete a file — so
|
|
36
|
+
retention here meant "the store stops tracking the version" rather than "the bytes
|
|
37
|
+
are gone", and reclaiming them was an owner operation. There is no file. The
|
|
38
|
+
version's words ARE its row, and the prune deletes them.*
|
|
39
|
+
|
|
40
|
+
`pruneSupersededVersions()` deletes `versions` rows older than H lived days and
|
|
41
|
+
reports the count (scar §2.4: every discard says what and how much). The owner
|
|
42
|
+
took that ruling knowing what the floor had done to its cost — on by default at 90
|
|
43
|
+
lived days, ruling 1 of 2026-09-18, his steer being simple working-memory mechanics
|
|
44
|
+
over keeping everything, and losing some data after a month or two an acceptable
|
|
45
|
+
price. It is a real cost and it is made visible by a test rather than left as a
|
|
46
|
+
sentence.
|
|
47
|
+
|
|
48
|
+
Two resolvabilities, deliberately distinct and separately tested:
|
|
49
|
+
|
|
50
|
+
- `resolve(oldId)` follows `superseded_by` **forever** — a dangling reference is a
|
|
51
|
+
hard error, so this can never expire (§5 G4).
|
|
52
|
+
- `versions(id)` / `readVersion(id, seq)` is the retained-history surface, and that
|
|
53
|
+
is what H bounds.
|
|
54
|
+
|
|
55
|
+
H defaults to **90 lived days** and is a constructor option (module-map ruling 2:
|
|
56
|
+
tunable, not an owner ruling).
|
|
57
|
+
|
|
58
|
+
## 4. `putMany` is atomic by default; per-item isolation is opt-in
|
|
59
|
+
|
|
60
|
+
§16 G6 wants per-item persistence isolation; the transactional box wants
|
|
61
|
+
all-or-nothing. Both are real, and they are different promises, so the caller picks
|
|
62
|
+
out loud: `putMany(inputs)` rolls the batch back on the first failure,
|
|
63
|
+
`putMany(inputs, { isolate: true })` skips the failure, logs `store.put.skipped`
|
|
64
|
+
with the reason code, and persists the rest.
|
|
65
|
+
|
|
66
|
+
## 6. Telemetry: an in-memory ring, and one durable table an adapter prunes
|
|
67
|
+
|
|
68
|
+
*Corrected (F8). This section used to say events go to the ring and an optional
|
|
69
|
+
`onEvent` sink and nowhere else — "a durable log sink belongs to an adapter". Half of
|
|
70
|
+
that held and half did not: the sink was built, and it is a table in box 2.*
|
|
71
|
+
|
|
72
|
+
Two channels, and the observer argument is what keeps them apart:
|
|
73
|
+
|
|
74
|
+
- **The ring** — capped, in-process, plus an optional `onEvent` sink. Every `emit`
|
|
75
|
+
goes here, an instrument's included. Nothing durable, nothing on disk.
|
|
76
|
+
- **`events`, a box 2 table** — written only by `appendEvent`, which is in
|
|
77
|
+
`WRITE_METHODS` and crosses the stance check like every other write. So an
|
|
78
|
+
instrument standing down writes no row, and observer mode's one deliberate write
|
|
79
|
+
stays its stand-down event (observer-mode.md G6) rather than becoming every event
|
|
80
|
+
it happened to watch. That was the whole reason this section said "not box 2", and
|
|
81
|
+
putting the check on the write METHOD answered it without giving up the log.
|
|
82
|
+
|
|
83
|
+
Retention belongs to the adapter that wanted it: `pruneEvents({ limit })` is called
|
|
84
|
+
by sleep's `log` phase, deletes UNLATCHED rows past `retentionDays` lived days
|
|
85
|
+
oldest-first, caps the call, and reports what went and what is left. Rows carry ids,
|
|
86
|
+
hashes, counts, kinds and codes only, never text (§5 G10).
|
|
87
|
+
|
|
88
|
+
## 7. Box 3 is an inverted table, not FTS5
|
|
89
|
+
|
|
90
|
+
FTS5 is a compile-time option and the two supported runtimes do not guarantee it
|
|
91
|
+
identically, so text search is a small tokenizer plus a `doc_tokens(memory_id,
|
|
92
|
+
token, tf)` table, and vectors are JSON in `embeddings`. Deterministic ordering
|
|
93
|
+
(score desc, id asc) is what makes "the same recall for the same cues" testable
|
|
94
|
+
after a rebuild (§5 G8). Contract open question 1 (one cache box or two) is answered
|
|
95
|
+
as **one file, two tables**: the split that matters is rebuild cost, and that is
|
|
96
|
+
expressed by the declaration below, not by a second file. Re-open if vectors ever
|
|
97
|
+
need a different backup posture than the text index.
|
|
98
|
+
|
|
99
|
+
Rebuild declares what it cannot recompute: without an `embed` function the
|
|
100
|
+
embeddings are not restored, and the report names `what` / `owner` / `repair` and
|
|
101
|
+
logs the count at every rebuild.
|
|
102
|
+
|
|
103
|
+
## 8. Observer mode
|
|
104
|
+
|
|
105
|
+
`observer.ts` holds the single predicate and imports nothing (observer-mode.md G2).
|
|
106
|
+
It sits in `store/` because the seam is its only consumer today; when a second core
|
|
107
|
+
module needs it, **move the file to `src/core/observer.ts`** — it has no imports, so
|
|
108
|
+
hoisting is a move, not a rewrite.
|
|
109
|
+
|
|
110
|
+
The check happens in `mutate()`, which every write method enters before it touches
|
|
111
|
+
anything, and every stand-down emits `store.observer.standdown` naming the site.
|
|
112
|
+
`WRITE_METHODS` is the enumerated list, and the totality test asserts it equals the
|
|
113
|
+
set of sites found in the source — adding a write method without listing it fails
|
|
114
|
+
the suite. *(It used to say "before any staging, so an observer cannot leave a temp
|
|
115
|
+
file behind". There is no staging and no `tmp/` since the floor; the position of the
|
|
116
|
+
check is unchanged and the reason for it is now the simpler one — nothing may reach
|
|
117
|
+
a transaction.)*
|
|
118
|
+
|
|
119
|
+
Not implemented, deliberately: the byte-identical-canonical-database assertion
|
|
120
|
+
(observer-mode.md G4). SQLite may touch file bytes on open alone, so the property is
|
|
121
|
+
tested as *refusal at the seam* plus the directory hashed around the open — which
|
|
122
|
+
since 2026-09-18 means the `-wal` WITH the database and only the `-shm` skipped
|
|
123
|
+
(`isDatabaseSidecar`), because a commit lives in the `-wal` until a checkpoint and a
|
|
124
|
+
hash that skipped it would pass over exactly the write it exists to catch. **Owner:
|
|
125
|
+
whoever builds the probe harness**; the honest form of the test is a populated-store
|
|
126
|
+
probe run compared on logical content, not bytes.
|
|
127
|
+
|
|
128
|
+
## 9. Runtime adapter
|
|
129
|
+
|
|
130
|
+
`db.ts` selects `bun:sqlite` under Bun and `node:sqlite` otherwise, via
|
|
131
|
+
`createRequire` so a missing module is a caught, named error rather than an import
|
|
132
|
+
crash. `PRAGMA foreign_keys = ON` at every open (SQLite defaults it OFF, and §5 G4
|
|
133
|
+
puts referential integrity in the store).
|
|
134
|
+
|
|
135
|
+
Journal mode was **DELETE**, and the reason given here was that WAL leaves permanent
|
|
136
|
+
`-wal`/`-shm` sidecars while every top-level path must be classified (§5 G11). That
|
|
137
|
+
reason had already expired when it was written — `LAYOUT`'s database entry matches by
|
|
138
|
+
PREFIX, so the sidecars were classified all along — and `db.ts` cites this line for
|
|
139
|
+
the reason that no longer holds. Both boxes are **WAL since 2026-09-18** (§5 G18);
|
|
140
|
+
the dated note below carries the pragma order, the measurements, and the three things
|
|
141
|
+
a WAL store cannot do that a DELETE store could.
|
|
142
|
+
|
|
143
|
+
**The Node branch is structurally present but has not been live-verified**: this
|
|
144
|
+
machine runs Node 20 and `node:sqlite` landed in 22. Verify at packaging, together
|
|
145
|
+
with the exact version floor CLAUDE.md flags.
|
|
146
|
+
|
|
147
|
+
## 10. Deferred, with the reason
|
|
148
|
+
|
|
149
|
+
- **The one-seam totality test over every ENTRANCE** (§5 G1) enumerates the Store's
|
|
150
|
+
own write methods. It is a SOURCE scan of this module, so an entrance that reaches
|
|
151
|
+
a write method is covered by construction and an entrance that goes around one
|
|
152
|
+
would not be. The hooks and the replay harness both exist now and both go through
|
|
153
|
+
`Counterpart`; the import entrance the guarantee named was deleted with the tool
|
|
154
|
+
(F8). What would make it total is the same enumeration one level out — over every
|
|
155
|
+
caller that mints canonical text — and nothing does that today.
|
|
156
|
+
- ~~**The caller-universality test on removal** (§5 G2) needs a caller.~~ **DONE.**
|
|
157
|
+
`owner-op-seam.ts` stopped being types-only on 2026-08-25 (`chaseRemoved`,
|
|
158
|
+
`grantOwnerOps`, `REMOVED_REASON`, later `unarchiveMerged`), its export list is
|
|
159
|
+
pinned by name, and `test/cli.test.ts` asserts that no core module, no other
|
|
160
|
+
adapter and no other test imports `removal.ts`.
|
|
161
|
+
- **`erase`-style copy-chasing across box 3 and the edge graph** (§5 G7) is the CLI's
|
|
162
|
+
operation; the store provides the record, the deny-list, and the rebuild skip.
|
|
163
|
+
- **Multi-writer / lock discipline (scar E5)** is satisfied for structured state by
|
|
164
|
+
the transaction, and since 2026-09-18 concurrent PROCESSES are covered for the two
|
|
165
|
+
databases as well — WAL plus a busy timeout set first, with a test that holds a
|
|
166
|
+
write transaction on one handle and asserts the second waits (§5 G18). What is
|
|
167
|
+
still argued rather than tested is the two mutable directories that are not
|
|
168
|
+
databases: §5 G3's totality does not prove one writer each for `spans/` and
|
|
169
|
+
`sessions/` (CONTRACT §7 question 4).
|
|
170
|
+
- **Backups** (§16 G18) are not this module's job; `backupSet()` reports the
|
|
171
|
+
classification so the backup tool cannot silently omit a directory the way v1 did.
|
|
172
|
+
|
|
173
|
+
## 2026-09-04 — the default data dir is `~/.counterparts/store`, not `~/.counterparts`
|
|
174
|
+
|
|
175
|
+
The launch inventory reproduced what the parallel-run preflight had worked around: the
|
|
176
|
+
host adapter writes `claude-code.json` (and the credentials file) into `~/.counterparts`,
|
|
177
|
+
and the store classifies every top-level entry of its data dir and refuses an
|
|
178
|
+
unclassified one at open (§5 G11). So the old default, `~/.counterparts` itself, was a
|
|
179
|
+
store that could not open on any installed host. The owner ruled (2026-09-04): the base
|
|
180
|
+
dir belongs to the adapters, the store sits one level below it, and the default says so.
|
|
181
|
+
One line in `dataDir()`, one replaced assertion. The live host is unaffected: its config
|
|
182
|
+
names `dataDir` explicitly and the MCP registration sets `COUNTERPARTS_DATA_DIR`, so no
|
|
183
|
+
live code path consulted the default. `FORBIDDEN_ROOT_NAMES` is unchanged; the
|
|
184
|
+
recall-bench and parallel tools still refuse the whole base dir by name.
|
|
185
|
+
|
|
186
|
+
## 2026-09-05 — box 3's vectors are float32 BLOBs (cache v4), converted in place
|
|
187
|
+
|
|
188
|
+
**The debt.** `embeddings.vec` held `JSON.stringify(vec)`: 177.5 MB at ~13.9K vectors on
|
|
189
|
+
the live store, ~12.7 KB a row against 4 KB of float32, and a `nearest()` scan that
|
|
190
|
+
`JSON.parse`d every row measured at 590–1,040 ms (LAUNCH-STATUS §E-W1(4)). None of that
|
|
191
|
+
is the parser being slow. It is the scan reading three times the bytes and then
|
|
192
|
+
allocating a 1,024-element `number[]` per row to throw away.
|
|
193
|
+
|
|
194
|
+
**What float32 costs, said precisely.** It is not a lossy choice for an EMBEDDING: every
|
|
195
|
+
provider computes and serves single precision, so the float64 room JSON text was paying
|
|
196
|
+
for never held float64 information. It IS lossy for a value that reached the store as a
|
|
197
|
+
float64 which is not float32-exact — and the live store's vectors are exactly that, which
|
|
198
|
+
the measurement below found rather than assumed. A provider serves ~8 significant decimal
|
|
199
|
+
digits; `JSON.parse` turns those into the nearest float64, and `Math.fround(x) === x` is
|
|
200
|
+
then false for almost every coordinate. So the conversion moves each coordinate by up to
|
|
201
|
+
one float32 ulp (~6e-8 relative).
|
|
202
|
+
|
|
203
|
+
Measured, on a synthetic store built under `mkdtemp` — 14,000 random unit-norm 1,024-dim
|
|
204
|
+
vectors, three scans each, `nearest(probe, 50)`, no real store touched:
|
|
205
|
+
|
|
206
|
+
| values | file before | file after | scan before (3 runs) | scan after (3 runs) | order | max abs Δscore |
|
|
207
|
+
|---|---|---|---|---|---|---|
|
|
208
|
+
| 8-digit decimals (**the live shape**: 12.8 KiB/row) | 175.3 MiB | 61.8 MiB (2.84×) | 540, 507, 459 ms | 49, 46, 42 ms (11.1×) | identical | 1.5e-9 |
|
|
209
|
+
| float32-exact (21.4 KiB/row) | 292.0 MiB | 61.8 MiB (4.72×) | 654, 619, 637 ms | 47, 49, 42 ms (13.9×) | identical | **0 — bit-identical** |
|
|
210
|
+
|
|
211
|
+
The first row is the one the owner's store will see; the second is the property the tests
|
|
212
|
+
pin, because it is the one that can be stated exactly. `test/store.test.ts` holds both:
|
|
213
|
+
bit-identical scores (`Object.is`, not `toBeCloseTo`) for float32-exact vectors, and
|
|
214
|
+
same-order-under-1e-6 for float64 ones. The conversion itself ran 14,000 rows in 0.9–1.2 s
|
|
215
|
+
plus a 0.3 s `VACUUM`.
|
|
216
|
+
|
|
217
|
+
**Why the migration converts and does not rebuild.** A rebuild recomputes, and the thing
|
|
218
|
+
that would recompute here is an embedder — which the console does not wire, and which
|
|
219
|
+
charges per row. `verify --rebuild` as the migration would have meant deleting ~13,700
|
|
220
|
+
paid vectors and hoping. The information needed to write the new shape is already in the
|
|
221
|
+
old one, so `counterparts migrate-cache` reads each JSON row and writes the BLOB: dry run
|
|
222
|
+
by default, `--apply` to convert, one transaction per `--batch` (500), `VACUUM` at the end
|
|
223
|
+
because free pages are not free space.
|
|
224
|
+
|
|
225
|
+
**Three properties that are design, not decoration:**
|
|
226
|
+
|
|
227
|
+
- **Reads tolerate BOTH shapes** (`decodeVector`). This is what makes it a conversion
|
|
228
|
+
rather than a flag day: an interrupted `--apply` leaves a mixed cache, and a reader that
|
|
229
|
+
assumed one shape would turn an unconverted row into a crash or — worse — a silent
|
|
230
|
+
zero-similarity lie. The cost is one `typeof` per row. `verify`'s census names the mix.
|
|
231
|
+
- **The batch is idempotent by its WHERE clause** (`typeof(vec) = 'text'`), so re-running
|
|
232
|
+
finishes an interrupted run and `--apply` on a converted store REFUSES rather than
|
|
233
|
+
printing a conversion it did not do.
|
|
234
|
+
- **No table rewrite.** The declared column type is AFFINITY, not a constraint: SQLite's
|
|
235
|
+
TEXT affinity leaves a bound BLOB a BLOB, so a v3 table whose DDL says `vec TEXT` stores
|
|
236
|
+
the new shape correctly. Asserted in a test rather than assumed, because the entire
|
|
237
|
+
write path rests on it.
|
|
238
|
+
|
|
239
|
+
**Two follow-ups filed by PR #43's review, closed here.** `Store.embeddingCount()` — what
|
|
240
|
+
box 3 HOLDS, which is not `unembeddedCount()`'s coverage denominator — and
|
|
241
|
+
`rebuildCache({ keepVectors })`, which re-indexes the token side and leaves `embeddings`
|
|
242
|
+
in place, dropping only the vectors whose memory is no longer canonical (a removed id, an
|
|
243
|
+
orphan) so §16 G12 still holds. `verify --rebuild --keep-vectors` is its door; the old
|
|
244
|
+
refusals are unchanged and now name it.
|
|
245
|
+
|
|
246
|
+
**How far the rounding can reach, which is further than its size suggests.** The
|
|
247
|
+
adversarial review (2026-09-05) found the argument that matters, and it belongs here rather
|
|
248
|
+
than only in a PR body. The 1e-9 movement is continuous, but two of its consumers are
|
|
249
|
+
DISCRETE:
|
|
250
|
+
|
|
251
|
+
- `recall/activate.ts:300` applies an ABSOLUTE floor, `if (h.score < SEMANTIC_SEED_FLOOR)
|
|
252
|
+
continue` (0.45). A candidate that crosses it by 1e-9 does not gain 1e-9 of anything — it
|
|
253
|
+
gains `semantic > 0`, and `recall/gate.ts:273` builds the turn's background from
|
|
254
|
+
`candidates.filter((c) => c.cue + c.semantic > 0)`. **Membership is a whole number.** So
|
|
255
|
+
the crossing changes `n`, `mean`, `sd` and every other candidate's leave-one-out bar by
|
|
256
|
+
O(1/n), and `background()` switches regime entirely at `n < MIN_BACKGROUND_SAMPLE` (3).
|
|
257
|
+
Measured on illustrative activations at TUNABLES defaults: the regime flip moved the bar
|
|
258
|
+
by 2.6e-1, and an in-regime n=3→4 by 4.6e-3. The magnitudes depend on the activations;
|
|
259
|
+
the O(1/n) shape does not.
|
|
260
|
+
- `ranked.slice(0, SEMANTIC_TOP_M)` (`activate.ts:301`, 8) is a RANK cut, fed the same way
|
|
261
|
+
from `counterpart.ts:840` and from the worker: a 1e-9 swap at ranks 8/9 changes the seed
|
|
262
|
+
set outright.
|
|
263
|
+
|
|
264
|
+
The probability is negligible — a top-8 cosine would have to land within ~1.5e-9 of exactly
|
|
265
|
+
0.45, and the smallest adjacent score gap in a 14,000-row top-50 measured 1.7e-7, about a
|
|
266
|
+
hundred times the perturbation. The CONSEQUENCE, should it happen, is finite. That is the
|
|
267
|
+
honest shape of the claim, and it is why the G12 class is the third one: "provably
|
|
268
|
+
identical" is a claim about consequences, not about probabilities.
|
|
269
|
+
|
|
270
|
+
**What the review changed, all of it in the same direction.** A `NaN` no longer survives a
|
|
271
|
+
write (`encodeVector` coerces non-finite to 0 and `countNonFinite` reports it) — v3 coerced
|
|
272
|
+
it by accident, via `JSON.stringify(NaN) === "null"`, and writing it through would have been
|
|
273
|
+
a regression dressed as a format change, since `nearest`'s comparator reads `NaN - x` as
|
|
274
|
+
falsy and lets such a row sort anywhere. A BLOB whose byte length is not a multiple of four
|
|
275
|
+
decodes EMPTY rather than truncated, and `vectorFormats` counts it as unreadable: a
|
|
276
|
+
silently shortened vector is a cosine over a prefix, a wrong number with no signal on it. A
|
|
277
|
+
row that will not parse costs one row — `convertVectorBatch` parses outside the transaction
|
|
278
|
+
and takes an `after` cursor, because the first version rolled the batch back and then
|
|
279
|
+
re-selected the same row forever, one corrupt byte holding 13,000 vectors hostage. And
|
|
280
|
+
`keepVectors` no longer offers a held row to the embedder at all: it called it and let
|
|
281
|
+
`indexDoc` overwrite what it had just promised to preserve.
|
|
282
|
+
|
|
283
|
+
**Brain analog: none, and that is the point.** This is the engineering floor biology does
|
|
284
|
+
not have (CONTRACT §2) — a substrate that stores a number in the precision it was computed
|
|
285
|
+
in. What is worth saying is the boundary the change respects: nothing canonical moved. Box
|
|
286
|
+
3 is rebuildable, so its format is a free variable, and a format change that had needed a
|
|
287
|
+
canonical migration would have been the wrong design showing itself.
|
|
288
|
+
|
|
289
|
+
## 2026-09-05 — the two clocks: lived days for physics, real dates for provenance
|
|
290
|
+
|
|
291
|
+
*The design behind LAUNCH-STATUS §I7 and the owner's ruling of 2026-09-04: "we do
|
|
292
|
+
lived days for good reason (if we don't chat for a few weeks we don't want everything
|
|
293
|
+
to fade) but we also need to use actual dates/clock times, so we should have a
|
|
294
|
+
solution that works and understands both."*
|
|
295
|
+
|
|
296
|
+
### The brain analog
|
|
297
|
+
|
|
298
|
+
**An episodic memory carries a "when" that is separate from its consolidation age.**
|
|
299
|
+
The hippocampus time-stamps an experience — the temporal context that lets you say
|
|
300
|
+
"that was the Tuesday before the trip" — and that stamp is CONTENT: it can be recalled,
|
|
301
|
+
it can be wrong, it can be corrected without changing anything about how strong the
|
|
302
|
+
memory is. Consolidation age is a different variable entirely, and it is the one that
|
|
303
|
+
governs forgetting: how much has happened since, how many times the trace was
|
|
304
|
+
reactivated, how far systems consolidation has carried it out of the hippocampus. Two
|
|
305
|
+
weeks in a coma and two weeks of living are the same fourteen calendar days and are
|
|
306
|
+
not the same amount of consolidation.
|
|
307
|
+
|
|
308
|
+
v2 had the second and was faking the first. `physics/clock.ts` is a careful,
|
|
309
|
+
well-defended lived-day clock — engram scar E8, "a week away must not decay a week's
|
|
310
|
+
worth". Provenance had no clock at all: `store.put` defaulted `learnedOn` to a
|
|
311
|
+
module-level `today()` that read the ambient `Date.now()`, `appendEvent` and the
|
|
312
|
+
version rows stamped `Date.now()` inline, and `Store.open` took no clock to be given
|
|
313
|
+
one. So the "when" was not a stamp on the experience, it was a stamp on the WRITE —
|
|
314
|
+
and every path where those two differ produced a row that says a thing that is not
|
|
315
|
+
true. Three of them, all measured:
|
|
316
|
+
|
|
317
|
+
- the demo store: 156 of 172 rows read the day the seeder ran; every one of the wake's
|
|
318
|
+
26 lines opened `2026-09-05 ·`;
|
|
319
|
+
- a replay of a corpus from months ago: every row dated the day the harness ran;
|
|
320
|
+
- the v1 import: 12,334 of 14,529 migrated memories carry the import day
|
|
321
|
+
(`docs/PARALLEL-RUN-STATUS.md`, 2026-09-04), which is why #29/#30 had to render a
|
|
322
|
+
migrated element as an upper bound, `by 2026-09-03 ·`, rather than as a claim.
|
|
323
|
+
|
|
324
|
+
### The model
|
|
325
|
+
|
|
326
|
+
**Two clocks, named, with a fixed division of fields.**
|
|
327
|
+
|
|
328
|
+
| | PHYSICS CLOCK | PROVENANCE CLOCK |
|
|
329
|
+
|---|---|---|
|
|
330
|
+
| what it measures | how much experience has passed | when in the world |
|
|
331
|
+
| where it lives | `livedDay()` / `advanceClock(date)` / `physics/clock.ts` | `StoreOptions.now`, `Store.now()`, `Store.today()` |
|
|
332
|
+
| who moves it | the host, once per lived day | the session, continuously |
|
|
333
|
+
| what reads it | decay, consolidation, dedup's tie-break, banding, pruning, `bornDay`, `bandDay`, `lastUsedDay` | `learnedOn`, `happenedOn`, the event log's `at`, a version's `archived_at`, a removal record's `at`, the in-process event ring |
|
|
334
|
+
| what a week away does | nothing — days not lived do not advance it | seven days pass, because they did |
|
|
335
|
+
|
|
336
|
+
The provenance clock is INJECTED and defaults to `Date.now`, so a host that gives it
|
|
337
|
+
nothing behaves exactly as it did before this entry existed. The seeder gives it the
|
|
338
|
+
story's day, the replay driver gives it the corpus day, and a migration would give it
|
|
339
|
+
the day the row was actually learned. There is now exactly one `Date.now()` call left
|
|
340
|
+
in `store/index.ts` — inside the module-level `today()` the adapters still use — and
|
|
341
|
+
`test/two-clocks.test.ts` counts it.
|
|
342
|
+
|
|
343
|
+
**The mint path takes the PROPOSAL'S instant, not the write's.** `mintProposal` dates a
|
|
344
|
+
memory `dateOf(proposal.at)`: the moment the author deposited, read off the span
|
|
345
|
+
buffer's injected clock. The row is written later — at a boundary, possibly the next
|
|
346
|
+
morning, possibly during a replay of a corpus from a year ago — and a memory is dated
|
|
347
|
+
by when it was learned. On the crash-fallback path the proposal's `at` is the
|
|
348
|
+
boundary's own `nowFn()`, which makes a swept memory dated the day it was INTERPRETED.
|
|
349
|
+
That is the honest default and it is named rather than assumed: the spans it read
|
|
350
|
+
carry their own instants, and deriving a `happenedOn` from them is DELIBERATELY not
|
|
351
|
+
done here, because `prospective/` reads `happenedOn` as a content date and would begin
|
|
352
|
+
arming windows off a field the interpreter never claimed. Filed, not forgotten.
|
|
353
|
+
|
|
354
|
+
### Four decisions, with the reason each was taken
|
|
355
|
+
|
|
356
|
+
1. **UTC, not local.** `dateOf(at)` is `toISOString().slice(0, 10)`, the same
|
|
357
|
+
arithmetic `today()` always used, and the same arithmetic every other date in this
|
|
358
|
+
codebase is written with: the hook that supplies `advanceClock`'s date
|
|
359
|
+
(`bin/hook.ts:101`), the worker (`bin/runner.ts:177`), `sleep/cycle.ts#todayDate`,
|
|
360
|
+
the embedder's seat rotation. Provenance dating locally while the physics clock is
|
|
361
|
+
keyed UTC would put the two calendars a few hours out of step for anyone west of
|
|
362
|
+
Greenwich and make a row's `learnedOn` disagree with the lived day it was born on.
|
|
363
|
+
**Moving ALL of them to local dating is a real question and it is filed, not
|
|
364
|
+
decided here**: it is a one-line change per site and a behaviour change on the live
|
|
365
|
+
store, and it wants its own carry-forward declaration.
|
|
366
|
+
2. **Not `physics/clock.ts#dayKey`.** `dayKey` shifts by `BOUNDARY_HOUR` so that a
|
|
367
|
+
lived evening running past midnight counts as one day. That is a PHYSICS idea — it
|
|
368
|
+
answers "which lived day does this activity belong to". A memory taken at 01:30 was
|
|
369
|
+
taken on the 14th whatever lived day it counts toward, so provenance does not get
|
|
370
|
+
the boundary shift. The two functions stay in two files for that reason.
|
|
371
|
+
3. **`revise` is the door for a date correction.** `store.revise` learned
|
|
372
|
+
`learnedOn` / `happenedOn`, writing the prose frontmatter and the column in one
|
|
373
|
+
transaction. A date correction is a revision: `revise` archives the prior document
|
|
374
|
+
first, so the wrong date stays readable in `versions/` (constitution 7 — revisions
|
|
375
|
+
keep their history, nothing is silently overwritten). This also closes
|
|
376
|
+
`prospective/INTERFACE-GAPS.md` §4, which asked for exactly `happenedOn?: string` in
|
|
377
|
+
the patch so a reschedule could complete in one call.
|
|
378
|
+
4. **The physics date key stays the host's.** `sleep/cycle.ts#todayDate()` still exists
|
|
379
|
+
and still reads the ambient clock; every live entry point passes `date` explicitly,
|
|
380
|
+
so it is only a fallback. What changed is which fallback: `Counterpart.sessionEnd`
|
|
381
|
+
now defaults `date` to `this.store.today()`, so a caller who forgets the date
|
|
382
|
+
advances the lived-day clock with THIS SESSION'S date rather than with a date from a
|
|
383
|
+
different year than everything the same run wrote. A boundary is the one place the
|
|
384
|
+
two clocks touch, and that is the only line where they do.
|
|
385
|
+
|
|
386
|
+
### The repair, and the three guards the review bought it
|
|
387
|
+
|
|
388
|
+
Nothing here is retroactive. The 12,334 migrated rows still carry the import day until
|
|
389
|
+
the owner runs `counterparts repair-dates --apply`, which proposes true dates from what
|
|
390
|
+
the rows themselves carry — engram-era ids that are millisecond timestamps, v1 `created`
|
|
391
|
+
fields, a v1 element's `statedOn` / `openedOn`, session references, source paths — and
|
|
392
|
+
writes nothing on a dry run.
|
|
393
|
+
|
|
394
|
+
The adversarial review of PR #67 reproduced the failure mode that matters, and it is
|
|
395
|
+
worth recording because the shape recurs in every repair tool: **a repair that measures
|
|
396
|
+
its own starting condition stops being able to measure it once it has run.**
|
|
397
|
+
`measureImportDay` takes the MODE of `learned_on`; after `--apply` the mode can move to a
|
|
398
|
+
repaired date, which both narrows the plausibility window and pulls correctly-dated rows
|
|
399
|
+
into the target set. Measured on the review's fixture: a second `--apply` wrote ten
|
|
400
|
+
no-op revisions and ten events for five rows, and at 12,334 rows that is ~12K archived
|
|
401
|
+
documents recording a change that did not happen. Three guards, in the order they fire:
|
|
402
|
+
|
|
403
|
+
1. **The import day is pinned, not re-measured.** The first `--apply` records the day it
|
|
404
|
+
used in store meta, later runs read it back, and `tools/migrate/apply.ts` now writes
|
|
405
|
+
`migratedOn` at import time so a store migrated from here on never has to be measured
|
|
406
|
+
at all. A recorded day the measurement contradicts is a REFUSAL with the flag that
|
|
407
|
+
overrides it printed — the two ways that happens are "somebody repaired this already"
|
|
408
|
+
and "this is not the store you think it is", and both want a human.
|
|
409
|
+
2. **A repaired row is never a target again**, by a marker on its own document
|
|
410
|
+
(`meta.dateRepaired`).
|
|
411
|
+
3. **A proposal equal to the date already there is never written.** A re-dating that
|
|
412
|
+
changes nothing must not archive a version and claim it did.
|
|
413
|
+
|
|
414
|
+
**The dry run shows the shape of what it would write, not only the count.** A v1 importer
|
|
415
|
+
that stamped one `created` date onto thousands of documents reads as confidence `high`
|
|
416
|
+
here, and applying it would re-do the exact failure this tool exists to undo — invisibly,
|
|
417
|
+
because twenty sample rows out of 12,334 cannot show it. So the report prints the
|
|
418
|
+
proposed dates by count and flags any single date carrying more than 5% of the proposals
|
|
419
|
+
(with a five-row floor, so a small store does not cry wolf).
|
|
420
|
+
|
|
421
|
+
**A repaired date stops being hedged.** `self/`'s wake renders a migrated element's date
|
|
422
|
+
as an upper bound — `by 2026-09-03 ·` — because the row could not say whether the date
|
|
423
|
+
was v1's or the importer's. A row repaired at HIGH confidence now says which, so it
|
|
424
|
+
renders plainly; `medium` and `low` keep the bound, because the session, the element's
|
|
425
|
+
statement and the source path are all still "no later than". The marker is read
|
|
426
|
+
structurally in `self/index.ts` (an adapter's constant may not be imported into core) and
|
|
427
|
+
a malformed one renders the bound, which is the safe direction.
|
|
428
|
+
|
|
429
|
+
### What this does not fix, on purpose
|
|
430
|
+
|
|
431
|
+
- **Migrated ELEMENTS have no evidence to recover from.**
|
|
432
|
+
`tools/migrate/apply.ts#writeElement` does not pass `el.v1Id` into the element's meta,
|
|
433
|
+
so every `sch_` row without a `statedOn` / `openedOn` lands in the `none` bucket and is
|
|
434
|
+
left exactly as it is. The count shows it; this is the reason. Fixing it means changing
|
|
435
|
+
the migration and re-importing, which is a different operation than a repair.
|
|
436
|
+
- **`happenedOn` from spans.** See above. `prospective/` reads it; deriving it would
|
|
437
|
+
arm windows nobody claimed.
|
|
438
|
+
- **Local dating.** Decision 1.
|
|
439
|
+
|
|
440
|
+
## 2026-09-05 — `COUNTERPARTS_REQUIRE_EXPLICIT_DIR`: the implicit default can be refused
|
|
441
|
+
|
|
442
|
+
**The incident (LAUNCH-STATUS I21).** Overnight an agent opened the owner's live store
|
|
443
|
+
by passing the wrong option name to a library call: `dir` was undefined, it had no
|
|
444
|
+
`COUNTERPARTS_DATA_DIR`, and `dataDir()` did what it is documented to do — returned
|
|
445
|
+
`~/.counterparts/store`. Read-only, nine titles printed to its own terminal, no write,
|
|
446
|
+
no egress; and exactly the shape every guard in this module was built to catch, one
|
|
447
|
+
directory over. `.counterparts` is deliberately NOT on `FORBIDDEN_ROOT_NAMES` — the store
|
|
448
|
+
has to be able to open its own default — so the path guard (§5 G9) could not have fired,
|
|
449
|
+
and `test/preload.ts`'s temp-home redirect protects only the test process. The owner
|
|
450
|
+
ruled: add a guard, OFF by default, ON in this repo's agent shells.
|
|
451
|
+
|
|
452
|
+
**The mechanism.** One environment variable, two new error codes. With
|
|
453
|
+
`COUNTERPARTS_REQUIRE_EXPLICIT_DIR` armed, `dataDir()` throws `IMPLICIT_DEFAULT_DIR_REFUSED`
|
|
454
|
+
instead of returning the fallback, with `{ guard, dir, remedy }` in the detail so the
|
|
455
|
+
message names all three without any caller composing it.
|
|
456
|
+
|
|
457
|
+
**Reading the switch — three answers, not two.** It arms on `1`, `true` or `on`, trimmed
|
|
458
|
+
and case-insensitive: a superset of the two `COUNTERPARTS_OBSERVER` accepts, so a person
|
|
459
|
+
who exports `=true` or `=on` by analogy is protected. It stands DOWN on `0`, `false` or
|
|
460
|
+
`off`, exactly as if unset. And it REFUSES anything else non-blank with
|
|
461
|
+
`EXPLICIT_DIR_GUARD_MALFORMED`, at the same decision point (`explicitDirRequired`), with
|
|
462
|
+
a sentence naming the value, the three words that arm it and the three that turn it off.
|
|
463
|
+
|
|
464
|
+
Two review rounds shaped that. The first draft armed on exactly `1`, and the #80 review
|
|
465
|
+
measured `=true`, `=yes`, `=on` and `= 1` all falling silently to the default: fail-open,
|
|
466
|
+
the one direction a safety guard may not have. The fix over-corrected — it refused `0` and
|
|
467
|
+
`false` too — and the owner ruled that back: a guard whose `=0` refuses trips the shell of
|
|
468
|
+
the person it protects, which is the surprising choice, and refusing on junk keeps the
|
|
469
|
+
fail-closed property without it. **Off means off; junk is a question this will not answer.**
|
|
470
|
+
|
|
471
|
+
`COUNTERPARTS_OBSERVER` is deliberately NOT widened to the same set, though the parity
|
|
472
|
+
argument runs both ways. It is matched exactly (`"1"` / `"true"`) in two places —
|
|
473
|
+
`cli/commands.ts` and `mcp/bin/serve.ts#launchOptions` — and the second is on the live MCP
|
|
474
|
+
server's launch path, which this change promises to leave instruction-for-instruction
|
|
475
|
+
identical; giving observer a fail-closed arm is a behaviour change to an unrelated
|
|
476
|
+
variable and wants its own ruling. So the guard is the superset, and says so. The guard is consulted
|
|
477
|
+
only where it decides — a malformed value beside a named `dir` or a named configuration
|
|
478
|
+
is not read at all, because the guard's one question is about the fallback. Every door
|
|
479
|
+
the store has funnels through that one function — `Store.open`,
|
|
480
|
+
`Counterpart.open`, `SpanBuffer`, `storeExists()` with no argument, the console's
|
|
481
|
+
`resolveDir`, the dashboard — so the guard sits in one place. The env-set case returns
|
|
482
|
+
before the guard is read: a process launched with `COUNTERPARTS_DATA_DIR` (the live MCP
|
|
483
|
+
server) executes the instructions it executed before. `dataDir()` also gained an
|
|
484
|
+
injectable `env` parameter (default `process.env`), which let `cli/commands.ts#resolveDir`
|
|
485
|
+
drop the swap-the-variable-in-and-out-of-`process.env` shape it had, and lets a test
|
|
486
|
+
construct the armed and unarmed cases without touching the process.
|
|
487
|
+
|
|
488
|
+
**The second door, and why it is covered.** The reviewer of PR #72 named the configuration
|
|
489
|
+
default as the other way into the live machine, and it is: a default-sourced
|
|
490
|
+
`~/.counterparts/claude-code.json` NAMES a store (`install` always writes `dataDir`) and
|
|
491
|
+
the credentials beside it, so the hook, the worker and the MCP server reach the live store
|
|
492
|
+
and the live keys with `dataDir()` never called — and `install` builds `~/.counterparts`
|
|
493
|
+
from `homedir()` itself and writes there. `adapters/config-path.ts#implicitConfigRefusal`
|
|
494
|
+
is the same variable at that door: armed AND the configuration resolved to the default →
|
|
495
|
+
a refusal string, chained after `namedConfigRefusal` in the three bins and applied by hand
|
|
496
|
+
in the console's `install` branch. It is a separate function, not a clause in
|
|
497
|
+
`resolveConfigPath`, because `rebrief` resolves through the resolver too, for a budget
|
|
498
|
+
NUMBER against a store already named by `--dir`; refusing that would teach people to unset
|
|
499
|
+
the guard. The line: **the guard refuses an implicit default that locates a store or
|
|
500
|
+
writes the live base; a number read from the default config is neither.**
|
|
501
|
+
|
|
502
|
+
**Not covered, on purpose.** `claude-code/primacy.ts` reads the parallel run's assignment
|
|
503
|
+
file at `~/.memory-ab` by default — read-only, no store, and `test/store.test.ts` pins it
|
|
504
|
+
read-only. `tools/parallel/bin/{preflight,daily,restart}.ts` carry the live paths as
|
|
505
|
+
defaults by their own contract (every real path is a flag; the run directory's overlap
|
|
506
|
+
guard needs them named). Neither goes through `dataDir()` and neither opens a store.
|
|
507
|
+
|
|
508
|
+
**The gap between the two doors, and how it surfaces.** A NAMED configuration that names
|
|
509
|
+
no store — `--config` at a file with only `injectionBudgetBytes` — and no
|
|
510
|
+
`COUNTERPARTS_DATA_DIR`: `implicitConfigRefusal` is not its business, so the bins proceed
|
|
511
|
+
and `loaded.dataDir ?? dataDir()` meets the STORE guard, thrown rather than returned. The
|
|
512
|
+
refusal is right (a config that omits `dataDir` named where the keys are, not which
|
|
513
|
+
memory); the first draft's rendering was not: the hook printed the raw `StoreError` JSON,
|
|
514
|
+
whose remedy said `--dir` — a flag the hook does not have — and the worker exited 0 and
|
|
515
|
+
the server exited 1 with nothing on stderr (#80 review, recommendations 3 and 4). Now
|
|
516
|
+
`store/paths.ts#describeGuardRefusal(err, remedy)` renders both guard codes as one
|
|
517
|
+
sentence with the SURFACE's own remedy: the console, the dashboard and the server say
|
|
518
|
+
`--dir <path>, or COUNTERPARTS_DATA_DIR`; the hook and the worker say `Set "dataDir" in
|
|
519
|
+
<the file they read>, or set COUNTERPARTS_DATA_DIR`. The worker's and the server's
|
|
520
|
+
rejection handlers print that sentence (or, for any other error, its message) before
|
|
521
|
+
their exit 0 / exit 1, where they printed nothing — the one place this PR widened two
|
|
522
|
+
entry points' failure legibility, because the reason was sitting in the error the
|
|
523
|
+
handler was discarding (`test/config-rule.test.ts`, "the WORKER and the MCP SERVER say why
|
|
524
|
+
in that same gap", which spawns both as real processes).
|
|
525
|
+
|
|
526
|
+
**THE SECOND INCIDENT, and the refusal it earned (2026-09-04, added in the #80 review
|
|
527
|
+
round).** I21 was read-only and cost nine titles. The day before it, the same door was
|
|
528
|
+
walked through in the other direction, with a WRITE at the end: a suite run that had lost
|
|
529
|
+
`test/preload.ts`'s home mock resolved the owner's REAL `~/.counterparts/claude-code.json`
|
|
530
|
+
and rewrote its `dataDir` to a temp path. That file is the one the hook, the worker and the MCP server
|
|
531
|
+
read when nothing names another, so from that moment his live memory was a directory the
|
|
532
|
+
OS was free to delete — and it recorded nothing for three days before anyone noticed.
|
|
533
|
+
This PR is the prevention, and the mock is only half of it: a mock can be lost, and was.
|
|
534
|
+
|
|
535
|
+
So `cli/install.ts#throwawayDefaultRefusal` refuses the shape itself, with no variable
|
|
536
|
+
involved — the incident's shell had neither the guard nor the mock, so a refusal that
|
|
537
|
+
needed either would not have been there. `install` will not write THE DEFAULT
|
|
538
|
+
`~/.counterparts/claude-code.json` with a `dataDir` under a temp root (`os.tmpdir()`,
|
|
539
|
+
`$TMPDIR`/`$TMP`/`$TEMP`, `/tmp` — each compared in both its spellings, because macOS
|
|
540
|
+
hands out `/var/folders/…` and `/private/var/folders/…` for the same directory).
|
|
541
|
+
`--config <elsewhere>` is the way through and moves the credentials and the store with
|
|
542
|
+
it, so a scratch install is scratch all the way down; `--force` does not buy past it,
|
|
543
|
+
because `--force` overwrites a file you named and this is the file nobody named.
|
|
544
|
+
|
|
545
|
+
The refusal's third clause is what keeps the clean rooms working, and it is the honest
|
|
546
|
+
answer to "key it on the REAL default path": it fires only when the CONFIG is **not**
|
|
547
|
+
itself under a temp root. `tools/install-loop/run.sh` installs into a fake `$HOME`
|
|
548
|
+
beneath `$TMPDIR` with no `--config`, so its default config and its store are both
|
|
549
|
+
throwaway and both under the same base — a stranger's install, correctly measured, not a
|
|
550
|
+
live default pointed at a temp store. The test suite is in the same position (the mocked
|
|
551
|
+
home is minted under `os.tmpdir()`), which is why the refusal is provable only with an
|
|
552
|
+
injected home outside the temp tree; both install-loop runs stayed 47/47 with it in.
|
|
553
|
+
|
|
554
|
+
**Observation, recorded (#80 review, 5).** The guard is read from the INJECTED
|
|
555
|
+
environment only: `dataDir(env)` and `cli/commands.ts#run(argv, { env })` read the object
|
|
556
|
+
they were handed, so `run(["status"], { env: {} })` with `process.env` armed is not
|
|
557
|
+
refused — it reaches the fallback, which in the suite is the mocked temp home. The real
|
|
558
|
+
bin passes no `env` (`opts.env ?? process.env`), so no live surface is affected, and the
|
|
559
|
+
preload's first layer still holds for a test that injects an empty environment; what the
|
|
560
|
+
second layer promises — "a forgetful test is REFUSED" — is true of tests that do not
|
|
561
|
+
inject one. OR-ing the injected env with `process.env` would close it at the cost of the
|
|
562
|
+
"unarmed → today's behaviour" tests having to stand the process guard down around their
|
|
563
|
+
bodies; left as is, and named here, so the choice is visible.
|
|
564
|
+
|
|
565
|
+
**Follow-up, filed (#80 review, 6).** `tools/parallel/bin/restart.ts` still reaches a live
|
|
566
|
+
path by naming nothing — its `--v2-data-dir` default is `join(homedir(), ".counterparts")`
|
|
567
|
+
— and WRITES there. It is outside this guard by construction (an explicit dir built from
|
|
568
|
+
`homedir()`, never `dataDir()`) and outside the ruling's scope; it is the incident's exact
|
|
569
|
+
class with a write at the end, and wants its own ruling.
|
|
570
|
+
|
|
571
|
+
**Where it is ON.** `test/preload.ts` (a forgetful test is now REFUSED, not redirected —
|
|
572
|
+
the second layer under the temp-home; `test/preload.test.ts` asserts it is armed when a
|
|
573
|
+
file starts, so a test that stood it down and forgot to re-arm it is caught), the demo
|
|
574
|
+
seeder's CLI path, the visual loop, the recall bench's bin. The install loop UNSETS it
|
|
575
|
+
inside its clean room: its fake HOME already makes the defaults throwaway, and the loop
|
|
576
|
+
measures a stranger's environment — the stranger's path IS the defaults. One loop step
|
|
577
|
+
arms it on purpose to prove the installed console and hook carry the refusal.
|
|
578
|
+
|
|
579
|
+
**Cost.** With the variable unset, every function in the change returns the same value and
|
|
580
|
+
performs the same side effects it did before, for every input, on every host. The MCP
|
|
581
|
+
server's arm has zero new instructions; the hook's and the console's fallback arms each
|
|
582
|
+
evaluate one new side-effect-free environment read. Surface-set hash unchanged
|
|
583
|
+
(`c3af0bef00209ba6` on master and branch). Declared to the parallel run as ANYTHING ELSE
|
|
584
|
+
riding today's owed restart rather than IDENTICAL — G12's first class is telemetry-only by
|
|
585
|
+
its text, and a guard is not telemetry — with the value-identity argument recorded as the
|
|
586
|
+
reach (`docs/PARALLEL-RUN-STATUS.md`, same date).
|
|
587
|
+
## 2026-09-05 — a store directory is self-contained (schema v5, and what survived the floor)
|
|
588
|
+
|
|
589
|
+
*Condensed at the floor (F8). The v5 MECHANISM is deleted and the long version of this
|
|
590
|
+
note with it: the store-relative path columns, `resolveStoredPath`'s four cases, the
|
|
591
|
+
blank-pointer line that mattered most in review, `relativizeStoredPath`'s deepest-segment
|
|
592
|
+
tail rule, the `../ESCAPE/…` guard, the argument for why a schema bump beat a tolerant
|
|
593
|
+
no-bump, the `OBSERVER_READ_FLOOR` exception that bump earned, and the migration's three
|
|
594
|
+
properties with their 79/82/67 ms measurement. All of it existed to keep a row's POINTER
|
|
595
|
+
honest, and there is no pointer. The bug and the property are what is worth keeping.*
|
|
596
|
+
|
|
597
|
+
**The bug** (finding I22, LAUNCH-STATUS G26). `insertOne` wrote an ABSOLUTE
|
|
598
|
+
`<dir>/prose/<family>/<id>.md` into `memories.prose_path`, and `revise`/`supersede` wrote
|
|
599
|
+
the same shape into `versions.path`. Every reader handed the column straight to
|
|
600
|
+
`readFileSync`, and `adapters/cli/removal.ts` handed it to `rmSync`. So a copied store —
|
|
601
|
+
`cp -R`, a `counterparts backup`, a restored snapshot — opened fine, listed its own rows,
|
|
602
|
+
and read the ORIGINAL's prose through them; a removal run in the copy reported success and
|
|
603
|
+
deleted the original's file while the copy's own survived. Constitution line 7's
|
|
604
|
+
catastrophe case — source gone, open the backup — is exactly where a read-only reader
|
|
605
|
+
failed.
|
|
606
|
+
|
|
607
|
+
**What keeps it now: nothing does, and that is the point.** A row IS its memory, so there
|
|
608
|
+
is no address outside the database for a copy to resolve against the wrong root, and no
|
|
609
|
+
resolver left to get one wrong. The criterion is unchanged and still proved —
|
|
610
|
+
`test/store-portable.test.ts` copies a store, destroys the source outright and reads
|
|
611
|
+
through the copy; removes through the copy and finds the source byte-identical; and opens
|
|
612
|
+
a `backup` snapshot standalone (§5 G15). `tools/parallel/legacy-paths.ts` keeps
|
|
613
|
+
`resolveStoredPath` and `relativizeStoredPath` for the read-only instruments that still
|
|
614
|
+
read the owner's parked pre-rows store; nothing in `src/` imports either.
|
|
615
|
+
|
|
616
|
+
**The one loose end the v5 note named, closed by the floor rather than by anybody:** the
|
|
617
|
+
plaintext `export` bundled `prose/` and the database but NOT `versions/`, so a restored
|
|
618
|
+
export's version rows dangled. Versions are rows in the one database `VACUUM INTO` copies,
|
|
619
|
+
so there is nothing left to omit.
|
|
620
|
+
|
|
621
|
+
**Brain analog: none.** This is the engineering floor (CONTRACT §2). What it protects is
|
|
622
|
+
constitution line 6 — memory that "travels across hosts" cannot be pinned to one machine's
|
|
623
|
+
directory tree — and line 7's "backups catch catastrophe", which was not true while a
|
|
624
|
+
backup's rows pointed at the live store.
|
|
625
|
+
|
|
626
|
+
## The backfill's give-up list lives in meta (I33, 2026-09-11)
|
|
627
|
+
|
|
628
|
+
`missingVectors` returns a STABLE order — first-person material first, oldest
|
|
629
|
+
first inside each group — and that order is a memory claim worth keeping. It is
|
|
630
|
+
also, without a skip list, a head-of-line block waiting for one un-embeddable
|
|
631
|
+
row: two migrated memories carrying a lone UTF-16 surrogate made the provider
|
|
632
|
+
answer 400 for the whole 64-text chunk, and the same head-64 was re-asked at
|
|
633
|
+
every boundary for a week while 165 blind memories waited behind them.
|
|
634
|
+
|
|
635
|
+
**`embed.failed.<id>` in box 2's meta, `EMBED_SKIP_AFTER` = 3.** Meta keys, not a
|
|
636
|
+
column and not a schema bump — the precedent is `sleep.pruned.<id>`, and the fact
|
|
637
|
+
being recorded is about a retry loop, not about the memory.
|
|
638
|
+
|
|
639
|
+
**Only an ITEM-ATTRIBUTABLE failure may move it, and "three" was never the guard
|
|
640
|
+
that made that true.** The first cut counted every failure and said three in a
|
|
641
|
+
row was past transient. It is not: a 429, a dead socket or — worst — the detached
|
|
642
|
+
worker's own watchdog abort fails the WHOLE window every time it happens, so
|
|
643
|
+
three bad boundaries retired sixty-four healthy rows and `unembeddedCount` then
|
|
644
|
+
read COMPLETE. That is I33 inverted, with the coverage watch failing in the
|
|
645
|
+
optimistic direction, and a 503 test now pins it shut. The counter moves only
|
|
646
|
+
when the last fill blamed ONE INPUT — a 400 the bisector narrowed to a single
|
|
647
|
+
item (`ChunkFailure.item`). Three is still the limit because even a 400 can be
|
|
648
|
+
answered for a reason that is not the text.
|
|
649
|
+
|
|
650
|
+
The gate is per FILL rather than per id: a `ChunkFailure`'s offsets address the
|
|
651
|
+
embedder's own deduped batch, not the backfill's ids, so a fill that mixed an
|
|
652
|
+
isolated 400 with a 500 elsewhere still charges the 500's victims. Bounded by a
|
|
653
|
+
run that saw poison at all, and named in the adapter's INTERFACE-GAPS.
|
|
654
|
+
|
|
655
|
+
**The moves are ONE transaction.** `setMetaMany` exists for this: one `setMeta`
|
|
656
|
+
per id was one lock acquisition per id, on exactly the run where things are
|
|
657
|
+
already going wrong, at a boundary where the adapter has measured six
|
|
658
|
+
overlapping workers against a 5 s busy timeout. A run where everything lands
|
|
659
|
+
writes nothing at all.
|
|
660
|
+
|
|
661
|
+
**A skip is not a denial, and the two must never merge.** `deniedIds()` is a
|
|
662
|
+
REMOVAL: the row is dark, it must never come back, and a read of it is a refusal.
|
|
663
|
+
A skipped id is live, recallable, lexically indexed and perfectly ordinary —
|
|
664
|
+
only its vector is missing. `skippedVectorIds()` names them, `verify` prints
|
|
665
|
+
them, and setting the counter back to zero puts the id straight back in the
|
|
666
|
+
rotation.
|
|
667
|
+
|
|
668
|
+
**The skip is self-sealing, so it needs a door of its own.** A run that LANDS
|
|
669
|
+
clears the counter — but a skipped id is never offered to a run again, so it
|
|
670
|
+
cannot land; and `rebuildCache` has no embedder to recompute a vector with and
|
|
671
|
+
never touches meta. The first cut of `verify` printed "repair it (or rebuild box
|
|
672
|
+
3) and the counter clears on the next run that lands", and neither half of that
|
|
673
|
+
was reachable. `counterparts verify --dir <store> --retry-skipped` is the remedy:
|
|
674
|
+
it clears every `embed.failed` counter, names how many and which ids, writes
|
|
675
|
+
nothing else, and lets the next boundary decide again on the evidence.
|
|
676
|
+
|
|
677
|
+
**`unembeddedCount()` excludes them, and that is the honest reading.** The count
|
|
678
|
+
exists so a coverage watch has a number that falls run over run; a number that
|
|
679
|
+
can never fall because three rows in it can never be embedded is a watch that has
|
|
680
|
+
quietly stopped meaning anything. The excluded rows are not hidden — the backfill
|
|
681
|
+
row carries `skipped`, `verify` prints the ids beside the count — so the two
|
|
682
|
+
numbers add up wherever a person actually reads them.
|
|
683
|
+
|
|
684
|
+
**`metaWithPrefix(prefix)`** is the read that makes this affordable: one `LIKE`
|
|
685
|
+
(with `%` and `_` escaped — callers pass a key prefix, not a pattern) instead of
|
|
686
|
+
one `getMeta` per live memory. `sleep.pruned.<id>` has the same shape and the
|
|
687
|
+
same potential reader.
|
|
688
|
+
|
|
689
|
+
## `memories.band` is the band of record, and decay keeps it true (U8, 2026-09-14)
|
|
690
|
+
|
|
691
|
+
**What the column meant until now, in practice: nothing anybody could trust.**
|
|
692
|
+
Every row is inserted `episodic` (`insertOne`, `input.band ?? "episodic"`);
|
|
693
|
+
`setBand` was called from exactly one place, `sleep/consolidate.ts` at the
|
|
694
|
+
identity crossing. Nothing ever wrote `semantic`. On the live store that read
|
|
695
|
+
`1,054` semantic rows in the ranking cache against `185` in the table, all of
|
|
696
|
+
them stamped `band_day = 184` — the one day a promotion ever fired — and 869 live
|
|
697
|
+
rows semantic in box 3 and episodic in box 2 at the same instant.
|
|
698
|
+
|
|
699
|
+
**The ruling: the table follows physics.** `sleep/decay.ts` now writes a row's
|
|
700
|
+
band back to `memories.band` / `band_day` whenever the column disagrees with
|
|
701
|
+
`band(m, d)`, in the same pass that emits the `band.transition` rows — so the
|
|
702
|
+
canonical column cannot contradict the crossing records the system publishes
|
|
703
|
+
about it. The reasoning, and why this is not the materialize-decay churn v2
|
|
704
|
+
declined, is in `sleep/NOTES.md` §5.
|
|
705
|
+
|
|
706
|
+
**Who reads the column, as of this PR** — enumerated, because changing what a
|
|
707
|
+
column means is only safe if the readers are known:
|
|
708
|
+
|
|
709
|
+
| reader | reads | effect of the change |
|
|
710
|
+
| --- | --- | --- |
|
|
711
|
+
| `self/identity.ts` (`list({ band: "identity" })`, `row.band !== "identity"`) | the identity band, as a set | none: `band()` answers `identity` only for a `promotedIdentity` row, which `consolidate` already stamped, and identity is decay-exempt |
|
|
712
|
+
| `adapters/mcp/server.ts` `status.byBand` | the column, directly | **fixed**: it stops reporting a fossil |
|
|
713
|
+
| `adapters/cli/commands.ts` `status` | computes the band from physics and says so in a comment | none; the workaround is now redundant rather than wrong |
|
|
714
|
+
| `adapters/dashboard/` (`browse.ts`, `status.ts`, `web/views.ts`) | computes live, shows the recorded column beside it | none; `recorded` now agrees after a pass |
|
|
715
|
+
| `schemas/` | reads `band`, writes none (§4 of its CONTRACT; source scan) | none |
|
|
716
|
+
| `sleep/consolidate.ts` | `rowToPhysics`, never `band` | none — promotion never gated on the column |
|
|
717
|
+
| `revision.ts:310` | **GATES**: `row.band === "identity" \|\| target.promotedIdentity` routes a declaration to the identity arm | none in the losing direction — see the argument below |
|
|
718
|
+
| `store/owner-op-seam.ts:213` → `self/identity.ts:388` | **GATES**: the removal tombstone captures `row.band` at chase time, and the enumeration lists a removed element as an identity absence on `gone.wasPromotedIdentity \|\| gone.band === "identity"` | none in the losing direction — see the argument below |
|
|
719
|
+
|
|
720
|
+
**Two of them GATE, and the reconciliation is safe for both.** An earlier
|
|
721
|
+
statement of this change said none of the readers gated on the column; that was
|
|
722
|
+
wrong, and the two above are why the enumeration is worth keeping. Both are ORs
|
|
723
|
+
with `promoted_identity`, and `band()` returns `identity` **iff**
|
|
724
|
+
`promotedIdentity` — it is the first line of the function, before any arithmetic
|
|
725
|
+
(`physics/index.ts`). So for a live row the reconciliation can only write the
|
|
726
|
+
column INTO identity (a promoted row whose column had not caught up), never out
|
|
727
|
+
of it, and a gate that fires on `band === "identity"` can only gain rows it
|
|
728
|
+
should already have had. The single path that writes `identity` into the column
|
|
729
|
+
without the flag is migration — `tools/migrate/plan.ts` hands a v1 trace above
|
|
730
|
+
the identity gradient cut `bandOf()` identity while `promotedIdentity` stays
|
|
731
|
+
false when v1 itself had retired the trace — and such a row is written ARCHIVED,
|
|
732
|
+
which the decay pass skips outright. Only the owner-op `unarchiveMerged` door
|
|
733
|
+
could put one back in front of the pass, and there the correction is the point:
|
|
734
|
+
an un-merged row whose column claims identity it was never promoted to is
|
|
735
|
+
exactly a column denying the arithmetic.
|
|
736
|
+
|
|
737
|
+
**`band_day` means "the lived day the column was last brought to physics."** It
|
|
738
|
+
has never been a crossing record: the latched `band.transition` row is, and it is
|
|
739
|
+
the one a reader should join on. The first pass after this ships stamps the whole
|
|
740
|
+
backlog with one day, which is the honest reading of what happened — the column
|
|
741
|
+
was reconciled that day.
|
|
742
|
+
|
|
743
|
+
**Checked, not believed:** `counterparts verify` counts live non-journal rows
|
|
744
|
+
whose column disagrees with box 3 (`cli/commands.ts#bandOfRecordCensus`), and it
|
|
745
|
+
is 0 after a decay pass that its budget did not cut short.
|
|
746
|
+
|
|
747
|
+
## WAL, and the busy timeout first (I38/I39, 2026-09-18)
|
|
748
|
+
|
|
749
|
+
`openDb` sets its pragmas in this order, and the order is the fix:
|
|
750
|
+
|
|
751
|
+
1. `PRAGMA busy_timeout = 5000` — **first**. Every statement after it can contend
|
|
752
|
+
for a lock, and without it SQLite fails them INSTANTLY. It used to be set LAST,
|
|
753
|
+
which meant the journal-mode statement ran with zero wait inside another
|
|
754
|
+
writer's commit window: I39, and the shape of the I38 "database is locked"
|
|
755
|
+
reports.
|
|
756
|
+
2. `PRAGMA foreign_keys = ON` (unchanged).
|
|
757
|
+
3. The journal mode is **read, then set only when it differs from `wal`** — and
|
|
758
|
+
only when the caller asked (`openDb(path, { wal: true })`). Reading is free;
|
|
759
|
+
setting is a write that takes the exclusive lock, so an opener that converted a
|
|
760
|
+
file it had come to read would be writing at open (§5, the observer rule). The
|
|
761
|
+
default is OFF for the openers that matter: `vacuumInto` opens the SOURCE of a
|
|
762
|
+
backup this way, and `cli` opens box 3 read-only for the vector census. The
|
|
763
|
+
writer path asks (`openOperational` when `initialize !== false`), and so does
|
|
764
|
+
`openCache` unconditionally — box 3 is declared rebuildable and its sidecars
|
|
765
|
+
live inside `cache/`, the same licence the constructor already takes to
|
|
766
|
+
materialize that directory under an instrument.
|
|
767
|
+
4. `PRAGMA synchronous = FULL` — unchanged. WAL's usual pairing is `NORMAL`; that
|
|
768
|
+
is a durability ruling for the owner, not a cleanup to make in passing.
|
|
769
|
+
TUNABLE, and the one knob here that trades fsyncs for commit speed.
|
|
770
|
+
|
|
771
|
+
**Why WAL at all:** several processes hold this one small database open at once —
|
|
772
|
+
the session hooks, a long-running MCP server, the nightly worker, the dashboard —
|
|
773
|
+
and in WAL a reader no longer blocks the writer.
|
|
774
|
+
|
|
775
|
+
**What was measured getting here** (bun:sqlite 1.3, macOS; all of it is pinned in
|
|
776
|
+
`test/store.test.ts`'s "WAL, the busy timeout, and I39"):
|
|
777
|
+
|
|
778
|
+
- **What a contended conversion costs depends on who holds the lock.** Against a
|
|
779
|
+
WRITER, SQLite does not run the busy handler: the statement fails in about a
|
|
780
|
+
millisecond (measured: 3 ms), the open continues in the old mode, and the next
|
|
781
|
+
open tries again. Against a READER the handler DOES run, so the open waits for
|
|
782
|
+
the reader and then converts — a 600 ms read costs 600 ms, and a reader holding
|
|
783
|
+
for longer than `BUSY_TIMEOUT_MS` costs the full five seconds and leaves the
|
|
784
|
+
file as it was (measured: 5,297 ms). So the ONE converting open can wait, once,
|
|
785
|
+
up to five seconds; every open after it reads `wal` and returns without a
|
|
786
|
+
statement, and in DELETE mode that opener's first WRITE would have waited on
|
|
787
|
+
the same shared lock anyway. *(The first cut of this note said "about a
|
|
788
|
+
millisecond" for both, which was measured against a writer and generalized.)*
|
|
789
|
+
Only SQLITE_BUSY/LOCKED is swallowed: "file is not a database" arrives on the
|
|
790
|
+
same statement, and `verify --rebuild`'s guard has to fail closed on it. One
|
|
791
|
+
consequence not to be surprised by: `SQLITE_READONLY` now propagates out of a
|
|
792
|
+
WRITER open on read-only media, where the old code opened and failed at the
|
|
793
|
+
first write.
|
|
794
|
+
- A handle opened while the file was in DELETE mode keeps reading **and writing**
|
|
795
|
+
correctly after another connection flips it to WAL. That is deploy day for the
|
|
796
|
+
MCP server: no restart needed.
|
|
797
|
+
- A **read-only** connection cannot create the `-shm`, so a WAL database whose
|
|
798
|
+
sidecars are BOTH missing is unreadable to one (`SQLITE_CANTOPEN`; with the
|
|
799
|
+
`-wal` still there and only the `-shm` gone it succeeds — SQLite's read-only
|
|
800
|
+
fallback). Every handle in this codebase is read-write — the dashboard's and
|
|
801
|
+
the census's included — so the exposure is `tools/parallel/readers.ts` alone,
|
|
802
|
+
and any ordinary open puts the sidecars back. **How often that state occurs is
|
|
803
|
+
a property of the SQLite build, not of this code**: Apple's system SQLite
|
|
804
|
+
enables persistent WAL, so on this machine the sidecars survive a clean close;
|
|
805
|
+
stock SQLite removes them on the last one, which means on Linux or a packaged
|
|
806
|
+
build a store nobody has open is in exactly this state. Deleting a `-wal` that
|
|
807
|
+
has not been checkpointed takes the commits inside it too: the sidecars are
|
|
808
|
+
part of the database, not litter.
|
|
809
|
+
- `close()` does not release the file to the PROCESS: a closed connection still
|
|
810
|
+
holds the lock a WAL → DELETE conversion needs. It is why the tests build a
|
|
811
|
+
DELETE-mode store with `VACUUM INTO` rather than a pragma, and why the sidecars
|
|
812
|
+
outlive a close here where SQLite would normally remove them.
|
|
813
|
+
- **A database's size is `page_count * page_size`, not a file size.** The file
|
|
814
|
+
alone under-reports (a cache mid-conversion read 1.8 MiB with 3.7 MB in the
|
|
815
|
+
`-wal`, enough to print "nothing to do" over a real compaction debt). The file
|
|
816
|
+
PLUS the `-wal` over-reports, and that was the first cut of `cli`'s
|
|
817
|
+
`databaseBytes`: the `-wal` holds COPIES of pages the file already counts, so a
|
|
818
|
+
fat one read as space a `VACUUM` would give back — 4,144,752 bytes of
|
|
819
|
+
reclaimable on a cache with nothing to reclaim, over the floor that sends
|
|
820
|
+
`migrate-cache --apply` into a pointless full VACUUM. What returns those bytes
|
|
821
|
+
is a checkpoint, and a checkpoint happens on its own. The two pragmas are true
|
|
822
|
+
wherever the pages are sitting and take no lock.
|
|
823
|
+
|
|
824
|
+
`counterparts verify` prints the mode and the timeout, and `counterparts doctor`
|
|
825
|
+
grades it — green in `wal`, amber otherwise with the reason and the way out — so
|
|
826
|
+
"is it on yet", and "did a conversion quietly not take", are both one command
|
|
827
|
+
rather than a `sqlite3` incantation. Amber is the only trace a swallowed refusal
|
|
828
|
+
leaves, deliberately: the alternative was an event row written from inside
|
|
829
|
+
`openDb`, which would mean a write at open on the path that exists to avoid one.
|
|
830
|
+
|
|
831
|
+
**Three things a WAL store cannot do that a DELETE store could.** None is a
|
|
832
|
+
reason to go back; all three are worth knowing before they are met.
|
|
833
|
+
|
|
834
|
+
1. **Read-only media.** With the sidecars absent and the directory not writable,
|
|
835
|
+
an instrument open of a WAL store fails `SQLITE_READONLY_DIRECTORY` and a
|
|
836
|
+
read-only one fails `SQLITE_CANTOPEN`; a DELETE store reads its rows in both.
|
|
837
|
+
The copies the owner actually takes are safe: `counterparts backup` and
|
|
838
|
+
`export` go through `VACUUM INTO`, whose output is always a plain DELETE-mode
|
|
839
|
+
database, so a snapshot is readable anywhere, on any medium, by any build. It
|
|
840
|
+
is the LIVE directory, copied as it stands onto read-only media, that refuses.
|
|
841
|
+
2. **The database file on its own is no longer the database.** *(Written as
|
|
842
|
+
`operational.sqlite`, which is what it was called until the floor renamed it
|
|
843
|
+
`counterparts.sqlite` two days later — owner ruling 5.)* A copy of the
|
|
844
|
+
file alone opens read-write and is *silently short* by everything committed
|
|
845
|
+
since the last checkpoint (it refuses `SQLITE_CANTOPEN` read-only, which is
|
|
846
|
+
the honest half). The supported copies are `counterparts backup`, `export`,
|
|
847
|
+
and a copy of the whole directory INCLUDING the sidecars. Deleting a `-wal`
|
|
848
|
+
deletes the memories inside it — a store went from 20 rows to "no such table"
|
|
849
|
+
that way in review.
|
|
850
|
+
3. **`sqlite3 "file:…?immutable=1"` now reads a short database.** `immutable=1`
|
|
851
|
+
promises SQLite the file cannot change, and SQLite keeps its side by ignoring
|
|
852
|
+
the `-wal` entirely — so the read returns the store as of the last checkpoint,
|
|
853
|
+
with no error. Plain `sqlite3 -readonly "<path>"` reads the `-wal` and is
|
|
854
|
+
correct. A fabricated number is what scar §2.4 is about, and this one arrives
|
|
855
|
+
through a diagnostic recipe.
|
|
856
|
+
|
|
857
|
+
**Filesystems.** WAL needs real shared-memory `mmap` between processes, so a
|
|
858
|
+
network mount (NFS, SMB) is out: either the conversion is silently refused and
|
|
859
|
+
the store runs in DELETE forever, or the header takes and every later open fails
|
|
860
|
+
`SQLITE_IOERR_SHMOPEN`. A synced folder (iCloud, Dropbox) is an ordinary local
|
|
861
|
+
filesystem and works, but the sync client now has three files it must capture at
|
|
862
|
+
one instant and will not — a store in one is a worse idea after this than before
|
|
863
|
+
it. `counterparts doctor` reports the mode, which is where a silent refusal shows.
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
**The byte-identity suites keep their teeth.** Five of them hash a store
|
|
867
|
+
directory and mean "nothing wrote": the dashboard's, the probe's (scar E7),
|
|
868
|
+
`encode`'s gated chunk, the parallel run's input manifest, `verify`'s census.
|
|
869
|
+
Under WAL a commit lands in the `-wal` until a checkpoint moves it into the file,
|
|
870
|
+
so they hash the `-wal` WITH the database and skip only the `-shm`, which every
|
|
871
|
+
connection writes read-marks into (`isDatabaseSidecar`, `paths.ts`). All five are
|
|
872
|
+
green with the `-wal` in the hash — an instrument writes nothing there either.
|
|
873
|
+
|
|
874
|
+
## The walking read and `StoredMemory.confidential` (2026-09-18)
|
|
875
|
+
|
|
876
|
+
Consumers outside this module read prose by PATH —
|
|
877
|
+
`readProseFile(store.absolutePath(row.prose_path), id)` in `schemas/index.ts`,
|
|
878
|
+
`cli/commands.ts`, `dashboard/`. That is the last reason anything above the store
|
|
879
|
+
knows there is a filesystem under it, and the bodies-in-rows work cannot start
|
|
880
|
+
while it is true. Two additions took them off it, and both are about a gate.
|
|
881
|
+
|
|
882
|
+
**The walking read is an exemption, not a convenience.** `Store.read` fires
|
|
883
|
+
`store.archived.read` (contract §5 G13) and refuses a denied id. The walking
|
|
884
|
+
callers wanted neither, which is why they went round the store in the first
|
|
885
|
+
place. Both exemptions had to be kept exactly:
|
|
886
|
+
|
|
887
|
+
- *The event.* `Schemas.load` scans every schema row at every open, so routing it
|
|
888
|
+
through `read` would file one archived-read per archived schema row per session
|
|
889
|
+
and invert what the event means. It answers "did anyone look at archived
|
|
890
|
+
CONTENT", and an index build is a look at the address.
|
|
891
|
+
- *The deny-list, which is the one that bit.* The first draft used `requireRow`,
|
|
892
|
+
which refuses a denied id — and a `dark`-stage removal marks the id while
|
|
893
|
+
leaving the row and the file until the chase. `Counterpart.open` then threw on
|
|
894
|
+
every subsequent session (`test/dashboard.test.ts`, "a protected element
|
|
895
|
+
removed since stops resolving", caught it). So the quiet read asks the
|
|
896
|
+
deny-list nothing, exactly as the direct file reads did; the refusal belongs
|
|
897
|
+
where the OWNER is answered — `read`, `resolve`, `readVersion` and the render
|
|
898
|
+
seams. It is a hole either way, but it is now one hole with a name on it
|
|
899
|
+
instead of five hand-rolled ones spread over two modules.
|
|
900
|
+
|
|
901
|
+
**And it is not on `Store`.** The first draft put it on `Store.prototype` beside
|
|
902
|
+
`read`. The adversarial review's objection was structural, not behavioural: no
|
|
903
|
+
live path was worse off, but `Counterpart.store` is public, so the method handed
|
|
904
|
+
every adapter and every future contributor a removal bypass they did not ask for,
|
|
905
|
+
and §4's "owner-initiated removal is unreachable from any model path" stopped
|
|
906
|
+
being true of the store's own surface. So it moved to `walk-seam.ts` — the
|
|
907
|
+
`chaseRemoved` pattern, a deliberate import from a pinned list of two files —
|
|
908
|
+
and the name carries the dangerous half rather than only the quiet one
|
|
909
|
+
(`readProseQuiet` → `readProseWalking`). The same review found the mitigating
|
|
910
|
+
fact that `Schemas.element` still refused a denied id only by *evaluation order*
|
|
911
|
+
(`physicsOf` happens to run after `statement` in the object literal), which is
|
|
912
|
+
luck; the follow-up that makes `schemas/` skip removed rows turns it into a
|
|
913
|
+
check.
|
|
914
|
+
|
|
915
|
+
It takes the caller's own `row` when the caller has one: every walk reads the
|
|
916
|
+
row's columns too, and a second lookup per id measured 54% of a 16,000-row walk
|
|
917
|
+
(650 ms → 990 ms on this machine). That is 3% with the row passed, and it matters
|
|
918
|
+
more once the body IS the row and the file read stops dominating. A row for the
|
|
919
|
+
wrong id is refused by name in the seam itself rather than relying on
|
|
920
|
+
`readProseFile`'s `expectId` check, which the bodies-in-rows work deletes.
|
|
921
|
+
|
|
922
|
+
**`StoredMemory.confidential` is the opposite move.** The confidentiality class
|
|
923
|
+
was a predicate over `doc.meta` that every caller re-derived
|
|
924
|
+
(`recall/activate.ts#isConfidential`). It is a gate, and a gate that parses JSON
|
|
925
|
+
at every call site is a gate that will one day fail open — so the truth table is
|
|
926
|
+
`confidentialByMeta` here, `read` carries the answer, and `isConfidential` is a
|
|
927
|
+
thin door for callers holding a bare `ProseDoc` (`dashboard/web/reveal.ts`,
|
|
928
|
+
`mcp/deliberate.ts`). It reads `meta` today and a column later; nothing above
|
|
929
|
+
notices. The table is odd in two places and both are preserved on purpose, with a
|
|
930
|
+
test per value: the class comparison is case-sensitive and untrimmed (`"OPEN"`
|
|
931
|
+
and `" open"` are confidential), and `confidential` is checked with `=== true`
|
|
932
|
+
(`1` and `"true"` are not).
|
|
933
|
+
|
|
934
|
+
## 2026-09-20 — the floor: the memory IS the row (schema v6)
|
|
935
|
+
|
|
936
|
+
*F5. Sections 1, 2 and 5 above described the floor this replaced and were deleted
|
|
937
|
+
by F8; 3, 6 and the 2026-09-05 self-contained note were rewritten in place, each
|
|
938
|
+
saying what it used to say. What follows is what this build learned, with the
|
|
939
|
+
measurements.*
|
|
940
|
+
|
|
941
|
+
**What moved.** `memories` gained `title`, `body`, `meta` and `confidential`;
|
|
942
|
+
`versions` gained `title`, `body`, `meta` and the two provenance dates; both
|
|
943
|
+
path columns are gone, and with them `prose/`, `versions/`, `tmp/`,
|
|
944
|
+
`stored.*`, the placement rules, the census and ~1,000 lines of code. `ProseDoc`
|
|
945
|
+
is unchanged, which is the seam that held: `physics/`, `recall/`, `associate/`,
|
|
946
|
+
`prospective/`, `encode/`, most of `sleep/` and all of S1's self page never
|
|
947
|
+
learned the floor moved, and S1's 78 tests passed on v6 without an edit.
|
|
948
|
+
|
|
949
|
+
**The refusal keys on FILENAMES, not on the schema version, and that was a
|
|
950
|
+
correction.** The first design read `meta.schemaVersion` out of the old database
|
|
951
|
+
and refused below 6. Two things are wrong with it. The rename to
|
|
952
|
+
`counterparts.sqlite` (ruling 5) means a v5 directory has no file at that path,
|
|
953
|
+
so `fresh` would have read true, `openOperational` would have MINTED a blank v6
|
|
954
|
+
store beside `operational.sqlite`, and the refusal would have arrived from
|
|
955
|
+
`assertLayout` — as `LAYOUT_UNCLASSIFIED`, after the damage, naming the wrong
|
|
956
|
+
thing. And since F1 the live store is in WAL: an open-and-close to read the
|
|
957
|
+
version can checkpoint and delete its `-wal`, so the act of asking would move the
|
|
958
|
+
bytes of the store the refusal exists to leave untouched. `PRE_ROWS_MARKERS` is
|
|
959
|
+
`operational.sqlite`, `prose`, `versions` — all three, because a store whose
|
|
960
|
+
database was moved by hand still holds every one of its words in files, and
|
|
961
|
+
minting a blank store on top of them would bury the only copy.
|
|
962
|
+
|
|
963
|
+
**`ADDED_COLUMNS` is empty, and that is the second lock.** `openOperational`
|
|
964
|
+
migrates anything below `SCHEMA_VERSION` by adding whatever is listed there. The
|
|
965
|
+
constructor's refusal makes a pre-rows store unreachable; the empty list is what
|
|
966
|
+
survives somebody relaxing the constructor. `test/store.test.ts` asserts both the
|
|
967
|
+
emptiness and that no entry may ever name a v6 column.
|
|
968
|
+
|
|
969
|
+
**`OBSERVER_READ_FLOOR` is the version itself.** v5 earned a floor below it
|
|
970
|
+
because its only change was a spelling every v5 reader resolved both ways. v6
|
|
971
|
+
cannot: a v6 instrument on a v5 store would report an EMPTY store rather than an
|
|
972
|
+
unreadable one, which is worse than refusing because it looks like an answer.
|
|
973
|
+
|
|
974
|
+
**The removal leaves its words in the store in TWO ways, and chases both.**
|
|
975
|
+
|
|
976
|
+
*The write-ahead log.* Measured 2026-09-20 on a store with 200 filler rows:
|
|
977
|
+
right after a chase the doomed text is in `counterparts.sqlite-wal`, and one
|
|
978
|
+
`wal_checkpoint(TRUNCATE)` clears it. Box 3 is in WAL too and holds the same
|
|
979
|
+
words as `doc_tokens` rows, so both databases are checkpointed.
|
|
980
|
+
|
|
981
|
+
*Freed pages, which is the harder one and which I got wrong first.* An earlier
|
|
982
|
+
version of this note said the checkpoint was sufficient and no VACUUM was
|
|
983
|
+
needed. **That was wrong**, and the third adversarial review caught it
|
|
984
|
+
(NEW-MAJOR-1). Blanking a body long enough to take OVERFLOW pages leaves whole
|
|
985
|
+
pages on the freelist still holding the words; `secure_delete` is 2 (FAST) by
|
|
986
|
+
default, which zeroes only the slack of a page being REWRITTEN, never a whole
|
|
987
|
+
freed page. My test passed because its marker sat at the START of the body —
|
|
988
|
+
the page holding the start of an overflow chain gets reused, the middle and the
|
|
989
|
+
end do not. With marks at the start, middle and end of a ~40 KB body the residue
|
|
990
|
+
is deterministic 5/5, in `counterparts.sqlite` itself, in a page no row points
|
|
991
|
+
at, while the report said `unchased: nothing`.
|
|
992
|
+
|
|
993
|
+
A second checkpoint does not help: the checkpoint is what MATERIALISES those
|
|
994
|
+
stale pages into the main file. `VACUUM` rebuilds the file from live pages
|
|
995
|
+
alone — and in WAL mode a VACUUM writes to the log, so it must be VACUUM **then**
|
|
996
|
+
checkpoint, which is why a VACUUM alone also reads as a no-op.
|
|
997
|
+
|
|
998
|
+
*Why VACUUM and not `secure_delete = ON` for the chase's connection*, which is
|
|
999
|
+
cheaper and was the obvious candidate: it measured clean on some shapes and left
|
|
1000
|
+
the middle and end marks on others, because it only zeroes what THAT transaction
|
|
1001
|
+
frees — a page freed by a revision months ago is not its business. VACUUM is the
|
|
1002
|
+
one remedy that clears residue whatever freed the page and whenever, which is
|
|
1003
|
+
what "removed means gone" has to mean. Cost, measured on a 17,000-memory store:
|
|
1004
|
+
**VACUUM 23 ms** on a 9.3 MB box 2 and **58 ms** on a 16.6 MB box 3, checkpoint
|
|
1005
|
+
under a millisecond. Removal is a rare, deliberate owner operation.
|
|
1006
|
+
|
|
1007
|
+
*What never carried it:* `backup` and `export` are `VACUUM INTO`, which copies
|
|
1008
|
+
live pages only — measured clean even with the source in the residue state, and
|
|
1009
|
+
the rotating snapshot takes the same route (`method: vacuum-into`), so no
|
|
1010
|
+
snapshot ever inherited a removed memory's words. **Snapshots taken BEFORE a
|
|
1011
|
+
removal are a different matter and contain the memory properly**; nothing here
|
|
1012
|
+
reaches into them, and the removal report does not pretend to.
|
|
1013
|
+
|
|
1014
|
+
**`content_hash`'s preimage got weaker, and where it travels is: nowhere.**
|
|
1015
|
+
Scar §2.20 says content-by-reference is only private if the reference cannot be
|
|
1016
|
+
inverted, and a 16-hex SHA-256 prefix of a SHORT, LOW-ENTROPY body is guessable
|
|
1017
|
+
— so the column is now a weaker reference than the whole-document hash it
|
|
1018
|
+
replaced (review B, MINOR-2). It is acceptable because of where it goes, which
|
|
1019
|
+
I traced rather than assumed:
|
|
1020
|
+
|
|
1021
|
+
- the removal record and the tombstone carry **no hash at all** (§16 G9), which
|
|
1022
|
+
is the one place a hash of a removed memory would matter;
|
|
1023
|
+
- `dashboard/web/views.ts` blanks it for confidential rows, and `browse.ts`
|
|
1024
|
+
prints it beside the body the owner is already reading;
|
|
1025
|
+
- `store.put`'s emitted `hash` field rides the store's in-memory ring, is
|
|
1026
|
+
relayed into `Counterpart`'s in-memory ring, and stops there: both are capped
|
|
1027
|
+
arrays, neither is persisted, and **`runOnce` is called with no `onEvent` in
|
|
1028
|
+
production** (`bin/runner.ts#main`) — the only caller that passes one is a
|
|
1029
|
+
test. It reaches no durable row and never leaves the machine.
|
|
1030
|
+
|
|
1031
|
+
Nothing joins on it either: `sleep/dedup.ts` hashes the body itself rather than
|
|
1032
|
+
reading the column, and `remember/`'s content-idempotency ledger hashes
|
|
1033
|
+
normalized content and never reads it. If it ever starts riding telemetry that
|
|
1034
|
+
lands on disk, this is the note that says to look again.
|
|
1035
|
+
|
|
1036
|
+
**`content_hash` is `hashText(body)` now**, one definition across both tables,
|
|
1037
|
+
where it used to address the whole serialized document. Two consequences worth
|
|
1038
|
+
knowing: two memories differing only in title hash the SAME (which sharpened
|
|
1039
|
+
`sleep/dedup.ts`'s test rather than weakening it — dedup pairs by the
|
|
1040
|
+
interpretation, and the interpretation is what the hash now addresses), and a
|
|
1041
|
+
title-only or meta-only revision no longer moves the hash. Nothing compares this
|
|
1042
|
+
column to a hash computed elsewhere; `origin.spanHash` is the buffer's own hash
|
|
1043
|
+
of a different string.
|
|
1044
|
+
|
|
1045
|
+
**`supersede` holds the words twice**, and `revise` holds them twice for as long
|
|
1046
|
+
as the version lives: the head row keeps its body and the version row carries a
|
|
1047
|
+
copy, where both used to point at one file. Bounded by the 90-day prune (ruling
|
|
1048
|
+
1) — and the prune now deletes the owner's earlier words rather than a note
|
|
1049
|
+
about a file that was never deleted. That is the ruling's real cost, and it is
|
|
1050
|
+
made visible by a test on the self page rather than left as a sentence.
|
|
1051
|
+
|
|
1052
|
+
**Two columns the plan did not ask for.** `versions.learned_on` and
|
|
1053
|
+
`versions.happened_on`. The plan's §1.1 listed `title`, `body`, `meta` and
|
|
1054
|
+
`content_hash`; the CODE disagreed, because `revise({learnedOn})` travels the
|
|
1055
|
+
same door as a body change precisely so a corrected date keeps its prior version
|
|
1056
|
+
(`index.ts#revise`, and the comment there predates the floor). Taking the dates
|
|
1057
|
+
from the LIVE row instead would have silently rewritten every version behind a
|
|
1058
|
+
correction. A version doc takes `type` and `bornDay` from the head row, because
|
|
1059
|
+
neither can be revised.
|
|
1060
|
+
|
|
1061
|
+
**The unreadable state has a name, and it needed one.** `body = ''` with
|
|
1062
|
+
`content_hash = ''` is a TOMBSTONE — the owner's removal — and `body = ''` beside
|
|
1063
|
+
a real hash is `MEMORY_BODY_MISSING`, a row whose words went missing underneath
|
|
1064
|
+
the store. No write path produces the second: `put` and `revise` both refuse an
|
|
1065
|
+
empty body (`revise` did not, and `patch.body ?? prior.body` accepted `""`
|
|
1066
|
+
happily — fixed here). The pair is what lets `Schemas.load` skip a removed schema
|
|
1067
|
+
row and keep the session alive (#139) while still standing the session down on a
|
|
1068
|
+
store that lost a memory's words.
|