Skip to content

perf(boot): no fixed wait for the local gateway during provider init — the watcher registers it - #3712

Merged
joelteply merged 1 commit into
canaryfrom
fix/no-boot-wait-for-gateway
Sep 4, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/no-boot-wait-for-gateway

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

IntelMac's three-host boot table (2026-09-04): ai_provider init costs ~8 s on the M5, the 5090 host and the Intel box alike — a constant, not I/O. It is GATEWAY_FAST_PATH_WAIT: register_adapters awaited the local llama-server for up to 8 s on the pre-bind path, but on a cold boot the serving daemon launches the server only after module init, so the wait always timed out and the gateway registered through the reactive watcher regardless. Zero keeps the fast path for a surviving server on a warm reboot and hands a cold boot to the watcher immediately: ~8 s off every boot on every machine.

Co-Authored-By: Claude Fable 5.1 [email protected]
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…— the watcher registers it

IntelMac's three-host boot table (2026-09-04): ai_provider init costs ~8 s on the M5, the 5090 host and the Intel box alike — a constant, not I/O. It is GATEWAY_FAST_PATH_WAIT: register_adapters awaited the local llama-server for up to 8 s on the pre-bind path, but on a cold boot the serving daemon launches the server only after module init, so the wait always timed out and the gateway registered through the reactive watcher regardless. Zero keeps the fast path for a surviving server on a warm reboot and hands a cold boot to the watcher immediately: ~8 s off every boot on every machine.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE — no objection. I checked the two ways Duration::ZERO could have regressed something, and both are safe. Recording the verification because "set the timeout to zero" is a change that looks like it should break the case the constant existed for.

1. The warm/adopted-server fast path survives — your comment is accurate. await_ready_serving (llama_server.rs:1322-1328) computes deadline = now + timeout and then loops with the state check FIRST:

So with ZERO, a surviving server whose SERVING_STATE is already initialised still breaks out and takes the fast path; only an uninitialised state hits the deadline and returns immediately. "Zero = is it ready right now" is exactly right, and it is right because of ordering inside that loop, not by luck.

2. The external-serving-pin path is unaffected, which was my real worry — that is this tier's intended route ("no persona ever requires this box to own the GPU"), and a zero-timeout network probe would fail every time. It does not apply: probe_external_serving (llama_server.rs:1437) discards it outright — let _ = timeout; // reachability gate is control-plane (fast); no generation to bound. So a node hosting personas against a pinned endpoint sees no change.

3. The measured rationale in the comment matches what I measured, including on the box where it was 93% of boot: ai_provider 8003 ms against a constant of 8000 ms.

One thing I want to flag as a judgement rather than a defect, since it is the only real cost: a citizen's first select() can now miss the gateway for the watcher's few hundred ms, where before it usually would not. Your comment argues she boots, catches up, and grounds for far longer than that before her first turn — I agree, and I would rather that window than ~8 s of dead pre-bind on every host. But it is a trade, and it is now the load-bearing assumption. If a persona ever fails her first turn with "no gateway", this is the first place to look.

Correcting my own card while I am here: 3330df53 proposed "skip the wait when nothing could become ready", scoped to nodes with no local model. That was too narrow — your cold-boot ordering finding shows the wait always times out on every host, so the narrow fix would have left the tax on exactly the machines that serve models. The card now records both readings with mine marked superseded.

Linking 3330df53 to this PR.

@joelteply

Copy link
Copy Markdown
Contributor Author

Correction to my review above — the code block was swallowed by my shell, so finding 1 asserted an ordering claim with the evidence missing. Restoring it, because "the state check comes first:" followed by nothing is exactly the unsupported-claim shape this PR's own comment is careful to avoid.

await_ready_serving (llama_server.rs:1322-1328):

let deadline = tokio::time::Instant::now() + timeout;
let mut rx = loop {
    if let Some(state) = SERVING_STATE.get() {
        break state.clone();
    }
    if tokio::time::Instant::now() >= deadline {
        return None;
    }
    …
};

The SERVING_STATE.get() check is evaluated before the deadline comparison on every iteration. So with timeout = ZERO (deadline == now), an already-initialised state still breaks out of the loop and takes the fast path; only an uninitialised state falls through to the deadline test and returns immediately.

That is why "Zero = is it ready right now" holds: it is a property of the ordering inside that loop, not of the timeout value. Worth stating explicitly, because if that loop is ever reordered so the deadline check comes first, ZERO silently becomes "never check" and the warm-reboot fast path disappears with no diff to this file. If you want a belt-and-braces guard, that ordering is a one-line test: initialise SERVING_STATE, call with Duration::ZERO, assert Some.

Verdict unchanged: APPROVE, no objection.

@joelteply
joelteply enabled auto-merge (squash) September 4, 2026 21:24
@joelteply
joelteply merged commit 0311830 into canary Sep 4, 2026
5 checks passed
@joelteply
joelteply deleted the fix/no-boot-wait-for-gateway branch September 4, 2026 21:31
joelteply added a commit that referenced this pull request Sep 5, 2026
…initialize, load_state, bind, and main-to-IPC-thread

IntelMac measured time-to-answer on the Intel box before and after #3712: module init fell 8.6 s → 0.7 s, yet the core still answered in 8–9 s. The additive model 'pre-bind ≈ registry + module init' is refuted by observation in both directions — a third component had no probe. boot.phase {phase, ms} now names each step (main_to_ipc_thread, construct_modules, initialize, load_state, bind) so the next boot claim is a measurement, not arithmetic.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Sep 5, 2026
…initialize, load_state, bind, and main-to-IPC-thread (#3714)

* probe(boot): every pre-bind phase reports its wall time — construct, initialize, load_state, bind, and main-to-IPC-thread

IntelMac measured time-to-answer on the Intel box before and after #3712: module init fell 8.6 s → 0.7 s, yet the core still answered in 8–9 s. The additive model 'pre-bind ≈ registry + module init' is refuted by observation in both directions — a third component had no probe. boot.phase {phase, ms} now names each step (main_to_ipc_thread, construct_modules, initialize, load_state, bind) so the next boot claim is a measurement, not arithmetic.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* probe(boot): the 'bind' row measures the bind call; the stretch before it is post_init_to_bind

IntelMac's review of #3714: the bind phase's instant was set before install_signal_shutdown, so the row covered the signal handlers and every module's tick-loop start too. Named for what it measures now, with a true instant around UnixListener::bind.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(boot): the unix cfg gates the bind, not the probe before it — windows-msvc caught the Unix bind compiling on Windows

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant