Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(client): resume completed shells and deduplicate repeated links #21627

Closedjuliusmarmingewants to merge 1 commit intossh-relay-remote-14/interface fromssh-relay-remote-14/shell-transportopened View on GitHub

juliusmarmingecommented

A completed in-memory shell was downloaded again after every socket reconnect. HTTP snapshots also repeated identical pull-request link lists across thread rows.

Resume a completed same-version shell when the server supports completion markers. Keep authoritative HTTP refresh for disk/partial caches, old servers, and server-version changes, and attribute buffered completion items to their source session. Add opt-in HTTP list references, consumed by the actual server handler and shared web/mobile decoder; the default response remains fully expanded. Deferred decoding reuses identical lists and preserves live updates arriving during fill.

Rebuilt from @maria-rcks’s #18979. Current main has a different shell format, so this does not import the older compact-projection prerequisites.

Verification: owning HTTP/shell-sync cases 15→20 in two existing files; 166 relevant cases across eight files pass. Scoped contracts/client-runtime/server types, changed-file lint and formatting pass. Two independent Codex/Claude review rounds; final round found no blockers. Review fixed same-session cursor retention on stream errors and refresh after a server-version change. An interrupted foreground resubscription can still conservatively refresh HTTP.

Actual paired Linux HTTP proof on two synthetic threads sharing a two-link list: default/false response 4,466 UTF-8 bytes; opt-in response 4,058 bytes (408 bytes / 9.1% for this fixture). Both decode to the same links, and the deferred decoder shares the list identity. HTTP output.

Actual browser socket-only reconnect on this revision: session generation 1→2, completed cursor 6 retained, zero HTTP shell fetches, link state retained, and unchanged page time origin. Reconnect output.

No general payload or latency improvement is claimed: an aggregate of the local developer snapshot had 97 active threads, 51 nonempty lists, and zero duplicate lists. Live server upgrades, legacy servers and replay/partial-fill races are covered by focused tests, not a multi-server deployment. Dev builds share version 0.1.0, so development code changes without a version change are not detected by the version gate. macOS, Windows, Electron desktop, iOS, Android and actual relay/tunnel deployments remain unverified. This changes wire/state behavior without a new visual control; API/browser output is the relevant proof.

Implementation and tests: Codex gpt-6.1-sol and gpt-6-astra in T3 Code; adversarial review: Codex gpt-6-sol and Claude claude-opus-5-5.

    1. juliusmarminge added labelsmacroscope-review

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This PR changes default shell synchronization behavior and wire handling across client and server code: completed sessions may skip authoritative HTTP refreshes, while all client snapshot requests opt into compact pull-request references. The state-machine and reconnect implications extend beyond a small isolated optimization and warrant human review.

      No code changes detected at a9d2a80. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—5.0 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.8 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.9 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—5.0 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.8 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—21.2 KiB—29.3 KiB✅
      ClaudeLive turn messages—2—8✅

      Baseline: unavailable · PR result: a9d2a80 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 952c4627-2a53-4c67-8e18-a125f35b102f
      📥 Commits

      Reviewing files that changed from the base of the PR and between 64cb539f4bde4a2ec1f6a3f75071bca6e1ebf057 and eb84f0c118c171f8b86716ac5cd3217fb51e6e12.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 4cad96d7-b363-44f0-a57c-6406eacb5baa
      📥 Commits

      Reviewing files that changed from the base of the PR and between be73f95fa01e32885f28d1c6395fcb8f8f369c9a and 64cb539f4bde4a2ec1f6a3f75071bca6e1ebf057.

      📒 Files selected for processing: 9
      • apps/server/src/orchestration-v2/ShellStream.ts
      • apps/server/src/orchestration-v2/http.test.ts
      • apps/server/src/orchestration-v2/http.ts
      • packages/client-runtime/src/state/shell-sync.test.ts
      • packages/client-runtime/src/state/shell.ts
      • packages/client-runtime/src/state/shellPullRequests.ts
      • packages/client-runtime/src/state/shellSnapshotHttp.ts
      • packages/contracts/src/environmentHttp.ts
      • packages/contracts/src/orchestrationV2.ts

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

      📝 Walkthrough

      The shell snapshot endpoint can emit references to earlier identical pull-request lists when requested, and the client restores those links. Shell synchronization now tracks stream sessions and completion markers to decide whether it can reuse an in-memory snapshot or must reload it.

      Changes: HTTP pull-request link deduplication

      Layer / File(s)Summary
      Define and emit deduplicated snapshots
      packages/contracts/src/environmentHttp.ts, packages/contracts/src/orchestrationV2.ts, apps/server/src/orchestration-v2/ShellStream.ts, apps/server/src/orchestration-v2/http.ts, apps/server/src/orchestration-v2/http.test.ts
      The endpoint accepts the deduplicatePullRequests query parameter. When its value is "true", repeated pull-request lists are replaced with references to the first matching thread. Server tests check default, enabled, and disabled responses.
      Request and restore referenced links
      packages/client-runtime/src/state/shellSnapshotHttp.ts, packages/client-runtime/src/state/shellPullRequests.ts, packages/client-runtime/src/state/shell-sync.test.ts
      The client requests deduplicated snapshots. It resolves valid references to earlier rows, reuses decoded lists, and preserves slots for rows without readable links. Tests cover referenced links and legacy inline links.

      Session-aware shell synchronization

      Layer / File(s)Summary
      Track sessions and determine snapshot reuse
      packages/client-runtime/src/state/shell.ts, packages/client-runtime/src/state/shell-sync.test.ts
      The client applies stream items only from the active session and records synchronization completion with the server version. It reuses an in-memory snapshot only under the specified session and server-version conditions; otherwise it loads an HTTP snapshot. Tests cover retries, errors, foreground resubscription, and session changes.

      Priority: ⬇️ Low

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Feature

      Sequence Diagram(s)

      sequenceDiagram
        participant shellSnapshotHttp
        participant shellSnapshotHandler
        participant loadShellSnapshot
        participant deduplicateShellPullRequests
        participant detachPullRequests
        shellSnapshotHttp->>shellSnapshotHandler: Request with deduplicatePullRequests=true
        shellSnapshotHandler->>loadShellSnapshot: Load snapshot with deduplication enabled
        loadShellSnapshot->>deduplicateShellPullRequests: Deduplicate repeated pull-request lists
        deduplicateShellPullRequests-->>shellSnapshotHandler: Snapshot with pullRequestReference values
        shellSnapshotHandler-->>shellSnapshotHttp: Return snapshot
        shellSnapshotHttp->>detachPullRequests: Restore pull-request links

      Suggested reviewers: t3dotgg, maria-rcks, bil0000

      Merge Risk: ⚪ Minimal · up to 64cb5

      No actionable merge-blocking issue remains; the changed snapshot and reconnect behavior is ready for normal merge checks.

      Pre-merge checks: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Description checkWarningThe description provides detailed problem, implementation, verification, limitations, and review context. However, it does not use the required Problem, Change, Scope and approval, and Verification se…Restructure the description using all required headings. Add a link to the triaged issue or approval discussion with the explicit maintainer approval comment, or explain why this focused change qualifies for an exemption.
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly summarizes both primary changes: completed shell resumption and pull-request link deduplication.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description provides detailed problem, implementation, verification, limitations, and review context. However, it does not use the required Problem, Change, Scope and approval, and Verification sections, and it does not provide explicit maintainer approval or explain why approval was not required.

      Resolution

      Restructure the description using all required headings. Add a link to the triaged issue or approval discussion with the explicit maintainer approval comment, or explain why this focused change qualifies for an exemption.

      ✨ Finishing Touches: 💡 1
      🛠️ Fix failing CI checks: 💡
      • Commit to this branch
      • Create a new PR
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    5. Tested the same idea in a port of #14098 (here: https://github.com/realhasanshoaib/t3code/compare/main...fix/mobile-resume-sync). One case our review found that the version gate can't catch: if a server's history is replaced under the same version (restore from backup, re-created home), a client can resume a cursor that points into different history once the new sequence passes it. We added a per-process epoch to the environment descriptor and only resume when it matches, plus a test where a stale snapshot from an older session arrives late. Glad to send it as a follow-up if you want it.

    6. juliusmarmingecommented

      Thanks @juliusmarminge and @maria-rcks for this work. #32287 (9557ab46c5) now resumes eligible shells and falls back to HTTP when needed. The remaining link-list deduplication has a synthetic saving but no repeated lists in the measured real snapshot. If that optimization still matters, please open a smaller PR focused on it with representative evidence. GitCafe prevented closing this PR because it belongs to an active stack.

    7. Note

      🤖 Claude Fable 5.2 responding on behalf of Theo

      Closing: both gains are covered or measure as zero.

      • Resume the shell after reconnect: on main since #32287.
      • Send repeated link lists once: saves 0 bytes on real data. One real database has 304 link lists across 3,934 active threads, and all 304 are distinct.

      The branch was not run for this comparison; it is from the diff and from measurements on current main.

Sign in to join this conversation.