Repository navigation
Provider add-on hold: fence late model loads, close the release race, keep native preload plans, harden the IPC socket - #1623
Conversation
A local request's cold load that was already past the load gate when a hold began could publish its slot after the hold reported held: the last unload sweep returned while the load still ran, and the publication checks looked only at shutdown and cancellation. - No load takes the load gate while a hold is active. A running load stops at its next check (after hashing, after the weight load, before install; Nemotron Super and native MiMo before their weights and at publication) with a transient (503) load failure. - Past the settle bound the hold waits for the load gate before its last sweep, so it reports held only once no load owns memory. - The settle bound is an instance value so tests can shorten it. Test: TinyModelLoadTests/AddonHoldLoadFence runs a real tiny-model load past the gate, holds, and checks the hold stays draining, the load fails with 503 without publishing, and new loads wait for the release.
When the last hold was released or expired while the drain bound's cleanup was suspended in cancelAllInflight(), admission reopened at once and the stale cleanup then cancelled newly registered native tasks and cleared new requests' task, profile and model tracking. The bound now cancels exactly the coordinator requests it captured when it expired, one at a time, and stops as soon as the hold is released or replaced. cancelAllInflight() stays the lost-connection path. Test: AddonHoldLoopTests.theDrainBoundCancelsItsStragglersButNever WorkAcceptedAfterARelease suspends the pass, releases the hold, starts a new request and checks it stays running and tracked, while the bound still cancels a straggler when no release intervenes.
…g a hold A hold that unloaded a native MiMo or Nemotron Super slot returned through retireNativeMiMoOwner() or retireNemotronSuperSlot(), which still called persistLoadedModelSet() whenever the provider was not shutting down. That rewrote loaded-models.json without those models (and could drop others already unloaded), so the next start lost its preload plan. persistLoadedModelSet() now keeps the file while any add-on hold is active, so every retirement path behaves like the generic unload; that unload's own owner check is folded into it. Tests: NemotronSuperManagedSlotTests.anAddonHoldRetiresTheSuperSlotBut KeepsItsPreloadPlan holds a real managed Super slot; AddonHoldLoopTests .noRetirementPathRewritesThePreloadPlanWhileHeld covers the shared write.
Connections entered the eight-slot connection set before any peer check, which ran only when a complete request line arrived. An unsigned same-user program could open every slot and send nothing, keeping the signed add-on out for the 300 s idle timeout and again on reconnect. - The server checks the kernel audit token against the add-on policy as it accepts a connection, before reserving a slot. An unverified peer is answered unauthorized and closed at once; slots hold only verified add-ons. Every request is still verified again. - A request line must finish within requestTimeout (10 s) of the server first holding it, however slowly its bytes trickle in; the idle and request bounds are injectable for tests. Tests: AddonIPCServerTests.silentUnsignedPeersCannotTakeTheAddonsConnection Slots and .anUnfinishedRequestLineIsBoundedWhileItsBytesTrickleIn.
AddonHoldStore.read() opened the hold record in blocking mode before it checked the file type. A same-user process could replace addon-hold.json with a writerless FIFO and stall restore in open(2); O_NOFOLLOW does not prevent that. The lifecycle mailbox, which carries the operator's darkbloom addon commands, read its files the same way. Both now open with O_NONBLOCK as well as O_NOFOLLOW, then require an owner-only regular file within their size bound before reading, so a FIFO or other special file is refused at once. Tests: AddonHoldStoreTests.aFIFOAtTheRecordPathIsRefusedWithoutBlocking and LifecycleMailboxTests.aFIFOInPlaceOfARequestIsIgnoredWithoutBlocking.
… fixes The threat-model review found the add-on IPC and mailbox control channel under-modelled and the IPC reference citing TB-012 as if undefined. TB-012 already existed at the reviewed head (the review read the base model); its content gaps were real. - threat-model.yaml: TB-012 now records the operator mailbox, accept-time and per-request peer checks, the request and idle bounds, DEBUG-only DARKBLOOM_ADDON_DEV_IDENTITY, DARKBLOOM_ADDON_SOCKET in every build (not passed by the LaunchAgent), self-reported busy fields, the unbounded hold under a held machine lock and the fail-open hold record. T-059 adds the model-load fence; new T-060 covers socket starvation and FIFO stalls. - architecture/security/local-control.md explains who can drive the socket and mailbox, what is checked, and what is not. - addon-hold.md, addon-hold-ipc.md, configuration.md, inference.md and test.md describe the load fence, scoped drain cancellation, the preload plan kept by every retirement path, accept-time verification, the request-line bound and non-blocking control-file reads. - changelog.d/provider-addon-hold-hardening.md.
The idle timeout needs no injection; only the request-line bound is shortened by AddonIPCServerTests. Its comment now says when the bound starts: when the server first holds part of the line.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…erruptions The accept loop answered an unverified peer and a full server with the same write-then-close block; name it refuseUnadmitted so the loop reads as ordered admission checks (configure, signer, slot). modelLoadInterruption now states its priority with guard returns: a stop or cancellation wins over the add-on hold refusal. No behavior change.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Threat model review — advisoryReviewed head Reviewers: anthropic/claude-sonnet-5.5: first pass completed; anthropic/claude-opus-5.5: selected depth completed (9 batches); openai/gpt-6.1-sol: selected depth completed (4 batches) No actionable findings in the reviewed text. This is not a security approval. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Scan completed; human review required. Coverage: 137/137 source units; cross-file integration complete. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. Bedrock: 46 request(s), 2066195 uncached + 0 cache-read + 135963 cache-write input / 36304 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately. |
Brings in #1615, #1617, #1618 (provider 0.10.3 hotfix), #1619, #1620 and #1623 (add-on hold), #1621 (Qwen JSON response formats without default thinking) and #1622 (Qwen JSON response_format answers under the JSON grammar). Conflicts and resolutions: - docs/architecture/inference.md: only the "Last updated" stamp conflicted (2026-10-26 here, 2026-10-27 on master). Kept the one 2026-10-27 stamp; both texts are kept (this branch's forced-admission table and whitespace rule, and master's constrained Qwen JSON answer sections, merged cleanly). Interplay with #1621 and #1622 (same Qwen 3.5/3.6 families): - QwenJSONAnswerPolicy installs the JSON grammar only for requests with no tools and no tool_choice, so a forced request keeps this branch's prompt-forced, withheld and post-validated path with no token constraint, also when it carries a JSON response_format. - templateAdditionalContext turns thinking off for forced legacy Qwen before #1621's JSON default is consulted; both give enable_thinking=false, and caller controls stay overridden on the forced path as before. - NativeToolStreamRouter drops framing whitespace only when a tool call is required. A constrained JSON answer is never forced, so its bytes, including whitespace, stream unchanged.
The merge adds #1566, #1591, #1602, #1605, #1606, #1607, #1612, #1621, #1622, #1623, #1625, #1629, #1630, #1631, #1632 (provider 0.10.4), #1633, #1644, #1652 and #1653 to this branch. Conflicts and resolutions: - CoordinatorClient+Connection.swift: #1606 moves the transport setup out of connectAndRun into the static function connectionParameters(for:), and puts the connectAndRun header below it. This branch adds the session parameter to the same header. The merge keeps the layout of master. The moved header has the signature of this branch: connectAndRun(_ session: CoordinatorSessionRecorder). Git merged the other changes without a conflict: the bounded handshake of master (CoordinatorConnectionHandshake.start) and the session recorder of this branch (markOpened after register, the session parameter of sessionLoop and receiveLoop, and the close-code read). - docs/provider/cli-reference.md: the runtime constants table. The merge keeps the three reconnect rows and the ping/pong row of this branch. It adds the handshake deadline row of master after the ping/pong row, where master has it. - docs/provider/troubleshooting.md: only the "Last updated" stamp had a conflict (2026-10-26 on this branch, 2026-10-27 on master). The merge keeps one stamp, 2026-10-27. Git merged the rows: the backoff citation of this branch and the new rows of master. Each decision has one owner after the merge: - CoordinatorReconnectPolicy chooses the wait before the next connection attempt, after each end of a session or of an attempt. - CoordinatorConnectionHandshake (#1606) cancels a handshake that does not complete in 30 s. runLoop catches the timeout error. That attempt did not send register, so the policy gives the next backoff range, as on master. - UnauthorizedConnectionRecovery (#1607, #1633) decides when to start a re-registration of a connection that the coordinator refuses. Its retry backoff counts re-registrations, not connection attempts, and an authorized verdict sets that count to zero. The re-registration closes the session. Then the policy chooses the wait, as for each other end. Checks: against master, the merge has only the changes of this branch, in its 15 files. The troubleshooting stamp is the one exception: it has the date of master. Against this branch, the merge has only the changes of master, in 651 files. The one exception is the connectAndRun header, which has the session parameter. The gitlinks do not change: libs/mlx 31f550af, libs/mlx-swift 4926d3d9, libs/mlx-swift-lm aee6ebb6. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Summary
Fixes the review findings left on the merged #1620 (reversible add-on hold). Every code fix comes with a regression test that fails on the unfixed code and passes with the fix. Merging publishes dev and staging builds only; this is not a release.
heldcancelAllInflight()lets the stale pass cancel new workloaded-models.jsonduring a holdpersistLoadedModelSet()O_NONBLOCK+O_NOFOLLOW, then owner-only regular file within the size boundTB-012,A-018andT-059already existed at the reviewed head; the listed content gaps were realTB-012andT-059extended, newT-060, new security pageTB-012TB-012is defined at the reviewed heade164315(the review read the base model)T-060Before
flowchart TB subgraph F1["1 · Late model load"] direction LR a1["Local cold load<br/>past the load gate"] --> a2["Settle bound ends;<br/>sweep finds no slot"] --> a3["Hold reports held"] --> a4["Load publishes its slot<br/>beside the VMs"] end subgraph F2["2 · Release during the drain bound"] direction LR b1["cancelAllInflight()<br/>suspended"] --> b2["Release reopens admission;<br/>new request accepted"] --> b3["Stale pass cancels it<br/>and clears its tracking"] end subgraph F3["3 · Native retirement while held"] direction LR c1["MiMo or Super slot<br/>retires in the hold"] --> c2["persistLoadedModelSet()"] --> c3["loaded-models.json<br/>loses the model"] end subgraph F4["4 · Add-on socket and hold record"] direction LR d1["Silent unsigned peers"] --> d2["Fill all 8 slots;<br/>checked only per request"] --> d3["Signed add-on gets<br/>unavailable"] d4["FIFO at addon-hold.json"] --> d5["open() blocks<br/>hold restore"] end F1 ~~~ F2 ~~~ F3 ~~~ F4 classDef trigger fill:#dbeafe,stroke:#1d4ed8,color:#172554 classDef step fill:#f1f5f9,stroke:#475569,color:#0f172a classDef bad fill:#fee2e2,stroke:#b91c1c,color:#7f1d1d class a1,b1,c1,d1,d4 trigger class a2,a3,b2,c2,d2 step class a4,b3,c3,d3,d5 badAfter
flowchart TB subgraph G1["1 · Load fence"] direction LR a1["Local cold load<br/>past the load gate"] --> a2{"Hold active<br/>at next check?"} a2 -->|yes| a3["Load ends with 503;<br/>no slot installed"] --> a4["Hold waits for the gate,<br/>sweeps, then held"] a5["New load while held"] --> a6["Refused at the gate (503)"] end subgraph G2["2 · Scoped drain cancellation"] direction LR b1["Pass captures the<br/>requests it will cancel"] --> b2["Release reopens admission;<br/>new request accepted"] --> b3["Pass stops; new work keeps<br/>its task and tracking"] end subgraph G3["3 · One persistence guard"] direction LR c1["Any retirement path<br/>in the hold"] --> c2{"persistLoadedModelSet():<br/>hold active?"} c2 -->|yes| c3["Preload plan kept"] end subgraph G4["4 · Add-on socket and hold record"] direction LR d1["Peer connects"] --> d2{"Signer verified<br/>on accept?"} d2 -->|no| d3["unauthorized, closed;<br/>never takes a slot"] d2 -->|yes| d6["Slot; each line within 10 s;<br/>verified per request"] d4["FIFO at addon-hold.json"] --> d5["O_NONBLOCK + fstat:<br/>refused at once"] end G1 ~~~ G2 ~~~ G3 ~~~ G4 classDef trigger fill:#dbeafe,stroke:#1d4ed8,color:#172554 classDef check fill:#fef3c7,stroke:#b45309,color:#78350f classDef good fill:#dcfce7,stroke:#15803d,color:#14532d classDef step fill:#f1f5f9,stroke:#475569,color:#0f172a classDef refuse fill:#ede9fe,stroke:#6d28d9,color:#2e1065 class a1,a5,b1,c1,d1,d4 trigger class a2,c2,d2 check class b2 step class a3,a4,b3,c3,d6,d5 good class a6,d3 refuseLegend: blue trigger · grey step · amber check · red faulty outcome (Before) · green fixed outcome · violet intended refusal. Panels match the finding numbers.
Changes
ProviderLoop+AddonHold.swiftaddonHoldLoadRefusal; checks inProviderLoop+ModelLoading.swiftensureModelLoaded,ProviderLoop+NemotronSuper.swift,ProviderLoop+NativeMiMo.swiftrequireNativeMiMoPublication). While any hold is active no load takes the load gate; a running load stops after hashing, after the weight load or before install (Super and native MiMo before their weights and at publication) with a transientmodelLoadFailed(503). After the settle bound,unloadAllModelsForAddonHoldwaits forisLoadingAnyto clear, then sweeps again, soheldmeans no load owns memory. The settle bound became an instance value (addonHoldSettleTimeoutDefaultis the 60 s default) so tests can shorten it.cancelRequestsOutlivingAddonHoldDrain). The bound captures the coordinator requests still running, cancels them one at a time throughhandleCancellation, and stops once the hold is released or replaced.cancelAllInflight()remains the lost-connection path. A nil-in-production hook suspends the pass for the test.persistLoadedModelSet()): returns early whileaddonHoldActive, which covers the generic, native MiMo and Nemotron Super retirement paths; the generic unload's own owner check is folded into it.AddonIPCServer): the accept loop verifies the kernel audit token against the policy before reserving one of the 8 slots; an unverified peer getsunauthorizedand is closed without a read. Requests are still verified again. A request line must finish withinrequestTimeout = .seconds(10)of the server first holding it, however slowly its bytes trickle in.AddonHoldStore.read()andLifecycleMailboxreads open withO_NONBLOCK | O_NOFOLLOW; the existingfstatchecks then refuse a FIFO or other non-regular file at once.docs/threat-model.yaml(TB-012now records the operator mailbox, accept-time and per-request checks, request and idle bounds, DEBUG-onlyDARKBLOOM_ADDON_DEV_IDENTITY,DARKBLOOM_ADDON_SOCKEThonored by every build but not passed by the LaunchAgent, self-reported busy fields, the unbounded hold under a held lock and the fail-open record;T-059adds the load fence; newT-060covers socket starvation and FIFO stalls), newdocs/architecture/security/local-control.md, plusaddon-hold.md,addon-hold-ipc.md,configuration.md,inference.md(docs-impact mapping forMiMo/),test.md, andchangelog.d/provider-addon-hold-hardening.md.Interface effects: no protocol, telemetry or manifest change. Add-on clients now get
unauthorizedat connect instead of at their first request, andinvalid_requestfor a line left unfinished for 10 s. Loads refused by a hold report the existing transient 503 /capacityoutcome.Validation
All on an Apple M4 Max with the source-matched staged metallib (
scripts/stage-test-metallib.sh), Debugswift build --build-tests, isolated test state as inscripts/run-provider-tests.sh.Fail before / pass after. The 8 new tests were first run on a tree with only the behavior-neutral test seams (settle-timeout instance value, cancellation hook,
requestTimeoutparameter) and none of the fixes: 8 of 8 failed with 15 issues. With the fixes: 8 of 8 pass.TinyModelLoadTests/AddonHoldLoadFence/aLoadRunningWhenTheHoldBeginsNeverPublishesAndTheHoldWaitsForIt(real tiny-model load)AddonHoldLoopTests/theDrainBoundCancelsItsStragglersButNeverWorkAcceptedAfterAReleaseNemotronSuperManagedSlotTests/anAddonHoldRetiresTheSuperSlotButKeepsItsPreloadPlan(real managed Super slot)loaded-models.jsonlost the Super modelAddonHoldLoopTests/noRetirementPathRewritesThePreloadPlanWhileHeldAddonIPCServerTests/silentUnsignedPeersCannotTakeTheAddonsConnectionSlotsunavailableAddonIPCServerTests/anUnfinishedRequestLineIsBoundedWhileItsBytesTrickleInAddonHoldStoreTests/aFIFOAtTheRecordPathIsRefusedWithoutBlockingread()blocked until a writer appearedLifecycleMailboxTests/aFIFOInPlaceOfARequestIsIgnoredWithoutBlockingPer commit. Each WIP fix commit's tree was built on its own and its new test plus neighbouring suites run (
AddonHoldLoopTests,ModelLoadRefusalTests,TinyModelLoadTests,ProviderLifecycleTests,NemotronSuperManagedSlotTests,LoadedModelsStoreTests,LoadedModelsPersistenceWiringTests,StartupPreload*Tests,ModelSlotBookkeepingTests,AutopilotStartupPreferencesTests,AddonIPCServerTests,AddonHoldServeLoopTests,AddonIPCTests,AddonPeerPolicyTests,AddonHoldStoreTests,LifecycleMailboxTests): all pass.Add-on selector suites (the updated
docs/developer/test.mdfilter, final head): 55 tests in 13 suites pass;AddonCommandTests4 pass.make provider-test(final head):DarkbloomCLITests692 pass; every isolated suite and the exclusive native-GPU test pass. Main run: 4,780 Swift Testing tests, all passing except 3 strict-MiMo scanner tests that requireMIMO_V26_SERIAL_LOAD_FIXTURES; XCTest has 26 unexpected failures, all inMiMoV26*classes that stop at fixture lookup (fixtureRequired,payloadFixtureRequired, unsetMIMO_PROMPT_ARTIFACT_DIRECTORY). None of these touch code changed here; the private MiMo fixtures are not on this machine.Repository checks (final head):
make changelog-check(6 valid fragments),make docs-check(199 files OK),make docs-impact-check BASE=origin/master(24 changed files, coverage OK),git diff --check origin/master...HEADclean. Both figures here and the new doc diagram were rendered withmmdc.Limitations
MIMO_V26_*fixtures) was not run.drainingrather than reportingheldbeside it.TB-012/T-060.Refactor pass
A dedicated behavior-preserving pass (AGENTS.md) reviewed all 24 changed files. It made one small cleanup, the signed 8th commit
eaf9abb5d(Verified): 2 source files, with no change to behavior, contracts, tests or docs.AddonIPCServer.acceptLoop: the unverified-peer and full-server refusals duplicated a write-then-close block. It is nowrefuseUnadmitted(_:with:), so the loop reads as ordered admission checks (configure, signer, slot). The bytes, error codes and close are unchanged, and the signer check still precedes the slot.modelLoadInterruption(ProviderLoop+ModelLoading.swift): thea || b ? x : yternary became guard returns. This makes explicit that a stop or cancellation (CancellationError) wins over the hold's 503 refusal. Evaluation order is unchanged.Reviewed and deliberately left as is:
if let refusal = addonHoldLoadRefusal(…) { throw refusal }sites. A throwing twin would be a second entry point, because the install checks need the optional form to clean up before throwing, and three docs cite the name.AddonHoldStore.readvsLifecycleMailbox.read. They differ on purpose (geteuid/getuid, ENOENT →.absent, size limits, schema and lease checks) and belong to different domains, so merging them would be an unrelated rewrite.lifecycleRemaining. That property is outside this PR and also countsacceptedLifecycleRequests.requestTimeoutstatic default with its injected value, the post-settle load wait, and the test helpers, which follow the existingaddon*helper convention.Revalidated at
eaf9abb5d:swift build --build-testswith the staged metallib: OK.docs/developer/test.mdadd-on filter: 55 tests in 13 suites plus 4AddonCommandTests, all passing.AddonCommandTests|TinyModelLoadTests/AddonHoldLoadFence|NemotronSuperManagedSlotTests|LifecycleMailboxTests|AddonHoldStoreTests|AddonIPCServerTests: 70 tests in 7 suites plus 4, all passing.make changelog-check,make docs-check,make docs-impact-check BASE=origin/master(24 files, coverage OK) andgit diff --check: all clean.make provider-testwas not rerun after this commit.Need help on this PR? Tag
@codesmith-botwith what you need.