Repository navigation
#237: end_task frees the engine; engine_busy names its holders; a desktop gate for engine tests - #252
Merged
Merged
Conversation
…lose, waiting on neither)
The engine service's turn-ended handler now calls the client's release: the
session's {hide: true} (when it has a cursor) and the close are written at
once on the live connection, so the engine stops counting it and engine
build/approve proceed. The next engine-bound request reconnects as after any
close. hideCursor is replaced by release.
Sminos-Session: cursor235#b93055dd (cua on macbook)
… on the engine's side A client's close no longer ends its connection's #200 after-action watch: the watch runs to its natural end under its own rules, held by the engine's ClosedConnectionWatches, and the next execute on any connection (or the engine's shutdown) ends it first. The connection leaves the open map at once, so status and shutdown's busy count drop at the close. A cursor fading at the close keeps its panel until the fade has played out. Menu span, focus hold, intervention drives and enablement still go at the close. Sminos-Session: cursor235#b93055dd (cua on macbook)
…bel)
The engine reads each admitted connection's peer pid at accept
(LOCAL_PEERPID; the uid check stays) and keeps the session's label from its
cursor requests, whatever the cursor switches. status adds holders: [{pid,
label}] for the other connections, keeping connections; shutdown's busy
refusal carries them too. cua engine stop/build/approve's engine_busy and
cua engine status name them (pid 42091 (MAWS)); an engine without holders
still gives the count.
Sminos-Session: cursor235#b93055dd (cua on macbook)
Condition 2's evidence on the EnablementAccess seam: the release at close, one write at the next connection's first observation (which waits for the page), none at its warm observations. Sminos-Session: cursor235#b93055dd (cua on macbook)
…down and holders Sminos-Session: cursor235#b93055dd (cua on macbook)
…equests A connect in flight at end_task could publish a live connection when its ping answered and send the ended task's request after end_task returned, leaving the engine busy again; requests queued on the tail could reconnect the same way. release now starts a new generation: a connect of an older one closes its socket instead of publishing, and an older queued request fails unsent (Released). A request made after release still reconnects lazily. Sminos-Session: cursor235#b93055dd (cua on macbook)
… or a drain Two races in the deferred watch. The close removed the connection from the open ones before adopting its watch, so a request or a shutdown in that gap found neither; Server.retire now adopts the watch and removes the connection in one step under the server's lock, before any other teardown. And cancelAll emptied the registry before cancelling outside the lock, so a second concurrent drain went ahead while the first still waited on a sample; drains are now serialized, so none returns before the watches it raced stop. Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
… the unit tests #237's incident: a unit test ran an execute on an engine nothing had stubbed and the engine launched TextEdit. Every call by which the engine acts on the desktop or another process's GUI now passes DesktopGate: the app launch, re-activation, CGEvent posts, Accessibility actions and writes (AXOps' defaults, route 1's action, the enablement write, the probes'), the screen-update hold, general-pasteboard writes, and the cursor panel ordered onto the screen. Open in the engine (a flag read); closed in any process with XCTest loaded, where a call is refused (nothing done, or desktopGateClosed naming the call), recorded, and made the running test's failure by an observer the test bundle registers as it loads (Tests/EngineTestGate). The proving test launches a bundle that does not exist and checks the gate's record; the rest of the suite triggers no refusal. Sminos-Session: cursor235#b93055dd (cua on macbook)
buildEngine reads the engine's status before the swift build, the staging and the signing, and refuses with the same engine_busy naming the holders; an engine that is not running is not busy and the build goes on. The already-current early return comes first (it touches nothing). The check at the swap stays the authority against a client that connects meanwhile. Sminos-Session: cursor235#b93055dd (cua on macbook)
… names built lazily The review of ce8fb2a..2f9a83e: approve, requireAccessibility and requireScreenRecording could put up real permission dialogs from a unit test. The Accessibility request with its prompt and CGRequestScreenCaptureAccess now pass the gate (refused, each answers the non-prompting preflight), and so do the screen's listing and capture, which can raise the capture confirmation. The engine requests no other grant. The gate takes the refused call's name as an autoclosure, so the engine never builds it. Sminos-Session: cursor235#b93055dd (cua on macbook)
…cratch engine) Sminos-Session: cursor235#b93055dd (cua on macbook)
… build busy check Sminos-Session: cursor235#b93055dd (cua on macbook)
SSFSKIM
added a commit
that referenced
this pull request
Nov 1, 2026
…71-m3 Main moved after the first merge (0982cab): #252 (#237: end_task frees the macOS engine, engine_busy names its holders, engine tests cannot touch the desktop). A merge again, not a rebase, so the gate judges the tree that ships. The overlapping files and how each was resolved: - .claude-plugin/plugin.json, marketplace.json (conflict): this branch's 0.21.0 (cabbb11) kept. It is still the next minor on top of main's 0.20.4. No other file overlaps. #252 touches the macOS engine client and service (src/services/engine/{client,service}.mjs), src/runtime/ engine.mjs, src/cli.mjs's engine status line and native/engine/; none of them is in cua's Linux service, its selection or the Linux engine. Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
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.
Summary
After a session's
end_task, cua's macOS engine kept counting that session's REPL host as connected, socua engine buildandapprovefrom any other session refusedengine_busy. That lasted until the first session's runtime stopped, which could be up to 15 minutes later. It cost two owner slots. Nowend_taskcloses the session's engine connection,engine_busynames who holds the engine, and a busyengine buildrefuses in well under a second, before it compiles anything.Cause. cua's engine client opens one connection per REPL host, lazily, on the first engine-bound request (
src/services/engine/service.mjs), and nothing ever closed it.end_taskonly hid the cursor, andEngineClient.close()had no caller. The runtime's idle stop, 15 minutes after the last call, was the only thing that closed it.Fix:
service.mjs,client.mjs). The turn-ended hook sends the cursor hide, if the session has a cursor, and closes the connection. Neither is waited for, soend_task's reply isn't delayed. The next engine-bound request reconnects lazily: milliseconds against a running engine.end_taskcloses its socket instead of publishing the connection, and requests still queued from the old task fail with aReleasedtransport error.js_resetis unchanged.Server.swift,Activation.swift,Cursor/CursorHub.swift). The connection leaves the open map at once, sostatusand the shutdown's busy count drop at the close. Two things still finish:end_taskusually follows a click closely and a late raise still has to be repaired. The nextexecuteon any connection cancels it;ping,statusandcursordon't.Server.retirepublishes the watch and removes the connection in one step under the server lock. Concurrent drains wait for each other.Server.swift,Methods.swift,src/runtime/engine.mjs). The engine records each connection's peer pid at accept (LOCAL_PEERPID; the uid check is unchanged) and the session's cursor label.statusaddsholders: [{pid, label}], andengine_busyandcua engine statusname them:pid 42091 (MAWS). An engine without holder support still gives the count.cua engine buildchecks busy first. It runs the same status read before the Swift build, staging and signing. The check at swap time stays the authority against a client that connects meanwhile.DesktopGate.swift, test targetEngineTestGate).executeon a realServerand launched TextEdit on the owner's Mac. It was killed after about 30 s.engine-swiftjob runs the test bundle, so it runs with the gate closed.Plugin 0.20.4 (its own commit).
Measured (live, MacBook, 2026-11-01;
docs/evidence/2026-11-01-engine-busy-end-task/)cua serve):end_task,engine statusread 1 other connection.end_taskread 0. It started 66 ms and 22 ms after the request, and the count was still 0 at +2 s.list_appscell reconnected.engine buildwith the holder connected refusedengine_busyin about 210 ms. The engine directory was untouched: no staging directory, mtimes unchanged. The run setCUA_SIGNING_IDENTITYbecause build checks for an identity first; nothing was signed.statusread2 other connection(s): pid 73206 (MAWS), pid 73207 (cursor235).engine stoprefusedengine_busynaming both.Limits
end_task:testATaskAfterEndTaskReEnablesOnceAndItsWarmObservationsWriteNothing). Basic mode from macOS engine: the first observation of a freshly enabled Chromium/Electron app returns an incomplete tree (vendor's is complete) #244's role read persists;end_taskstill holds the engine until the 15-minute idle stop. Whoever is blocked now sees who to ask.end_taskwas not read.Tests
LOCAL_PEERPID;end_task;DesktopGateTests.test/services-engine-client.test.mjs,test/services-engine-service.test.mjs);test/runtime-engine*.test.mjs);test/native-engine.test.mjs).ci-gateon 76be59e: plugin, engine-swift, sandbox-live and test PASS (run 41291865985). parity-browser went red there on the known racywaitforcell alone (parity-browser hosted gate: fix the two racy parity cells (waitfor deadline race, drag ended wait), then run it on PRs #168) and passed on its re-run (run 41293528519, GREEN). The PR's own checks are green (run 41291839928).Docs
end_task, the deferred teardown, holders, the rejected alternatives), with amendments for the race fixes and the desktop gate.Closes #237
Sminos-Session: cursor235#b93055dd (cua on macbook)