Skip to content

feat(ssh): bound relay PTY output end to end - #11005

Merged
OrcaWin merged 43 commits into
mainfrom
ssh-relay-pty-backpressure
Jul 30, 2026
Merged

OrcaWin merged 43 commits into
mainfrom
ssh-relay-pty-backpressure

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements bounded SSH relay PTY output end to end, from the native PTY through relay publication, dispatcher/SSH transport, bounded frame decoding, main-process model and projection admission, renderer/remote consumer settlement, cumulative source ACK publication, exit, and reconnect.

The production invariant for every negotiated delivery token is:

0 <= sentEndSu - creditedEndSu <= windowSu

Every immutable source span and required consumer obligation ends exactly once as settled, transferred, or canceled. A write(false) owns one frame exactly once; later ordinary traffic waits for drain while bounded control/liveness capacity remains available.

What changed

  • Added one drain-aware relay writer with bounded ordinary, bulk, control, sentinel, and connect-mode lanes.
  • Bounded relay and main frame-decoder turns and connected their pause/resume behavior to transport settlement.
  • Added a shared semantic PtyConsumerSession state machine with an SSH-specific authenticated transport adapter.
  • Added immutable source ledgers, cumulative token-scoped credit, bounded main model admission, desktop and required-remote reserve/commit/rollback, and ACK publication fenced by mux write settlement.
  • Added private provisional/recovery ownership, sealed exit retention, token-scoped cancellation proof, exact reconnect recovery, stale-owner one-shot retry, and bounded eight-wide reattach.
  • Added a reconnect model-migration fence that waits for the exact running raw admission, contains migration-owned failure to one PTY, and preserves the shared provider and sibling terminals.
  • Preserved fixed-size filesystem framing, capacity-aware Git/PTY slicing, WSL stdio settlement, Windows named-pipe/ConPTY contracts, and prior-version relay install isolation.

This is intentionally a large cross-layer change: the bound is only real if the source, every transport queue, model admission, desktop/remote consumers, ACK publication, reconnect, exit, and cleanup share one lifecycle. The current PR is 43 commits and 189 files (+34,172/-2,418), with most added lines in focused contracts and adversarial tests.

Default and compatibility behavior

V1 source credit is the default and only same-build behavior:

  • every new SshRelaySession offers V1;
  • every same-build relay advertises V1;
  • a successful V1 negotiation must contain an exact valid grant or the session fails closed;
  • a peer whose pty.openClient method is absent uses the bounded legacy fallback;
  • older clients remain token-free;
  • prior-version relays remain isolated through content-hashed installs and version checks.

There is no target setting, experimental toggle, environment override, relay launch flag, or .pty-source-credit-policy. No Orca restart is needed to select a mode because there is no selectable mode. Local and daemon protocols are not replaced by the SSH wire protocol.

Compatibility is negotiated rather than inferred from version strings. Same-build SSH gets source credit; old peers retain legacy semantics without receiving unknown token fields. The legacy path still benefits from the bounded writer and decoder, but cannot provide the V1 source-window guarantee.

Architecture and lifecycle review

The architecture review located authority at the authenticated relay session, immutable source ledger, dispatcher writer, main SSH intake, model/projection owners, and mux ACK publication boundary. It selected shared PtyConsumerSession semantics with transport adapters rather than a universal wire protocol.

Adversarial review drove substantive fixes for the original major findings:

  • exited delivery remains retained until all uncredited spans terminate;
  • obligation terminality, ACK queueing, and ACK publication are separate, breaking the circular dependency;
  • immutable span/range identity reaches desktop projection admission and has exact rollback;
  • recovery frames transfer atomically into a private quarantine before fence validation and never publish provisionally;
  • reconnect migration waits for exact raw admission and contains migration-owned callback failure to the exact PTY;
  • cancellation, stale attempts, generation close, replacement activation, and cleanup are exact-token/exact-generation operations.

These contracts are reflected across invariants, pseudocode, lifecycle tables, implementation mapping, tests, rollout, and cleanup in the design document. Internal final architecture/lifecycle and transport reviews are clean. All GitHub review threads are resolved; human architecture/terminal review remains requested from @nwparker.

Validation

Current branch head is 8c35d4f89826e5a38ee5642434caf557ef71b89d with tree b2e35b5fdab000cb5475345298baa64b67190fce. Current origin/main@0349cb6bdbdb19119585ecb6048d884c5ee8b97d is nine unrelated commits ahead of the last branch merge; synthetic merge tree 802c27aa3c0a3c28e1c3c8176c5eb876e8d522b5 is conflict-free.

Post-main-merge validation:

  • pnpm run typecheck
  • 17 focused source-credit, relay, provider, reconnect, migration, and transport files: 645 tests
  • SSH IPC always-on handshake and source-identity fixture: 51 tests
  • Exact CI shard 11/16 after fake-relay grant repair: 239 files, 2,123 tests
  • Final architecture/lifecycle suite: 27 files, 296 tests
  • Changed-code quality review: 0 findings
  • pnpm run check:reliability-gates: 53 gates
  • pnpm exec oxfmt --check docs/plans/2026-07-27-ssh-relay-pty-backpressure.md config/reliability-gates.jsonc
  • git diff --check
  • pnpm exec electron-vite build --mode e2e
  • All relay targets built: Linux/macOS/Windows x64/arm64 and WSL hook relay
  • Exact-current Docker OpenSSH/deployed-relay E2E: 4/4 in 56.7 seconds
    • direct typing median/worst: 5.3/108.9 ms
    • ACK-stalled typing median/worst: 4.8/107.6 ms
    • exact held source units: 262,144
    • fixed-size filesystem/Git churn median/worst: 152.0/173.3 ms, 84 bulk reads
    • owner reconnect: 14.3 seconds

Exact Docker artifact provenance is bound to production merge commit adba3410fe4427ceb7525f3fdce2ec58973263a7, tree e43d87340666ca3a733bdb38007c24f95be3f219:

  • E2E main bundle SHA-256: 3c304ffc0618520e42bede9a52f72d4b7bb68cbfe543974f89e82a3c477c44b3
  • deployed Linux-x64 relay SHA-256: 366cb7ccf2e4b388cc6f81a8f6055ab9fde57d2d91381767005c15908832e776

Commit 728ed98ab7 changes only validation provenance. Commits 6ddd86ae4e and 8c35d4f898 update the SSH IPC and fake-relay test harnesses to grant the now-unconditional V1 capability; they change no production source. Fresh GitHub CI is green for the current pushed head: PR Checks run 30497200229 attempt 2 has 35/35 jobs green, and the accompanying golden macOS/Linux, Ubuntu/Windows smoke, Windows terminal restart, and packaged crash-survival workflows are green (41 passing checks total; 3 expected platform skips). The only first-attempt failure was an unrelated combined-diff scroll E2E flake; the exact test passed locally and the failed job passed on rerun.

Evidence boundaries and remaining gaps

The Docker suite proves direct SSH against the deployed Linux relay: real SSH transport/process/filesystem/Git behavior, main desktop intake, writable/drain behavior, the exact source-window plateau, activity isolation, and reconnect.

It does not prove live headed/headless paired Orca runtime behavior, physical WSL, Windows ConPTY/named pipes, local daemon/provider behavior, folder workspaces, prior/mixed-version binaries, or Ubuntu 20.04 packaging. Those distinctions remain explicit in the design and reliability gate. Deterministic contracts cover their shared seams, but this PR does not claim unrun live topology evidence.

The primary tradeoff is protocol and lifecycle complexity across a broad surface. V1 bounds memory and makes ownership explicit, but legacy peers cannot gain the full source-window invariant, and wider live-topology soak history remains desirable. Because the behavior is always on for same-build SSH, operational rollback is a normal binary/code rollback rather than a user setting.

Security

  • Session-owner eligibility comes only from the existing authenticated SSH session and first framed pty.openClient request.
  • Token, owner generation, PTY incarnation, checkpoint, sent end, and credited end are validated as exact immutable identities/ranges.
  • Missing or malformed successful grants, invalid cancellation proofs, gaps, overlaps, stale generations, and reclaimed replacements fail closed.
  • Paths, stdout content, .git, socket order, and worktree identity grant no authority.
  • No terminal-output telemetry or raw terminal logging was added.

Fresh CI is complete. Do not merge until normal maintainer review, including the requested architecture/terminal review from @nwparker, is complete.

@coderabbitai

coderabbitai Bot commented Jul 27, 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

Adds a design plan for bounded SSH relay PTY output backpressure, and implements it end-to-end: bounded frame decoding and multiplexer/writer backpressure, relay-side PTY source-credit ledgers/scheduling/publication and consumer-session adapter, main-process bounded output intake with legacy projection ledger, model admission, source obligations/coordinator, remote source-range consumers, and ACK coalescing, provider/notification-routing changes for source activation and recovery, SSH relay session recovery/reattach orchestration with a new per-target source-credit rollout module, deploy/launcher credential-file plumbing, runtime terminal-multiplex source-range ledger support, renderer ACK negotiation, shared contracts/validation, settings UI and persistence for the per-target opt-in, updated reliability gates, and new unit/integration/e2e tests.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.24% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 summarizes the main SSH PTY output bounding change and matches the changed areas.
Description check ✅ Passed The description is detailed and covers summary, validation, security, compatibility, and rollout concerns.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 17daf58b-f58c-441f-ada1-48b27facaaca

📥 Commits

Reviewing files that changed from the base of the PR and between cdd5ceb and a7c6e40.

📒 Files selected for processing (1)
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md

@OrcaWin
OrcaWin force-pushed the ssh-relay-pty-backpressure branch from a7c6e40 to e13c740 Compare July 28, 2026 00:14
@OrcaWin
OrcaWin requested a review from nwparker July 28, 2026 00:16
@OrcaWin
OrcaWin force-pushed the ssh-relay-pty-backpressure branch 3 times, most recently from 161b173 to 118d1b4 Compare July 28, 2026 23:20
@greptile-apps

greptile-apps Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Too many files changed for review. (189 files found, 100 file limit)

Bypass the limit by tagging @greptile-apps to review.

@OrcaWin OrcaWin changed the title docs: design SSH relay PTY backpressure feat(ssh): bound relay PTY output end to end Jul 28, 2026

@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: f4c2b48b-3a2c-44ab-8bde-38e5516af145

📥 Commits

Reviewing files that changed from the base of the PR and between a7c6e40 and 118d1b4e445a2e3db3007a45d53fd0beb63756b2.

📒 Files selected for processing (4)
  • config/reliability-gates.jsonc
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md

Comment thread config/reliability-gates.jsonc Resolved
@OrcaWin
OrcaWin force-pushed the ssh-relay-pty-backpressure branch from 118d1b4 to db167ea Compare July 29, 2026 00:47

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

Note

Due to the large number of review comments, Critical, Major severity comments were prioritized as inline comments.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts (1)

903-924: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Use encoded source-frame bytes for source-range ACKs, not JSON payload size.

TerminalSourceRangeLedger resolves ACK settlement against encodedEndByte, which is the byte count passed through prepareAccept/accept. For OutputSpan, that count should match the encoded frame bytes admitted by the server, not frame.payload.byteLength; accumulating raw span.rawLength and the JSON frame bytes separately will misalign sourceAckedEndByte with the server-side ACK watermark.

🟡 Minor comments (11)
src/relay/relay.ts-170-182 (1)

170-182: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Wrap the credential read so a missing/unreadable file yields the intended error.

readFileSync throws a raw ENOENT/EACCES before the uncaughtException/unhandledRejection handlers are installed later in main, so startup fails with an opaque stack instead of the "missing or invalid" message this function is clearly trying to produce.

🛡️ Proposed fix
-  const credential = readFileSync(credentialFile, 'utf8').trim()
+  let credential: string
+  try {
+    credential = readFileSync(credentialFile, 'utf8').trim()
+  } catch {
+    throw new Error('Relay endpoint credential is missing or invalid')
+  }
src/relay/pty-source-credit-record.ts-205-234 (1)

205-234: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Mutate old only after the replacement is fully built.

Lines 218-222 advance old.sentEndSu / clear old.attemptedEndSu before the span reconstruction at Lines 226-229, which can still throw (sliceAtSourceStart rejects an indivisible span whose start precedes acceptedSourceEndSu). On that throw RelayPtySourceCreditLedger.rotate aborts with the old record left mutated and no replacement registered, so the delivery's checkpoint bookkeeping is silently corrupted. Building the spans first keeps rotation atomic.

🛡️ Proposed reordering
-  if (acceptedSourceEndSu > old.sentEndSu) {
-    old.sentEndSu = acceptedSourceEndSu
-    old.sentBoundaries.add(acceptedSourceEndSu)
-  }
-  old.attemptedEndSu = null
   const replacement = createDeliveryRecord(newIdentity, windowSu, acceptedSourceEndSu)
   replacement.state = old.state === 'sealed-unsettled' ? 'sealed-unsettled' : 'active'
   replacement.receivedEndSu = old.receivedEndSu
   replacement.spans = old.spans
     .filter((span) => span.sourceEndSu > acceptedSourceEndSu)
     .map((span) => sliceAtSourceStart(span, Math.max(span.sourceStartSu, acceptedSourceEndSu)))
     .map((span) => Object.freeze({ ...span, ...replacement.identity }))
   replacement.retainedDataBytes = replacement.spans.reduce(
     (bytes, span) => bytes + chargedPtyRetainedStringBytes(span.data),
     0
   )
+  if (acceptedSourceEndSu > old.sentEndSu) {
+    old.sentEndSu = acceptedSourceEndSu
+    old.sentBoundaries.add(acceptedSourceEndSu)
+  }
+  old.attemptedEndSu = null
   return replacement
src/main/ipc/ssh-pty-output-intake.ts-138-160 (1)

138-160: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Release the model source obligation on model-admission failure.

The projection transfer settles the desktop consumer, but after receipt.then(...).catch(...) the source span’s model obligation remains outstanding in ssh_exit_delivery_canceled, because that branch skips closeProvider and the source generation is only closed via the exit deadline. Add cancellation-path cleanup that settles/closes the model obligation for sourceReservation before rethrowing.

src/main/ipc/ssh-pty-output-intake.test.ts-514-596 (1)

514-596: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

These two exit-deadline tests race the wall clock.

exitBarrierMs: 1 with exitCancellationProofMs: 10/100 on real timers makes the outcome depend on how fast the event loop turns. On a loaded CI runner the 100ms proof window in the second test can elapse before cancelSourceDelivery settles, flipping expect(closeProvider).not.toHaveBeenCalled(). Consider vi.useFakeTimers() with explicit advanceTimersByTimeAsync, or widen the proof window well beyond scheduling jitter.

src/main/ipc/ssh-pty-output-intake-registry.ts-54-56 (1)

54-56: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Publisher maps are never pruned on generation close.

closeSshPtyOutputGeneration tears down intake state for a generation but leaves that generation's entries in sourceAckPublishers / sourceCancellationPublishers. If a session ends without its uninstaller running (crash, error path between install and cleanup), the closures — and everything they capture, including the SSH session — stay referenced for the process lifetime, one entry per generation.

🧹 Suggested cleanup
 export function closeSshPtyOutputGeneration(providerGeneration: number, reason: string): void {
   installedIntake?.closeGeneration(providerGeneration, reason)
+  sourceAckPublishers.delete(providerGeneration)
+  sourceCancellationPublishers.delete(providerGeneration)
 }
src/main/ipc/pty.test.ts-11517-11527 (1)

11517-11527: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

These negative assertions can't fail the way the test name implies.

Data for source-credit-pty is injected through acceptSshPtyOutputData, never through provider.emitData, so pauseProducer('source-credit-pty') could never be called regardless of whether the bounded source-credit path is wired at all — the test would still pass if runtime.acceptPtyDataBounded were never invoked. Line 11527's not.toHaveBeenCalledWith('unrelated-pty') is unconditionally true since no such PTY exists.

Add a positive assertion that the bounded lane actually ran, so the test fails if the wiring regresses:

💚 Suggested strengthening
       expect(getPtyRendererDeliveryDebugSnapshot()).toMatchObject({
         pendingPtyCount: 1,
         pendingChars: 0
       })
+      expect(runtime.acceptPtyDataBounded).toHaveBeenCalledTimes(17)
       expect(provider.pauseProducer).not.toHaveBeenCalledWith('source-credit-pty')
       expect(provider.resumeProducer).not.toHaveBeenCalledWith('source-credit-pty')
src/shared/pty-source-credit-validation.ts-28-46 (1)

28-46: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Validate emitted text against the display range.

A transformed span can pass with data: "x" and a much larger displayEnd - displayStart. That publishes source metadata that cannot describe the delivered output, breaking downstream range/ACK accounting. Require data to be a string and require its length to equal the display interval.

Proposed fix
 export function assertPtySourceSpan(span: PtySourceSpan): void {
   assertPtySourceIdentity(span)
+  if (typeof span.data !== 'string') {
+    throw new Error('PTY source span data must be a string')
+  }
   if (!span.spanId) {
     throw new Error('spanId is required')
   }
@@
   if (!span.transform.transformed && span.data.length !== span.transform.rawLengthSu) {
     throw new Error('Untransformed PTY source span length is invalid')
   }
+  if (span.data.length !== span.displayEnd - span.displayStart) {
+    throw new Error('PTY source span display length is invalid')
+  }
config/reliability-gates.jsonc-3117-3154 (1)

3117-3154: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Register the two new multiplexer transport tests in this gate.

src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts and src/main/ssh/ssh-channel-multiplexer-settlement.test.ts are added by this cohort (decoder pause/resume, ordered dispatch across continuations, write-settlement semantics) but appear in neither commands nor testFiles, so the gate can pass without exercising them. The related invariant text at Line 3106 explicitly covers writer settlement and read pause/resume.

🧪 Suggested registration
-        "pnpm exec vitest run --config config/vitest.config.ts src/shared/pty-consumer-session.test.ts src/main/ipc/ssh-pty-output-intake.test.ts src/main/ipc/ssh-pty-remote-source-range-consumers.test.ts src/main/runtime/rpc/terminal-multiplex.test.ts src/main/ssh/ssh-multiplexer-transport-writer.test.ts src/main/ssh/ssh-channel-multiplexer.test.ts src/main/ssh/ssh-pty-source-credit-rollout.test.ts src/main/ssh/ssh-relay-deploy.test.ts src/relay/dispatcher-client-writer.test.ts --reporter=dot",
+        "pnpm exec vitest run --config config/vitest.config.ts src/shared/pty-consumer-session.test.ts src/main/ipc/ssh-pty-output-intake.test.ts src/main/ipc/ssh-pty-remote-source-range-consumers.test.ts src/main/runtime/rpc/terminal-multiplex.test.ts src/main/ssh/ssh-multiplexer-transport-writer.test.ts src/main/ssh/ssh-channel-multiplexer.test.ts src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts src/main/ssh/ssh-channel-multiplexer-settlement.test.ts src/main/ssh/ssh-pty-source-credit-rollout.test.ts src/main/ssh/ssh-relay-deploy.test.ts src/relay/dispatcher-client-writer.test.ts --reporter=dot",

Add the matching testFiles entries (and an assertionRefs block describing them as deterministic transport coverage, not live evidence).

src/main/ssh/ssh-multiplexer-transport-writer.ts-147-188 (1)

147-188: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

A drain observed during an accepted write can leave the writer stuck saturated.

handleDrain defers to drainObservedDuringWrite whenever writing is true, but that flag is only consulted on the accepted === false branch. If a drain lands during a write that returns true — e.g. the liveness bypass at Line 92 issued while saturated is already true — the saturation flag is never cleared and no further drain will be emitted, so pump() never resumes the queued lanes. The hostile-transport test at ssh-multiplexer-transport-writer.test.ts Lines 193-219 exercises the synchronous-drain shape but only on the write(false) path.

🐛 Proposed fix
       if (accepted === false) {
         if (!this.transport.onDrain) {
           throw new Error('Multiplexer transport returned write(false) without drain support')
         }
         this.setSaturated(!this.drainObservedDuringWrite)
         if (this.transport.supportsWriteSettlement !== true && this.saturated) {
           this.settleOnDrain.add(entry)
         } else if (this.transport.supportsWriteSettlement !== true) {
           this.handleWriteSettlement(entry, { ok: true })
         }
-      } else if (this.transport.supportsWriteSettlement !== true) {
-        this.handleWriteSettlement(entry, { ok: true })
+      } else {
+        if (this.drainObservedDuringWrite) {
+          this.handleDrain()
+        }
+        if (this.transport.supportsWriteSettlement !== true) {
+          this.handleWriteSettlement(entry, { ok: true })
+        }
       }
src/relay/dispatcher.ts-408-411 (1)

408-411: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

pty.replay admission failure is silently dropped.

Every other branch in notify closes the client when publication capacity is exceeded, but the pty.replay path ignores the enqueueFrame boolean. If the control lane is at its bound, the client loses replay content with no error and no reconnect signal — the terminal just shows a gap. Either close the client on failure or surface it to the caller.

🐛 Proposed fix
         if (method === 'pty.replay') {
-          this.enqueueFrame(client, msg, 'control')
+          if (!this.enqueueFrame(client, msg, 'control')) {
+            this.closeClient(
+              client,
+              new Error('Relay replay publication capacity exceeded'),
+              client !== this.primaryClient
+            )
+          }
           continue
         }
src/relay/relay-frame-decoder.ts-53-66 (1)

53-66: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Copy non-Buffer frames before retaining them.

Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength) keeps the Uint8Array backing store alive in this.chunks, so a caller that reuses a recycled read buffer can corrupt data still queued for continuation. Since frames are retained across scheduled turns, copy this path instead of sharing the caller’s buffer.

🧹 Nitpick comments (36)
src/relay/relay-pty-source-send-scheduler.ts (1)

76-96: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

rotationPending has no self-release path.

waitForPendingSend latches record.rotationPending = true and only releaseRotationFence (driven by a subsequent activate call) clears it. Any caller that awaits the fence but doesn't reach activate leaves the delivery permanently unpumpable. Today PtyHandler.attach always calls activate, so this is a contract constraint rather than a live bug — worth a one-line comment on the method documenting that callers must always follow up with activate.

src/relay/relay.ts (1)

278-281: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Unbounded waitForIdle on socket close can hang the bridge process.

Exit was previously immediate on close; now it depends on the writer settling. If stdout is wedged (peer gone, no drain, no write callback), --connect never exits and the relay's grace window doesn't start. Consider racing a short timeout.

♻️ Suggested guard
   sock.on('close', async () => {
-    await stdoutWriter.waitForIdle()
+    await Promise.race([
+      stdoutWriter.waitForIdle(),
+      new Promise((resolve) => setTimeout(resolve, 2_000).unref?.())
+    ])
     process.exit(0)
   })
src/relay/ssh-pty-consumer-session-adapter.ts (1)

76-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

sourceCreditEnabled defaults to true, inverting the rollout gate for any caller that omits it.

The feature is meant to be off unless --pty-source-credit-v1 / ORCA_SSH_PTY_SOURCE_CREDIT_V1 is latched. relay.ts passes the flag explicitly, but the default makes every other construction site (tests, future callers) advertise outputFlowControl capabilities. Defaulting to false keeps the fail-safe direction aligned with the gate.

src/relay/pty-handler.ts (1)

1052-1066: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Don’t gate source-credit output resumes on the legacy retention ledger.

legacyRetentionBelowLowWater only checks legacy client retention, while source-credit delivery uses sourcePublication/onCreditAvailable. If this path must never resume source-credit-only PTYs despite source capacity, add a one-line note; otherwise gate resume by sourcePublication availability/capacity.

src/relay/pty-source-replay-index.ts (1)

133-138: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

output.read() on every append makes retention accounting O(n) per span.

read() materializes the whole retained buffer just to obtain its length, and evictUnmappedPrefix runs on each append. On a hot PTY output path with many small spans this degrades to quadratic work plus large transient string allocations.

Prefer tracking retained length directly (or exposing a length/size accessor on RecentPtyOutputBuffer) instead of reading the full buffer.

src/relay/ssh-pty-source-credit-adapter.ts (1)

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

Consider surfacing non-stale ACK rejections.

The blanket catch treats a protocol-violating ACK (e.g. an in-frame cumulative boundary) identically to a benign stale one, so peer bugs on this path are invisible. A debug-level log or a counter would make flow-control regressions diagnosable without changing behavior.

src/main/ipc/ssh-pty-remote-source-range-consumers.ts (2)

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

Centralize the remote: consumer-id encoding.

The prefix is constructed in three places (remoteConsumerId, requiredConsumers, and the trackSpan membership test). A single primitive taking a bare consumerId keeps the wire format in one spot and lets remoteConsumerId delegate to it.

♻️ Proposed refactor
+function remoteConsumerIdFor(consumerId: string): SshPtySourceConsumerId {
+  return `remote:${consumerId}`
+}
+
 function remoteConsumerId(
   identity: RemoteTerminalSourceRangeStreamIdentity
 ): SshPtySourceConsumerId {
-  return `remote:${identity.consumerId}`
+  return remoteConsumerIdFor(identity.consumerId)
 }
   requiredConsumers(ptyId: string): readonly SshPtySourceConsumerId[] {
     return Object.freeze(
-      Array.from(this.consumersByPty.get(ptyId)?.keys() ?? []).map(
-        (consumerId) => `remote:${consumerId}` as const
-      )
+      Array.from(this.consumersByPty.get(ptyId)?.keys() ?? []).map(remoteConsumerIdFor)
     )
   }
     for (const [consumerId, state] of this.consumersByPty.get(ptyId) ?? []) {
-      if (requiredConsumers.includes(`remote:${consumerId}`)) {
+      if (requiredConsumers.includes(remoteConsumerIdFor(consumerId))) {

Also applies to: 58-64, 75-76


236-239: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Redundant union in spanIds.

The second term is filtered to spans already in state.spans, so it can never contribute an id beyond state.spans.keys(). Either drop it or, if the intent was to restrict cancellation to the supplied ranges when non-empty, make that explicit — as written the ranges argument has no effect on which spans are canceled.

♻️ Simplification
-    const spanIds = new Set([
-      ...state.spans.keys(),
-      ...uniqueSpanIds(ranges).filter((spanId) => state.spans.has(spanId))
-    ])
+    const spanIds = new Set(state.spans.keys())
src/relay/pty-source-credit-ledger.ts (1)

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

Simplify the reservation-length resolution.

After the === null early return, reservedLengthSu is number | undefined, so the ?? fallback at Line 146 is the only path that uses Math.min(remainingWindowSu, maxSourceSu). Reading reservedLengthSu twice for that obscures intent; also consider hoisting the 16 * 1024 default into a named constant next to the scheduler's PTY_SOURCE_SCHEDULER_MAX_SU.

♻️ Suggested clarification
-    const reservedLengthSu = reservedPtySourceSendLength(record, remainingWindowSu, maxSourceSu)
-    if (reservedLengthSu === null) {
-      return null
-    }
-    const available = reservedLengthSu ?? Math.min(remainingWindowSu, maxSourceSu)
+    const reservedLengthSu = reservedPtySourceSendLength(record, remainingWindowSu, maxSourceSu)
+    if (reservedLengthSu === null) {
+      return null
+    }
+    // undefined => no reserved ACK boundary; fall back to the full available window.
+    const available = reservedLengthSu === undefined
+      ? Math.min(remainingWindowSu, maxSourceSu)
+      : reservedLengthSu
src/relay/pty-source-credit-record.ts (1)

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

Move the endOffset > 0 guard ahead of the charCodeAt reads.

trailing/following are read before the bounds guard; with maxSourceSu === 0 this reads index -1. Harmless today (NaN comparisons short-circuit and the throw at Line 146 catches it) but the guard placement is misleading.

src/relay/relay-handshake.ts (1)

144-151: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Compare the endpoint credential in constant time.

!== on the shared secret leaks length/prefix timing. The exposure is limited (each mismatch destroys the socket, transport is SSH-tunneled), but timingSafeEqual over hashed buffers is cheap here and avoids the question entirely.

🔒️ Proposed fix
+import { createHash, timingSafeEqual } from 'node:crypto'
+
+function sameCredential(expected: string, received: string | undefined): boolean {
+  const digest = (value: string): Buffer => createHash('sha256').update(value, 'utf8').digest()
+  return received !== undefined && timingSafeEqual(digest(expected), digest(received))
+}
-  if (
-    endpointCredential !== undefined &&
-    ('endpointCredential' in msg ? msg.endpointCredential : undefined) !== endpointCredential
-  ) {
+  if (
+    endpointCredential !== undefined &&
+    !sameCredential(endpointCredential, 'endpointCredential' in msg ? msg.endpointCredential : undefined)
+  ) {
src/relay/relay-pty-source-recovery-completion.ts (1)

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

Reuse onceSinkSettlement instead of redefining it.

relay-pty-source-send-scheduler already exports onceSinkSettlement with identical semantics (it's imported by src/relay/relay-pty-source-exit-publication.ts). Dropping this local copy keeps one settle-once contract.

♻️ Proposed change
-import type { RelayDispatcher, SinkWriteSettlement } from './dispatcher'
-import type { RelayPtySourceDeliveryRecord } from './relay-pty-source-send-scheduler'
+import type { RelayDispatcher } from './dispatcher'
+import {
+  onceSinkSettlement,
+  type RelayPtySourceDeliveryRecord
+} from './relay-pty-source-send-scheduler'
 import type { SshPtyConsumerSessionAdapter } from './ssh-pty-consumer-session-adapter'
-
-function onceSettlement(
-  callback: (result: SinkWriteSettlement) => void
-): (result: SinkWriteSettlement) => void {
-  let settled = false
-  return (result) => {
-    if (settled) {
-      return
-    }
-    settled = true
-    callback(result)
-  }
-}
-  const settle = onceSettlement((result) => {
+  const settle = onceSinkSettlement((result) => {

Check for an import cycle first — relay-pty-source-send-scheduler imports this module.

src/main/ipc/ssh-pty-model-admission-limits.ts (1)

31-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive global low watermarks from the resolved highs.

perPtyLow* correctly derives from the resolved high values, but globalLow* fall back to absolute constants. A caller that lowers only globalHighBytes (e.g. to 16 MiB) ends up with globalLowBytes (48 MiB) above the high mark, so isBelowGlobalLowWatermark() in ssh-pty-model-admission.ts is always true and global resume gating silently disappears.

♻️ Proposed fix
+  const globalHighSourceUnits = options.globalHighSourceUnits ?? DEFAULT_GLOBAL_HIGH_SOURCE_UNITS
+  const globalHighBytes = options.globalHighBytes ?? DEFAULT_GLOBAL_HIGH_BYTES
   return {
     perPtyHighSourceUnits,
     perPtyHighBytes,
     perPtyLowSourceUnits: options.perPtyLowSourceUnits ?? Math.floor(perPtyHighSourceUnits / 2),
     perPtyLowBytes: options.perPtyLowBytes ?? Math.floor(perPtyHighBytes / 2),
-    globalHighSourceUnits: options.globalHighSourceUnits ?? DEFAULT_GLOBAL_HIGH_SOURCE_UNITS,
-    globalHighBytes: options.globalHighBytes ?? DEFAULT_GLOBAL_HIGH_BYTES,
-    globalLowSourceUnits: options.globalLowSourceUnits ?? 8 * 1024 * 1024,
-    globalLowBytes: options.globalLowBytes ?? 48 * 1024 * 1024,
+    globalHighSourceUnits,
+    globalHighBytes,
+    globalLowSourceUnits:
+      options.globalLowSourceUnits ?? Math.min(8 * 1024 * 1024, Math.floor(globalHighSourceUnits / 2)),
+    globalLowBytes: options.globalLowBytes ?? Math.min(48 * 1024 * 1024, Math.floor(globalHighBytes / 2)),
src/main/ipc/ssh-pty-model-admission-pressure.ts (1)

140-144: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Provider-hook error handling is asymmetric and silent.

resume() swallows every resumeProvider failure with a bare catch {} (no log, no metric), while pauseProvider at Line 54 is unguarded — a throw there escapes admit() into the accept() promise executor and rejects the frame instead of taking the intended pressure/close path. Consider guarding pauseProvider (treat a throw as "not paused") and at least logging in the resume catch.

src/main/ipc/ssh-pty-legacy-projection-publication.ts (1)

60-99: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Notify after state mutation.

onSettled at Line 85 runs before record.settledAccounting is advanced and before reclamation; a throwing or re-entrant callback leaves the record half-settled. Move the callback after the counters are updated (and after reclaimProjectionRecord, or collect callbacks and fire them at the end).

src/main/ipc/ssh-pty-source-ack-coalescer.ts (1)

91-111: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

No watchdog if publish never settles.

Once inFlight is set, requestFlush short-circuits and every subsequent ACK stays pending indefinitely if the transport's onSettled is never invoked (dropped channel, swallowed callback). Since ACKs gate source credit, that stalls the whole PTY stream rather than failing fast. Consider a settle deadline that fails the batch so members can retry.

src/main/ipc/ssh-pty-source-obligation-coordinator.test.ts (1)

119-136: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering whenTerminal rejection on dispose/closeGeneration.

dispose and closeGeneration reject outstanding terminal waiters; without a test, an accidental regression there surfaces as unhandled promise rejections in production rather than a failing spec.

src/main/ipc/ssh-pty-output-intake-contract.ts (1)

28-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the source-span shape into one exported type.

This inline source object is structurally identical to the source field of SshPtyLegacyProjectionLedger.reserve(...) args (src/main/ipc/ssh-pty-legacy-projection.ts lines 62-70). Since the intake forwards the event's source straight into reserve, the two can silently diverge (e.g. a new field added on one side only) without a type error.

♻️ Suggested shared type
+export type SshPtySourceSpanRef = Readonly<{
+  relayPtyId?: string
+  spanId: string
+  clientGeneration: number
+  ownerGeneration: number
+  deliveryToken: string
+  sourceStartSu: number
+  sourceEndSu: number
+}>
+
 export type SshPtyOutputDataEvent = Readonly<{
   id: string
   data: string
   providerGeneration: number
   ptyIncarnation: string
   rawLength: number
   transformed: boolean
   sequence?: number
-  source?: Readonly<{
-    relayPtyId?: string
-    spanId: string
-    clientGeneration: number
-    ownerGeneration: number
-    deliveryToken: string
-    sourceStartSu: number
-    sourceEndSu: number
-  }>
+  source?: SshPtySourceSpanRef
 }>

Then have reserve's source reference the same type.

src/main/ipc/pty.ts (1)

3139-3159: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move hasPtyDeliveryPauseAdapter, providerGeneration, and closeOutputIntake onto the provider contract.

These three inline structural casts bypass the type system: a rename on the SSH provider silently degrades to a no-op pause, an unmatched generation, or a skipped intake close, with no compile error. Declaring them as optional members on IPtyProvider (or the SSH provider contract added in this stack) keeps the capability checks honest.

src/main/ipc/ssh.test.ts (2)

352-356: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse createRelayLaunchResult() here.

This inline fixture duplicates the helper at Line 296-300 — this diff had to add serverBuildId to both, which is exactly the drift the helper exists to prevent.

♻️ Proposed fix
-    mockDeployAndLaunchRelay.mockReset().mockResolvedValue({
-      transport: { write: vi.fn(), onData: vi.fn(), onClose: vi.fn() },
-      platform: 'linux-x64',
-      serverBuildId: relayBuildId
-    })
+    mockDeployAndLaunchRelay.mockReset().mockResolvedValue(createRelayLaunchResult())

1549-1554: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

These assertions don't prove the refresh.

mockAcceptSshPtyOutputData/Exit are not cleared between the first and second window in this test, so toHaveBeenCalledWith is satisfied by calls made before the refresh. The renderer assertion below is correctly scoped to secondWindow, but the output-authority half — the thing the renamed title now claims to cover — is not.

Use toHaveBeenLastCalledWith, or clear the intake mocks after the first window's activity and before re-injecting.

src/main/providers/ssh-pty-session-reattach.ts (1)

157-169: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate activation-equality helper.

sameSourceActivation here is field-for-field identical to sameReceivingActivation in src/main/providers/ssh-pty-notification-routing.ts (Lines 193-205). Since both compare the shared PtySourceReceivingActivation contract, exporting a single helper from src/shared/pty-source-receiving-activation.ts keeps the two staleness/identity checks from drifting if the contract gains a field.

src/main/runtime/rpc/terminal-source-range-ledger.test.ts (1)

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

Assert the connection cap via the exported constant.

Line 233 hardcodes 16 * 1024 * 1024, which silently duplicates TERMINAL_SOURCE_RANGE_CONNECTION_MAX_BYTES from terminal-source-range-registry.ts. Referencing the constant (or 8 * TERMINAL_SOURCE_RANGE_STREAM_MAX_BYTES) also makes the "8 saturated streams fill the connection budget" assumption of this test explicit.

src/main/runtime/rpc/terminal-multiplex.test.ts (1)

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

Reuse sendDesktopSourceRangeSubscribe for the inline subscribe frames.

The exact same Subscribe frame with capabilities: { ackOutput: 1, ackOutputSourceRanges: 1 } is rebuilt inline at Lines 330-344, 456-470, 559-573, and 618-632 despite the helper existing at Line 142.

Also applies to: 330-344

src/main/runtime/rpc/terminal-output-frame-source-ranges.test.ts (1)

80-95: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a case that actually exercises the indivisible-split throw.

This test only covers the early-return path where the whole range passes through untouched. The terminal_source_range_indivisible_split error at terminal-output-frame-chunks.ts Line 193 (a non-splittable range straddling a chunk boundary) is currently untested.

src/main/ssh/ssh-relay-session-incarnation.test.ts (1)

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

Intake-registry mock factories drifted from the module's export surface. Both suites stub ../ipc/ssh-pty-output-intake-registry without installSshPtySourceCancellationPublisher and applySshPtySourceCancellationProof, which ssh-relay-session.ts now imports; they pass only because neither suite negotiates outputFlowControl.

  • src/main/ssh/ssh-relay-session-incarnation.test.ts#L19-L26: add both stubs to the factory, matching ssh-relay-session-recovery-races.test.ts.
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts#L19-L26: add the same two stubs.
src/main/ssh/ssh-relay-session.ts (1)

844-850: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

(error as { code?: unknown }).code throws if a nullish value is rejected.

openSshPtyConsumerSession rejecting with undefined/null (e.g. from a mock or a reject() with no arg) turns the recovery-retry path into a TypeError that masks the original failure.

🛡️ Suggested guard
-      if (
-        !previousOwner ||
-        (error as { code?: unknown }).code !== PTY_CONSUMER_STALE_OWNER_RECOVERY_ERROR
-      ) {
+      if (
+        !previousOwner ||
+        (error as { code?: unknown } | null | undefined)?.code !==
+          PTY_CONSUMER_STALE_OWNER_RECOVERY_ERROR
+      ) {
         throw error
       }
src/main/ssh/ssh-relay-session.test.ts (1)

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

Remove the stale mocked SSHC_PTY_SOURCE_WINDOW_SU export.

ssh-relay-session.ts imports and passes DEFAULT_PTY_SOURCE_WINDOW_SU from src/shared/pty-source-credit-contract.ts, and SSH_PTY_SOURCE_WINDOW_SU is no longer consumed elsewhere, so this export can be removed from the vi.mock fixture.

src/main/runtime/rpc/methods/terminal.ts (1)

1908-1914: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Non-accepted ledger results are dropped without a trace.

A stale/mismatched streamGeneration or rejected ack silently stops replenishing the window, which is indistinguishable from an idle stream during debugging. A log or stream error on the rejected branch would make the stall diagnosable.

src/main/ssh/relay-frame-decoder.ts (1)

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

Split the comma-chained export const into separate declarations.

FRAME_DECODER_MAX_TURN_MS = 4, reads like a stray trailing comma and hides a second exported constant on the continuation line.

♻️ Proposed change
-export const FRAME_DECODER_MAX_TURN_MS = 4,
-  FRAME_DECODER_MAX_RETAINED_BYTES = MAX_MESSAGE_SIZE + HEADER_LENGTH + 1024 * 1024
+export const FRAME_DECODER_MAX_TURN_MS = 4
+export const FRAME_DECODER_MAX_RETAINED_BYTES =
+  MAX_MESSAGE_SIZE + HEADER_LENGTH + 1024 * 1024
src/main/ssh/ssh-channel-multiplexer-settlement.test.ts (1)

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

Dispose the multiplexer at the end of this test.

The constructor starts a setInterval health timer and these tests use real timers, so this case leaves a live interval (plus its transport closure) behind for the rest of the run. The other cases either dispose explicitly or are disposed by the failure path.

🧹 Proposed cleanup
     expect(settled).toHaveBeenCalledOnce()
     expect(settled).toHaveBeenCalledWith({ ok: true })
+    mux.dispose()
   })
src/main/ssh/ssh-channel-multiplexer.ts (1)

550-575: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider bounding how long writerSaturated may suppress dead-link detection.

decoderReadPaused self-clears on the next scheduler turn, but writerSaturated only clears on a transport drain. Against a black-hole peer whose send buffer stays full, the health check returns early on every tick, so the mux never declares the link dead and never triggers reconnect until the OS socket layer eventually errors out (which can be many minutes). A saturation-start timestamp with a generous grace window would keep the false-death fix while retaining an upper bound.

src/main/ssh/ssh-multiplexer-transport-writer.ts (1)

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

Fold the liveness lane into the control accounting explicitly.

retain/release/admissionError all treat liveness as "not ordinary" and therefore charge it to controlBytes/controlFrames, which is correct but only implicitly. An explicit lane→bucket mapping helper would make the reserve semantics obvious and prevent a future fourth lane from silently landing in the control reserve.

src/main/ssh/relay-protocol-backpressure.test.ts (1)

161-189: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Suite diverges from the relay copy: missing the oversized-payload resync case.

src/relay/protocol-backpressure.test.ts additionally covers "resynchronizes after an oversized payload across bounded discard turns" (multi-turn discard + subsequent valid frame). Since both decoders are duplicated implementations kept in lockstep, mirroring that case here would keep the SSH-side decoder honest about incremental discard across scheduled turns.

src/relay/dispatcher.ts (1)

190-216: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Binary search fully encodes the frame on every probe.

estimateFrameBytes calls encodeJsonRpcFrame, which serializes and allocates the whole frame. For a 128 KiB PTY chunk this is ~17 full serializations per call on the output hot path. Since the only variable part is the JSON-escaped data slice, consider computing the empty-frame byte cost once (as producerDataBudget already does) and deriving the character bound from it, falling back to the search only when escaping makes the estimate ambiguous.

src/relay/dispatcher-client-writer.ts (1)

254-287: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Subtle synchronous drain reentrancy — worth documenting.

armDrain() can trigger handleDrain() synchronously when waitWriteDrain invokes its callback immediately (e.g. a sink whose drain fires inline rather than on a future tick). In that case handleDrain runs while armDrain is still mid-execution and this.drainArmed/this.saturated get flipped back before armDrain's own post-registration branching runs, relying on the if (this.drainArmed) check to pick the right branch. This is exercised and passes (see the "settles callback-less saturated writes when drain fires during registration" test), but the control flow is easy to break with future edits since nothing calls this out.

A short inline comment noting that waitWriteDrain may invoke its callback synchronously, and that this reentrancy is intentionally handled via the drainArmed flag check, would help future maintainers avoid regressing this path.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c9b1dac-12aa-4903-9e85-9b053452fe03

📥 Commits

Reviewing files that changed from the base of the PR and between 118d1b4e445a2e3db3007a45d53fd0beb63756b2 and db167ea.

📒 Files selected for processing (165)
  • config/reliability-gates.jsonc
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
  • src/main/ipc/pty-pending-data-drain-contract.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh-pty-legacy-projection-publication.ts
  • src/main/ipc/ssh-pty-legacy-projection-record.ts
  • src/main/ipc/ssh-pty-legacy-projection.test.ts
  • src/main/ipc/ssh-pty-legacy-projection.ts
  • src/main/ipc/ssh-pty-model-admission-contract.ts
  • src/main/ipc/ssh-pty-model-admission-entry.ts
  • src/main/ipc/ssh-pty-model-admission-limits.ts
  • src/main/ipc/ssh-pty-model-admission-pressure.ts
  • src/main/ipc/ssh-pty-model-admission.test.ts
  • src/main/ipc/ssh-pty-model-admission.ts
  • src/main/ipc/ssh-pty-output-exit-deadline.ts
  • src/main/ipc/ssh-pty-output-exit.ts
  • src/main/ipc/ssh-pty-output-generation-guard.ts
  • src/main/ipc/ssh-pty-output-intake-contract.ts
  • src/main/ipc/ssh-pty-output-intake-registry.ts
  • src/main/ipc/ssh-pty-output-intake-validation.ts
  • src/main/ipc/ssh-pty-output-intake.test.ts
  • src/main/ipc/ssh-pty-output-intake.ts
  • src/main/ipc/ssh-pty-output-source-obligations.ts
  • src/main/ipc/ssh-pty-projection-terminality.ts
  • src/main/ipc/ssh-pty-remote-source-range-consumers.test.ts
  • src/main/ipc/ssh-pty-remote-source-range-consumers.ts
  • src/main/ipc/ssh-pty-remote-source-range-replacement.ts
  • src/main/ipc/ssh-pty-source-ack-coalescer.test.ts
  • src/main/ipc/ssh-pty-source-ack-coalescer.ts
  • src/main/ipc/ssh-pty-source-ack-publication.ts
  • src/main/ipc/ssh-pty-source-ack-session-contract.test.ts
  • src/main/ipc/ssh-pty-source-obligation-contract.ts
  • src/main/ipc/ssh-pty-source-obligation-coordinator.test.ts
  • src/main/ipc/ssh-pty-source-obligation-coordinator.ts
  • src/main/ipc/ssh-pty-source-obligation-ledger.test.ts
  • src/main/ipc/ssh-pty-source-obligation-ledger.ts
  • src/main/ipc/ssh-pty-source-obligation-state.ts
  • src/main/ipc/ssh-pty-source-obligation-transitions.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-pty-notification-routing.test.ts
  • src/main/providers/ssh-pty-notification-routing.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider-output-state.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-source-frame.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-terminal-source-range-consumer.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/terminal-multiplex.test.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks-equivalence.test.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks.ts
  • src/main/runtime/rpc/terminal-output-frame-source-ranges.test.ts
  • src/main/runtime/rpc/terminal-source-range-ledger.test.ts
  • src/main/runtime/rpc/terminal-source-range-ledger.ts
  • src/main/runtime/rpc/terminal-source-range-registry.ts
  • src/main/runtime/rpc/terminal-source-range-validation.ts
  • src/main/ssh/relay-frame-decoder.ts
  • src/main/ssh/relay-protocol-backpressure.test.ts
  • src/main/ssh/relay-protocol.ts
  • src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts
  • src/main/ssh/ssh-channel-multiplexer-settlement.test.ts
  • src/main/ssh/ssh-channel-multiplexer.test.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/main/ssh/ssh-multiplexer-transport-writer.test.ts
  • src/main/ssh/ssh-multiplexer-transport-writer.ts
  • src/main/ssh/ssh-pty-consumer-session.test.ts
  • src/main/ssh/ssh-pty-consumer-session.ts
  • src/main/ssh/ssh-pty-recovery-retention-budget.test.ts
  • src/main/ssh/ssh-pty-recovery-retention-budget.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.test.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.ts
  • src/main/ssh/ssh-relay-deploy-helpers.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.ts
  • src/main/ssh/ssh-relay-deploy.test.ts
  • src/main/ssh/ssh-relay-deploy.ts
  • src/main/ssh/ssh-relay-gc-retry.test.ts
  • src/main/ssh/ssh-relay-native-deps-install.test.ts
  • src/main/ssh/ssh-relay-session-agent-hooks.integration.test.ts
  • src/main/ssh/ssh-relay-session-data-delivery.test.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-recovery-races.test.ts
  • src/main/ssh/ssh-relay-session-terminal-error.test.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/ssh/ssh-relay-sftp-namespace-install.test.ts
  • src/main/ssh/ssh-remote-cli-launcher.test.ts
  • src/main/ssh/ssh-remote-cli-launcher.ts
  • src/relay/dispatcher-client-writer.test.ts
  • src/relay/dispatcher-client-writer.ts
  • src/relay/dispatcher-writer-admission.ts
  • src/relay/dispatcher-writer-lane-scheduler.ts
  • src/relay/dispatcher-writer-sink.ts
  • src/relay/dispatcher.test.ts
  • src/relay/dispatcher.ts
  • src/relay/fs-stream-pty-echo-backpressure.integration.test.ts
  • src/relay/git-response-pty-echo-backpressure.integration.test.ts
  • src/relay/git-response-stream.ts
  • src/relay/legacy-relay-publication-ledger.test.ts
  • src/relay/legacy-relay-publication-ledger.ts
  • src/relay/protocol-backpressure.test.ts
  • src/relay/protocol.ts
  • src/relay/pty-handler-output-drain-differential.test.ts
  • src/relay/pty-handler-source-publication.test.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/relay/pty-source-cancellation-index.ts
  • src/relay/pty-source-credit-ledger.test.ts
  • src/relay/pty-source-credit-ledger.ts
  • src/relay/pty-source-credit-limits.ts
  • src/relay/pty-source-credit-record.ts
  • src/relay/pty-source-credit-scheduler.test.ts
  • src/relay/pty-source-credit-scheduler.ts
  • src/relay/pty-source-credit-settlement.ts
  • src/relay/pty-source-delivery-ownership.ts
  • src/relay/pty-source-replay-index.test.ts
  • src/relay/pty-source-replay-index.ts
  • src/relay/relay-frame-decoder.ts
  • src/relay/relay-handshake-roundtrip.test.ts
  • src/relay/relay-handshake.ts
  • src/relay/relay-pty-source-activation.ts
  • src/relay/relay-pty-source-exit-publication.ts
  • src/relay/relay-pty-source-output.ts
  • src/relay/relay-pty-source-publication.test.ts
  • src/relay/relay-pty-source-publication.ts
  • src/relay/relay-pty-source-recovery-completion.test.ts
  • src/relay/relay-pty-source-recovery-completion.ts
  • src/relay/relay-pty-source-recovery-interleavings.test.ts
  • src/relay/relay-pty-source-send-scheduler.ts
  • src/relay/relay-watcher-event-emitter.test.ts
  • src/relay/relay-watcher-event-emitter.ts
  • src/relay/relay.ts
  • src/relay/ssh-pty-consumer-session-adapter.test.ts
  • src/relay/ssh-pty-consumer-session-adapter.ts
  • src/relay/ssh-pty-source-credit-adapter.test.ts
  • src/relay/ssh-pty-source-credit-adapter.ts
  • src/relay/wsl-agent-hook-relay.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts
  • src/renderer/src/runtime/runtime-terminal-stream.test.ts
  • src/shared/pty-consumer-session-contract.ts
  • src/shared/pty-consumer-session.test.ts
  • src/shared/pty-consumer-session.ts
  • src/shared/pty-retained-string-memory.ts
  • src/shared/pty-source-credit-contract.ts
  • src/shared/pty-source-credit-validation.ts
  • src/shared/pty-source-receiving-activation.ts
  • src/shared/pty-source-recovery-contract.ts
  • src/shared/relay-frame-decoder-contract.ts
  • src/shared/terminal-output-source-range.ts
  • tests/e2e/helpers/remote-terminal-source-range-contract-fixture.ts
  • tests/e2e/helpers/remote-terminal-source-range-contract-fixture.unit.test.ts
  • tests/e2e/ssh-docker-relay-perf.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md

Comment thread src/main/ipc/pty.ts Resolved
Comment thread src/main/ipc/pty.ts Resolved
Comment thread src/main/ipc/pty.ts Resolved
Comment thread src/main/ipc/ssh-pty-model-admission.ts Resolved
Comment thread src/relay/git-response-stream.ts Resolved
Comment thread src/relay/pty-handler.ts Resolved
Comment thread src/relay/relay-frame-decoder.ts Resolved
Comment thread src/shared/pty-consumer-session.ts Resolved
@OrcaWin
OrcaWin force-pushed the ssh-relay-pty-backpressure branch from db167ea to 5f7330b Compare July 29, 2026 04:33
@OrcaWin

OrcaWin commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Final implementation head is 5f7330bbbcf04c4359952a863c022e9318feab5c (7327640d3a2b1f0d6aa11a3e8c0fc2dea7f63c8d is the exact code/artifact commit; the final commit records evidence only).

The final architecture/lifecycle review is clean, the final transport review's only stale-provenance finding is closed, all 17 prior major threads have exact fix/test replies, and the fresh four-case Docker OpenSSH/deployed-relay gate passed.

@coderabbitai review

Human architecture/terminal review remains requested from @nwparker. Please do not merge until fresh CI and normal maintainer review are complete.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

@OrcaWin: Acknowledged. I’ll review the final implementation, with attention to the exact code/artifact commit and the evidence-only final commit context. I will not approve or recommend merging ahead of fresh CI and normal maintainer review.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

@OrcaWin: Acknowledged. I’ll review the final implementation with the code/artifact commit and evidence-only final commit context in mind. I will not approve or recommend merging before fresh CI and normal maintainer review are complete.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@OrcaWin

OrcaWin commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Final validation checkpoint: current PR head is f4bad7ab3a6700f423279acba592001002792c8a; 7327640d3a2b1f0d6aa11a3e8c0fc2dea7f63c8d remains the exact production implementation/artifact commit, and f4bad7ab3 only aligns deploy fixtures with the shipped credential-publication sequence. Fresh CI run 30423205432 is fully green, including 16/16 unit shards, 10/10 E2E shards, typecheck/static/package/compatibility contracts, Docker watcher isolation, golden macOS/Linux, Ubuntu/Windows smoke, Windows terminal restart, and packaged crash-survival. Current origin/main@1df8aa56051c is eight unrelated commits ahead; synthetic merge tree d4dccc674726548eedea1e1be881575cc874fc62 is conflict-free. There are zero unresolved review threads, GitHub reports CLEAN/MERGEABLE, and the local worktree is clean and matches the PR head. Human architecture/terminal review remains requested from @nwparker; do not merge without normal maintainer approval.

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

🧹 Nitpick comments (9)
src/main/ipc/ssh-pty-output-exit-deadline.test.ts (1)

121-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering the cancellation-proof timeout path.

Both tests exercise resolved or fenced cancellations. The exitCancellationProofMs deadline (which rejects with ssh_source_cancellation_proof_timeout and triggers closeProvider('ssh-exit-cancellation-proof-failed')) is never reached — advancing past 100ms with the pending cancellation promise would cover it cheaply since fake timers are already in place.

src/main/ipc/ssh-pty-output-intake.ts (1)

158-173: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Rejection handler dereferences error without a null guard.

If a dependency rejects with undefined/null (e.g. a bare Promise.reject() from acceptModel's completion), Line 165 throws a TypeError that replaces the original rejection and skips the closeProvider decision entirely.

🛡️ Proposed guard
-        const code = (error as { code?: unknown }).code
+        const code = (error as { code?: unknown } | null | undefined)?.code
src/main/providers/ssh-pty-notification-routing.ts (1)

110-128: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Unbounded pty.cancelDelivery fan-out on repeated malformed/non-admitted frames.

Every malformed or rejected frame issues its own cancel request for the same (relayPtyId, deliveryToken). A misbehaving or out-of-sync relay streaming such frames turns each one into an outbound RPC. Consider deduping per delivery token (e.g., a short-lived set of already-canceled tokens) so at most one cancel is in flight per delivery.

src/main/ssh/ssh-relay-session-data-delivery.test.ts (1)

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

Collapse the four repeated dynamic imports of the same module.

../ipc/ssh-pty-output-intake-registry is imported four times for four named exports; one destructuring import is clearer.

♻️ Proposed consolidation
-const { closeSshPtyOutputGeneration } = await import('../ipc/ssh-pty-output-intake-registry')
-const { applySshPtySourceCancellationProof } = await import('../ipc/ssh-pty-output-intake-registry')
-const { applySshPtySourceRecoveryCancellationProof } =
-  await import('../ipc/ssh-pty-output-intake-registry')
-const { getSshPtyAcceptedSourceCheckpoints } = await import('../ipc/ssh-pty-output-intake-registry')
-const { installSshPtySourceAckPublisher } = await import('../ipc/ssh-pty-output-intake-registry')
+const {
+  applySshPtySourceCancellationProof,
+  applySshPtySourceRecoveryCancellationProof,
+  closeSshPtyOutputGeneration,
+  getSshPtyAcceptedSourceCheckpoints,
+  installSshPtySourceAckPublisher
+} = await import('../ipc/ssh-pty-output-intake-registry')
src/main/ssh/ssh-relay-session-recovery-races.test.ts (1)

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

Derive the over-capacity payload size from the shared limit constant.

2 * 1024 * 1024 + 1 hardcodes the admission capacity threshold. If that limit moves, this test stops exercising the capacity-rejection path it names. Importing the constant (as terminal-source-range-ledger.test.ts does with TERMINAL_SOURCE_RANGE_STREAM_MAX_BYTES) keeps them in lockstep.

src/main/runtime/rpc/terminal-source-range-ledger.test.ts (1)

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

Express the aggregate bound in terms of the imported per-stream constant.

Line 321 hardcodes 16 * 1024 * 1024, which silently encodes TERMINAL_SOURCE_RANGE_STREAM_MAX_BYTES === 2 MiB. Deriving it keeps the assertion meaningful if the per-stream cap moves.

♻️ Proposed change
-    expect(registry.getDebugSnapshot().retainedBytes).toBe(16 * 1024 * 1024)
+    expect(registry.getDebugSnapshot().retainedBytes).toBe(
+      8 * TERMINAL_SOURCE_RANGE_STREAM_MAX_BYTES
+    )
src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts (1)

18-29: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Consumed slots are never released while a lane stays non-empty.

shift only truncates when head reaches entries.length. A lane that stays continuously backlogged (the saturated-writer case this scheduler exists for) keeps growing entries while the leading head slots still hold references to already-written frames, so those frames can't be collected. Null the consumed slot and/or compact once head passes a threshold.

♻️ Proposed compaction
 function shift<T>(queue: LaneQueue<T>): T | undefined {
   const entry = queue.entries[queue.head]
   if (entry === undefined) {
     return undefined
   }
+  queue.entries[queue.head] = undefined as unknown as T
   queue.head += 1
   if (queue.head === queue.entries.length) {
     queue.entries.length = 0
     queue.head = 0
+  } else if (queue.head >= 1024 && queue.head * 2 >= queue.entries.length) {
+    queue.entries = queue.entries.slice(queue.head)
+    queue.head = 0
   }
   return entry
 }

(Requires dropping readonly on the entries field or mutating via splice.)

src/shared/relay-frame-buffer.ts (1)

25-39: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add bounds guards to peek/take/discard.

All three dereference this.chunks[0] without checking count <= this.bytes. Today's decoder callers always pre-check length, but an over-request from a future caller yields Cannot read properties of undefined (reading 'length'), and discard additionally drives this.bytes negative — which silently breaks every subsequent length check instead of failing fast. A single guard per method makes the contract explicit for this shared primitive.

🛡️ Proposed guards
   peek(count: number): Buffer {
+    if (count > this.bytes) {
+      throw new RangeError(`RelayFrameBuffer.peek(${count}) exceeds ${this.bytes} buffered bytes`)
+    }
     const first = this.chunks[0]
   take(count: number): Buffer {
+    if (count > this.bytes) {
+      throw new RangeError(`RelayFrameBuffer.take(${count}) exceeds ${this.bytes} buffered bytes`)
+    }
     const first = this.chunks[0]
   discard(count: number): void {
+    if (count > this.bytes) {
+      throw new RangeError(
+        `RelayFrameBuffer.discard(${count}) exceeds ${this.bytes} buffered bytes`
+      )
+    }
     let remaining = count

Also applies to: 41-68, 70-83

src/relay/relay-handshake-roundtrip.test.ts (1)

127-142: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Add the matching-credential accept case.

This only proves rejection. A regression that closes every same-build socket once endpointCredential is configured — or that ignores the credential and rejects unconditionally — still passes. Pair it with a test that passes 'secret-credential' to both startDaemon and runConnectHandshake and asserts accepted resolves.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3e48674-edd0-44ca-a751-8cbdcede95c3

📥 Commits

Reviewing files that changed from the base of the PR and between db167ea and f4bad7a.

📒 Files selected for processing (190)
  • config/reliability-gates.jsonc
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
  • src/main/ipc/pty-pending-data-drain-contract.ts
  • src/main/ipc/pty-pending-projection-admissions.test.ts
  • src/main/ipc/pty-pending-projection-admissions.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/main/ipc/ssh-pty-closed-generation-ranges.ts
  • src/main/ipc/ssh-pty-legacy-projection-publication.ts
  • src/main/ipc/ssh-pty-legacy-projection-record.ts
  • src/main/ipc/ssh-pty-legacy-projection.test.ts
  • src/main/ipc/ssh-pty-legacy-projection.ts
  • src/main/ipc/ssh-pty-model-admission-contract.ts
  • src/main/ipc/ssh-pty-model-admission-entry.ts
  • src/main/ipc/ssh-pty-model-admission-limits.ts
  • src/main/ipc/ssh-pty-model-admission-migration.ts
  • src/main/ipc/ssh-pty-model-admission-pressure.ts
  • src/main/ipc/ssh-pty-model-admission-snapshot.ts
  • src/main/ipc/ssh-pty-model-admission.test.ts
  • src/main/ipc/ssh-pty-model-admission.ts
  • src/main/ipc/ssh-pty-output-exit-deadline.test.ts
  • src/main/ipc/ssh-pty-output-exit-deadline.ts
  • src/main/ipc/ssh-pty-output-exit.ts
  • src/main/ipc/ssh-pty-output-generation-guard.test.ts
  • src/main/ipc/ssh-pty-output-generation-guard.ts
  • src/main/ipc/ssh-pty-output-intake-contract.ts
  • src/main/ipc/ssh-pty-output-intake-registry.ts
  • src/main/ipc/ssh-pty-output-intake-test-harness.ts
  • src/main/ipc/ssh-pty-output-intake-validation.ts
  • src/main/ipc/ssh-pty-output-intake.test.ts
  • src/main/ipc/ssh-pty-output-intake.ts
  • src/main/ipc/ssh-pty-output-model-migration.test.ts
  • src/main/ipc/ssh-pty-output-model-migration.ts
  • src/main/ipc/ssh-pty-output-source-obligations.ts
  • src/main/ipc/ssh-pty-projection-terminality.ts
  • src/main/ipc/ssh-pty-remote-source-range-consumers.test.ts
  • src/main/ipc/ssh-pty-remote-source-range-consumers.ts
  • src/main/ipc/ssh-pty-remote-source-range-replacement.ts
  • src/main/ipc/ssh-pty-source-ack-coalescer.test.ts
  • src/main/ipc/ssh-pty-source-ack-coalescer.ts
  • src/main/ipc/ssh-pty-source-ack-publication.ts
  • src/main/ipc/ssh-pty-source-ack-session-contract.test.ts
  • src/main/ipc/ssh-pty-source-obligation-contract.ts
  • src/main/ipc/ssh-pty-source-obligation-coordinator.test.ts
  • src/main/ipc/ssh-pty-source-obligation-coordinator.ts
  • src/main/ipc/ssh-pty-source-obligation-ledger.test.ts
  • src/main/ipc/ssh-pty-source-obligation-ledger.ts
  • src/main/ipc/ssh-pty-source-obligation-state.ts
  • src/main/ipc/ssh-pty-source-obligation-transitions.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh.ts
  • src/main/providers/pty-spawn-result.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/providers/ssh-pty-notification-routing.test.ts
  • src/main/providers/ssh-pty-notification-routing.ts
  • src/main/providers/ssh-pty-provider-agent-session-create-operation.test.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/providers/ssh-pty-provider-output-state.ts
  • src/main/providers/ssh-pty-provider-process-events.test.ts
  • src/main/providers/ssh-pty-provider-reattach-incarnation.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/main/providers/ssh-pty-session-reattach.ts
  • src/main/providers/ssh-pty-source-delivery-ledger.test.ts
  • src/main/providers/ssh-pty-source-delivery-ledger.ts
  • src/main/providers/ssh-pty-source-frame.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-terminal-source-range-consumer.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/terminal-multiplex.test.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks-equivalence.test.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks.ts
  • src/main/runtime/rpc/terminal-output-frame-source-ranges.test.ts
  • src/main/runtime/rpc/terminal-source-range-ledger.test.ts
  • src/main/runtime/rpc/terminal-source-range-ledger.ts
  • src/main/runtime/rpc/terminal-source-range-registry.ts
  • src/main/runtime/rpc/terminal-source-range-validation.ts
  • src/main/ssh/relay-frame-decoder.ts
  • src/main/ssh/relay-protocol-backpressure.test.ts
  • src/main/ssh/relay-protocol.ts
  • src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts
  • src/main/ssh/ssh-channel-multiplexer-settlement.test.ts
  • src/main/ssh/ssh-channel-multiplexer.test.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/main/ssh/ssh-multiplexer-transport-writer.test.ts
  • src/main/ssh/ssh-multiplexer-transport-writer.ts
  • src/main/ssh/ssh-multiplexer-writer-lane-scheduler.ts
  • src/main/ssh/ssh-pty-consumer-session.test.ts
  • src/main/ssh/ssh-pty-consumer-session.ts
  • src/main/ssh/ssh-pty-recovery-retention-budget.test.ts
  • src/main/ssh/ssh-pty-recovery-retention-budget.ts
  • src/main/ssh/ssh-pty-retired-source-deliveries.test.ts
  • src/main/ssh/ssh-pty-retired-source-deliveries.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.test.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.ts
  • src/main/ssh/ssh-relay-cross-version-isolation.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.ts
  • src/main/ssh/ssh-relay-deploy.test.ts
  • src/main/ssh/ssh-relay-deploy.ts
  • src/main/ssh/ssh-relay-endpoint-credential.test.ts
  • src/main/ssh/ssh-relay-endpoint-credential.ts
  • src/main/ssh/ssh-relay-gc-retry.test.ts
  • src/main/ssh/ssh-relay-native-deps-install-fixture.ts
  • src/main/ssh/ssh-relay-native-deps-install.test.ts
  • src/main/ssh/ssh-relay-session-agent-hooks.integration.test.ts
  • src/main/ssh/ssh-relay-session-data-delivery.test.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-model-migration.test.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session-recovery-races.test.ts
  • src/main/ssh/ssh-relay-session-terminal-error.test.ts
  • src/main/ssh/ssh-relay-session-test-fixtures.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/ssh/ssh-relay-sftp-namespace-install.test.ts
  • src/main/ssh/ssh-remote-cli-launcher.test.ts
  • src/main/ssh/ssh-remote-cli-launcher.ts
  • src/relay/dispatcher-client-writer.test.ts
  • src/relay/dispatcher-client-writer.ts
  • src/relay/dispatcher-writer-admission.ts
  • src/relay/dispatcher-writer-lane-scheduler.ts
  • src/relay/dispatcher-writer-sink.ts
  • src/relay/dispatcher.test.ts
  • src/relay/dispatcher.ts
  • src/relay/fs-stream-pty-echo-backpressure.integration.test.ts
  • src/relay/git-response-pty-echo-backpressure.integration.test.ts
  • src/relay/git-response-stream-ownership.test.ts
  • src/relay/git-response-stream.ts
  • src/relay/legacy-relay-publication-ledger.test.ts
  • src/relay/legacy-relay-publication-ledger.ts
  • src/relay/protocol-backpressure.test.ts
  • src/relay/protocol.ts
  • src/relay/pty-handler-output-drain-differential.test.ts
  • src/relay/pty-handler-source-publication.test.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/relay/pty-source-cancellation-index.ts
  • src/relay/pty-source-credit-ledger.test.ts
  • src/relay/pty-source-credit-ledger.ts
  • src/relay/pty-source-credit-limits.ts
  • src/relay/pty-source-credit-record.ts
  • src/relay/pty-source-credit-scheduler.test.ts
  • src/relay/pty-source-credit-scheduler.ts
  • src/relay/pty-source-credit-settlement.ts
  • src/relay/pty-source-delivery-ownership.ts
  • src/relay/pty-source-replay-index.test.ts
  • src/relay/pty-source-replay-index.ts
  • src/relay/relay-frame-decoder.ts
  • src/relay/relay-handshake-roundtrip.test.ts
  • src/relay/relay-handshake.ts
  • src/relay/relay-pty-source-activation.ts
  • src/relay/relay-pty-source-exit-publication.ts
  • src/relay/relay-pty-source-output.ts
  • src/relay/relay-pty-source-publication.test.ts
  • src/relay/relay-pty-source-publication.ts
  • src/relay/relay-pty-source-recovery-completion.test.ts
  • src/relay/relay-pty-source-recovery-completion.ts
  • src/relay/relay-pty-source-recovery-interleavings.test.ts
  • src/relay/relay-pty-source-restore-retry.test.ts
  • src/relay/relay-pty-source-send-scheduler.ts
  • src/relay/relay-watcher-event-emitter.test.ts
  • src/relay/relay-watcher-event-emitter.ts
  • src/relay/relay.ts
  • src/relay/ssh-pty-consumer-session-adapter.test.ts
  • src/relay/ssh-pty-consumer-session-adapter.ts
  • src/relay/ssh-pty-source-credit-adapter.test.ts
  • src/relay/ssh-pty-source-credit-adapter.ts
  • src/relay/wsl-agent-hook-relay.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts
  • src/renderer/src/runtime/runtime-terminal-stream.test.ts
  • src/shared/pty-consumer-session-contract.ts
  • src/shared/pty-consumer-session.test.ts
  • src/shared/pty-consumer-session.ts
  • src/shared/pty-retained-string-memory.ts
  • src/shared/pty-source-credit-contract.ts
  • src/shared/pty-source-credit-validation.ts
  • src/shared/pty-source-receiving-activation.ts
  • src/shared/pty-source-recovery-contract.ts
  • src/shared/relay-frame-buffer.ts
  • src/shared/relay-frame-decoder-contract.ts
  • src/shared/terminal-output-source-range.ts
  • tests/e2e/helpers/remote-terminal-source-range-contract-fixture.ts
  • tests/e2e/helpers/remote-terminal-source-range-contract-fixture.unit.test.ts
  • tests/e2e/ssh-docker-relay-perf.spec.ts
🚧 Files skipped from review as they are similar to previous changes (136)
  • src/main/ipc/ssh-pty-output-intake-validation.ts
  • src/main/ipc/ssh-pty-source-ack-publication.ts
  • src/main/providers/ssh-pty-spawn-env.ts
  • src/shared/pty-retained-string-memory.ts
  • src/main/ipc/ssh-pty-model-admission-contract.ts
  • tests/e2e/helpers/remote-terminal-source-range-contract-fixture.unit.test.ts
  • src/main/providers/pty-spawn-result.ts
  • src/relay/legacy-relay-publication-ledger.test.ts
  • src/relay/relay-watcher-event-emitter.test.ts
  • src/main/ipc/ssh-pty-source-obligation-coordinator.test.ts
  • src/relay/pty-source-delivery-ownership.ts
  • src/main/runtime/rpc/terminal-output-frame-source-ranges.test.ts
  • src/shared/pty-source-receiving-activation.ts
  • src/main/ssh/ssh-relay-gc-retry.test.ts
  • src/relay/relay-pty-source-output.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.ts
  • src/main/ipc/ssh-pty-model-admission-limits.ts
  • src/main/ssh/ssh-pty-recovery-retention-budget.test.ts
  • src/relay/pty-handler-output-drain-differential.test.ts
  • src/relay/relay-pty-source-recovery-interleavings.test.ts
  • src/relay/relay-pty-source-recovery-completion.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/shared/pty-source-credit-contract.ts
  • src/main/ipc/ssh-pty-source-obligation-contract.ts
  • src/main/ssh/ssh-remote-cli-launcher.test.ts
  • src/relay/pty-source-credit-scheduler.ts
  • src/main/ipc/pty-pending-data-drain-contract.ts
  • src/main/ipc/ssh.ts
  • src/shared/pty-source-credit-validation.ts
  • src/relay/relay-watcher-event-emitter.ts
  • src/shared/terminal-output-source-range.ts
  • src/shared/pty-source-recovery-contract.ts
  • src/main/runtime/rpc/terminal-source-range-registry.ts
  • src/relay/git-response-stream.ts
  • src/relay/pty-source-credit-limits.ts
  • src/main/ipc/ssh-pty-source-ack-coalescer.test.ts
  • src/main/ssh/ssh-pty-consumer-session.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts
  • src/main/ssh/ssh-pty-consumer-session.test.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
  • src/main/ipc/ssh-pty-model-admission-pressure.ts
  • src/main/providers/ssh-pty-provider-contract.ts
  • src/main/ipc/ssh-pty-output-intake-contract.ts
  • src/main/ipc/ssh-pty-source-ack-session-contract.test.ts
  • tests/e2e/ssh-docker-relay-perf.spec.ts
  • src/main/ssh/ssh-relay-deploy-helpers.ts
  • src/relay/dispatcher-writer-lane-scheduler.ts
  • src/main/ipc/ssh-pty-output-generation-guard.ts
  • src/relay/wsl-agent-hook-relay.ts
  • src/relay/fs-stream-pty-echo-backpressure.integration.test.ts
  • src/shared/pty-consumer-session-contract.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks-equivalence.test.ts
  • src/main/ipc/ssh-pty-output-exit.ts
  • src/main/ssh/ssh-relay-session-incarnation.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.test.ts
  • src/relay/relay-handshake.ts
  • src/relay/pty-source-replay-index.test.ts
  • src/main/ipc/ssh-pty-projection-terminality.ts
  • tests/e2e/helpers/remote-terminal-source-range-contract-fixture.ts
  • src/main/ssh/ssh-channel-multiplexer.test.ts
  • src/main/ssh/ssh-channel-multiplexer-backpressure.test.ts
  • src/main/ssh/relay-protocol-backpressure.test.ts
  • src/main/providers/ssh-pty-provider-exit-race.test.ts
  • src/main/ipc/ssh-pty-source-obligation-state.ts
  • src/main/ipc/ssh-pty-model-admission-entry.ts
  • src/relay/pty-source-credit-settlement.ts
  • src/main/ipc/ssh-pty-legacy-projection-record.ts
  • src/main/ssh/ssh-channel-multiplexer-settlement.test.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.test.ts
  • src/main/ipc/ssh-pty-output-intake-registry.ts
  • src/main/providers/ssh-pty-source-frame.ts
  • src/shared/pty-consumer-session.test.ts
  • src/renderer/src/runtime/runtime-terminal-stream.test.ts
  • src/relay/legacy-relay-publication-ledger.ts
  • src/relay/dispatcher-writer-sink.ts
  • src/main/ipc/ssh-pty-source-obligation-coordinator.ts
  • src/relay/git-response-pty-echo-backpressure.integration.test.ts
  • src/main/runtime/remote-terminal-source-range-consumer.ts
  • src/relay/relay-pty-source-exit-publication.ts
  • src/main/ssh/ssh-relay-session-terminal-error.test.ts
  • src/relay/ssh-pty-source-credit-adapter.test.ts
  • src/main/ssh/ssh-remote-cli-launcher.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • src/relay/pty-source-credit-ledger.ts
  • src/relay/protocol.ts
  • src/main/ssh/relay-protocol.ts
  • src/relay/pty-source-replay-index.ts
  • src/main/providers/ssh-pty-provider-output-state.ts
  • src/main/ipc/ssh-pty-source-ack-coalescer.ts
  • src/main/providers/ssh-pty-notification-routing.test.ts
  • src/main/ssh/ssh-pty-recovery-retention-budget.ts
  • src/relay/protocol-backpressure.test.ts
  • src/relay/pty-source-cancellation-index.ts
  • src/main/ipc/ssh-pty-legacy-projection.test.ts
  • src/main/ssh/ssh-multiplexer-transport-writer.test.ts
  • src/main/ssh/ssh-relay-session-agent-hooks.integration.test.ts
  • src/relay/relay-pty-source-recovery-completion.test.ts
  • src/relay/relay-pty-source-send-scheduler.ts
  • src/main/ssh/ssh-multiplexer-transport-writer.ts
  • src/shared/pty-consumer-session.ts
  • src/relay/dispatcher-client-writer.ts
  • src/main/providers/ssh-agent-session-create-operation.ts
  • src/main/ipc/ssh-pty-remote-source-range-replacement.ts
  • src/main/ipc/ssh-pty-legacy-projection.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks.ts
  • src/relay/pty-handler.test.ts
  • src/main/ssh/ssh-relay-session.test.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/relay/relay-pty-source-publication.test.ts
  • src/relay/ssh-pty-consumer-session-adapter.ts
  • src/main/ipc/ssh.test.ts
  • src/main/ipc/ssh-pty-source-obligation-ledger.ts
  • src/main/providers/ssh-pty-provider.ts
  • src/relay/pty-source-credit-record.ts
  • src/relay/ssh-pty-consumer-session-adapter.test.ts
  • src/relay/dispatcher-client-writer.test.ts
  • src/main/ipc/ssh-pty-output-intake.test.ts
  • src/relay/dispatcher-writer-admission.ts
  • src/main/ipc/ssh-pty-remote-source-range-consumers.ts
  • src/main/ipc/pty.ts
  • src/main/ssh/relay-frame-decoder.ts
  • src/relay/relay-pty-source-publication.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/relay/ssh-pty-source-credit-adapter.ts
  • src/main/runtime/rpc/terminal-source-range-ledger.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/relay/relay.ts
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md
  • src/main/ssh/ssh-relay-sftp-namespace-install.test.ts
  • src/relay/pty-source-credit-ledger.test.ts
  • src/main/providers/ssh-pty-provider.test.ts
  • src/relay/pty-handler.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/pty-handler-source-publication.test.ts
  • src/relay/dispatcher.ts

Comment thread src/main/ssh/ssh-relay-deploy.ts Resolved

@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

🧹 Nitpick comments (1)
src/renderer/src/i18n/locales/en.json (1)

7037-7039: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Locale keys break the SshTargetForm hash-key convention.

The new keys (ptySourceCreditV1Label, ptySourceCreditV1Description, ptySourceCreditV1Toggle) are descriptive, while every other key in this SshTargetForm namespace is a 10-char SHA1-style hash. Consider regenerating these as hash keys and syncing via pnpm bootstrap:locale-catalog / pnpm sync:localization-catalog for consistency with the established per-namespace convention.

Based on learnings: "use hash-based locale keys with translate('auto.components.<Dir>.<ComponentFile>.<10-char-hash>', 'Default English text')" and "prefer semantic locale keys when they match the established neighboring namespaces ... Hash-based keys may be generated for unnamed strings, but they are not a blanket requirement" — since the neighboring SshTargetForm namespace is entirely hash-based, the new descriptive keys don't match its established convention.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f1eecd51-621c-4f62-a693-7f4bae246559

📥 Commits

Reviewing files that changed from the base of the PR and between f4bad7a and aca0580.

📒 Files selected for processing (21)
  • config/reliability-gates.jsonc
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md
  • src/main/ipc/ssh.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.test.ts
  • src/main/ssh/ssh-pty-source-credit-rollout.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/renderer/src/components/settings/SshHostAdvancedFields.test.tsx
  • src/renderer/src/components/settings/SshHostAdvancedFields.tsx
  • src/renderer/src/components/settings/ssh-target-draft.test.ts
  • src/renderer/src/components/settings/ssh-target-draft.ts
  • src/renderer/src/components/settings/ssh-target-save-payload.test.ts
  • src/renderer/src/components/settings/ssh-target-save-payload.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/ssh-types.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/plans/2026-07-27-ssh-relay-pty-backpressure.md
  • src/main/ssh/ssh-relay-session.ts

@OrcaWin

OrcaWin commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Final current-main checkpoint: production merge commit adba341 is validated by the exact four-case Docker SSH run; current PR head 728ed98 adds only provenance. The PR body now records the always-on same-build V1 decision, negotiated legacy behavior, exact hashes/results, and remaining topology gaps. All review threads are resolved, main is an ancestor, and fresh CI is running. @coderabbitai review Human architecture/terminal review remains requested from @nwparker. Do not merge until CI and normal maintainer review complete.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

@OrcaWin: Acknowledged. I’ll review the current-main/provenance state, treating adba3410fe as the production implementation baseline and 728ed98ab7 as provenance-only context. I will not approve or recommend merging until fresh CI completes and normal maintainer review—including the requested architecture/terminal review from @nwparker—is complete.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@OrcaWin

OrcaWin commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Final validation checkpoint: current head is 8c35d4f89826e5a38ee5642434caf557ef71b89d, tree b2e35b5fdab000cb5475345298baa64b67190fce, and the local worktree is clean and matches origin/ssh-relay-pty-backpressure. Fresh GitHub CI is green: PR Checks run 30497200229 attempt 2 has 35/35 jobs green, with 41 passing checks total and 3 expected platform skips. The only first-attempt failure was an unrelated combined-diff scroll E2E flake; the exact test passed locally and the failed job passed on rerun. All 26 review threads are resolved. Current origin/main@0349cb6bdbdb19119585ecb6048d884c5ee8b97d is nine unrelated commits ahead of the last branch merge, and synthetic merge tree 802c27aa3c0a3c28e1c3c8176c5eb876e8d522b5 is conflict-free. No material implementation, design, test, CI, or cleanup issue remains. The concrete external blocker is the requested human architecture/terminal review from @nwparker; do not merge until normal maintainer approval is complete.

@OrcaWin
OrcaWin merged commit 5f78074 into main Jul 30, 2026
78 of 79 checks passed
nwparker added a commit that referenced this pull request Aug 1, 2026
…pacity (#11917)

* fix(relay): chunk fs.changed notifications to fit the client frame capacity

emitRelayWatcherEvents published an entire watcher batch as one
fs.changed notification on the ordinary lane. A batch runs routinely
tens of times over the per-frame producer capacity (12,288 bytes against
a Node <=21 socket, 49,152 against Node >=22), and an over-capacity
frame there is not queued or trimmed -- notify() fails admission and
closes the client, tearing down every in-flight request on that
connection. Regressed in 5f78074 (#11005).

The emitter now sizes chunks against the tightest capacity across
attached clients, measured in encoded bytes through the same envelope
admission measures, and preserves event order. A single event too large
for an empty envelope cannot be chunked, so the ordinary-lane close
remains its backstop: a silent drop on this lane has no resync contract.

* chore(relay): shorten watcher chunking comments
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* docs: design SSH relay PTY backpressure

* fix(ssh): bound relay frame decoding

* fix(relay): bound PTY output publication

* fix(ssh): bound PTY model admission

* fix(ssh): settle closed model admissions

* feat(ssh): negotiate bounded PTY consumer sessions

* fix(ssh): fence exit on renderer settlement

* feat(ssh): track PTY source credit end to end

* fix(ssh): recover bounded PTY output across reconnect

* feat(ssh): complete relay PTY output backpressure

* fix(ssh): close final PTY source credit races

* docs(ssh): record final backpressure validation

* feat(ssh): complete relay PTY source-credit lifecycle

* test(ssh): complete provider notification fixture

* fix(ssh): preserve terminal source credit across rotation

* fix(ssh): fail closed on recovery cancellation

* fix(ssh): prioritize mux control writes after drain

* fix(ssh): retire canceled relay restore deliveries

* fix(ssh): order exit cancellation cleanup

* fix(ssh): gate provisional source activation

* test(ssh): register mux drain-priority coverage

* fix(ssh): type stale owner recovery mismatches

* fix(ssh): close projection replacement races

* fix(relay): contain streaming edge failures

* fix(ssh): secure relay endpoint credentials

* docs(ssh): reconcile final backpressure lifecycle

* fix(ssh): bound main IPC output lifecycle

* fix(ssh): close recovery ownership gaps

* docs(ssh): record exact artifact validation

* fix(ssh): reject reclaimed snapshot replacements

* fix(ssh): fence model admission across reconnect

* fix(ssh): contain migration failure per PTY

* docs(ssh): record final exact-head validation

* test(ssh): align deploy fixtures with credential publication

* feat(ssh): add per-target bounded output setting

* fix(ssh): close source recovery review gaps

* fix(ssh): latch source credit environment override

* feat(ssh): make PTY source credit the default

* docs(ssh): record always-on relay validation

* docs(ssh): bind validation to current main

* test(ssh): grant source credit in IPC fixture

* test(ssh): grant source credit in fake relay

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…pacity (stablyai#11917)

* fix(relay): chunk fs.changed notifications to fit the client frame capacity

emitRelayWatcherEvents published an entire watcher batch as one
fs.changed notification on the ordinary lane. A batch runs routinely
tens of times over the per-frame producer capacity (12,288 bytes against
a Node <=21 socket, 49,152 against Node >=22), and an over-capacity
frame there is not queued or trimmed -- notify() fails admission and
closes the client, tearing down every in-flight request on that
connection. Regressed in 63ec0b0 (stablyai#11005).

The emitter now sizes chunks against the tightest capacity across
attached clients, measured in encoded bytes through the same envelope
admission measures, and preserves event order. A single event too large
for an empty envelope cannot be chunked, so the ordinary-lane close
remains its backstop: a silent drop on this lane has no resync contract.

* chore(relay): shorten watcher chunking comments
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.

2 participants