perf(runtime): gate PTY path-candidate extraction on mobile-connected#9422
Draft
nwparker wants to merge 1 commit into
Draft
perf(runtime): gate PTY path-candidate extraction on mobile-connected#9422nwparker wants to merge 1 commit into
nwparker wants to merge 1 commit into
Conversation
The 3-regex path extractor ran on every PTY chunk of every session for a mobile-only consumer. Now gated behind a sticky mobile-connected flag; first onReady synchronously backfills candidates from the retained 64KB window per original chunk boundary (lazy safety-net fallback). ~28.5us/chunk (~99.8%) saved on the desktop-only hot path; mobile parity preserved (Tier-1 raw-window read unchanged + backfill before any file RPC). 5-round review converged 2-consecutive-clean; independently verified tsc+902 tests. Co-authored-by: Orca <help@stably.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TITLE: perf(runtime): gate PTY path-candidate extraction on mobile-connected
BRANCH: nwparker/perf-path-candidate-gate
Description
Terminal path provenance for the mobile file-tap feature runs a 3-regex path extractor (
appendRecentPtyPathCandidates) on every PTY chunk of every session, insiderecordRecentPtyOutputForPathProvenance(src/main/runtime/orca-runtime.ts:8121). The sole consumer of the extracted candidates ishasRecentTerminalOutputPath(orca-runtime.ts:8163), reached only from the mobile file-tap provenance check inorca-runtime-files.ts:695. Desktop-only sessions — which never open that path — pay the full extraction cost for nothing.This change gates the extraction behind a sticky "a mobile/remote client has authenticated this session" flag:
orca-runtime.ts— newprivate recentPtyPathCandidateTrackingActive = false. InrecordRecentPtyOutputForPathProvenancethe rawRecentPtyOutputBuffer.append(data)stays unconditional (it also feeds terminal replay at:15790); only theappendRecentPtyPathCandidatescall is wrapped in the flag. New idempotentactivateRecentPtyPathCandidateTracking()sets the flag and synchronously backfills candidates from every retained raw buffer, replaying each buffer's original chunk boundaries (via newRecentPtyOutputBuffer.retainedChunks()) so the candidate set matches per-chunk extraction.hasRecentTerminalOutputPathlazily activates on first call as a safety net.recent-pty-output-buffer.ts— addsretainedChunks()/compact()to expose original chunk boundaries for backfill parity while preserving the read-time collapse/defrag invariant.runtime-rpc.ts:894— theMobileSocketWiringonReadychokepoint now callsactivateRecentPtyPathCandidateTracking(). Direct WS transport and the cloud relay transport (relay/relay-control-origin.ts:56) both attach to this same wiring, so one hook covers all mobile/remote/SSH-hosted PTY paths (recentPtyOutputByIdis keyed byptyIdregardless of host).Over-limit chunks (>64KiB) are still extracted eagerly at append, since their original text is unrecoverable after the buffer pre-slices them.
Documented, accepted best-effort loss (not hidden): output that scrolled past the 64KiB raw window before the first-ever mobile connect no longer yields candidates. This is unreachable for real taps except for stale pre-connect scrolled-off output, where provenance is already best-effort. It is codified in a dedicated boundary test.
Evidence
Measured with an in-repo throwaway bench (
path-candidate-gate.bench.test.ts, deleted before merge): 10,000 representative ~2.3KB build-log chunks (compiler lines,ls-style listings, a path every 7th chunk), median of 3 runs.What this does NOT help: mobile-connected sessions see no per-chunk savings (parity by construction) and additionally pay the sub-ms per-pty backfill spike at first connect. The win is entirely for desktop-only sessions.
Proof of no regressions
npx tsc --noEmit -p config/tsconfig.node.json --composite false→ exit 0, 0 errors.orca-runtime.test.ts+orca-runtime-files.test.ts= 837 passed;recent-pty-output-buffer.test.ts+runtime-rpc.test.ts= 65 passed. 902 passed, 0 failed. New/updated coverage:runtime-rpctest: real E2EE mobile session →onReadybackfill → pathless flood scrolls the raw window →files.resolveTerminalPathstill grants;orca-runtime.test.ts:8390/:8415pass unmodified.npx oxlinton all changed files → exit 0, clean;oxfmtapplied.pnpm run check:max-lines-ratchet→ OK, no new suppressions.hasRecentTerminalOutputPathis unchanged and always active, so any path still inside the retained 64KiB window resolves identically to pre-gate. Tier-2 candidates are backfilled per original chunk boundary at firstonReady(direct WS + relay share the wiring), synchronously before any file RPC from that authenticated socket can dispatch; over-limit chunks stay eagerly extracted; a lazy fallback covers any query that never sawonReady. The full-E2E test proves a real mobile file tap still grants after the raw window scrolls past the path.retainedChunks()/compact()per-chunk backfill, eager over-limit handling, and the full-E2Eruntime-rpctest. Converged to 2 consecutive clean verdicts (rounds 4 and 5) with only non-blocking notes (delete the throwaway bench; keep untrackednode_modulesout of the change).ELI5
The app used to scan every line of every terminal for file paths, all the time, just so your phone could tap a path later — even when no phone was connected. Now it only starts scanning once a phone actually connects, and it catches up on the recent scrollback at that moment so nothing you tap goes missing. If you never use your phone, your computer skips a bunch of pointless work on every burst of terminal output.
Made with Orca 🐋