Skip to content

Split pty-connection.ts into focused modules under 400 lines - #15166

Merged
AmethystLiang merged 14 commits into
mainfrom
split-pty-connection
Aug 23, 2026
Merged

AmethystLiang merged 14 commits into
mainfrom
split-pty-connection

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​445 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​433
Prod 72 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10739 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9752 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​987

Problem

The pty-connection.ts file had grown to 9490 lines, making it unmaintainable and requiring an oxlint-disable max-lines exemption. Developers struggle to locate and modify specific concerns, and the file's sheer size inhibits testing and understanding.

Solution

Extracted the monolithic file into 79 focused modules organized under src/renderer/src/components/terminal-pane/pty-connection/. Each module now owns a discrete concern:

  • Agent status tracking and lifecycle
  • Session initialization and attachment
  • PTY input/output flows
  • Hidden output restoration and recovery
  • Terminal state management

Shared state is passed through a ConnectPanePtySession type that each installer function mutates, avoiding circular dependencies. The split improves discoverability, testability, and code review surface without changing behavior.

Testing

Test assertions in pty-connection-agent-session-resume.test.ts improved to extract and reuse the launch token, eliminating duplicate regex matchers.

Notes

  • Pure refactoring; no functional changes
  • All imports reorganized; max-lines baseline updated
  • Extracted reattach payload handlers as factory functions per prior commit
  • Design doc removed as part of this cleanup

@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change modularizes PTY connection setup across session contracts, deferred attachment, fresh spawning, reattachment, terminal restoration, hidden-output recovery, output scheduling, agent tracking, input handling, resizing, SSH recovery, E2E controls, serialization, and disposal. It adds UUID-linked cold-restore launch assertions, foreground-output budget tests, reattach payload tests, and a longer event-loop settling window for an updater test. It also removes the PTY connection file from the max-lines baseline allowlist.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 69 functions across 50 files. (21 skipped: 21 over the file limit.) Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem and solution but omits required sections, including Linked Issue, Visual Proof, AI Disclosure, Review, Agent skill boundary, and Checklist. Add all required template sections, provide the linked issue, mark Visual Proof as N/A with a reason if applicable, and complete testing and checklist details.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the primary change: splitting the large pty-connection.ts file into focused modules.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch split-pty-connection

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: 7

🧹 Nitpick comments (21)
src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts (1)

5-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove or correct the two orphaned comments left by the file split.

Two comments no longer match this module:

  • Lines 19-22 hold a JSDoc block describing PTY binding, input, output, title synchronization, and agent status tracking. An import type statement at line 24 separates it from installTerminalKeydownFit, so no tooling attaches it as the function doc. The text also describes the former monolithic module, not this installer.
  • Lines 5-6 explain a restored pane's stale-account prompt, but the import below is parseAppSshPtyId, which this file uses only at line 247 to classify local Windows PTYs for inspection cost.

Move the imports above the doc block, and rewrite the doc to describe what installTerminalKeydownFit installs.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

♻️ Proposed cleanup
-// Why: a restored pane's stale-account prompt can only be raised once a PTY is
-// actually attached — nothing is inspectable while the session hydrates.
 import { parseAppSshPtyId } from '../../../../../shared/ssh-pty-id'
 import { isAgentTaskCompleteTrackingEnabled } from './agent-task-complete-settings'
 import { isRemoteRuntimePtyId } from './paired-parked-terminal-restore'
+import type { ConnectPanePtySession } from './connect-pane-pty-session'
 
-/**
- * Establishes a binding between a terminal pane and its corresponding PTY stream,
- * managing input, output, title synchronization, and agent status tracking.
- */
-
-import type { ConnectPanePtySession } from './connect-pane-pty-session'
-
+/** Installs terminal keydown intent handling, PTY fit binding, side-effect fact
+ *  consumption, and the agent completion coordinator on the session. */
 export function installTerminalKeydownFit(session: ConnectPanePtySession): void {

Source: Coding guidelines

src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts (1)

9-11: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the misplaced "Why" comment above the import.

The comment describes a restored pane's stale-account prompt. The import below it resolves a runtime PTY environment id. The comment does not explain that import. The same comment block appears above unrelated imports in most new modules of this layer, which makes the extracted files harder to read.

src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts (1)

53-57: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add parentheses to the mixed || and ternary condition.

The condition relies on || binding tighter than ?:. The current layout reads as if isTuiAgent(registeredLaunchAgent) ? null : candidateAgent is the right operand of ||. Parentheses make the intended grouping explicit and protect the behavior against future edits.

♻️ Proposed clarification
-    const nextAgent =
-      state.paneForegroundAgentByPaneKey[session.cacheKey]?.agent ||
-      isTuiAgent(registeredLaunchAgent)
-        ? null
-        : candidateAgent
+    const nextAgent =
+      state.paneForegroundAgentByPaneKey[session.cacheKey]?.agent ||
+      isTuiAgent(registeredLaunchAgent)
+        ? null
+        : candidateAgent
+    // grouping: (foregroundAgent || isTuiAgent(registeredLaunchAgent)) ? null : candidateAgent

Prefer an explicit boolean:

const hasStrongerOwnership = Boolean(
  state.paneForegroundAgentByPaneKey[session.cacheKey]?.agent
) || isTuiAgent(registeredLaunchAgent)
const nextAgent = hasStrongerOwnership ? null : candidateAgent
src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts (1)

41-46: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

The file split copied one docblock and one unrelated comment into every module. Each of these modules repeats the same "Establishes a binding between a terminal pane and its corresponding PTY stream" docblock, and most also carry a "restored pane's stale-account prompt" comment above an import that does not raise that prompt. Both are extraction artifacts, and they now misdescribe seven different installers.

  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts#L41-L46: replace the docblock with a one-line description of installDirectSshRetryStatus, and delete the stale-account comment at lines 14-15.
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts#L20-L25: replace the docblock with a one-line description of installPaneAgentIdentity, and delete the stale-account comment at lines 6-7.
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts#L16-L21: replace the docblock with a one-line description of installPanePtyVisibilityBind, and delete the stale-account comment at lines 3-4.
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts#L18-L23: replace the docblock with a one-line description of installPtyExitHibernate, and delete the stale-account comment at lines 11-12.
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts#L25-L30: replace the docblock with a one-line description of installPtyInputRecovery, and delete the stale-account comment at lines 14-15.
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts#L7-L12: replace the docblock with a one-line description of bindCaptureTransportOutputCallbacks, and delete the stale-account comment at lines 3-4.
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts#L15-L20: replace the docblock with a one-line description of bindWritePtyOutputToXterm, and delete the stale-account comment at lines 3-4.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

Source: Coding guidelines

src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts (1)

272-280: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider moving the grace window to pty-connect-limits.ts.

TRANSPORT_CONNECT_SETTLE_GRACE_MS is a fixed policy value, but it is stored per session. The cohort already keeps such values in pty-connect-limits.ts (for example DIRECT_SSH_PANE_RETRY_SETTLEMENT_TIMEOUT_MS). A module constant removes one mutable field from ConnectPanePtySession. Keep the session field if a test overrides it at runtime.

src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty-session.ts (1)

6-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

The [key: string]: any index signature disables type checking for all derived Pick types.

Every member other than pane, manager, and deps resolves to any. This also affects consumers that narrow the bag. For example, ReattachPayloadSession in reattach-payload-session.ts uses Pick<ConnectPanePtySession, ...>; because of the index signature, each picked key resolves to any, and a misspelled key still compiles. The narrowing contract that the PR objectives describe as isolating "required capabilities" therefore provides documentation value only, not compile-time enforcement.

This is acceptable for a mechanical extraction. Plan a follow-up that declares the real member types on the bag and then removes the index signature, so the Pick-based session contracts start enforcing their members.

src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts (1)

4-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Two copied comment artifacts repeat across the extracted modules. The mechanical split duplicated a header comment block into each new module without re-scoping it, producing two misleading comments in seven files.

The first artifact is the comment "a restored pane's stale-account prompt can only be raised once a PTY is actually attached", which now sits above an unrelated import in each file. The second artifact is the docblock "Establishes a binding between a terminal pane and its corresponding PTY stream, managing input, output, title synchronization, and agent status tracking", which describes the former monolith rather than the module it heads. Both mislead a reader about what the module does, and the coding guidelines require comments to be non-obvious and to avoid explaining behavior that is not there.

  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts#L4-L15: delete the stale-account comment above the output-scheduler import and replace the generic docblock with one describing serializer and title-source registration.
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts#L9-L10: delete the stale-account comment above the discardTerminalOutput import.
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts#L3-L20: delete the stale-account comment and replace the generic docblock with one describing fresh-spawn orchestration.
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts#L4-L17: delete the stale-account comment and replace the generic docblock with one describing reattach-result handling.
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts#L3-L12: delete the stale-account comment and replace the generic docblock with one describing live-data deferral.
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts#L10-L25: delete the stale-account comment and replace the generic docblock with one describing follow-output reset and replay writes.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts#L9-L22: delete the stale-account comment and replace the generic docblock with one describing hidden startup query extraction and salvage.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

Source: Coding guidelines

src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts (1)

174-300: 🩺 Stability & Availability | 🔵 Trivial | 🏗️ Heavy lift

One throwing teardown step aborts the rest of dispose.

dispose runs about sixty teardown calls in a linear sequence with no error isolation. Many of these calls reach into xterm, the DOM, zustand subscriptions, and coordinator objects. If any one call throws, every later step is skipped. The pane then leaks the remaining timers, event listeners, subscriptions, and the hidden PTY delivery gate that line 213 releases.

The behavior matches the previous monolithic implementation, so this is not a regression. The extraction is a good point to add isolation. Consider grouping the steps into small named teardown functions and invoking them through a helper that catches and logs per step, so a single failure cannot strand the pane.

src/renderer/src/components/terminal-pane/pty-connection/ssh-session-connect.ts (1)

90-118: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

waitForSshConnection shares one unbounded IPC call across all waiting panes.

window.api.ssh.connect has no timeout. The promise is stored in sshConnectPromises and returned to every concurrent caller for the same connectionId. If the call never settles, all panes that await this connection stay pending, and the finally at line 112 never removes the entry, so new callers join the same stalled promise.

The behavior is carried over from the previous implementation. Consider wrapping the call with an explicit timeout so a stalled SSH connect resolves to { connected: false, error } instead of blocking every pane that shares the connection.

src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts (1)

69-69: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Move bindStartFreshSpawn to the composition root.

bindFreshSpawnFollowReset installs follow-reset, replay-write, and viewport-blanking behavior. Line 69 also installs the fresh-spawn starter from a different module, in the middle of unrelated assignments. This hides an installer dependency inside a sibling installer and makes the install order harder to read.

Call bindStartFreshSpawn(session) from connect-pane-pty.ts next to the other installers instead. This aligns with the module-boundary goal of the refactor.

src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts (1)

98-109: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the self-comparison in getStartupDraftPtyId.

Line 99 stores session.transport.getPtyId() in ptyId. Line 104 compares session.transport.getPtyId() against that same value inside the same synchronous block, so the condition is always false. The check adds no protection and suggests a guard that does not exist. Keep the disposal and transport-identity checks only.

♻️ Proposed simplification
   const getStartupDraftPtyId = (): string | null => {
     const ptyId = session.transport.getPtyId()
     if (
       !ptyId ||
       session.disposed ||
-      session.deps.paneTransportsRef.current.get(session.pane.id) !== session.transport ||
-      session.transport.getPtyId() !== ptyId
+      session.deps.paneTransportsRef.current.get(session.pane.id) !== session.transport
     ) {
       return null
     }
     return ptyId
   }
src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts (3)

4-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the stray comments carried over from the monolith.

The comment at Lines 4-6 describes a restored pane's stale-account prompt. It does not describe the resolveSshPaneConnectGate import below it. The JSDoc block at Lines 15-19 describes binding a pane to a PTY stream, but it is attached to no declaration and does not describe runDeferredSessionAttach. Both fragments also appear in deferred-session-reattach-choice.ts.

Delete both fragments, or move the stale-account rationale to the code it explains.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

Also applies to: 15-19

Source: Coding guidelines


180-206: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the repeated pending-serializer cleanup.

The sequence that awaits preSignalPromise and then calls window.api.pty.clearPendingPaneSerializer(session.cacheKey, gen) appears three times with an identical body (Lines 182-187, 201-206, 250-255). Extract one local helper inside the async block and call it from each site. This reduces the chance that a future change updates only some copies.

♻️ Proposed helper
const clearPreSignaledSerializer = async (): Promise<void> => {
  const gen = await preSignalPromise
  if (typeof gen === 'number') {
    await window.api.pty.clearPendingPaneSerializer(session.cacheKey, gen).catch(() => {})
  }
}

Also applies to: 248-255


4-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Comment fragments were copied during the file split without being re-anchored. Both modules carry the same stale-account "Why" note above an unrelated import and the same orphan JSDoc block about binding a pane to a PTY stream. Neither fragment describes the code it now precedes.

  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts#L4-L19: delete the stale-account note above the resolveSshPaneConnectGate import and the orphan JSDoc block above the ConnectPanePtySession type import, or move the stale-account rationale to the code it explains.
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts#L3-L24: delete the duplicated stale-account note and the duplicated orphan JSDoc block, and reword the "inside the rAF" note at Line 24 so it names the caller's frame gap instead of a requestAnimationFrame that this module does not contain.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

Source: Coding guidelines

src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts (1)

3-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fix the comments carried over from the monolith.

Three comment fragments no longer match this module:

  • Lines 3-5 describe a restored pane's stale-account prompt. They sit above the isWebTerminalSurfaceTabId import and do not describe it.
  • Lines 16-20 form a JSDoc block about binding a pane to a PTY stream. It is attached to no declaration and does not describe runDeferredSessionReattachChoice.
  • Line 24 says "re-read session IDs inside the rAF". This function contains no requestAnimationFrame; the frame gap now lives in the caller.

Delete the first two fragments. Reword Line 24 so it names the caller's frame gap.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

Also applies to: 16-20, 24-24

Source: Coding guidelines

src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts (2)

240-242: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Move the drain-outcome comment to the function it documents.

The comment at Line 240 explains the 'drained' | 'overflow' | 'refetch' return values. drainPendingLiveChunksAfterSnapshot is declared in hidden-output-restore-drain.ts at Lines 23-25. At this call site the comment documents only a bind call, so the meaning is lost.


12-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Comments were copied or detached during the file split. The extraction duplicated two module-level comment blocks into every new module, and it left three rationale comments separated from the code they describe. The shared root cause is comment provenance during the split, not the logic. Delete the copied blocks, and move each detached comment next to its declaration.

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts#L12-L23: delete the stale-account comment and the generic pane/PTY JSDoc; also move the drain-outcome comment at Line 240 to drainPendingLiveChunksAfterSnapshot in hidden-output-restore-drain.ts.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts#L1-L11: delete the stale-account comment and the generic pane/PTY JSDoc.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts#L1-L13: delete the stale-account comment and the generic pane/PTY JSDoc.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts#L4-L18: delete the stale-account comment and the generic pane/PTY JSDoc.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts#L6-L27: delete the stale-account comment and the generic pane/PTY JSDoc.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts#L9-L30: delete the stale-account comment and the generic pane/PTY JSDoc.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts#L1-L12: delete the stale-account comment and the generic pane/PTY JSDoc; also move the suppression-window comment at Line 150 to noteHiddenOutputRestoreFloodBackpressure in foreground-output-refresh.ts.
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts#L4-L17: delete the stale-account comment and the generic pane/PTY JSDoc.
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts#L9-L10: delete the stale-account comment and the generic pane/PTY JSDoc at Lines 33-36; also move the DECSET 2031 comment at Lines 308-314 to observeLiveMode2031Chunk in hidden-output-seq-and-skip.ts.

Source: Coding guidelines

src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts (2)

150-151: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Move or delete the orphaned trailing comment.

The comment at Line 150 describes how the suppression window is extended. The code it describes is noteHiddenOutputRestoreFloodBackpressure in foreground-output-refresh.ts at Lines 41-57. Here it documents nothing.


17-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

HiddenOutputSnapshotResult is declared twice across a producer-consumer boundary. serializeHiddenOutputSnapshot returns the union, and requestHiddenOutputRestoreIfNeeded switches on kind. Two independent declarations can drift, and a new variant added on the producer side will not force the consumer to handle it.

  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts#L17-L22: export the union as the single definition.
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts#L31-L36: delete the local declaration and import the exported type.
src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts (2)

308-314: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Move or delete the orphaned trailing comment.

The comment at Lines 308-314 explains DECSET 2031 record-only handling. That behavior is observeLiveMode2031Chunk in hidden-output-seq-and-skip.ts at Lines 35-57. At the end of bindForegroundOutputRefresh it documents nothing.


203-214: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

The rolling immediate-write budget is implemented twice. Both functions reset the window after FOREGROUND_BUDGET_WINDOW_MS, compare accumulated chars against a cap, and accumulate on success. Only the state holder and the cap differ. Extract one helper that accepts the mutable state and the cap.

  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts#L203-L214: call the shared helper with the session-scoped state and FOREGROUND_IMMEDIATE_BUDGET_CHARS.
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts#L118-L132: call the shared helper with the module-scoped state and INACTIVE_FOREGROUND_IMMEDIATE_BUDGET_CHARS.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 582c5118-0f93-4543-8226-cbba378c01fb

📥 Commits

Reviewing files that changed from the base of the PR and between 32ee3b0 and a018e7a1a04c5321d4bc88ad9dc23668add60b61.

📒 Files selected for processing (71)
  • config/max-lines-baseline.txt
  • src/renderer/src/components/terminal-pane/pty-connection-agent-session-resume.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-done-started-at.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-settings.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/codex-pane-stale.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cursor-agent-reattach-screen.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-lease.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/e2e-terminal-pty-harness.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/paired-parked-terminal-restore.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-binding.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/setup-split-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-session-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/startup-cwd-fallback-notice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
💤 Files with no reviewable changes (1)
  • config/max-lines-baseline.txt

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

@coderabbitai Fixing. Will be in the next commit

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@AmethystLiang Thanks. I will check the update in the next commit.

You are interacting with an AI system.

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

@coderabbitai Fixing. Will be in the next commit

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@AmethystLiang Thanks. I will review the update after the next commit.

You are interacting with an AI system.

@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: 22329f96-7a93-4755-97af-ae99458792b6

📥 Commits

Reviewing files that changed from the base of the PR and between 9761e45 and f2b4eb9.

📒 Files selected for processing (48)
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
💤 Files with no reviewable changes (22)
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
🚧 Files skipped from review as they are similar to previous changes (24)
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection/paired-parked-terminal-restore.ts (1)

21-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the new Why: comments.

Use one concise line for each non-obvious constraint. Remove implementation walkthroughs.

  • src/renderer/src/components/terminal-pane/pty-connection/paired-parked-terminal-restore.ts#L21-L23: reduce the session-ID format explanation to one line.
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts#L50-L51: reduce the legacy-alias selection explanation to one line.
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts#L84-L85: reduce the stale-alias cleanup explanation to one line.
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts#L115-L117: reduce the launch-token delivery explanation to one line.
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts#L140-L140: shorten the deferred-connect reservation explanation.
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts#L160-L161: reduce the daemon-identity explanation to one line.
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts#L169-L170: reduce the reattach-metadata explanation to one line.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06268779-2ced-4c2c-bf86-88f1348b8103

📥 Commits

Reviewing files that changed from the base of the PR and between 13b10e0 and bbfbb60.

📒 Files selected for processing (76)
  • config/max-lines-baseline.txt
  • config/scripts/pr-e2e-gate-contract.test.mjs
  • src/main/persistence-native-chat-tab-view-mode.test.ts
  • src/main/updater.linux-root-package-install.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-agent-session-resume.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-done-started-at.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-settings.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/codex-pane-stale.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cursor-agent-reattach-screen.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-lease.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/e2e-terminal-pty-harness.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/paired-parked-terminal-restore.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-binding.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/setup-split-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-session-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/startup-cwd-fallback-notice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees/teardown/removed-worktree-renderer-teardown.ts
💤 Files with no reviewable changes (2)
  • config/max-lines-baseline.txt
  • src/renderer/src/store/slices/worktree-helpers.ts
🚧 Files skipped from review as they are similar to previous changes (66)
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-binding.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-lease.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/startup-cwd-fallback-notice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/setup-split-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-done-started-at.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-session-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/codex-pane-stale.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cursor-agent-reattach-screen.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-settings.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/e2e-terminal-pty-harness.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts (1)

29-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the shared launch-agent candidate ladder.

paneExpectsLaunchAgent and resolveExpectedLaunchTuiAgent read the same four sources in the same order: tab?.launchAgent, session.paneStartup?.launchAgent, session.paneStartup?.initialAgentStatus?.agent, and state.agentLaunchConfigByPaneKey[session.cacheKey]?.identity.agentType. Only the return shape differs. The comment on lines 22-24 states the goal of deriving each signal once so callers cannot drift. Two copies of the ladder can drift.

Extract one candidate resolver and derive both results from it.

♻️ Proposed refactor
+  const resolveLaunchAgentCandidate = (
+    state: ReturnType<typeof useAppStore.getState>
+  ): string | undefined => {
+    const tab = (state.tabsByWorktree[session.deps.worktreeId] ?? []).find(
+      (candidate) => candidate.id === session.deps.tabId
+    )
+    return (
+      tab?.launchAgent ??
+      session.paneStartup?.launchAgent ??
+      session.paneStartup?.initialAgentStatus?.agent ??
+      state.agentLaunchConfigByPaneKey[session.cacheKey]?.identity.agentType
+    )
+  }
   session.paneExpectsLaunchAgent = (state: ReturnType<typeof useAppStore.getState>): boolean => {
-    const tab = (state.tabsByWorktree[session.deps.worktreeId] ?? []).find(
-      (candidate) => candidate.id === session.deps.tabId
-    )
-    const registeredLaunchAgent =
-      state.agentLaunchConfigByPaneKey[session.cacheKey]?.identity.agentType
-    return Boolean(
-      tab?.launchAgent ??
-      session.paneStartup?.launchAgent ??
-      session.paneStartup?.initialAgentStatus?.agent ??
-      (isTuiAgent(registeredLaunchAgent) ? registeredLaunchAgent : undefined)
-    )
+    return Boolean(resolveLaunchAgentCandidate(state))
   }
   session.resolveExpectedLaunchTuiAgent = (): TuiAgent | null => {
-    const state = useAppStore.getState()
-    const tab = (state.tabsByWorktree[session.deps.worktreeId] ?? []).find(
-      (candidate) => candidate.id === session.deps.tabId
-    )
-    const candidate =
-      tab?.launchAgent ??
-      session.paneStartup?.launchAgent ??
-      session.paneStartup?.initialAgentStatus?.agent ??
-      state.agentLaunchConfigByPaneKey[session.cacheKey]?.identity.agentType
+    const candidate = resolveLaunchAgentCandidate(useAppStore.getState())
     return isTuiAgent(candidate) ? candidate : null
   }

Note: paneExpectsLaunchAgent currently applies isTuiAgent only to the registered launch agent, so this refactor also changes the last rung to an unfiltered candidate. Keep the filter on that rung if the current asymmetry is intentional.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02cde25e-be7e-42f8-91dc-60aa9771b9e1

📥 Commits

Reviewing files that changed from the base of the PR and between 42a4228 and bbc7108.

📒 Files selected for processing (73)
  • config/max-lines-baseline.txt
  • src/main/updater.linux-root-package-install.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-agent-session-resume.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-done-started-at.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-settings.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/codex-pane-stale.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/command-inferred-pane-agent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cursor-agent-reattach-screen.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-lease.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/e2e-terminal-pty-harness.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/paired-parked-terminal-restore.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-binding.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/setup-split-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-session-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/startup-cwd-fallback-notice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
💤 Files with no reviewable changes (1)
  • config/max-lines-baseline.txt
🚧 Files skipped from review as they are similar to previous changes (62)
  • src/renderer/src/components/terminal-pane/pty-connection/startup-cwd-fallback-notice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-lease.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-budgets.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pending-hidden-output-restore-chunk.ts
  • src/main/updater.linux-root-package-install.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/codex-pane-stale.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-binding.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-register.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-settings.ts
  • src/renderer/src/components/terminal-pane/pty-connection/setup-split-geometry.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-snapshot-serialize.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-connect-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/terminal-keydown-fit.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-limits.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts
  • src/renderer/src/components/terminal-pane/pty-connection/retained-legacy-pty-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/paired-parked-terminal-restore.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-session-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cursor-agent-reattach-screen.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-restore-state-and-ssh-probe.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-request.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts
  • src/renderer/src/components/terminal-pane/pty-connection/sleeping-record-access.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/title-spawn-bell.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection/agent-task-complete-notify.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/shell-command-inference.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-live-data-deferral.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/pty-connection/interrupt-input-intent.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
  • src/renderer/src/components/terminal-pane/pty-connection/e2e-terminal-pty-harness.ts
  • src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/foreground-output-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

@coderabbitai Fixing. Will be in the next commit

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@AmethystLiang Thanks. I will review the update after the next commit.

You are interacting with an AI system.

- Replace bindApplyReattachPayload with createReattachPayloadHandlers factory that returns handlers instead of mutating session directly, enabling better composability and testing
- Extract waitForUserInitiatedSshConnect as standalone function for reuse across deferred session attach flows
- Create ReattachPayloadSession type to document and isolate required session capabilities
- Add test coverage for overlapping reattach payload attempts
- Clean up comments to remove redundant prefixes (session.pane → pane, session.transport → transport)
- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint
- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint
Increase event loop turns from 40 to 200 in the timer settlement loop.
Node 26's libuv poll phase can briefly starve when concurrent workers
transform tests, causing cleanup to leak into the next test. The higher
iteration count ensures async operations complete before returning.
At the exact window boundary, the budget should roll over. Change the
comparison from > to >= so the window resets when now equals
windowStart + FOREGROUND_BUDGET_WINDOW_MS, not just after. Add tests
to verify budget rejection and rollover behavior.
- Track agent status observations with origin and transition metadata
- Separate interactive redraw input timing from general terminal input
- Restore pane authority on bind and reattach
- Refine routing trust and confirmation state handling
- Invoke queued startup callbacks when PTY is bound
- Resolve Windows shell overrides with user settings
Consolidate duplicated launch-agent resolution logic into a shared helper to prevent future divergence between paneExpectsLaunchAgent and resolveExpectedLaunchTuiAgent.
Direct SSH reconnects now restore from the full SSH model snapshot (complete scrollback) when dimensions are compatible, instead of the bounded relay tail. Falls back gracefully when incompatible or alternate-screen was exited.
Preserve deferred SSH session IDs longer when they serve as the only retry binding,
allowing the system to attempt recovery through direct SSH retries or PTY remounts
when reattach fails in an unverifiable way. Simplify reconnect model restoration
by removing the conditional model snapshot probe and using relay replay directly.
# Conflicts:
#	src/renderer/src/components/terminal-pane/pty-connection.ts
Retry the terminal list assertion with polling to account for timing
delays in PTY state reporting from the runtime.
@AmethystLiang
AmethystLiang merged commit 7a72f34 into main Aug 23, 2026
49 of 50 checks passed
erishforG added a commit to erishforG/orca that referenced this pull request Aug 23, 2026
Rebased onto the pty-connection.ts module split (stablyai#15166), which merged after
this fix and reintroduced the pre-fix onAgentExited body at its new home in
agent-idle-working-handlers.ts. Ports the same retire-on-confirmed-exit logic
onto the session.* API the split introduced.
brennanb2025 pushed a commit that referenced this pull request Aug 25, 2026
* refactor: split pty-connection.ts under 400 lines

* rm design doc

* refactor(pty-connection): extract reattach payload handlers as factories

- Replace bindApplyReattachPayload with createReattachPayloadHandlers factory that returns handlers instead of mutating session directly, enabling better composability and testing
- Extract waitForUserInitiatedSshConnect as standalone function for reuse across deferred session attach flows
- Create ReattachPayloadSession type to document and isolate required session capabilities
- Add test coverage for overlapping reattach payload attempts
- Clean up comments to remove redundant prefixes (session.pane → pane, session.transport → transport)

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(test): increase poll iterations to prevent Node 26 test leakage

Increase event loop turns from 40 to 200 in the timer settlement loop.
Node 26's libuv poll phase can briefly starve when concurrent workers
transform tests, causing cleanup to leak into the next test. The higher
iteration count ensures async operations complete before returning.

* fix(foreground-output-budgets): use >= for budget window boundary check

At the exact window boundary, the budget should roll over. Change the
comparison from > to >= so the window resets when now equals
windowStart + FOREGROUND_BUDGET_WINDOW_MS, not just after. Add tests
to verify budget rejection and rollover behavior.

* refactor(pty-connection): add status observations and routing improvemen

- Track agent status observations with origin and transition metadata
- Separate interactive redraw input timing from general terminal input
- Restore pane authority on bind and reattach
- Refine routing trust and confirmation state handling
- Invoke queued startup callbacks when PTY is bound
- Resolve Windows shell overrides with user settings

* refactor: extract resolveLaunchAgentCandidate helper

Consolidate duplicated launch-agent resolution logic into a shared helper to prevent future divergence between paneExpectsLaunchAgent and resolveExpectedLaunchTuiAgent.

* refactor(pty-connection): use model snapshot for direct SSH reconnects

Direct SSH reconnects now restore from the full SSH model snapshot (complete scrollback) when dimensions are compatible, instead of the bounded relay tail. Falls back gracefully when incompatible or alternate-screen was exited.

* refactor(pty): retry unverifiable SSH reattaches via preserved bindings

Preserve deferred SSH session IDs longer when they serve as the only retry binding,
allowing the system to attempt recovery through direct SSH retries or PTY remounts
when reattach fails in an unverifiable way. Simplify reconnect model restoration
by removing the conditional model snapshot probe and using relay replay directly.

* test: poll terminal readiness in expectSingleOwningPty

Retry the terminal list assertion with polling to account for timing
delays in PTY state reporting from the runtime.
brennanb2025 pushed a commit that referenced this pull request Aug 25, 2026
…iation

#15172's split modules pass providerExitObserved to onPtyExit, but the option
was declared by #15212, which this release deliberately does not carry — it is
only reachable via #15166, whose split silently drops the SSH reconnect
model-paint gate from #14844 (STA-5395).

Widen the option type so the split typechecks, and take #15212's assertion
updates for the three test files that observe the call shape. The behaviour
#15212 adds — reconciling agent status on a certified process death — is NOT
included; the option is accepted and unused.
brennanb2025 added a commit that referenced this pull request Aug 25, 2026
…16361)

* fix(ssh): restore the reconnect model-paint gate dropped by #15166

#15166 split pty-connection.ts and dropped the "paint from main's model on SSH
reconnect" half of the reattach gate that shipped in v1.4.188 (#14844), leaving
only the park-reveal half. A non-park SSH reconnect has repainted from the
~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose
start it no longer holds.

Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel,
the exited-transition veto computed before the probe, and the kitty scanReplay
layered after the snapshot baseline. Adds a call-site test over
createReattachPayloadHandlers, because the surviving pure-function test stayed
green through the entire removal.

Fixes STA-5395

* fix(ssh): restore empty-tail reconnect snapshots
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…i#15166)

* refactor: split pty-connection.ts under 400 lines

* rm design doc

* refactor(pty-connection): extract reattach payload handlers as factories

- Replace bindApplyReattachPayload with createReattachPayloadHandlers factory that returns handlers instead of mutating session directly, enabling better composability and testing
- Extract waitForUserInitiatedSshConnect as standalone function for reuse across deferred session attach flows
- Create ReattachPayloadSession type to document and isolate required session capabilities
- Add test coverage for overlapping reattach payload attempts
- Clean up comments to remove redundant prefixes (session.pane → pane, session.transport → transport)

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(test): increase poll iterations to prevent Node 26 test leakage

Increase event loop turns from 40 to 200 in the timer settlement loop.
Node 26's libuv poll phase can briefly starve when concurrent workers
transform tests, causing cleanup to leak into the next test. The higher
iteration count ensures async operations complete before returning.

* fix(foreground-output-budgets): use >= for budget window boundary check

At the exact window boundary, the budget should roll over. Change the
comparison from > to >= so the window resets when now equals
windowStart + FOREGROUND_BUDGET_WINDOW_MS, not just after. Add tests
to verify budget rejection and rollover behavior.

* refactor(pty-connection): add status observations and routing improvemen

- Track agent status observations with origin and transition metadata
- Separate interactive redraw input timing from general terminal input
- Restore pane authority on bind and reattach
- Refine routing trust and confirmation state handling
- Invoke queued startup callbacks when PTY is bound
- Resolve Windows shell overrides with user settings

* refactor: extract resolveLaunchAgentCandidate helper

Consolidate duplicated launch-agent resolution logic into a shared helper to prevent future divergence between paneExpectsLaunchAgent and resolveExpectedLaunchTuiAgent.

* refactor(pty-connection): use model snapshot for direct SSH reconnects

Direct SSH reconnects now restore from the full SSH model snapshot (complete scrollback) when dimensions are compatible, instead of the bounded relay tail. Falls back gracefully when incompatible or alternate-screen was exited.

* refactor(pty): retry unverifiable SSH reattaches via preserved bindings

Preserve deferred SSH session IDs longer when they serve as the only retry binding,
allowing the system to attempt recovery through direct SSH retries or PTY remounts
when reattach fails in an unverifiable way. Simplify reconnect model restoration
by removing the conditional model snapshot probe and using relay replay directly.

* test: poll terminal readiness in expectSingleOwningPty

Retry the terminal list assertion with polling to account for timing
delays in PTY state reporting from the runtime.

(cherry picked from commit 7a72f34)
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…15166 (stablyai#16361)

* fix(ssh): restore the reconnect model-paint gate dropped by stablyai#15166

stablyai#15166 split pty-connection.ts and dropped the "paint from main's model on SSH
reconnect" half of the reattach gate that shipped in v1.4.188 (stablyai#14844), leaving
only the park-reveal half. A non-park SSH reconnect has repainted from the
~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose
start it no longer holds.

Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel,
the exited-transition veto computed before the probe, and the kitty scanReplay
layered after the snapshot baseline. Adds a call-site test over
createReattachPayloadHandlers, because the surviving pure-function test stayed
green through the entire removal.

Fixes STA-5395

* fix(ssh): restore empty-tail reconnect snapshots

(cherry picked from commit 656e489)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…i#15166)

* refactor: split pty-connection.ts under 400 lines

* rm design doc

* refactor(pty-connection): extract reattach payload handlers as factories

- Replace bindApplyReattachPayload with createReattachPayloadHandlers factory that returns handlers instead of mutating session directly, enabling better composability and testing
- Extract waitForUserInitiatedSshConnect as standalone function for reuse across deferred session attach flows
- Create ReattachPayloadSession type to document and isolate required session capabilities
- Add test coverage for overlapping reattach payload attempts
- Clean up comments to remove redundant prefixes (session.pane → pane, session.transport → transport)

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(test): increase poll iterations to prevent Node 26 test leakage

Increase event loop turns from 40 to 200 in the timer settlement loop.
Node 26's libuv poll phase can briefly starve when concurrent workers
transform tests, causing cleanup to leak into the next test. The higher
iteration count ensures async operations complete before returning.

* fix(foreground-output-budgets): use >= for budget window boundary check

At the exact window boundary, the budget should roll over. Change the
comparison from > to >= so the window resets when now equals
windowStart + FOREGROUND_BUDGET_WINDOW_MS, not just after. Add tests
to verify budget rejection and rollover behavior.

* refactor(pty-connection): add status observations and routing improvemen

- Track agent status observations with origin and transition metadata
- Separate interactive redraw input timing from general terminal input
- Restore pane authority on bind and reattach
- Refine routing trust and confirmation state handling
- Invoke queued startup callbacks when PTY is bound
- Resolve Windows shell overrides with user settings

* refactor: extract resolveLaunchAgentCandidate helper

Consolidate duplicated launch-agent resolution logic into a shared helper to prevent future divergence between paneExpectsLaunchAgent and resolveExpectedLaunchTuiAgent.

* refactor(pty-connection): use model snapshot for direct SSH reconnects

Direct SSH reconnects now restore from the full SSH model snapshot (complete scrollback) when dimensions are compatible, instead of the bounded relay tail. Falls back gracefully when incompatible or alternate-screen was exited.

* refactor(pty): retry unverifiable SSH reattaches via preserved bindings

Preserve deferred SSH session IDs longer when they serve as the only retry binding,
allowing the system to attempt recovery through direct SSH retries or PTY remounts
when reattach fails in an unverifiable way. Simplify reconnect model restoration
by removing the conditional model snapshot probe and using relay replay directly.

* test: poll terminal readiness in expectSingleOwningPty

Retry the terminal list assertion with polling to account for timing
delays in PTY state reporting from the runtime.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…15166 (stablyai#16361)

* fix(ssh): restore the reconnect model-paint gate dropped by stablyai#15166

stablyai#15166 split pty-connection.ts and dropped the "paint from main's model on SSH
reconnect" half of the reattach gate that shipped in v1.4.188 (stablyai#14844), leaving
only the park-reveal half. A non-park SSH reconnect has repainted from the
~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose
start it no longer holds.

Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel,
the exited-transition veto computed before the probe, and the kitty scanReplay
layered after the snapshot baseline. Adds a call-site test over
createReattachPayloadHandlers, because the surviving pure-function test stayed
green through the entire removal.

Fixes STA-5395

* fix(ssh): restore empty-tail reconnect snapshots
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…i#15166)

* refactor: split pty-connection.ts under 400 lines

* rm design doc

* refactor(pty-connection): extract reattach payload handlers as factories

- Replace bindApplyReattachPayload with createReattachPayloadHandlers factory that returns handlers instead of mutating session directly, enabling better composability and testing
- Extract waitForUserInitiatedSshConnect as standalone function for reuse across deferred session attach flows
- Create ReattachPayloadSession type to document and isolate required session capabilities
- Add test coverage for overlapping reattach payload attempts
- Clean up comments to remove redundant prefixes (session.pane → pane, session.transport → transport)

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(pty-connection): correct sequencing and state bugs in spawn and reat

- Fix terminal tail slice to take prefix instead of suffix, preserving escape
  sequence markers needed by next scan
- Clear pending pane serializer when direct SSH retry PTY is unclaimed
- Initialize interrupt status baseline to undefined so first input advances
  sequence counter
- Bump reattach generation only after confirming current attempt owns the stream,
  preventing superseded results from canceling in-flight prepaint

* fix(test): increase poll iterations to prevent Node 26 test leakage

Increase event loop turns from 40 to 200 in the timer settlement loop.
Node 26's libuv poll phase can briefly starve when concurrent workers
transform tests, causing cleanup to leak into the next test. The higher
iteration count ensures async operations complete before returning.

* fix(foreground-output-budgets): use >= for budget window boundary check

At the exact window boundary, the budget should roll over. Change the
comparison from > to >= so the window resets when now equals
windowStart + FOREGROUND_BUDGET_WINDOW_MS, not just after. Add tests
to verify budget rejection and rollover behavior.

* refactor(pty-connection): add status observations and routing improvemen

- Track agent status observations with origin and transition metadata
- Separate interactive redraw input timing from general terminal input
- Restore pane authority on bind and reattach
- Refine routing trust and confirmation state handling
- Invoke queued startup callbacks when PTY is bound
- Resolve Windows shell overrides with user settings

* refactor: extract resolveLaunchAgentCandidate helper

Consolidate duplicated launch-agent resolution logic into a shared helper to prevent future divergence between paneExpectsLaunchAgent and resolveExpectedLaunchTuiAgent.

* refactor(pty-connection): use model snapshot for direct SSH reconnects

Direct SSH reconnects now restore from the full SSH model snapshot (complete scrollback) when dimensions are compatible, instead of the bounded relay tail. Falls back gracefully when incompatible or alternate-screen was exited.

* refactor(pty): retry unverifiable SSH reattaches via preserved bindings

Preserve deferred SSH session IDs longer when they serve as the only retry binding,
allowing the system to attempt recovery through direct SSH retries or PTY remounts
when reattach fails in an unverifiable way. Simplify reconnect model restoration
by removing the conditional model snapshot probe and using relay replay directly.

* test: poll terminal readiness in expectSingleOwningPty

Retry the terminal list assertion with polling to account for timing
delays in PTY state reporting from the runtime.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…15166 (stablyai#16361)

* fix(ssh): restore the reconnect model-paint gate dropped by stablyai#15166

stablyai#15166 split pty-connection.ts and dropped the "paint from main's model on SSH
reconnect" half of the reattach gate that shipped in v1.4.188 (stablyai#14844), leaving
only the park-reveal half. A non-park SSH reconnect has repainted from the
~100KiB relay tail ever since, which cannot rebuild a full-screen frame whose
start it no longer holds.

Restores followsDirectSshReconnect (PENDING-only retry read), reconnectMayUseModel,
the exited-transition veto computed before the probe, and the kitty scanReplay
layered after the snapshot baseline. Adds a call-site test over
createReattachPayloadHandlers, because the surviving pure-function test stayed
green through the entire removal.

Fixes STA-5395

* fix(ssh): restore empty-tail reconnect snapshots
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