PR #9715 review: stop linking PRs that closed before the workspace existed
Summary
Fixes SUPER-3460: the host-service PR sweep finds a workspace's PR by head branch name, so a workspace on a reused branch (release, staging, a recycled feature name) linked the newest old merged/closed PR and kept it in link history. The PR reads GitHub's closed_at and refuses a merged/closed match that closed before workspace.createdAt unless HEAD is the PR head, and prunes such rows from workspace_pull_requests. No tRPC shape change, no migration.
Verdict
Needs changes — the logic is sound and well tested for new workspaces, but the PR commits 99 stray test-output files, and the createdAt anchor leaves the bug in place for long-lived workspaces that switch onto a reused branch.
Findings
packages/host-service/undefined/worktrees/*/fix-login-*/README.md — the PR adds 99 files (104 files changed, only 5 are the real change). They are test output: packages/host-service/src/daemon/manifest.test.ts:27 does process.env.SUPERSET_HOME_DIR = undefined, which Bun/Node store as the string "undefined" (verified: bun -e 'process.env.X = undefined; …' prints "undefined"). Later tests then resolve resolveAppHomeDir() to ./undefined and create worktrees there. main already has 66 such files from an earlier commit.
Fix: git rm -r packages/host-service/undefined on this branch. Separately (own PR): use delete process.env.SUPERSET_HOME_DIR in manifest.test.ts (restore the original value), delete the 66 files on main, and add packages/host-service/undefined/ to .gitignore as a guard.
packages/host-service/src/runtime/pull-requests/pull-requests.ts:223 — the cut-off is workspace.createdAt, but a workspace can move onto a branch long after it was created. This is the common case for type: "local" workspaces that share the primary checkout, where people switch to staging/develop/release. Concrete input: workspace created 2025-06-01, now on release at workspace-sha; GitHub's newest release PR #515 merged 2025-12-27 with head old-release-sha. Result at the PR head: #515 is still linked (probe test below fails, pullRequestId is set).
Fix: anchor to when the workspace started tracking its current branch, not when the row was created. syncWorkspaceRow already detects the branch change (pull-requests.ts:967); record a dedicated branchChangedAt there (needs a host-DB migration) or reuse updatedAt if renames bumping it is acceptable, and compare closedAt against max(createdAt, branchChangedAt). At minimum, state the limitation in the PR body, since the description implies staging/develop are covered.
packages/host-service/src/workspaces/local-workspace-store.ts:273 — adoption paths (adopt-existing-worktree.ts:127,205) stamp createdAt = now. Adopting an existing worktree whose PR already merged, while its local HEAD is behind the PR head (for example the PR got a GitHub "Update branch" or suggestion commit that was never pulled), now loses its link and history row. Rare, but it is a new regression of a working link. Fix: for adoption, fall back to "HEAD is an ancestor of the PR head" instead of strict equality, or accept and note it with the existing trade-off.
pull-requests.ts:749 — forgetEarlierBranchUseLinks runs a join query for every workspace on every sweep and the workspaces join only re-checks archivedAt for a row the caller already holds. Not a bug; could be one project-level query, like the sweep's other bulk reads.
Evidence
Host-service runtime (API surface) — verified
PR suite at head acd10db9:
$ bun test src/runtime/pull-requests 122 pass 0 fail 332 expect() calls Ran 122 tests across 5 files. [2.12s]
The PR's tests against the base implementation (base pull-requests.ts + github-query files from 340f4ae6, PR tests kept) — confirms the author's claim that 3 fail without the fix:
(fail) earlier use of a branch name > drops a PR that merged before the workspace existed from its link and history (fail) earlier use of a branch name > does not link a PR that was closed without merging before the workspace existed (fail) earlier use of a branch name > drops an older merged PR from history while a new PR on the branch is open 2 pass 3 fail
Probe for finding 2 (local edit, not pushed): workspace created 2025-06-01 on release, PR #515 merged 2025-12-27, HEAD ≠ PR head:
PROBE linked: e64fa2d4-bcbe-428e-b201-e80843f8ff4b (fail) review probe > PROBE: long-lived workspace that switched to a reused branch still links the old PR 122 pass 1 fail
tsc --noEmit (host-service): exit 0. biome check on src/runtime/pull-requests: clean.
Desktop sidebar / activity panel — not verified
Two attempts to start the dev stack for CDP verification failed: bun dev stopped on turbo's concurrency check (4 persistent tasks, concurrency 4); the retry with --concurrency=8 failed with EADDRINUSE :3001 for the API and an @superset/i18n compile failure in web/desktop predev. No screenshots were captured. The author's PR body reports a before/after CDP reproduction on a release workspace; I did not reproduce it.
Questions for the author
- Was Martin's workspace freshly created, or a long-lived (likely
local) workspace that switched branch? If the latter, this PR does not fix his case (finding 2). - Is dropping the link when HEAD moves past an old checked-out PR's head intended for PRs that were linked via upstream, not only no-upstream checkouts? The history row is deleted too, so the activity panel loses it for good.
- Should
closed_atparsing reuse a helper named for its purpose rather thanparseMergedAt(github-query.ts:130)? Behaviour is fine; the name reads wrong.
Test / CI notes
- Commit reviewed:
acd10db9175cbe5c7603a4f2d20125fc15f7a4f3(base340f4ae6). - CI at time of review: all completed checks pass (Lint, Typecheck, Test, Sherif, etc.); CodeRabbit and the mobile development-client build were still pending. Nothing failing.
- Ran locally:
bun test src/runtime/pull-requests(122 pass), base-vs-head check of the new tests, one probe test (reverted),tsc --noEmit,biome check. Did not run the full host-service suite. - No tRPC or DB schema change, so trpc-compat and db-migrations rules do not apply. No user-facing strings, so no i18n impact.