Repository navigation
feat(macos): bound the kernels each supervisor runs at once (#64 PR 2a) - #108
Merged
Merged
Conversation
Each supervisor service admits at most L = clamp(physical memory / (4 x 4096 MB), 1, cores) kernels at once: about a quarter of RAM per service, a half across the thumbnail and preview services. Requests over L wait in a FIFO queue; their deadline counts from submission, and one that expires or is cancelled there is withdrawn without spawning a kernel. Queueing, admission and withdrawal are logged, and each service names itself (bundle id) and its L in its start line: the two supervisors are one binary, so the log cannot tell them apart by image path. Tests (scripts/ql-e2e/supervisor.sh): a test build (STEPV_TEST_HOOKS, never shipped) with L = 1: the second of two runs spawns only after the first ended, and a run past its deadline in the queue never spawns; the probe's concurrency check follows the service's logged L. Refs: #64
gerchowl
added a commit
that referenced
this pull request
Oct 13, 2026
…read (#64 PR 2) Review round 2 on #107 (the admission limit is #108, which merges first): - closing a preview releases its view controller; deinit cancels the run. ql-e2e closes a preview of a 4000-part file at 8 s: its kernel is cancelled with SIGKILL, reaped, and gone (fails without the cancel) - StepvPreviewSession: the ready rule, the 20 s ready timer, a 122 s backstop that cancels a run whose service never replies and shows why, late replies dropped once (StepvOnce, shared with the thumbnail), the mesh decoded and its scene built off the main thread; unit tests with a fake service (fail without the backstop) - test-macos.sh: the linkage check fails closed (/nonexistent fails) - run-all.sh: the wait for huge.step's kernel fails when it runs out; the deadline kill must be huge.step's own pid; services name themselves (bundle id) in their start line, as the log cannot tell the two supervisors apart by image path - docs no longer call the kernel in-process (plan.md status and risks, extension.entitlements, capi/src/lib.rs) Refs: #64
… slot budget (#64 PR 2a) - the queued-deadline test asserts order: the withdrawal reply comes while the first run still runs, and says "in the queue" (fails without the timer); the admission-time check has its own test, via a test-build handover hold (fails without the check) - cancel race: the withdraw is installed before the run can be queued, and cancelled is re-checked once it is; a cancel before the spawn gets the cancelled reply. Tested: a queued run cancelled is withdrawn once, never spawns, and the run behind it is admitted next - no sleeps order the tests: the first run's first event, and a "go" from supervisor.sh once the run to cancel is logged as queued - the test-build admission-limit outside 1...cores is a startup error - one slot's budget, 4096 MB (Admission.slotMemoryMB), bounds both L and a request's memoryMB: more is refused (tested: 4097) Refs: #64
5 tasks
gerchowl
added a commit
that referenced
this pull request
Oct 13, 2026
…read (#64 PR 2) Review round 2 on #107 (the admission limit is #108, which merges first): - closing a preview releases its view controller; deinit cancels the run. ql-e2e closes a preview of a 4000-part file at 8 s: its kernel is cancelled with SIGKILL, reaped, and gone (fails without the cancel) - StepvPreviewSession: the ready rule, the 20 s ready timer, a 122 s backstop that cancels a run whose service never replies and shows why, late replies dropped once (StepvOnce, shared with the thumbnail), the mesh decoded and its scene built off the main thread; unit tests with a fake service (fail without the backstop) - test-macos.sh: the linkage check fails closed (/nonexistent fails) - run-all.sh: the wait for huge.step's kernel fails when it runs out; the deadline kill must be huge.step's own pid; services name themselves (bundle id) in their start line, as the log cannot tell the two supervisors apart by image path - docs no longer call the kernel in-process (plan.md status and risks, extension.entitlements, capi/src/lib.rs) Refs: #64
gerchowl
added a commit
that referenced
this pull request
Oct 13, 2026
…imit (#64 PR 2) On top of #108: at L >= 2, box.brep must draw while huge.step still runs; at L = 1 (CI's 7 GB runner) it must queue behind it and spawn only after huge.step's kernel is killed. L comes from the thumbnail service's own start line, and the log is scoped to the request (e2elog.py). Refs: #64
This was referenced Oct 13, 2026
Closed
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
… event (#111) (#113) ## Fix #111: the supervisor tests wait on the service's own logged events, and tell runs apart by identity Fixes #111. ### Root cause (#111) A 1.5 s run was killed before its first event, with admission limit 1 on the runner. #108 round 2 had replaced a sleep with "wait for the run's first event" as the sign that its kernel was running. The slow run's deadline is 1.5 s, and on CI's slower runner its TREE didn't arrive before the kill (`deadline: 1 run #4 … killed at 1509 ms`, then the wait ran out at `up 20440 ms`). The handover case, with a 2 s deadline, had the same flaw. This is a test bug. ### A separate bug, introduced by this PR's own earlier commits When 9a6ac31 removed the `sleep 1`, the harness's whole-second log windows began to catch the lines of the step before. - 9a6ac31 counted `6 kernel spawns, expected 10`, waiting on the wrong service instance. - cd30216 failed ql-e2e's cache control on the previous request's line. - d4efd38 narrowed the windows to the microsecond. That still tells runs apart by time, so this round replaces it with identity. ### Fix - **Waiting on the logged event, not on time.** The probe asks `supervisor.sh`, on stdout, to wait for a run's logged spawn, queueing or held-deadline (`await <what> <run> <pid>`), and goes on once that exact line is there. - **Identity, not time windows.** When the service takes a run, it now sends the client `accepted(run)` with the run's number in its log. The client then has the service's pid as well (`StepvSupervisorRun.onAccepted`, `servicePid`). `processIdentifier` stays 0 until a message from the service arrives, so it can't stand alone. - `drive` matches exactly that run of that service, and every log check is scoped to the service pid its probe reported. - `set_start` only bounds how much log is read. - A self-check plants a decoy line from another service: a pattern that ignores the pid fails it. - ql-e2e's cache control asks the second time through a hard link (same inode, new path), and the verdict goes by path. - **The held handover is released by the test, not by elapsed time.** A test build (`STEPV_TEST_HOOKS`, `admission-hold`) holds each admitted run until `release-N` appears in the service's tmp. It logs when the run's deadline passes while held, and the probe releases the run only after seeing that line. The run then reaches the admission-time check past its deadline and is refused, never spawned. The earlier widenings are reverted (deadline 2 s, drive 60 s, wait 15 s). This also resolves #109's first item. - **The fix for the real cause stays.** The deadline kill needs no "running" precondition. At L ≥ 2 it is also tested beside a running run (killed at 1.5 s while the held run goes on). At L = 1 no two kernels run at once, so the kill alone is the case there. Runs that must hold a slot while an order is checked use a 4000-part file and are cancelled by the probe. ### Results (sage) - `scripts/test-macos.sh`: exit 0 (L = 16). - `scripts/ql-e2e/supervisor.sh` on an L = 1 test build (CI's case): exit 0. - `scripts/ql-e2e/run-all.sh`: exit 0, ALL PASS. - **Fails without the change:** | Change | Exit | Result | |---|---|---| | Reproduction: main's `supervisor.sh` with a slower slow file | 1 | `the slow run's kernel is running` fails, as on CI | | The same reproduction, after the fix | 0 | passes | | B1: a `drive` pattern that ignores the pid | 1 | `drive takes another service's run #6 for its own` | | B2: the hold released by its own timer | 1 | both handover checks fail | (The branch is `bugfix/111-…`: the repo's commit hook rejects `fix/` branch names.) ### Round 4: ql-e2e judged by identity, from one log stream (dcabac0, 37de33d) - **Root cause of the ql-e2e red** (run 38405706989): the extension's lines *were* logged — the failure dump showed `thumbnail <the request's own path>: drawn` stamped 13:57:15.076 — but stamped before the request's own start, taken earlier by the wall clock. On CI's macOS VM a log event's timestamp runs behind `date` (an estimated ~0.7 s), so every window opened at a wall-clock instant (`log show --start`, or e2elog's microsecond `since`) dropped the request's own line, and a 769 ms thumbnail was judged cached. Not log lag: polling longer could not find it. - **Fix:** `run-all.sh` starts one `log stream` before the first request (`QL_E2E_STREAM`), read by `ql-e2e.sh` and `supervisor.sh`; no `log show` anywhere. A request's lines are found by its own path, the supervisor's by service pid and run number; no time is compared (`e2elog.py`). Every wait is bounded (30 s) and says so when reached. - **37de33d:** c71e629's probe signalled `taken` after `done`, so a refused run's temporary probe could be freed first: `swift_abortRetainUnowned` on sage (L = 4). `done` is now signalled last. - **Results (sage):** `just macos-test` exit 0; `scripts/ql-e2e/supervisor.sh` exit 0; `just ql-e2e` exit 0, ALL PASS. - **Cache control stays honest:** with the cache defeat removed (each request a hard link to the source: same inode), `run-all.sh` exits 1 once the inodes are in Quick Look's cache: all three thumbnails `QL served a cached thumbnail` (8–9 ms), VERDICT FAIL.
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…read (#64 PR 2) Review round 2 on #107 (the admission limit is #108, which merges first): - closing a preview releases its view controller; deinit cancels the run. ql-e2e closes a preview of a 4000-part file at 8 s: its kernel is cancelled with SIGKILL, reaped, and gone (fails without the cancel) - StepvPreviewSession: the ready rule, the 20 s ready timer, a 122 s backstop that cancels a run whose service never replies and shows why, late replies dropped once (StepvOnce, shared with the thumbnail), the mesh decoded and its scene built off the main thread; unit tests with a fake service (fail without the backstop) - test-macos.sh: the linkage check fails closed (/nonexistent fails) - run-all.sh: the wait for huge.step's kernel fails when it runs out; the deadline kill must be huge.step's own pid; services name themselves (bundle id) in their start line, as the log cannot tell the two supervisors apart by image path - docs no longer call the kernel in-process (plan.md status and risks, extension.entitlements, capi/src/lib.rs) Refs: #64
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…ream (#64 PR 2) #107's Quick Look cases (the deadline with a thumbnail beside it, the next request, the closed preview) were written against log show and "since T" windows; #113 replaced both with one log stream, matched by identity. They now follow it: - each extension logs which run of which service took its file ("accepted: run #N (service pid P), thumbnail|preview <path>"), and runs.py reads that run's own lines from the stream, in stream order; no timestamp is compared - the concurrency check follows the service's admission limit (#108): at L >= 2 the run beside is never queued and exits before the held run's kill; at L = 1 it is queued and spawns only after that kill, if at all - a closed preview's cancel must fall between the host's logged close and its logged quit, 3 s later, so the kill at the quit cannot pass - a preview switched to another file under a live run: the old kernel goes at the switch, box.brep is shown. Quick Look makes a new controller (measured, again); should it ever reuse one, the controller cancels the session it replaces and logs it - verdict.py: a preview is ready once, on its tree before the scene (STEP) or on its mesh (IGES, BREP), in stream order - runs_test.py checks every verdict on made-up streams, a decoy service whose pid has the real one's as a prefix among them Refs: #64
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…read (#64 PR 2) Review round 2 on #107 (the admission limit is #108, which merges first): - closing a preview releases its view controller; deinit cancels the run. ql-e2e closes a preview of a 4000-part file at 8 s: its kernel is cancelled with SIGKILL, reaped, and gone (fails without the cancel) - StepvPreviewSession: the ready rule, the 20 s ready timer, a 122 s backstop that cancels a run whose service never replies and shows why, late replies dropped once (StepvOnce, shared with the thumbnail), the mesh decoded and its scene built off the main thread; unit tests with a fake service (fail without the backstop) - test-macos.sh: the linkage check fails closed (/nonexistent fails) - run-all.sh: the wait for huge.step's kernel fails when it runs out; the deadline kill must be huge.step's own pid; services name themselves (bundle id) in their start line, as the log cannot tell the two supervisors apart by image path - docs no longer call the kernel in-process (plan.md status and risks, extension.entitlements, capi/src/lib.rs) Refs: #64
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…ream (#64 PR 2) #107's Quick Look cases (the deadline with a thumbnail beside it, the next request, the closed preview) were written against log show and "since T" windows; #113 replaced both with one log stream, matched by identity. They now follow it: - each extension logs which run of which service took its file ("accepted: run #N (service pid P), thumbnail|preview <path>"), and runs.py reads that run's own lines from the stream, in stream order; no timestamp is compared - the concurrency check follows the service's admission limit (#108): at L >= 2 the run beside is never queued and exits before the held run's kill; at L = 1 it is queued and spawns only after that kill, if at all - a closed preview's cancel must fall between the host's logged close and its logged quit, 3 s later, so the kill at the quit cannot pass - a preview switched to another file under a live run: the old kernel goes at the switch, box.brep is shown. Quick Look makes a new controller (measured, again); should it ever reuse one, the controller cancels the session it replaces and logs it - verdict.py: a preview is ready once, on its tree before the scene (STEP) or on its mesh (IGES, BREP), in stream order - runs_test.py checks every verdict on made-up streams, a decoy service whose pid has the real one's as a prefix among them Refs: #64
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…read (#64 PR 2) Review round 2 on #107 (the admission limit is #108, which merges first): - closing a preview releases its view controller; deinit cancels the run. ql-e2e closes a preview of a 4000-part file at 8 s: its kernel is cancelled with SIGKILL, reaped, and gone (fails without the cancel) - StepvPreviewSession: the ready rule, the 20 s ready timer, a 122 s backstop that cancels a run whose service never replies and shows why, late replies dropped once (StepvOnce, shared with the thumbnail), the mesh decoded and its scene built off the main thread; unit tests with a fake service (fail without the backstop) - test-macos.sh: the linkage check fails closed (/nonexistent fails) - run-all.sh: the wait for huge.step's kernel fails when it runs out; the deadline kill must be huge.step's own pid; services name themselves (bundle id) in their start line, as the log cannot tell the two supervisors apart by image path - docs no longer call the kernel in-process (plan.md status and risks, extension.entitlements, capi/src/lib.rs) Refs: #64
gerchowl
added a commit
that referenced
this pull request
Nov 8, 2026
…ream (#64 PR 2) #107's Quick Look cases (the deadline with a thumbnail beside it, the next request, the closed preview) were written against log show and "since T" windows; #113 replaced both with one log stream, matched by identity. They now follow it: - each extension logs which run of which service took its file ("accepted: run #N (service pid P), thumbnail|preview <path>"), and runs.py reads that run's own lines from the stream, in stream order; no timestamp is compared - the concurrency check follows the service's admission limit (#108): at L >= 2 the run beside is never queued and exits before the held run's kill; at L = 1 it is queued and spawns only after that kill, if at all - a closed preview's cancel must fall between the host's logged close and its logged quit, 3 s later, so the kill at the quit cannot pass - a preview switched to another file under a live run: the old kernel goes at the switch, box.brep is shown. Quick Look makes a new controller (measured, again); should it ever reuse one, the controller cancels the session it replaces and logs it - verdict.py: a preview is ready once, on its tree before the scene (STEP) or on its mesh (IGES, BREP), in stream order - runs_test.py checks every verdict on made-up streams, a decoy service whose pid has the real one's as a prefix among them Refs: #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#64 PR 2a: the supervisor's admission limit
Refs #64. This merges before #107 (#64 PR 2), so
mainnever ships unbounded kernel concurrency. #107 rebases onto it.What changes
Admissioninmacos/Supervisor/main.swift: each service runs at most L = clamp(physical memory / (4 × 4096 MB), 1, cores) kernels at once.Tests (against main's code: the supervisor probe and harness, not the extensions)
scripts/ql-e2e/supervisor.shbuilds a test supervisor (-D STEPV_TEST_HOOKS, never shipped) that reads L = 1 from its bundle. With it:Results (sage)
scripts/test-macos.sh: exit 0 (L = 16, plus the L = 1 test build).scripts/ql-e2e/supervisor.shon a copy whose supervisors are the L = 1 build (CI's case): exit 0.