[PR #400] [CLOSED] fix(glm): preserve turn checkpoints after restoring conversation slots #515

Closed
opened 2026-10-29 21:26:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/400
Author: @Zcg2021
Created: 10/22/2026
Status: ❌ Closed

Base: main ← Head: codex/glm-slot-turn-checkpoint


📝 Commits (2)

  • 8714483 fix(glm): checkpoint restored conversation slots before a new turn
  • 5d93b90 test(glm): document and reproduce slot-restored turn edits

📊 Changes

6 files changed (+1893 additions, -17 deletions)

View changed files

➕ bench/results/2026-10-23-glm-slot-turn/README.md (+152 -0)
➕ bench/results/2026-10-23-glm-slot-turn/engine-excerpts.txt (+20 -0)
➕ bench/results/2026-10-23-glm-slot-turn/results.json (+1496 -0)
📝 src/program/generate.cpp (+19 -17)
➕ tools/repro_glm_slot_turn.py (+126 -0)
➕ tools/test_repro_glm_slot_turn.py (+80 -0)

📄 Description

Problem

With one GLM sequence, switching A → B → A can restore A's conversation slot correctly, but editing the short user turn just submitted after that restore rereads the whole conversation. At 248K tokens this meant approximately four minutes before the first output.

The turn-start checkpoint introduced in #253 was captured before slot_take. Consequently it only covered an already-live snapshot. Slot restoration happened later and invalidated the previous conversation's checkpoints.

Change

Move the existing turn-start checkpoint block after slot restoration and ckpt_drop_past(reuse), before prefill. The restored snapshot can then be retained before prefill replaces it. No condition, model arithmetic, CUDA call, public API, flag default, checkpoint layout or slot serialization changes.

This PR contains only the upstream checkpoint fix, a synthetic HTTP reproduction probe with six CPU tests, and the measurement report. It does not contain the local alesha projection implementation.

Reproduction

Use an isolated idle GLM server, --parallel 1, normal slot/checkpoint defaults, fresh per-arm slot directories, and identical model/settings. Do not run against production.

  1. Submit archive A and keep its answer.
  2. Submit a different archive B, replacing the live model state.
  3. Continue A with a short question; its slot is restored.
  4. Replace that last user message and discard its answer, retaining A's earlier history.

Run the included stdlib probe against the unpatched/patched server respectively:

python tools/repro_glm_slot_turn.py --model YOUR_SERVED_GLM_MODEL \
  --rows 1024 --expect baseline --output before.json
python tools/repro_glm_slot_turn.py --model YOUR_SERVED_GLM_MODEL \
  --rows 1024 --expect fixed --output after.json

--base-url and the optional MAYA_API_KEY environment variable select the isolated endpoint. The probe checks synthetic archive facts, restored prefix reuse and a short edited tail, without imposing a machine-dependent latency threshold. The probe itself has CPU/mocked-HTTP coverage; the GPU results below came from the earlier 23-request harness, not this new four-request script.

Measured result

Same frozen synthetic workload, one serial run per arm, Windows 11 build 26100, Ryzen 9 5900X, 128 GB RAM, RTX 3090 24 GB, CUDA 12.8. Both GPU arms used Maya-M with alesha runtime projection, v1.1.21 (451f9cb) plus that local projection port; candidate additionally applied only this ordering fix. These are not stock-model or current-main GPU measurements.

Metric Before After
Edited turn, first output 248.810 s 4.934 s
Edited turn, whole response 251.781 s 7.486 s
Edited turn, reused tokens 0 248,595
Edited turn, newly read tokens 248,672 77
248K cold prompt, first output 244.630 s 244.731 s
Sum of all 23 request durations, excluding startup 999.449 s 754.935 s
  • Each arm passed 23/23 requests and 81 assertions: archive facts, edited/repeated turns, automatic/required tools, nested Unicode arguments, tool-result edits, cancellation and recovery.
  • All 22 complete outputs matched exactly after excluding random tool-call IDs. The intentionally cancelled stream has a different cutoff; recovery passed in both arms.
  • Both Windows builds completed successfully, 151/151 steps.
  • The affected edit's first-output wait fell 98.02%; this synthetic workload's total duration fell 24.46%. These are single-run measurements, not a general throughput or quality claim.

Full settings, scope, per-request metrics/assertions/output hashes and selected native logs: bench/results/2026-10-23-glm-slot-turn/README.md.

Current-main validation and compatibility

Based on main 25deec5 (after v1.1.24). The complete generate.cpp file was unchanged from the measured v1.1.21 base; the slot-load and checkpoint-copy implementations were also unaffected by intervening changes.

Local Python 3.12 checks:

  • python tools/check_hip_compat.py: passed.
  • python -m unittest tools.test_repro_glm_slot_turn: 6 passed.
  • python -m unittest discover -s serve -p 'test_*.py' -t .: 342 tests, OK, 11 skipped.
  • Full tools suite on macOS: 390 tests, 6 failures / 19 errors / 29 skipped (missing CMake, Linux /proc/meminfo, and macOS /var vs /private/var path assumptions). These are not reported as passing local tests; the equivalent Ubuntu suite passed below.

Ubuntu CI on this PR head 5d93b90: passed in 2m15s. Full run and logs:

  • HIP CUDA-name mapping check: passed.
  • Server suite: 342 tests, OK (11 skipped).
  • Installer/tools suite, including the six new probe tests: 390 tests, OK (28 skipped).

This is the fork's run of the repository's unchanged tests.yml workflow. It does not substitute for upstream maintainer approval or GPU validation.

No current-main CUDA build/GPU rerun, stock-model A/B, HIP runtime, multi-GPU, RAM-slot or long-soak result is claimed. The maintainer GPU gates in CONTRIBUTING.md still apply.

For future rebases, preserve restore selected state → invalidate incompatible checkpoints → retain valid turn-start snapshot → prefill and the existing snapshot-copy synchronization. Existing single-sequence/fast-path/text-only/reuse/checkpoint guards and STRATA_GLM_CKPT_TURN=0 opt-out remain unchanged. Old slot files need no migration. This does not persist all historical checkpoints: earlier edits, changed prefixes, evictions and cold restarts can still reread history.

Related #387 touches the same function for multi-sequence shared-prefix slots; it addresses a different guarded path. Both probes should be rerun if those changes are combined.


🔄 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/mw00/project-maya/pull/400 **Author:** [@Zcg2021](https://github.com/Zcg2021) **Created:** 10/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/glm-slot-turn-checkpoint` --- ### 📝 Commits (2) - [`8714483`](https://github.com/mw00/project-maya/commit/87144830d581fde266164a22dc922593a4bae732) fix(glm): checkpoint restored conversation slots before a new turn - [`5d93b90`](https://github.com/mw00/project-maya/commit/5d93b90d5be1a663f38eb42f155bd5772f425907) test(glm): document and reproduce slot-restored turn edits ### 📊 Changes **6 files changed** (+1893 additions, -17 deletions) <details> <summary>View changed files</summary> ➕ `bench/results/2026-10-23-glm-slot-turn/README.md` (+152 -0) ➕ `bench/results/2026-10-23-glm-slot-turn/engine-excerpts.txt` (+20 -0) ➕ `bench/results/2026-10-23-glm-slot-turn/results.json` (+1496 -0) 📝 `src/program/generate.cpp` (+19 -17) ➕ `tools/repro_glm_slot_turn.py` (+126 -0) ➕ `tools/test_repro_glm_slot_turn.py` (+80 -0) </details> ### 📄 Description ## Problem With one GLM sequence, switching A → B → A can restore A's conversation slot correctly, but **editing the short user turn just submitted after that restore rereads the whole conversation**. At 248K tokens this meant approximately four minutes before the first output. The turn-start checkpoint introduced in #253 was captured before `slot_take`. Consequently it only covered an already-live snapshot. Slot restoration happened later and invalidated the previous conversation's checkpoints. ## Change Move the existing turn-start checkpoint block **after slot restoration and `ckpt_drop_past(reuse)`, before prefill**. The restored snapshot can then be retained before prefill replaces it. No condition, model arithmetic, CUDA call, public API, flag default, checkpoint layout or slot serialization changes. This PR contains only the upstream checkpoint fix, a synthetic HTTP reproduction probe with six CPU tests, and the measurement report. It does **not** contain the local alesha projection implementation. ## Reproduction Use an isolated idle GLM server, `--parallel 1`, normal slot/checkpoint defaults, fresh per-arm slot directories, and identical model/settings. Do not run against production. 1. Submit archive A and keep its answer. 2. Submit a different archive B, replacing the live model state. 3. Continue A with a short question; its slot is restored. 4. Replace that last user message and discard its answer, retaining A's earlier history. Run the included stdlib probe against the unpatched/patched server respectively: ```sh python tools/repro_glm_slot_turn.py --model YOUR_SERVED_GLM_MODEL \ --rows 1024 --expect baseline --output before.json python tools/repro_glm_slot_turn.py --model YOUR_SERVED_GLM_MODEL \ --rows 1024 --expect fixed --output after.json ``` `--base-url` and the optional `MAYA_API_KEY` environment variable select the isolated endpoint. The probe checks synthetic archive facts, restored prefix reuse and a short edited tail, without imposing a machine-dependent latency threshold. The probe itself has CPU/mocked-HTTP coverage; the GPU results below came from the earlier 23-request harness, not this new four-request script. ## Measured result Same frozen synthetic workload, one serial run per arm, Windows 11 build 26100, Ryzen 9 5900X, 128 GB RAM, RTX 3090 24 GB, CUDA 12.8. **Both GPU arms used Maya-M with alesha runtime projection**, v1.1.21 (`451f9cb`) plus that local projection port; candidate additionally applied only this ordering fix. These are not stock-model or current-main GPU measurements. | Metric | Before | After | |---|---:|---:| | Edited turn, first output | 248.810 s | 4.934 s | | Edited turn, whole response | 251.781 s | 7.486 s | | Edited turn, reused tokens | 0 | 248,595 | | Edited turn, newly read tokens | 248,672 | 77 | | 248K cold prompt, first output | 244.630 s | 244.731 s | | Sum of all 23 request durations, excluding startup | 999.449 s | 754.935 s | - Each arm passed **23/23 requests and 81 assertions**: archive facts, edited/repeated turns, automatic/required tools, nested Unicode arguments, tool-result edits, cancellation and recovery. - All **22 complete outputs** matched exactly after excluding random tool-call IDs. The intentionally cancelled stream has a different cutoff; recovery passed in both arms. - Both Windows builds completed successfully, 151/151 steps. - The affected edit's first-output wait fell 98.02%; this synthetic workload's total duration fell 24.46%. These are single-run measurements, not a general throughput or quality claim. Full settings, scope, per-request metrics/assertions/output hashes and selected native logs: [`bench/results/2026-10-23-glm-slot-turn/README.md`](https://github.com/Zcg2021/project-maya/blob/codex/glm-slot-turn-checkpoint/bench/results/2026-10-23-glm-slot-turn/README.md). ## Current-main validation and compatibility Based on `main` **25deec5** (after v1.1.24). The complete `generate.cpp` file was unchanged from the measured v1.1.21 base; the slot-load and checkpoint-copy implementations were also unaffected by intervening changes. Local Python 3.12 checks: - `python tools/check_hip_compat.py`: passed. - `python -m unittest tools.test_repro_glm_slot_turn`: 6 passed. - `python -m unittest discover -s serve -p 'test_*.py' -t .`: 342 tests, OK, 11 skipped. - Full tools suite on macOS: 390 tests, 6 failures / 19 errors / 29 skipped (missing CMake, Linux `/proc/meminfo`, and macOS `/var` vs `/private/var` path assumptions). These are not reported as passing local tests; the equivalent Ubuntu suite passed below. **Ubuntu CI on this PR head `5d93b90`: passed in 2m15s.** [Full run and logs](https://github.com/Zcg2021/project-maya/actions/runs/39872743681): - HIP CUDA-name mapping check: passed. - Server suite: **342 tests, OK (11 skipped)**. - Installer/tools suite, including the six new probe tests: **390 tests, OK (28 skipped)**. This is the fork's run of the repository's unchanged `tests.yml` workflow. It does not substitute for upstream maintainer approval or GPU validation. No current-main CUDA build/GPU rerun, stock-model A/B, HIP runtime, multi-GPU, RAM-slot or long-soak result is claimed. The maintainer GPU gates in CONTRIBUTING.md still apply. For future rebases, preserve **restore selected state → invalidate incompatible checkpoints → retain valid turn-start snapshot → prefill** and the existing snapshot-copy synchronization. Existing single-sequence/fast-path/text-only/reuse/checkpoint guards and `STRATA_GLM_CKPT_TURN=0` opt-out remain unchanged. Old slot files need no migration. This does not persist all historical checkpoints: earlier edits, changed prefixes, evictions and cold restarts can still reread history. Related #387 touches the same function for multi-sequence shared-prefix slots; it addresses a different guarded path. Both probes should be rerun if those changes are combined. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:17 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#515
No description provided.