Skip to content

Make the ingress wait configurable and add an autoscaling guide - #270

Merged
Hazzng merged 14 commits into
mainfrom
feat/ingress-wait-autoscaling
Oct 17, 2026
Merged

Hazzng merged 14 commits into
mainfrom
feat/ingress-wait-autoscaling

Conversation

@Hazzng

@Hazzng Hazzng commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #268. Review and merge #268 first. This PR's base is feat/workers-default-231.

What changes

  • New setting SQL_FS_MAX_INGRESS_WAIT_MS. It sets how long a request or MCP listener waits for ingress capacity before it gets a 503 EWORKER_BUSY. Before, the wait was a hard-coded 250 ms. The default stays 250 ms, so nothing changes unless an operator sets it. It is read the same way as the other SQL_FS_MAX_INGRESS_* settings.
  • New guide: docs/AUTOSCALING.md.
    • The /healthz, /readyz and /metrics endpoints, and how a scraper authenticates to /metrics.
    • A reference for every metric /metrics emits. The names were captured from a running server's /metrics output and checked against metrics.ts.
    • Signals to scale on, ranked: the refusal rate first, then queue depth and the worker wait p95 as early warnings, then CPU and RSS. Each comes with example PromQL. The guide explains why the wait histogram tops out at the wait limit and misses refused requests.
    • What adding replicas does not fix: waits on one sandbox, locks and recovery, and the per-tenant limit on concurrent execs.
    • Measured capacity on a 2 GiB replica, and a rule of thumb for replica count.
    • Shutdown behavior: a SIGTERM closes ingress at once, running worker operations get 30 s, and the process force-exits at 60 s.
    • An Azure Container Apps example matching deploy/azure/aca.yaml.
  • Updated docs. docs/CONFIGURATION.md gets the new row and names both wait settings, and the autoscaling list there now points to the new guide. README.md and AGENTS.md link to it.

Why the default stays 250 ms

We planned a 1000 ms default, then measured it. One replica with 2 GiB of memory and 2 CPUs, and clients that waited 1 s after each 503 as Retry-After: 1 asks:

Load 250 ms 1000 ms
100 agents start at once, 10 tenants 83 refusals 83 refusals
One tenant, about 100 execs/s offered, three runs: refusals 317, 385, 395 403, 479, 414
The same runs: p99 latency 123, 151, 174 ms 246, 283, 173 ms

The ingress queue holds no more requests than ingress admits at once (maxQueued: options.maxRequests, 8 per replica and 4 per tenant). A longer wait therefore cannot absorb a burst: everything beyond those 8 is refused at once. #269 tracks a deeper ingress queue. The guide's "Wait limits" section has the table.

Notes for reviewers

  • deploy/azure/aca.yaml is unchanged. The guide explains that its scale rule of 50 concurrent requests per replica fires long after 503s begin, because one replica admits 8. Fixing the file is left for a separate change.
  • Neither shutdown limit (30 s and 60 s) can be configured, while a script can run for 120 s by default. The guide tells operators to set a termination grace period above 60 s.
  • The Container Apps YAML and the PromQL examples have not been run against a real platform or Prometheus.

Tests

  • A request and an MCP listener queued with SQL_FS_MAX_INGRESS_WAIT_MS=40 are still queued at 39 ms. At 40 ms each gets a 503 EWORKER_BUSY with Retry-After: 1. These tests fail if either gate ignores the setting.
  • The default is 250 ms even when SQL_FS_WORKER_QUEUE_WAIT_MS is 900. An explicit value wins.
  • Invalid values, such as 0, -1, 1.5 and NaN, stop startup.

Verification

  • pnpm check passed: 2332 and 154 tests.
  • pnpm verify:local passed: contracts 94, output-cap 26, integration 265 (none skipped), SDK clients 102.

Summary by cubic

Adds SQL_FS_MAX_INGRESS_WAIT_MS to control how long a request or MCP listener waits for ingress capacity before a 503 EWORKER_BUSY, fixes shutdown hanging on open MCP listener streams, and adds an autoscaling guide. The default stays the previous hard-coded 250 ms; measurements showed a longer wait cannot absorb bursts because the ingress queue caps at 8 requests per replica.

  • Shutdown now ends GET /mcp listener streams first, so a client holding one open no longer blocks the drain until the 60 s force exit. In-flight MCP tool calls still finish, and terminating replicas refuse new connections. The new scripts/verify/shutdown.mjs asserts that SIGTERM with a listener open ends the stream cleanly and exits before the force-exit timer, and scripts/verify-local.sh runs it.
  • Both SQL_FS_MAX_INGRESS_WAIT_MS and SQL_FS_WORKER_QUEUE_WAIT_MS now reject values above 2147483647 ms, which Node's timer would otherwise run after 1 ms. Invalid values such as 0, -1, 1.5 and NaN already stopped startup.
  • docs/AUTOSCALING.md is new and covers health and metrics endpoints, every exported metric, ranked scaling signals with example PromQL, measured single-replica capacity, shutdown draining, and an Azure Container Apps scale rule. It also lists the settings a replica needs when running 4 workers. docs/CONFIGURATION.md, README.md, and AGENTS.md link to it, and docs/CONFIGURATION.md adds the setting row.
  • CI and Python SDK CI now run on push to main only; the old branch push patterns ran each workflow twice per push.

Written for commit 85c1fce. Summary will update on new commits.

View guided diff Turn on auto-fix

SQL_FS_MAX_INGRESS_WAIT_MS sets how long a request or MCP listener waits
for an ingress permit before a 503 EWORKER_BUSY. The default rises from
250 ms to 1000 ms: a refused request is told to retry after 1 s, so
refusing a burst sooner only sends the client to the back of the line.
The worker queue wait keeps its 250 ms default.
AUTOSCALING.md documents /healthz, /readyz and /metrics, every metric
the server emits, the signals to scale on in priority order, what more
replicas do not fix, measured single-replica capacity, shutdown
draining, the two wait limits, and an Azure Container Apps scale rule.
CONFIGURATION.md gains SQL_FS_MAX_INGRESS_WAIT_MS and points its
autoscaling notes at the new guide.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 768d9908-4276-4273-b46c-9c45dfc1b83d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Hazzng
Hazzng added this pull request to stack #271 October 17, 2026 02:11
Base automatically changed from feat/workers-default-231 to main October 17, 2026 02:11

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files

You’re at about 90% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/AUTOSCALING.md Outdated
Comment thread docs/AUTOSCALING.md Outdated
Comment thread src/api/ingress-admission.ts Outdated
Comment thread src/api/ingress-admission.ts Outdated
Comment thread docs/AUTOSCALING.md Outdated
@Hazzng

Hazzng commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@Hazzng

Hazzng commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T02:34:58.197276Z 289a54b Manual request
🔒 Security Review ✅ Completed 2026-10-17T02:21:24.848070Z 7dd0269 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

server.close() waited on every open connection before shutdownMcp() ran, so a
client holding a GET /mcp listener stream blocked the worker drain until the
60 s force exit. Shutdown now ends standalone listener streams first and leaves
in-flight tool calls to finish.
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7dd026948a

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7dd026948a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/api/ingress-admission.ts Outdated
@Hazzng

Hazzng commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0ac855ee2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/verify/shutdown.mjs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/AUTOSCALING.md Outdated
Comment thread docs/AUTOSCALING.md Outdated
Comment thread scripts/verify/shutdown.mjs Outdated
@Hazzng

Hazzng commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/verify/shutdown.mjs
Comment thread .changeset/ingress-wait.md Outdated
Comment thread docs/AUTOSCALING.md Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/AUTOSCALING.md Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 289a54b603

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/AUTOSCALING.md
Comment thread docs/AUTOSCALING.md Outdated
PR branches matching the push patterns ran each workflow twice per push, once
for push and once for pull_request. The pull_request run still reports every
required check.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

You’re at about 92% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Tip: Review your code locally with the cubic CLI to iterate faster.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/AUTOSCALING.md Outdated
@Hazzng
Hazzng merged commit e9cf495 into main Oct 17, 2026
16 checks passed
@Hazzng
Hazzng deleted the feat/ingress-wait-autoscaling branch October 17, 2026 04:27
@Hazzng Hazzng mentioned this pull request Oct 17, 2026
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.

1 participant