Repository navigation
Make the ingress wait configurable and add an autoscaling guide #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3005c30
feat(api): make the ingress admission wait configurable
Hazzng 7dd0269
docs: add an autoscaling guide for probes, metrics and replica count
Hazzng 3f17409
fix(api): end MCP listener streams before shutdown waits for connections
Hazzng 23cf6c8
fix(api): reject wait limits above Node's timer maximum
Hazzng a0ac855
docs: scrape every replica, state per-tenant queue limits and the new…
Hazzng 21aab70
test(verify): start one API in the shutdown check
Hazzng 224e877
test(verify): shorten the shutdown check comment
Hazzng 7979c73
Merge branch 'main' into feat/ingress-wait-autoscaling
Hazzng 289a54b
docs, test(verify): correct worker_busy and ingress shutdown scope; w…
Hazzng 64fe69c
test(verify), docs: assert a clean listener end; qualify startup vali…
Hazzng 7a2a274
docs: list the settings a 4-worker replica needs
Hazzng 8bad586
docs: describe refused connections and the effective 60 s request dea…
Hazzng fe50d5d
ci: run CI and Python SDK CI on push to main only
Hazzng 85c1fce
docs: say new connections, not new requests, fail at shutdown
Hazzng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "sql-fs-api": patch | ||
| --- | ||
|
|
||
| Add `SQL_FS_MAX_INGRESS_WAIT_MS`, the time a request or MCP listener waits for ingress capacity before it gets a 503 `EWORKER_BUSY`. The default stays 250 ms, the previous fixed value. Like the other ingress settings, an empty value uses the default. With workers on, any other invalid value, including a wait above 2147483647 ms, stops startup. `SQL_FS_WORKER_QUEUE_WAIT_MS` now rejects values above 2147483647 ms too, because Node would run such a timer after 1 ms. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "sql-fs-api": patch | ||
| --- | ||
|
|
||
| Shut down promptly when MCP clients hold a `GET /mcp` listener stream open. The server waited for those streams before it drained workers, so every such shutdown ran into the 60 s force exit and exited with code 1. It now ends listener streams first and lets in-flight MCP tool calls finish. |
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
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env node | ||
| import { once } from "node:events"; | ||
| import { join } from "node:path"; | ||
| import { performance } from "node:perf_hooks"; | ||
| import { LocalApiRun, repo } from "./local-api.mjs"; | ||
|
|
||
| const run = new LocalApiRun("shutdown"); | ||
| let failure; | ||
| try { | ||
| const server = await run.start({ SQL_FS_WORKERS_ENABLED: "true" }); | ||
| // No run.owner(): its cleanup needs a live server after this one exits. | ||
| const { signToken } = await import(join(repo, "dist/api/lib/jwt.js")); | ||
| const token = await signToken({ sub: `${run.runId}-mcp`, expiresIn: "1h", secret: process.env.AUTH_SECRET }); | ||
| const headers = { | ||
| Authorization: `Bearer ${token}`, | ||
| Accept: "application/json, text/event-stream", | ||
| "Content-Type": "application/json", | ||
| }; | ||
| const initialize = await fetch(`${server.base}/mcp`, { | ||
| method: "POST", | ||
| headers, | ||
| body: JSON.stringify({ | ||
| jsonrpc: "2.0", | ||
| id: 1, | ||
| method: "initialize", | ||
| params: { protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "shutdown-verifier", version: "1" } }, | ||
| }), | ||
| }); | ||
| await initialize.text(); | ||
| const sessionId = initialize.headers.get("mcp-session-id"); | ||
| run.equal(typeof sessionId === "string" && sessionId.length > 0, true, "MCP session opened"); | ||
| const sessionHeaders = { ...headers, "mcp-session-id": sessionId }; | ||
| const initialized = await fetch(`${server.base}/mcp`, { | ||
| method: "POST", | ||
| headers: sessionHeaders, | ||
| body: JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }), | ||
| }); | ||
| await initialized.text(); | ||
| const listener = await fetch(`${server.base}/mcp`, { | ||
| method: "GET", | ||
| headers: { ...sessionHeaders, Accept: "text/event-stream" }, | ||
| }); | ||
| run.equal(listener.status, 200, "MCP listener stream is open before SIGTERM"); | ||
| const drained = listener.body | ||
| .pipeTo(new WritableStream()) | ||
| .then(() => "ended") | ||
| .catch(() => "aborted"); | ||
|
|
||
| const started = performance.now(); | ||
| const exited = once(server.child, "close"); | ||
| server.child.kill("SIGTERM"); | ||
| const [code] = await exited; | ||
| const seconds = (performance.now() - started) / 1000; | ||
| const listenerEnd = await drained; | ||
| run.record({ case: "sigterm-with-mcp-listener", exitCode: code, seconds, listener: listenerEnd }); | ||
| run.equal(listenerEnd, "ended", "Shutdown ends the MCP listener stream cleanly"); | ||
| run.equal(code, 0, "SIGTERM with an open MCP listener exits cleanly"); | ||
| run.equal(seconds < 10, true, "SIGTERM with an open MCP listener does not wait for the force-exit timer"); | ||
| run.equal(server.log.includes('"event":"shutdown_complete"'), true, "Shutdown logs shutdown_complete"); | ||
| run.equal(server.log.includes('"event":"shutdown_force_exit"'), false, "Shutdown does not force-exit"); | ||
| } catch (error) { | ||
| failure = error; | ||
| } finally { | ||
| await run.finish(failure); | ||
| } | ||
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.