Repository navigation
Reject reused plugin migration indexes - #2626
Conversation
|
@slopcop check this |
|
@slopcop check it |
| database.transaction(() => { | ||
| for (const row of rows) { | ||
| const statement = statements[row.id]; | ||
| adopt.run( |
There was a problem hiding this comment.
🚨 slopcop/review — Skip unchanged legacy rows before the write call.
This loop calls a synchronous UPDATE for every recorded migration on every load. It does this even when statement_hash already has a value. It also calculates the same statement hash again. Please check for a null hash before the write and reuse the calculated hash. This is a low-priority performance suggestion.
There was a problem hiding this comment.
Fixed in abd821f. The host now calculates each hash once and skips legacy update calls for rows that already contain a hash.
| assertLive(); | ||
| database.exec( | ||
| "CREATE TABLE IF NOT EXISTS _bb_migrations (id INTEGER PRIMARY KEY, applied_at INTEGER NOT NULL)", | ||
| "CREATE TABLE IF NOT EXISTS _bb_migrations (id INTEGER PRIMARY KEY, applied_at INTEGER NOT NULL, statement_hash TEXT)", |
There was a problem hiding this comment.
🚨 slopcop/review — Share this migration policy between the real and fake hosts.
This migration algorithm duplicates the production algorithm in plugin-api.ts. The Plugin SDK already holds shared internal host policy. A shared internal migration helper would prevent drift between production and the test host. This is a low-priority refactor suggestion.
There was a problem hiding this comment.
I am keeping these implementations separate. The fake host ships in the published Plugin SDK, while the production policy lives in the server. Sharing this helper would require a new cross-package internal surface. The parity tests guard the contract between them.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain-English summary: BB lists each plugin database change by number. This change also stores a hash for each change. BB rejects a changed or reused number.
I found no blocking issue.
Two low-priority notes remain:
- The production loop issues a no-op SQLite update for every old migration on every plugin load. It also calculates most hashes twice.
- The fake host copies the full production migration algorithm. A shared internal helper would reduce future drift.
The security review found no new security boundary. Plugins already receive the database handle and run trusted server code.
All GitHub checks passed at this SHA. These checks include server, package, integration, version, and package smoke tests. git diff --check also passed.
I started focused Turbo tests in an isolated exact-head worktree. Shared-host CPU contention delayed SDK declaration generation, so I stopped those local jobs. GitHub CI completed the same test areas successfully.
A browser test does not apply here. This pull request changes no UI, HTTP route, or browser behavior. A dev server and Doobie test would not exercise this migration path.
The final independent GPT-5.6 review gate returned APPROVE. I posted this as a comment only, with no approval or change request.
Main advanced to 0.4.27 (get-bb#2626 migration indexes) while this branch carried its own bridge dist changes; reclaim the next patch.
Main advanced to 0.4.27 (get-bb#2626 migration indexes) while this branch carried its own bridge dist changes; reclaim the next patch.
Human comments
What was wrong
The plugin migration helper tracked only a statement index. A plugin could later reuse that index for another statement. The host then treated the new statement as applied and silently omitted its schema change.
What changed
The host and the fake plugin host now store a SHA-256 hash for each migration statement. They reject a changed or reused index. Legacy applied indexes beyond the current migration list receive a reserved value, so later statements cannot reuse them. The Plugin Guide and the SDK contract now document this behavior. The Plugin SDK version increases to 0.4.27. This change does not alter the host daemon protocol.
How you verified