Skip to content

Orchestrator smoke cleanup: simplify, test, docs#362

Merged
arul28 merged 1 commit into
mainfrom
ade/orch-smoke-481aaba0
May 26, 2026
Merged

Orchestrator smoke cleanup: simplify, test, docs#362
arul28 merged 1 commit into
mainfrom
ade/orch-smoke-481aaba0

Conversation

@arul28
Copy link
Copy Markdown
Owner

@arul28 arul28 commented May 26, 2026

Summary

  • Simplify code across 14 files after the large missions-removal (ade/missions removal 0a31b5b5 #359) and Cursor SDK cleanup (Cursor Sdk Cleanup #360) merges — replace nested ternaries with switch statements, consolidate duplicated validation guards, inline one-use helpers, restore precise type annotations
  • Add work session and lane integration tests for terminals, CLI launch, and lane work sessions
  • Update feature docs (chat, lanes, terminals-and-sessions) to reflect post-cleanup API surfaces

Test plan

  • All 3 typechecks pass (desktop, ade-cli, web)
  • Lint: 0 errors
  • Desktop tests: 5,206 tests across 8 shards
  • ade-cli tests: 789 tests
  • All 3 builds pass
  • Doc validation: 157 files

🤖 Generated with Claude Code

Greptile Summary

This PR refactors the orchestrator layer after two large merges (missions-removal #359, Cursor SDK cleanup #360): it unifies chat and CLI draft-launch paths into a single launchDraftSession callback, introduces the WorkPtyLaunchArgs/WorkPtyLaunchResult type pair to replace several inline object literals, and replaces nested-ternary chains with switch statements across 14 files.

  • AgentChatPane.tsx extracts startDraftChatLaunch, startDraftCliLaunch, and clearDraftLaunchComposer from the old monolithic launchDraftChat callback, wires them through a unified launchDraftSession, and extends draft launch controls to CLI sessions (background launch support, lane auto-create for CLI).
  • useWorkSessions.ts / useLaneWorkSessions.ts add a disposition field to launchPtySession so background launches skip selectLane/focusSession/openSessionTab, and startupDelayMs is now correctly forwarded in useLaneWorkSessions.
  • New integration tests cover foreground/background CLI session drafts and the PTY background-disposition path.

Confidence Score: 5/5

Safe to merge; the refactor is mechanical and the new CLI-background launch path is covered by integration tests.

The changes are primarily a refactor of an existing launch flow into smaller, well-named helpers, plus new background-disposition support for CLI sessions. Draft restore on failure is preserved via restoreDraftLaunchSnapshot in the catch block, PTY-layer disposition plumbing is validated by new unit tests, and the startupDelayMs omission in useLaneWorkSessions is fixed. All observations are style-level.

No files require special attention beyond what was already flagged in earlier review threads.

Important Files Changed

Filename Overview
apps/desktop/src/renderer/components/chat/AgentChatPane.tsx Core orchestrator refactor: unified draft launch, CLI background support, and lane auto-create for CLI. The constrainedModelSelectionError guard (flagged in a previous thread) is the main open concern; otherwise the extraction into helper callbacks is clean.
apps/desktop/src/renderer/components/terminals/cliLaunch.ts Adds WorkPtyLaunchArgs / WorkPtyLaunchResult types and WorkPtyLaunchDisposition; consolidates the scattered inline arg shapes into a single canonical type.
apps/desktop/src/renderer/components/terminals/useWorkSessions.ts launchPtySession now accepts WorkPtyLaunchArgs and conditionally skips focus/select for background disposition; return type tightened to WorkPtyLaunchResult.
apps/desktop/src/renderer/components/lanes/useLaneWorkSessions.ts Mirrors useWorkSessions disposition logic; fixes a pre-existing omission where startupDelayMs was not forwarded to pty.create.
apps/ade-cli/src/cli.ts Removes .trim()
apps/desktop/src/shared/linearWorkflowPresets.ts Nested-ternary chains replaced with switch statements in createWorkflowPreset and defaultLaunchStepName; functionally identical, significantly more readable.
apps/desktop/src/main/services/config/projectConfigService.ts coerceAutomationExecution refactored to lift repeated isRecord checks; one subtle behavioral difference: a record session with no valid fields now returns undefined instead of {} (semantically correct).
apps/desktop/src/renderer/components/chat/AgentChatPane.submit.test.tsx Adds foreground and background CLI draft launch tests, installs a matchMedia mock that was missing, and updates aria-label assertion to match the renamed button.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Submit["handleSubmit / onSubmitInBackground"] --> CliCheck{isWorkCliLaunchDraft?}
    CliCheck -->|yes| LaunchCli["launchDraftCliSession(mode)"]
    CliCheck -->|no| ChatCheck{draftLaunchTargetIsAutoCreate\nor forceDraft?}
    ChatCheck -->|yes| LaunchChat["launchDraftChat(mode)"]
    ChatCheck -->|no| RegularSend["regular agentChat.send()"]

    LaunchCli --> DS["launchDraftSession('cli', mode)"]
    LaunchChat --> DS2["launchDraftSession('chat', mode)"]

    DS --> ResolveLane["resolveDraftLaunchLane(snapshot)"]
    DS2 --> ResolveLane

    ResolveLane -->|auto-create| CreateLane["window.ade.lanes.create()"]
    ResolveLane -->|existing| LaneTarget["DraftLaunchLaneTarget\n{laneId, laneName, worktreePath, autoCreated}"]
    CreateLane --> LaneTarget

    LaneTarget --> ClearComposer["clearDraftLaunchComposer(snapshot)"]
    ClearComposer --> KindSwitch{kind?}

    KindSwitch -->|chat| StartChat["startDraftChatLaunch(prepared, lane)"]
    KindSwitch -->|cli| StartCli["startDraftCliLaunch(prepared, lane, mode)"]

    StartChat --> ChatAPI["window.ade.agentChat.send()"]
    StartChat --> SessionId["StartedDraftLaunch {sessionId, draftKind:'chat'}"]

    StartCli --> PtyLaunch["onLaunchCliSession() → launchPtySession()"]
    StartCli --> CliId["StartedDraftLaunch {sessionId, draftKind:'cli'}"]

    SessionId --> ModeCheck{mode?}
    CliId --> ModeCheck

    ModeCheck -->|foreground + chat| OpenSession["openLaunchedDraftSession()\nsetWorkViewState + navigate"]
    ModeCheck -->|foreground + cli| PtyFocus["PTY layer: selectLane + focusSession + openSessionTab"]
    ModeCheck -->|background| BgNotice["setBackgroundLaunchNotice(launch)"]

    BgNotice --> OpenBtn["'Open' button → openLaunchedDraftSession()"]
Loading

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/desktop/src/renderer/components/chat/AgentChatPane.tsx:5178-5183
**Foreground CLI launch leaves the draft pane in a no-feedback state**

When `mode === "foreground"` and `launched.draftKind === "cli"`, neither branch executes: `openLaunchedDraftSession` is gated on `draftKind === "chat"`, and `setBackgroundLaunchNotice` is gated on `mode === "background"`. The PTY layer does call `selectLane`/`focusSession`/`openSessionTab`, so the terminal session opens in the work area. However, `AgentChatPane` itself performs no state update after a successful foreground CLI launch — the composer is already cleared by `clearDraftLaunchComposer`, and no navigation or notice is issued from the pane's side. If this pane is ever rendered outside an embedded work layout, the user sees an empty composer with no indication of what happened. Consider whether a foreground CLI launch should call `openLaunchedDraftSession(launch)` unconditionally, or at minimum leave a short-lived confirmation notice analogous to the background path.

### Issue 2 of 2
apps/desktop/src/renderer/components/chat/AgentChatPane.tsx:5200-5206
`createSessionForLane` appears in the `launchDraftSession` dependency array but is no longer called inside the callback body — it was moved into `startDraftChatLaunch`. The stale entry causes an unnecessary memoization invalidation whenever `createSessionForLane` changes.

```suggestion
    backgroundLaunchBusy,
    buildDraftLaunchSnapshotForCurrentState,
    busy,
    clearDraftLaunchComposer,
    constrainedModelSelectionError,
    draftLaunchTargetIsAutoCreate,
```

Reviews (2): Last reviewed commit: "ship: orchestrator smoke cleanup — simpl..." | Re-trigger Greptile

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@arul28, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 78066217-72ee-453e-bfcc-b4f432e62a0d

📥 Commits

Reviewing files that changed from the base of the PR and between 5962526 and 0952d79.

⛔ Files ignored due to path filters (4)
  • docs/features/chat/README.md is excluded by !docs/**
  • docs/features/lanes/README.md is excluded by !docs/**
  • docs/features/terminals-and-sessions/README.md is excluded by !docs/**
  • docs/features/terminals-and-sessions/ui-surfaces.md is excluded by !docs/**
📒 Files selected for processing (24)
  • apps/ade-cli/src/adeRpcServer.ts
  • apps/ade-cli/src/bootstrap.ts
  • apps/ade-cli/src/cli.ts
  • apps/ade-cli/src/headlessLinearServices.ts
  • apps/ade-cli/src/multiProjectRpcServer.ts
  • apps/ade-cli/src/tuiClient/connection.ts
  • apps/desktop/src/main/services/config/projectConfigService.ts
  • apps/desktop/src/renderer/components/chat/AgentChatComposer.tsx
  • apps/desktop/src/renderer/components/chat/AgentChatPane.submit.test.tsx
  • apps/desktop/src/renderer/components/chat/AgentChatPane.tsx
  • apps/desktop/src/renderer/components/chat/chatSurfaceTheme.ts
  • apps/desktop/src/renderer/components/history/EventDetailPanel.tsx
  • apps/desktop/src/renderer/components/lanes/useLaneWorkSessions.test.ts
  • apps/desktop/src/renderer/components/lanes/useLaneWorkSessions.ts
  • apps/desktop/src/renderer/components/shared/ModelPicker/ModelPicker.tsx
  • apps/desktop/src/renderer/components/terminals/WorkStartSurface.test.tsx
  • apps/desktop/src/renderer/components/terminals/WorkStartSurface.tsx
  • apps/desktop/src/renderer/components/terminals/WorkViewArea.test.tsx
  • apps/desktop/src/renderer/components/terminals/WorkViewArea.tsx
  • apps/desktop/src/renderer/components/terminals/cliLaunch.ts
  • apps/desktop/src/renderer/components/terminals/useWorkSessions.test.ts
  • apps/desktop/src/renderer/components/terminals/useWorkSessions.ts
  • apps/desktop/src/shared/laneLinearIssue.ts
  • apps/desktop/src/shared/linearWorkflowPresets.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ade/orch-smoke-481aaba0

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 and usage tips.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored Preview May 26, 2026 3:37am

@arul28
Copy link
Copy Markdown
Owner Author

arul28 commented May 26, 2026

@copilot review but do not make fixes

@capy-ai
Copy link
Copy Markdown

capy-ai Bot commented May 26, 2026

Capy auto-review is paused for this organization because the monthly auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

PR Review

Scope: 28 file(s), +759 / −401
Verdict: Looks good

This PR refactors orchestrator smoke follow-up work: unifies Work draft launch paths for chat and CLI (including background disposition), consolidates PTY launch typing via WorkPtyLaunchArgs, simplifies nested control flow in CLI/desktop services, and adds targeted tests plus feature-doc updates. The behavioral changes are intentional and covered by new/updated unit tests.


Notes

  • Draft launch structure (AgentChatPane.tsx): Splitting startDraftChatLaunch, startDraftCliLaunch, and shared launchDraftSession makes foreground vs background handling explicit. Foreground CLI correctly relies on launchPtySession focus/tab wiring; background CLI uses the dismissible notice with draftKind so "Open" restores the right Work surface — matches the new tests.
  • Lane cleanup on failure now keys off targetLane.autoCreated rather than the auto-create UI flag alone, which is tighter and avoids deleting a pre-existing lane if resolution ever diverges.
  • PTY launch (useWorkSessions.ts, useLaneWorkSessions.ts): disposition: "background" skipping selectLane / focusSession / openSessionTab is a clear fix for focus-stealing; passing startupDelayMs through the lane hook aligns it with the Work tab path.
  • CLI runtime info parsing (cli.ts, connection.ts, multiProjectRpcServer.ts): Dropping redundant .trim() || null after asString / shared helpers is behavior-preserving, not a regression.
  • projectConfigService agent-session coercion: Refactor is equivalent to main for empty-session filtering (Object.keys(session).length guard was already present).
  • Most ade-cli hunks are readability-only (nested ternaries → if/else, removed no-op wrappers, dropped redundant type assertions where inference suffices). No new trust-boundary or injection surfaces identified.
Open in Web View Automation 

Sent by Cursor Automation: BUGBOT in Versic

Comment thread apps/ade-cli/src/cli.ts
Comment thread apps/desktop/src/renderer/components/chat/AgentChatPane.tsx
…rk session tests

Simplify nested ternaries, inline one-use helpers, consolidate duplicated
guards, restore precise types, and update feature docs after the large
missions-removal and Cursor SDK cleanup merges.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@arul28 arul28 force-pushed the ade/orch-smoke-481aaba0 branch from 565353b to 0952d79 Compare May 26, 2026 03:37
@arul28
Copy link
Copy Markdown
Owner Author

arul28 commented May 26, 2026

@copilot review but do not make fixes

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