Rebasing onto the updated #4556 turned up two doc drifts: the base moved
the script list from `vp run` to `bun run`, and the state-directory
paragraph still described the fixed `userdata` preference that the mtime
tiebreak replaced.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three findings from Macroscope review:
- Settling `pending` rows to `interrupted` was the wrong verb. The server
deletes them (`clearPendingProjectionTurnsByThread`) once the turn
starts or the thread stops, and never settles one in place. They also
cannot be settled coherently: `turn_id` is NULL, so an "interrupted"
pending row is a terminal turn with no id, a shape no real turn has.
Now deleted, matching the server's predicate exactly so a checkpoint
row is never caught by it.
- `COALESCE(completed_at, requested_at)` preserved a stale completion on
a running turn. One can carry a completion from an earlier settle that
a later checkpoint reverted to "running" — the `...existingTurn` spread
in ProjectionPipeline keeps the old value — and dating the interruption
to that checkpoint gives a wrong duration. Overwritten unconditionally.
- The CLI hard-coded `<base>/userdata/state.sqlite` while a dev server
under an implicit dev home stores state in `<base>/dev`. A main-checkout
`bun run dev` was therefore unseedable, and said so by claiming no
database existed and suggesting the user start the server that was
already running. Source and target now follow whichever directory holds
a database, `userdata` breaking the tie; attachments follow the same
directory. Verified both a dev-only target and the precedence order.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review of the seeding path found five ways a seeded database could
describe something the copy cannot back up:
- Nothing stopped `dev:seed` from running against a live server. SQLite
locking lets the seed take the write lock between the server's own
writes and commit cleanly; what it cannot do is tell that server its
projections and event log were replaced underneath it. Refuse instead,
via a pid probe over both state directories.
- A thread copied mid-turn kept `state = 'running'`. The session override
did not cover it — the turn is read independently, and an unsettled one
leaves the thread spinning and its timeline unfoldable forever. Settle
those to "interrupted", matching what the server does when a session
leaves "running". Streaming messages are finished for the same reason.
- Attachment metadata was copied without the files behind it, so a seeded
thread rendered an image whose request 404s. Report the referenced ids
and copy the matching files alongside the rows.
- Orphaned `provider_session_runtime` rows survived the seed naming
threads it had just deleted, which the session reaper then tried to
stop against a provider instance the worktree may not define.
- `--threads` had no upper bound, so a large enough value died with "too
many SQL variables" after the target was already emptied.
Also corrects the projector-cursor comment: `orchestration_events.sequence`
is AUTOINCREMENT, so emptying the log does not reset its high-water mark
and sequence does not restart at 1. Zero remains the right cursor, for the
reason now stated.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>