Fix workspace switch latency from hibernation portal reconcile
Summary
Fixes #7226.
Switching into an already-open workspace was running setAgentHibernationAutoResumePresentationVisible(true), which immediately performed a full terminal portal visibility reconcile. That path is meant to auto-resume hibernated agents, but for ordinary non-hibernated terminal panes it restored every terminal portal from inside SwiftUI visibility updates. Each restore calls GhosttySurfaceScrollView.setVisibleInUI(true) and refreshSurfaceNow, which forced AppKit layout once per visible terminal.
This narrows the auto-resume visibility gate so it only resumes visible hibernated panels. Normal terminal portal visibility remains owned by the existing SwiftUI/portal layout paths.
Regression coverage
Two-commit structure:
test: cover hibernation gate portal restoreadds a focused Swift Testing regression that fails onmain: toggling the hibernation presentation gate must not restore a non-hibernated terminal portal.fix: avoid portal reconcile on workspace auto-resume gatechanges the production call to resume hibernated panels only.
Evidence
Baseline debug log from current main on macOS 15.7.4 showed repeated workspace toggles where ws.handoff.complete finished around 105-113 ms, but selected workspace terminal visibility then advanced per surface around 193 ms through 648 ms, with ws.select.asyncDone around 1.2-1.35 s. The sample attributed the slow block to WorkspaceContentView visibility onChange -> GhosttySurfaceScrollView.setVisibleInUI -> refreshSurfaceNow -> AppKit layoutSubtreeIfNeeded.
Local verification
No local build, local tests, or bare xcodebuild were run per handoff constraint. Non-build guards run:
python3 scripts/swift_file_length_budget.py --budget .github/swift-file-length-budget.tsv./scripts/lint-pbxproj-test-wiring.sh./scripts/check-pbxproj.shgit diff --check
Dogfood build
Do not launch until explicitly requested. After CI is green, use:
CMUX_SKIP_ZIG_BUILD=1 /Users/austinwang/manaflow/cmuxterm-hq/scripts/reload-cloud.sh --tag issue-7226-workspace-switch-latency --launch
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
Summary by cubic
Fixes workspace switch latency by stopping the full terminal portal reconcile when showing the hibernation auto‑resume presentation. Only visible hibernated panels resume; non‑hibernated terminals keep their visibility (fixes #7226).
- Bug Fixes
- Use
resumeVisibleAgentHibernationPanels(panelIds: agentHibernationVisiblePanelIdsForCurrentLayout())instead ofreconcileTerminalPortalVisibilityForCurrentRenderedLayout()when enabling auto‑resume. - Add and wire
AgentHibernationPortalVisibilityTeststo verify toggling the auto‑resume presentation does not restore a non‑hibernated terminal portal.
- Use
Summary by CodeRabbit
-
Bug Fixes
- Improved behavior when enabling auto-resume presentations so only eligible agent hibernations are handled.
- Prevented non-hibernated terminal portals from becoming visible when auto-resume presentation is toggled.
-
Tests
- Added UI-focused test coverage to verify auto-resume visibility behavior keeps non-hibernated terminal portals hidden.