Skip to content

feat(macos): the Quick Look extensions run the kernel out of process (#64 part 2) - #107

Merged
gerchowl merged 6 commits into
mainfrom
feature/64-xpc-supervisor-2
Nov 8, 2026
Merged

gerchowl merged 6 commits into
mainfrom
feature/64-xpc-supervisor-2

Conversation

@gerchowl

@gerchowl gerchowl commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

#64 part 2: the Quick Look extensions run the kernel out of process

Closes #64. Builds on #98 (part 1: the supervisor service), #103 (the kernel reads its descriptor directly) and #91.

What changes

  • No kernel in the extensions. They link libstepv_capi.a only (the renderer and header reader). otool -L shows no libstepvocct and no OCCT, and scripts/test-macos.sh now checks that. The app's Frameworks/ serves the CLI's kernel alone.
  • Thumbnail:
    • The fd goes to the service, which runs the kernel; the extension replies once with the rendered image.
    • Deadline 15 s, enforced by the service, plus a 17 s backstop in the extension. Quick Look's thumbnail watchdog is reportedly about 20 s, and a thumbnail has nothing to show partway, so the kernel gets 15 s and the render and reply get the rest.
  • Preview:
    • The header shows at once, then the assembly tree (the outline, indented, at most 14 lines) and live progress, then the scene.
    • handler(nil): once the header and tree are on screen. With no tree (IGES, BREP, a failed or oversized outline), on the first mesh or the failure. At the latest after 20 s (the watchdog is about 30 s; 10 s of margin).
    • The view lives on, so the run may take up to 120 s (the 42 s Ultimaker assembly loads). The run is cancelled when the view goes away.
  • Memory cap: 4096 MB in both, the CLI's default.

ql-e2e on the real extensions (just ql-e2e)

Every check reads #113's single log stream and matches by identity, never by time:

  • Each extension logs which run of which service took its file: accepted: run #N (service pid P), thumbnail|preview <path>. scripts/ql-e2e/runs.py reads that run's own lines and judges by stream order alone. runs_test.py checks each verdict on made-up streams first, with a pid-prefix decoy among them.
  • A preview and a thumbnail for STEP, IGES and BREP. Each preview must be ready exactly once: on its tree before the scene for STEP, on its mesh for IGES and BREP.
  • A 4000-part file is thumbnailed past its 15 s deadline, with box.brep beside it.
    • At L ≥ 2, box.brep's run is never queued and exits before the held run's kill.
    • At L = 1, box.brep's run is queued and spawns only after that kill, if at all.
    • Then the held run's killed (deadline), no thumbnail, its kernel gone, and the next thumbnail under 3 s.
  • Closed preview: the host closes on a signal sent once the file's ready line is in the stream, never at a set time. It logs its close and its quit 3 s later. The kernel's SIGKILL cancel must fall between the two, be reaped within 1 s, and be gone.
  • Closed before ready: Quick Look keeps the controller until its handler is called, so the kernel is cancelled at the preview's ready (20 s at the latest), not at the close (macOS preview: a preview closed before it is ready keeps its kernel until it becomes ready (≤ 20 s) #122). The case closes on the kernel's spawn. The close must come before the ready line, and the cancel after it, before the quit.
  • Switched preview: the host switches the view to box.brep once the file is ready. The old kernel must be cancelled between the switch and the quit, and box.brep must be shown.
    • Quick Look makes a new controller per item; this was measured again: no controller is prepared twice.
    • For a closed or switched preview, no result line may follow for the file that went, and its handler must complete exactly once.
  • A cancelled session (closed, or superseded by a second prepare: StepvPreviewSlot):
    • Its kernel is killed.
    • Nothing of it reaches the view: a late tree, progress, result, ready or decode is dropped and logged stale, dropped.
    • Quick Look's handler completes exactly once: nil when ready, CocoaError(.userCancelled) if cancelled first. It is then released, because it retains the controller.
  • The supervisor probe and the cache control are unchanged from main.

Results (head 08eb056; sage, macOS 26.4; rebased on main after #113, #81, #116 and #119)

  • just macos-test: exit 0. That includes the preview-session unit tests, the linkage check and the supervisor probe.
  • Linkage check fails closed: it requires a Mach header and at least one (compatibility version line. A text file fails it, and so does /nonexistent. The old check passed a text file, because otool -L exits 0 on one.
  • just ql-e2e on the product build (L = 4): exit 0, ALL PASS.
    • Deadline: killed at 15 023 ms, reaped in 22.4 ms, gone.
    • Concurrent: box.brep was never queued and exited before the kill.
    • No throttle: 112 ms.
    • Closed: cancelled between the close and the quit, reaped in 17.7 ms.
    • Switched: the same, reaped in 18.7 ms.
  • The same run on an L = 1 test build (CI's 7 GB case): exit 0, ALL PASS. box.brep was queued and spawned after huge.step's kill (killed at 15 031 ms).
  • Without the deinit cancel (mutant): FAILURES. The closed and the switched preview were each cancelled only after the host quit.
  • Controller reuse (round 6, PreviewSessionTests): A's result arrives and its decode is still running when B supersedes it.
    • Passes: A shows nothing and its handler completes once, cancelled. B is ready on its own result, and its handler completes once.
    • Without the liveness check: exit 1. A's result is shown, and it marks B ready.
    • Without the handler's release: exit 1. In ql-e2e the closed and the switched previews were then cancelled only at the quit.
  • cbbe55e's macos-15 CI was red: the closed preview was cancelled only at the quit. The tree had not come by the fixed 8 s close, and the controller lives until its handler is called. Closes and switches are now ordered on the logged ready (08eb056).
  • Round 6 on 08eb056: just macos-test exit 0, just ql-e2e exit 0, ALL PASS. Closed before ready: ready (tree) at 4.47 s, then the cancel, reaped in 15.9 ms.
  • Nits filed: macOS: .p21 is declared as STEP but no extension or kernel path accepts it #120 (.p21), macOS preview: a mesh that fails to decode is reported as "no geometry" #121 (a mesh decode error is reported as "no geometry"). Design question: macOS preview: a preview closed before it is ready keeps its kernel until it becomes ready (≤ 20 s) #122 (call the handler sooner?).
  • scripts/ql-e2e/supervisor.sh: exit 0. cargo fmt --check: exit 0. cargo clippy --all-targets -- -D warnings: exit 0. No kernel change.

Known limits

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
…a) (#108)

## #64 PR 2a: the supervisor's admission limit

Refs #64. This merges **before** #107 (#64 PR 2), so `main` never ships
unbounded kernel concurrency. #107 rebases onto it.

### What changes
- `Admission` in `macos/Supervisor/main.swift`: each service runs at
most **L = clamp(physical memory / (4 × 4096 MB), 1, cores)** kernels at
once.
- That's about ¼ of RAM per service, ½ across the thumbnail and preview
services.
  - L is 1 on an 8–16 GB Mac and on CI's 7 GB runner, and 16 on sage.
- Requests over L wait in a **FIFO** queue.
  - Their **deadline counts from submission**: queue time is spent.
- A request that expires or is cancelled in the queue is **withdrawn
without spawning a kernel**, and gets its normal deadline or cancelled
reply.
- Queueing, admission and withdrawal are logged. Each service also names
itself (bundle id) and its L in its start line: the two supervisors are
one binary, so the log can't tell them apart by image path.

### Tests (against main's code: the supervisor probe and harness, not
the extensions)
- `scripts/ql-e2e/supervisor.sh` builds a **test supervisor** (`-D
STEPV_TEST_HOOKS`, never shipped) that reads L = 1 from its bundle. With
it:
- the second of two runs spawns only after the first has ended, checked
from the log's order;
  - a run whose deadline passes in the queue **never spawns**.
- The probe's concurrency check follows the service's logged L: at L ≥ 2
the second run finishes beside the first, at L = 1 it is served after
it.

### Results (sage)
- `scripts/test-macos.sh`: exit 0 (L = 16, plus the L = 1 test build).
- `scripts/ql-e2e/supervisor.sh` on a copy whose supervisors are the L =
1 build (CI's case): exit 0.
- Product code: +114 lines.
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
gerchowl force-pushed the feature/64-xpc-supervisor-2 branch from 688855f to 5309724 Compare October 13, 2026 09:48
gerchowl added a commit that referenced this pull request Oct 13, 2026
Root cause of #107's red CI: log show --start takes whole seconds and
verdicts matched by file alone, so the repeated cache-control request
(served from Quick Look's cache in 7 ms) passed on the "drawn" line of
the request before it, for the same file, in the same second.
Reproduced 5 of 5 locally; caught 5 of 5 after.

- e2elog.py: events from a request's own start on, to the microsecond;
  supervisor lines attributed to their service by pid from the start
  lines that name them. verdict.py, the huge.step deadline case (its own
  kernel pid, from the thumbnail service) and the closed preview use it
- the closed preview is measured from the host's logged close (within
  3 s), so a kill when the host quits cannot pass
- the linkage check requires a Mach header and linked libraries: a text
  file fails it (otool exits 0 on one)
- plan.md: Quick Look makes a new controller per previewed item and
  releases the old one (measured), so prepare is not called twice on one

Refs: #64
gerchowl added a commit that referenced this pull request Oct 13, 2026
…ase holds past its deadline (#111)

#113's first CI run, reproduced locally with the new diagnostics: the
held run DID spawn, but drive() waited on the wrong service: a window
opened at a whole second held step 1's killed instance's start line, taken
for step 2's (the same window counted 11 spawns for 10). Its second run
failed in ql-e2e's cache control: the same whole-second window, there
fixed on #107 (e2elog.py), still on main.

- supervisor.sh opens each window at a microsecond (set_start, e2elog.py)
- ql-e2e.sh and verdict.py count only the events from the request's own
  start on (e2elog.py, as on #107)
- handover: B's deadline 20 s, the test build's hold 30 s, so B's deadline
  passes during the hold whatever the log's latency (it once exceeded the
  4 s deadline)

Refs: #111
@gerchowl
gerchowl force-pushed the feature/64-xpc-supervisor-2 branch from 5309724 to ecb5616 Compare November 8, 2026 16:32
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
gerchowl force-pushed the feature/64-xpc-supervisor-2 branch from ecb5616 to 21d8dec Compare November 8, 2026 17:33
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
…s once (#64 PR 2)

#107's review: cancelling a session did not stop a result it had already
accepted. A finished, then the controller was reused for B while A's decode
ran: A's scene was shown and logged under B, B was marked ready by A's
result, and A's completion handler was overwritten and never called.

- the session owns its path and Quick Look's handler. Once cancelled (the
  view closed, or superseded; main thread), a tree, progress, result or
  ready on its way is dropped and logged "stale, dropped", never shown
- the handler completes exactly once per prepare: nil when ready, or
  CocoaError(.userCancelled) if cancelled first; each call is logged
- the handler is released once called: it retains the view controller,
  which holds the session, and a controller kept alive past its close
  never cancels its run (ql-e2e's closed preview failed without this)
- StepvPreviewSlot holds the controller's one preview and cancels the one
  a second prepare supersedes
- PreviewSessionTests drives the reuse path with a fake service. Without
  the liveness check it fails (exit 1): A's result is shown and marks B
  ready
- ql-e2e asserts that a closed or switched preview shows no result for the
  file that went, and completes its handler exactly once (runs.py gone)
- plan.md: what a cancelled session guarantees for the kernel, the display
  and the handler

Refs: #64
…64 part 2)

Both extensions hand the file to their supervisor service (#98) and
link no kernel: no libstepvocct, no OCCT (otool-checked in
test-macos.sh).

- Thumbnail: one reply with the rendered image; deadline 15 s (QL's
  thumbnail watchdog is reportedly ~20 s), a 17 s backstop for a
  service that cannot reply.
- Preview: the header at once, then the assembly tree and progress as
  they stream, then the scene. handler(nil) once the header and tree are
  on screen; with no tree, on the first mesh or the failure; at the latest
  after 20 s (watchdog ~30 s). The run may take 120 s, and is cancelled
  when the view goes.
- ql-e2e on the real extensions: preview and thumbnail for STEP, IGES and
  BREP, with the handler rule checked from the log; a thumbnail past its
  deadline killed with no survivor, a concurrent request beside it, and
  the next request with no throttle.
- plan.md and CHANGELOG: the design, the deadline values and why, the
  limits (#92, #97, #101, macos-outer).

Refs: #64
…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
… close (#64 PR 2)

- the linkage check requires a Mach header and linked libraries: a text
  file fails it (otool -L exits 0 on one)
- the ql-e2e preview host logs its close to the unified log, so the
  closed-preview case is measured from the close, not from the spawn
- plan.md: Quick Look makes a new controller per previewed item and
  releases the old one (measured), so prepare is not called twice on one

The log scoping this commit first carried (log show, to the microsecond)
is superseded by #113's single log stream and identity matching.

Refs: #64
…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
…s once (#64 PR 2)

#107's review: cancelling a session did not stop a result it had already
accepted. A finished, then the controller was reused for B while A's decode
ran: A's scene was shown and logged under B, B was marked ready by A's
result, and A's completion handler was overwritten and never called.

- the session owns its path and Quick Look's handler. Once cancelled (the
  view closed, or superseded; main thread), a tree, progress, result or
  ready on its way is dropped and logged "stale, dropped", never shown
- the handler completes exactly once per prepare: nil when ready, or
  CocoaError(.userCancelled) if cancelled first; each call is logged
- the handler is released once called: it retains the view controller,
  which holds the session, and a controller kept alive past its close
  never cancels its run (ql-e2e's closed preview failed without this)
- StepvPreviewSlot holds the controller's one preview and cancels the one
  a second prepare supersedes
- PreviewSessionTests drives the reuse path with a fake service. Without
  the liveness check it fails (exit 1): A's result is shown and marks B
  ready
- ql-e2e asserts that a closed or switched preview shows no result for the
  file that went, and completes its handler exactly once (runs.py gone)
- plan.md: what a cancelled session guarantees for the kernel, the display
  and the handler

Refs: #64
… a set time (#64 PR 2)

cbbe55e's macos-15 CI: the closed preview was cancelled only at the
host's quit, with no completion logged. Quick Look keeps the extension's
view controller while its handler is outstanding, and on the small runner
the 4000-part file's tree had not come by the host's fixed 8 s close; so
the controller, and its run, lived until the handler. Measured on sage:
closed at 0.3 s, ready (tree) at 4.97 s, cancelled 32 ms after that.

- the preview host logs its pid and closes or switches on SIGUSR1, which
  run-all.sh sends once the file's ready line is in the stream; it quits
  3 s later, the bound the cancel must keep
- a new case, closed before ready (on the file's kernel spawn): the close
  must come before the ready line and the cancel after it, before the quit
- runs.py: first, order; cancelled bounds on any logged line
- plan.md: what a preview closed before it is ready costs (until its
  ready, 20 s at the latest); #122 asks whether to call the handler sooner

Refs: #64
@gerchowl
gerchowl merged commit d30d1d1 into main Nov 8, 2026
13 checks passed
@gerchowl
gerchowl deleted the feature/64-xpc-supervisor-2 branch November 8, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: the kernel as a child of an XPC supervisor service per Quick Look extension (#54)

1 participant