mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4306] [Other] serve: session ladder — conversations survive an engine unload #4994
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4994
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4306
Author: @sakuumomo
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:pr/serve-session-ladder📝 Commits (10+)
ca1cfe5serve: session ladder decision core (event join, save/restore policy, prefix fidelity)ea653e2serve: ladder event intake (ConvCacheLog.drain_events) + per-session bookkeepingca6c7d8serve: ladder hooks the request path (save-on-switch, restore-before-forward, refuse→prefill posture)c628e49serve+fix: ladder refusal-class registration + bounded last_prompts (Task 7 review round 1)98ff2faserve: ladder idle-save, save-all unload, warm-restore engine start2abd947serve: ladder config from strata.json (park budget read from engine args)2a05e43serve+fix: ladder refuses to start without a resolvable park budget (Task 9 review round 1)9023e8dserve+fix: ladder join tolerance, identity-unknown switch, dirty-skipped saves, lock-scoped engine I/O (final-review wave)8bf8b19serve+fix(dormancy): fidelity matches a grown single-message prompt; a zero-reuse DONE unparks a park claim59c8e74docs: the session ladder in DETAILS.md — the opt-in checkpoint ledger, checkpoint-everything unload, warm restore, and its two block keys📊 Changes
6 files changed (+2901 additions, -1 deletions)
View changed files
📝
docs/DETAILS.md(+15 -0)📝
serve/server.py(+214 -1)➕
serve/session_ladder.py(+888 -0)➕
serve/test_session_ladder.py(+798 -0)➕
serve/test_session_ladder_lifecycle.py(+512 -0)➕
serve/test_session_ladder_wiring.py(+474 -0)📄 Description
Problem and result: Before: a conversation held in the engine died when the engine unloaded (manual click, idle unload, or crash) or when another client took the active slot — the next request re-prefilled from cold, about 2 minutes for a 145k-token agent conversation on a desktop. After: an opt-in session ladder checkpoints conversations to disk (switch-away saves at turn end, save-all before every unload, idle saves), hands the checkpoint back to the engine before the next request (warm restore), and the same prompt reads from the restored prefix in ~3 s at full reuse. Absent the
session_ladderconfig block, every code path stays exactly as before. A follow-up on this branch closes a subagent hole found on a live host: OpenCode stamps every child (subagent) request with its own id inx-opencode-session-id, while the affinity family (X-Session-Id,x-session-affinity,x-opencode-session) carries the PARENT session id — the client assembles it asparentID ?? fork source ?? own idfor provider-side cache affinity. With affinity-first extraction every subagent collapsed into the main session: never tracked, never saved to disk, its turn figures misattributed to the parent (the engine log named only main session ids across days of subagent use). The requesting session's own id now outranks the family, and a subagent earns its own checkpoint file and its own ledger entry.Dependencies: none — this branch is
main+ 13 commits and lands on its own. PR #4307 stacks on top of this branch.Related discussion: follow-up PR #4307 ("unload that works") makes the unload controls ride on these checkpoints.
Approach: a ladder of ledger + policy + plumbing around the engine's own session-file SAVE/RESTORE. Save-on-switch keeps a multi-client host (agent + webui + API clients) from losing context to slot churn.
POST /unloadcheckpoints every dirty conversation before the engine closes. Warm restore re-attaches the checkpoint during the engine start, before the next request's first token. Refused saves/restores (park budget, disk) degrade to a normal cold prefill with one log line and never fail a request. A child session's parent (recorded fromx-opencode-parent-session-id/x-parent-session-id) is kept only as a retention mark, never as identity. Subagent checkpoints are retained on their own terms: an over-cap save retires an orphan or child file before an older main file (a child re-prefills a subagent conversation, a main re-prefills its whole multi-GB context);retention_max_child_filescaps child files so a fleet never occupies the whole ledger; a clean child checkpoint no request has touched forchild_ttl_sis retired on the idle beat — a finished subagent never returns to the engine, and silence is the only completion signal the wire carries. A main file is never swept, a dirty child is never swept (its save is still owed), and the current session never loses its safety-net file. Config:session_ladderblock (idle_save_s8.0,retention_max_files16,retention_max_child_files8,child_ttl_s21600, 0 = the sweep off); the park budget is read from the engine's own--conversation-cache-mib, and an enabled ladder without a resolvable budget refuses to start rather than coerce it. Includes the dormancy fixes: fidelity matches a grown single message, and a zero-reuse DONE unparks a stale park claim (the live incident this branch self-heals from).docs/DETAILS.mdcarries the user-facing paragraph.Validation:
Passed: the full serve suite is green on trees containing these commits — the owner's deploy branch
nixosrebuilt on upstreamv0.2.8(1386 passed, 17 skipped; see Failed). The subagent rules add nine pins: parent-header extraction, child-before-older-main retirement, the separate child cap, the TTL sweep with its guards (main never swept, dirty child never swept, current session never swept, 0 disables), a child's mark surviving a restart through the ledger sidecar, and a live-HTTP child request landing as its own session with its parent recorded. Measured live on momo (RX 6900 XT, 262144 ctx, 2026-10-25..27): warm restores brought back 144,590 / 152,129 tokens with the 145k–152k prompt read completing in 3 s (cold prefill is ~2 min at ~1200 tok/s on this box); a field incident of a parked session silently going cold was reproduced deterministically, fixed, and re-verified on the deployed tree.Failed: two
serve/test_lifeline.pywatcher tests (the engine-subprocess watchdog) error intermittently under heavy concurrent load on this machine and pass in isolation on the unmodified base — environment-sensitive, pre-existing, unrelated to this PR.Not run: serve-side only, so no engine builds are touched; hybrid hosts in the owner's fleet run with the ladder deliberately off (config rendering verified, no multi-device park measurement).
Limits: opt-in only; park files grow with the conversation (~1.2 GB per 63k tokens, stated in the startup log line) under a 16-file retention cap with an 8-file child sub-cap; restore only accepts files written by the same server.
Changes since the last update (2026-11-07)
v0.2.12(123bad4a, engine 0.1.58); branch tip64925fb4(still 13 commits). One request-path conflict, resolved as a fusion: the ladder's token-accounting hook now sits inside upstream's (#471/#3040)seen = 0 if admission_rejected else prompt_tokens_seen(...)shape, so a rejected admission still counts nothing.test_session_ladder,test_session_ladder_lifecycle,test_session_ladder_wiring) is 123 tests OK, all subagent pins intact. The owner's flavor builds (HIP gfx1030, CUDA+HIP hybrid gfx1150) are green with installCheck on the redeployed trainnixos@c3e4cdc4. The runtime-requirements and title jobs are green on the new head; the PR is mergeable against currentmain.Commits were re-signed (GPG ed25519) on 2026-11-07 after rebasing onto upstream
v0.2.12(123bad4a); branch tip64925fb4; the pre-rebase tip0849fb78stays fetchable as an ancestor of the train tagpin-f6f00908.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.