Skip to content

perf(desktop): make session resume incremental (salvage of #62799) - #87522

Merged
teknium1 merged 5 commits into
mainfrom
salvage/incremental-resume-62799
Aug 16, 2026
Merged

perf(desktop): make session resume incremental (salvage of #62799)#87522
teknium1 merged 5 commits into
mainfrom
salvage/incremental-resume-62799

Conversation

@teknium1

@teknium1 teknium1 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Salvage of #62799 by @embwl0x — Desktop cold resume now returns its session.resume acknowledgement in <1ms by deferring the transcript read off the RPC path (measured 19x faster RPC-critical section on a real 1175-message production session).

Infographic

Incremental session resume

What this is

Rebase/salvage of #62799 (perf(desktop): make session resume incremental) by @embwl0x onto current main, with authorship preserved via cherry-pick. The original branch predates the methods_session.py split-out and several resume-path changes on main; the cherry-picks landed cleanly on top of them and the integration was re-verified against main's current resume machinery (profile-scoped DB ownership, assert_resume_safe, resolve_resume_session_id, deferred agent build, lazy watch resumes, omit_messages).

Carried vs dropped

Carried (main lacks all of this):

  • defer_history: true opt-in on session.resume: gateway registers the runtime and returns the descriptor immediately (hydrating: true, empty messages), then loads replay/display history on a background worker (_schedule_resume_hydration in tui_gateway/server.py).
  • session.resume_progress events (loading / complete / failed).
  • _start_agent_build gates on history readiness (resume_history_ready) and rechecks runtime ownership before building; _finalize_session cancels a waiting build on close.
  • Hydration failure releases the provisional claim (session record removed, lease released) so a retry gets a fresh runtime — the durable session is preserved.
  • Profile-scoped resume hands its DEDICATED db handle to the hydration worker, which closes it after the read on both success and failure paths (pinned by the new tests/tui_gateway/test_session_resume_db_ownership.py test).
  • Desktop opts into defer_history on cold resumes (use-session-actions), keeps REST as the transcript authority, and paints the bounded latest page as it arrives; hydrating? added to SessionResumeResponse.
  • 4 new gateway tests (ack/reuse, failure+retry, close-cancels-build, deferred profile-DB close) + desktop test updates.

Dropped as redundant (already on main):

  • Deferring the AGENT build off the resume RPC — main's cold-resume default already does this (_schedule_agent_build).
  • The PR's original conflict-era restructuring of the resume handler — main's methods_session.py layout is kept; the deferred branch slots in between the lazy/watch branch and the cold-resume default.

Follow-up (own commit, not folded into contributor's):

  • docs(tui): explicit precedence comment — defer_history SUPERSEDES omit_messages; the single history read happens in the background worker, the synchronous omit_messages read is skipped, so the transcript is never loaded twice for one resume.

Validation

E2E against a real 297MB production state.db copy (session 20260812_162043_803c70, 1175 messages), SessionDB imported from this branch:

Metric Before (synchronous) After (defer_history)
Resume RPC-critical section 10.9–32.9 ms (min 10.9) 0.58 ms (~19x)
Background hydration (full 1175-row read) n/a (on RPC path) 13.0 ms, completes + reports
Historical desktop-audit baseline ~131 ms @ 1175 rows (cold cache) off the RPC path entirely

Tests (targeted, this branch):

  • tests/test_tui_gateway_server.py + tests/tui_gateway/test_session_resume_db_ownership.py + tests/tui_gateway/test_protocol.py: 640 passed, 0 failed
  • Full tests/test_tui_gateway_server.py tests/tui_gateway/ sweep: 1049 passed, 2 skipped, 2 failed — both failures (test_cold_start_gil_stall, test_iso_certify_seam) reproduce identically on bare origin/main with the same interpreter: pre-existing minimal-venv env gaps, not introduced here (verified by running the same test ids on detached origin/main).
  • Desktop: vitest run use-session-actions.test.tsx54 passed (includes the new bounded deferred-resume test); npm run check:lint — 0 errors (108 pre-existing warnings).

Notes

embwl0x and others added 5 commits August 16, 2026 00:43
Follow-up to the #62799 salvage: Desktop sends both defer_history and
omit_messages on a cold resume. Make explicit in the deferred branch that
defer_history supersedes omit_messages — the single history read happens in
the background hydration worker and the synchronous omit_messages read on
the cold-resume default path is skipped entirely, so the transcript is
never loaded twice for one resume.
@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on cfcaee1 — docs(tui): document defer_history vs omit_messages precedenc

⚠️ Warnings

CI timings · View report · View job

Wall time 11m24s vs 3m20s (+242.0%). 19 job(s) slower, 17 faster, 1 unchanged.

  • JS & TS checks / apps/desktop / check:test:desktop:all: +602.0s
  • JS & TS checks / apps/desktop / check:test:ui:shard-1of3: -42.0s
  • JS & TS checks / apps/desktop / check:test:ui:shard-2of3: +36.0s
  • Python tests / Run tests slice 2/12: -30.0s
  • Python tests / Run tests slice 3/12: +29.0s

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.

@teknium1
teknium1 merged commit 69f7c65 into main Aug 16, 2026
57 checks passed
@teknium1
teknium1 deleted the salvage/incremental-resume-62799 branch August 16, 2026 08:28
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.

[Performance]: Make session.resume incremental or asynchronous to fit the Desktop RPC budget

2 participants