Repository navigation
Commit 3ee6cba
fix(server): purge imported v1 rows the v2 runtime never reads (#1723)
## Problem
The V2 runtime never reads a thread's V1 events after its transcript import, yet nothing deletes them.
On `ugrindtime` that dead data is most of a 12 GB database:
| Rows | Count | Payload |
| --- | --- | --- |
| V1 events | 2.58M | 3.18 GB, plus indexes |
| `projection_thread_activities` | 1.81M | 2.86 GB, no reader |
Every page of it adds disk IO to checkpoints, backups, and cold reads.
Upstream's `ProjectionMaintenance.compactEventStore` (`pingdotgg#2829`) drops the same V1 events, but nothing calls it in production.
Its thread-state supersession would also delete the fork's legacy issue markers, which are V2 `thread.metadata-updated` events.
Losing a marker re-runs the issue import and undoes V2 unlinks.
## Change
### Code
- **New file:** `LegacyV1Purge.fork.ts`
- **Hook:** two lines in the V1 importer
- **When:** after the background transcript import
### Rows
- **Events:** V1 rows of imported threads
- **Activities:** whole table
- **Kept:** V2, project, and pending-thread events
### Pacing
- **Pages:** 200 rows, 50 ms pause between
- **Failure:** logged; the next startup resumes
### Measured on a full copy of the live database
- **Live data:** 12.09 GB to 3.08 GB
- **Page hold:** p50 8 ms, p99 171 ms
- **Expected first run:** about 25 min, background
- **Later runs:** no-op
## Reclaiming disk
The purge frees pages for reuse, so the file stops growing but does not shrink.
To shrink it once, after the purge has logged `Purged imported legacy v1 rows`:
1. Stop `t3code.service`
2. Back up `~/.t3/userdata/statev2.sqlite`
3. Run `sqlite3 ~/.t3/userdata/statev2.sqlite VACUUM`
4. Start the service
## Follow-ups
- **Growth:** `turn-item.updated` adds ~260 MB/day
- **Markers:** store outside events first
## Scope and approval
Refs #1720.
The maintainer chose this narrow purge over wiring upstream's compaction.
## Verification
- **New test:** 1001-row purge keeps live rows
- **Mutation check:** fails without import filter
- **Legacy tests:** 10 of 10 pass
- **Typecheck:** `apps/server`, exit 0
- **Fork CI:** `vp run fork:ci`, exit 0
- **Not checked:** a live server on this build
Claude Code, claude-opus-5-5.
## Fork trailers
Squashes:
- 7595062 fix(server): purge imported v1 rows the v2 runtime never reads (#1723) (#1723)
- d1395ce fixup! fix(server): purge imported v1 rows the v2 runtime never reads (#1723) (#1723)
Fork-Domain: upstream-fixes
Fork-Tier: bugfix
Fork-Upstreamable: yes1 parent cb27f62 commit 3ee6cba
3 files changed
Lines changed: 134 additions & 0 deletions
File tree
- apps/server/src/orchestration-v2/legacy
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
804 | 805 | | |
805 | 806 | | |
806 | 807 | | |
| 808 | + | |
807 | 809 | | |
808 | 810 | | |
809 | 811 | | |
| |||
0 commit comments