fix(ssh): retain actionable errors from failed device commands#19972

merged4
main
GitHub fork: fix/ssh-error-output-tail
openedOct 15, 2026byQQuicksaver
View on GitHubTwo-way sync enabledPR last imported 28d ago

A failed remote device command can put its actionable error at the end of verbose stdout. Keeping only the first 4,000 characters hid that final diagnostic.

Add opt-in tail retention to the SSH command helper and enable it for device commands. Redact matching credential fields before selecting the last 4,000 characters; preserve stderr preference and generic callers’ default head retention. Successful output remains complete. The retained diagnostic is available in the SSH log and error cause; the client’s generic error label is unchanged.

Maintainer takeover of @Quicksaver’s #19972, retaining the original commits.

Verification:

  • Focused real subprocess fixtures and the device-host adapter regression verify the final diagnostic, redaction before truncation, generic head retention, stderr preference, and successful output.
  • Focused suites: 13 → 12 passing tests. Removing tail retention causes both tail and device regressions to fail; removing only the device opt-in fails the adapter regression.
  • SSH and server typechecks, targeted lint, formatting and diff checks passed. Independent Claude Opus 5.5 and Codex GPT-6 Sol whole-PR reviews returned one clean round. The original production implementation was already minimal and was retained; the test rewrite removes overlapping failure cases.
  • These are real local processes behind a synthetic SSH endpoint and synthetic device handles, not a live SSH connection, remote shell, SDK, emulator or physical device. No UI changed, so screenshots do not add proof.
  • Not verified: macOS, Windows, iOS, Android or Electron desktop. Human approval remains required for the default remote-device error presentation change.

Implemented with Codex GPT-6.1 Sol; regression tests with Codex GPT-6 Astra; reviewed with Claude Opus 5.5 and Codex GPT-6 Sol through T3 Code.

Checks

21 successful · 10 skipped
All checks passed
6eb6943
Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR not approvable — This is a small, well-tested SSH diagnostic bug fix, and generic SSH callers retain their existing truncation behavior. Hard-coding tail retention in the device host changes the product’s default error presentation for all remote device commands, so the default-change policy warrants human review.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Review in Change Stack →

Warning

Review limit reached

Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd96b0ee-f1f2-4a8c-9d32-4372f4533140
📥 Commits

Reviewing files that changed from the base of the PR and between c115c3c58bcc57050f890ad02d8e41bd0535d1fb and 6eb6943037a473663fd19f37aefdacf8b7624e8e.

📒 Files selected for processing: 4
  • apps/server/src/device/SshDeviceHost.test.ts
  • apps/server/src/device/SshDeviceHost.ts
  • packages/ssh/src/command.test.ts
  • packages/ssh/src/command.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 915a715b-d045-46c0-a24e-d1b13e5b80c7
📥 Commits

Reviewing files that changed from the base of the PR and between c49dd9f4656a643c38908dd3204f0b06167b0fb5 and c115c3c58bcc57050f890ad02d8e41bd0535d1fb.

📒 Files selected for processing: 2
  • packages/ssh/src/command.test.ts
  • packages/ssh/src/command.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

Failed SSH commands can retain the beginning or end of long stdout while preserving redaction and the 4,000-character limit. Remote device commands enable tail retention. Tests cover truncation, redaction, stderr, and failure reporting.

Changes: SSH failure output retention

Layer / File(s)Summary
Configure failed-command output retention
packages/ssh/src/command.ts, packages/ssh/src/command.test.ts
RunSshCommandOptions adds keepErrorOutputTail. Failed-command stdout retains its first 4,000 characters by default or its last 4,000 characters when enabled. Tests cover truncation, redaction, stderr, and failure messages.
Enable tail retention for device commands
apps/server/src/device/SshDeviceHost.ts, apps/server/src/device/SshDeviceHost.test.ts
SshDeviceHost.run enables tail retention. The test fixture emits long failing emulator output, and the test checks its exit code, truncated stdout, and stderr.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant SshDeviceHost
3 participant runSshCommand
4 participant ChildProcess
5 SshDeviceHost->>runSshCommand: Execute remote command with tail retention enabled
6 runSshCommand->>ChildProcess: Run command
7 ChildProcess-->>runSshCommand: Return exit code and output
8 runSshCommand-->>SshDeviceHost: Return redacted, truncated failure output

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to c115c

Failed device commands can retain trailing error details. No actionable merge-blocking risk remains after normal checks.

### Architecture Summary

Architecture risk: 🔵 Low · up to c115c

The change affects 2 systems.

Changed systems: packages/ssh, apps/server

Architecture concerns No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/ssh (library) was modified; 2 changed files map to changed impact.
  • observed — apps/server (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in apps/server/src/device/SshDeviceHost.test.ts: The child-process fixture initializes its mocked exit code to 0.
  • observed — Modified behavior in apps/server/src/device/SshDeviceHost.test.ts: When the parsed mode is empty, the fixture replaces the normal JSON output with a long verbose prefix and emulator SDK panic message and sets the exit code to 1. Non-forwarding handles return that configured exit code instead of always returning 0; forwarding handles still never complete.
  • observed — Modified behavior in apps/server/src/device/SshDeviceHost.test.ts: The test now reads the current ready host and, when present, runs the emulator command and checks for exit code 1, truncated stdout, stderr equal to trimmed stdout, and the panic message at the end of stderr.
  • observed — Modified behavior in apps/server/src/device/SshDeviceHost.ts: run now enables retaining the tail of SSH error output for remote command execution.
Pre-merge checks: Passed 4
Check nameStatusExplanation
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Title checkPassedThe title clearly and concisely describes the main change: preserving actionable errors from failed SSH device commands.
Description checkPassedThe description explains the problem, implementation, verification coverage, limitations, and affected behavior. It does not use the template headings and does not provide an explicit maintainer appro…
Full details: Description check

Explanation

The description explains the problem, implementation, verification coverage, limitations, and affected behavior. It does not use the template headings and does not provide an explicit maintainer approval comment, but the required technical information is mostly present.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Synced from GitHub

@coderabbitai full review

The review in https://github.com/pingdotgg/t3code/pull/19972#issuecomment-6199194835 still identifies 6cd6b7f49ca40d0c93b02cb5a00bd113b596328f as the covered commit. Please review the complete PR at current head c49dd9f4656a643c38908dd3204f0b06167b0fb5 after its rebase. Full CI run 38789244752 has passed. The customization patch is unchanged.

🤖 Generated by GPT 6.1 Sol in Codex via T3 Code.

Added 1 commit

  • fix(ssh): retain failed device command output tailsc115c3c

Taking over this one. I’ll preserve your commits and push a focused maintainer rebuild to this branch.

Added 3 commits

  • Merge remote-tracking branch 'origin/main' into fix/ssh-error-output-tail5554ab1
  • test(ssh): focus device error tail regressions52af9df
  • Merge remote-tracking branch 'origin/main' into l53-199726eb6943