Commit Graph
7 Commits
Author SHA1 Message Date
Magolor 0e56ff698b fix(session): recover an unusable database, keep planner statistics, and carry over damaged frames
Close the six review findings against the event-row store, add provisioned
recovery, and make the derived tables' indexes actually reachable.

Data carried over from the frame layout:
- Carry over the readable prefix of a frame recorded longer than its lines.
  The frame layout served whatever prefix a read asked for, so only a sequence
  with no readable line gets a row no reader decodes.
- Drop lines past a frame's recorded range: the frame layout never read them,
  so reporting them as damage would fail a read that used to succeed.
- Repeat the nearest readable event's `time` in the stand-in row instead of 0,
  so `session_summary.last_event_time` stays a real instant.
- Tolerate an absent version 1 trigger or index. A build that narrowed the
  frame layout dropped some, and losing a trigger costs no stored event.
- Refuse a child Segment that does not start where its parent ends instead of
  giving it a history the frame layout rejected.
- Set aside a frame whose Segment row is absent, which the version 1 foreign
  key never checked.

Derived tables:
- Compare every declared object (table, session view, indexes, further views)
  so a dropped view or index is rebuilt rather than silently missing forever.
- Analyze once when no statistics exist and `PRAGMA optimize` on close. Without
  statistics SQLite scanned every result in the Segment per tool call:
  `session_tools` took 2.3 s on 84,000 tool calls against 22 ms analyzed.

Recovery, new `recovery` setting defaulting to `replace`:
- An absent database becomes a new empty one.
- A lock waits the busy timeout, then the file moves to
  `<name>.locked-<timestamp>` and a new empty database takes its place.
- An unreadable file moves to `<name>.unreadable-<timestamp>` the same way.
- `report` keeps the previous refusal for a storage root another process
  may write. A newer schema version is never replaced under either mode.

Documentation records the recovery setting, the raw-state damage behavior, the
compression limit on JSON queries, and the statistics step. 488 tests with full
coverage on the package sources.
2026-11-26 11:52:53 +08:00
Magolor 6da7ed3f6e refactor(session): keep the SQLite store's SQL in versioned .sql resources
The schema and every static statement of the SQLite Session store were
string literals in TypeScript, and the upgrade step from the frame layout
executed whatever the current schema constant held. They now live under
resources/sql: schema/vN.sql is the whole schema of one version and is
not edited once released, upgrade/A-to-B holds the statements of one
upgrade step, and store/ and derived/ hold the statements of the store
and of the derived-table runtime. src/sql.ts is their only reader.

Two internal views, segment_extents and session_heads, replace the SQL
fragments the store shared by string interpolation. Transaction control,
connection pragmas and the DDL generated from a derivation stay inline.
2026-11-25 18:47:26 +08:00
Tianyi Cui 4553c9d957 refactor(session)!: remove SQLite persistence backend 2026-08-31 13:23:07 +08:00
Tianyi Cui 2c6ff296af Revert "Merge pull request #3087 from deepseek-harness/worktree/remove-ignorable-session-events"
This reverts commit 2123b2f418b1c8fbb86dc327b598fb11423da226, reversing
changes made to 3c0b5c68ce697537a21084f9135663017474a2e1.
2026-08-30 12:26:20 +08:00
Magolor df76bc695b feat(session): reduce persistence storage size (#3048) 2026-08-26 08:01:07 +00:00
Tianyi Cui 42dc2a46c2 refactor(session): require known event types on read 2026-08-26 00:22:31 +08:00
Magolor 93b4b98ef3 feat(session): optimize SQLite persistence layout 2026-08-19 18:36:27 +08:00