[Bugfix #826] iter-7: Fix release blocker — LOCAL_SCHEMA CREATE INDEX vs migration order - #834
Merged
Merged
Conversation
… vs migration order
ROOT CAUSE: ensureLocalDatabase runs `db.exec(LOCAL_SCHEMA)` BEFORE
migrations on every open. LOCAL_SCHEMA contained
`CREATE INDEX idx_architect_workspace ON architect(workspace_path)`.
On any pre-v11 install (every v3.1.1 user upgrading to v3.1.2), the
architect table lacks the workspace_path column, so the CREATE INDEX
threw 'no such column: workspace_path' and aborted ensureLocalDatabase
before migration v11 could run. The schema stayed at v10 and every
subsequent setArchitectByName call failed with the same error.
Release blocker — would have broken every v3.1.1 user's upgrade.
FIX:
1. Drop the CREATE INDEX statement from schema.ts LOCAL_SCHEMA.
2. Add it to db/index.ts migration v11 block, OUTSIDE the inner
`if (!alreadyMigrated)` guard but inside the outer `if (!v11)` guard.
- Upgrade install: inner block runs (architect → architect_v11
rename), then CREATE INDEX creates the index.
- Fresh install: LOCAL_SCHEMA created the v11-shaped table, inner
block is a no-op (workspace_path column already present), CREATE
INDEX still runs (idempotent via IF NOT EXISTS).
3. CREATE INDEX uses `IF NOT EXISTS` so subsequent opens (after v11 is
recorded) don't matter — the index is just there.
TESTS (3 new in bugfix-826-migration.test.ts):
1. `db.exec(LOCAL_SCHEMA)` against a pre-v11 architect table no longer
throws. Pre-iter-7 this test would have failed with 'no such column';
it's the literal release-blocker repro.
2. Full upgrade sequence: v10 schema → LOCAL_SCHEMA → migrate. Asserts
the table is migrated AND the index exists.
3. Fresh-install path: LOCAL_SCHEMA creates v11 shape → migration inner
block skipped (alreadyMigrated=true) → CREATE INDEX still runs in
the outer block. Asserts the index exists.
The existing migration tests didn't catch this because they set up the
v10 schema directly in SQL and called the migration body — they never
exercised LOCAL_SCHEMA's db.exec sequence, where the bug lived.
1853 agent-farm tests pass. `tsc --noEmit` clean.
Contributor
Author
iter-7 CMAP 3-way result: unanimous APPROVE
No REQUEST_CHANGES, no flagged concerns. The release blocker is closed for both upgrade and fresh-install paths. @waleedkadous — ready for re-merge. |
waleedkadous
added a commit
that referenced
this pull request
May 23, 2026
Critical hotfix on the Jacobean line. Closes #826: cross-workspace sibling-architect leak introduced by v3.1.1's #786 multi-architect lifecycle work. Schema-level fix (PR #827 — workspace_path column on state.db.architect with composite PK, all state accessors take workspacePath, realpath canonicalization at the boundary) plus migration-ordering hotfix (PR #834 — CREATE INDEX moved out of LOCAL_SCHEMA into the migration block so upgrade installs don't crash). 7-iteration CMAP-driven development. Architect's independent CMAP caught a real bug at every iteration that the builder's own CMAP missed: original cross-workspace fix had a race, then stop+start regression, then exit-handler delete leakage, then getTerminalsForWorkspace stale-cleanup, then migration backfill non-determinism, then path canonicalization, then the upgrade-install release blocker. Single-CMAP review on this PR would have shipped a regression. End-to-end verified locally before publish: added a sibling to codev, confirmed manazil (the original report workspace) showed only its own main and did not leak the codev sibling. Migration v11 ran cleanly against the architect's real v10 state.db.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to merged PR #827 (Fixes #826) — fixes a release blocker discovered during local manazil verification: every v3.1.1 user's upgrade would have crashed at startup.
Root cause
ensureLocalDatabaserunsdb.exec(LOCAL_SCHEMA)BEFORE migrations on every open. PR #827'sLOCAL_SCHEMAcontained:On any pre-v11 install, the
architecttable lacks theworkspace_pathcolumn. The CREATE INDEX threwno such column: workspace_pathand abortedensureLocalDatabasebefore migration v11 could run. The schema stayed at v10 and every subsequentsetArchitectByNamecall failed with the same error.Architect caught it on the user's actual
codev/.agent-farm/state.db:Fresh installs would have worked (LOCAL_SCHEMA's
CREATE TABLEwould have created the v11 shape from scratch) — but upgrade installs would not.Fix
schema.tsLOCAL_SCHEMA.db/index.tsmigration v11 block, OUTSIDE the innerif (!alreadyMigrated)guard but inside the outerif (!v11)guard.CREATE INDEX IF NOT EXISTScreates the index on the new table.IF NOT EXISTSmakes subsequent opens (after v11 is recorded in_migrations) a no-op.Tests
3 new in
bugfix-826-migration.test.ts:db.exec(LOCAL_SCHEMA)against a pre-v11 architect table no longer throws. Pre-iter-7 this test would have failed withno such column; it's the literal release-blocker repro.The existing migration tests didn't catch this because they set up the v10 schema directly in SQL and called the migration body — they never exercised LOCAL_SCHEMA's
db.execsequence, where the bug lived. Architect explicitly called out this test gap.Test results
pnpm exec tsc --noEmitclean.Diff stat
3 files, +136 / -3.
CMAP
Will run 3-way after PR creation per the BUGFIX protocol.