[PR #4614] [GUI] Time Skip trials drop their poll, entry, chat pointer, model choice and ended promise #5111

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4614
Author: @codingkoala
Created: 10/29/2026
Status: 🔄 Open

Base: main ← Head: gui-timeskip-trial-cleanup


📝 Commits (1)

  • 891d70a apps/host: a Time-skip trial drops its poll, entry, chat pointer, model choice and ended promise

📊 Changes

2 files changed (+30 additions, -5 deletions)

View changed files

📝 apps/host/server/index.mjs (+26 -4)
📝 apps/host/server/timeskip.mjs (+4 -1)

📄 Description

Problem and result

Four things are keyed on a Time-skip trial's run id and none of them is released (#4611):

  • endedOf (apps/host/server/timeskip.mjs:297) held the run's end promise for the host's whole life: ended.then cleaned live only. Measured on 46c152a — after a run completes, live: 0, endedOf: 1. With this change: live: 0, endedOf: 0. whenEnded behaves as before: stop() takes the promise (endedOf.get(id) ?? Promise.resolve(), timeskip.mjs:410) before the settle handler runs, and a settled promise is what that fallback returns anyway.
  • timeskipChoices (apps/host/server/index.mjs:782) had no delete and no clear anywhere in the tree (a grep over apps/host finds only the declaration, the set on start, and one get at the revision route): one entry per trial ever started, never read again. Now the newest 60 are kept, the same bound the request board and the Time-skip listing use (serving.mjs MAX_REQUESTS, monitor.mjs HISTORY, timeskip.mjs MAX_LISTED). A Map iterates in insertion order, so the oldest goes first.
  • watchTrial's if (!run) branch (index.mjs:803) cleared only its timer, so trials, trialByChat and the model choice stayed until the host restarted when the run's record disappeared (folder removed, or run.json unparseable). The user-visible part: /api/chat/stop (index.mjs:1974) resolved that chat to the dead run id, timeskip.stop() answered false for an id that is not a run, and agent.stop(sessionId) was never reached — the chat's Stop button reported ended: 'time-skip' and did not stop the assistant's turn. After the change the pointer is gone and Stop falls through to agent.stop.
  • A trial whose record is gone can never post a revision request, so dropping its model choice on that branch is safe; the revision route already falls back to the loaded local instance, and otherwise answers 503 Load a model first.

#4611 (opened as the scope thread for the 60 bound). Focused fix, two files, +30/−5. I also read #4529 and PR #4570 (killTree on Linux/macOS) and PR #4442 (stop() raises when the folder is not gone): different problems, no overlap with these lines.

Approach

One dropTrial(id, timer) covers every way out of a trial — the vanished record, the terminal phase, and Stop — so the four maps cannot drift apart again, which is how this happened in the first place. stopTrial keeps its controller.abort() and chatStore.removeById() before it. Nothing else changes: the terminal-phase cleanup is the same set it already dropped, plus the model choice that nothing reads after a run finishes.

Validation

Measured on commit 46c152a, Ubuntu 26.04.1 LTS (kernel 7.0.0-38, x86_64), RTX 4070 SUPER, 62 GB RAM, Node v22.22.1, Python 3.14.4. The card is irrelevant: App Host JavaScript only. Every line number in this body is on the base 46c152a.

Passed:

  • node --check apps/host/server/index.mjs, node --check apps/host/server/timeskip.mjs — no syntax error.
  • node --test apps/host/tests/tune-and-timeskip-routes.test.mjs → 7 pass, 0 fail (the Time-skip run-list and apply routes, and test 7 "an HTTP caller cannot supply an arbitrary revision command"). No test in the repository calls /api/internal/timeskip-revise — that route's behaviour below is read from the code, not exercised.
  • node --test apps/host/tests/timeskip-real.test.mjs tests/timeskip-fork.test.mjs tests/timeskip-compare-server.test.mjs → 13 pass, 1 fail, 4 skipped; the one failure is pre-existing and listed under Failed.
  • node --test apps/host/tests/host-lifecycle.test.mjs → 4 pass, 0 fail (run against the final state of the change); that suite boots server/index.mjs itself, so the edited file loads, answers /api/health and shuts down with its parent — no runtime error at load or at exit. It does not reach any Time-skip route.
  • The endedOf probe from #4611, run the same way against 46c152a (endedOf: 1 after completion) and against this change (endedOf: 0), with list(), whenEnded() and stop() unchanged on both sides.
  • A 12-trial soak through the real host (method and table in #4611): after watchTrial had polled twice, 46c152a held endedOf and timeskipChoices at 1, 2, … 12 — one entry per trial, never released — while this change held both at 0 after every run, with trials, trialByChat and live at 0 and host RSS 92 → 86 MB on both (the leftovers are too small to see in RSS; the maps are the instrument). The harness lives outside the repository: it inserts a debug route for the duration of a run, removes it in finally, and the tree was byte-identical to its source commit after each variant.
  • The bound, replayed as the same two statements with a 1000-run loop and a 100000-run loop: steady at 60 entries, the newest 60 kept, the entry of the current run still present.

Failed:

  • apps/host/tests/timeskip-real.test.mjs test 6 ("Stop ends the job and everything it started…") — the grandchild assertion, which is #4529 (PR #4570 fixes it). Pre-existing: the unmodified 46c152a tree fails the same assertion, measured in the same session on the same three files. In that failing run the two preceding assertions still pass (the copies are deleted, phase === 'cancelled'), so Stop's bookkeeping and the file removal are not what breaks.
  • apps/host/tests/qa1-storage.test.mjs "item 8" (the app-version line) — fails on the base revision too, unrelated to these files.
  • Like-for-like on the same three Time-skip files, same machine, same session (timeskip-real, timeskip-fork, timeskip-compare-server): base 46c152a → 12 pass / 2 fail / 4 skipped (tests 4 and 6 of timeskip-real); this change → 13 pass / 1 fail / 4 skipped (test 6 only). Base test 4 ("a run starts without the caller waiting … applies the chosen revision") failed there and passes with the change: it is flaky on this box in my runs, not something I can attribute to this diff, and I am reporting it rather than dropping it.

Not run:

  • npm test in full and tsc --noEmit: apps/host has no node_modules here, so it needs npm ci. I ran the suites that matter for these files directly with node --test.
  • The project's Node: apps/host/package.json says engines.node >= 24.12.0, and this box has v22.22.1. Nothing in this change depends on the version; the #4529 failure may be environment-dependent (that report reproduces it on Node 26.12.1), so I am not attributing it to Node.
  • Nothing was measured on Windows or macOS, and no desktop-app installer was run — the change is in the host module, not the engine.

Limits

  • The stale-pointer consequence is a path I read, not one I made happen: it needs the run's record to disappear outside stopTrial (something removing the Time-skip state folder, or a run.json touched by something else — timeskip.mjs:30-42 already says a parse failure means something else touched the file).
  • No regression check added: trials, trialByChat and timeskipChoices are private to the module's closure, so an assertion would need a test-only accessor. The closest observable is whenEnded, which PR #4570 already asserts after Stop. Say the word and I will add the accessor, or move the drop into timeskip.mjs where the existing test can see it.
  • If #4442 lands first, a Stop that cannot delete the folder raises before dropTrial(), so that trial stays watched (its record still exists, so status() is not null). Today's line it replaces behaves the same, and I would rather keep the chat's Stop retryable than silently drop it — this is a note, not a change.
  • The stopped set (timeskip.mjs:298) is deliberately kept until the host restarts, so its entries are left alone.

🔄 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/4614 **Author:** [@codingkoala](https://github.com/codingkoala) **Created:** 10/29/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `gui-timeskip-trial-cleanup` --- ### 📝 Commits (1) - [`891d70a`](https://github.com/Niko1221/Strata/commit/891d70a53ab1addd1a7cec7cd90e6570261efbca) apps/host: a Time-skip trial drops its poll, entry, chat pointer, model choice and ended promise ### 📊 Changes **2 files changed** (+30 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/server/index.mjs` (+26 -4) 📝 `apps/host/server/timeskip.mjs` (+4 -1) </details> ### 📄 Description ## Problem and result Four things are keyed on a Time-skip trial's run id and none of them is released (#4611): - `endedOf` (`apps/host/server/timeskip.mjs:297`) held the run's end promise for the host's whole life: `ended.then` cleaned `live` only. Measured on `46c152a` — after a run completes, `live: 0`, `endedOf: 1`. With this change: `live: 0`, `endedOf: 0`. `whenEnded` behaves as before: `stop()` takes the promise (`endedOf.get(id) ?? Promise.resolve()`, `timeskip.mjs:410`) *before* the settle handler runs, and a settled promise is what that fallback returns anyway. - `timeskipChoices` (`apps/host/server/index.mjs:782`) had **no `delete` and no `clear` anywhere in the tree** (a `grep` over `apps/host` finds only the declaration, the `set` on start, and one `get` at the revision route): one entry per trial ever started, never read again. Now the newest 60 are kept, the same bound the request board and the Time-skip listing use (`serving.mjs MAX_REQUESTS`, `monitor.mjs HISTORY`, `timeskip.mjs MAX_LISTED`). A `Map` iterates in insertion order, so the oldest goes first. - `watchTrial`'s `if (!run)` branch (`index.mjs:803`) cleared only its timer, so `trials`, `trialByChat` and the model choice stayed until the host restarted when the run's record disappeared (folder removed, or `run.json` unparseable). The user-visible part: `/api/chat/stop` (`index.mjs:1974`) resolved that chat to the dead run id, `timeskip.stop()` answered `false` for an id that is not a run, and `agent.stop(sessionId)` was never reached — the chat's Stop button reported `ended: 'time-skip'` and did not stop the assistant's turn. After the change the pointer is gone and Stop falls through to `agent.stop`. - A trial whose record is gone can never post a revision request, so dropping its model choice on that branch is safe; the revision route already falls back to the loaded local instance, and otherwise answers `503 Load a model first`. ## Related discussion #4611 (opened as the scope thread for the 60 bound). Focused fix, two files, +30/−5. I also read #4529 and PR #4570 (`killTree` on Linux/macOS) and PR #4442 (`stop()` raises when the folder is not gone): different problems, no overlap with these lines. ## Approach One `dropTrial(id, timer)` covers every way out of a trial — the vanished record, the terminal phase, and Stop — so the four maps cannot drift apart again, which is how this happened in the first place. `stopTrial` keeps its `controller.abort()` and `chatStore.removeById()` before it. Nothing else changes: the terminal-phase cleanup is the same set it already dropped, plus the model choice that nothing reads after a run finishes. ## Validation Measured on commit `46c152a`, Ubuntu 26.04.1 LTS (kernel 7.0.0-38, x86_64), RTX 4070 SUPER, 62 GB RAM, Node v22.22.1, Python 3.14.4. The card is irrelevant: App Host JavaScript only. Every line number in this body is on the base `46c152a`. **Passed:** - `node --check apps/host/server/index.mjs`, `node --check apps/host/server/timeskip.mjs` — no syntax error. - `node --test apps/host/tests/tune-and-timeskip-routes.test.mjs` → **7 pass, 0 fail** (the Time-skip run-list and apply routes, and test 7 "an HTTP caller cannot supply an arbitrary revision command"). No test in the repository calls `/api/internal/timeskip-revise` — that route's behaviour below is read from the code, not exercised. - `node --test apps/host/tests/timeskip-real.test.mjs tests/timeskip-fork.test.mjs tests/timeskip-compare-server.test.mjs` → **13 pass, 1 fail, 4 skipped**; the one failure is pre-existing and listed under Failed. - `node --test apps/host/tests/host-lifecycle.test.mjs` → **4 pass, 0 fail** (run against the final state of the change); that suite boots `server/index.mjs` itself, so the edited file loads, answers `/api/health` and shuts down with its parent — no runtime error at load or at exit. It does not reach any Time-skip route. - The `endedOf` probe from #4611, run the same way against `46c152a` (`endedOf: 1` after completion) and against this change (`endedOf: 0`), with `list()`, `whenEnded()` and `stop()` unchanged on both sides. - A 12-trial soak through the real host (method and table in #4611): after `watchTrial` had polled twice, `46c152a` held `endedOf` and `timeskipChoices` at 1, 2, … 12 — one entry per trial, never released — while this change held both at 0 after every run, with `trials`, `trialByChat` and `live` at 0 and host RSS 92 → 86 MB on **both** (the leftovers are too small to see in RSS; the maps are the instrument). The harness lives outside the repository: it inserts a debug route for the duration of a run, removes it in `finally`, and the tree was byte-identical to its source commit after each variant. - The bound, replayed as the same two statements with a 1000-run loop and a 100000-run loop: steady at 60 entries, the newest 60 kept, the entry of the current run still present. **Failed:** - `apps/host/tests/timeskip-real.test.mjs` test 6 ("Stop ends the job and everything it started…") — the grandchild assertion, which is #4529 (PR #4570 fixes it). Pre-existing: the unmodified `46c152a` tree fails the same assertion, measured in the same session on the same three files. In that failing run the two preceding assertions still pass (`the copies are deleted`, `phase === 'cancelled'`), so Stop's bookkeeping and the file removal are not what breaks. - `apps/host/tests/qa1-storage.test.mjs` "item 8" (the app-version line) — fails on the base revision too, unrelated to these files. - Like-for-like on the same three Time-skip files, same machine, same session (`timeskip-real`, `timeskip-fork`, `timeskip-compare-server`): base `46c152a` → **12 pass / 2 fail / 4 skipped** (tests 4 and 6 of `timeskip-real`); this change → **13 pass / 1 fail / 4 skipped** (test 6 only). Base test 4 ("a run starts without the caller waiting … applies the chosen revision") failed there and passes with the change: it is flaky on this box in my runs, not something I can attribute to this diff, and I am reporting it rather than dropping it. **Not run:** - `npm test` in full and `tsc --noEmit`: `apps/host` has no `node_modules` here, so it needs `npm ci`. I ran the suites that matter for these files directly with `node --test`. - The project's Node: `apps/host/package.json` says `engines.node >= 24.12.0`, and this box has v22.22.1. Nothing in this change depends on the version; the #4529 failure may be environment-dependent (that report reproduces it on Node 26.12.1), so I am not attributing it to Node. - Nothing was measured on Windows or macOS, and no desktop-app installer was run — the change is in the host module, not the engine. ## Limits - The stale-pointer consequence is a path I read, not one I made happen: it needs the run's record to disappear outside `stopTrial` (something removing the Time-skip state folder, or a `run.json` touched by something else — `timeskip.mjs:30-42` already says a parse failure means something else touched the file). - No regression check added: `trials`, `trialByChat` and `timeskipChoices` are private to the module's closure, so an assertion would need a test-only accessor. The closest observable is `whenEnded`, which PR #4570 already asserts after Stop. Say the word and I will add the accessor, or move the drop into `timeskip.mjs` where the existing test can see it. - If #4442 lands first, a Stop that cannot delete the folder raises before `dropTrial()`, so that trial stays watched (its record still exists, so `status()` is not `null`). Today's line it replaces behaves the same, and I would rather keep the chat's Stop retryable than silently drop it — this is a note, not a change. - The `stopped` set (`timeskip.mjs:298`) is deliberately kept until the host restarts, so its entries are left alone. --- <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#5111
No description provided.