[PR #4307] [Other] serve+webui: unload that works — pre-staged checkpoints, polite waits, honest answers #4993

Open
opened 2026-11-07 16:31:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4307
Author: @sakuumomo
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: pr/serve-unload-works


📝 Commits (10+)

  • b39ec94 serve: session ladder decision core (event join, save/restore policy, prefix fidelity)
  • 7dad123 serve: ladder event intake (ConvCacheLog.drain_events) + per-session bookkeeping
  • aafce06 serve: ladder hooks the request path (save-on-switch, restore-before-forward, refuse→prefill posture)
  • e28d04d serve+fix: ladder refusal-class registration + bounded last_prompts (Task 7 review round 1)
  • df2f3e9 serve: ladder idle-save, save-all unload, warm-restore engine start
  • 8c7bc96 serve: ladder config from strata.json (park budget read from engine args)
  • e9d4234 serve+fix: ladder refuses to start without a resolvable park budget (Task 9 review round 1)
  • 3100881 serve+fix: ladder join tolerance, identity-unknown switch, dirty-skipped saves, lock-scoped engine I/O (final-review wave)
  • bde316e serve+fix(dormancy): fidelity matches a grown single-message prompt; a zero-reuse DONE unparks a park claim
  • 9adf057 docs: the session ladder in DETAILS.md — the opt-in checkpoint ledger, checkpoint-everything unload, warm restore, and its two block keys

📊 Changes

9 files changed (+2887 additions, -15 deletions)

View changed files

📝 docs/DETAILS.md (+14 -3)
📝 serve/server.py (+295 -3)
➕ serve/session_ladder.py (+761 -0)
📝 serve/test_monitor.py (+15 -0)
📝 serve/test_server.py (+68 -3)
➕ serve/test_session_ladder.py (+632 -0)
➕ serve/test_session_ladder_lifecycle.py (+550 -0)
➕ serve/test_session_ladder_wiring.py (+540 -0)
📝 serve/web/monitor.js (+12 -6)

📄 Description

Problem and result: Before: every Unload click paid for a synchronous save on the click — 36.7 s+ for a 4 GB conversation on the owner's desktop, with the web control appearing frozen; a click while busy answered 409 claiming "a request is running" even when the engine was actually saving; if the engine died on /unload, /v1/unload or POST /load, the server dropped the connection with a traceback. After: a background pass pre-stages checkpoints once the request queue has been quiet for one expected save length, so a quiet click costs teardown only (measured 2.4 s, {"status": "unloaded"}); a click during a save answers 409 in 0.6 ms with a body you can read: a request is running or the model is saving; try again when it is quiet; engine death answers 503 {"error": {"type": "server_error"}} on all three routes; and the last-active session is always parked on unload whatever its size (a 4.3 GB dirty park verified live, then restored as 152,129 tokens in a 3 s prompt read). All existing status fields keep their values, so current clients are unaffected.

Dependencies: stacked on #4306 — this branch is main + the ladder branch's 13 commits (..64925fb4) + 21 new commits (tip b97e6edb): review those twenty-one. If #4306 merges first, this branch re-lands cleanly on main.

Related discussion: extends the same /load / /unload routes the chat-header PR #3550 uses; docs/DETAILS.md is updated in both PRs.

Approach: a daemon pre-save pass consults the ladder's gates before touching the request FIFO, saves with a non-blocking FIFO grab only when one is actually possible, and estimates the quiet window from the engine's own measured save durations scaled by conversation growth (size fallback, clamped 5–600 s); session_ladder.pre_save_idle_s pins or disables the estimate (null = adaptive, number = pinned seconds, 0 = any idle moment). A refused save backs off exponentially (5 s doubled, cap 300 s) instead of hammering a failing engine or disk. Retention order: an over-cap save retires an orphan or subagent (child) checkpoint first, then an aux-sized one, with plain least-recent as the fallback — a finished subagent's checkpoint must not evict the expensive main file. WebUI: the monitor page's Unload posts ?wait=240 (server waits politely for a gap, strictly under the browser's ~300 s fetch timeout) and keeps its label and state-pill consistent while the control request is in flight.

Validation:
Passed: full serve suite green on this branch tip and on the owner's rebuilt deploy branch (1386 passed, 17 skipped on the deploy branch rebuilt onto upstream v0.2.8; see Failed). Live on momo 2026-10-27: quiet unload 200 in 2.4 s with no save behind it; busy click 409 in 0.6 ms with the message quoted above; ?wait=240 click parked 4.3 GB of dirty conversation and unloaded in 53 s; same-session restores 144,590 / 152,129 tokens with 3 s prompt reads; a manual file deletion racing an in-flight save produced a logged refused (io), the cooldown backed off, and the re-save landed clean 5 s later.
Failed: two serve/test_lifeline.py watcher tests fail identically on the unmodified base on this machine (environment-sensitive, pre-existing).
Not run: the post-engine-death backoff loop was not provoked live on the fleet box (pinned in the suite instead); moko renders no session_ladder block (build-gate verified only).
Limits: the adaptive gate deliberately never opens while requests chain (a busy agent loop is never disturbed — confirmed operationally); pre-stage writes cost up to the conversation size on disk under the 16-file retention cap.

Changes since the last update (2026-11-07)

  • Rebased onto upstream v0.2.12 (123bad4a, engine 0.1.58); branch tip b97e6edb (still those 21 commits on top of the ladder branch). The same one request-path fusion as #4306: the token-seen accounting rides upstream's seen = 0 if admission_rejected else prompt_tokens_seen(...) shape.
  • Gate refresh: full serve suite 1640 OK / 37 skipped on the deploy lineage carrying this branch; the pre-save pass, the 409 fast refusal, the 503 engine-death answers and the ?wait=240 WebUI contract are all pinned in that suite unchanged. Owner flavor builds (HIP gfx1030, CUDA+HIP hybrid gfx1150) green with installCheck on the redeployed train nixos @ c3e4cdc4. The runtime-requirements and title jobs are green on the new head; the PR is mergeable against current main.

Commits were re-signed (GPG ed25519) on 2026-11-07 after rebasing onto upstream v0.2.12 (123bad4a); trees are unchanged from the originally validated work; branch tip b97e6edb; the pre-rebase tip b764970e stays fetchable as an ancestor of the train tag pin-f6f00908.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4307 **Author:** [@sakuumomo](https://github.com/sakuumomo) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/serve-unload-works` --- ### 📝 Commits (10+) - [`b39ec94`](https://github.com/Niko1221/Strata/commit/b39ec94895773f36d2235d8797a354e372251272) serve: session ladder decision core (event join, save/restore policy, prefix fidelity) - [`7dad123`](https://github.com/Niko1221/Strata/commit/7dad1237bf68082b82f87f9fdf12aa6a1a10e456) serve: ladder event intake (ConvCacheLog.drain_events) + per-session bookkeeping - [`aafce06`](https://github.com/Niko1221/Strata/commit/aafce06f4e184c39959eccf7522bc186b2d1f583) serve: ladder hooks the request path (save-on-switch, restore-before-forward, refuse→prefill posture) - [`e28d04d`](https://github.com/Niko1221/Strata/commit/e28d04d0c38466ce5f506fbe9b4341ac33165286) serve+fix: ladder refusal-class registration + bounded last_prompts (Task 7 review round 1) - [`df2f3e9`](https://github.com/Niko1221/Strata/commit/df2f3e9a63aca06a75e663b2edde99e751f6531c) serve: ladder idle-save, save-all unload, warm-restore engine start - [`8c7bc96`](https://github.com/Niko1221/Strata/commit/8c7bc964ea1a1f69591422d270ec8bc05aa88302) serve: ladder config from strata.json (park budget read from engine args) - [`e9d4234`](https://github.com/Niko1221/Strata/commit/e9d4234b3d3b38f1403b705a23e88782c8db0b4c) serve+fix: ladder refuses to start without a resolvable park budget (Task 9 review round 1) - [`3100881`](https://github.com/Niko1221/Strata/commit/3100881f39fcb4b62e58c70d2e46dffa1576c36c) serve+fix: ladder join tolerance, identity-unknown switch, dirty-skipped saves, lock-scoped engine I/O (final-review wave) - [`bde316e`](https://github.com/Niko1221/Strata/commit/bde316ef330ee3e98a357c9547a9a63d58b6a668) serve+fix(dormancy): fidelity matches a grown single-message prompt; a zero-reuse DONE unparks a park claim - [`9adf057`](https://github.com/Niko1221/Strata/commit/9adf05708942ec37ce5c037c16f3a9b949eecfc5) docs: the session ladder in DETAILS.md — the opt-in checkpoint ledger, checkpoint-everything unload, warm restore, and its two block keys ### 📊 Changes **9 files changed** (+2887 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+14 -3) 📝 `serve/server.py` (+295 -3) ➕ `serve/session_ladder.py` (+761 -0) 📝 `serve/test_monitor.py` (+15 -0) 📝 `serve/test_server.py` (+68 -3) ➕ `serve/test_session_ladder.py` (+632 -0) ➕ `serve/test_session_ladder_lifecycle.py` (+550 -0) ➕ `serve/test_session_ladder_wiring.py` (+540 -0) 📝 `serve/web/monitor.js` (+12 -6) </details> ### 📄 Description Problem and result: Before: every Unload click paid for a synchronous save on the click — 36.7 s+ for a 4 GB conversation on the owner's desktop, with the web control appearing frozen; a click while busy answered 409 claiming "a request is running" even when the engine was actually saving; if the engine died on `/unload`, `/v1/unload` or `POST /load`, the server dropped the connection with a traceback. After: a background pass pre-stages checkpoints once the request queue has been quiet for one expected save length, so a quiet click costs teardown only (measured 2.4 s, `{"status": "unloaded"}`); a click during a save answers 409 in 0.6 ms with a body you can read: `a request is running or the model is saving; try again when it is quiet`; engine death answers 503 `{"error": {"type": "server_error"}}` on all three routes; and the last-active session is always parked on unload whatever its size (a 4.3 GB dirty park verified live, then restored as 152,129 tokens in a 3 s prompt read). All existing `status` fields keep their values, so current clients are unaffected. Dependencies: stacked on #4306 — this branch is `main` + the ladder branch's 13 commits (`..64925fb4`) + 21 new commits (tip `b97e6edb`): review those twenty-one. If #4306 merges first, this branch re-lands cleanly on `main`. Related discussion: extends the same `/load` / `/unload` routes the chat-header PR #3550 uses; `docs/DETAILS.md` is updated in both PRs. Approach: a daemon pre-save pass consults the ladder's gates before touching the request FIFO, saves with a non-blocking FIFO grab only when one is actually possible, and estimates the quiet window from the engine's own measured save durations scaled by conversation growth (size fallback, clamped 5–600 s); `session_ladder.pre_save_idle_s` pins or disables the estimate (`null` = adaptive, number = pinned seconds, 0 = any idle moment). A refused save backs off exponentially (5 s doubled, cap 300 s) instead of hammering a failing engine or disk. Retention order: an over-cap save retires an orphan or subagent (child) checkpoint first, then an aux-sized one, with plain least-recent as the fallback — a finished subagent's checkpoint must not evict the expensive main file. WebUI: the monitor page's Unload posts `?wait=240` (server waits politely for a gap, strictly under the browser's ~300 s fetch timeout) and keeps its label and state-pill consistent while the control request is in flight. Validation: Passed: full serve suite green on this branch tip and on the owner's rebuilt deploy branch (1386 passed, 17 skipped on the deploy branch rebuilt onto upstream `v0.2.8`; see Failed). Live on momo 2026-10-27: quiet unload 200 in 2.4 s with no save behind it; busy click 409 in 0.6 ms with the message quoted above; `?wait=240` click parked 4.3 GB of dirty conversation and unloaded in 53 s; same-session restores 144,590 / 152,129 tokens with 3 s prompt reads; a manual file deletion racing an in-flight save produced a logged `refused (io)`, the cooldown backed off, and the re-save landed clean 5 s later. Failed: two `serve/test_lifeline.py` watcher tests fail identically on the unmodified base on this machine (environment-sensitive, pre-existing). Not run: the post-engine-death backoff loop was not provoked live on the fleet box (pinned in the suite instead); moko renders no `session_ladder` block (build-gate verified only). Limits: the adaptive gate deliberately never opens while requests chain (a busy agent loop is never disturbed — confirmed operationally); pre-stage writes cost up to the conversation size on disk under the 16-file retention cap. ## Changes since the last update (2026-11-07) - Rebased onto upstream `v0.2.12` (`123bad4a`, engine 0.1.58); branch tip `b97e6edb` (still those 21 commits on top of the ladder branch). The same one request-path fusion as #4306: the token-seen accounting rides upstream's `seen = 0 if admission_rejected else prompt_tokens_seen(...)` shape. - Gate refresh: full serve suite 1640 OK / 37 skipped on the deploy lineage carrying this branch; the pre-save pass, the 409 fast refusal, the 503 engine-death answers and the `?wait=240` WebUI contract are all pinned in that suite unchanged. Owner flavor builds (HIP gfx1030, CUDA+HIP hybrid gfx1150) green with installCheck on the redeployed train `nixos` @ `c3e4cdc4`. The runtime-requirements and title jobs are green on the new head; the PR is mergeable against current `main`. Commits were re-signed (GPG ed25519) on 2026-11-07 after rebasing onto upstream `v0.2.12` (`123bad4a`); trees are unchanged from the originally validated work; branch tip `b97e6edb`; the pre-rebase tip `b764970e` stays fetchable as an ancestor of the train tag `pin-f6f00908`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4993
No description provided.