Repository navigation
fix(workspaces): re-seed a gate-reported empty workspace after an agent selection - #20182
Conversation
…nt selection #19940 routed two different questions through one predicate. An agent selection justifies skipping the *pre-emptive* shell at create time, but it was also suppressing the async activation gate's fail-closed re-seed. The gate returns `empty` only after adoption, structured inventory and resume all produced nothing, so it is positive evidence the agent surface never arrived (dead PTY, unreadable census, null startup plan) — exactly when the re-seed is needed. Suppressing it there left the workspace with zero tabs and no recovery: ensureWebRuntimeWorktreeTerminalAfterWake returns early for a plain local workspace, so nothing else seeds one. `gatedEmptyOutcomeReseedSuppressed` now answers the re-seed question on its own, honouring only an explicit `providesInitialSurface` caller promise — restoring v1.4.200's behaviour for that path. The create-time skip keeps using the agent-inclusive `activationProvidesInitialSurface` unchanged.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change makes gated empty-workspace reseeding accept explicit caller-surface and execution-host values. Folder and worktree activation pass these values to the gate. Reseeding skips caller-provided surfaces, inactive workspaces, and mismatched execution hosts. Tests cover surface selection, pending activation replacement, recovery races, and local and SSH workspace state. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Rapidly switching a workspace between local and SSH activation can leave the workspace with an incorrect terminal surface or no terminal surface. The gate result must remain bound to the host that produced it before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Split the gate's re-seed predicate from the create-time promise — new
gatedEmptyOutcomeReseedSuppressed(worktree-activation-surface-selection.ts:47) returns true only for an explicitprovidesInitialSurface, so an agent selection no longer suppresses the fail-closed re-seed after the async gate reportsempty. - Both activation entry points use it — the folder callback (
worktree-activation.ts:154) and the git callback (:253) now pass the narrower predicate instead ofactivationProvidesInitialSurface. Create-time seeding (#19940) is untouched, so no stray "Terminal 1" beside a live agent. - Contract recorded in docs —
reseedGatedEmptyWorkspace's doc (worktree-initial-terminal-seeding.ts:38) tells callers to derive the flag from the new predicate, never from an agent selection. - Four new cases pin both sides on both paths — agent selection re-seeds (1 tab); agent +
providesInitialSurfacestays empty (0 tabs), for bothactivateAndRevealWorktreeandactivateAndRevealFolderWorkspace.
I verified the split is real and the coverage bites: the new test file passes at head (24 tests), and reverting only the two call sites to providesInitialSurface fails exactly the two agent-selection rows (:109, :370) while the providesInitialSurface: true rows stay green — matching the PR's ablation. pnpm tc:web and oxlint on all four files are clean, and the sibling activation suites (37 tests) pass.
The one deliberate asymmetry is sound: an explicit providesInitialSurface still suppresses the gate re-seed because those callers (editor/diff/structured chat) own their surface, while empty is positive evidence that an agent surface never materialized.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Reframed the gate re-seed predicate as an explicit policy —
gatedEmptyOutcomeReseedSuppressedbecomesgatedEmptyWorkspaceReseedPolicy, returning'reseed' | 'caller-provides-surface'(worktree-activation-surface-selection.ts:44). The folder (worktree-activation.ts:153) and git (:252) callbacks now gate on=== 'reseed'and callreseedGatedEmptyWorkspace(key, false). Behavior is unchanged from the previous commit: an explicitprovidesInitialSurfacestill suppresses, an agent selection no longer does. - Added SSH-host coverage to the folder re-seed case — the folder matrix now parameterizes
executionHostId, including anSSH_HOST_IDrow that asserts the re-seeded tab resolves to the host'sconn-1connection viagetRemoteConnectionIdForWorktree. - Trimmed comments and dropped the doc-only edit — the
worktree-initial-terminal-seeding.tsJSDoc change is no longer part of the PR, so the diff is back to 3 files.
I re-ran the file at head (25 passed) and ablated the policy back to treating an agent as 'caller-provides-surface': exactly the three agent rows fail (:107, :376 local and SSH), while the providesInitialSurface rows stay green. pnpm tc:web and oxlint on the three files are clean.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Electron QA completed on the rendered app, including a current- One limitation up front: I could not complete the full New Workspace modal flow under the required hidden-window launch. Both clicking New workspace through Playwright and calling the real Empty-prompt Codex path: current
|
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes
This run re-reviewed commit 278e5ed3 ("harden gated empty reseeding"), the delta since pullfrog's previous review at 5f01512c.
- Replaced the policy predicate with per-gate intent tracking —
gateAndReseedEmptyWorkspacerecords{ callerProvidesSurface, executionHostId }in aWeakMapkeyed by the in-flight gate promise, so concurrent activations that share one gate resolve theemptyoutcome with the newest caller's intent only. - Added a stale-host guard to the re-seed —
reseedGatedEmptyWorkspacenow takesexecutionHostIdand skips when the active workspace host no longer matches, so a gate settling after the user switched hosts cannot seed into the wrong one. - Made active-folder connection resolution host-aware —
getFolderWorkspaceConnectionIdaccepts an explicit host, andgetConnectionIdFromState, the retained file selector,worktreeUsesWslPath,worktreeUsesRemoteConnection, andgetRemoteConnectionIdForWorktreeall thread the active workspace host through. - Expanded coverage — folder rows for local + SSH and duplicate-id routing, plus gate-supersession and no-double-seed cases.
I re-ran the three affected suites (56 passed), pnpm tc:web (clean), and audited the host-routing and async-supersession paths independently; both found the new logic consistent.
ℹ️ The PR description still describes the pre-hardening change
The body says "Net source change: 3 lines (1 import + 2 call sites)", "Cherry-pickable: 4 files", and "Which existing assertion changed: none", and the removed test comment called the host-blind resolution defect out of scope. At 278e5ed3 the PR is 10 files and changes how every active folder workspace resolves its connection. A reviewer or merger reading the description would badly underestimate the blast radius.
Technical details
# Update the PR description for the hardening commit
## Affected sites
- PR body `## What Changed` — still claims "Net source change: 3 lines (1 import + 2 call sites)".
- PR body `## Notes` — still claims "Cherry-pickable: 4 files, renderer-only".
- PR body `## Testing` — the "Which existing assertion changed: none" section and the ablation numbers predate `278e5ed3`.
- `worktree-activation-emptied-workspace-reseed.test.ts` — the removed comment that declared the host-blind connection defect out of scope is gone because the commit fixes it.
## Required outcome
- The description should describe the current 10-file change: the per-gate intent supersession, the stale-host re-seed guard, and the host-aware folder connection resolution.
- Call out the blast radius: while a folder workspace is active, its file/terminal connection resolution now depends on `activeWorkspaceExecutionHostId`, not just the workspace row.openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| if ( | ||
| callerProvidesSurface === true || | ||
| state.activeWorktreeId !== workspaceKey || | ||
| (executionHostId !== undefined && state.activeWorkspaceExecutionHostId !== executionHostId) |
There was a problem hiding this comment.
The new executionHostId guard has no coverage: every folder re-seed test sets activeWorkspaceExecutionHostId to the requested host before the gate settles, so a regression that always or never skipped on host mismatch would still pass. A case that moves the active host after the gate starts — e.g. setActiveFolderWorkspace(FOLDER_ID, SSH_HOST_ID) while a local gate is pending, then resolving it 'empty' — and asserts zero tabs would pin it.
There was a problem hiding this comment.
ℹ️ No new issues — this delta splits the folder-routing change out of the PR; the re-seed fix itself is unchanged and green.
Reviewed changes
This run re-reviewed commit 54bca206 ("chore(workspaces): split duplicate-folder routing fix"), the delta since pullfrog's previous review at 278e5ed3.
- Split the host-aware folder connection routing out of the PR — reverted
getFolderWorkspaceConnectionId's explicit-host parameter and the host threading throughgetConnectionIdFromState, the retained file selector,worktreeUsesWslPath,worktreeUsesRemoteConnection, andgetRemoteConnectionIdForWorktree, restoring main's host-blind resolution. - Trimmed the folder re-seed tests to match — the gate rows keep their tab-count and active-host assertions but drop the connection-resolution assertions that the split removed.
- Left the gate re-seed fix and its hardening intact —
gateAndReseedEmptyWorkspace, theWeakMaplatest-intent supersession, and thereseedGatedEmptyWorkspacestale-host guard are unchanged.
I verified the revert is clean (no dangling references to getSelectedExecutionHostId, the removed policy predicates, or the 3-arg signature; every call site uses the 2-arg form), re-ran the re-seed suite (27 passed at head), and pnpm tc:web exits 0.
One prior inline thread (missing coverage for the executionHostId guard's mismatch branch) remains open and unchanged by this commit, so this run does not approve.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/lib/worktree-initial-terminal-seeding.ts (1)
39-50: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftPreserve
executionHostIdduring terminal seeding.reseedGatedEmptyWorkspaceuses the host only for its guard, then passes the bare worktree ID toensureWorktreeHasInitialTerminalandcreateTab. The repository supports the same worktree ID on multiple hosts, while bare lookup uses the first matching row. Therefore, an empty SSH reseed can create a terminal through another host's connection. Pass the selected host through terminal creation or use a host-qualified lookup.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 77cd1325-08f4-451c-9b01-ddf00fc450ab
📒 Files selected for processing (1)
src/renderer/src/lib/worktree-activation-emptied-workspace-reseed.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/lib/worktree-activation-gated-empty-reseed.ts (1)
18-38: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftKey the activation gate by execution host
gateWorktreeAgentActivationdeduplicates only byworkspaceKey, butlistActivationPtySessionsperforms a host-scoped census. If local activation starts a census and SSH activation occurs before it settles, the SSH call reuses the local promise whilelatestReseedIntentByGatereplaces the intent with SSH. A localemptyresult can therefore reseed SSH without checking SSH, while a localadoptedorresumedresult can suppress a required SSH reseed. Capture the host for the census and key the in-flight gate by(workspaceKey, executionHostId), or enforce an equivalent host-matching result before applying the latest intent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 655ab90c-ff5f-4a86-bff4-be1dd9836a86
📒 Files selected for processing (2)
src/renderer/src/lib/worktree-activation-gated-empty-reseed.tssrc/renderer/src/lib/worktree-activation.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.






ELI5
Creating a workspace with an agent used to leave it with an empty tab bar when the agent's surface failed to appear. The safety net that normally drops a shell in an empty workspace had been switched off for agent selections. This turns that net back on, while keeping the fix that stopped a stray "Terminal 1" appearing next to every agent.
What Changed
activationProvidesInitialSurface(added in #19940) answers "is a surface coming?" — true for anyagent != null. That one value was being used for two different questions inworktree-activation.ts:empty-outcome re-seed — this was the bug.Added
gatedEmptyOutcomeReseedSuppressedinworktree-activation-surface-selection.ts, deliberately narrower: only an explicitprovidesInitialSurfacecaller promise suppresses the re-seed. Both gate callbacks (git worktree at:253, folder workspace at:154) now use it. The two predicates sit adjacent with comments explaining why they must not be re-unified, andreseedGatedEmptyWorkspace's doc records the contract.Net source change: 3 lines (1 import + 2 call sites), plus comments.
Why
gateWorktreeAgentActivationreturns'empty'only after PTY adoption, structured-session inventory, and sleeping-session resume have all produced nothing — the gate's own comment calls it "this gate produced no surface, seed one." It is positive evidence that no surface materialised, not a "couldn't tell" (that's'blocked', which never re-seeds).So an agent selection and a gate-reported empty are different facts. The selection is a request;
emptyis the report that the request produced nothing — a dead PTY, an unreadable PTY census, or a null startup plan. Suppressing the fail-closed re-seed (STA-5701) on that report is what left the workspace with zero tabs. Nothing else recovers it:ensureWebRuntimeWorktreeTerminalAfterWakereturns early atweb-runtime-worktree-terminal-after-wake.ts:39when no web-runtime session is active, so for a plain local workspace it is a no-op.Reachable from
worktree-creation-flow-execute.ts:170andfull-creation-execution.ts:220, which passagentwith no explicitprovidesInitialSurface; when the backend already spawned the startup terminal there is nostartup/setup/defaultTabs/issueCommand, sohasActivationWorkis false and the gate runs.Why only the agent half, rather than ignoring the predicate entirely: pre-#19940 this path passed
opts?.providesInitialSurface, so honouring the explicit promise is exactly v1.4.200's shipped behaviour. Dropping that half too would change behaviour v1.4.200 shipped and no bug report covers, and would mean editingforwards providesInitialSurface=%s through the async activation gate— an assertion that predates #19940 and encodes the editor/diff-caller intent. This fix edits no existing assertion. That also keeps it cherry-pickable.Linked Issue
Regression from #19940 (
2ffac471bd), which is not in v1.4.200 (git merge-base --is-ancestor 2ffac471bd v1.4.200fails), so this ships new.Fixes #
Visual Proof
N/A— no rendering change. The observable difference is tab count in a failure path that needs a dead agent PTY to reproduce; it is covered by the unit tests below rather than a screenshot.Testing
Which existing assertion changed: none
The
['an agent', 'codex' as const, 0]cases inworktree-activation-emptied-workspace-reseed.test.ts(:37,:256) were the suspected pin. They are not pinning the defect — they exercise the create-time path, not the gate. In both,canInspectAgentActivationInventory()is false (nowindow.apistub) and there are no sleeping sessions, soshouldGateAgentActivationis false and the gate is never entered. Expecting 0 tabs there is #19940's legitimate no-stray-shell behaviour, so they are kept as-is and still pass. No assertion anywhere pinned the gate+agent path — it simply had no coverage, which is how the regression landed.Checked #19940's siblings for the same pin:
worktree-activation-empty-remote.test.ts,worktree-creation-agent-seeding.test.ts,worktree-activation-web-runtime.test.ts,worktree-activation-surface-caller-wiring.test.ts. None assert the gate+agent outcome;worktree-creation-agent-seeding.test.ts:75only asserts theagentoption is forwarded.gateWorktreeAgentActivationis referenced by only one other test file (app-startup-routing.test.ts, source-text assertions). No sibling needed a change.New coverage
Four cases added, pinning both sides of the split on both activation entry points — the folder-workspace twin goes through
activateAndRevealFolderWorkspace, notsetActiveWorktree(folderWorkspaceKey(id)), which never reaches the folder path:activateAndRevealWorktree{ agent: 'codex' }activateAndRevealWorktree{ agent: 'codex', providesInitialSurface: true }activateAndRevealFolderWorkspace{ agent: 'codex' }activateAndRevealFolderWorkspace{ agent: 'codex', providesInitialSurface: true }The
providesInitialSurface: truerows guard against over-broadening the fix into ignoring the caller promise.Ablation (measured)
Both source files reverted to
origin/mainwith the new tests kept — not a one-lever arm:origin/main, new tests kept): 2 failed | 22 passed. The two failures are exactly the agent-selection rows:expected [] to have a length of 1 but got +0at:109(git) and:370(folder). The twoprovidesInitialSurface: truerows pass on both arms, as intended — they pin the half deliberately preserved.app-startup-routing.test.ts.shasum), and the pre-commit hook changed nothing, so the ablation holds at this head.Create-time behaviour still pinned
Confirmed —
seeds a default shell for %s selection only(both the git and folder copies, including theagent → 0 tabsrows) is untouched and green, so this cannot silently reintroduce #19940's stray "Terminal 1".Gates
oxlinton all 4 changed files: exit 0, zero errors, zero warnings. Nomax-linesdisable added (largest file 349 lines, cap 400 with blanks/comments skipped).tsc --noEmitrun sequentially onconfig/tsconfig.tc.web.json,config/tsconfig.node.json,config/tsconfig.tc.cli.json: all exit 0, no output.oxfmtreports no changes.NUL-byte scan on all 4 changed files: clean.
pnpm-lock.yamlrestored toorigin/mainand excluded from the commit.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
ensureWorktreeHasInitialTerminalbecause the host owns terminal creation, so this does not seed into an SSH/runtime host's gap. The folder-workspace tests cover an SSH-host row sharing onetabsByWorktreekey.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)