Skip to content

fix(terminal): wait for home sidebar geometry#523

Open
moonixt wants to merge 1 commit into
cline:mainfrom
moonixt:fix/home-sidebar-terminal-geometry
Open

fix(terminal): wait for home sidebar geometry#523
moonixt wants to merge 1 commit into
cline:mainfrom
moonixt:fix/home-sidebar-terminal-geometry

Conversation

@moonixt

@moonixt moonixt commented May 30, 2026

Copy link
Copy Markdown

Summary

  • delay home sidebar terminal-agent startup until the agent panel is visible
  • clear stale terminal geometry before startup and wait for fresh reported geometry
  • fall back to sidebar-width-based geometry when no terminal measurement is available
  • request a resize after terminal reset so reused home terminals report the correct dimensions

Validation

  • npm --prefix web-ui run test -- src/hooks/use-home-agent-session.test.tsx
  • npm --prefix web-ui run build
  • pre-commit: typecheck + test:precommit

@greptile-apps

greptile-apps Bot commented May 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a race where the home sidebar terminal-agent session was started before the agent panel was visible, resulting in incorrect terminal geometry. It gates session startup on canStartTerminalSession (true only when the sidebar is expanded and the agent section is active), clears stale geometry before startup, polls for fresh geometry (up to 300 ms), falls back to a sidebar-width-based estimate, and requests a resize after terminal reset so reused terminals re-report their dimensions.

  • use-home-agent-session.ts: Adds canStartTerminalSession and homeSidebarWidth inputs; uses clearTerminalGeometry / prepareWaitForTerminalGeometry before calling startTaskSession; guards the post-await continuation against the session having become inactive while waiting; also removes the stale sessionSummaries dependency from the start-session effect.
  • App.tsx / use-home-sidebar-agent-panel.tsx: Moves useProjectNavigationLayout earlier so sidebarWidth and isCollapsed can feed the new isAgentSectionActive / homeSidebarWidth props.
  • persistent-terminal-manager.ts: Calls requestResize() after terminal.reset() so reused terminals emit a fresh geometry event that unblocks the wait in waitForTerminalGeometry.

Confidence Score: 4/5

Safe to merge; the gating logic, geometry-wait flow, and all async cancellation paths are correctly guarded.

The async startup sequence now has multiple await points and several interleaved ref-based guards. The guards are all present and correct, but the 300 ms polling window in prepareWaitForTerminalGeometry is a fixed constant: on a reused terminal that happens to be mid-write-queue flush when reset() is enqueued, requestResize fires after the queue drains, which could exceed 300 ms and silently fall back to the sidebar-width estimate instead of the measured geometry. This is a latent imprecision rather than a hard failure, and the fallback is reasonable, but it is a timing assumption worth knowing about.

web-ui/src/hooks/use-home-agent-session.ts — the async startup block has the most moving parts and is the place to look first if geometry-related start regressions appear.

Important Files Changed

Filename Overview
web-ui/src/hooks/use-home-agent-session.ts Core logic change: gates terminal startup on canStartTerminalSession, adds geometry-wait flow, and removes stale sessionSummaries dep; logic is carefully guarded for disposal, task-ID drift, and visibility transitions.
web-ui/src/hooks/use-home-agent-session.test.tsx Two new test cases cover the reported-geometry fast path and the canStartTerminalSession=false gate; mock setup and assertions are correct.
web-ui/src/hooks/use-home-sidebar-agent-panel.tsx Passes new homeSidebarWidth and isAgentSectionActive props through to useHomeAgentSession; otherwise unchanged.
web-ui/src/App.tsx Moves useProjectNavigationLayout call earlier so sidebarWidth/isCollapsed are available when building homeSidebarAgentPanel props; no functional change to other callers.
web-ui/src/terminal/persistent-terminal-manager.ts One-line addition of requestResize() after terminal.reset() in the write queue; safely guarded by !this.visibleContainer inside requestResize.

Reviews (1): Last reviewed commit: "fix(terminal): wait for home sidebar geo..." | Re-trigger Greptile

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