From e87cb1a929bd12ebc348b5e1f3bcbbd6dd7c4819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20=C5=BBuk?= <93780882+lythx@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:13:31 +0000 Subject: [PATCH 1/2] docs: status polling through task totals, results matched by output uuid Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SJ9KD35iAW6g4FnGoBkxTo --- .../docs/frontend/simulation-services.md | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/content/docs/frontend/simulation-services.md b/src/content/docs/frontend/simulation-services.md index 64bb5b8..571897e 100644 --- a/src/content/docs/frontend/simulation-services.md +++ b/src/content/docs/frontend/simulation-services.md @@ -49,32 +49,21 @@ Uses `ky` (a fetch wrapper) with: ### Polling Loop -```typescript -// Simplified polling logic -async function pollJobStatus(jobId: string) { - while (true) { - const status = await authKy.get(`jobs/direct?job_id=${jobId}`).json(); - - if (status.jobState === 'COMPLETED') { - const results = await authKy.get(`results?job_id=${jobId}`).json(); - displayResults(results); - return; - } - - if (status.jobState === 'FAILED' || status.jobState === 'CANCELED') { - showError(status); - return; - } - - // Update progress bars - updateTaskProgress(status.jobTasksStatus); - - await sleep(getPollingInterval()); - } -} -``` +The Simulations tab polls the status of every simulation on the current page (`SimulationsGridHelpers.ts`): + +- Every **1.5 s** while any simulation is unfinished, every **10 s** once all have settled. +- A hidden browser tab does not poll. The next tick after the tab is shown again catches up. +- A status is requested with `GET /jobs/direct?job_id=…` or `GET /jobs/batch?job_id=…`. + +Progress and the "primaries" and "ntask" chips on the simulation card come from `taskTotals(status)` (`src/util/taskTotals.ts`). It reads the server's `jobTasksSummary` (number of tasks, tasks per state, requested and simulated primaries) when the status has one, and otherwise sums the task list `jobTasksStatus`. Simulations run in the browser (Geant4) only have the task list. Read task progress through `taskTotals()`, never from `jobTasksStatus` directly, because a status may carry only the summary. + +When the simulation the user just started completes, its results open once. A finished run is remembered, so reopening the Simulations tab does not jump back to its results. + +When the editor is connected to the backend, `useUpdateCurrentSimulationEffect` looks for the completed simulation whose input hash equals the editor's, and loads its results into the editor. A failed request skips that simulation, and an older search that ends late does not overwrite a newer one. + +### Matching results to editor outputs -The polling interval increases over time to reduce server load on long-running simulations. +The results of each estimator are linked to the scoring output in the editor that produced them (`recreateRefsInResults` in `RemoteWorkerSimulationService.ts`). The backend sends each estimator's `output_uuid` with the results, and the UI matches it to `scoringManager.outputs[].uuid`. Results without it, such as simulations stored before the backend sent it, are matched by output name. An estimator that matches no output gets no reference and is logged as an error. ### Result Caching From 91438aa41e22bac226164d4621128a7cf8bc29f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20=C5=BBuk?= <93780882+lythx@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:42:20 +0000 Subject: [PATCH 2/2] docs: a loaded simulation is found by the hash of its input Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SJ9KD35iAW6g4FnGoBkxTo --- src/content/docs/frontend/simulation-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/frontend/simulation-services.md b/src/content/docs/frontend/simulation-services.md index 571897e..1c416ab 100644 --- a/src/content/docs/frontend/simulation-services.md +++ b/src/content/docs/frontend/simulation-services.md @@ -59,7 +59,7 @@ Progress and the "primaries" and "ntask" chips on the simulation card come from When the simulation the user just started completes, its results open once. A finished run is remembered, so reopening the Simulations tab does not jump back to its results. -When the editor is connected to the backend, `useUpdateCurrentSimulationEffect` looks for the completed simulation whose input hash equals the editor's, and loads its results into the editor. A failed request skips that simulation, and an older search that ends late does not overwrite a newer one. +When the editor is connected to the backend, `useUpdateCurrentSimulationEffect` looks for the completed simulation whose input hash equals the editor's, or the hash of the input the editor was loaded from (kept until the first edit, because serializing a loaded editor again can give another hash). It attaches that simulation's results to the editor, where the Save dialog can include them. A failed request skips that simulation, and an older search that ends late does not overwrite a newer one. ### Matching results to editor outputs