Skip to content

fix(workspace): closing the last editor keeps the workspace selected - #471

Merged
nplez1 merged 4 commits into
mainfrom
nplez1/issue-96-empty-tabs-state
Nov 26, 2026
Merged

nplez1 merged 4 commits into
mainfrom
nplez1/issue-96-empty-tabs-state

Conversation

@nplez1

@nplez1 nplez1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Refs #96

Possibly already fixed — what #185 already delivered

Most of #96 shipped in #185 (095cf327059, merged 2026-10-25, "Refs #96"):

  • Closing the last terminal, browser or chat tab keeps the workspace selected (terminal-tab-actions.ts:244-268, tabs-close-actions.ts:184-186).
  • The empty-tabs surface WorkspaceEmptyState renders in TabGroupPanel.tsx:402.
  • An emptied workspace does not read as sleeping (use-worktree-sleep-state.ts:73-109).
  • Re-activation honours the terminal close record instead of seeding a terminal (worktree-initial-terminal-seeding.ts:190-198, use-terminal-startup-activation.ts:87-91).

The tests the issue names (store-active-worktree-tab-close.test.ts, worktree-activation-emptied-workspace-reseed.test.ts) were deleted upstream; workspace-emptied-on-purpose.test.ts (10 cases) still passes.

What this PR changes

  • Editor close no longer deselects. closeFile and closeAllFiles (close-file-action.ts, recently-closed-editor-tabs.ts) still wrote the landing patch feat(workspace): keep an emptied workspace open on its own empty-tabs surface #185 removed elsewhere: open a file, close the terminal, close the file, and the workspace dropped to Landing. They now keep it selected; unified-tabs-keep-worktree-selected.ts, used only there, is deleted.
  • Surface instead of a blank pane. useTabGroupWorkspaceModel.ts also shows the empty-tabs surface when the workspace was emptied while on screen, which covers a last chat, browser or editor close that writes no terminal close record. The mark resets whenever the workspace leaves the screen, so a retained pane cannot carry it into a later visit (sleep, or an unrecorded empty workspace re-seeding on return).
  • Dead code. tabs-empty-workspace.ts (emptiedWorktreeLandingPatch, landOnEmptiedWorktree) had no callers after a sync re-homed it; deleted with its re-export.
  • Store test last-editor-close-keeps-workspace.test.ts: real closeFile / closeAllFiles on the only file of the active workspace write no landing patch. Fails on the base versions (expected null to be 'wt-1').
  • Layout-writer baselines pruned (pnpm check:layout-writer-ratchets --prune). Besides the deleted tabs-empty-workspace.ts row, the prune removed four rows already stale on base — pty-binding-persistence.ts, ssh-target-id-migration.ts, use-agent-pane-threads.ts, use-worktree-activity-statuses.ts. Unrelated drift; counts only went down.

Remaining gaps (why this is Refs, not Fixes)

  • No terminal close record → sleeping and re-seed. A workspace emptied by an editor, browser or chat close, with no terminal close in the record's 30 days, reads Sleeping once deselected (and "Hide sleeping" hides it), and re-opening or restarting seeds "Terminal 1". Closing it needs a persisted workspace-level "emptied on purpose" record; the terminal record's persistence spans 34 shared/main files (session schema, host field ownership, WSL-move and profile-transfer dispositions, migrations), so it is a follow-up.
  • 30-day exemption. The close-record exemption from sleeping lasts the record's TTL, even after the user leaves the workspace.
  • Mobile "Hide sleeping" reads host-stamped activity facts, not close records, so it may still hide an emptied workspace.
  • Host re-mirror flash. A host list that drops every row and re-mirrors while on screen shows the surface until its rows return.

Verification

Rebased onto main @ 323e127eb81 after the conflict, then again onto 1c437ac03c3 once the gate fix below
landed. The only conflicting file was local/upstream-file-comments-baseline.json (a regenerated ratchet
artifact), resolved as the union of both sides — total 4767 → 4763 and useTabGroupWorkspaceModel.ts 7 → 6,
measured by node local/check-upstream-file-comments.mjs (4763/4763, 0 stale). No source hunk conflicted: main
changed none of the files this branch touches, and the code commits are byte-identical to the reviewed R2.
Every row below was re-run on the final revision.

The lint gate was red on this branch for a reason that was not this branch's: #466 wired a host-group seam
register into gate-lint.mjs which failed on any upstream-owned file a diff touched, and this diff touches
eight of them. JSON that the diff does not declare is not a declaration this PR can make honestly, so it is fixed
where the defect is — #484 scopes the register to that feature's own diffs and is on main as 1c437ac03c3.
The gate is green here now.

Check Result
pnpm tc:web clean
pnpm test src/renderer/src/store/slices/editor/closing/last-editor-close-keeps-workspace.test.ts --maxWorkers=2 2 passed; both fail with the base editor-close files restored
pnpm test src/renderer/src/components/tab-group/TabGroupPanel.empty-workspace.test.tsx --maxWorkers=2 3 passed
pnpm test src/renderer/src/components/tab-bar/model/tab-bar-item-surface.test.ts --maxWorkers=2 2 passed
pnpm test src/renderer/src/components/editor/save/flush/discard-editor-file-changes.save-race.test.ts --maxWorkers=2 5 passed
pnpm test src/renderer/src/lib/workspace-emptied-on-purpose.test.ts --maxWorkers=2 10 passed
pnpm test src/renderer/src/components/workspace-empty-state/WorkspaceEmptyState.test.tsx --maxWorkers=2 5 passed
pnpm check:changed 40 of 42 passed; max-lines-ratchet (src/main/host-mesh/host-mesh-driver.ts, src/main/host-mesh/host-mesh-rpc-service.ts, src/main/startup/runtime-startup/main-process-runtime-launch.ts) and react-compiler-compat-ratchet (src/renderer/src/components/settings/runtime-environments/host-group/use-host-group-snapshot.ts, src/renderer/src/components/status-bar/host-connections/use-relayed-fleet-hosts.ts) fail identically on base 1c437ac03c3 — all five are the host group's rows, already allowlisted in local/lint-known-red.json, none is in this diff
orca-queue node local/gate-unit.mjs Unit gate @a04a1c9ebc (clean): PASS — 11028 passed; 0 failed (0 allowlisted, 0 unexpected); 0 flaky re-run passed; 0 unhandled error headline(s); 61 s
node local/checks/host-mesh-upstream-seams.mjs --base origin/main exit 0, 8 upstream files / 158 lines as notes
node local/check-upstream-file-comments.mjs 4763/4763, 0 stale
CI on a04a1c9ebc9 fork-pr-gates: lint gate pass (4m02s), typecheck pass, changed lines pass
App not launched — the surface's on-screen behaviour is reasoned from code

Full unit suite: gate 1 PASS on the committed revision (this diff touches config/**); nightly and again at release.

Reviewed by Opus 5.5, high: R1 (1 blocking fixed), delta clean on R2

The rebase conflicts resolved above touch no source file, so R2 still covers every reviewed hunk; the
only post-review edit is the regenerated fork-comment baseline.

Review NITs, not acted on

  • Reopening a workspace while its sleep teardown is still running shows the empty surface until the re-seed lands (useTabGroupWorkspaceModel.ts:89-96). Rare, and arguably correct.
  • close-file-action.ts: a pre-existing activeBrowserTabId overwrite; untouched.

🤖 Generated with Claude Code

@nplez1
nplez1 force-pushed the nplez1/issue-96-empty-tabs-state branch from cb9b0bb to 815fb3e Compare November 26, 2026 07:48
nplez1 added a commit that referenced this pull request Nov 26, 2026
…er feature's PR (#484)

#466 wired `check-host-mesh-upstream-seams` into the lint gate, where it runs on every pull
request, and it failed on any upstream-owned file a diff touched. The first branch to run it
after that merge was #471, a workspace state fix touching eight upstream renderer files and no
host-group seam at all, so the gate went from green to red for a whole class of work.

A register of one feature's surface cannot demand a declaration from features it does not
describe. The budget of a declared seam still fails hard — that is the guarantee the file
exists to keep — and an undeclared upstream file is reported as a note. `--strict` restores
the red for the host group's own branches, where an undeclared hook is exactly the sprawl the
check was built to catch.

The same change fixes a latent crash the old exit-early path hid: the verbose listing read
`seam.budget` for every touched file.
nplez1 and others added 4 commits November 26, 2026 00:21
…pty-tabs surface

#185 kept an emptied workspace selected for terminal, browser and chat closes,
but the two editor close paths still wrote the old landing patch: closing the
last file of a workspace with no terminal or browser row (for example after the
terminal was closed first) nulled activeWorktreeId and showed Landing.

- closeFile and closeAllFiles no longer deselect the workspace; the
  now-unused unifiedTabsKeepWorktreeSelected goes with them.
- The empty-tabs surface also renders when this pane has already shown
  content, so a last chat, browser or editor close that writes no terminal
  close record lands on the surface instead of a blank pane. The close record
  still governs re-activation and restart, where the pane has no history.
- Delete tabs-empty-workspace.ts: emptiedWorktreeLandingPatch and
  landOnEmptiedWorktree had no callers after a sync re-homed them.

Refs #96

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t visit

Review round 1 of the editor-close fix.

- The pane's "has shown content" mark resets whenever its workspace leaves
  the screen, so a retained pane cannot flash the surface on a later visit:
  sleep deselects before tearing tabs down, and an unrecorded empty
  workspace re-seeds on return. A host list that drops every row and
  re-mirrors while on screen is the remaining case, noted at the mark.
- Pin the store invariant: closeFile and closeAllFiles on the only file of
  the active workspace leave it selected. A sync restored the landing patch
  once already.
- Prune the layout-writer baselines after tabs-empty-workspace.ts went away.

Refs #96

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… files

The lint gate's check-upstream-file-comments step counted 9 fork comment lines
this branch added to upstream-owned files (4776 against a baseline of 4767).

- Drop the two "no deselect" comments in close-file-action.ts and
  recently-closed-editor-tabs.ts; the rationale is in the fix commit.
- Fold the surface gate's two comment blocks in useTabGroupWorkspaceModel.ts
  into one six-line block, under the file's baseline of seven.
- Lower the baseline to 4766 with --prune.

Moved out of the code: a host list that drops every row and re-mirrors while
its workspace is on screen shows the empty-tabs surface until its rows return.

Refs #96

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nplez1
nplez1 force-pushed the nplez1/issue-96-empty-tabs-state branch from 815fb3e to a04a1c9 Compare November 26, 2026 08:23
@nplez1
nplez1 merged commit 8293fd7 into main Nov 26, 2026
10 checks passed
@nplez1
nplez1 deleted the nplez1/issue-96-empty-tabs-state branch November 26, 2026 08:35
nplez1 added a commit that referenced this pull request Nov 26, 2026
…repeating them

R4's minors: the seam paragraph pointed at "the anchors below" when they sit above
it and repeated the allowlist paragraph's sentence; and the Verified paragraph
credited two of the three pre-rebase dispatches while saying three.

The run at 449bc7d — the rebased branch — is green on all three legs, the
test that reddened taking 26,170 ms.

Rebased again onto 8293fd7 (#471), which pruned the comment baseline by one:
the entry's 4764/4764 is now 4763/4763.
lab-agent-np Bot added a commit that referenced this pull request Nov 26, 2026
* local(test): the perf contract Windows reddens on wall clock, not its count

fork-performance-contracts reddened on main at 767c078 (run 45683322849):
the windows-latest leg timed out at 30s on
journal-domain-operation-window.performance.test.ts:377, while the other two
legs passed and the 11-23 run was green only because the file had not reached
main yet.

The contract counts rows returned, not time. Its fixture builds ten chats of up
to 500 turns in tmpdir(), which is 1.6s here and 33,065ms on windows-2022 —
Defender scans every write, so the per-turn cost is ~20x and no product code is
slow.

Two closing }) lines become }, 120_000): the failing test, which upstream fixed
the same way in 7b6c852 (stablyai#47789) after our sync base, and the file's other
fixture-heavy test, which passed by 3.5s on that runner (26,488ms of 30s on
windows-2022, 18,920ms on ubuntu-24.04) and is the slowest test in the lane.

No allowlist widened: both tests still run on all three legs and assert the
same counts. LOCAL-PATCHES.md carries the reason and the anchors.

* local(test): the timeout bumps carry the reason the flaky-test ratchet demands

`pnpm check:changed` refused the two `}, 120_000)` lines: the fork's
`test-timeout-needs-reason` rule requires a reason comment directly above a
per-test timeout, and that rule is right — it is what stops a timeout bump from
hiding a slow test.

Each comment is one line marked `fork-comment-ok:`, so
`check-upstream-file-comments` stays at 4764/4764 rather than growing: the
reason belongs in LOCAL-PATCHES.md, and the marker is the documented way to put
the pointer above upstream's code.

Also corrects the entry from the review: twelve chats, not ten, and the Defender
explanation is stated as the likely cause rather than a measured one.

* local(test): declare the test file's six-line seam, as the seams register requires

`gate-lint`'s `check-host-mesh-upstream-seams` refused the change: an
upstream-owned file the fork touches must be a declared seam with a measured
budget, so the surface a sync pays for stays visible instead of silent.

Budget 6 is what this costs today (two timeouts, two reason comments, two
replaced lines). It only shrinks: the next sync brings upstream's own
`}, 120_000)` and comment, after which our line there is identical.

* local(test): record the green Windows run, and what the sync will collide with

The delta review found the entry claiming the next sync "needs no decision": upstream
7b6c852 inserts its comment at exactly the spot our `fork-comment-ok:` line
occupies, so that hunk collides. The resolution is now written down: keep
upstream's comment, drop ours, keep the timeout.

The run evidence replaces the forward reference: run 45780910456 at 803bad1
is green on all three legs, the test that reddened taking 26,610 ms against
33,065 ms on the red run.

* local(test): name both dispatches, and the tests by title rather than by line

R3's minors: the entry credited only one of the two green dispatches, and the
line numbers are where the tests sat on the red run — they have moved. The
seam paragraph names the test it means instead of "the second".

* local(test): drop the seam row #484 made unnecessary, and wrong to keep

main's #484 scoped `check-host-mesh-upstream-seams` to the host group's own
diffs: an undeclared upstream file is a note for any other feature, and only a
declared seam's budget fails hard either way.

This diff carries no hosts path, so the row was not required — and keeping it
would have put a hard budget on a test file that is not hosts work, so the next
branch to grow it would red the lint gate for a reason #484 exists to remove.
The register is main's file again; the entry records why, and its anchors are
the two `it(...)` titles.

* local(test): record the post-rebase run, and the two anchors without repeating them

R4's minors: the seam paragraph pointed at "the anchors below" when they sit above
it and repeated the allowlist paragraph's sentence; and the Verified paragraph
credited two of the three pre-rebase dispatches while saying three.

The run at 449bc7d — the rebased branch — is green on all three legs, the
test that reddened taking 26,170 ms.

Rebased again onto 8293fd7 (#471), which pruned the comment baseline by one:
the entry's 4764/4764 is now 4763/4763.

---------

Co-authored-by: Nathan Plesnicher <[email protected]>
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.

1 participant