Repository navigation
feat(worker): delete an organization's Code Storage mirror when its last link to a repository goes - #112
Draft
electric-gizzard wants to merge 1 commit into
Draft
feat(worker): delete an organization's Code Storage mirror when its last link to a repository goes#112electric-gizzard wants to merge 1 commit into
electric-gizzard wants to merge 1 commit into
Conversation
…ast link to a repository goes An organization's mirror of a linked GitHub repository held a copy of the code, and its sessions' saved work, for good. It is now deleted as soon as no folder of the organization links the repository: on an unlink from the last folder, a GitHub account disconnect, the App being uninstalled, and the repository being taken out of what the App may access (`installation_repositories` removed, which also unlinks it). The mirror is deleted before the link is taken away, so a failure leaves everything in place to be tried again. Deleting is immediate and drops the saved session work; the app asks before an unlink or disconnect that does. Closes #86 Co-Authored-By: Claude Fable 5.2 <[email protected]>
This branch has not been deployed
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.
Closes #86.
What was wrong
With Code Storage configured, linking a GitHub repository makes a mirror of it for the organization (
codeStorageRepoName(orgId, fullName)): a copy of the code, plus the work its sessions save on branches GitHub never sees. Nothing ever deleted one, so the organization kept a readable copy after its access to the repository ended.What this does
The organization's mirror of a repository is deleted as soon as none of its folders links the repository, whatever took the last link away:
installationdeleted)installation_repositoriesremoved)A mirror is kept while another folder of the same organization still links the repository, and another organization's mirror of the same repository is never touched.
Decisions (the three the issue left open)
UnlinkRepoDialog, shown only for a last link with a store), and the disconnect dialog says it too. Webhook causes cannot ask anyone.How it is ordered
The mirror is deleted before the link is taken away. If Code Storage refuses, the route answers 502 with a message a person can act on, nothing else has changed, and the action can be tried again. Deleting after the unlink would have left an orphan with nothing left to say which repository it was. A mirror that is already gone is not a failure, so retries and redeliveries are safe.
Mirror names are always derived from the organization and
owner/name, never read from a link'sstore, so links written beforeRepoRef(no store recorded) are covered and nothing outsideorg-<orgId>/can be deleted.Behaviour changes to be aware of
DELETE /workspace/folders/{folderId}/reposnow fails (500) when the workspace's folders cannot be read, where it used to send the unlink anyway. Guessing "not linked elsewhere" could delete a mirror still in use.NormalizedWebhookhas a new kind,installation.repos.removed.Known gaps
disconnectAccountalready documents). Its sessions run but cannot save until it is relinked.Testing
bun run verifypasses (types, tests, lint, format), andbun run check:package.apps/worker/src/github/repo-links.test.ts(16 tests) drives the real routes and webhook handler against a fake Code Storage: last link vs. still linked elsewhere, legacy links, other organizations untouched, delete-before-unlink order, a refused delete leaving everything in place, an already-missing mirror, redelivery after a failure, and no Code Storage configured.unlinkDeletesSavedWorkhave unit tests..dev.vars), and nothing was run against real Code Storage. Worth a manual pass: unlink a last-linked repository and confirm the dialog, then check the mirror is gone in Code Storage.🤖 Generated with Claude Code