Repository navigation
fix(server): deduplicate symlinked project checkouts #32212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
48011f6
7cc3c4d
63acf89
6dfb3e6
bee7ea2
c41492e
3bf768c
89920b2
99eac53
8b48870
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,6 +250,39 @@ export const make = Effect.gen(function* () { | |
| ), | ||
| ); | ||
|
|
||
| const findByWorkspaceRoot = Effect.fn("ProjectService.findByWorkspaceRoot")(function* ( | ||
| workspaceRoot: string, | ||
| options?: { readonly includeDeleted?: boolean }, | ||
| ) { | ||
| if (options?.includeDeleted !== true) { | ||
| const exact = yield* projects | ||
| .findActiveByWorkspaceRoot(workspaceRoot) | ||
| .pipe( | ||
| Effect.mapError( | ||
| (cause) => new ProjectOperationError({ operation: "read-project", cause }), | ||
| ), | ||
| ); | ||
| if (Option.isSome(exact)) return exact; | ||
| } | ||
| const rows = yield* projects | ||
| .list(options) | ||
| .pipe( | ||
| Effect.mapError( | ||
| (cause) => new ProjectOperationError({ operation: "list-projects", cause }), | ||
| ), | ||
| ); | ||
| const exact = rows.find((row) => row.workspaceRoot === workspaceRoot); | ||
| if (exact !== undefined) return Option.some(exact); | ||
| // Older registrations can still store a symlink spelling. Resolve without rewriting their history. | ||
| return yield* Effect.findFirst(rows, (row) => | ||
| normalizeWorkspaceRoot({ workspaceRoot: row.workspaceRoot }).pipe( | ||
|
Comment on lines
+277
to
+278
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bound each saved-root probe so an unresponsive mount cannot block unrelated registrations. When the exact lookup misses, Each saved-root probe must finish within a bound. A probe that does not finish must count as no match for that row, so the lookup completes and the command can commit. The bound and the no-match policy need an explicit choice. A timed-out probe for a row that is the same checkout can let a duplicate registration through, so that case must be accounted for.
|
||
| Effect.map((root) => root === workspaceRoot), | ||
| // An unavailable checkout cannot establish a matching filesystem identity. | ||
| Effect.orElseSucceed(() => false), | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| const rejectWorktreeContainer = Effect.fn("ProjectService.rejectWorktreeContainer")(function* ( | ||
| projectId: ProjectId, | ||
| workspaceRoot: string, | ||
|
|
@@ -272,9 +305,7 @@ export const make = Effect.gen(function* () { | |
| workspaceRoot === undefined | ||
| ? undefined | ||
| : Option.getOrUndefined( | ||
| yield* projects | ||
| .findActiveByWorkspaceRoot(workspaceRoot) | ||
| .pipe(Effect.mapError(dispatchError)), | ||
| yield* findByWorkspaceRoot(workspaceRoot).pipe(Effect.mapError(dispatchError)), | ||
| ); | ||
| const now = yield* DateTime.now; | ||
| const eventId = yield* idAllocator.allocate | ||
|
|
@@ -377,19 +408,7 @@ export const make = Effect.gen(function* () { | |
| "ProjectService.getByWorkspaceRoot", | ||
| )(function* (workspaceRoot, options) { | ||
| const normalized = yield* normalizeWorkspaceRoot({ workspaceRoot }); | ||
| const row = yield* ( | ||
| options?.includeDeleted === true | ||
| ? projects | ||
| .list({ includeDeleted: true }) | ||
| .pipe( | ||
| Effect.map((rows) => | ||
| Option.fromUndefinedOr(rows.find((row) => row.workspaceRoot === normalized)), | ||
| ), | ||
| ) | ||
| : projects.findActiveByWorkspaceRoot(normalized) | ||
| ).pipe( | ||
| Effect.mapError((cause) => new ProjectOperationError({ operation: "list-projects", cause })), | ||
| ); | ||
| const row = yield* findByWorkspaceRoot(normalized, options); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the exact saved path before the canonical path. If project A is saved at Keep both path forms. Check the exact saved path with the caller's
|
||
| return Option.isNone(row) ? Option.none() : Option.some(yield* hydrate(row.value)); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject ambiguous canonical matches before rename or remove.
If two legacy projects are saved under different symlinks to the same checkout, a third symlink matches both.
Effect.findFirstselects one project even though the argument identifies neither saved registration.project removethen deletes that project. With--force, it also deletes the project's threads. Before the alias fallback, that unsaved path did not match either registration. (raw.githubusercontent.com)Keep exact ID and saved-path matches. If canonical fallback finds a second match, stop and ask for the project ID or an exact saved path.