Repository navigation
fix(persistence): repo writes take the row's identity, never a bare id - #30616
Conversation
updateRepo(target, updates) now takes Pick<Repo,'id'|'connectionId'|'executionHostId'> (RepoHostTarget) and resolves the host from it, so a caller that holds the row can no longer drop its host and write a same-id sibling on another host. The id-only callers (project host setup controller and IPC handler, folder-to-Git upgrade watch, both clone paths, registration adoption, fork backfill) pass the row they resolved. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
ELI5
The same project can be registered twice with the same id: once on this computer and once on an SSH host (or a paired server). Saving a change to "this project" used to look the project up by id alone, so a change meant for one copy could land on the other. Now every save is handed the exact project row it is about, including which machine it lives on, so it can only change that row.
What Changed
updateRepo(id, updates, hostId?)took the host as an optional third argument. When a caller left it out, the store wrote the first row with that id. Several callers had already looked up the right row and then passed onlyrepo.id: project-host setup (runtime controller and desktop IPC handler), the folder-to-Git upgrade watch, both clone paths, project registration's host adoption and the fork backfill. Where the same id existed on two hosts, those writes could rename, re-type or re-stamp the wrong copy.updateRepo(target, updates)takesRepoHostTarget = Pick<Repo, 'id' | 'connectionId' | 'executionHostId'>, the same shapesetResolvedRepoGitUsernamealready uses. The store works out the host from the target withgetRepoExecutionHostId, andfindRepoRowForHostScopedWriteno longer has its "no host: take the first match" branch. Every caller now passes the row it resolved. A caller that has only an id no longer compiles.repos:updateIPC. The renderer sends nohostIdfor unstamped local rows, and the issue-source preference write never sends one. With ahostId, the handler addresses that host directly. Without one, it keeps today's first-match row, resolved once at the boundary (store.getRepo). The wire is unchanged.There are no user-visible changes on a single-host setup. With twin rows, edits now stay on the copy they were made for.
Why
This is round 4 decision D-A: write APIs take the row's identity fields, never a bare id.
hostId: a caller can still fill it from a first-match lookup, which is the bug.Passing the row also means there is only one place that derives the host from the two legacy fields.
Linked Issue
Round 4 SSH hardening, slice R4-2 (decision D-A), following #30584 (findings 2 and 3). No GitHub issue.
Visual Proof
N/A. This is a main-process persistence API change with no UI.
Testing
pnpm tcis clean. A bare-id or three-argumentupdateRepocall is now a type error.tests/e2etypecheck ratchet: OK.The 71 unit files that touch
updateRepopass, run with--maxWorkers=1.New and rewritten tests:
persistence-update-repo.test.ts: with the SSH twin stored first, a write handed the local row lands on the local row.repo-update-host-guard.test.ts: a target with no host fields means the local row, not the first same-id row; an SSH row is addressable throughconnectionIdalone.Call expectations now assert the host through
repoTarget(id, hostId)(src/main/persistence/repo-host-target-matcher.test-fixture.ts), so a write to the wrong twin fails them.I ran the full "static analysis and typecheck" job steps locally.
Not live-verified on an SSH host. The change is in-process only and changes no wire format.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
tests/e2e/folder-upgrade-identity-persistence.unit.test.tsstill used the string form. It is fixed and was re-reviewed.repo.id), soupdateProjectHostSetup({ setupId })can't tell twins apart. Fixing that needs an optionalhostIdon the update arguments, so it is left as a follow-up.Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)