fix(lokee): bind revert execute to history database identity - #256
Merged
Conversation
POST /lokee/databases/:id/revert planned reverse DDL from one history row but ran it on any resolved connection. Refuse with connection_mismatch when the credential fingerprint does not match. Co-authored-by: huy.phan9 <huyplb@users.noreply.github.com>
Contributor
Author
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_047cbbbf-b86f-4be2-aaf2-c3fe56e9c497) |
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.
Bug and impact
POST /lokee/databases/:id/revertplanned reverse DDL from the History database (:id) but executed it on whatever connection the client sent. The History UI uses separate dropdowns for history database and credential, so a user can select DB A’s history and DB B’s credential, then apply A’s reverse migration to B — wrong-target DDL / possible data loss.Root cause
Revert only checked that the history row was owned by the user (
assertOwned/planRevert). It never compared the resolved connection’sdatabaseIdentityfingerprint tolokee_databases.fingerprint.Fix
LokeeWeaveStore.matchDatabaseIdentity.409withcode: "connection_mismatch".LokeeRevertErrorin the client API.Validation
npx vitest run apps/web/src/backend/modules/lokee-weave.module.test.ts— 40 passed (includes new match/mismatch/not_found cases).cd apps/web && npx tsc --noEmit— clean.Note
Medium Risk
Changes revert execution safety by blocking wrong-target DDL; scope is limited to one endpoint and fingerprint comparison, but mistakes here could still block legitimate reverts if identity hashing diverges from capture.
Overview
Revert execute now refuses to run when the client’s resolved connection does not match the schema history row (
:id). Before planning or applying reverse DDL, the handler compares the connection’sdatabaseIdentityfingerprint tolokee_databases.fingerprintvia newLokeeWeaveStore.matchDatabaseIdentity.On mismatch the API returns 409 with
code:connection_mismatch`` (404 when the history id is missing or not owned). The frontendLokeeRevertErrorand `executeLokeeRevert` parsing recognize that code so the UI can prompt the user to pick the credential for the same database.Tests cover ok, mismatch (different
databasename), and not_found.Reviewed by Cursor Bugbot for commit b88b9e2. Bugbot is set up for automated code reviews on this repo. Configure here.