Skip to content

fix: recover schema-ahead DB migration + worktree branch-resolution collision - #471

Merged
getappz merged 3 commits into
masterfrom
fix/backend-migration-0011
Aug 12, 2026
Merged

getappz merged 3 commits into
masterfrom
fix/backend-migration-0011

Conversation

@getappz

@getappz getappz commented Aug 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two independent, verified infra fixes found and fixed while diagnosing why mcp__flare__item/claim were completely broken this session:

1. Backend migration 0011 recovery + schema-ahead diagnostics

  • ~/.agentflare/agentflare.db was at schema version 11 (from an unpushed feat/pm-fast-follows dev-install earlier), but master's binary only defined migrations 0001-0010 — every DB open failed with an opaque rusqlite_migration "too high" error and no indication why.
  • Forward-ported migration 0011_item_assignment_events.sql onto master so the current binary can open the DB again.
  • agentflare-db-kit::open::open_file now detects DatabaseTooFarAhead specifically and reports the actual recorded schema version plus remediation steps, for every DB that goes through this shared opener (backend, store, jobs, memory).
  • dev-install now warns when installing from a non-default branch, since it replaces the one shared binary+db and any migration it carries can't be downgraded by reinstalling from master later.

2. Worktree branch-resolution collision (blocked all re-dispatch of items with a pre-existing worktree)

  • create_worktree/push_branch recomputed task_branch_name(item) fresh on every call — a slug derived from the item's current title. A worktree already checked out to a different branch (a legacy bare task/<seq> branch predating the slugged naming scheme, or simply because the item was renamed since its first claim) then failed the exact-match re-claim check, so git worktree add collided with the already-occupied path instead of reusing it — silently looping forever (claim succeeded but no worktree was created).
  • resolve_worktree_branch now checks what branch a pre-existing worktree is actually on (any task/<seq> or task/<seq>-* branch) before falling back to the freshly-derived slug, so a re-claim reuses it instead of colliding.
  • Verified live against the daemon: item fix(item): release/done no longer silently no-op on claim identity mismatch #447 (an EPIC whose worktree predated this fix) now dispatches cleanly with zero collision errors.

Test plan

  • cargo test -p agentflare-db-kit — new a_database_migrated_by_a_newer_build_reports_schema_ahead regression test passes
  • cargo test -p agentflare-backend — migration suite passes
  • cargo test -p flare-git-core worktree — 57/57 pass, including 2 new regression tests reproducing the exact collision (legacy bare branch + renamed-item cases)
  • cargo fmt --all --check clean
  • cargo clippy --locked -p agentflare-db-kit -p agentflare-backend -p flare-git-core -p agentflare --all-targets -- -D warnings -A unsafe_code -A clippy::pedantic clean
  • Installed live via dev-install, daemon self-restarted, confirmed real re-dispatch of a previously-stuck item with no errors

Summary by CodeRabbit

  • New Features
    • Added tracking for item assignee changes, including previous and new assignees and timestamps.
    • Existing task worktrees now continue using their checked-out branches, including renamed or legacy branches.
  • Bug Fixes
    • Improved worktree reuse when item titles or branch names change.
  • Developer Experience
    • Added a clear warning when running dev-install from a non-default branch.
    • Databases created by newer builds now report a specific schema-ahead error instead of a generic migration failure.

…d DBs, warn on off-branch dev-install

The live ~/.agentflare/agentflare.db was at schema version 11 (item_assignment_events,
from the unpushed feat/pm-fast-follows branch) while master's binary only defined
migrations 0001-0010, so every item/claim MCP call failed with an opaque
rusqlite_migration 'too high' error and no way to tell why.

- Forward-port migration 0011 (item_assignment_events) onto master so the current
  binary can open the DB again.
- agentflare-db-kit::open::open_file now detects DatabaseTooFarAhead specifically
  and reports the recorded schema version plus remediation steps instead of the
  bare upstream error string, for every DB that goes through this shared opener.
- dev-install now warns when installing from a non-default branch, since it
  replaces the one shared binary+db and any migration it carries can't be
  downgraded by reinstalling from master later.

Agentflare-Agent: claude-code_2-1-228_agent
Agentflare-Branch: fix/backend-migration-0011
… freshly recomputed slug

create_worktree/push_branch called task_branch_name(item) fresh every time, which
re-slugs from the item's current title. A worktree already sitting at
.worktrees/task/<seq> on a different branch (a legacy bare task/<seq> branch
predating the slugged naming scheme, or simply because the item was renamed since
its first claim) then fails the exact-match re-claim check, so git worktree add
collides with the already-occupied path instead of reusing it -- item #447's
worktree (bare task/447 branch) hit this on every dispatch attempt, silently
looping forever (claim succeeded but no worktree was created).

resolve_worktree_branch now checks what branch a pre-existing worktree is
actually on (any task/<seq> or task/<seq>-* branch) before falling back to the
freshly-derived slug, so a re-claim reuses it instead of colliding.

Agentflare-Agent: claude-code_2-1-228_agent
Agentflare-Branch: fix/backend-migration-0011
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aeb82b3f-8a8e-4780-9b99-40e0e54b081a

📥 Commits

Reviewing files that changed from the base of the PR and between 9e81d00 and 9523f62.

📒 Files selected for processing (3)
  • crates/agentflare-db-kit/src/open.rs
  • crates/flare-git-core/src/branch.rs
  • src/dev_install/mod.rs
📝 Walkthrough

Walkthrough

The backend adds an item assignment-events migration and schema-ahead detection. Git worktrees preserve legacy or renamed task branches. dev-install warns when run from a non-default branch.

Changes

Database migration handling

Layer / File(s) Summary
Assignment events and schema-ahead detection
crates/agentflare-backend/src/db.rs, crates/agentflare-backend/src/migrations/0011_item_assignment_events.sql, crates/agentflare-db-kit/src/open.rs
The migration sequence creates item_assignment_events. Database opening returns Error::SchemaAhead when the database uses newer migrations. Regression coverage verifies the applied version.

Worktree branch reuse

Layer / File(s) Summary
Existing task branch resolution
crates/flare-git-core/src/worktree.rs, crates/flare-git-core/src/worktree_tests.rs
Worktree creation and branch pushing reuse existing legacy or renamed task branches. Tests cover bare sequence branches and changed item titles.

Development installation branch warning

Layer / File(s) Summary
Non-default branch warning
src/dev_install/mod.rs
dev-install checks the current and default branches before building and warns when they differ.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies both primary fixes: schema-ahead database migration recovery and worktree branch-resolution collision handling.
Description check ✅ Passed The description explains the two fixes, their rationale, implementation details, regression tests, and validation results; only the optional reviewer notes section is absent.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backend-migration-0011

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/agentflare-db-kit/src/open.rs`:
- Around line 44-46: Update the user_version query in the open/schema-version
flow to propagate the SQLite error instead of using unwrap_or(-1). Ensure the
retrieved version is returned through the existing Result path so
Error::SchemaAhead always uses the actually recorded schema version.

In `@src/dev_install/mod.rs`:
- Around line 175-176: Update resolve_default_branch and the surrounding
migration check so inconclusive resolution returns an explicit unknown state
instead of the current branch; in the current != default logic, handle unknown
conservatively by emitting the migration warning. Add a regression test covering
a repository with default branch trunk and current branch feature when
origin/HEAD, main, and master are unavailable.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6427e16d-e888-4015-9bc9-cff1b9d50ebf

📥 Commits

Reviewing files that changed from the base of the PR and between 085de53 and 9e81d00.

📒 Files selected for processing (6)
  • crates/agentflare-backend/src/db.rs
  • crates/agentflare-backend/src/migrations/0011_item_assignment_events.sql
  • crates/agentflare-db-kit/src/open.rs
  • crates/flare-git-core/src/worktree.rs
  • crates/flare-git-core/src/worktree_tests.rs
  • src/dev_install/mod.rs

Comment thread crates/agentflare-db-kit/src/open.rs Outdated
Comment thread src/dev_install/mod.rs Outdated
- open.rs: propagate the PRAGMA user_version query error instead of
  swallowing it into a -1 sentinel, so SchemaAhead always carries the
  actually recorded version.
- Add resolve_default_branch_known(), returning None instead of falling
  back to the current branch when no authoritative default (origin/HEAD,
  local main/master) is resolvable. dev-install's off-default-branch
  warning now uses it and warns conservatively on 'unknown' instead of
  silently matching current == fallback-to-current and never firing.

Agentflare-Agent: claude-code_2-1-228_agent
Agentflare-Branch: fix/backend-migration-0011
@getappz

getappz commented Aug 12, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@getappz
getappz merged commit 5697944 into master Aug 12, 2026
16 checks passed
@getappz
getappz deleted the fix/backend-migration-0011 branch August 12, 2026 18:32
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