Skip to content

feat(workspace): allow selecting empty workspaces without auto-terminal - #11159

Closed
innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/empty-workspace-no-auto-terminal
Closed

innocarpe wants to merge 2 commits into
stablyai:mainfrom
innocarpe:fix/empty-workspace-no-auto-terminal

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Description

Re-selecting a workspace after all tabs were closed no longer auto-creates a blank terminal or relaunches the creation agent. The workspace can stay empty until the user explicitly opens a tab.

Focused fix

  • In scope: gate ensureWorktreeHasInitialTerminal on first-activation / explicit create work; remove Terminal.tsx auto-create-on-activate effect; regression tests
  • Out of scope: new Settings toggle (not required for minimal fix), dedicated empty-state redesign

Preserves

  • First activation this session still seeds a terminal (and creation agent when configured)
  • Explicit create/launch paths with startup/setup/defaultTabs still seed as before
  • Folder workspaces follow the same reselect policy

Evidence

  • worktree-activation* + empty-reselect + related store tests green (see suite run in worktree)

User-regression-tradeoffs

  • After restart, first activation of a previously emptied workspace may still seed a terminal (everActivated is session-scoped). Same-session empty reselect is fixed.

Fixes #11108

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4325797-c7ad-4002-9caa-f05b6d68c233

📥 Commits

Reviewing files that changed from the base of the PR and between 05fccb8049d7e0d1f43d49b8f29da842438d529b and 373b3afcbac943edce5a3804bef288827526f310.

📒 Files selected for processing (1)
  • src/renderer/src/lib/worktree-activation-empty-reselect.test.ts

📝 Walkthrough

Walkthrough

Initial terminal seeding moved into worktree activation logic. Terminals are created on first activation or when explicit activation work is requested, while reselecting an emptied worktree leaves it empty. Terminal rendering no longer performs automatic tab creation. Tests cover empty reselection and explicit startup seeding, and the createdWithAgent documentation reflects the updated behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change well, but it omits required template sections like Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Add the missing template sections, including screenshots or 'No visual change', the test checklist, AI review report, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: allowing empty workspaces to remain empty without auto-terminal creation.
Linked Issues check ✅ Passed The code and tests implement #11108 by preventing terminal/agent seeding on empty workspace reselection while preserving explicit-startup and first-activation paths.
Out of Scope Changes check ✅ Passed The changes stay focused on workspace reselection behavior, regression tests, and related comments/docs, with no clear unrelated code introduced.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f72ea4c-4471-4ccd-a64b-cb21c5b64028

📥 Commits

Reviewing files that changed from the base of the PR and between 0404f27 and f04a52aca3da17e3e6a82f7de2b0753cf01c3677.

📒 Files selected for processing (5)
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/lib/worktree-activation-created-agent.test.ts
  • src/renderer/src/lib/worktree-activation-empty-reselect.test.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/shared/types.ts

@innocarpe
innocarpe force-pushed the fix/empty-workspace-no-auto-terminal branch from f04a52a to 05fccb8 Compare July 29, 2026 01:01
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (05fccb804)

Rebase onto main + CodeRabbit: skip sleeping-agent resume on empty workspace reselect

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes #11108 by ensuring that re-selecting a workspace whose tabs were all closed no longer auto-creates a blank terminal or relaunches a sleeping agent session. The fix moves terminal seeding responsibility from a reactive useEffect in Terminal.tsx into the activation functions themselves, gated by a shouldSeedInitialTerminal predicate.

  • Terminal.tsx: The useEffect that called createTab whenever activeWorktreeId changed with no renderable tabs has been removed. The cold-restore path (startupResumeWorktreeIdsRef effect) is intentionally kept for startup hydration, and is naturally guarded by the ref so it fires at most once per worktree per session.
  • worktree-activation.ts: Both activateAndRevealWorktree and activateAndRevealFolderWorkspace now compute shouldSeedInitialTerminal before calling ensureWorktreeHasInitialTerminal and resumeSleepingAgentSessionsForWorktree. The isFirstActivation snapshot is captured before setActiveWorktree updates everActivatedWorktreeIds, so ordering is correct.
  • Tests: Four new scenarios cover empty-reselect suppression and explicit-startup seeding for both worktrees and folder workspaces.

Confidence Score: 5/5

Safe to merge — the change is tightly scoped to the activation path with no impact on explicit create/launch flows or cold-restore hydration.

The shouldSeedInitialTerminal guard is computed from a pre-activation state snapshot so the first-activation check is always accurate. The removed useEffect in Terminal.tsx was the only source of spurious tab creation on reselect; the remaining cold-restore effect is bounded by startupResumeWorktreeIdsRef. Tests cover all four scenarios for both workspace types.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/lib/worktree-activation.ts Core logic change: introduces shouldSeedInitialTerminal gate before calling ensureWorktreeHasInitialTerminal and resumeSleepingAgentSessionsForWorktree in both activation functions. Ordering is correct — isFirstActivation is captured from the pre-setActiveWorktree snapshot.
src/renderer/src/components/Terminal.tsx Removes the useEffect that auto-created a terminal tab on workspace activation. The cold-restore startupResumeWorktreeIdsRef effect is intentionally kept and bounded to fire at most once per worktree per session.
src/renderer/src/lib/worktree-activation-empty-reselect.test.ts New test file covering empty-reselect policy for both worktrees and folder workspaces across 4 scenarios.
src/shared/types.ts JSDoc update for createdWithAgent to reflect narrowed semantics — seeds only first-activation terminal, not every reselect.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[activateAndRevealWorktree / activateAndRevealFolderWorkspace] --> B{shouldSeedInitialTerminal?}
    B -- "isFirstActivation OR hasActivationWork OR initialCwd" --> C[resumeSleepingAgentSessionsForWorktree]
    C --> D[ensureWorktreeHasInitialTerminal]
    D --> E{renderableTabCount == 0?}
    E -- yes --> F[createTab + queueTabStartupCommand]
    E -- no --> G[return existing tabId or null]
    B -- "previously activated + no explicit work" --> H[skip resume + skip tab creation]
    H --> I[primaryTabId = null]
    F --> J[return primaryTabId]
    G --> J
    I --> J
Loading

Reviews (2): Last reviewed commit: "test(workspace): cover folder empty rese..." | Re-trigger Greptile

@innocarpe

Copy link
Copy Markdown
Contributor Author

Re: sleeping-agent resume on empty reselect — already gated on current HEAD:

  • Folder path: if (shouldSeedInitialTerminal) resumeSleepingAgentSessionsForWorktree(...) (~L213)
  • Git worktree path: same guard before ensureWorktreeHasInitialTerminal (~L298)

No further code change in this pass. Folder-workspace empty-reselect unit coverage is a nice-to-have follow-up if reviewers want it.

@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (373b3afcb)

Address review: folder empty-reselect tests + assert sleeping agents are not resumed

innocarpe and others added 2 commits August 3, 2026 15:29
Stop auto-creating a terminal/agent when re-selecting a workspace that
has no open tabs; keep create-flow launch behavior unchanged.

Fixes stablyai#11108
…stablyai#11159)

Greptile/CodeRabbit: assert empty folder reselect seeds nothing and does
not call resumeSleepingAgentSessionsForWorktree; keep git worktree cases.

Co-Authored-By: Grok Companion <[email protected]>
@innocarpe
innocarpe force-pushed the fix/empty-workspace-no-auto-terminal branch from 373b3af to 6458172 Compare August 3, 2026 06:30
@innocarpe

Copy link
Copy Markdown
Contributor Author

Closing this stale branch as superseded. The local empty-workspace path is already partially fixed on current releases, and the remaining local/remote landing-screen gaps are tracked separately in #17681 and #17682. Please continue there instead of rebasing this conflicting branch.

@AmethystLiang

Copy link
Copy Markdown
Contributor

Thank you so much, @innocarpe, for the earlier implementation and follow-up coverage here, and for clearly documenting the remaining local/remote gaps when you closed this branch. We referred to this PR and its discussion while checking the scope of the empty-pane launch UI that has now landed in #32182.

I have added a named acknowledgment and a link back to your PR in #32182. Your work separating intentional activation from unwanted terminal/agent recreation remains valuable context, and the remaining last-tab selection behavior is explicitly distinguished from the UI work in #32182.

Thank you again for the contribution and the care you put into the tests and discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Allow selecting an empty workspace without creating a terminal

3 participants