Skip to content

Commit 4fe94eb

Browse files
docs: the refusal list repaired and pinned; what deletion does; what the binding means for restore
Council pass 8 (sol S1/S4/S5, luna M2/M3), reproduced: the coordinator's troubleshooting insert had severed lane U's unclassified entry mid-sentence, duplicated two entries and left constraint_violation out. The list is rebuilt as one bullet per stable reason code and pinned by a test that reads _REFUSAL_FIXES (which also found controls_changed sharing a bullet). The setup guide no longer claims a deleted note or parked topic leaves its old row in the full database (owned records retire, and the retirement is a control the full tier applies); it names StudyLoop's own application tables as not mirrored. session-db-tiering stops promising session-sync --tier full consolidation on the current schema and describes what the binding means for a restore from the full file (instance_mismatch; a rebind is an open item).
1 parent ed6c206 commit 4fe94eb

4 files changed

Lines changed: 80 additions & 41 deletions

File tree

‎docs/session-db-tiering.md‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ graph TB
2323
| **Full** | `database.full_db_path` (e.g. external volume) | The record. Complete history, kept by the background `sync-full` as a single-writer mirror of this machine's hot DB: bound to it on the first sync, it receives whole sessions and the memory captured from them, never the hot DB's own replication, access or policy state. Read opportunistically by federated search; verification anchor for prune. |
2424
| **Snapshots** | `database.snapshot_dir` | Point-in-time `VACUUM INTO` copies of the full DB, auto-created every `snapshot_interval_days` after a sync, rotated to `snapshot_retention`. Protect the record from corruption that sync would faithfully propagate. |
2525

26-
The full DB is **per-machine**. Cross-machine consolidation is
27-
`session-sync`'s job: `--tier hot` (default) moves the recent working set
28-
between hosts (prune-aware — locally pruned sessions are not resurrected);
29-
`--tier full` consolidates the records (requires `full_db` on the host
30-
entry in config.yaml).
26+
The full DB is **per-machine** and, since the mirror contract (ADR-0016,
27+
2026-10-23), **single-writer**: it is bound to the everyday database that
28+
first synced into it, and `sync-full` refuses to write anyone else's. Cross-
29+
machine consolidation through `session-sync --tier full` is therefore not
30+
available on the current schema: the legacy SQL path refuses any database
31+
that holds captured memory (`replication/legacy.py`), and a second machine
32+
writing into a bound full database would contradict the binding. `--tier
33+
hot` (default) still moves the recent working set between hosts (prune-aware
34+
— locally pruned sessions are not resurrected). What `--tier full` should
35+
mean under the mirror contract is an open design item.
3136

3237
## Configuration
3338

@@ -109,19 +114,23 @@ session-sync sync HOST --tier full # consolidate records across machines
109114

110115
## Restore procedures
111116

112-
**Hot DB lost** (disk failure, new machine):
117+
**Hot DB lost** (disk failure, new machine): copy the record into place as the
118+
new everyday database —
113119

114120
```bash
115-
# 1. Copy the record into place
116121
cp /Volumes/<external-drive>/StudyLoop/DB/sessions_full.db ~/.config/studyloop/sessions.db
117-
# 2. Trim it back to a working set
118-
studyloop prune --days 30 --apply
119-
# 3. Verify
120122
studyloop doctor
121123
```
122124

123-
With `sync_mode: always` the loss window is seconds — whatever the last
124-
background sync missed.
125+
— and keep working from it. Two consequences of the binding, until a rebind
126+
exists (an open design item): the restored everyday database carries the full
127+
database's own identity, not the one the full database is bound to, so the
128+
next `sync-full` into that same full file refuses (`instance_mismatch`) —
129+
point `database.full_db_path` at a new file, which the first run binds, and
130+
keep the old one; and `studyloop prune` cannot trim the restored copy against
131+
the old full file for the same reason (it would refuse before verifying). With
132+
`sync_mode: always` the loss window is seconds — whatever the last background
133+
sync missed.
125134

126135
**Full DB corrupted or lost:**
127136

‎docs/setup-guide.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,13 +1087,18 @@ database:
10871087
and learning metadata; your learner records (study sessions, teach-backs, parked topics, study
10881088
notes, practice attempts, the parking board's columns) and the concept graph they point at.
10891089
Deletions and permanent forgets reach the full database first, so a forgotten session is never
1090-
brought back; an ordinary edit or delete of a mutable record (a note, a parked topic) is mirrored
1091-
as an update, and a plain delete leaves the old row in the full database — it is an archive.
1090+
brought back; deleting an owned record (a note, a parked topic) retires it, and the retirement is
1091+
one of those controls, so the full database drops its copy too. An edit of a mutable record is
1092+
mirrored as an update; a plain delete of an unowned row (a parking board column) leaves the old
1093+
row in the full database — it is an archive.
10921094
Captured memory is never overwritten: if the full database holds a different version of the same
10931095
record, `sync-full` refuses instead.
10941096
- **What it never copies.** This machine's own state — access generations, replication receipts and
10951097
peer history, policy and lifecycle mode, capture runs, retention origins, quarantine. The full
1096-
database's search index follows the rows it receives; embeddings are not copied.
1098+
database's search index follows the rows it receives; embeddings are not copied. StudyLoop's own
1099+
application tables in the same file (card reviews and review sessions, study plans and their
1100+
checkpoints, practice-check events) are not mirrored either: `prune` never touches them, and the
1101+
full database is not their backup.
10971102
- **Repeated runs.** A run with nothing new copies nothing. With `database.full_db_path` set,
10981103
StudyLoop also starts a quiet `sync-full` in the background after exports and study-session
10991104
starts (`database.sync_mode`); it prints nothing, so run `session-maint sync-full` by hand to see

‎docs/troubleshooting.md‎

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -384,40 +384,43 @@ Each reason, and what to do:
384384
- **`managed_store_busy_or_unavailable`** — another program held one of the two databases while
385385
deletions were being reconciled. Wait, or stop what else is using them (the web app, an MCP
386386
server, another sync), then run again.
387-
- **`controls_unstable`** or **`controls_changed`** — a deletion or forget changed while
388-
`sync-full` was reconciling deletions or about to copy. Run again; if it repeats, stop other
389-
StudyLoop processes first.
387+
- **`controls_unstable`** — the deletion and forget records of the two databases could not be
388+
brought to agreement before copying (one of them changed under `sync-full`, or the full volume
389+
went away mid-way). Run again; if it repeats, stop other StudyLoop processes first.
390+
- **`controls_changed`** — a deletion or forget landed between reconciling them and copying, so the
391+
copy stopped before writing anything. Run again.
390392
- **`immutable_collision`**, naming a table and a key — the full database holds a record under the
391393
same key with different content. Captured memory is never overwritten, so the copy stops. Do not
392394
edit either database: keep both files and report the table and key. Pointing
393395
`database.full_db_path` at a new file starts a fresh mirror in the meantime.
394396
- **`noncanonical_override`** — `--db` names a database other than the configured
395397
`database.path`; the mirror belongs to the configured everyday database only. Run without `--db`.
396-
- **`unclassified tier table: <name>`** — the everyday database has a memory table this version of
397-
StudyLoop does not know how to mirror, usually because a newer StudyLoop wrote it. Run the
398-
`distinct_paths` — `database.path` and `database.full_db_path` name the same file. Point
399-
`full_db_path` at a different file (on the external volume) and run `sync-full` again.
400-
401-
`schema_mismatch` — the everyday database is not on the current schema, or the full database could
402-
not be brought to it. Run `session-maint schema` on each; an unwritable full volume is the usual cause.
403-
404-
`unclassified_table` — the everyday database holds a `context_*` table the mirror does not know (a
405-
newer migration than this install). Upgrade StudyLoop; the mirror and `prune` both refuse rather
406-
than copy a table whose role they cannot name.
407-
408-
`orphan_row` — a row in the everyday database points at a parent that exists in neither database
409-
(left by a deletion made with foreign keys off, before the lifecycle fixes). Nothing is copied. List
410-
the rows with `sqlite3 <database.path> "PRAGMA foreign_key_check"`; there is no repair command yet,
411-
so back the file up, delete the listed rows by hand, and run `sync-full` again.
412-
413-
current StudyLoop on this machine, then `sync-full` again. `prune` refuses the same way.
414-
- **The two databases are on different schema versions**, or the everyday one is behind. Upgrade
415-
StudyLoop, run `session-export` once (it migrates the everyday database), then `sync-full`.
398+
- **`unclassified_table`**, naming the table — one of the two databases has a memory table this
399+
version of StudyLoop does not know how to mirror, usually because a newer StudyLoop wrote it
400+
(the message says which database). Run the current StudyLoop on this machine, then `sync-full`
401+
again. `prune` refuses the same way, by name, rather than skip everything silently.
402+
- **`distinct_paths`** — `database.path` and `database.full_db_path` name the same file. Point
403+
`full_db_path` at a different file (on the external volume) and run `sync-full` again.
404+
- **`schema_mismatch`** — the everyday database is not on this build's schema, or the full database
405+
is on a newer one than this build. Upgrade StudyLoop on this machine (or, if the everyday
406+
database is behind, run `session-export` once: it migrates it), then `sync-full`.
407+
- **`orphan_row`** — a row in the everyday database points at a parent row that exists in neither
408+
database (left by a deletion made with foreign keys off, before the lifecycle fixes). The copy
409+
stops and nothing is copied. List the rows with
410+
`sqlite3 <database.path> "PRAGMA foreign_key_check"`; there is no repair command yet, so back the
411+
file up, delete the listed rows by hand, and run `sync-full` again. (A parent that survives only
412+
in the full database is not an orphan: the row copies.)
413+
- **`constraint_violation`**, naming a table — the full database refused a row under a constraint
414+
other than a foreign key (a unique index or a check). Do not edit either database; keep both files
415+
and report the table named. Pointing `database.full_db_path` at a new file starts a fresh mirror
416+
in the meantime.
416417
- **`Legacy SQL sync cannot transfer scoped or source-grounded memory`** — the configuration
417418
scopes memory (`memory.sync`, `memory.projects`, or a `memory.default_scope` other than
418419
`unclassified`). Scoped memory moves only through the structured replication protocol, so
419420
`sync-full` is not available with that configuration and sessions stay in the everyday database.
420421

421-
`session-maint prune` reporting every old session as skipped (not in the full database) means the
422-
full database is behind: something was captured after the last `sync-full`. Run `sync-full`, fix
423-
any refusal above, then `prune` again.
422+
`session-maint prune` first proves the full database is this database's mirror — bound to it by
423+
`sync-full`, or a copy of this very database — and refuses with `unbound_full` or
424+
`instance_mismatch` otherwise, before it verifies anything. `prune` reporting every old session as
425+
skipped (not in the full database) means the full database is behind: something was captured after
426+
the last `sync-full`. Run `sync-full`, fix any refusal above, then `prune` again.

‎packages/agent-session-tools/tests/test_tiering_cli.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,25 @@ def test_spawned_sync_full_refusal_exits_nonzero_and_logs_the_reason(spawned):
123123
assert full.execute("SELECT id FROM sessions").fetchall() == [
124124
("other-history",)
125125
]
126+
127+
128+
def test_troubleshooting_lists_each_stable_reason_once():
129+
"""Pass 8 (sol S1): the setup guide promises 'each reason is explained'; a
130+
bad hand-merge once severed one entry, duplicated two and omitted one.
131+
Every stable reason code the mirror can raise appears exactly once as a
132+
bold bullet in the troubleshooting list."""
133+
from pathlib import Path
134+
135+
from agent_session_tools.tiering import _REFUSAL_FIXES
136+
137+
root = Path(__file__).resolve()
138+
while not (root / "docs" / "troubleshooting.md").exists():
139+
root = root.parent
140+
text = (root / "docs" / "troubleshooting.md").read_text()
141+
section = text[text.index("## `session-maint sync-full` Refuses") :]
142+
section = (
143+
section[: section.index("\n## ", 1)] if "\n## " in section[1:] else section
144+
)
145+
for reason in _REFUSAL_FIXES:
146+
bullets = section.count(f"- **`{reason}`**")
147+
assert bullets == 1, (reason, bullets)

0 commit comments

Comments
 (0)