Skip to content

fix(ssh): time out stalled remote file streams - #11364

Merged
Jinwoo-H merged 5 commits into
stablyai:mainfrom
Turtle-Hwan:agent/ssh-file-stream-timeout
Aug 5, 2026
Merged

Jinwoo-H merged 5 commits into
stablyai:mainfrom
Turtle-Hwan:agent/ssh-file-stream-timeout

Conversation

@Turtle-Hwan

@Turtle-Hwan Turtle-Hwan commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #11362.

  • prevent AI Vault's Scanning sessions state from waiting forever on a stalled SSH file read
  • start a 30-second inactivity deadline after SSH file stream metadata arrives
  • reset the deadline after every valid chunk, so large active transfers can run longer than 30 seconds
  • cancel the remote stream and remove listeners when a stream stalls

This PR is intentionally scoped to the SSH file-stream lifecycle. It does not change AI Vault session discovery, provider filters, file-size limits, or parsing behavior.

Screenshots

Observed symptom on stable cask releases

AI Vault session list stuck on “세션 스캔 중” (Scanning sessions) in the Korean UI

The screenshot uses the Korean UI; 세션 스캔 중 means Scanning sessions. It was captured after installing the latest stable Homebrew cask available at approximately 2026-07-29 15:00 KST (v1.4.160). After updating to the current stable cask (v1.4.161), the same indefinite loading symptom reproduced again.

The screenshot documents the user-visible loading state, but no per-stream trace was captured during those runs, so it does not by itself establish that a stalled stream caused a specific instance. The focused regression tests isolate the verified stream-layer defect: after metadata arrives, a stream that produces neither another chunk nor a terminal frame previously had no deadline.

When that condition occurs, this PR cancels and rejects the read after 30 seconds of inactivity, allowing the session scanner to settle through its existing result/error path instead of waiting forever.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm build
  • pnpm test — PR branch: 3,777 passing files / 39,949 passing tests with 8 failures; clean upstream/main: 3,777 passing files / 39,947 passing tests with the same 8 failures in the two Codex runtime-home rollback suites
  • pnpm vitest run src/main/providers/ssh-filesystem-provider-stream.test.ts (10/10)
  • pnpm run check:code-quality:changed -- upstream/main
  • Added focused coverage for timeout cancellation/listener cleanup and for long active streams

AI Review Report

  • macOS / Linux / Windows: the change uses Node timers only and does not add OS-specific paths, shell commands, shortcuts, or Electron APIs
  • local / remote / WSL: the behavior is scoped to SSH filesystem streams; local filesystem and WSL providers are unchanged
  • provider neutrality: no agent-provider or CLI-specific behavior changed
  • performance: one unref'd timer exists per active SSH file stream and is cleared on every terminal path
  • UI: no user-facing copy or layout changed

Security Audit

  • no new dependencies, IPC channels, commands, path handling, auth flow, or secret handling
  • timeout failure uses the existing fs.cancelStream capability and existing cleanup path
  • the change reduces the lifetime of abandoned stream listeners and buffers without broadening filesystem authority

Notes

  • Reproduction versions: stable cask 1.4.160 (cask commit) and current stable cask 1.4.161 (cask commit).
  • High-volume provider discovery and large remote transcript handling are separate follow-up concerns and are intentionally outside this PR.
  • Backward compatible: relays that do not implement cancellation already tolerate the existing best-effort notification behavior.
  • X handle: not provided.

@Turtle-Hwan
Turtle-Hwan marked this pull request as ready for review July 29, 2026 18:05
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added a 60-second inactivity deadline for SSH file streams. The deadline pauses during system suspend and re-arms on resume. readFileViaStream resets it after metadata and chunks and clears it on success or failure. System power lifecycle publication now supports state replay, listener isolation, and unsubscribe behavior. Shutdown cleanup now runs during committed will-quit teardown. Tests cover timeout, suspend/resume, cleanup, and lifecycle ordering.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The implementation addresses [#11362] but changes the required 30-second inactivity deadline to 60 seconds. Set SSH_FILE_STREAM_INACTIVITY_TIMEOUT_MS to 30,000 milliseconds, or update the linked requirement and supporting tests if 60 seconds is intentional.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: timing out stalled SSH remote file streams.
Description check ✅ Passed The description includes all required sections, testing evidence, review findings, security audit, and scope notes.
Out of Scope Changes check ✅ Passed The lifecycle, quit-teardown, tests, and reliability-gate changes support SSH stream timer suspension and cleanup objectives.

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.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a 30-second inactivity deadline to SSH file stream reads so that a stalled stream (one that sends metadata but then stops delivering chunks) is automatically cancelled and rejected instead of blocking the session scanner indefinitely.

  • ssh-file-stream-inactivity-deadline.ts (new): Tiny single-purpose module that wraps a re-settable, unref'd setTimeout behind reset() / clear() APIs.
  • ssh-filesystem-stream-reader.ts: Wires the deadline in — starts after metadata arrives, resets on every valid chunk, and clears on both the success and failure terminal paths; the cancel() call inside fail() sends fs.cancelStream so the remote side is notified.
  • ssh-filesystem-provider-stream.test.ts: Two new fake-timer tests cover the stall-and-cancel path and the long-but-active-transfer path, plus afterEach(() => vi.useRealTimers()) to prevent timer state from leaking across test cases.

Confidence Score: 5/5

Safe to merge. The change is tightly scoped to SSH file stream reading, uses only Node built-in timers with no new dependencies, and every terminal path consistently clears the timer and removes listeners.

The deadline module is small and single-purpose. Integration in the stream reader is correct: streamIdRef is populated before the timer starts, so fs.cancelStream always carries a valid stream ID. Both fail() and succeed() call inactivity.clear() before any further side-effects, ruling out double-fire. Two focused fake-timer tests verify the stall path and the long-but-active path, including listener and timer count assertions confirming no leaks.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/ssh/ssh-file-stream-inactivity-deadline.ts New file: clean re-settable deadline wrapper; correctly unref's the timer and nulls it out inside clear() before re-arming in reset().
src/main/ssh/ssh-filesystem-stream-reader.ts Integrates the inactivity deadline correctly: started after streamIdRef is populated, reset per chunk, and cleared on every terminal path.
src/main/providers/ssh-filesystem-provider-stream.test.ts Two new fake-timer tests verify stall cancellation/listener cleanup and long-but-active-transfer liveness; afterEach guard prevents timer state leakage.

Reviews (1): Last reviewed commit: "fix(ssh): time out stalled remote file s..." | Re-trigger Greptile

@Jinwoo-H
Jinwoo-H force-pushed the agent/ssh-file-stream-timeout branch from 7bb56f5 to cc710d1 Compare August 5, 2026 08:08
@coderabbitai

coderabbitai Bot commented Aug 5, 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.

@Jinwoo-H
Jinwoo-H merged commit 0f9caf5 into stablyai:main Aug 5, 2026
42 checks passed

@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: 382b1508-c8f7-4636-902b-596ef1c923d8

📥 Commits

Reviewing files that changed from the base of the PR and between 2ec36a9 and cc710d1.

📒 Files selected for processing (10)
  • config/reliability-gates.jsonc
  • src/main/index.ts
  • src/main/providers/ssh-filesystem-provider-stream.test.ts
  • src/main/ssh/ssh-file-stream-inactivity-deadline.ts
  • src/main/ssh/ssh-filesystem-stream-reader.ts
  • src/main/startup/desktop-startup-ordering.test.ts
  • src/main/system-power-lifecycle.test.ts
  • src/main/system-power-lifecycle.ts
  • src/main/system-resume-broadcast.test.ts
  • src/main/system-resume-broadcast.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/ssh/ssh-filesystem-stream-reader.ts

type SystemPowerLifecycleListener
} from '../system-power-lifecycle'

export const SSH_FILE_STREAM_INACTIVITY_TIMEOUT_MS = 60_000

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Locate relevant files =="
git ls-files | rg '(^src/main/ssh/ssh-file-stream-inactivity-deadline\.ts$|^config/reliability-gates\.jsonc$|ssh-file-stream-inactiv|reliability-gates)' || true

echo
echo "== Git diff stat/name =="
git diff --stat || true

echo
echo "== Current constants =="
sed -n '1,40p' src/main/ssh/ssh-file-stream-inactivity-deadline.ts 2>/dev/null || true

echo
echo "== Reliability gate relevant excerpts =="
rg -n '"invariant"|"30 seconds"|"30-second"|"knownGaps"|"30 uninterrupted|post-metadata|reliability-gates|inactivity|SSH_FILE_STREAM_INACTIVITY_TIMEOUT_MS' config/reliability-gates.jsonc src/main/ssh/ssh-file-stream-inactivity-deadline.ts 2>/dev/null || true

echo
echo "== All repository occurrences of timeout and related strings =="
rg -n 'SSH_FILE_STREAM_INACTIVITY_TIMEOUT_MS|ssh-file-stream-inactiv|30 seconds|30-second|30 uninterrupted awake seconds|post-metadata inactivity deadline|inactivity deadline' . -g '!node_modules' -g '!dist' -g '!build' || true

Repository: stablyai/orca

Length of output: 50369


Align the SSH file-stream inactivity timeout with the reliability-gate target. SSH_FILE_STREAM_INACTIVITY_TIMEOUT_MS is 60_000, but the gate text requires cancellation within 30 seconds in three places. Pick the intended timeout and update the code or the gate entries together.

📍 Affects 2 files
  • src/main/ssh/ssh-file-stream-inactivity-deadline.ts#L6-L6 (this comment)
  • config/reliability-gates.jsonc#L205-L206
  • config/reliability-gates.jsonc#L278-L279

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(ssh): time out stalled remote file streams

* test(ssh): cover stream dispose-listener cleanup

* fix(ssh): pause file stream deadlines during sleep

* fix(ssh): replay suspended state to late streams

* fix(ssh): allow slower file stream progress

---------

Co-authored-by: OrcaWin <[email protected]>
Co-authored-by: Jinwoo-H <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Stalled SSH file streams can leave AI Vault stuck on Scanning sessions

4 participants