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,770 @@
|
|
|
1
|
+
# `sleep/` — implementation notes
|
|
2
|
+
|
|
3
|
+
*Where the CONTRACT is silent, contradicts itself, or was overruled by a later
|
|
4
|
+
ruling, this file says what was decided and why. Constitution line 13: decisions
|
|
5
|
+
are defaults. Every one of these is revisable; none of them is hidden.*
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Phase order: `prune` before `dedup`
|
|
10
|
+
|
|
11
|
+
The contract fixes three consequences (§3 G5) and leaves the rest of the ordering
|
|
12
|
+
open; the build brief fixes the full list, and this module implements it:
|
|
13
|
+
|
|
14
|
+
clock → decay → consolidate → prune → dedup → versions → briefing
|
|
15
|
+
|
|
16
|
+
**The tension worth recording:** a merge credits `uses` on the ORIGINAL, which
|
|
17
|
+
raises `base`, which raises `strength`. Running dedup FIRST would therefore
|
|
18
|
+
rescue a floor memory whose duplicate was about to vouch for it. Running prune
|
|
19
|
+
first — as here — means a memory can be archived at the floor on the same cycle
|
|
20
|
+
that a near-duplicate would have credited it.
|
|
21
|
+
|
|
22
|
+
In practice the window is narrow: prune requires `D_FLOOR_DAYS` (90) of dwell and
|
|
23
|
+
strength under `PHI_PRUNE` (0.02), and one `usesDelta: 1` is worth `REP_PER_USE`
|
|
24
|
+
(0.12) of repetition credit — enough to matter only for a `wRep > 0` kind that
|
|
25
|
+
has sat untouched for a quarter. It is also RECOVERABLE, because the prune is
|
|
26
|
+
archival: nothing was lost, an id still resolves, and a future dedup pass sees an
|
|
27
|
+
archived original and leaves it alone.
|
|
28
|
+
|
|
29
|
+
Reverse the order if replay shows the window is real. It is one line.
|
|
30
|
+
|
|
31
|
+
## 2. The floor prune ARCHIVES — CONTRACT open question 1, resolved
|
|
32
|
+
|
|
33
|
+
`CONTRACT.md` §4 says the floor prune "is the one place the system deletes" and
|
|
34
|
+
§7 OQ1 flags it as unresolved, against v1's §11 G6 which says the opposite in as
|
|
35
|
+
many words ("fading is not deletion... human forgetting deletes; this only
|
|
36
|
+
fades").
|
|
37
|
+
|
|
38
|
+
**Resolved toward archival**, and the store settles it structurally rather than
|
|
39
|
+
by preference: `store/` exports no `delete`, `remove`, `unlink`, or `rm`, for
|
|
40
|
+
prose or anything else — there is no verb to call. A pruned memory keeps its
|
|
41
|
+
prose file, keeps its id, stays resolvable, and carries
|
|
42
|
+
`archived_reason = "pruned"`.
|
|
43
|
+
|
|
44
|
+
What is NOT lost by choosing archival: the exit is still countable (scar §2.17 —
|
|
45
|
+
a band with no exit is a defect), the prune record is still written, and the
|
|
46
|
+
memory still stops competing for ranking. What IS paid: disk, and the honest
|
|
47
|
+
version of constitution line 3 is now "forget the trials" in the sense of
|
|
48
|
+
*access*, not *bytes*. If the disk bill is ever the argument, the answer is an
|
|
49
|
+
owner operation on the structurally-distinct removal path (`owner-op-seam.ts`),
|
|
50
|
+
not a delete verb inside the librarian.
|
|
51
|
+
|
|
52
|
+
`CONTRACT.md` §2's named deviation (b) — "this module deletes, loudly and on
|
|
53
|
+
physics' verdict alone" — should be re-read as "this module retires, loudly and
|
|
54
|
+
on physics' verdict alone" when the contract is next revised.
|
|
55
|
+
|
|
56
|
+
## 3. Observer: a full read-only REPORT, and no spawn
|
|
57
|
+
|
|
58
|
+
The contract (§5 G10) says an observer session **spawns no cycle at all**. The
|
|
59
|
+
build brief says an observer **runs the whole cycle as a read-only report**. Both
|
|
60
|
+
are implemented, and they are not the same statement:
|
|
61
|
+
|
|
62
|
+
- `shouldSpawn(store)` returns `{ spawn: false, reason: "observer" }`. That is the
|
|
63
|
+
spawner's question, and its answer is the contract's.
|
|
64
|
+
- `runCycle` on an observer store computes every phase with `ctx.apply === false`
|
|
65
|
+
and returns the full report. That is the dashboard's and the replay scorer's
|
|
66
|
+
path (constitution line 16 wants the workings visible), and it writes nothing.
|
|
67
|
+
|
|
68
|
+
The mechanism matters: an observer does not *attempt* writes and catch the
|
|
69
|
+
store's refusal — it never calls a `WRITE_METHOD` at all. The test asserts zero
|
|
70
|
+
`store.observer.standdown` events alongside a byte-identical data dir, because
|
|
71
|
+
"stood down at the seam" and "never reached the seam" are different claims and
|
|
72
|
+
only the second is what an instrument should be able to make about itself.
|
|
73
|
+
|
|
74
|
+
`ctx.apply` also means the observer report is a REAL report: `changed` carries the
|
|
75
|
+
count the phase WOULD have acted on, while `status` stays `did-not-run` so the two
|
|
76
|
+
can never be confused.
|
|
77
|
+
|
|
78
|
+
**One honest caveat on that number, for `decay` only.** An observer is handed a
|
|
79
|
+
`null` ranking cache — opening the SQLite file would CREATE it, and a created file
|
|
80
|
+
is a mutation. So the calm-day comparison has nothing to compare against, and the
|
|
81
|
+
observer's decay `changed` counts every live row rather than the rows that would
|
|
82
|
+
actually move. Every other phase's observer count is exact. Fixing it needs a
|
|
83
|
+
read-only cache handle that refuses to create its file; it is not worth a second
|
|
84
|
+
code path until a dashboard actually reads that number.
|
|
85
|
+
|
|
86
|
+
## 4. The consolidation criterion is stated here, not imported
|
|
87
|
+
|
|
88
|
+
Physics has no `consolidationEligibility` (INTERFACE-GAPS §5). The rule used:
|
|
89
|
+
|
|
90
|
+
> not already consolidated · not archived · `day > birthDay` · `band(m, d) ===
|
|
91
|
+
> "semantic"` (or already identity)
|
|
92
|
+
|
|
93
|
+
Built only from physics' exports, so it cannot drift from the band definition.
|
|
94
|
+
The two deliberate choices inside it:
|
|
95
|
+
|
|
96
|
+
- **No reinforcement requirement.** Physics protects "a formative one-shot
|
|
97
|
+
consolidates without repetition" with a `max` in `base`; a `reinforcedDays >= 1`
|
|
98
|
+
gate here would repeal it from the outside.
|
|
99
|
+
- **`day > birthDay`.** Sleep consolidates yesterday's experience. Note the
|
|
100
|
+
interaction with the clock: the clock phase runs FIRST, so a memory written
|
|
101
|
+
during the session that just ended is already a day behind by the time this
|
|
102
|
+
phase looks at it, and consolidates on the very next cycle. That is the correct
|
|
103
|
+
brain analog (consolidation happens during the sleep that follows the day) but
|
|
104
|
+
it makes "born today" a narrow category in practice — it catches memories minted
|
|
105
|
+
*during* the cycle's own lived day, not memories minted during the session the
|
|
106
|
+
cycle is closing. Worth a second look when the adapter fixes the boundary's
|
|
107
|
+
exact ordering.
|
|
108
|
+
|
|
109
|
+
## 5. Decay writes the CACHE, and reconciles ONE canonical column
|
|
110
|
+
|
|
111
|
+
The brief is explicit and the contract agrees (§4, owner rescope 1): the daily
|
|
112
|
+
materialize-decay pass is released, and canonical state takes no decay STEP. So:
|
|
113
|
+
|
|
114
|
+
- No `uses`, no `lastUsedDay`, no prose write in the decay phase. Strength lives
|
|
115
|
+
in the ranking cache and nowhere else.
|
|
116
|
+
- v1 materialized decay into canonical files (~1.9K writes/day) and ratified it
|
|
117
|
+
on the grounds that "a memory stating its own current strength is directly
|
|
118
|
+
trustworthy". v2 received that as an open choice with the evidence attached
|
|
119
|
+
(behavioral-spec §11) and declined it: strength is a pure function, so the
|
|
120
|
+
cached number is derived and a replayed day is a no-op **by construction**
|
|
121
|
+
rather than by a per-item stamp.
|
|
122
|
+
|
|
123
|
+
**Amended 2026-09-14 (IMPROVEMENTS U8) — the box-2 `band` column is the band of
|
|
124
|
+
record, and decay keeps it true.** Until this date the column was written by
|
|
125
|
+
`consolidate` on promotion only, on the reasoning that "a crossing is a decision,
|
|
126
|
+
not a decay reading, and the two must not share a writer". That reasoning was
|
|
127
|
+
sound about the CROSSING and wrong about the COLUMN, and the live store showed
|
|
128
|
+
the cost: `ranking` said 1,054 memories were semantic while `memories.band` said
|
|
129
|
+
185 — every one stamped `band_day = 184`, the single day `band.promoted` ever
|
|
130
|
+
fired — and 869 live rows were semantic in the cache and episodic in the table.
|
|
131
|
+
The same decay pass emitted `band.transition` rows for moves the table went on
|
|
132
|
+
denying. Three things settled the ruling:
|
|
133
|
+
|
|
134
|
+
1. **Two readers gate on the column, and the reconciliation can only move it
|
|
135
|
+
toward identity, so neither can lose a row.** The first draft of this note
|
|
136
|
+
said "nothing gates on it", and that was wrong — `store/NOTES.md` now
|
|
137
|
+
enumerates all of them. The two that gate: `revision.ts` routes a declaration
|
|
138
|
+
to the identity arm on `row.band === "identity" || target.promotedIdentity`,
|
|
139
|
+
and `self/identity.ts` lists a removed element as an identity absence on
|
|
140
|
+
`gone.wasPromotedIdentity || gone.band === "identity"` (the band a tombstone
|
|
141
|
+
captured at chase time, `store/owner-op-seam.ts`). Both are ORs with the
|
|
142
|
+
promotion flag, and `band()` answers `identity` **iff** `promotedIdentity`
|
|
143
|
+
(`physics/index.ts`: it is the function's first line, before any arithmetic),
|
|
144
|
+
so on a live row the reconciliation only ever writes the column INTO identity
|
|
145
|
+
— never out of it — and those two gates can only gain rows they should
|
|
146
|
+
already have had. The one path that can put `identity` in the column without
|
|
147
|
+
the flag is migration (`tools/migrate/plan.ts`: a v1 trace above the identity
|
|
148
|
+
gradient cut that v1 itself had retired arrives with `bandOf()` identity and
|
|
149
|
+
`promotedIdentity: false`), and it arrives ARCHIVED, which decay skips; only
|
|
150
|
+
the owner-op `unarchiveMerged` door could bring such a row back into the pass,
|
|
151
|
+
and then the column would be corrected to what the arithmetic says. The rest
|
|
152
|
+
only read: `consolidate` builds physics with `rowToPhysics` and never reads
|
|
153
|
+
`band`; `schemas/` reads it and never writes it (§4 of its CONTRACT, and a
|
|
154
|
+
source scan); `self/identity.ts` also selects `list({ band: "identity" })`,
|
|
155
|
+
and identity is decay-exempt, so that set is byte-identical before and after.
|
|
156
|
+
What DID read the stale column and report it: the `status` MCP tool's
|
|
157
|
+
`byBand`. The CLI census and the dashboard had already routed around the
|
|
158
|
+
column by computing the band themselves and saying so in a comment — a
|
|
159
|
+
workaround is evidence of the bug, not a fix for it.
|
|
160
|
+
2. **A surface that emits a transition must not contradict it.** Constitution 16:
|
|
161
|
+
the system shows its workings. Two stores of the same fact, one of them
|
|
162
|
+
wrong and both of them read, is the shape the parallel run keeps finding.
|
|
163
|
+
3. **It is not v1's churn.** The write fires only when the column disagrees with
|
|
164
|
+
`band(m, d)` — a handful of rows a day once caught up, zero on a replayed day,
|
|
165
|
+
and one catch-up pass for the backlog while the store fits the decay phase's
|
|
166
|
+
budget (`BUDGETS.decay` = 20,000 examined rows; the live store is ~14,000, and
|
|
167
|
+
a larger one clears a budget's worth a day like every other phase). Strength, the number that actually
|
|
168
|
+
moves every day for every row, is still cache-only. (The first catch-up pass
|
|
169
|
+
on a large store is ~900 single-statement `UPDATE`s under `synchronous =
|
|
170
|
+
FULL`; it happens once, inside a boundary that already writes per row.)
|
|
171
|
+
|
|
172
|
+
`consolidate` still writes the column at the identity crossing, and still writes
|
|
173
|
+
it FIRST — the crossing is its decision. Decay now brings every other row to the
|
|
174
|
+
arithmetic. `band_day` therefore means **"the lived day the column was last
|
|
175
|
+
brought to physics"**, which is what it always meant for promotions and now means
|
|
176
|
+
for everything; the crossing's own record is the latched `band.transition` row,
|
|
177
|
+
never this column. `counterparts verify` counts the disagreement
|
|
178
|
+
(`cli/commands.ts#bandOfRecordCensus`) so the invariant is checked rather than
|
|
179
|
+
believed, and `DecayResult.bandsReconciled` reports it per pass.
|
|
180
|
+
|
|
181
|
+
**The skip list is reported, not branched on.** An identity-band memory is not
|
|
182
|
+
skipped by an `if`; `physics.decay()` returns `D = 1` for it and the arithmetic
|
|
183
|
+
does the exempting. The category is still counted, because "how many rows did not
|
|
184
|
+
move, and why" is the question the telemetry exists to answer.
|
|
185
|
+
|
|
186
|
+
**`DECAY_QUANTUM` earns its place.** Without it, exponential decay moves every
|
|
187
|
+
floor memory by ~1e-9 a day and "calm by default" (v1 §11 G8) would be a claim
|
|
188
|
+
instead of a measurement — the cache would rewrite in full every quiet day.
|
|
189
|
+
|
|
190
|
+
## 6. A merge ARCHIVES the duplicate, and that is not optional
|
|
191
|
+
|
|
192
|
+
`physics.dedupVerdict` states the whole effect of a merge as `uses(orig) += 1`
|
|
193
|
+
and says nothing about the duplicate. Leaving it live would make dedup **not
|
|
194
|
+
idempotent**: the next cycle finds the same pair and credits again — a `uses`
|
|
195
|
+
ratchet, and a direct breach of §5 G3. So the duplicate is archived with reason
|
|
196
|
+
`"merged"`. Archival, not deletion, on the same grounds as §2 above; and it feeds
|
|
197
|
+
the created-versus-exited census, which is how a curation path that stops firing
|
|
198
|
+
becomes visible (scar §2.17).
|
|
199
|
+
|
|
200
|
+
## 7. The default dedup candidate source hashes the BODY, not the document
|
|
201
|
+
|
|
202
|
+
`memories.content_hash` addresses the whole serialized prose document — id and
|
|
203
|
+
frontmatter included — so two distinct memories can never share one. It is a
|
|
204
|
+
change detector, not a duplicate detector. The duplicate question is about the
|
|
205
|
+
body, which is the memory. The body hash is computed in memory and never
|
|
206
|
+
recorded: prune records are content-by-reference and carry no hash at all (scar
|
|
207
|
+
§2.20).
|
|
208
|
+
|
|
209
|
+
Embedding-backed candidates arrive INJECTED (`SleepOptions.candidates`), are
|
|
210
|
+
permitted arithmetic rather than a generative call (§4), and are isolated: a
|
|
211
|
+
throw degrades the pass to lexical-only and logs it (scar E1). The lexical pairs
|
|
212
|
+
already found still stand — degradation is partial, not total.
|
|
213
|
+
|
|
214
|
+
## 8. Budget semantics: the marker advances on a truncated phase
|
|
215
|
+
|
|
216
|
+
"A budget is not a debt" (§3, v1 §5 G4). A phase stopped by its budget still
|
|
217
|
+
advances its marker and reports `budgetExhausted` + `skippedForBudget`. The work
|
|
218
|
+
not done is not owed: tomorrow's cycle starts from tomorrow's store, not from a
|
|
219
|
+
backlog. A phase that FAILS is the opposite case — its marker does not advance, so
|
|
220
|
+
the next lived day retries it.
|
|
221
|
+
|
|
222
|
+
**A budget is not a blindfold either — the consolidate cursor, 2026-09-18.** "Not
|
|
223
|
+
owed" was read as "start from the head again", and on a store bigger than the
|
|
224
|
+
budget those are very different sentences. `runConsolidate` walked
|
|
225
|
+
`store.list()` — `ORDER BY id`, every row — from index 0 and stopped at 5,000.
|
|
226
|
+
Measured on the live store the day before
|
|
227
|
+
(`docs/promotion-diagnosis-2026-09-17.md`): 15,292 examinable rows, so the pass
|
|
228
|
+
had never looked past about the 5,300th of them, **10,000+ memories had never once
|
|
229
|
+
been asked whether they consolidate or belong to who the owner is, and under those
|
|
230
|
+
settings never would.** The tell was arithmetic rather than anecdote — of the ten
|
|
231
|
+
most-reinforced semantic rows, the only one inside the window was the only one
|
|
232
|
+
consolidated.
|
|
233
|
+
|
|
234
|
+
The phase now keeps a resume cursor (`markers.ts`, one box-2 meta row per phase,
|
|
235
|
+
`sleep.cursor.<phase>`, beside the completion marker): the marker says WHEN the
|
|
236
|
+
phase last ran, the cursor says WHERE it stopped. It resumes strictly after the
|
|
237
|
+
cursor, wraps to the head when it reaches the end, and visits each id at most once
|
|
238
|
+
per run, so a store of N rows is covered in `ceil(N / budget)` runs. The ordering
|
|
239
|
+
is `list()`'s own, which is why a cursor means anything; "strictly after" is why
|
|
240
|
+
the row it stopped on is not re-read; and a cursor whose row has since gone lands
|
|
241
|
+
on the next id that is still there, out of the comparison rather than a branch of
|
|
242
|
+
its own. The cursor moves only under `ctx.apply`, so an observer's read-only
|
|
243
|
+
report does not move the store's place in the store, and a run killed mid-phase
|
|
244
|
+
re-walks the same stretch — the marker's own bargain.
|
|
245
|
+
|
|
246
|
+
**What the rotation changes for a NEW memory, named rather than left to be
|
|
247
|
+
found.** Ids are random hex, so a memory written today lands anywhere in the
|
|
248
|
+
rotation, not at the end of it. Before, a row in the first budget's worth was
|
|
249
|
+
looked at every night and everything past it never; now every row is looked at,
|
|
250
|
+
and a new one waits up to `ceil(N / budget)` nights for its first look — about
|
|
251
|
+
three on a 15,000-row store at 5,000. Against a consolidate cadence of 3 lived
|
|
252
|
+
days that is a shift of the same order, not a new kind of delay, and the trade is
|
|
253
|
+
"a few nights later for every memory" against "never, for two thirds of them".
|
|
254
|
+
For now that reads as clearly the better side; if the wait on fresh memories is
|
|
255
|
+
ever felt, raising the budget shortens it directly.
|
|
256
|
+
|
|
257
|
+
**Raising the budget was the other option and was NOT taken here.** It is one
|
|
258
|
+
number (`tunables.ts`) against a store that will keep growing; the cursor makes
|
|
259
|
+
the budget mean "per night" rather than "ever", which is what it always read as.
|
|
260
|
+
The two are independent, and the number is still the owner's to raise.
|
|
261
|
+
|
|
262
|
+
**And the durable row now says a phase ran out of road.** `sleep.cycle`'s phase
|
|
263
|
+
entries carry `budgetExhausted` (always) and `skippedForBudget` (only where a
|
|
264
|
+
phase left rows behind), and doctor's Sleep line names them — *"consolidate ran
|
|
265
|
+
out of budget (N rows not reached this run)"*, without a severity, because with a
|
|
266
|
+
cursor a big store is MEANT to take several nights over a pass. The report has
|
|
267
|
+
carried both numbers since the budgets existed and nothing durable copied them:
|
|
268
|
+
the truncation was not wrong, it was unsayable, which is scar §2.4's shape and
|
|
269
|
+
what hid this for two weeks.
|
|
270
|
+
|
|
271
|
+
**The other budgeted phases were left alone, on purpose.** `decay` (20,000) and
|
|
272
|
+
`prune` (1,000) have the identical start-from-index-0 shape over `store.list()`;
|
|
273
|
+
neither is truncating on this store today, and a cursor changes what they see, so
|
|
274
|
+
that is a decision to take with a measurement rather than by symmetry. `dedup`
|
|
275
|
+
(1,000) iterates candidate PAIRS, not rows, and the pair list is rebuilt each run
|
|
276
|
+
from the grouping — a row cursor would not even be the right key. `log` (5,000)
|
|
277
|
+
deletes oldest-first, so the work it does is consumed and the next pass naturally
|
|
278
|
+
continues; it needs no cursor at all.
|
|
279
|
+
|
|
280
|
+
The three-way vocabulary that makes this legible (§5 G6, scar §2.4):
|
|
281
|
+
|
|
282
|
+
| status | reason | means |
|
|
283
|
+
|---|---|---|
|
|
284
|
+
| `ran` | `completed` | it ran and changed something |
|
|
285
|
+
| `ran-nothing-found` | `nothing-to-do` | it ran and there was nothing to do |
|
|
286
|
+
| `did-not-run` | `already-done-today` / `not-due-this-cadence` / `observer-report` / `no-render-fn` | it never ran, and here is which |
|
|
287
|
+
| `failed` | `failed` (+ `error` code) | it threw; the marker stands still |
|
|
288
|
+
|
|
289
|
+
**`changed` is "rows this phase acted on", and the band reconciliation is one of
|
|
290
|
+
them (U8, amended 2026-09-14).** The first cut counted the reconciliation in
|
|
291
|
+
`DecayResult.bandsReconciled` only, and nothing durable read it: on the exact
|
|
292
|
+
live shape — the column wrong and the ranking cache already right, so no row's
|
|
293
|
+
cache "moved" — the pass issued 869 `UPDATE`s and then filed itself
|
|
294
|
+
`ran-nothing-found` / `nothing-to-do`, and the `sleep.decay.materialized` ring
|
|
295
|
+
event was skipped because no strength row was written. A row is now counted once,
|
|
296
|
+
in whichever category is true (`changed` when its column was reconciled,
|
|
297
|
+
`skipped.unchanged` when nothing about it moved at all), the count rides the
|
|
298
|
+
phase outcome as `reconciled` onto the `PhaseReport` and the durable
|
|
299
|
+
`sleep.cycle` row's decay entry, and the ring event fires when either half did
|
|
300
|
+
work. The count is taken under OBSERVER too — only the write is gated on
|
|
301
|
+
`PhaseCtx.apply`, which is what that flag's contract promises and what
|
|
302
|
+
`sleep.observer.report`'s `would` rests on.
|
|
303
|
+
|
|
304
|
+
## 9. `CycleKilled` — why a crash needs its own class
|
|
305
|
+
|
|
306
|
+
Degrade-don't-abort would otherwise swallow the very thing the crash test is
|
|
307
|
+
trying to prove: a test throwing from `onStep` would be caught, recorded as a
|
|
308
|
+
failed phase, and the cycle would sail on and advance every later marker. So
|
|
309
|
+
`CycleKilled` is the one error `runCycle` rethrows untouched. It is not
|
|
310
|
+
test-only scaffolding — a cooperative watchdog abort should throw it too, and
|
|
311
|
+
markers stay honest either way.
|
|
312
|
+
|
|
313
|
+
`onStep` itself is ordinary per-step telemetry. That a test can weaponize it is
|
|
314
|
+
the point: the crash seam is the same seam the adapter watches through.
|
|
315
|
+
|
|
316
|
+
## 10. Records are keyed by memory id, never by day or sequence
|
|
317
|
+
|
|
318
|
+
`sleep.pruned.<id>`, `sleep.promoted.<id>`, `sleep.merged.<id>`. Ids are never
|
|
319
|
+
reused (`store/` G2), so a replayed day rewrites the identical key with identical
|
|
320
|
+
content instead of appending a second line. That is what makes the meta-row
|
|
321
|
+
workaround (INTERFACE-GAPS §3) idempotent enough to satisfy §5 G3 while the real
|
|
322
|
+
table is missing.
|
|
323
|
+
|
|
324
|
+
## 11. What is measured on full membership
|
|
325
|
+
|
|
326
|
+
CONTRACT §3: *over-budget is measured at full membership, not on the rendered
|
|
327
|
+
output — a renderer that demotes until it fits by construction never reports
|
|
328
|
+
being over budget.* That detector lives in `self/`, which owns the render and its
|
|
329
|
+
lanes. `sleep/` reports its OWN budgets the same way — `skippedForBudget` counts
|
|
330
|
+
candidates never reached, not items dropped from an output — so the same honesty
|
|
331
|
+
applies on this side of the seam.
|
|
332
|
+
|
|
333
|
+
## 12. Dedup ate a revision's successor — 2026-09-04
|
|
334
|
+
|
|
335
|
+
**Symptom.** The demo seeder built the first store that ever crossed the pressure
|
|
336
|
+
bar, and the `stories` view rendered the crossing as a disappearance:
|
|
337
|
+
|
|
338
|
+
it now says "The migration Teodoro Whitlock merged cannot be rev…" [sch_…, archived: merged]
|
|
339
|
+
day 29 … REVISED, becoming "…" [sch_…, archived: merged]
|
|
340
|
+
|
|
341
|
+
The revised belief was superseded correctly and then, the same evening, archived
|
|
342
|
+
out of existence as a belief: `schemas.beliefs(entity)` empty, the successor gone
|
|
343
|
+
from every slice. Constitution 7 — "revisions keep their history; nothing
|
|
344
|
+
bulk-wipes silently" — broken by a phase doing exactly what it was told.
|
|
345
|
+
|
|
346
|
+
**Cause.** `schemas/index.ts#supersedeElement` mints the successor with
|
|
347
|
+
`input.statement ?? store.readProse(challengerId).body`. That is the design: the
|
|
348
|
+
statement that won the argument IS the new belief (§5.6), so successor and
|
|
349
|
+
challenger are byte-identical BY CONSTRUCTION. `contentHashCandidates` groups on
|
|
350
|
+
the body, the tie-break sorts by birth day and then by id — both born the same
|
|
351
|
+
lived day, and `mem_` sorts before `sch_` — so the successor is always the
|
|
352
|
+
candidate and the challenger always the original. `dedupVerdict`'s existing
|
|
353
|
+
refusal, `declared-revision-never-merged`, compares the CANDIDATE's `updates:`
|
|
354
|
+
declaration against the original's id; the successor declares nothing, and the
|
|
355
|
+
challenger's declaration names the PREDECESSOR, which is archived and out of the
|
|
356
|
+
live set. Nothing in the pass could see what the pair was. Both arms of the
|
|
357
|
+
dispatch fire it: the belief path and the current-state replacement, plus
|
|
358
|
+
`revision.ts`'s identity arm, which supersedes the same way.
|
|
359
|
+
|
|
360
|
+
**Fix.** A second named refusal rather than a change to what a successor says —
|
|
361
|
+
the contract wants the challenger's statement verbatim, so the body is not
|
|
362
|
+
negotiable. `physics.dedupVerdict` gains `revisionSuccessorPair` and the verdict
|
|
363
|
+
`revision-successor-never-merged`, checked before hash and before cosine (the
|
|
364
|
+
hash is exactly what is guaranteed to match). `dedup.ts` supplies the fact from
|
|
365
|
+
two columns — `source: "accommodation"`, written at exactly the two supersede
|
|
366
|
+
sites that mint with lineage, and `origin_ref`, the challenger.
|
|
367
|
+
|
|
368
|
+
The rule as shipped is **"an accommodation row is never the LOSING candidate of a
|
|
369
|
+
same-hash merge"**, not merely the pair relation. The pair relation alone was the
|
|
370
|
+
first draft and it is not enough — see the two doors below, both closed by the
|
|
371
|
+
wider clause, both regression-tested. The wider clause is sound rather than a
|
|
372
|
+
blanket exemption: a successor's body IS its challenger's body by construction
|
|
373
|
+
(`schemas/index.ts:946`), so every same-hash group a successor belongs to is that
|
|
374
|
+
challenger plus ordinary twins of the same sentence, and none of those is the
|
|
375
|
+
thing the revision produced. The COSINE path is deliberately untouched — a merely
|
|
376
|
+
similar row is an ordinary near-duplicate question, and the argument above does
|
|
377
|
+
not hold for it. The guard is otherwise narrow: two ordinary memories with one
|
|
378
|
+
body still merge, and a test says so.
|
|
379
|
+
|
|
380
|
+
**The two doors the pair relation left open**, both found by the adversarial
|
|
381
|
+
review, both closed here:
|
|
382
|
+
|
|
383
|
+
1. **A twin born EARLIER takes the original's seat.** An ordinary memory that
|
|
384
|
+
already says what the challenger is about to say becomes the group's original.
|
|
385
|
+
The challenger and the successor then both pair against the TWIN, the relation
|
|
386
|
+
reads false against it, and **both archive** — so the element is left with no
|
|
387
|
+
live version at all: `currentState(entity) === []`. Strictly worse than the
|
|
388
|
+
finding this note opened with, which at least left the challenger standing.
|
|
389
|
+
2. **Two challengers with one body, revising two elements on one day.** `sb`
|
|
390
|
+
pairs against `ca` rather than against its own `cb`; the relation is false;
|
|
391
|
+
`cb` and `sb` both archive and element *b* silently loses its revision while
|
|
392
|
+
element *a* keeps its own.
|
|
393
|
+
|
|
394
|
+
The trigger for both is ordinary — the same sentence noted twice — not exotic.
|
|
395
|
+
|
|
396
|
+
**What the fix deliberately does not protect in case 1: the challenger.** It is a
|
|
397
|
+
plain memory saying what a plain memory already said, so it merges into the twin
|
|
398
|
+
under the ordinary rule and credits it. Nothing about the revision is lost: the
|
|
399
|
+
successor holds the words, the element holds the successor, and `origin_ref`
|
|
400
|
+
still names the challenger, whose prose and id survive the archive.
|
|
401
|
+
|
|
402
|
+
Same shape as the journal finding a day earlier (CONTRACT §5 G15), and worth
|
|
403
|
+
naming as a class: **phases that walk "every row" were written when two identical
|
|
404
|
+
bodies could only mean a duplicate.** Three constructions now make identical
|
|
405
|
+
bodies on purpose — an episode and the memory ingested from it; a revised
|
|
406
|
+
belief's successor and its challenger; a replaced now-fact's successor and its
|
|
407
|
+
challenger — and each needed the pass to be told what it was looking at.
|
|
408
|
+
|
|
409
|
+
**What this fix deliberately did NOT do.** CONTRACT §5 G7 already promises that
|
|
410
|
+
nothing "in a live revision chain" is decayed, merged, or pruned, and a fresh
|
|
411
|
+
successor is the head of one — so the shorter fix looks like handing dedup
|
|
412
|
+
`prune.ts#inLiveRevisionChain`. It would not have worked as that predicate
|
|
413
|
+
stands: a successor has no forwarding address, no standing pressure (the seed
|
|
414
|
+
resets it) and no version rows of its own, so the predicate reads `false` for
|
|
415
|
+
exactly the row this bug destroys, and dedup never consulted it in any case.
|
|
416
|
+
Widening the predicate to "is the head of a chain still inside `H`" and reading
|
|
417
|
+
it in dedup would be the general close of G7's wording; G9b's own rule reaches
|
|
418
|
+
every case the finding and the review produced, so G7's paragraph in the CONTRACT
|
|
419
|
+
now states what the predicate actually enforces rather than more.
|
|
420
|
+
|
|
421
|
+
**CLOSED 2026-09-05 — probe H (adversarial review, 2026-09-04).** The paragraph
|
|
422
|
+
below is kept as written, because it is the filing that led to §14. Read it as
|
|
423
|
+
history: the answer it asks for — "whether a `type: "schema"` row should ever be
|
|
424
|
+
a dedup candidate at all" — is yes-it-should-not, and §14 is the fix.
|
|
425
|
+
An element and an ordinary memory can collide with **no revision anywhere**: an
|
|
426
|
+
`addBelief` whose statement is X and a memory whose body is X, born the same
|
|
427
|
+
lived day. No accommodation row is involved, so G9b does not apply; the tie-break
|
|
428
|
+
puts `mem_` before `sch_` and the belief is archived `merged` into the memory.
|
|
429
|
+
Kin of the migration case: migrated ELEMENTS were minted at the import day while
|
|
430
|
+
migrated MEMORIES kept their v1 `birthDay`, so on the live store a migrated
|
|
431
|
+
belief colliding with a memory body would already have lost — the memory is older
|
|
432
|
+
on every such pair. Not chased here (constitution 15: named, not built), because
|
|
433
|
+
the honest fix is the wider question of whether a `type: "schema"` row should
|
|
434
|
+
ever be a dedup candidate at all — the same shape as G15's journal answer.
|
|
435
|
+
|
|
436
|
+
**The owner's read-only check, for both this and the finding above:** look for
|
|
437
|
+
`memory.merged` events whose `candidateId` starts with `sch_`. That one query
|
|
438
|
+
answers "has an element ever been archived as a duplicate on this store", needs
|
|
439
|
+
no writes, and does not depend on any claim made in this file.
|
|
440
|
+
|
|
441
|
+
**What changes on a live store.** Only stores where a dedup pass runs while a
|
|
442
|
+
revision's successor and its challenger are both live — in practice any cycle
|
|
443
|
+
after a crossing, not merely the same evening, since the pair stays live and
|
|
444
|
+
identical until something merges it. Nothing is repaired retroactively: a
|
|
445
|
+
successor already archived `merged` stays archived (its prose and id survive, and
|
|
446
|
+
its merge record names the original). Stores that never revise are untouched;
|
|
447
|
+
genuine duplicates merge exactly as before.
|
|
448
|
+
|
|
449
|
+
**UNVERIFIED, and do not repeat it as fact:** "the owner's live store has had 1
|
|
450
|
+
revision declaration with 0 effect — zero `superseded_by`, zero
|
|
451
|
+
`revision.pressure`" is a day-1 reading that master's day-2 watch list still owes
|
|
452
|
+
a recount of, and this session cannot open that store. It is also the weakest
|
|
453
|
+
possible claim to lean on here, because the CURRENT-STATE arm supersedes on ONE
|
|
454
|
+
declaration with no bar to climb (PR #22 is live), so a successor may already
|
|
455
|
+
exist without any pressure event to show for it. The read-only check that settles
|
|
456
|
+
it: `memory.merged` events whose `candidateId` starts with `sch_`.
|
|
457
|
+
|
|
458
|
+
## 13. Nothing sweeps the events table — the missing `pruneEvents` caller
|
|
459
|
+
|
|
460
|
+
**RESOLVED 2026-09-05, the same day, by owner ruling ("wire it into sleep") —
|
|
461
|
+
§15 records the two decisions this section asked for and what was built. The
|
|
462
|
+
filing is kept as written, because it is the argument §15 answers.**
|
|
463
|
+
|
|
464
|
+
**Filed 2026-09-05, during replay §2a's review. Not fixed here, deliberately.**
|
|
465
|
+
|
|
466
|
+
`Store.pruneEvents()` exists, is documented as bounded retention ("logs are
|
|
467
|
+
telemetry, not canonical memory — the one named exception to
|
|
468
|
+
no-silent-destruction"; the comment cited `CLAUDE.md` for that, wrongly — the
|
|
469
|
+
source is v1's spec, `docs/harvest/behavioral-spec.md` #17, and both citations
|
|
470
|
+
were fixed with §15), deletes `WHERE day < livedDay - retentionDays AND
|
|
471
|
+
dedup_key IS NULL`, has a `PruneReport`, emits `store.events.pruned`, and is
|
|
472
|
+
covered by `test/seams.test.ts`. **It has no caller anywhere in `src/`.** The
|
|
473
|
+
only invocation in the repo is that test's.
|
|
474
|
+
|
|
475
|
+
So `DEFAULT_RETENTION_DAYS = 90` is a number the log is *eligible* for and never
|
|
476
|
+
subject to. Every unlatched row ever written is still there — `recall.decision`
|
|
477
|
+
(one per turn, and replay INTERFACE-GAPS §7 explicitly reasoned "it ages out on
|
|
478
|
+
the log's existing window" when choosing not to latch it), the adapter rows, and
|
|
479
|
+
now `gate.deposit` (one per authored deposit, same reasoning, same gap). None of
|
|
480
|
+
those choices is *wrong*; the sentence they each leaned on is not true yet.
|
|
481
|
+
|
|
482
|
+
**What is owed, and the two decisions it needs.**
|
|
483
|
+
|
|
484
|
+
1. **Which phase calls it.** `prune` is the obvious name and the wrong one — it
|
|
485
|
+
is the memory floor, and a phase that both forgets memories and truncates
|
|
486
|
+
telemetry is one budget away from doing half of each. A separate terminal
|
|
487
|
+
step after `decay`, or a call at `runCycle`'s end outside the phase budget,
|
|
488
|
+
keeps "what the cycle forgot" and "what the log dropped" separately
|
|
489
|
+
reportable. The phase list is `satisfies`-checked in three places, so adding
|
|
490
|
+
one is a typed change, not a quiet one.
|
|
491
|
+
2. **What the retention should be.** 90 lived days is the store's current
|
|
492
|
+
default and nobody has measured against it. The parallel run is the first
|
|
493
|
+
thing that will have an opinion: its evidence is the store after the fact, so
|
|
494
|
+
a window shorter than the run destroys the run's own record. Whatever number
|
|
495
|
+
is chosen must be longer than the longest run any contract plans, and the
|
|
496
|
+
choice belongs beside that number rather than inside a phase.
|
|
497
|
+
|
|
498
|
+
**Why not tonight.** Turning a dormant deletion path on is a change to what the
|
|
499
|
+
owner's live store *loses*, on a store where nothing has ever been swept — the
|
|
500
|
+
opposite risk profile from the record that surfaced it. Constitution line 7's
|
|
501
|
+
"nothing bulk-wipes silently" points the same way: the first run of this would
|
|
502
|
+
delete months of rows in one pass, and it should be a decision someone made on
|
|
503
|
+
purpose, with a count printed first.
|
|
504
|
+
|
|
505
|
+
## 14. Beliefs are not dedup candidates — 2026-09-05
|
|
506
|
+
|
|
507
|
+
**The finding, restated as a question rather than a bug.** §12 above closed two
|
|
508
|
+
ways a REVISION could lose its successor to a merge, and filed probe H as the
|
|
509
|
+
third: an element and an ordinary memory colliding with no revision anywhere.
|
|
510
|
+
The honest fix was named there and not built ("constitution 15: named, not
|
|
511
|
+
built") because it is not a patch to the tie-break — it is a question about what
|
|
512
|
+
the dedup pass is *for*. The owner answered it in one sentence: beliefs and
|
|
513
|
+
memories are different kinds of things, and the duplicate-merger should compare
|
|
514
|
+
notes with notes.
|
|
515
|
+
|
|
516
|
+
**The rule as shipped: (a), the wide one.** A `type: "schema"` row is not a
|
|
517
|
+
dedup candidate at all. `types.ts#isSchemaRow` is read in `runDedup` where the
|
|
518
|
+
LIVE SET is built, so `contentHashCandidates` and any injected cosine source
|
|
519
|
+
both receive a `liveIds` with no element in it. The alternative on the table was
|
|
520
|
+
(b) — compare schema rows only with schema rows on the same entity — and it was
|
|
521
|
+
rejected on contract grounds rather than taste:
|
|
522
|
+
|
|
523
|
+
- `schemas/` §2 and constitution line 12: **named deviation.** "Beliefs never
|
|
524
|
+
blend into each other. Generalization is only ever an explicit,
|
|
525
|
+
provenance-carrying revision." A merge is exactly a blend with a `uses`
|
|
526
|
+
credit and no provenance.
|
|
527
|
+
- `schemas/` §5 G4: **near collisions refuse LOUDLY rather than merging.** Two
|
|
528
|
+
beliefs saying one thing is a schemas-module question with a schemas-module
|
|
529
|
+
answer — refuse and say so — and a sleep phase archiving one at 2am is the
|
|
530
|
+
opposite of loud.
|
|
531
|
+
- `schemas/` §5 G1: **no operation edits a belief.** Rule (b) would have made
|
|
532
|
+
the nightly pass the exception.
|
|
533
|
+
- And empirically: `tools/migrate/apply.ts#writeElement` already de-duplicates
|
|
534
|
+
same-entity elements at import time, by `entity + role + statement`. The pair
|
|
535
|
+
rule (b) would police is not arriving through this door.
|
|
536
|
+
|
|
537
|
+
Both alternatives were tested rather than argued: "two beliefs with one body are
|
|
538
|
+
left to `schemas/`, not merged here" is the test that would pass under (b) too
|
|
539
|
+
if it asserted a merge, and asserts the refusal instead.
|
|
540
|
+
|
|
541
|
+
**Why (a) is narrow even though it sounds wide.** Elements still fade, still
|
|
542
|
+
take pressure, still cross bands, still get pruned. This is not `isJournal` —
|
|
543
|
+
that predicate is read by four phases and takes the journal out of forgetting
|
|
544
|
+
altogether. `isSchemaRow` is read by ONE phase, and its doc comment says so, so
|
|
545
|
+
the next reader does not generalize it into an exemption nobody granted.
|
|
546
|
+
|
|
547
|
+
**G9b is not made redundant, and this is the fact that decided the shape of the
|
|
548
|
+
change.** `schemas/index.ts:955` mints element successors with `type: "schema"`,
|
|
549
|
+
which (a) covers. `revision.ts:387` mints the IDENTITY arm's successor with
|
|
550
|
+
`type: "memory"` — an ordinary `mem_` row carrying `source: "accommodation"` —
|
|
551
|
+
and (a) does not reach it. Without G9b, an identity element revised under three
|
|
552
|
+
days of pressure would still lose its successor to the challenger. There is now
|
|
553
|
+
a test at exactly that case, and it is the one that would fail if someone
|
|
554
|
+
decided G9b had become dead code. The five PR #56 tests keep every invariant
|
|
555
|
+
assertion; only their `leftAlone` reason line moved to `skipped.schema`, with
|
|
556
|
+
the reason written beside it.
|
|
557
|
+
|
|
558
|
+
**Two honesty repairs made in the same loop.** The journal exclusion in this
|
|
559
|
+
phase was SILENT while CONTRACT §5 G15 claims "counted as a named skip in each
|
|
560
|
+
phase" — decay, prune and consolidate counted it and dedup did not. It counts
|
|
561
|
+
now. And a pair handed over by an injected source naming a stood-down row used
|
|
562
|
+
to be counted `already-archived`, which is false for a live belief; it is named
|
|
563
|
+
`schema` or `journal`.
|
|
564
|
+
|
|
565
|
+
**What changes on a live store, and it is not nothing.** Any cycle where an
|
|
566
|
+
element and an ordinary memory share a body. Migration makes that likely: every
|
|
567
|
+
migrated element was minted at the import day while migrated memories kept their
|
|
568
|
+
v1 birth day, so the memory is older on every such pair and wins without even
|
|
569
|
+
needing the `mem_` < `sch_` tie-break. Nothing is repaired by the fix itself —
|
|
570
|
+
an element already archived `merged` stays archived, with its prose, its id and
|
|
571
|
+
its merge record intact. The repair is a separate, owner-run tool:
|
|
572
|
+
`counterparts repair-merged-beliefs --dry-run`, and `--apply` if the owner
|
|
573
|
+
chooses (`cli/NOTES.md` §5).
|
|
574
|
+
|
|
575
|
+
**Two things the adversarial review measured that belong here rather than in a
|
|
576
|
+
PR comment.**
|
|
577
|
+
|
|
578
|
+
1. **The cosine arm has never fired on the live store.** `Counterpart.sessionEnd`
|
|
579
|
+
calls `runCycle({store, render, …})` with no `candidates`
|
|
580
|
+
(`core/counterpart.ts:1114`), so `runDedup`'s `source` is `undefined` and only
|
|
581
|
+
the content-hash arm has ever run in production. The cosine test in this
|
|
582
|
+
suite is a guard against future wiring, not a description of something that
|
|
583
|
+
has already happened — worth saying plainly, because it makes the live
|
|
584
|
+
exposure smaller than the tests' coverage suggests, and a reader who assumed
|
|
585
|
+
otherwise would over-read the finding in either direction.
|
|
586
|
+
2. **`skipped["schema"]` now counts every live element, every night.** On a
|
|
587
|
+
migrated store that is a number in the thousands, and it means "nothing
|
|
588
|
+
happened" — the same shape as the journal skip. It is a census of what the
|
|
589
|
+
phase stood down, not an alarm, and nobody should read a cycle report as if
|
|
590
|
+
a big number there were a problem.
|
|
591
|
+
|
|
592
|
+
**The class, for G12:** anything else. Not "telemetry-only and provably
|
|
593
|
+
identical" — the surface-set hash is unchanged (`800a9a9421cd969f` on master and
|
|
594
|
+
on this branch) because it hashes FIELD NAMES on three record shapes and no
|
|
595
|
+
field moved, but what the store HOLDS moves: an element that would have been
|
|
596
|
+
archived stays live, one fewer `sleep.merged.<id>` is written, and recall, the
|
|
597
|
+
wake and every schema slice see a belief where they would have seen nothing.
|
|
598
|
+
The day-1 record says nothing either way about schema/memory collisions, so
|
|
599
|
+
"no live row is affected" is not a claim this session can make.
|
|
600
|
+
|
|
601
|
+
## 15. The log sweep — §13's caller, and the two decisions it asked for — 2026-09-05
|
|
602
|
+
|
|
603
|
+
**What was built.** A new terminal phase, `log` (`log.ts`), after `briefing`,
|
|
604
|
+
that calls `Store.pruneEvents({ limit: ctx.budget })` and reports like every
|
|
605
|
+
other phase: `examined` = rows past the window (unlatched + latched), `changed`
|
|
606
|
+
= rows deleted, `skipped.latched` = rows past the window kept by their latch,
|
|
607
|
+
`skippedForBudget` = eligible rows the cap left for tomorrow. It emits
|
|
608
|
+
`sleep.log.swept` (counts only) and the store emits `store.events.pruned`.
|
|
609
|
+
`Store.pruneEvents` grew the cap (`WHERE seq IN (SELECT seq … ORDER BY seq
|
|
610
|
+
LIMIT ?)`, oldest first) and a fuller report (`eligible`, `remaining`,
|
|
611
|
+
`limit`); `Store.eventLogCensus()` is the read-only count of the same numbers,
|
|
612
|
+
which is what the observer report and `counterparts verify` use. CONTRACT §5
|
|
613
|
+
G16 states the guarantee.
|
|
614
|
+
|
|
615
|
+
**Decision 1 — which phase.** §13 named `prune` as the obvious and wrong home,
|
|
616
|
+
and the alternative of a call at `runCycle`'s end outside the phase machinery.
|
|
617
|
+
Neither. A PHASE gets everything the sweep needs for free and would otherwise
|
|
618
|
+
have to re-spell: a marker (once per lived day, `already-done-today` on replay),
|
|
619
|
+
a budget (the per-pass cap, and "a budget is not a debt" already means "take a
|
|
620
|
+
cap's worth today, report the rest, owe nothing"), degrade-don't-abort, the
|
|
621
|
+
observer's `apply === false` path, the three-way outcome vocabulary, and a row
|
|
622
|
+
in the dashboard's cycle table via `CYCLE_PHASES` (which is `PHASES`, imported).
|
|
623
|
+
It runs LAST because §3's guarantee is that the briefing is the last **content**
|
|
624
|
+
write, and a telemetry delete is not one — the order test now asserts both: the
|
|
625
|
+
briefing's `store.put` is the final content write, and `store.events.pruned`
|
|
626
|
+
comes after it. The name is `log` because that is what the code calls the table
|
|
627
|
+
everywhere (`eventLog`, "the durable event log", `no-durable-event-log`);
|
|
628
|
+
`events` would collide with `CycleReport.events`, the in-memory telemetry ring.
|
|
629
|
+
|
|
630
|
+
**Decision 2 — the retention, and where it lives.** `Store.retentionDays`
|
|
631
|
+
stays the one window, default `DEFAULT_RETENTION_DAYS` = 90 lived days in
|
|
632
|
+
`store/operational.ts`. It was already the knob for the version and
|
|
633
|
+
gate-session sweeps, and the dashboard already promised it in prose in two
|
|
634
|
+
places ("I keep events for `${store.retentionDays}` lived days; older ones are
|
|
635
|
+
swept unless a replay latch holds them" — `activity.ts`, `web/views.ts`), so a
|
|
636
|
+
second sleep-side number would have made two 90s that drift, and moving the
|
|
637
|
+
store's default into physics would have made the store import physics for one
|
|
638
|
+
constant. What the sleep module owns is the FLOOR ON THE DEFAULT: a test pins
|
|
639
|
+
`DEFAULT_RETENTION_DAYS >= 90` with the reason beside it — the parallel run's
|
|
640
|
+
instrument reads its evidence off this table and needs ≥ 7 active days plus
|
|
641
|
+
review slack. The knob remains the owner's: a store opened with
|
|
642
|
+
`retentionDays: 30` sweeps at 30 and no test forbids it, because a floor that
|
|
643
|
+
silently refused the owner's own setting would be the ceremony constitution 15
|
|
644
|
+
tells us not to build ahead of a failure.
|
|
645
|
+
|
|
646
|
+
**Every reader of the table, and what each needs — the survey the retention
|
|
647
|
+
was chosen against.** Latched (kept at any age, so retention is irrelevant to
|
|
648
|
+
them): `repair-merged-beliefs` and the seam's `unarchiveMerged` (`memory.merged`
|
|
649
|
+
by name and by ref — and the command ALSO unions archived schema rows via
|
|
650
|
+
`list()`, so it does not lean on the log alone); the symmetry counter in
|
|
651
|
+
`cycle.ts`, `dashboard/status.ts`, `web/views.ts#healthView`, the replay
|
|
652
|
+
driver (`band.transition`); `schemas.story()`, `dashboard/stories.ts`
|
|
653
|
+
(`revision.pressure`); the replay driver and the daily (`gate.chunk`); the
|
|
654
|
+
dashboard's exits and the demo seeder (`memory.pruned`, `memory.merged`,
|
|
655
|
+
`band.promoted`). Unlatched (subject to the window): `tools/parallel/readers.ts`
|
|
656
|
+
reads `adapter.*`, `sweep.gate`, `recall.decision` **for one date at a time**
|
|
657
|
+
(SQL-filtered by `day` or by the payload's `date`) plus a whole-table
|
|
658
|
+
`COUNT(*)` of `recall.decision` — a run window of ≥ 7 active days sits far
|
|
659
|
+
inside 90; `tools/replay/driver.ts` reads `gate.deposit` over the WHOLE run at
|
|
660
|
+
the end, on a store it created whose lived days are the corpus's active days
|
|
661
|
+
— **26 in the recorded replay** — so a corpus longer than the window would lose
|
|
662
|
+
its first days' deposit records to the sweep, and that is the one bound worth
|
|
663
|
+
naming (the fix, if a longer corpus ever exists, is a driver that reads
|
|
664
|
+
incrementally or opens its store with a longer window, not a longer default);
|
|
665
|
+
`tools/demo/seed.ts` counts `recall.decision` over its 30 days; the dashboard's
|
|
666
|
+
feed, node lists and health heatmap read `LOG_CEILING` or the last 21 lived
|
|
667
|
+
days and already say "what I still have"; `eventDetail(seq)` already answers
|
|
668
|
+
"no event with that seq in the kept window"; the `session` node's "N sessions
|
|
669
|
+
seen" is now a count over the window rather than since birth. `date.repaired`
|
|
670
|
+
and `salience.defaulted` (repair tools) are unlatched and written at repair
|
|
671
|
+
time; nothing reads them back. No reader needs more than 90 lived days.
|
|
672
|
+
|
|
673
|
+
**The cap.** `TUNABLES.BUDGETS.log = 5_000` rows per pass. Measured, not
|
|
674
|
+
calibrated: on a 100,000-row log, a 5,000-row capped delete took 177 ms cold and
|
|
675
|
+
17 ms warm, 20,000 rows took 35 ms, and the census over 70,000 rows took 10 ms
|
|
676
|
+
(bun 1.3.10, this machine, 2026-09-05). A day's inflow on the live store is
|
|
677
|
+
hundreds of rows, not thousands, so steady state clears in one pass and the cap
|
|
678
|
+
only bites on a backlog — which is the case it exists for.
|
|
679
|
+
|
|
680
|
+
**What the live store's events table holds — and the premise the "0 rows"
|
|
681
|
+
claim rests on.** This session never opened `~/.counterparts`. What CAN be said
|
|
682
|
+
is arithmetic on the write sites: every `appendEvent` in `src/` passes a `day`
|
|
683
|
+
taken from `livedDay()` at write time (or a `d.day` / `t.day` / `log.day` that
|
|
684
|
+
is that same value carried a few lines), `advanceClock` refuses to move
|
|
685
|
+
backwards, and `tools/migrate` writes no events (it sets `livedDay` to v1's
|
|
686
|
+
`activeDay` and writes rows, not log entries). So the oldest event's day ≥ the
|
|
687
|
+
lived day at migration, the store has lived at most the calendar days since
|
|
688
|
+
2026-08-25 — eleven at the time of writing — and the cutoff is `livedDay − 90`:
|
|
689
|
+
**the first pass should delete 0 rows**, whatever v1's clock set `livedDay` to,
|
|
690
|
+
until the store has lived 90 days past its first v2 event.
|
|
691
|
+
|
|
692
|
+
**The premise, named (adversarial review of PR #81):** that argument holds
|
|
693
|
+
only for a store that had **no events before migration set its clock**.
|
|
694
|
+
"Forward-only" is `advanceClock`'s promise, and `tools/migrate/apply.ts`
|
|
695
|
+
does not use `advanceClock` — `setMetaIfChanged` (`apply.ts:364`) writes
|
|
696
|
+
`livedDay` through `setMeta`, the side door, with no guard that the target
|
|
697
|
+
store is fresh. A store that had already run a hook, `verify`, or an install
|
|
698
|
+
before migration jumped its clock carries day-0 rows that a 400-ish clock puts
|
|
699
|
+
three hundred days past the cutoff. The reviewer's probe: five `adapter.boundary`
|
|
700
|
+
rows at day 0, then `setMeta("livedDay", "400")`, one row at 400 — first cycle
|
|
701
|
+
`eligible=5`, deleted 5, the post-migration row kept; clock set first, then
|
|
702
|
+
rows — `eligible=0`, deleted 0. **The live store is the second shape:** the
|
|
703
|
+
coordinator ran `counterparts verify` read-only against it on 2026-09-05 and it
|
|
704
|
+
printed **1,342 rows held, oldest lived day 184, 0 past the window** — so the
|
|
705
|
+
arithmetic holds there, on a measurement rather than on this paragraph. If a
|
|
706
|
+
future `verify` ever shows a non-zero `past the window` on a store that should
|
|
707
|
+
have none, the named suspect is a clock moved by `setMeta` over rows that
|
|
708
|
+
predate it, not the write sites.
|
|
709
|
+
|
|
710
|
+
**`gate.deposit` stays unlatched, on purpose.** The reviewer argued it and this
|
|
711
|
+
note agrees: a latch needs a dedup key, a per-row key would make the most
|
|
712
|
+
voluminous kind "kept at any age" — the I23 growth shape again — and a key that
|
|
713
|
+
collapses repeats would change the "two refusals are two events" semantics
|
|
714
|
+
`test/gate-records.test.ts` protects. Readers that need it past the window size
|
|
715
|
+
their own store's `retentionDays` instead — which is what the replay driver now
|
|
716
|
+
does (`tools/replay/driver.ts`).
|
|
717
|
+
|
|
718
|
+
**The cycle now leaves ONE durable row per run (`sleep.cycle`, 2026-09-14,
|
|
719
|
+
IMPROVEMENTS U9).** Everything this module emits — `sleep.cycle.start`,
|
|
720
|
+
`sleep.cycle.done`, `sleep.phase.failed` — lives in an in-process `EVENT_RING`
|
|
721
|
+
that dies with the worker, so "did the cycle run today, and did every phase
|
|
722
|
+
succeed" was not a question the store could answer; the only durable evidence
|
|
723
|
+
was the SIDE EFFECTS other phases wrote (`band.transition`, `memory.pruned`),
|
|
724
|
+
which a quiet cycle does not leave at all. `sleep/` did not change: the row is
|
|
725
|
+
written by the composition root from the returned `CycleReport`, the same way
|
|
726
|
+
`sweep.gate` is written from the sweep reports, because this module has no
|
|
727
|
+
opinion about the store's event log and should not grow one. Payload:
|
|
728
|
+
`reason` (`ran` | `clock-failed` | `threw`) and `code`, `date`, `day`,
|
|
729
|
+
`phases: [{ phase, status, reason, code? }]` for EVERY phase in the executed
|
|
730
|
+
order, `started` (how many the cycle entered), `failedPhase`/`stage` when the
|
|
731
|
+
thrower said, and the counts `promoted`, `pruned`, `merged`, `bandUp`,
|
|
732
|
+
`bandDown`, `failed`, `trimmed`. Unlatched like `sweep.gate` — two boundaries in
|
|
733
|
+
one lived day leave two rows, because the cycle really did run twice — and pruned
|
|
734
|
+
with everything else at the store's 90-lived-day window.
|
|
735
|
+
|
|
736
|
+
**And a cycle that DIES carries its work out with it** (`CyclePartial`, added in
|
|
737
|
+
review of the same PR). Degrade-don't-abort covers a phase BODY that throws; a
|
|
738
|
+
throw from outside one — a marker advance, the clock, `onStep`'s hard kill —
|
|
739
|
+
escapes with no `CycleReport`, and the first version of the row read it as a
|
|
740
|
+
quiet clean night: seven phases had run and the briefing had trimmed six
|
|
741
|
+
elements, and the row said `phases: [], failed: 0, promoted: 0`. That is the
|
|
742
|
+
fabricated zero (scar §2.4) arriving through an exception. `runCycle` now
|
|
743
|
+
attaches the reports it had — plus `CycleKilled`'s phase and stage — to the
|
|
744
|
+
escaping error as a non-enumerable symbol property, and the recorder writes
|
|
745
|
+
`null`, never 0, for every count the run never finished taking.
|
|
746
|
+
|
|
747
|
+
## 16. `skipped` reaches the durable row — 2026-09-20 (E2)
|
|
748
|
+
|
|
749
|
+
Every phase has always counted what it turned away, by reason, in `PhaseReport.skipped` —
|
|
750
|
+
consolidate mirrors physics' whole `blockedBy` vocabulary into it as `promotion:<reason>`,
|
|
751
|
+
and each phase pre-seeds its categories with zeroes so one can never go missing from the
|
|
752
|
+
report. Nothing durable copied it. `recordSleepCycle` built the `sleep.cycle` payload out
|
|
753
|
+
of `phase`, `status`, `reason`, `budgetExhausted` and `skippedForBudget`, and dropped the
|
|
754
|
+
map.
|
|
755
|
+
|
|
756
|
+
So the consequence of `docs/promotion-diagnosis-2026-09-17.md` — one consolidate pass that
|
|
757
|
+
examined a third of the store and promoted nothing — was unanswerable the moment the
|
|
758
|
+
worker exited. The reasons existed, in memory, for the length of one cycle. That is the
|
|
759
|
+
pattern the mechanism inventory named as running through everything: *the system records
|
|
760
|
+
what happened and almost never records what was prevented.*
|
|
761
|
+
|
|
762
|
+
**Nothing new is computed and nothing new is read.** The map is the value the phase
|
|
763
|
+
already produced, spread into a payload that is already built inside the try that protects
|
|
764
|
+
the throw path. Only the NONZERO entries ride: the zeroes exist so the in-process report
|
|
765
|
+
is total, and eight of them per phase per boundary is how a log gets too big to read. A
|
|
766
|
+
phase that turned nothing away carries no field at all — absent, rather than an empty
|
|
767
|
+
object a reader has to interpret.
|
|
768
|
+
|
|
769
|
+
`adapters/fired.ts` reads them keyed `<phase>/<reason>`, so one row answers for promotion,
|
|
770
|
+
prune, dedup and decay and none of them can claim another's.
|