Skip to content

Request ids resume from the store, so a restart stops eating history - #70

Merged
fylorn merged 1 commit into
mainfrom
fix/request-ids-survive-restart
Sep 21, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/request-ids-survive-restart

Conversation

@fylorn

@fylorn fylorn commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Every restart destroyed the oldest records, silently.

EventBus::new starts the request counter at 1 and nothing ever seeded it from disk, while the recorder writes with INSERT OR REPLACE — it has to, because a request is written twice, once when it starts and once when it ends. Put together, the first request after a restart overwrites historical request 1, the second overwrites 2, and so on. The desktop app restarts on every update, so this ran regularly.

Measured

A throwaway instance, eight requests, restart, eight more, restart, five more:

v0.14.0 with the counter seeded
after 8 requests 8 rows 8 rows
after restart + 8 8 rows 16 rows
after restart + 5 8 rows 21 rows

Twenty-one requests, eight rows left.

The fix

Db::last_request_id reads MAX(id), and build_store hands it to the bus before serve starts, so the first request of the run already has a number above everything on disk. resume_after is a fetch_max: winding the counter backwards would be manufacturing collisions, which is the bug itself.

Reading it can fail, and then the run carries on as before — losing a few old records is worse than recording nothing at all this session.

Tests cover both halves: that MAX(id) is what the next run has to start from, that a reused id really does overwrite the older row (the problem this exists to avoid), and that resuming never hands out a number twice.

🤖 Generated with Claude Code

…ing history

Every restart destroyed the oldest records, silently.

`EventBus::new` starts the request counter at 1 and nothing ever seeded
it from disk, while the recorder writes with `INSERT OR REPLACE` — it
has to, because a request is written twice, once when it starts and
once when it ends. Put together, the first request after a restart
overwrites historical request 1, the second overwrites 2, and so on.
The desktop app restarts on every update, so this ran regularly.

Measured against v0.14.0 with a throwaway instance: eight requests,
restart, eight more, restart, five more. Twenty-one requests, eight
rows left. With the counter seeded: twenty-one rows.

`Db::last_request_id` reads `MAX(id)`, and `build_store` hands it to the
bus before `serve` starts, so the first request of the run already has
a number above everything on disk. `resume_after` is a `fetch_max`:
winding the counter backwards would be manufacturing collisions, which
is the bug itself.

Reading it can fail, and then the run carries on as before — losing a
few old records is worse than recording nothing at all this session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 2e0f77c into main Sep 21, 2026
1 check passed
@fylorn
fylorn deleted the fix/request-ids-survive-restart branch September 21, 2026 08:09
@fylorn fylorn mentioned this pull request Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant