PR #9715 review: stop linking PRs that closed before the workspace existed

PR #9715 · Review workspace · author harshithmullapudi · reviewed at acd10db9 · 2026-11-13

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

High · repo hygiene

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.

Medium · correctness

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.

Low · edge case

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.

Low · nit

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

Test / CI notes