Compare commits

...

208 Commits

Author SHA1 Message Date
dependabot[bot]
b2df4f2848 chore(deps): bump actions/setup-node from 7.0.0 to 7.1.0
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 7.0.0 to 7.1.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v7...949feb2413d6458794dcd2491c4babbbce0c15c1)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: 7.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-11-21 09:43:48 +00:00
Diego Rodrigues de Sa e Souza
93d0cbc243 Merge pull request #20650 from cheaper-inference/fix/qg-release-acceptance-live-20261119
fix(ci): bind shadow acceptance to the real checkout
2026-11-21 06:41:11 -03:00
Diego Rodrigues de Sa e Souza
3f6c13948e Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-21 05:14:31 -03:00
Diego Rodrigues de Sa e Souza
5c3ef759c3 Merge pull request #20870 from cheaper-inference/fix/merge-train-e1b-20261121
chore(release): contributor train e1b of 21 PRs for v3.8.55 (2026-11-21)
2026-11-21 05:12:06 -03:00
Diego Rodrigues de Sa e Souza
113601cb13 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-21 04:02:52 -03:00
Diego Rodrigues de Sa e Souza
a78e2a87cc Merge pull request #20749 from cheaper-inference/fix/qg-mcp-a2a-toggle-readiness-20261120
test(ui): synchronize MCP and A2A toggle fixtures
2026-11-21 04:02:05 -03:00
diegosouzapw
8414b3ad03 Merge #20088 (head 68b07075) into contributor train e1b 2026-11-21 03:46:44 -03:00
diegosouzapw
8e8c9ea23f Merge #20078 (head 0a94768e) into contributor train e1b 2026-11-21 03:46:43 -03:00
diegosouzapw
7ed80d6a59 Merge #19950 (head 00f2a34c) into contributor train e1b 2026-11-21 03:46:42 -03:00
diegosouzapw
3e63be6cb8 Merge #19949 (head 768b4aea) into contributor train e1b 2026-11-21 03:46:40 -03:00
diegosouzapw
3cfb61b269 Merge #19948 (head 1907e831) into contributor train e1b 2026-11-21 03:46:39 -03:00
diegosouzapw
09a94f4e6f Merge #19876 (head b871c074) into contributor train e1b 2026-11-21 03:46:37 -03:00
diegosouzapw
360ec203f8 Merge #19867 (head 9983d081) into contributor train e1b 2026-11-21 03:46:36 -03:00
diegosouzapw
141ed1b6d5 Merge #19763 (head f4eae213) into contributor train e1b 2026-11-21 03:46:35 -03:00
diegosouzapw
2a8d2d520f Merge #19750 (head 668c18fe) into contributor train e1b 2026-11-21 03:46:34 -03:00
diegosouzapw
1a30d83faf Merge #19724 (head 610fbaac) into contributor train e1b 2026-11-21 03:46:32 -03:00
diegosouzapw
1a19467176 Merge #19680 (head d1fa6a36) into contributor train e1b 2026-11-21 03:46:31 -03:00
diegosouzapw
8d030a8bd5 Merge #19678 (head a9b7506a) into contributor train e1b 2026-11-21 03:46:29 -03:00
diegosouzapw
17a0647e93 Merge #19670 (head efd935b2) into contributor train e1b 2026-11-21 03:46:26 -03:00
diegosouzapw
9103f74912 Merge #19669 (head d720f0e6) into contributor train e1b 2026-11-21 03:46:25 -03:00
diegosouzapw
f2aa022ed9 Merge #19667 (head 75535a76) into contributor train e1b 2026-11-21 03:46:23 -03:00
diegosouzapw
60383f4fa5 Merge #19592 (head fc4b408e) into contributor train e1b 2026-11-21 03:46:20 -03:00
diegosouzapw
5464f83a07 Merge #19583 (head 213be12d) into contributor train e1b 2026-11-21 03:46:19 -03:00
diegosouzapw
f381a8876a Merge #18738 (head 01781da0) into contributor train e1b 2026-11-21 03:46:17 -03:00
diegosouzapw
f65c9cceb0 Merge #18674 (head 9aa9b274) into contributor train e1b 2026-11-21 03:46:17 -03:00
diegosouzapw
bc7007b913 Merge #18626 (head 41c6c724) into contributor train e1b 2026-11-21 03:46:15 -03:00
diegosouzapw
7c5ea2388d Merge #18544 (head 039bfcf2) into contributor train e1b 2026-11-21 03:46:14 -03:00
Diego Rodrigues de Sa e Souza
b87bf33013 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-21 02:47:00 -03:00
Diego Rodrigues de Sa e Souza
913f200b34 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-21 02:46:59 -03:00
Diego Rodrigues de Sa e Souza
1771948e1a feat(ci): omni-queue owner voice and signed merge commits (both off) (#20792)
* feat(ci): omni-queue owner voice and signed merge commits, both off

Owner voice (config `voice`, default "app"): with "owner", the queue's
comments and label removals on pull requests, the dashboard issue and its
comments, base-red comments and the tree-divergence issue go out with
OMNI_QUEUE_LAND_TOKEN (scripts/merge-queue/voice.mjs). Reads, commit
statuses, refs, the state branch and re-runs stay the App's. A missing
token or a 401/403 retries the same write with the App's token and records
one error event per tick. commentOnce trusts markers by the App or by the
owner's login read from the token itself (GET /user).

Signed merge commits (config landing.signing, default "none"): with "ssh"
and landing.actor "owner", composeCandidate signs every merge commit with
the key the tick job writes from the OMNI_QUEUE_SIGNING_KEY secret to a
0600 file under RUNNER_TEMP (removed by an always() step). git gets the
path as per-command configuration through the environment. A missing key
or a failed signature composes unsigned and records one error event per
batch.

The shipped config keeps both off and mode shadow.

* docs(changelog): add the fragment for the omni-queue owner voice and signed merges (#20792)

* test(ci): compare the signed commit's committer by prefix, not a built regex (#20792)
2026-11-21 02:39:36 -03:00
Diego Rodrigues de Sa e Souza
e07bc35c4c Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-21 02:39:27 -03:00
Diego Rodrigues de Sa e Souza
f7b9c46a54 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-21 02:39:26 -03:00
Diego Rodrigues de Sa e Souza
59e3965a8a test(ci): audit only git-tracked files for retired provider asset references (#20827)
The retired-asset audit in provider-assets-generic-fallback.test.mjs walked the
working tree at module load and read every text file whole. In the omni-queue
base check, "Fast Quality Gates" builds config/quality/test-impact-map.json
(gitignored, ~556 MB on release/v3.8.55) before running the whole unit suite,
and readFile(path, "utf8") on it threw "RangeError: Invalid string length"
(run 44795004759).

The audit now lists files with git ls-files (same scope rules; the old walk
stays as the fallback for a tree without git metadata), reads each file with a
64 MiB bound, and reports oversized or unreadable files by name instead of
aborting. A regression test builds a temporary git repository with an
untracked 600 MB sparse file in a walked directory.
2026-11-21 02:32:46 -03:00
Diego Rodrigues de Sa e Souza
6204e4082d Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-21 01:19:00 -03:00
Diego Rodrigues de Sa e Souza
0c85b5c548 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-21 01:19:00 -03:00
Diego Rodrigues de Sa e Souza
76b26b8ead Merge pull request #20824 from cheaper-inference/fix/codeql-media-poll-clamp
fix(security): clamp media polling and guard syntx provider rules (CodeQL #1389, #1392)
2026-11-21 00:58:11 -03:00
Diego Rodrigues de Sa e Souza
c8688bcd69 Merge pull request #20820 from cheaper-inference/fix/admission-bypass-process-secret
fix(security): require the per-process token for the internal admission bypass
2026-11-21 00:57:59 -03:00
Diego Rodrigues de Sa e Souza
59bf5d718f Merge pull request #20819 from cheaper-inference/fix/codeql-operator-only-path-roots
fix(security): operator-only credential and denied roots for corpus and vault paths (CodeQL #1371, #1372, #1373)
2026-11-21 00:57:48 -03:00
Diego Rodrigues de Sa e Souza
78a20f38dc Merge pull request #20776 from cheaper-inference/fix/subscription-quota-400-status-gate
fix(security): gate subscription quota text on HTTP 400 behind a structured code
2026-11-21 00:57:36 -03:00
Diego Rodrigues de Sa e Souza
8736b8e086 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-21 00:35:38 -03:00
Diego Rodrigues de Sa e Souza
46d97cae33 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-21 00:35:37 -03:00
Diego Rodrigues de Sa e Souza
0f5237563c Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 23:01:57 -03:00
Diego Rodrigues de Sa e Souza
8399632bb5 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 21:30:12 -03:00
Diego Rodrigues de Sa e Souza
fe56151a82 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 21:29:28 -03:00
Diego Rodrigues de Sa e Souza
ee1c974f45 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 20:09:12 -03:00
Diego Rodrigues de Sa e Souza
42573d7883 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 19:24:25 -03:00
diegosouzapw
d7727a7e99 Merge remote-tracking branch 'origin/release/v3.8.55' into fix/subscription-quota-400-status-gate 2026-11-20 18:47:10 -03:00
diegosouzapw
4625936608 chore(changelog): number the media polling fragment for #20824 2026-11-20 18:32:15 -03:00
diegosouzapw
c28fec4e9f chore(changelog): name the fragment after PR #20820 2026-11-20 18:23:37 -03:00
diegosouzapw
0d56007238 fix(security): clamp media polling and guard syntx provider rules (CodeQL #1389, #1392)
Caller-supplied poll_interval_ms, timeout_ms and poll_timeout_ms on the
NanoBanana, Magnific, Black Forest Labs and RenderHour image handlers are
clamped (30 s interval, 10 min window) by a shared helper that never
shortens a default. The RenderHour poller passes the request abort signal
to sleep(). applySyntxProviderRules only runs own entries of the rules
table.
2026-11-20 18:22:31 -03:00
diegosouzapw
035b02bcd1 chore(changelog): number the fragment for #20819 2026-11-20 18:12:44 -03:00
diegosouzapw
380b6a7786 fix(security): operator-only credential and denied roots for corpus and vault paths (CodeQL #1371, #1372, #1373)
POST /api/settings/local-corpus (rootPath) and POST /api/settings/obsidian/webdav
(vaultPath) now require an operator credential (dashboard session or local CLI) through
requireOperatorCredential; API keys of any scope and access tokens get 403. The webdav
route passes alwaysRequireAuth because /api/settings/obsidian is ALWAYS_PROTECTED.

Both roots also refuse the filesystem root, the home directory itself and the system
directories /etc /usr /bin /sbin /var /proc /sys /dev /boot /root (and below), compared
after path.resolve and realpath, with a fixed 400 message. The vault keeps its DATA_DIR
overlap refusal.
2026-11-20 18:05:40 -03:00
diegosouzapw
eec0dbba04 fix(security): require the per-process token for the internal admission bypass
isInternalAdmissionBypass() accepted the bypass header together with a
bearer equal to resolveSelfLoopBearer(), which is the deployment env key
when one is configured. That key is an ordinary API key clients hold, so
it proved nothing about where a request came from.

Apply the rule from #19292: only the per-process self-hop token (held in
memory on globalThis, compared in constant time) grants the bypass and
the internal upstream-start cap. The vision bridge describe call, the
only caller that sends the bypass header, now also sends the token; it
only does so for this process's own listener.
2026-11-20 17:35:35 -03:00
Diego Rodrigues de Sa e Souza
03bef29916 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 11:10:21 -03:00
Diego Rodrigues de Sa e Souza
d5b9af42f2 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 11:10:20 -03:00
diegosouzapw
667e8bf086 chore(changelog): name the fragment after #20776 2026-11-20 10:26:33 -03:00
diegosouzapw
763fa9896d fix(security): gate subscription quota text on HTTP 400 behind a structured code
Apply the #20567 status contract to the subscription/plan quota text
signals ("usage limit reached", "plan limit", weekly/session usage
limits). On a 400 such a phrase now counts only with a structured
credit/quota code or for the message-only allow-listed providers
(command-code, bai, openai-compatible-*), so a phrase repeated from the
request no longer classifies as QUOTA_EXHAUSTED or puts a shared LLM or
search connection on hold. 429, 403 and every other status are
unchanged.

The status rule is extracted from isCreditsExhaustedForStatus into
quotaTextSignalCountsForStatus and reused by the classifier, the
fallback engine and the search cooldown.
2026-11-20 10:22:56 -03:00
Diego Rodrigues de Sa e Souza
8b6d316fa2 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 08:57:25 -03:00
Diego Rodrigues de Sa e Souza
26f2b46a09 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 08:57:25 -03:00
Diego Rodrigues de Sa e Souza
372c5bddd0 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 07:31:43 -03:00
Diego Rodrigues de Sa e Souza
58d5456411 Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 07:31:43 -03:00
Diego Rodrigues de Sa e Souza
6d03588cb9 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 06:10:16 -03:00
Diego Rodrigues de Sa e Souza
0c64e2aa0c Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 06:10:15 -03:00
Diego Rodrigues de Sa e Souza
bb417eb1fb Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 04:53:50 -03:00
Diego Rodrigues de Sa e Souza
15a524d68f Merge branch 'release/v3.8.55' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 04:53:49 -03:00
Diego Rodrigues de Sa e Souza
6e9f26d725 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 03:28:52 -03:00
diegosouzapw
850f8e42d4 Merge commit '6a5dadd172195d2e1b39c6904f8f12af32192c91' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 03:27:36 -03:00
diegosouzapw
e8e2af304a Merge commit '4624250231f49ed118fb4522a9d735e4894322c6' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 02:22:53 -03:00
Diego Rodrigues de Sa e Souza
981285b1eb Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 01:57:14 -03:00
diegosouzapw
17293dfef7 Merge commit 'bd9b1324abb82f0e00066f631b6dd7744e5d975a' into fix/qg-mcp-a2a-toggle-readiness-20261120 2026-11-20 01:31:15 -03:00
Bl0ck154
01781da04c chore(upstream): reconcile Terra catalog with current release branch
Additive merge of cheaper-inference/OmniRoute release/v3.8.55; retain upstream's equivalent VS Code Terra effort recognition and keep provider catalog changes focused. Upstream's existing translated-doc whitespace is outside the PR delta.
2026-11-20 06:13:15 +02:00
diegosouzapw
480c40c98e test(ui): synchronize MCP and A2A toggle fixtures 2026-11-20 00:37:15 -03:00
Diego Rodrigues de Sa e Souza
6e82b457ed Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-20 00:04:35 -03:00
Diego Rodrigues de Sa e Souza
f64643f540 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 23:14:20 -03:00
Diego Rodrigues de Sa e Souza
07024bc8ae Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 20:30:10 -03:00
Diego Rodrigues de Sa e Souza
673b7b7920 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 18:56:30 -03:00
Diego Rodrigues de Sa e Souza
ed369ab631 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 17:06:49 -03:00
Diego Rodrigues de Sa e Souza
f463a50c92 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 15:25:03 -03:00
Diego Rodrigues de Sa e Souza
660abd192e Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 14:41:48 -03:00
Diego Rodrigues de Sa e Souza
da6ebce463 Merge branch 'release/v3.8.55' into fix/qg-release-acceptance-live-20261119 2026-11-19 13:06:33 -03:00
diegosouzapw
c99b06a882 fix(ci): bind shadow acceptance to the real checkout 2026-11-19 11:23:08 -03:00
Praveen K Palaniswamy
9aa9b27457 test(images): import the combos module before the first Leonardo edit test
check:test-tla-order rejected the top-level await placed between test() calls:
under --test-force-exit the later tests can silently never run (#18045). Move
the combos.ts import up with the other top-level imports.
2026-11-19 08:20:50 -03:00
diegosouzapw
5dbfad9be4 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 08:08:53 -03:00
diegosouzapw
668c18fed3 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 07:30:40 -03:00
sdfsdfw2
0a94768e38 style(dashboard): apply prettier to the banned keywords card and its test 2026-11-19 07:26:46 -03:00
diegosouzapw
7cdaaddf62 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 07:17:26 -03:00
diegosouzapw
213be12dfa Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 06:06:47 -03:00
diegosouzapw
039bfcf2b1 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 05:32:55 -03:00
diegosouzapw
41c6c72406 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 05:19:19 -03:00
diegosouzapw
efd935b29c Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 03:30:24 -03:00
Bl0ck154
75535a76a5 style(tests): restore Prettier 3.9 formatting of image route imports 2026-11-19 02:41:17 -03:00
diegosouzapw
941ae91f12 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 02:25:04 -03:00
xiaoyaner0201
d720f0e6d8 fix(db): read, merge and write a reasoning rule update in one tick
update() awaited findById() between reading the row and running the
UPDATE, so two overlapping updates of the same rule could both read the
same base row and the second write dropped the first caller's fields.
Read the row synchronously so the read, merge, reference check and write
cannot interleave.
2026-11-19 01:53:45 -03:00
diegosouzapw
8d1f89789a Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-19 01:46:17 -03:00
serenity
610fbaac81 fix(security): budget the encoded-injection decode in bytes, not candidates
A count of 64 candidates let short decoy hex runs placed first use up the
budget, so a base64-encoded instruction after them was never decoded.
Budget decoded bytes instead, sized above what the 16 KB scan text can
produce over both layers, so no candidate is skipped. Covered by a
failing-then-passing decoy test plus a cost test for a text packed with
readable encoded runs.
2026-11-18 22:34:52 -03:00
diegosouzapw
b5ab2b23b3 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-18 22:17:44 -03:00
ggdayup
68b0707532 fix(pricing): price Vertex Gemini 3 Flash, 2.5 Pro and 2.5 Flash Lite at their own rates
The new vertex default rows copied Pro rates onto gemini-3-flash-preview
($2/$12 instead of $0.50/$3), used a flat $2/$12 for gemini-2.5-pro
(Google bills $1.25/$10 up to 200K prompt tokens and $2.50/$15 above),
and set the 2.5 Flash Lite cached-input rate to $0.025 instead of $0.01.
Add the long_context tier for 2.5 Pro and a test that pins the rows.
2026-11-18 18:27:16 -03:00
diegosouzapw
6609bd451c Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD 2026-11-18 18:16:58 -03:00
Safeer Ahmad
b871c0747d style(antigravity): format the conversation session-id test with Prettier 2026-11-18 14:19:11 -03:00
diegosouzapw
b36604bf08 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD
# Conflicts:
#	open-sse/handlers/chatCore.ts
2026-11-18 14:07:32 -03:00
Bl0ck154
ff254bf503 chore(upstream): integrate current v3.8.55 security fixes for PR #19667 2026-11-18 19:04:23 +02:00
diegosouzapw
a9b7506a16 Merge remote-tracking branch 'origin/release/v3.8.55' into HEAD
# Conflicts:
#	package-lock.json
#	package.json
2026-11-18 13:09:44 -03:00
bufftop25
f4eae2131b fix(auth): maintain OAuth tokens for inactive connections during background health check 2026-11-18 08:29:28 -03:00
serenity
51a6de526c refactor(shared): split provider index build and encoded-layer decode into helpers 2026-11-17 19:34:50 +03:30
serenity
cea9cc1a8a Merge release/v3.8.55 into this branch 2026-11-17 19:30:20 +03:30
Bl0ck154
9fa9d49c2a refactor(codex-images): isolate bounded edit reference resolution helpers
Reduce PR #19667 new-code complexity without changing 16/128 input eligibility, serial SSRF-pinned fetching, the shared 20 MiB budget, cancellation, or request-shape errors. Keep the exact existing regression suite.
2026-11-17 11:46:42 +02:00
Bl0ck154
9983d081b7 chore(upstream): sync PR #19867 with active release/v3.8.55 2026-11-17 11:32:29 +02:00
Bl0ck154
1907e8310f chore(upstream): sync PR #19948 with active release/v3.8.55 2026-11-17 11:32:17 +02:00
Bl0ck154
768b4aea86 chore(upstream): sync PR #19949 with active release/v3.8.55 2026-11-17 11:32:06 +02:00
Bl0ck154
00f2a34c61 chore(upstream): sync PR #19950 with active release/v3.8.55 2026-11-17 11:31:56 +02:00
Bl0ck154
d1fa6a3611 chore(upstream): sync PR #19680 with active release/v3.8.55 2026-11-17 11:30:38 +02:00
Bl0ck154
363219832e chore(upstream): sync PR #19667 with active release/v3.8.55 2026-11-17 11:28:43 +02:00
Bl0ck154
d59f97cb66 chore(upstream): sync PR #18738 with active release/v3.8.55 2026-11-17 11:26:55 +02:00
Bl0ck154
fc4b408ef7 chore(upstream): sync PR #19592 with active release/v3.8.55 2026-11-17 11:26:45 +02:00
Praveen K Palaniswamy
36ed4d7e3a Merge remote-tracking branch 'upstream/release/v3.8.55' into feat/leonardo-image-edits
# Conflicts:
#	src/app/api/v1/images/edits/route.ts
2026-11-16 21:09:08 -05:00
Tomas Fecko
7ab0e30474 Merge release/v3.8.54 into feat/expiry-first-deadline-order
Conflict in src/sse/services/auth.ts (imports only): keep isExpiryFirstDeadlineOrder
from this branch and isWorkspacePolicyBudget429 from #19314.

expiry-first-combo-ordering case 8 (#17829) pinned the old reading of a lapsed
reset as maximally urgent. With this PR a lapsed weekly reset counts as a refilled
window rolled forward one period, so the expected score is 1/167 instead of 3.2.
2026-11-16 10:59:00 +01:00
Bl0ck154
d3fed13791 chore: reconcile Codex plan header PR with current release 2026-11-16 09:14:57 +02:00
Bl0ck154
22c5dfb464 merge(release): refresh PR #19680 on current upstream baseline 2026-11-16 09:14:37 +02:00
diegosouzapw
c495b920e9 chore: drop derived values the release refresh now owns
Plan 2026-11-13 (derived numbers resolved only at release): feature PRs no longer write values
that depend on the state of the base. This commit restores the lines this PR changed only to
update such values (counts in docs, the llm.txt mirrors, the Stryker test list, the package
description, counts in agent-instruction files) to the text of the PR's merge base, so merging
the current base brings the values `npm run release:refresh-derived` maintains. Every other
change of the PR is untouched.
2026-11-15 05:14:16 -03:00
diegosouzapw
a52f213ab7 chore: drop derived values the release refresh now owns
Plan 2026-11-13 (derived numbers resolved only at release): feature PRs no longer write values
that depend on the state of the base. This commit restores the lines this PR changed only to
update such values (counts in docs, the llm.txt mirrors, the Stryker test list, the package
description, counts in agent-instruction files) to the text of the PR's merge base, so merging
the current base brings the values `npm run release:refresh-derived` maintains. Every other
change of the PR is untouched.
2026-11-15 05:14:00 -03:00
diegosouzapw
db6313add2 chore: drop derived values the release refresh now owns
Plan 2026-11-13 (derived numbers resolved only at release): feature PRs no longer write values
that depend on the state of the base. This commit restores the lines this PR changed only to
update such values (counts in docs, the llm.txt mirrors, the Stryker test list, the package
description, counts in agent-instruction files) to the text of the PR's merge base, so merging
the current base brings the values `npm run release:refresh-derived` maintains. Every other
change of the PR is untouched.
2026-11-15 05:05:09 -03:00
sdfsdfw2
7b71e9a8ef fix(dashboard): polish banned keywords card load failure and positioning 2026-11-13 01:19:27 +08:00
Bl0ck154
b034e36442 merge(upstream): reconcile PR #19680 with current release without losing feature 2026-11-12 18:46:35 +02:00
Bl0ck154
386f5dab89 merge(upstream): reconcile PR #18738 with current release without losing feature 2026-11-12 18:46:29 +02:00
ggdayup
fe6363a033 fix(pricing): map Vertex AI LiteLLM buckets and add default rates 2026-11-12 23:54:32 +08:00
sdfsdfw2
6170f698f3 docs(changelog): add fragment for #20078 2026-11-12 19:55:49 +08:00
sdfsdfw2
009399f6d3 fix(dashboard): keep banned keywords editor available when resilience load fails 2026-11-12 19:37:18 +08:00
sdfsdfw2
d143840867 refactor(dashboard): move custom banned keywords to Resilience page 2026-11-12 18:59:42 +08:00
Minxi Hou
0fabf5fe8a feat(search): forward Tavily max_age_hours
Tavily added max_age_hours in October 2026 so a search can cap how old the
cached copy of each result is: 1 to 720 hours, 0 to always fetch live, -1 to
never fetch live. The provider_options bag drops any key that is not on the
allow-list, so callers had no way to send it.

The field now passes through with that exact value set, and anything outside
it (721, a fraction, a string) is dropped instead of forwarded.

Signed-off-by: Minxi Hou <houminxi@gmail.com>
2026-11-11 13:35:24 -05:00
Bl0ck154
819d029701 test(openrouter): assert malformed regex stripping and counter
Port the focused fork regression for invalid pattern predicate evaluation,
correct removal counts and input immutability. No runtime changes.
2026-11-11 17:31:15 +02:00
Bl0ck154
f063a25349 test(gemini): verify cached input stays bounded by prompt tokens
Port the existing fork regression to protect already upstreamed usage clamping.

No production or live working tree changes.
2026-11-11 17:26:57 +02:00
Bl0ck154
600fc6f07b test(media): prove pinned fetch returns before response body ends
Port the focused fork regression without fork-only runtime changes.
No builds or production modification on the VPS; off-host CI validates.
2026-11-11 17:26:37 +02:00
Safeer Ahmad
619c595385 fix(antigravity): keep the conversation session on non-streaming server-tool follow-ups
The follow-up leg of a non-streaming server-owned tool loop re-translates the next
source body without antigravitySessionKey, so it fell back to the account-wide
sessionId and could evict a parallel conversation's cache. chatCore now resolves
the key once at function scope and passes it to runNonStreamingResponse, whose
follow-up translation forwards it. Adds docstrings for the session helpers.

Review: CodeRabbit on #19876.
2026-11-11 14:55:40 +05:00
xiaoyaner0201
4370081fde refactor(db): drop unused reasoning rule type re-exports
knip flags ReasoningEffortMode, ReasoningRuleScope and ReasoningTargetKind as
new dead exports in the touched facade. No importer uses them through
src/lib/db/reasoningRoutingRules; they remain exported from the domain
repository contract.
2026-11-11 17:42:35 +08:00
Safeer Ahmad
c64ce472ab chore(changelog): fragment for #19876 2026-11-11 14:09:15 +05:00
Safeer Ahmad
b8fa424900 fix(antigravity): scope the upstream sessionId per conversation, not per account
The OpenAI->Antigravity envelope derived request.sessionId from the account
email alone (#13305), so every conversation running in parallel on one
account shared a single Cloud Code session. Parallel coding-agent tasks then
evicted each other's prompt cache: on a live 8-task opencode run against
gemini-4-carbon-medium, tokens_cache_read collapsed from ~280k to 10,443/None
and 250k-380k uncached prefills took 250-589s (two 600s pre-header 504s),
while the same conversation alone on an account finished 255k-271k cached
turns in 11-14s.

chatCore now passes the resolved conversationId (falling back to the
session-affinity key) into translateRequest as antigravitySessionKey, and the
envelope hashes account + conversation. One conversation keeps one stable
session across turns (cache reuse is preserved), parallel conversations get
distinct sessions, and requests with no conversation key keep the old
account-derived id.
2026-11-11 14:07:30 +05:00
Bl0ck154
037a8455aa fix(images): resolve hosted Codex remote edit refs within 128/20MiB bounds 2026-11-11 10:38:51 +02:00
Bl0ck
dbb882582e test(cursor): freeze live reset countdown during markup equality assertion 2026-11-11 10:31:59 +02:00
Bl0ck154
87a464842d merge(upstream): reconcile Terra model support with current release 2026-11-11 10:30:10 +02:00
Bl0ck
cad3cc79ad chore(tests): sync Stryker tap fixtures with current release 2026-11-11 10:29:03 +02:00
Bl0ck154
078d8a4bbd docs(changelog): format hosted image references entry as bullet 2026-11-11 10:28:12 +02:00
diegosouzapw
bf7a8aca0d Merge release/v3.8.54 into fix/18045-property-force-exit-preload 2026-11-10 15:21:02 -03:00
Bl0ck154
f4787d6b40 merge: sync upstream release into PR #18738 without losing changes 2026-11-10 19:33:19 +02:00
Bl0ck154
f8d4f71c9b merge: sync upstream release into PR #19667 without losing changes 2026-11-10 19:32:44 +02:00
Bl0ck154
86932f5e2f merge: sync upstream release into PR #19680 without losing changes 2026-11-10 19:32:40 +02:00
Bl0ck
c5178f36b0 merge: sync Codex plan diagnostics with upstream release/v3.8.54 2026-11-10 19:18:14 +02:00
serenity
1d038f69b9 docs(changelog): number the fragment (#19750) 2026-11-10 20:39:25 +03:30
serenity
bc6d0b9eb9 perf(claude): cache the final tool-result turn of an agent loop
An OpenAI-format tool loop sent to Claude ends with the results of the last
assistant turn's tool calls. They sit after that turn's cache breakpoint, so
they are billed as fresh input, and the next call sends them again.

prepareClaudeRequest rebuilds every message marker, so the policy must live
there. Add markFinalToolResults: when the final user turn holds a tool_result
and fewer than 4 markers exist, mark its last block with the tail marker (same
5m class as the other tail markers). The next call then reads those tokens
from cache at 0.1x. A request with no follow-up pays a one-time 0.25x write
premium on those tokens. Client-managed (passthrough) markers are not changed,
and the 4-marker limit still holds: enforceCacheControlBlockLimit and the new
helper share one marker walk.
2026-11-10 20:28:46 +03:30
diegosouzapw
1a50f78356 docs(changelog): add fragment for batch E2E startup isolation 2026-11-10 12:41:15 -03:00
diegosouzapw
3a4da7066a Merge release/v3.8.54 into fix/batch-e2e-startup-isolation
# Conflicts:
#	src/instrumentation-node.ts
2026-11-10 12:37:09 -03:00
serenity
1c79a825bd docs(changelog): number the fragment (#19724) 2026-11-10 18:32:53 +03:30
serenity
3384c13632 test(stryker): list the bundle's covering tests in tap.testFiles 2026-11-10 18:22:11 +03:30
serenity
672437cbb5 perf(providers): index providers by alias and id for O(1) lookup
resolveProviderId calls getProviderByAlias, which looped over every
provider section and compared alias and id on each entry. A miss, for
example an openai-compatible-* id, scanned the whole catalog of about
380 providers and then returned the input. Circuit-breaker names,
target gates, quota lookups and failure records call it on every
routing step.

Build one Map from alias and id to provider on first use. A key is
claimed by the first provider in section order whose alias or id
equals it, the same rule as the old scan, so an alias that equals
another provider's id (poe) keeps resolving as before. Only the
internal lookup changes: ALIAS_TO_ID and getProviderById are untouched.

(cherry picked from commit a95c42fda203fabf12cf226431340d1c2c6f57f1)
2026-11-10 18:22:11 +03:30
serenity
3982e38e39 fix(pii): refuse custom regexes that run slowly on a long character run
The custom PII pattern gate relied on safe-regex alone. safe-regex is a
static star-height check and accepts overlapping alternations such as
(a|aa)+$, which take exponential time on a run of one character. Such a
pattern passed save, preview and runtime compile, then froze the event
loop on the first matching text.

After the static check, run the pattern on seven 64-character runs
(letter, non-ASCII letter, digit, space, dash, underscore, dot) under a
100 ms vm deadline. A pattern that is cut off is refused as unsafe.
The same gate covers save, preview and the runtime skip of stored rows.

(cherry picked from commit e45b0378848f3428ce7d9ae62b63641cc4e50370)
2026-11-10 18:22:11 +03:30
serenity
be1efe54ef fix(resilience): require all half-open probes to pass before closing
A HALF_OPEN circuit breaker closed on the first probe success, whatever
`halfOpenRequests` was. One lucky probe could restore a flapping
provider, and the setting had no effect above 1.

The breaker now counts probe successes in the HALF_OPEN episode and
closes when `halfOpenRequests` of them have passed. A probe failure
still reopens the breaker. The count resets on every state change and
when a stale probe lease is renewed. The default (1) behaves as before.

(cherry picked from commit f2d231c43c41ed330d733231fe4ffb812d16d91d)
2026-11-10 18:22:11 +03:30
serenity
c31ec5bc46 fix(security): scan base64, hex and percent-encoded text for prompt injection
detectInjection matched the surface text only. "Ignore all previous
instructions" wrapped in base64, hex or percent-encoding passed the guard
with no detection, even in block mode. The only rule that mentioned encoding
(encoding_evasion) needs the words "base64 decode" next to "instruction".

detectInjection now also decodes encoded runs in the scanned text, to two
layers, and runs the injection patterns on what they decode to. A hit keeps
the rule's severity and is reported as "decoded:<rule>", so the block
threshold, logging and the guard treat it like the plain form.

Bounds: the input is still the 16 KB scan window. A run needs 24 base64
characters or 12 hex bytes, at most 64 decode attempts run per request, and
a run that decodes to binary (a hash, a token, random data) is dropped. The
run patterns are single character classes, so they are linear. Worst case on
a 16 KB window is about 0.6 ms in the benchmark, and no benign sample (hashes,
random base64, kebab-case paths, form data) produced a hit.

(cherry picked from commit 838f618f8ba16be77af64147a1128eb9075f51fd)
2026-11-10 18:22:11 +03:30
Bl0ck
79da76e719 test(providers): scope async credential probes to their originating POST 2026-11-10 13:30:29 +02:00
AiCapitan357
71893b283f fix(deps): upgrade Next.js to 16.4.6 for November security fixes 2026-11-10 10:48:15 +00:00
xiaoyaner0201
952ca75e68 chore(changelog): number reasoning routing repository entry 2026-11-10 17:51:05 +08:00
Bl0ck
602671430e style(tests): align route imports with Prettier 2026-11-10 11:48:50 +02:00
Bl0ck
9b629504d9 docs: explain independent hosted and dedicated image input bounds 2026-11-10 11:41:59 +02:00
Bl0ck
fe157b413a test(images): forward 128 hosted references and reject 129 2026-11-10 11:41:56 +02:00
Bl0ck
03e1c29c4b fix(images): lift verified Codex hosted edit reference guard to 128 2026-11-10 11:41:54 +02:00
Bl0ck
f0e8c12f17 docs(codex): document opt-in selected plan response header 2026-11-10 11:28:46 +02:00
xiaoyaner0201
1cf48f6323 fix(db): invalidate reasoning rule cache before awaiting persistence 2026-11-10 16:29:01 +08:00
xiaoyaner0201
08d5907f59 refactor(db): extract reasoning routing rule repository 2026-11-10 14:40:41 +08:00
diegosouzapw
155652bef2 fix(providers): clear #19583 mutation and cognitive-complexity gates
- list expiry-first-deadline-order and -session-spreading tests in
  stryker tap.testFiles (they cover quotaScoring.ts and sse/services/auth.ts)
- extract windowUsableCap() from resolveUsableAndReset so the lapsed-window
  cap stays under the cognitive-complexity limit (same behaviour)
- move pickExpiryFirstConnection's JSDoc back above its function
2026-11-10 01:43:26 -03:00
diegosouzapw
0d0e46707e Merge remote-tracking branch 'origin/release/v3.8.54' into HEAD 2026-11-10 01:05:35 -03:00
Praveen K Palaniswamy
95d9902bf0 fix(images): reject extra references for a Leonardo combo edit target
A combo edit routed to Leonardo uploaded only the first reference and dropped
the rest, while the single-model route answers 400. The combo branch now
returns the same 400, so the combo moves on to its next provider.
2026-11-09 21:54:35 -05:00
Tomas Fecko
b6b31604b0 fix(providers): keep expiry-first deadline picks out of OAuth session spreading
After a strategy picks an account, getProviderCredentials moves the request to
a peer OAuth account with fewer foreign sessions in flight. Under
`expiryFirstOrder: "deadline"` that undid the decision: on a two-account
Claude pool every parallel Claude Code conversation after the first was moved
to the account whose week resets two days later, so it kept being spent.
Deadline order now keeps its pick; the default rate order still spreads.
2026-11-09 21:54:08 +01:00
Bl0ck
ba4f6cdda9 fix(codex): do not surface stale account plan on no-credentials response 2026-11-09 22:48:58 +02:00
Bl0ck
26464e5b70 fix(codex): correct plan sanitizer and format diagnostics 2026-11-09 22:48:18 +02:00
Bl0ck
d69bad2c11 fix(codex): correct plan sanitizer and format diagnostics 2026-11-09 22:48:14 +02:00
Bl0ck
1fbd5f0c45 fix(codex): correct plan sanitizer and format diagnostics 2026-11-09 22:48:11 +02:00
Bl0ck
0e3d307e17 docs(changelog): note opt-in Codex plan troubleshooting header 2026-11-09 22:47:10 +02:00
Bl0ck
e108c0dc7e docs(codex): document disabled-by-default account plan response diagnostics 2026-11-09 22:46:49 +02:00
Bl0ck
0fecfd8165 test(codex): verify plan header opt-in and sanitization 2026-11-09 22:46:03 +02:00
Bl0ck
e4fd2574bf feat(codex): report current selected account plan to telemetry 2026-11-09 22:46:00 +02:00
Bl0ck
fd1dcad9bb feat(codex): gate account plan header behind opt-in allowlist 2026-11-09 22:45:57 +02:00
Bl0ck
76518d6507 feat(codex): declare optional selected-plan diagnostics header 2026-11-09 22:45:54 +02:00
Tomas Fecko
53ce8e3653 fix(providers): roll lapsed session-only resets forward in expiry-first
A session whose reset already passed was only skipped when a longer window
existed. For a session-only account the past reset stayed negative and its
stale fraction still capped `usable`, so deadline order ranked it as already
expiring. A lapsed session is now refilled with its next reset one 5h period
later, like weekly and monthly windows. Adds two regression tests.
2026-11-09 21:24:45 +01:00
Tomas Fecko
2aba63fe7e docs(changelog): add fragment for #19583 2026-11-09 19:54:23 +01:00
Tomas Fecko
9debe722cf feat(providers): expiry-first deadline order and lapsed-reset handling
A longer quota window whose reset already passed comes from a stale quota
read. expiry-first scored it as "expires now" (deadline floored to
minHours), so a stale account looked like the most urgent one and took the
traffic: on 2026-11-06/07 a Claude Team account whose last read still carried
the previous Friday's weekly reset drained ahead of a Max account resetting two
days later. A lapsed weekly/monthly window is now treated as refilled, with its
next reset one nominal period later; a lapsed window of unknown length keeps no
deadline.

Adds `expiryFirstOrder: "deadline"` (provider override or global): accounts
that still hold quota are spent strictly by the nearest deadline, a spent 5h
session or exhausted window is skipped until it refills, and deadlines within
`expiryFirstDeadlineTieMinutes` (default 60) rotate least-recently-used. The
default stays the per-hour rate. Provider strategy overrides now reach the
expiry-first config, and the settings schema accepts both keys per provider.
2026-11-09 19:24:56 +01:00
diegosouzapw
40e27525c6 fix(images): send the request size on Leonardo edits
/v1/images/edits passed only the prompt to the Leonardo handler, so every
edit came back 1024x1024 whatever size the client asked for, while
/v1/images/generations already maps size to width/height. Pass size on the
single-model and combo edit paths; the route test now asserts 576x1024.
2026-11-09 05:09:04 -03:00
diegosouzapw
394d56b82b Merge remote-tracking branch 'origin/release/v3.8.54' into HEAD
# Conflicts:
#	src/app/api/v1/images/edits/route.ts
2026-11-09 04:36:56 -03:00
diegosouzapw
9c982b1aaf test(images): route the Leonardo edit result download through the pinned media fetch stub
The release now downloads Leonardo results through the guarded media fetch
(DNS resolve + pinned agent), so the edit tests stub the lookup and the pinned
fetch the same way the other Leonardo tests do, and wait for call-log saves
before closing the DB.
2026-11-07 19:53:44 -03:00
diegosouzapw
55466d43cf Merge remote-tracking branch 'origin/release/v3.8.54' into HEAD
# Conflicts:
#	open-sse/handlers/imageGeneration/providers/leonardo.ts
#	open-sse/handlers/videoGeneration/leonardoHandler.ts
#	tests/unit/leonardo-image-model-id.test.ts
#	tests/unit/leonardo-video-generation.test.ts
2026-11-07 19:49:54 -03:00
Bl0ck154
2f5532d7e0 test(combo): keep uncataloged ceiling coverage after Terra registration
Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
2026-11-07 23:00:47 +02:00
Bl0ck154
d17b135642 Merge release/v3.8.54 into feat/gpt61-terra-upstream-20261102; resolve Stryker registrations 2026-11-07 21:27:53 +02:00
Bl0ck
aedc445cb0 test(openai): cover Terra sampling in native and translated Responses 2026-11-07 21:05:43 +02:00
Bl0ck
783e35d292 fix(openai): strip Terra logprobs only for active reasoning 2026-11-07 21:05:20 +02:00
Bl0ck
5b721ffb9d fix(openai): keep Terra sampling when reasoning is disabled 2026-11-07 21:05:05 +02:00
Bl0ck154
1b44f42a4b Merge remote-tracking branch 'upstream/release/v3.8.53' into audit/pr18738-quality-20261102
Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
2026-11-02 20:34:30 +02:00
Bl0ck154
8bf129e62e fix(quality): avoid added Fast multiplier complexity and include coverage test
Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
2026-11-02 20:34:30 +02:00
Praveen K Palaniswamy
55f499c284 Merge branch 'fix/leonardo-image-model-id' into feat/leonardo-image-edits 2026-11-02 11:37:27 -05:00
Praveen K Palaniswamy
bb51084f7e Merge remote-tracking branch 'upstream/release/v3.8.53' into fix/leonardo-image-model-id 2026-11-02 11:37:17 -05:00
Bl0ck154
296f7a0219 docs(changelog): format Terra model fragment as release bullet 2026-11-02 17:19:05 +02:00
Bl0ck154
18e24bda3a Merge current release/v3.8.53 into GPT-6.1 Terra model support
Signed-off-by: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com>
2026-11-02 17:12:10 +02:00
Bl0ck154
9505140652 test(models): type Responses translation regression result 2026-11-02 00:57:53 +02:00
Bl0ck154
0491633369 fix(models): preserve Terra effort-only Codex Responses requests 2026-11-02 00:56:57 +02:00
Bl0ck154
85b3cfedb2 feat(models): register GPT-6.1 Terra for OpenAI API and Codex 2026-11-02 00:54:57 +02:00
Praveen K Palaniswamy
cde7a030aa docs(changelog): add Leonardo image edits 2026-10-31 11:12:38 -04:00
Praveen K Palaniswamy
8c600b7ac9 feat(images): support Leonardo reference-image edits on /v1/images/edits (#18671)
/v1/images/edits rejected every Leonardo model, although Leonardo does
image-to-image on its generations call. Upload the edit reference through
Leonardo's init-image flow (presigned S3 form post, no Leonardo token sent
to S3) and generate with init_image_id and init_strength 0.3, on both the
single-model and the combo edit paths. Edits are call-logged under
/v1/images/edits.
2026-10-31 11:01:30 -04:00
Praveen K Palaniswamy
6deb70bb83 docs(changelog): add the Leonardo image and video fix 2026-10-31 10:46:32 -04:00
Praveen K Palaniswamy
02df761457 fix(sse): send Leonardo video to the text-to-video endpoint and return the mp4
The video handler posted an image-generation body (modelId "phoenix",
num_frames) to /generations, which Leonardo rejects with 400 "Unexpected
variable num_frames", so leonardo video never worked. Submit to
/generations-text-to-video with a model enum and resolution, read
motionVideoGenerationJob, poll the generations status URL, and download
motionMP4URL (url is a jpg thumbnail). The catalog lists Motion 2.0 and
Motion 2.0 Fast; the old phoenix id maps to Motion 2.0.
2026-10-31 10:45:29 -04:00
Praveen K Palaniswamy
ce3be09269 fix(sse): send Leonardo image requests a platform-model UUID, not the catalog id
Leonardo's v1 generations API takes a platform-model UUID as modelId. The
handler sent the catalog id (phoenix, sdxl), which Leonardo answers with
HTTP 500 "internal error", so every leonardo/* image request failed.
Map phoenix and sdxl to the Phoenix 1.0 and SDXL 1.0 UUIDs; a raw UUID
passes through so any Leonardo model can be used.
2026-10-31 10:30:49 -04:00
ahmedgo17390
18c2af93a5 test(batch): isolate E2E worker startup 2026-10-30 22:16:32 +03:00
ahmedgo17390
92ead552ec test: protect property runner reports 2026-10-29 13:26:33 +03:00
164 changed files with 7783 additions and 796 deletions

View File

@@ -2613,6 +2613,13 @@ APP_LOG_TO_FILE=true
# Used by: src/lib/healthzLag.ts (event-loop stall sampler). Disabled by default;
# logs sizes and inflight count only, never bodies or heap snapshots.
# OMNIROUTE_EVENT_LOOP_STALL_THRESHOLD_MS=0 stops that sampler, and this diagnostic with it.
# Optional response header for troubleshooting Codex OAuth plan eligibility.
# OFF by default: when enabled, API callers can see the recognized subscription tier
# of the selected Codex connection in X-OmniRoute-Selected-Connection-Plan.
# Do not enable on public/multi-tenant gateways if this account metadata is private.
# Arbitrary/unrecognized plan values and non-Codex requests never get this header.
# OMNIROUTE_CODEX_PLAN_RESPONSE_HEADER=0
# OMNIROUTE_HEAP_DIAGNOSTICS_ENABLED=0
# Heap-use threshold in MiB for the opt-in diagnostic (default: 900).
# A high-heap log is rate-limited to once per 60 seconds.

View File

@@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: "24"
cache: npm

View File

@@ -1897,7 +1897,7 @@ jobs:
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
package-manager-cache: false
node-version: ${{ env.CI_NODE_VERSION }}

View File

@@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
cache: npm

View File

@@ -168,7 +168,7 @@ jobs:
echo "refresh=true" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
if: steps.drift.outputs.refresh == 'true'
with:
package-manager-cache: false

View File

@@ -76,7 +76,7 @@ jobs:
with:
ref: ${{ needs.resolve-branch.outputs.target }}
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
package-manager-cache: false

View File

@@ -133,7 +133,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
cache: npm

View File

@@ -72,7 +72,7 @@ jobs:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NIGHTLY_NODE_VERSION }}
package-manager-cache: false
@@ -146,7 +146,7 @@ jobs:
path: .
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NIGHTLY_NODE_VERSION }}
registry-url: https://registry.npmjs.org

View File

@@ -73,7 +73,7 @@ jobs:
sparse-checkout: |
scripts/merge-queue
config/merge-queue
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
package-manager-cache: false
node-version: "24"

View File

@@ -22,7 +22,11 @@ name: omni-queue
# • Both jobs run in the `omni-queue` environment, which holds the App's credentials and the
# owner's OMNI_QUEUE_LAND_TOKEN and admits the default branch only, by its exact name: a
# workflow on a candidate branch cannot read them. The App writes omni-queue/land, the status release rulesets
# require, so its private key is the root of trust. The land token reaches the tick only.
# require, so its private key is the root of trust. The land token reaches the tick only
# (the landing with landing.actor "owner"; the comments, label removals and issues with
# config voice "owner"). The owner's merge-commit signing key (OMNI_QUEUE_SIGNING_KEY,
# config landing.signing "ssh") reaches one step of the tick, which writes it to a 0600 file
# under RUNNER_TEMP; the job's last step removes it, whatever happened.
# • action=bless (the explicit emergency exit): the tick writes omni-queue/land on ONE commit
# for a hotfix, sync-back or base repair, after checking that both the dispatcher
# (github.actor) and whoever triggered the run (github.triggering_actor, the re-runner of a
@@ -126,7 +130,7 @@ jobs:
sparse-checkout: |
scripts/merge-queue
config/merge-queue
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
package-manager-cache: false
node-version: "24"
@@ -210,7 +214,7 @@ jobs:
sparse-checkout: |
scripts/merge-queue
config/merge-queue
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
package-manager-cache: false
node-version: "24"
@@ -235,10 +239,35 @@ jobs:
echo "name=${login}"
echo "email=${id}+${login}@users.noreply.github.com"
} >> "$GITHUB_OUTPUT"
# config.landing.signing "ssh": the owner's SSH signing key, for the queue's merge commits
# (scripts/merge-queue/compose.mjs reads it at compose.signingKeyPath(RUNNER_TEMP) and hands
# git the path as per-command configuration, never as an argument). The key exists only in
# this step's environment and in a file only the runner user can read; it is never
# printed. Without the secret nothing is written and a tick that is asked to sign composes
# unsigned, with one `error` event per batch. This step never fails the job: a key it
# cannot write is the same case (signing never blocks the queue).
- name: Write the merge-commit signing key
env:
OMNI_QUEUE_SIGNING_KEY: ${{ secrets.OMNI_QUEUE_SIGNING_KEY }}
run: |
set -uo pipefail
if [ -z "${OMNI_QUEUE_SIGNING_KEY:-}" ]; then
echo "no merge-commit signing key in the environment: nothing written"
exit 0
fi
umask 077
if ! { mkdir -p "$RUNNER_TEMP/omni-queue-signing" \
&& chmod 700 "$RUNNER_TEMP/omni-queue-signing" \
&& printf '%s\n' "$OMNI_QUEUE_SIGNING_KEY" > "$RUNNER_TEMP/omni-queue-signing/signing-key" \
&& chmod 600 "$RUNNER_TEMP/omni-queue-signing/signing-key"; }; then
rm -rf "$RUNNER_TEMP/omni-queue-signing"
echo "::warning::the merge-commit signing key could not be written: merge commits stay unsigned"
fi
# Inputs travel through env and are assembled into an argv array: no expression is ever
# expanded inside the script body. Scheduled, workflow_run and pull_request_target ticks
# pass no base (the tick discovers the bases with work). The owner's land token is used
# only by the landing itself when config.landing.actor is "owner" (never printed).
# by the landing itself when config.landing.actor is "owner", and by the queue's comments,
# label removals and issues when config.voice is "owner" (never printed).
# GITHUB_ACTOR and GITHUB_TRIGGERING_ACTOR are the runner's own default variables, named
# here because a bless is checked against both: the original dispatcher, whose inputs a
# re-run keeps, and whoever triggered this run (the re-runner of a re-run).
@@ -265,3 +294,8 @@ jobs:
if [ -n "${INPUT_SHA:-}" ]; then args+=(--sha "$INPUT_SHA"); fi
fi
node scripts/merge-queue/tick.mjs "${args[@]}"
# Last step, whatever happened before it (failure, cancellation): the signing key leaves
# the runner. Needs no secret; nothing to remove is not an error.
- name: Remove the merge-commit signing key
if: always()
run: rm -rf "$RUNNER_TEMP/omni-queue-signing"

View File

@@ -120,7 +120,7 @@ jobs:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.PREVIEW_NODE_VERSION }}
package-manager-cache: false

View File

@@ -573,7 +573,7 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6
with:
package-manager-cache: false
node-version: ${{ env.CI_NODE_VERSION }}
@@ -613,7 +613,7 @@ jobs:
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
package-manager-cache: false
node-version: ${{ env.CI_NODE_VERSION }}

View File

@@ -20,6 +20,7 @@ jobs:
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
@@ -28,17 +29,13 @@ jobs:
- uses: ./.github/actions/npm-ci-retry
with:
cache: "false"
- name: Emit shadow acceptance report
run: |
node scripts/quality/validate-release-acceptance.mjs \
--plan tests/fixtures/release-acceptance/plan-lint.json \
--manifests tests/fixtures/release-acceptance/shadow-manifests \
--out release-acceptance-report.json
- name: Validate and retain the live gate inventory
run: node scripts/quality/release-acceptance/run-shadow.mjs "$RUNNER_TEMP/release-acceptance-shadow"
continue-on-error: true
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: release-acceptance-report
path: release-acceptance-report.json
if-no-files-found: ignore
path: ${{ runner.temp }}/release-acceptance-shadow/
if-no-files-found: error
retention-days: 30

View File

@@ -0,0 +1 @@
- **feat(images):** `/v1/images/edits` supports Leonardo: the reference image is uploaded through Leonardo's init-image flow and the generation is guided by it (`init_image_id`, `init_strength` 0.3), instead of the edit being rejected as unsupported. Leonardo takes one reference image; more than one returns 400, and a combo moves on to its next provider rather than editing with the first image only ([#18674](https://github.com/cheaper-inference/OmniRoute/pull/18674), closes [#18671](https://github.com/cheaper-inference/OmniRoute/issues/18671))

View File

@@ -0,0 +1 @@
- **feat(providers):** `expiry-first` treats a lapsed weekly/monthly reset (stale quota read) as refilled instead of "expires now", and gains an opt-in `expiryFirstOrder: "deadline"` (per provider) that spends the account whose quota is lost first while it has quota ([#19583](https://github.com/diegosouzapw/OmniRoute/pull/19583)) — thanks @feci

View File

@@ -0,0 +1 @@
- **feat(ci):** omni-queue can speak as the owner and sign its merge commits, both off by default. With `voice: "owner"` in `config/merge-queue/config.json`, the queue's comments and label removals on pull requests, the dashboard issue and its comments, base-red comments and the tree-divergence issue go out with `OMNI_QUEUE_LAND_TOKEN`; statuses, refs, the state branch, re-runs and reads stay the App's, and a missing or refused token falls back to the App with one `error` event. With `landing.signing: "ssh"` (owner actor only), every merge commit the queue composes is signed with the owner's key from the `OMNI_QUEUE_SIGNING_KEY` environment secret, and a missing key composes unsigned with one `error` event per batch ([#20792](https://github.com/cheaper-inference/OmniRoute/pull/20792))

View File

@@ -0,0 +1 @@
- Add an opt-in `X-OmniRoute-Selected-Connection-Plan` response header for Codex account-routing troubleshooting (`OMNIROUTE_CODEX_PLAN_RESPONSE_HEADER=1`), off by default with an explicit plan allowlist.

View File

@@ -0,0 +1 @@
- **feat(models):** add GPT-6.1 Terra to OpenAI API and Codex model catalogs, including Responses-only tool routing, supported reasoning tiers, verified token pricing, long-context rates, and Codex aliases.

View File

@@ -0,0 +1 @@
- **fix(security):** the prompt-injection guard now decodes base64, hex and percent-encoded text in a request and scans the result, so an instruction hidden in an encoded string is scored like the same instruction in plain text. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))

View File

@@ -0,0 +1 @@
- **fix(resilience):** a circuit breaker with `halfOpenRequests` above 1 now needs that many probe successes in a row before it closes, so one lucky probe no longer restores a flapping provider. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))

View File

@@ -0,0 +1 @@
- **fix(pii):** a custom PII regex that backtracks for exponential time on a long run of one character, such as an overlapping alternation, is now refused when you save or test it, instead of freezing the gateway. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))

View File

@@ -0,0 +1 @@
- **fix(antigravity):** parallel conversations on one account no longer share a single Cloud Code session and evict each other's prompt cache — the upstream `sessionId` is now derived from account + conversation ([#19876](https://github.com/cheaper-inference/OmniRoute/pull/19876)) — thanks @adevwithpurpose

View File

@@ -0,0 +1 @@
- **fix(dashboard):** move the custom banned-keyword editor back to the Resilience settings tab (next to Auto Disable) instead of Security, and harden its save/load path: keywords appear only after the server accepts the PATCH, a failed settings load surfaces an error instead of a misleading empty list, the 200-character limit is enforced in the UI, and removals match by keyword value rather than index. The editor now also stays available when `/api/resilience` fails to load ([#20078](https://github.com/cheaper-inference/OmniRoute/pull/20078)) — thanks @sdfsdfw2

View File

@@ -0,0 +1 @@
- **fix(security):** an HTTP 400 counts subscription/plan quota wording ("usage limit reached", "plan limit", weekly/session usage limits) as quota exhaustion only when the structured error code is a credit/quota code or the provider documents a message-only 400 form (`command-code`, `bai`, `openai-compatible-*`), the same contract as #20567, so such a phrase echoed from the request no longer puts a shared LLM or search connection on hold

View File

@@ -0,0 +1 @@
- **fix(security):** Choosing the local corpus root (`POST /api/settings/local-corpus`) or the Obsidian WebDAV vault (`POST /api/settings/obsidian/webdav`) now needs a dashboard session or the local CLI: API keys and access tokens of any scope get 403. Both routes also refuse the filesystem root, the home directory itself and system directories (`/etc`, `/usr`, `/bin`, `/sbin`, `/var`, `/proc`, `/sys`, `/dev`, `/boot`, `/root`) with a fixed 400 (CodeQL #1371, #1372, #1373)

View File

@@ -0,0 +1 @@
- **fix(security):** The internal chat admission bypass and the internal upstream-start cap are granted only on a per-process token held in memory; the deployment env key (`OMNIROUTE_API_KEY` / `ROUTER_API_KEY`) still authenticates requests but no longer marks them as internal

View File

@@ -0,0 +1 @@
- **fix(security):** Image generation on NanoBanana, Magnific, Black Forest Labs and RenderHour caps a caller's `poll_interval_ms` at 30 s and `timeout_ms` / `poll_timeout_ms` at 10 minutes (defaults unchanged), and RenderHour stops waiting between polls when the request is aborted; SYNTX provider rules only run for names defined in the rules table, so an `ai_name` such as `constructor` or `__proto__` no longer reaches an inherited `Object.prototype` member (CodeQL #1389, #1392) ([#20824](https://github.com/cheaper-inference/OmniRoute/pull/20824))

View File

@@ -0,0 +1 @@
- **fix(auth):** continue background token health-check and OAuth credential refresh for inactive connections (`isActive: false`), preserving their disabled routing state while preventing rotating refresh token expiration on quota-exhausted Claude accounts.

View File

@@ -0,0 +1 @@
- Codex hosted Responses `image_generation` edits now admit up to 128 reference images instead of the historical, unverified eight-image guard. Live isolated Codex OAuth smokes with 9, 17, 24, 32, 64 and 128 small references each returned a real PNG (HTTP 200). The 128-image value is an operational request guard, **not** a claim of the backend's absolute maximum. The separate dedicated GPT Image edits endpoint remains capped at its documented 16 inputs. Existing per-image MIME/size checks and 20 MiB aggregate decoded-input limit remain unchanged.

View File

@@ -0,0 +1 @@
- **test(batch):** the batch rate-limit E2E keeps the background-services kill switch on and starts only the batch worker, behind a development-only double opt-in, instead of booting every production scheduler ([#18626](https://github.com/cheaper-inference/OmniRoute/pull/18626)) — thanks @ahmedgo17390

View File

@@ -0,0 +1 @@
- **refactor(db):** Isolate reasoning-routing rule persistence behind a Promise-based repository while preserving rule ordering, reference validation, cache invalidation and SQLite reset behavior (#19669 — thanks @xiaoyaner0201).

View File

@@ -0,0 +1 @@
- **perf(providers):** resolving a provider alias or id is now one map lookup instead of a scan of the whole provider catalog on every routing step. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))

View File

@@ -0,0 +1 @@
- **perf(claude):** The last tool-result turn of a translated Claude tool loop now gets the 5m cache marker (when fewer than 4 markers are used), so the next call reads those tool results from cache instead of paying the full input price again. A single request that ends with a tool result and has no follow-up pays a one-time 0.25x write premium on those tokens. ([#19750](https://github.com/cheaper-inference/OmniRoute/pull/19750))

View File

@@ -14,7 +14,8 @@
"name": "diegosouzapw",
"email": "8016841+diegosouzapw@users.noreply.github.com"
},
"statusContext": "omni-queue/land"
"statusContext": "omni-queue/land",
"signing": "none"
},
"requiredChecks": [
"Gate / CI",
@@ -51,5 +52,6 @@
"config/merge-queue/**",
".mergify.yml"
],
"mode": "shadow"
"mode": "shadow",
"voice": "app"
}

View File

@@ -635,7 +635,7 @@
},
{
"name": "test:property",
"command": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --test --test-force-exit tests/unit/correctness/*.property.test.ts",
"command": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./tests/_setup/isolateDataDir.ts --test --test-force-exit tests/unit/correctness/*.property.test.ts",
"disposition": "separately-invoked"
},
{

View File

@@ -153,6 +153,7 @@ commit status the release rulesets require (`scripts/merge-queue/config.mjs`):
| `actor` | `app` (the default when absent) or `owner` | `app`: the App's token pushes or merges. `owner`: the owner's token (`OMNI_QUEUE_LAND_TOKEN`) does, and the queue's merge commits carry `landing.identity`. |
| `identity` | `{name, email}`; the email ends in `@users.noreply.github.com` | Required when `actor` is `owner`, refused otherwise. |
| `statusContext` | `[A-Za-z0-9._/-]{1,100}`, starting with `omni-queue/`; default `omni-queue/land` | The commit status the release ruleset requires. It must not equal a name in `requiredChecks` or `aggregateChecks`, nor an approval context (`omni-queue/approval`, `omni-queue/protected-approval`). |
| `signing` | `none` (the default when absent) or `ssh` | `ssh`: every merge commit the queue composes is signed with the owner's SSH key (see [Signed merge commits](#signed-merge-commits-landingsigning)). Refused unless `actor` is `owner`. |
With `actor: "owner"` (the value in the shipped config):
@@ -332,6 +333,119 @@ In live mode:
The land token is fine-grained and valid for 90 days: write the date it expires next to the secret
and rotate it before then.
### Signed merge commits (`landing.signing`)
With `landing.signing: "ssh"` (shipped `none`) the queue signs every merge commit it composes:
batch candidates, bisection halves and recompositions, in shadow and in live mode
(`composeCandidate` in `scripts/merge-queue/compose.mjs`, `git commit-tree -S`). The commits carry
`landing.identity`, so `signing: "ssh"` is refused unless `landing.actor` is `owner`: GitHub
verifies a signature against the signing keys of the committer's account, and the App's bot user
has none.
**Where the key lives.** The private key is the environment secret OMNI_QUEUE_SIGNING_KEY
(environment `omni-queue`, next to the land token). Only the tick job reads it, in one step,
"Write the merge-commit signing key", which writes it to `$RUNNER_TEMP/omni-queue-signing/signing-key`
(directory `0700`, file `0600`); the job's last step, "Remove the merge-commit signing key"
(`if: always()`), deletes the directory whatever happened before it. The tick process never holds
the key: it reads the file's path (`signingKeyPath` in `scripts/merge-queue/compose.mjs`) and
hands it to git as configuration of the `commit-tree` call alone (`gpg.format=ssh`,
`user.signingkey=<path>`), through the environment (`GIT_CONFIG_COUNT`/`KEY`/`VALUE`), never as an
argument. Neither the key nor its path is written to a log line, an event, the state, a comment or
an error message. The step's script, which GitHub prints, names `$RUNNER_TEMP/omni-queue-signing/signing-key`
unexpanded.
**A missing key or a failed signature never blocks the queue.** When signing is configured and the
file is not there (no secret, a write that failed), or git cannot sign (a key that is not a valid
unencrypted SSH private key, for example), the batch is composed unsigned, exactly as without
signing, and one `error` event per batch says so: `<batchId>: <n> merge commit(s) composed
unsigned: <cause>`, where the cause is
`no signing key file in the job (is the OMNI_QUEUE_SIGNING_KEY secret set?)` or
`git could not sign a merge commit (exit <code>)` (see [Merge commits composed
unsigned](#merge-commits-composed-unsigned)). This "degrade and alert" choice keeps the queue
landing when the key breaks; an unsigned queue merge commit then lands without the Verified badge.
**What verifies a candidate does not read signatures.** `verifyComposition` and every other reader
of a candidate (`mergedPrsBetween`, `candidate-base.mjs`, `history-map.mjs`) read trees, parents
and messages (`%B`, which never contains the `gpgsig` header): a signed candidate verifies exactly
as the unsigned composition of the same inputs, and a signed commit with another tree, other
parents or other trailers is refused as before
(`tests/unit/merge-queue/integration/compose-signing.test.mjs` signs with a real ed25519 key and
checks the result with `git verify-commit`).
**The owner's setup**, once, before `signing` is set to `ssh` (GitHub's rules:
[About commit signature verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification),
[Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account),
[Telling Git about your signing key](https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key)):
1. Generate a dedicated key, used for nothing else, without a passphrase (the job cannot type one):
`ssh-keygen -t ed25519 -N "" -C "omni-queue merge commits" -f omni-queue-signing`.
2. On the account of `landing.identity` (Settings → SSH and GPG keys → New SSH key), add the public
key `omni-queue-signing.pub` with the key type **Signing Key**. A key added as an authentication
key does not verify commits; the same key used for both must be added twice, and this one
should be a signing key only.
3. Store the full contents of the private key file `omni-queue-signing` as the environment secret
OMNI_QUEUE_SIGNING_KEY of the environment `omni-queue` (never at repository level).
4. Delete both local files. The key exists only in the secret and, as a public key, on the account.
5. In a separate change, set `landing.signing` to `ssh`.
GitHub shows a commit as **Verified** when its signature verifies against a signing key of the
account; the committer of the queue's merge commits is `landing.identity`, the account's
`@users.noreply.github.com` address. With vigilant mode on (Settings → SSH and GPG keys → "Flag
unsigned commits as unverified"), every unsigned commit with that committer shows **Unverified**: a
batch composed unsigned (above) would land so; GitHub advises vigilant mode only to people who sign
every commit. The badge can only be proven on real GitHub: rehearse a landing in the rehearsal
repository before production turns signing on.
**Rotation.** Generate a new key (step 1), add its public key as a signing key (step 2), replace the
secret (step 3), delete the files, then remove the old public key from the account. GitHub keeps a
verification record of every commit it verified: per the first page above, "once a commit signature
is verified, it remains verified within its repository's network", "even if signing keys are
rotated, revoked". If the key leaks, remove it from the account and rotate at once.
### Who speaks (`voice`)
The top-level `voice` key (shipped `app`) chooses whose token performs the queue's writes that
people read on GitHub (`scripts/merge-queue/voice.mjs`). With `app`, every one is the App's
(`omni-queue[bot]`). With `owner`, they go out with the owner's `OMNI_QUEUE_LAND_TOKEN`, the token the
tick already holds for the landing (no second token secret), whatever `landing.actor` says. The
full list is in [What appears as the owner and what appears as the App](#what-appears-as-the-owner-and-what-appears-as-the-app).
- **Reads stay the App's.** Every read (comments, issues, pull requests, statuses) uses the App's
token; the owner's makes only the writes, plus one `GET /user` per run that reads the owner's
login from the token itself.
- **The queue still recognises its own comments.** A comment marker (the hidden key of
`commentOnce`, which makes each comment once) counts only when the comment's author is
`<appSlug>[bot]` or, with `voice: "owner"`, that login read from the token. A marker in anybody
else's comment never counts. Switching `voice` back to `app` makes the owner's earlier comments
unknown again: a comment the owner already posted may be posted once more by the App.
- **Never a lost message.** Without `OMNI_QUEUE_LAND_TOKEN`, or when GitHub answers 401 or 403 to
an owner write (or to the login read), the same write is made with the App's token at once.
Each such write is a line in the tick's decisions
(`owner voice: <write> written with the App's token (<cause>)`), and the first of the tick is an
`error` event, `owner voice unavailable, written with the App's token instead: <cause>`, not
repeated while the newest such event names the same cause (a token missing for days adds one
event, not one per tick). A refused owner write never fails the tick. Any other error (a 5xx, a
timeout) is handled as the App's own errors are: the next tick redoes the write. The failure path
of a failed tick (the stalled alert, a missing dashboard) writes the same way and logs the
fallback. See [Owner voice unavailable](#owner-voice-unavailable).
- **Shadow mode** still writes nothing on a pull request. It writes the dashboard issue, its
stalled alert and the base-red comments, so with `voice: "owner"` shadow mode uses the token
too: without it those writes fall back to the App, with the event above.
- **The approval job is the exception**: it never receives the owner's token (it runs on label
events with minimal permissions), so its "not an approver" comment stays the App's. The tick's
own `not-approver` comment for the same pull request then finds that one by its marker and posts
nothing.
- **Dashboard migration.** A tick finds the dashboard issue of a base by its exact title and the
label `omni-queue-dashboard` among the open issues (the oldest wins), never by its author, and
the queue never closes or recreates an issue by itself. An open dashboard opened by the App
stays the App's issue: with `voice: "owner"` the owner edits its body and posts its comments. To
have a dashboard opened by the owner: set `voice` to `owner`, close the old dashboard issue by
hand, then dispatch a tick for that base (`workflow_dispatch`, action `tick`, its `base`). That
tick opens a new dashboard with the configured voice. Dispatch it at once: a tick run without a
base finds a base with no labeled pull request only through its open dashboard issue
(`discoverBases` in `scripts/merge-queue/tick.mjs`), so until a tick of that base runs, a base
whose only work is a pause or stored withdrawals is not visited.
## Eligibility
A PR can enter a batch only when **all** of these hold (`scripts/merge-queue/eligibility.mjs`;
@@ -1050,40 +1164,41 @@ history holds a type the code does not know is refused, which matters for a roll
[Cut-over and rollback](#cut-over-and-rollback)). `tests/unit/merge-queue/runbook.test.mjs` fails
when this table and `EVENT_TYPES` differ.
| Event | When it happens | What the operator does |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `batch-started` | A candidate was composed and pushed: a new batch, a recomposition or a bisection segment. The detail names the PRs and the base, and for a root batch with `batch.adaptive` the window it was cut to (`window W`). A lane batch names its lane instead of a window (`lane hotfix` or `lane base-repair`). | Nothing. Its CI is linked from the dashboard. |
| `pr-skipped-conflict` | A PR conflicts with an earlier PR of the same batch. It is left out of this candidate and stays queued for a later batch. | Nothing. If it repeats, the author rebases the PR over the one it conflicts with. |
| `pr-dequeued` | A PR left the queue: `base-conflict` (it no longer merges into the base: label removed, comment), `already-in-base` (both labels removed, comment), or `withdrawn: <why>` before composition (label, head or approval changed). In shadow mode the first two are `would-dequeue` events instead. | For `base-conflict` the author updates the branch and an approver labels it again; the other cases need nothing. |
| `checks-green` | Every required check of the candidate (or of a base check) concluded `success`. | Nothing. The landing (or `would-land`) follows. |
| `checks-red` | A check of the candidate failed. The detail names the failing checks; on a base check it starts with `base-check red`. It ends with `; re-run refused (<status or reason>)` when the re-run of the failed jobs was refused. A batch red again after its re-run records a second one. | Nothing yet: classification follows (a re-run of the failed jobs, infra retry, base check, bisection or culprit). |
| `flaky-rerun` | A red batch or bisection segment that would be bisected, tested against the base or dequeued: its failed jobs are re-run once after its runs end (`flakyReruns`). Detail: `re-running the failed jobs of <batch> once (<jobs>) before <bisecting\|a base check\|dequeuing #n>` (five jobs at most). A green re-run's `checks-green` reads `green after re-running <jobs> (flaky)`. | Nothing. A real failure is blamed later: after the rest of the CI run and the re-run. Jobs that often turn green on the re-run are flaky tests to fix. |
| `checks-timeout` | No verdict after `checksTimeoutMinutes`, or no CI run at all after 45 minutes (`no CI run for candidate`). | For `no CI run`, check the Actions policies and the `omni-queue/**` triggers of `ci.yml` / `quality.yml` (see [Infra failure or timeout](#infra-failure-or-timeout)). |
| `land-blessed` | Live mode: the App wrote the land status (`landing.statusContext`, `success`) on the commits about to land, right before the landing. | Nothing. A `landed` event should follow; if a pause follows, the status was withdrawn. |
| `manual-bless` | An approver's `bless`: the App wrote the land status on one chosen commit. The detail names who and why. | Push or merge that commit yourself (see [Land status and manual bless](#land-status-and-manual-bless)). |
| `landed` | Live mode: the batch reached the base (the `merge-ff` push or every `squash-api` merge). | Nothing. |
| `would-land` | Shadow mode: a green batch that live mode would have landed. The detail can add `merged meanwhile by another path`, `live mode would pause: queue refs unprotected (…)` and, after the name of a check, `could not run (…): live mode would fail the tick`. | Compare with what Mergify merged. Both notes must be gone before `mode: "live"`: apply the queue-refs ruleset, or fix the check that could not run. |
| `would-dequeue` | Shadow mode: live mode would have removed this PR from the queue (label kept, no comment). The detail gives the reason code(s). | Nothing during shadow. |
| `land-rejected` | The batch was not landed: the base moved (`base moved…; recomposing`: the same PRs are recomposed on the tip), the batch changed before landing (`batch changed before landing: …`: the PRs left are recomposed), or a release-freeze holds it (`base-frozen: …; <batch> waits for the freeze to lift`, once per batch: it stays in flight, not recomposed, and lands after the freeze). | Nothing for an occasional one; frequent ones mean something else merges into the base (see [Recomposition when the base moves](#recomposition-when-the-base-moves)). |
| `bisect-split` | A red batch (or a red segment of a bisection) is split; the detail names the segment tested next. | Nothing. |
| `culprit-found` | Bisection or a batch of one isolated the PR that fails. Live: label removed, comment. Shadow, or a head that moved: label kept. | The author fixes the PR and an approver labels it again. |
| `base-check-started` | A red batch on a base with no verdict: the bare base is pushed as a `basecheck-<sha12>` candidate. | Nothing. |
| `base-red-paused` | The base check is red with the same failures as the batch: the base is paused with reason `base-red`. | Fix the base (see [Base-red](#base-red)). The pause lifts when the tip moves. |
| `hang-suspected` | A job hit its time limit on every run of the candidate: treated as a hanging test (base check, then bisection) instead of an infra pause. | Nothing yet; look at the culprit comment when one is named. |
| `infra-retry` | Every failure is infrastructure (or the checks timed out): the same SHA is retried under a new ref (`-r1`, `-r2`, …), while retries of `infraRetries` are left. The detail reads `retry <n>/<infraRetries>: …`. | Nothing. |
| `infra-paused` | An infrastructure failure (or a timeout) with no retry of `infraRetries` left: the base is paused with reason `infra`. With the shipped `infraRetries: 1` that is the second failure; with `0`, the first. When every run only hit a job time limit, the outcome is `hang-suspected` instead (see its row). A base repair under a `base-red` pause is dropped instead, with an `error` event, and the `base-red` pause stays. | Check the Actions status and the candidate's run, then `npm run queue -- resume <base>`. |
| `paused` | A manual pause (`npm run queue -- pause`, or `action=pause`). The detail is the reason, on one line, cut at 200 characters. | `npm run queue -- resume <base>` when ready. |
| `resumed` | A manual resume (`manual resume (was <reason>)`, followed by `; the pause it cleared named commits kept nowhere (both lists full), check their <landing.statusContext> by hand: <sha> (<batchId>), …` when that pause named such commits), a `base-red` pause lifted because the base tip moved (`base moved <sha12> → <sha12> after a base-red pause`), or, in live mode, a `base-red` pause lifted because a PR of the base-repair lane landed (`base repaired by #<n>`). Neither automatic lift happens while `landWithdrawalsOverflow` holds entries: a tick replaces such a `base-red` pause with the full-list pause. | For a detail that names commits kept nowhere: check their land status by hand (see [Paused: landWithdrawals is full](#paused-landwithdrawals-is-full)). Otherwise nothing. |
| `tree-divergence` | `squash-api` only: the base tree after the merges differs from the candidate tree, or an open divergence issue stops a landing. The base is paused with reason `tree-divergence`. | Compare the trees, fix the base, close the issue, resume (see [Tree divergence](#tree-divergence-squash-api-only)). |
| `error` | A tick failed (the detail is its error message); a landing pause (reason `error`: land token, landing refused, composition mismatch, queue refs, base not found, attempts limit); a land-status withdrawal GitHub refused (`<batchId>: could not withdraw …`); a stored withdrawal refused for a day (`… has been refused for more than 24 h, since …; the queue keeps retrying it`); a refused withdrawal that found the `landWithdrawals` list (20) full, kept in `landWithdrawalsOverflow` (`landWithdrawals is full …`; it pauses a base that is not paused, or replaces a `base-red` pause, also one a tick loads together with overflow entries); a refused resume (`resume refused: …`, the pause stays); a candidate gone from origin (`… is gone from origin; recomposing …`), whose PRs are recomposed; check runs on the candidate that are no job of its push runs (`check runs on the candidate that are not jobs of its push runs, ignored for the verdict: …`, once per batch); a base repair dropped after an infrastructure failure under a `base-red` pause (`… failed for infrastructure after … dropped; the base-red pause stays`). A tick that hit a rate limit while landing fails with `landing <batchId> hit a rate limit (…)`. The detail says which. | Read the detail: each pause detail, and each other `error` detail an operator must act on, has an entry in [Incidents](#incidents). A landing that fails on every tick ends in the pause after three attempts. |
| `queue-stalled` | The queue stopped making progress: paused for more than 120 minutes (with reason `error` or `tree-divergence`, at once), a candidate in flight for more than `checksTimeoutMinutes` + 60, eligible PRs and nothing started for more than `batch.maxWaitMinutes` + 30, three ticks in a row that failed, a stored withdrawal refused for more than 60 minutes, or three landings in a row without a verdict. One per episode, with one comment on the dashboard issue that mentions the approvers (see [Health](#health)). The detail lists the reasons. | See [The queue stalled](#the-queue-stalled). |
| Event | When it happens | What the operator does |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `batch-started` | A candidate was composed and pushed: a new batch, a recomposition or a bisection segment. The detail names the PRs and the base, and for a root batch with `batch.adaptive` the window it was cut to (`window W`). A lane batch names its lane instead of a window (`lane hotfix` or `lane base-repair`). | Nothing. Its CI is linked from the dashboard. |
| `pr-skipped-conflict` | A PR conflicts with an earlier PR of the same batch. It is left out of this candidate and stays queued for a later batch. | Nothing. If it repeats, the author rebases the PR over the one it conflicts with. |
| `pr-dequeued` | A PR left the queue: `base-conflict` (it no longer merges into the base: label removed, comment), `already-in-base` (both labels removed, comment), or `withdrawn: <why>` before composition (label, head or approval changed). In shadow mode the first two are `would-dequeue` events instead. | For `base-conflict` the author updates the branch and an approver labels it again; the other cases need nothing. |
| `checks-green` | Every required check of the candidate (or of a base check) concluded `success`. | Nothing. The landing (or `would-land`) follows. |
| `checks-red` | A check of the candidate failed. The detail names the failing checks; on a base check it starts with `base-check red`. It ends with `; re-run refused (<status or reason>)` when the re-run of the failed jobs was refused. A batch red again after its re-run records a second one. | Nothing yet: classification follows (a re-run of the failed jobs, infra retry, base check, bisection or culprit). |
| `flaky-rerun` | A red batch or bisection segment that would be bisected, tested against the base or dequeued: its failed jobs are re-run once after its runs end (`flakyReruns`). Detail: `re-running the failed jobs of <batch> once (<jobs>) before <bisecting\|a base check\|dequeuing #n>` (five jobs at most). A green re-run's `checks-green` reads `green after re-running <jobs> (flaky)`. | Nothing. A real failure is blamed later: after the rest of the CI run and the re-run. Jobs that often turn green on the re-run are flaky tests to fix. |
| `checks-timeout` | No verdict after `checksTimeoutMinutes`, or no CI run at all after 45 minutes (`no CI run for candidate`). | For `no CI run`, check the Actions policies and the `omni-queue/**` triggers of `ci.yml` / `quality.yml` (see [Infra failure or timeout](#infra-failure-or-timeout)). |
| `land-blessed` | Live mode: the App wrote the land status (`landing.statusContext`, `success`) on the commits about to land, right before the landing. | Nothing. A `landed` event should follow; if a pause follows, the status was withdrawn. |
| `manual-bless` | An approver's `bless`: the App wrote the land status on one chosen commit. The detail names who and why. | Push or merge that commit yourself (see [Land status and manual bless](#land-status-and-manual-bless)). |
| `landed` | Live mode: the batch reached the base (the `merge-ff` push or every `squash-api` merge). | Nothing. |
| `would-land` | Shadow mode: a green batch that live mode would have landed. The detail can add `merged meanwhile by another path`, `live mode would pause: queue refs unprotected (…)` and, after the name of a check, `could not run (…): live mode would fail the tick`. | Compare with what Mergify merged. Both notes must be gone before `mode: "live"`: apply the queue-refs ruleset, or fix the check that could not run. |
| `would-dequeue` | Shadow mode: live mode would have removed this PR from the queue (label kept, no comment). The detail gives the reason code(s). | Nothing during shadow. |
| `land-rejected` | The batch was not landed: the base moved (`base moved…; recomposing`: the same PRs are recomposed on the tip), the batch changed before landing (`batch changed before landing: …`: the PRs left are recomposed), or a release-freeze holds it (`base-frozen: …; <batch> waits for the freeze to lift`, once per batch: it stays in flight, not recomposed, and lands after the freeze). | Nothing for an occasional one; frequent ones mean something else merges into the base (see [Recomposition when the base moves](#recomposition-when-the-base-moves)). |
| `bisect-split` | A red batch (or a red segment of a bisection) is split; the detail names the segment tested next. | Nothing. |
| `culprit-found` | Bisection or a batch of one isolated the PR that fails. Live: label removed, comment. Shadow, or a head that moved: label kept. | The author fixes the PR and an approver labels it again. |
| `base-check-started` | A red batch on a base with no verdict: the bare base is pushed as a `basecheck-<sha12>` candidate. | Nothing. |
| `base-red-paused` | The base check is red with the same failures as the batch: the base is paused with reason `base-red`. | Fix the base (see [Base-red](#base-red)). The pause lifts when the tip moves. |
| `hang-suspected` | A job hit its time limit on every run of the candidate: treated as a hanging test (base check, then bisection) instead of an infra pause. | Nothing yet; look at the culprit comment when one is named. |
| `infra-retry` | Every failure is infrastructure (or the checks timed out): the same SHA is retried under a new ref (`-r1`, `-r2`, …), while retries of `infraRetries` are left. The detail reads `retry <n>/<infraRetries>: …`. | Nothing. |
| `infra-paused` | An infrastructure failure (or a timeout) with no retry of `infraRetries` left: the base is paused with reason `infra`. With the shipped `infraRetries: 1` that is the second failure; with `0`, the first. When every run only hit a job time limit, the outcome is `hang-suspected` instead (see its row). A base repair under a `base-red` pause is dropped instead, with an `error` event, and the `base-red` pause stays. | Check the Actions status and the candidate's run, then `npm run queue -- resume <base>`. |
| `paused` | A manual pause (`npm run queue -- pause`, or `action=pause`). The detail is the reason, on one line, cut at 200 characters. | `npm run queue -- resume <base>` when ready. |
| `resumed` | A manual resume (`manual resume (was <reason>)`, followed by `; the pause it cleared named commits kept nowhere (both lists full), check their <landing.statusContext> by hand: <sha> (<batchId>), …` when that pause named such commits), a `base-red` pause lifted because the base tip moved (`base moved <sha12> → <sha12> after a base-red pause`), or, in live mode, a `base-red` pause lifted because a PR of the base-repair lane landed (`base repaired by #<n>`). Neither automatic lift happens while `landWithdrawalsOverflow` holds entries: a tick replaces such a `base-red` pause with the full-list pause. | For a detail that names commits kept nowhere: check their land status by hand (see [Paused: landWithdrawals is full](#paused-landwithdrawals-is-full)). Otherwise nothing. |
| `tree-divergence` | `squash-api` only: the base tree after the merges differs from the candidate tree, or an open divergence issue stops a landing. The base is paused with reason `tree-divergence`. | Compare the trees, fix the base, close the issue, resume (see [Tree divergence](#tree-divergence-squash-api-only)). |
| `error` | A tick failed (the detail is its error message); a landing pause (reason `error`: land token, landing refused, composition mismatch, queue refs, base not found, attempts limit); a land-status withdrawal GitHub refused (`<batchId>: could not withdraw …`); a stored withdrawal refused for a day (`… has been refused for more than 24 h, since …; the queue keeps retrying it`); a refused withdrawal that found the `landWithdrawals` list (20) full, kept in `landWithdrawalsOverflow` (`landWithdrawals is full …`; it pauses a base that is not paused, or replaces a `base-red` pause, also one a tick loads together with overflow entries); a refused resume (`resume refused: …`, the pause stays); a candidate gone from origin (`… is gone from origin; recomposing …`), whose PRs are recomposed; check runs on the candidate that are no job of its push runs (`check runs on the candidate that are not jobs of its push runs, ignored for the verdict: …`, once per batch); a base repair dropped after an infrastructure failure under a `base-red` pause (`… failed for infrastructure after … dropped; the base-red pause stays`); a batch composed unsigned although `landing.signing` is `ssh` (`<batchId>: <n> merge commit(s) composed unsigned: …`, once per batch); the owner voice falling back to the App's token (`owner voice unavailable, written with the App's token instead: …`, at most once per tick). A tick that hit a rate limit while landing fails with `landing <batchId> hit a rate limit (…)`. The detail says which. | Read the detail: each pause detail, and each other `error` detail an operator must act on, has an entry in [Incidents](#incidents). A landing that fails on every tick ends in the pause after three attempts. |
| `queue-stalled` | The queue stopped making progress: paused for more than 120 minutes (with reason `error` or `tree-divergence`, at once), a candidate in flight for more than `checksTimeoutMinutes` + 60, eligible PRs and nothing started for more than `batch.maxWaitMinutes` + 30, three ticks in a row that failed, a stored withdrawal refused for more than 60 minutes, or three landings in a row without a verdict. One per episode, with one comment on the dashboard issue that mentions the approvers (see [Health](#health)). The detail lists the reasons. | See [The queue stalled](#the-queue-stalled). |
## Configuration keys
`config/merge-queue/config.json`, validated by `validateConfig` in `scripts/merge-queue/config.mjs`.
The workflow reads the copy on the default branch. Every key without a default is required, except
`landing.identity`, which is required or refused depending on `landing.actor` (see its row). An
unknown key, top-level or in `batch`, `landing`, `landing.identity` or `lanes`, is refused.
`landing.identity`, which is required or refused depending on `landing.actor` (see its row), and
`landing.signing: "ssh"`, which needs `landing.actor: "owner"`. An unknown key, top-level or in
`batch`, `landing`, `landing.identity` or `lanes`, is refused.
"Shipped" is the value in the config file of this repository.
`tests/unit/merge-queue/runbook.test.mjs` fails when this table and the keys `validateConfig` reads
differ.
@@ -1106,6 +1221,7 @@ differ.
| `landing.mode` | `merge-ff` or `squash-api` | none; shipped `merge-ff` | How a green batch lands (see [Landing modes](#landing-modes-landingmode)). |
| `landing.actor` | `app` or `owner` | `app`; shipped `owner` | Whose token lands: the App's, or `OMNI_QUEUE_LAND_TOKEN` (see [Who lands](#who-lands-landingactor)). |
| `landing.identity` | `{name, email}`, the email a `@users.noreply.github.com` one | none; required with `actor: "owner"`, refused otherwise | Identity of the queue's merge commits when the owner lands. |
| `landing.signing` | `none` or `ssh` | `none`; shipped `none` | `ssh` signs every merge commit the queue composes with the key of the secret OMNI_QUEUE_SIGNING_KEY; refused unless `landing.actor` is `owner` (see [Signed merge commits](#signed-merge-commits-landingsigning)). |
| `landing.statusContext` | `omni-queue/<name>`, `[A-Za-z0-9._/-]{1,100}` | `omni-queue/land`; shipped `omni-queue/land` | The land status the release ruleset requires. Must not be a required, aggregate or approval context. |
| `requiredChecks` | list of check names, at least one | none; shipped three checks | Checks that must conclude `success` on a candidate (see [Accepting a candidate](#accepting-a-candidate)). |
| `advisoryChecks` | list of check names, none in `requiredChecks` | none; shipped `Build (advisory)` | Checks whose failure does not make a candidate red. |
@@ -1118,6 +1234,7 @@ differ.
| `prChecksRequired` | list of distinct check names | `[]`; shipped `Gate / CI`, `Gate / Quality`, `API Route Typecheck` | Green on a PR head to enter a batch: worst of the suites reporting it; if they disagree, a run superseded by a newer run of the same workflow and event drops ([Eligibility](#eligibility)). |
| `protectedPaths` | list of globs, at least one | none; shipped the agent-instruction surfaces and the queue's control plane | A PR that touches one also needs `protectedApprovalLabel` (see [Eligibility](#eligibility)). |
| `lanes.hotfixLabel` | label name, distinct from every other label of the config | no `lanes` = no lanes; shipped `omni-queue-hotfix` | Applied by an approver to an eligible PR: at the next batch start it is composed alone, ahead of the FIFO. Never replaces what is in flight. Repeated in the tick's job filter. |
| `voice` | `app` or `owner` | `app`; shipped `app` | Whose token posts the queue's comments, removes its labels and writes its issues: the App's, or `OMNI_QUEUE_LAND_TOKEN`, with a fallback to the App's (see [Who speaks](#who-speaks-voice)). |
| `lanes.baseRepairLabel` | label name, distinct from every other label of the config | no `lanes` = no lanes; shipped `omni-queue-base-repair` | Applied by an approver: composed alone (PR gates not required), the only work of a `base-red` pause; its landing lifts the pause. Never in a FIFO batch. Repeated in the tick's job filter. A repair that fails like the base is not composed again at that head (`repairTried`): push a fix (a new head is tried again), or remove this label (anyone who can label the PR can): the PR rejoins the FIFO. |
## CLI
@@ -1426,16 +1543,16 @@ action.
3. **Homepage URL**: the repository URL. **Webhook**: untick "Active" (the queue needs no webhook).
4. **Repository permissions**:
| Permission | Access | What the queue does with it |
| --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Contents | Read and write | tick: push candidate branches, read and write `state/<base>.json` on `omni-queue-state`, delete candidate branches, read base tips and commits; with `landing.actor: "app"`, the landing push or merges too. approval: read |
| Pull requests | Read and write | tick: read each queued PR (head, base, files, mergeability); write: only the per-PR merge of `squash-api` with `landing.actor: "app"` (`PUT /repos/{owner}/{repo}/pulls/{n}/merge`). Labels and comments on PRs go through the issues endpoints. With the shipped config (`owner`, `merge-ff`) no call of the App uses write here. approval: read the PR |
| Issues | Read and write | tick: the dashboard issue and its stalled comment, comments on the `base-red` issue, the tree-divergence issue, reading `release-freeze` issues and PR timelines, removing labels from and commenting on PRs (live mode only). approval: the "not an approver" comment |
| Commit statuses | Read and write | approval: write `omni-queue/approval` and `omni-queue/protected-approval`. tick: read them, write and withdraw the land status, `bless` |
| Workflows | Read and write | tick: push a candidate (and, with `landing.actor: "app"`, land it) when a PR of the batch changes a file under `.github/workflows/` |
| Checks | Read-only | tick: the check runs and annotations of a candidate, and the PR gates of a PR head |
| Actions | Read and write | tick: list the workflow runs of a candidate ref and of a PR head (read); re-run the failed jobs of a red candidate (write, `flakyReruns`) |
| Metadata | Read-only | always granted |
| Permission | Access | What the queue does with it |
| --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Contents | Read and write | tick: push candidate branches, read and write `state/<base>.json` on `omni-queue-state`, delete candidate branches, read base tips and commits; with `landing.actor: "app"`, the landing push or merges too. approval: read |
| Pull requests | Read and write | tick: read each queued PR (head, base, files, mergeability); write: only the per-PR merge of `squash-api` with `landing.actor: "app"` (`PUT /repos/{owner}/{repo}/pulls/{n}/merge`). Labels and comments on PRs go through the issues endpoints. With the shipped config (`owner`, `merge-ff`) no call of the App uses write here. approval: read the PR |
| Issues | Read and write | tick: the dashboard issue and its stalled comment, comments on the `base-red` issue, the tree-divergence issue, reading `release-freeze` issues and PR timelines, removing labels from and commenting on PRs (live mode only); with `voice: "owner"` the App makes these writes only when the owner's token is missing or refused. approval: the "not an approver" comment |
| Commit statuses | Read and write | approval: write `omni-queue/approval` and `omni-queue/protected-approval`. tick: read them, write and withdraw the land status, `bless` |
| Workflows | Read and write | tick: push a candidate (and, with `landing.actor: "app"`, land it) when a PR of the batch changes a file under `.github/workflows/` |
| Checks | Read-only | tick: the check runs and annotations of a candidate, and the PR gates of a PR head |
| Actions | Read and write | tick: list the workflow runs of a candidate ref and of a PR head (read); re-run the failed jobs of a red candidate (write, `flakyReruns`) |
| Metadata | Read-only | always granted |
Each job mints its token with only part of this (the `approval` job: contents and pull requests
read, issues and statuses write; the `tick` job: everything above). The tick also reads the
@@ -1488,6 +1605,9 @@ action.
Secrets: OMNI_QUEUE_APP_CLIENT_ID the Client ID from step 5
OMNI_QUEUE_APP_PRIVATE_KEY the full contents of the .pem from step 6
OMNI_QUEUE_LAND_TOKEN the owner's fine-grained token (see below)
OMNI_QUEUE_SIGNING_KEY optional: the owner's SSH signing key, only
for landing.signing "ssh" (see Signed merge
commits)
Repository variable (Settings → Secrets and variables → Actions → Variables)
OMNI_QUEUE_ENABLED "true" only when the queue should run
```
@@ -1500,7 +1620,24 @@ action.
write the expiry date down and rotate it before then. GitHub requires the Workflows permission
for a push of commits that change files under `.github/workflows/`, and the landing is made with
this token: without it, the landing of every batch that touches a workflow is refused. The token
is optional while the queue runs in shadow mode (see [Who lands](#who-lands-landingactor)).
is optional while the queue runs in shadow mode (see [Who lands](#who-lands-landingactor)),
unless `voice` is `owner`.
With `voice: "owner"` ([Who speaks](#who-speaks-voice)) the same token also needs **Issues: Read
and write**: opening and updating an issue (the dashboard, the tree-divergence issue) and
commenting on an issue (the dashboard, the `base-red` issue) are Issues endpoints. Comments on
pull requests and the removal of a label from a pull request are already covered by Pull
requests: Read and write. GitHub's table of
[permissions required for fine-grained personal access tokens](https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens)
lists `POST /repos/{owner}/{repo}/issues` under Issues (write) only;
`PATCH /repos/{owner}/{repo}/issues/{issue_number}`,
`POST /repos/{owner}/{repo}/issues/{issue_number}/comments`,
`DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}` and
`DELETE /repos/{owner}/{repo}/issues/{issue_number}/labels/{name}` under both Issues (write) and
Pull requests (write), marked as needing additional permissions, which on an issue are Issues.
The tick also reads the owner's login with `GET /user`, which that table does not list. A
missing permission is a 403: the write is made by the App (see [Who speaks](#who-speaks-voice)),
and the `error` event names it.
Both jobs of `.github/workflows/omni-queue.yml` declare this environment with
`deployment: false`: they get its secrets and its branch policy, and no deployment record is
@@ -1557,7 +1694,9 @@ this order:
exact name, step 8 above);
2. put its secrets in it: OMNI_QUEUE_APP_CLIENT_ID and OMNI_QUEUE_APP_PRIVATE_KEY, and
`OMNI_QUEUE_LAND_TOKEN`. A shadow run never lands, so it works without the land token, but a live
landing needs it: have it in place at the latest before `mode: "live"`;
landing needs it: have it in place at the latest before `mode: "live"`, and before `voice` is
set to `owner` (shadow mode writes the dashboard issue with it). OMNI_QUEUE_SIGNING_KEY only
before `landing.signing` is set to `ssh`;
3. check that the App's installation has every permission of step 4 above, Actions: Read and
write included, and that the labels of step 9 exist;
4. in a public repository, create the Actions policy that allows the events of
@@ -1871,6 +2010,38 @@ the pause. While no ruleset requiring the status is applied to the branch (the c
before the cut-over), a bless changes nothing about what can be pushed: it only records the status
and the event.
## What appears as the owner and what appears as the App
With the shipped config (`landing.actor: "owner"`, `voice: "app"`, `landing.signing: "none"`):
| On GitHub | Appears as |
| --------------------------------------------------------------- | ---------------------------------------- |
| "merged by" on a landed pull request (the `merge-ff` push) | the owner (`OMNI_QUEUE_LAND_TOKEN`) |
| author and committer of the queue's merge commits | `landing.identity` (the owner), unsigned |
| every comment on a pull request, every label removal | the App (`omni-queue[bot]`) |
| the dashboard issue, its body, its comments (the stalled alert) | the App |
| comments on the `base-red` issue, the tree-divergence issue | the App |
| commit statuses (`omni-queue/land`, both approvals, a bless) | the App, always |
With `voice: "owner"` the third to fifth rows become the owner (each one the App's again when the
owner's token is missing or refused), and with `landing.signing: "ssh"` the merge commits are
signed with the owner's key.
**Always the App, whatever the config**, and why:
- every commit status: `omni-queue/land` (the release ruleset's door pins it to the App's
integration id), `omni-queue/approval`, `omni-queue/protected-approval`, a `bless`;
- candidate branches `omni-queue/**` and the `omni-queue-state` branch (the queue-refs ruleset
admits the App only);
- re-runs of a candidate's failed jobs;
- every read, including the comment listings the markers are checked against;
- the `approval` job's "not an approver" comment: that job never receives the owner's token;
- a write the owner's token cannot make (missing token, 401 or 403): the App makes it instead, and
an `error` event says so.
**The watchdog speaks as `github-actions[bot]`**: its issue and comments use the workflow's own
token on purpose, so it works when the environment's secrets fail.
## Security posture
- **No PR code runs in the queue workflow.** Both jobs check out the default branch (sparse:
@@ -1887,7 +2058,18 @@ and the event.
trigger on candidate branches.
- **Least privilege**: one App token per job with only the permissions that job needs; the
workflow's own `GITHUB_TOKEN` is read-only. The owner's `OMNI_QUEUE_LAND_TOKEN` reaches only the
tick step, and only the landing uses it.
tick step; the landing uses it with `landing.actor: "owner"`, and the queue's comments, label
removals and issues with `voice: "owner"` (never a commit status, a ref, the state branch or a
re-run). The `approval` job never receives it.
- **The signing key** (OMNI_QUEUE_SIGNING_KEY, `landing.signing: "ssh"`) reaches one step of the
tick job, which writes it to a `0600` file under `RUNNER_TEMP`; the job's last step removes it
(`if: always()`). git gets the path as per-command configuration through the environment, never
as an argument; no log line, event, state, comment or error message holds the key or its path.
A signature changes nothing the queue verifies (see
[Signed merge commits](#signed-merge-commits-landingsigning)).
- **Comment markers are trusted by author**: only markers written by `<appSlug>[bot]`, or by the
owner's login read from the owner's token itself, count; a marker anybody else writes is
ignored.
- **The App key is the root of trust of the status door.** Whoever can use it can write the land
status on any commit. Both jobs run in the `omni-queue` environment, which holds the App's
credentials and the land token and admits the default branch only, so a workflow on a candidate
@@ -1897,6 +2079,9 @@ and the event.
message and escaped in the dashboard; git runs through `scripts/merge-queue/gitexec.mjs` (no
shell, token in the environment as an HTTP header, OMNI_QUEUE_TOKEN and `OMNI_QUEUE_LAND_TOKEN`
removed from the environment of every git process, redacted errors).
- **One thing still speaks as `github-actions[bot]`**: the watchdog
(`.github/workflows/omni-queue-watchdog.yml`, `scripts/merge-queue/watchdog.mjs`) uses its
workflow's own token on purpose, so it keeps working when the environment's secrets fail.
- **Approvals are bound to SHAs**, never to commit dates (see [Eligibility](#eligibility)).
## Incidents
@@ -2160,6 +2345,31 @@ discovery (red runs with `setup failed` or `base discovery failed`, see
that is pending forever (only one tick runs at a time, by design); a closed dashboard issue, on a
base whose only work is not a labeled PR (see [State](#state)).
### Owner voice unavailable
`error` event `owner voice unavailable, written with the App's token instead: <cause>` (with
`voice: "owner"`). Nothing was lost: every write of that tick was made by the App. By cause:
- `OMNI_QUEUE_LAND_TOKEN is not set`: put the token in the environment `omni-queue`;
- `GitHub refused the owner's token (401)` or `… reading its login (401)`: the token expired or was
revoked: rotate it;
- `GitHub refused the owner's token (403)`: a permission is missing, most often Issues: Read and
write (see [Installing the GitHub App](#installing-the-github-app), step 8);
- `the owner's token does not name a user account`: the secret holds some other token.
The event is not repeated while the cause stays the same; the decisions of every tick that falls
back say which write did.
### Merge commits composed unsigned
`error` event `<batchId>: <n> merge commit(s) composed unsigned: <cause>` (with
`landing.signing: "ssh"`). The batch was composed, tested and (live) lands as usual, without the
signature. `no signing key file in the job …`: the secret OMNI_QUEUE_SIGNING_KEY is missing from
the environment or the step that writes it warned that it could not. `git could not sign a merge
commit (exit <code>)`: the secret is not an unencrypted SSH private key (a passphrase, a public key,
a truncated paste); store the private key file's full contents again. To stop signing, set
`landing.signing` back to `none`.
### Dequeued PR
What you see, in live mode: a comment on the PR that starts "❌ omni-queue isolated this PR as the

View File

@@ -929,6 +929,7 @@ REQUEST_TIMEOUT_MS (global override)
| `OMNIROUTE_AGENT_GOAL_READINESS_MAX_TIMEOUT_MS` | `600000` | Maximum first-event readiness window for detected `/goal` agent runs or requests forced with `x-omniroute-agent-goal`. |
| `OMNIROUTE_AGENT_GOAL_STREAM_RECOVERY` | `true` | Enable early stream recovery automatically for detected `/goal` agent runs. Set `false`/`0`/`off` to disable the goal-specific opt-in. This can only ADD recovery on top of the operator default — it never overrides an explicit `STREAM_RECOVERY_ENABLED`/DB settings opt-out. |
| `OMNIROUTE_CODEX_DROP_NONSTANDARD_EVENTS` | `true` | Strip non-standard `codex.*` SSE events (e.g. `codex.rate_limits`) that break the OpenAI SDK's `responses.stream()` with a 502. Default ON (#11014). Set `0`/`false`/`no`/`off` to forward them. |
| `OMNIROUTE_CODEX_PLAN_RESPONSE_HEADER` | `0` (off) | Opt-in Codex OAuth troubleshooting response header. Set to `1` to emit `X-OmniRoute-Selected-Connection-Plan` with the recognized plan tier of the selected Codex connection. Not sent for non-Codex requests or unrecognized plans. Avoid enabling on public or multi-tenant gateways where subscription metadata is private. |
| `OMNIROUTE_CODEX_APPSERVER_WS` | _(unset)_ | Opt-in Codex app-server transport. WebSocket endpoint (`ws://`/`wss://`) of a local `codex app-server` sidecar. When set together with a token, Codex requests are routed over JSON-RPC to the sidecar instead of the HTTP Responses API. Also settable per-connection via `providerSpecificData.codexAppServerUrl`. Used by `open-sse/executors/codex/appServerConfig.ts`. |
| `OMNIROUTE_CODEX_APPSERVER_WS_TOKEN` | _(unset)_ | Inline capability/bearer token presented to the app-server. Per-connection override: `providerSpecificData.codexAppServerToken`. |
| `OMNIROUTE_CODEX_APPSERVER_WS_TOKEN_FILE` | _(unset)_ | Path to a file holding the app-server capability token (from `codex app-server --ws-token-file`). Used when `OMNIROUTE_CODEX_APPSERVER_WS_TOKEN` is unset. Per-connection override: `providerSpecificData.codexAppServerTokenFile`. |

View File

@@ -83,6 +83,23 @@ export const codexProvider: RegistryEntry = {
},
{ id: "gpt-6.1-sol-medium", name: "GPT 6.1 Sol (Medium)", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6.1-sol-low", name: "GPT 6.1 Sol (Low)", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6.1-terra", name: "GPT 6.1 Terra", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6.1-terra-ultra", name: "GPT 6.1 Terra (Ultra)", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6.1-terra-max", name: "GPT 6.1 Terra (Max)", ...GPT_5_6_CODEX_CAPABILITIES },
{
id: "gpt-6.1-terra-xhigh",
name: "GPT 6.1 Terra (xHigh)",
...GPT_5_6_CODEX_CAPABILITIES,
timeoutMs: 1200000,
},
{
id: "gpt-6.1-terra-high",
name: "GPT 6.1 Terra (High)",
...GPT_5_6_CODEX_CAPABILITIES,
timeoutMs: 1200000,
},
{ id: "gpt-6.1-terra-medium", name: "GPT 6.1 Terra (Medium)", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6.1-terra-low", name: "GPT 6.1 Terra (Low)", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6-luna", name: "GPT 6 Luna", ...GPT_5_6_CODEX_CAPABILITIES },
{ id: "gpt-6-luna-max", name: "GPT 6 Luna (Max)", ...GPT_5_6_CODEX_CAPABILITIES },
{

View File

@@ -22,6 +22,16 @@ export const openaiProvider: RegistryEntry = {
...GPT_5_6_API_CAPABILITIES,
unsupportedParams: ["temperature", "top_p", "top_logprobs", "logprobs"],
},
// https://developers.openai.com/api/docs/models/gpt-6.1-terra
{
id: "gpt-6.1-terra",
name: "GPT-6.1 Terra",
...GPT_5_6_API_CAPABILITIES,
// Unlike Sol/Astra, Terra accepts sampling with reasoning.effort="none".
// The effort-aware GPT sampling guard strips these fields only with
// active reasoning; static unsupportedParams would strip them always.
supportedThinkingEfforts: ["none", "low", "medium", "high", "xhigh", "max"],
},
// Astra shares the public GPT-5.6 limits; tool calling requires Responses.
// https://developers.openai.com/api/docs/guides/latest-model
{

View File

@@ -10,6 +10,7 @@ export const CODEX_EFFORT_ORDER = [
export type CodexEffortLevel = (typeof CODEX_EFFORT_ORDER)[number];
export const CODEX_MAX_ALIAS_MODELS = new Set([
"gpt-6.1-sol",
"gpt-6.1-terra",
"gpt-5.6-sol",
"gpt-5.6-terra",
"gpt-5.6-luna",
@@ -20,6 +21,7 @@ export const CODEX_MAX_ALIAS_MODELS = new Set([
]);
export const CODEX_ULTRA_ALIAS_MODELS = new Set([
"gpt-6.1-sol",
"gpt-6.1-terra",
"gpt-5.6-sol",
"gpt-5.6-terra",
"gpt-6-astra",

View File

@@ -1015,6 +1015,10 @@ async function handleChatCoreInner({
)) || null;
const pipelineSessionId = explicitSessionIdHeader || skillRequestId;
const reasoningReplaySessionKey = sessionAffinityKey || explicitSessionIdHeader;
// One upstream Antigravity session per conversation (prompt-cache scope); the
// non-streaming server-tool follow-up leg must reuse it, or it falls back to the
// account-wide session and evicts parallel conversations' caches.
const antigravitySessionKey = conversationId || sessionAffinityKey || null;
const reasoningCacheScope = buildReasoningCacheScope(
apiKeyInfo?.id,
reasoningReplaySessionKey ? String(reasoningReplaySessionKey) : null
@@ -2457,6 +2461,7 @@ async function handleChatCoreInner({
signatureNamespace: connectionId,
copilotClient: copilotCompatibleReasoning,
reasoningCacheScope,
antigravitySessionKey,
videoTranscriptSensitive: videoBridgeObserved,
onReasoningReplayHistory: (messages) => {
reasoningReplayHistory = messages;
@@ -3504,6 +3509,7 @@ async function handleChatCoreInner({
persistFailureUsage,
pipelineRecovered,
pipelineSessionId,
antigravitySessionKey,
preserveCacheControl,
provider,
providerHeaders,

View File

@@ -209,6 +209,7 @@ export async function runNonStreamingResponse(deps: NonStreamingDeps) {
isResponsesEndpoint,
preserveCacheControl,
reasoningCacheScope,
antigravitySessionKey,
requestToolIdentityMap,
stream,
toolNameMap,
@@ -574,6 +575,7 @@ export async function runNonStreamingResponse(deps: NonStreamingDeps) {
signatureNamespace: connectionId,
copilotClient: copilotCompatibleReasoning,
reasoningCacheScope,
antigravitySessionKey,
onReasoningReplayHistory: (messages) => {
reasoningReplayHistory = messages;
},

View File

@@ -24,6 +24,7 @@ import { mapImageSize } from "../translator/image/sizeMapper.ts";
import { getCodexClientVersion, getCodexUserAgent } from "../config/codexClient.ts";
import { isCodexFreePlan } from "../executors/codex/tools.ts";
import { sleep } from "../utils/sleep.ts";
import { clampPollIntervalMs, clampPollTimeoutMs } from "../utils/pollBounds.ts";
import { codexReferenceImageUrl } from "./imageGeneration/providers/codexReferences.ts";
export { shrinkCodexReferenceImage } from "./imageGeneration/providers/codexReferences.ts";
import {
@@ -2965,11 +2966,11 @@ async function handleNanoBananaImageGeneration({
return { success: false, status: 500, error: errorText };
}
const timeoutMs = normalizePositiveNumber(
const timeoutMs = clampPollTimeoutMs(
body.timeout_ms,
normalizePositiveNumber(process.env.NANOBANANA_POLL_TIMEOUT_MS, 120000)
);
const pollIntervalMs = normalizePositiveNumber(
const pollIntervalMs = clampPollIntervalMs(
body.poll_interval_ms,
normalizePositiveNumber(process.env.NANOBANANA_POLL_INTERVAL_MS, 2500)
);

View File

@@ -7,11 +7,11 @@
import { mapImageSize } from "../../../translator/image/sizeMapper.ts";
import { sleep } from "../../../utils/sleep.ts";
import { clampPollIntervalMs, clampPollTimeoutMs } from "../../../utils/pollBounds.ts";
import { sanitizeErrorMessage } from "../../../utils/error.ts";
import {
extractImageInputs,
isHttpUrl,
normalizePositiveNumber,
normalizeProviderImagePayload,
normalizeRequestedImageFormat,
parseSizeToDimensions,
@@ -180,8 +180,8 @@ export async function handleBlackForestLabsImageGeneration({
}
async function pollBlackForestLabsResult({ pollingUrl, token, body, log }) {
const timeoutMs = normalizePositiveNumber(body.timeout_ms, 300000);
const pollIntervalMs = normalizePositiveNumber(body.poll_interval_ms, 1500);
const timeoutMs = clampPollTimeoutMs(body.timeout_ms, 300000);
const pollIntervalMs = clampPollIntervalMs(body.poll_interval_ms, 1500);
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {

View File

@@ -40,6 +40,51 @@ export function resolveLeonardoImageSize(body: {
};
}
// init_strength (0.1-0.9) is how closely the output follows the edit reference. In a live
// check 0.3 kept the reference's composition and still applied the edit prompt (#18671).
const LEONARDO_EDIT_INIT_STRENGTH = 0.3;
const LEONARDO_INIT_IMAGE_EXTENSIONS: Record<string, string> = {
"image/png": "png",
"image/jpeg": "jpg",
"image/jpg": "jpg",
"image/webp": "webp",
};
/**
* Uploads an edit reference through Leonardo's init-image flow (a presigned S3 form post,
* which must not carry the Leonardo token) and returns the init image id.
*/
export async function uploadLeonardoInitImage(
generationsUrl: string,
token: string,
image: { bytes: Buffer; mime: string }
): Promise<string> {
const res = await fetch(generationsUrl.replace(/\/generations$/, "/init-image"), {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
body: JSON.stringify({ extension: LEONARDO_INIT_IMAGE_EXTENSIONS[image.mime] ?? "png" }),
});
if (!res.ok) throw new Error(`Leonardo init-image request failed: HTTP ${res.status}`);
const { uploadInitImage } = await res.json();
const form = new FormData();
for (const [key, value] of Object.entries(JSON.parse(uploadInitImage.fields))) {
form.append(key, String(value));
}
form.append("file", new Blob([new Uint8Array(image.bytes)], { type: image.mime }), "init");
// Send the multipart body pre-encoded: a FormData body handed to OmniRoute's patched
// fetch reached S3 as HTTP 412, while the same form as bytes plus its boundary header is
// accepted (204).
const encoded = new Response(form);
const upload = await fetch(uploadInitImage.url, {
method: "POST",
headers: { "Content-Type": encoded.headers.get("content-type") || "" },
body: Buffer.from(await encoded.arrayBuffer()),
});
if (!upload.ok) throw new Error(`Leonardo init-image upload failed: HTTP ${upload.status}`);
return uploadInitImage.id;
}
export async function handleLeonardoImageGeneration({
model,
provider,
@@ -48,14 +93,23 @@ export async function handleLeonardoImageGeneration({
credentials,
log,
pollIntervalMs = 5000,
// An edit reference (/v1/images/edits): the generation becomes image-to-image.
initImage = null,
}) {
const startTime = Date.now();
const logPath = initImage ? "/v1/images/edits" : "/v1/images/generations";
const token = credentials?.apiKey || "";
const prompt = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? "");
if (log) {
log.info("IMAGE", `${provider}/${model} (leonardo) | prompt: "${prompt.slice(0, 60)}..."`);
}
try {
const initFields = initImage
? {
init_image_id: await uploadLeonardoInitImage(providerConfig.baseUrl, token, initImage),
init_strength: LEONARDO_EDIT_INIT_STRENGTH,
}
: {};
const res = await fetch(providerConfig.baseUrl, {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
@@ -64,13 +118,14 @@ export async function handleLeonardoImageGeneration({
prompt,
...resolveLeonardoImageSize(body),
num_images: 1,
...initFields,
}),
});
if (!res.ok) {
const errorText = await res.text();
saveCallLog({
method: "POST",
path: "/v1/images/generations",
path: logPath,
status: res.status,
model: `${provider}/${model}`,
provider,
@@ -84,7 +139,7 @@ export async function handleLeonardoImageGeneration({
if (!genId) {
saveCallLog({
method: "POST",
path: "/v1/images/generations",
path: logPath,
status: 502,
model: `${provider}/${model}`,
provider,
@@ -116,7 +171,7 @@ export async function handleLeonardoImageGeneration({
}
saveCallLog({
method: "POST",
path: "/v1/images/generations",
path: logPath,
status: 200,
model: `${provider}/${model}`,
provider,
@@ -134,7 +189,7 @@ export async function handleLeonardoImageGeneration({
if (gen.status === "FAILED") {
saveCallLog({
method: "POST",
path: "/v1/images/generations",
path: logPath,
status: 502,
model: `${provider}/${model}`,
provider,
@@ -146,7 +201,7 @@ export async function handleLeonardoImageGeneration({
}
saveCallLog({
method: "POST",
path: "/v1/images/generations",
path: logPath,
status: 504,
model: `${provider}/${model}`,
provider,
@@ -158,7 +213,7 @@ export async function handleLeonardoImageGeneration({
if (log) log.error("IMAGE", `${provider} leonardo error: ${err.message}`);
saveCallLog({
method: "POST",
path: "/v1/images/generations",
path: logPath,
status: 502,
model: `${provider}/${model}`,
provider,

View File

@@ -9,6 +9,7 @@
import { saveCallLog } from "../../imageResult.ts";
import { sleep } from "../../../utils/sleep.ts";
import { clampPollIntervalMs, clampPollTimeoutMs } from "../../../utils/pollBounds.ts";
import { sanitizeErrorMessage } from "../../../utils/error.ts";
import {
UPSTREAM_MEDIA_LIMITS,
@@ -19,12 +20,6 @@ import {
const DEFAULT_POLL_INTERVAL_MS = 4000;
const DEFAULT_POLL_TIMEOUT_MS = 180000;
function normalizePositiveNumber(value: unknown, fallback: number): number {
const n = Number(value);
if (!Number.isFinite(n) || n <= 0) return fallback;
return Math.floor(n);
}
interface MagnificProviderConfig {
baseUrl: string;
statusUrl?: string;
@@ -267,8 +262,8 @@ export async function handleMagnificImageGeneration({
const startTime = Date.now();
const token = credentials?.apiKey || "";
const prompt = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? "");
const pollIntervalMs = normalizePositiveNumber(body.poll_interval_ms, DEFAULT_POLL_INTERVAL_MS);
const pollTimeoutMs = normalizePositiveNumber(body.poll_timeout_ms, DEFAULT_POLL_TIMEOUT_MS);
const pollIntervalMs = clampPollIntervalMs(body.poll_interval_ms, DEFAULT_POLL_INTERVAL_MS);
const pollTimeoutMs = clampPollTimeoutMs(body.poll_timeout_ms, DEFAULT_POLL_TIMEOUT_MS);
if (log) {
log.info(
"IMAGE",

View File

@@ -10,7 +10,6 @@ import {
renderhourBaseUrl,
renderhourConfig,
renderhourFailure,
renderhourNumber,
renderhourToken,
runRenderhourJob,
uploadRenderhourInputs,
@@ -22,6 +21,7 @@ import {
saveImageErrorResult,
saveImageSuccessResult,
} from "../../imageGeneration.ts";
import { clampPollIntervalMs, clampPollTimeoutMs } from "../../../utils/pollBounds.ts";
const MAX_IMAGES_PER_JOB = 4;
@@ -72,8 +72,8 @@ export async function handleRenderhourImageGeneration({
baseUrl,
token,
request,
timeoutMs: renderhourNumber(body.timeout_ms, 300_000),
pollIntervalMs: renderhourNumber(body.poll_interval_ms, 2000),
timeoutMs: clampPollTimeoutMs(body.timeout_ms, 300_000),
pollIntervalMs: clampPollIntervalMs(body.poll_interval_ms, 2000),
log,
signal,
});

View File

@@ -302,7 +302,7 @@ async function pollRenderhourJob({
error: `RenderHour job ${job.id} did not finish within ${Math.round(timeoutMs / 1000)} s`,
};
}
await sleep(delay);
await sleep(delay, signal);
delay = pollIntervalMs;
// Asking about a job also moves it forward on RenderHour's side.
const response = await fetch(`${baseUrl}/v1/generations/${encodeURIComponent(job.id)}`, {

View File

@@ -193,6 +193,9 @@ const TAVILY_FIELDS: FieldSchemas = {
exact_match: z.boolean(),
include_usage: z.boolean(),
safe_search: z.boolean(),
// 1..720 hours of cache, 0 to always fetch live, -1 to never fetch live.
// Anything else (2.5, 721, "720") is dropped rather than sent upstream.
max_age_hours: z.union([z.literal(-1), z.literal(0), int(1, 720)]),
};
export function resolveTavilyPassthrough(

View File

@@ -16,7 +16,7 @@ import { fetchWithCheckedRedirects, isRegistryEndpoint } from "./redirectGuard.t
import type { SearchUrlGuard } from "./baseUrl.ts";
import { HTTP_STATUS } from "../../config/constants.ts";
import { lockBorrowedSearchKey } from "./borrowedKeyLock.ts";
import { isSubscriptionQuotaText } from "../../services/quotaTextCooldowns.ts";
import { isSubscriptionQuotaForStatus } from "../../services/quotaTextCooldowns.ts";
import type { SearchProviderConfig } from "../../config/searchRegistry.ts";
import type { SearchResult } from "../search.ts";
import {
@@ -53,7 +53,9 @@ export function shouldCoolDownSearchConnection(status: number, errorText: string
if (SEARCH_COOLDOWN_STATUSES.has(status)) return true;
const lower = errorText.toLowerCase();
if (SEARCH_CREDIT_EXHAUSTION_PHRASES.some((phrase) => lower.includes(phrase))) return true;
return isSubscriptionQuotaText(lower);
// A 400 can quote the caller's query back: plan/usage-limit wording counts on 400
// only with a structured quota code (same status contract as LLM fallback).
return isSubscriptionQuotaForStatus(status, null, errorText);
}
/** Post-dispatch state cleanup shared by JSON and SSE search providers. */

View File

@@ -138,7 +138,10 @@ import { resolveApiKeyForbiddenFallback } from "./accountFallback/nonRetryableUp
import * as exactModelLock from "./accountFallback/exactModelLock.ts";
import { isCreditsExhaustedWithSharedWallet } from "./accountFallback/sharedWalletCredits.ts";
import { CREDITS_EXHAUSTED_SIGNALS } from "./accountFallback/creditExhaustionSignals.ts";
import { isCreditsExhaustedForStatus } from "./accountFallback/creditsExhaustedForStatus.ts";
import {
isCreditsExhaustedForStatus,
quotaTextSignalCountsForStatus,
} from "./accountFallback/creditsExhaustedForStatus.ts";
export { CREDITS_EXHAUSTED_SIGNALS } from "./accountFallback/creditExhaustionSignals.ts";
import { isMistralAmbiguous401 } from "./accountFallback/mistralAmbiguousAuth.ts";
import { isRegisteredFeatureFlagEnabled } from "../utils/registeredFeatureFlag.ts";
@@ -2306,8 +2309,20 @@ export function checkFallbackError(
// UNCONDITIONALLY (not gated by shouldUseQuotaSignal) because it targets
// apikey-category providers like ollama-cloud, which the oauth-only
// shouldUseQuotaSignal gate deliberately excludes from the subscription
// check above.
if (shouldUseQuotaSignal && !isCreditsExhausted(errorStr) && !isDailyQuotaExhausted(errorStr)) {
// check above. On 400 none of these quota TEXT signals counts without a structured
// code or an allow-listed provider: the message may quote the caller's own input.
const quotaTextCounts = quotaTextSignalCountsForStatus(
status,
provider,
errorStr,
structuredError?.code
);
if (
quotaTextCounts &&
shouldUseQuotaSignal &&
!isCreditsExhausted(errorStr) &&
!isDailyQuotaExhausted(errorStr)
) {
const subResult = buildSubscriptionQuotaFallback(
errorStr,
getUpstreamRetryHint,
@@ -2317,14 +2332,17 @@ export function checkFallbackError(
);
if (subResult) return subResult;
}
const weeklyResult = buildWeeklyQuotaFallback(errorStr, undefined, provider);
const weeklyResult = quotaTextCounts
? buildWeeklyQuotaFallback(errorStr, undefined, provider)
: null;
if (weeklyResult) return weeklyResult;
// Issue #7071 (session usage cap) is the same sibling gap as #3709 above —
// runs UNCONDITIONALLY for the same reason: apikey-category providers
// like ollama-cloud are excluded from the oauth-only shouldUseQuotaSignal
// gate.
const sessionResult =
buildSessionQuotaFallback(errorStr) ?? buildRolling24hQuotaFallback(errorStr);
const sessionResult = quotaTextCounts
? (buildSessionQuotaFallback(errorStr) ?? buildRolling24hQuotaFallback(errorStr))
: null;
if (sessionResult) return sessionResult;
const detectedRetryHint = detectRetryHint();
@@ -2336,6 +2354,7 @@ export function checkFallbackError(
? "body"
: undefined;
if (
quotaTextCounts &&
shouldUseQuotaSignal &&
quotaResetHintMs &&
classifyErrorText(errorStr) === RateLimitReason.QUOTA_EXHAUSTED

View File

@@ -60,6 +60,25 @@ function hasCreditErrorCode(text: string, structured: unknown): boolean {
return codes.some((code) => CREDIT_ERROR_CODES.has(code.trim().toLowerCase()));
}
/**
* Whether a quota/credit TEXT signal found in an upstream error may count at this
* status. Every status except 400 keeps the plain text match; on 400 the signal
* counts only with a structured credit code or for an allow-listed provider (see
* the header). Shared by the credit check below and the subscription/plan quota
* text checks in quotaTextCooldowns.ts.
*/
export function quotaTextSignalCountsForStatus(
status: number,
provider: string | null | undefined,
errorText: string,
structured?: unknown
): boolean {
if (status !== 400) return true;
return (
allowsMessageOnlyCredit400(provider) || hasCreditErrorCode(String(errorText || ""), structured)
);
}
/**
* Status-aware credit exhaustion check shared by the classifier, the fallback
* engine and terminal-status resolution. `structured` is what the caller holds
@@ -73,6 +92,5 @@ export function isCreditsExhaustedForStatus(
): boolean {
const text = String(errorText || "");
if (!isCreditsExhaustedWithSharedWallet(text, CREDITS_EXHAUSTED_SIGNALS)) return false;
if (status !== 400) return true;
return allowsMessageOnlyCredit400(provider) || hasCreditErrorCode(text, structured);
return quotaTextSignalCountsForStatus(status, provider, text, structured);
}

View File

@@ -102,6 +102,33 @@ export function deriveAntigravitySessionId(accountKey?: string | null): string |
return hash.toString();
}
/**
* Upstream Cloud Code session for one conversation on one account. Stable across turns
* of that conversation (prompt-cache reuse) yet distinct between conversations running in
* parallel on the same account, which otherwise share and evict one session cache.
*
* @param credentials - Connection credentials; their account key scopes the session.
* @param conversationKey - Resolved conversation id (or session-affinity key); when empty,
* the account-derived session from {@link getAntigravitySessionId} is returned unchanged.
* @returns The `request.sessionId` to send in the Cloud Code envelope.
*/
export function getAntigravityConversationSessionId(
credentials?: AntigravityCredentialsLike | null,
conversationKey?: string | null
): string {
const conversation = toNonEmptyString(conversationKey);
const account = getAntigravityAccountKey(credentials);
if (!conversation) return getAntigravitySessionId(credentials);
return (
deriveAntigravitySessionId(`${account ?? ""}\x1f${conversation}`) ||
getAntigravitySessionId(credentials)
);
}
/**
* Account-scoped Cloud Code session id: an explicit fallback wins, else a stable hash of the
* account key, else a random id when no account is known.
*/
export function getAntigravitySessionId(
credentials?: AntigravityCredentialsLike | null,
fallback?: unknown

View File

@@ -411,10 +411,24 @@ const EXPIRY_FIRST_DEFAULTS = {
tieBandPercent: 5,
minHours: 0.25,
exhaustedFloorPercent: 1,
deadlineTieMinutes: 60,
};
/**
* How `expiry-first` orders accounts that still hold quota:
* - `rate` (default): by how much each account must spend per hour before its
* deadline (`scoreExpiryFirstQuota`).
* - `deadline`: strictly by the nearest deadline — the account whose quota is
* lost first is spent first, as long as it has quota left. Exhausted accounts
* (including a spent 5h session) are skipped until they refill.
*/
export const EXPIRY_FIRST_ORDERS = ["rate", "deadline"] as const;
export type ExpiryFirstOrder = (typeof EXPIRY_FIRST_ORDERS)[number];
/** Reads the expiry-first settings (global or a provider override) with their defaults and bounds. */
export function resolveExpiryFirstConfig(config: Record<string, unknown> | null | undefined) {
const minHours = finiteNumberOrNull(config?.expiryFirstMinHours);
const deadlineTieMinutes = finiteNumberOrNull(config?.expiryFirstDeadlineTieMinutes);
return {
tieBand:
getPercentConfig(config?.expiryFirstTieBandPercent, EXPIRY_FIRST_DEFAULTS.tieBandPercent) /
@@ -425,6 +439,19 @@ export function resolveExpiryFirstConfig(config: Record<string, unknown> | null
config?.expiryFirstExhaustedFloorPercent,
EXPIRY_FIRST_DEFAULTS.exhaustedFloorPercent
) / 100,
order: (config?.expiryFirstOrder === "deadline" ? "deadline" : "rate") as ExpiryFirstOrder,
deadlineTieMs:
Math.min(
24 * 60,
Math.max(
0,
deadlineTieMinutes !== null
? deadlineTieMinutes
: EXPIRY_FIRST_DEFAULTS.deadlineTieMinutes
)
) *
60 *
1000,
};
}
@@ -467,6 +494,44 @@ function msUntilWindowReset(window: QuotaWindowSnapshot, nowMs: number): number
return Number.isFinite(resetMs) ? resetMs - nowMs : Number.POSITIVE_INFINITY;
}
/** Nominal length of a longer (non-session) window, read from its name; null when unknown. */
function nominalLongerWindowMs(key: string): number | null {
const name = key.toLowerCase();
if (name.startsWith("weekly") || name.includes("(7d)")) return RESET_AWARE_WEEKLY_WINDOW_MS;
if (name.startsWith("monthly") || name.includes("(30d)")) return RESET_AWARE_MONTHLY_WINDOW_MS;
return null;
}
/**
* Time left until a window's reset, and whether that reset already lapsed.
*
* A window whose reset is in the past comes from a stale quota read: the window
* has refilled since, so its old fraction no longer applies and its real next
* reset is one nominal period later (5h session, 7d weekly, 30d monthly).
* Treating the lapsed reset as "expires now" made a stale account look like the
* most urgent one and drained it first (two Claude accounts, 2026-11-06/07). A
* lapsed window of unknown length keeps no deadline.
*/
function resolveWindowReset(
entry: ExpiryWindow,
nowMs: number
): { msLeft: number; lapsed: boolean } {
const msLeft = msUntilWindowReset(entry.window, nowMs);
if (!Number.isFinite(msLeft) || msLeft > 0) return { msLeft, lapsed: false };
const periodMs = entry.session ? RESET_AWARE_SESSION_WINDOW_MS : nominalLongerWindowMs(entry.key);
if (periodMs === null) return { msLeft: Number.POSITIVE_INFINITY, lapsed: true };
return { msLeft: msLeft + periodMs * (Math.floor(-msLeft / periodMs) + 1), lapsed: true };
}
/**
* How much of a window can still be spent. An unreported fraction caps nothing, and
* neither does a lapsed window: it has refilled, so its stale fraction no longer applies.
*/
function windowUsableCap(window: QuotaWindowSnapshot, lapsed: boolean): number {
if (window.fractionReported === false || lapsed) return 1;
return clamp01(1 - (window.percentUsed ?? 0.5));
}
function resolveUsableAndReset(
windows: ExpiryWindow[],
nowMs: number,
@@ -476,14 +541,14 @@ function resolveUsableAndReset(
let usable = 1;
let msUntilReset = Number.POSITIVE_INFINITY;
let msUntilSessionReset = Number.POSITIVE_INFINITY;
for (const { window, session } of windows) {
for (const entry of windows) {
const { window, session } = entry;
if (window.fractionReported === false && skipUnreported) continue;
const msLeft = msUntilWindowReset(window, nowMs);
const { msLeft, lapsed } = resolveWindowReset(entry, nowMs);
const capOnly = session && hasLongerWindow;
if (capOnly && msLeft <= 0) continue;
if (window.fractionReported !== false) {
usable = Math.min(usable, clamp01(1 - (window.percentUsed ?? 0.5)));
}
// A lapsed session has refilled: inside a longer window it caps nothing.
if (capOnly && lapsed) continue;
usable = Math.min(usable, windowUsableCap(window, lapsed));
if (capOnly) msUntilSessionReset = Math.min(msUntilSessionReset, msLeft);
else msUntilReset = Math.min(msUntilReset, msLeft);
}
@@ -517,19 +582,22 @@ function projectExpiryScore(
): { score: number; hasReset: boolean } {
let score = 0;
let hasReset = false;
for (const { key, window, session } of windows) {
for (const entry of windows) {
const { key, window, session } = entry;
if (window.fractionReported === false && ctx.skipUnreported) continue;
// A session refills many times before a longer window resets, so its reset is not
// where quota is lost (#18541); it already caps `usable`. This also covers an
// unreported longer reset, a conservative deadline fallback that is not evidence
// that the session's entire balance must be spent in a few hours (#18552).
if (session && ctx.skipSession) continue;
const resetMs = parseResetTimeMs(window.resetAt);
if (!Number.isFinite(resetMs)) continue;
const { msLeft, lapsed } = resolveWindowReset(entry, ctx.nowMs);
if (!Number.isFinite(msLeft)) continue;
hasReset = true;
const hours = Math.max(ctx.config.minHours, (resetMs - ctx.nowMs) / (60 * 60 * 1000));
const hours = Math.max(ctx.config.minHours, msLeft / (60 * 60 * 1000));
const remaining =
window.fractionReported === false ? ctx.usable : clamp01(1 - (window.percentUsed ?? 0.5));
window.fractionReported === false || lapsed
? ctx.usable
: clamp01(1 - (window.percentUsed ?? 0.5));
const burnRate = Math.max(0, ctx.burnRates[key] ?? 0);
const projectedRemaining = Math.max(0, remaining - burnRate * hours);
const predictedWaste = Math.min(ctx.usable, projectedRemaining);
@@ -618,6 +686,32 @@ export function scoreExpiryFirstQuota(
return { score };
}
/**
* The deadline view `expiry-first` uses in `deadline` order: how much an account
* can spend right now (`usable`, the tightest window, a spent session included)
* and how long until its quota is lost (the nearest longer-window reset, rolled
* forward when it already lapsed; the session reset only when no longer window
* reports one). Null when there is no telemetry or nothing left to spend.
*/
export function resolveExpiryFirstDeadline(
quota: unknown,
config: ExpiryConfig,
nowMs: number = Date.now()
): { usable: number; msUntilDeadline: number } | null {
if (!quota || !isRecord(quota)) return null;
if (quota.limitReached === true) return null;
const windows = collectExpiryWindows(quota);
if (windows.length === 0) return null;
if (windows.every(({ window }) => window.fractionReported === false)) return null;
const { usable, msUntilReset } = resolveUsableAndReset(
windows,
nowMs,
hasLongerReset(windows, true)
);
if (usable <= config.exhaustedFloor) return null;
return { usable, msUntilDeadline: msUntilReset };
}
export function getResetAwareRemainingPercent(quota: unknown): number {
if (!quota || !isRecord(quota)) return 100;
if (quota.limitReached === true) return 0;

View File

@@ -5,7 +5,7 @@ import {
isDailyQuotaExhausted,
isOAuthInvalidToken,
} from "./accountFallback.ts";
import { isSubscriptionQuotaText } from "./quotaTextCooldowns.ts";
import { isSubscriptionQuotaForStatus } from "./quotaTextCooldowns.ts";
import { isCreditsExhaustedForStatus } from "./accountFallback/creditsExhaustedForStatus.ts";
import { isProviderSafetyRefusalBody } from "../utils/providerSafety.ts";
import { isModelScopedAccessDenial } from "./accountFallback/modelScopedAccessDenial.ts";
@@ -453,8 +453,9 @@ export function classifyProviderError(
const bodyStr = responseBodyToString(responseBody);
const creditsExhausted = isCreditsExhaustedForStatus(statusCode, provider, bodyStr);
// Claude's native weekly 429 wording is provider-scoped; omitting provider
// silently classified the long-window quota as a short RPM rate limit.
const subscriptionQuotaExhausted = isSubscriptionQuotaText(bodyStr.toLowerCase(), provider);
// silently classified the long-window quota as a short RPM rate limit. On 400 the
// phrase needs a structured code (same contract as the credit signal above).
const subscriptionQuotaExhausted = isSubscriptionQuotaForStatus(statusCode, provider, bodyStr);
const accountDeactivated = isAccountDeactivated(bodyStr);
const oauthInvalid = isOAuthInvalidToken(bodyStr);
const preserveQuota429 = shouldPreserveQuotaSignalsFor429(provider);

View File

@@ -26,6 +26,11 @@ import { FORMATS } from "../translator/formats.ts";
type JsonRecord = Record<string, unknown>;
const SAMPLING_PARAMS = ["temperature", "top_p"] as const;
// Terra additionally rejects log-probability controls when reasoning is active.
// With effort "none" all four fields remain eligible for passthrough.
const TERRA_REASONING_SAMPLING_PARAMS = [
...SAMPLING_PARAMS, "top_logprobs", "logprobs",
] as const;
// Suffix that encodes an active (non-none) reasoning effort, e.g. `gpt-5.4-high`.
const ACTIVE_EFFORT_SUFFIX = /-(low|medium|high|xhigh|minimal)$/i;
// Suffix that encodes the explicit non-reasoning mode, e.g. `gpt-5.4-none`.
@@ -68,7 +73,9 @@ export function stripGpt5SamplingWhenReasoning<T extends Record<string, unknown>
if (!hasActiveReasoning(record, model)) return body;
const stripped: string[] = [];
for (const param of SAMPLING_PARAMS) {
const params = model.toLowerCase() === "gpt-6.1-terra"
? TERRA_REASONING_SAMPLING_PARAMS : SAMPLING_PARAMS;
for (const param of params) {
if (Object.hasOwn(record, param)) stripped.push(param);
}
if (stripped.length === 0) return body;

View File

@@ -111,6 +111,13 @@ export const CODEX_NATIVE_UNPREFIXED_MODELS = new Set([
"gpt-6.1-sol-high",
"gpt-6.1-sol-medium",
"gpt-6.1-sol-low",
"gpt-6.1-terra",
"gpt-6.1-terra-ultra",
"gpt-6.1-terra-max",
"gpt-6.1-terra-xhigh",
"gpt-6.1-terra-high",
"gpt-6.1-terra-medium",
"gpt-6.1-terra-low",
"gpt-5.6-sol",
"gpt-5.6-sol-ultra",
"gpt-5.6-sol-max",

View File

@@ -12,6 +12,7 @@
import { RateLimitReason } from "../config/constants.ts";
import { parseDayGranularityResetMs, parseIsoDateTimeResetMs } from "./quotaResetParsing.ts";
import { quotaTextSignalCountsForStatus } from "./accountFallback/creditsExhaustedForStatus.ts";
type RateLimitReasonValue = (typeof RateLimitReason)[keyof typeof RateLimitReason];
@@ -64,6 +65,26 @@ export function isSubscriptionQuotaText(lower: string, provider?: string | null)
);
}
/**
* Status-aware form of isSubscriptionQuotaText, under the same contract as the
* credit signal (creditsExhaustedForStatus.ts): a 400 often quotes the caller's
* own input back in its message, so on 400 the phrase counts only with a
* structured credit/quota code or for a provider whose documented 400 form is
* message-only. Every other status keeps the plain text match.
*/
export function isSubscriptionQuotaForStatus(
status: number,
provider: string | null | undefined,
errorText: string,
structured?: unknown
): boolean {
const text = String(errorText || "");
return (
isSubscriptionQuotaText(text.toLowerCase(), provider) &&
quotaTextSignalCountsForStatus(status, provider, text, structured)
);
}
export const SUBSCRIPTION_QUOTA_COOLDOWN_MS = 60 * 60 * 1000; // 1 hour
/** Same value space as accountFallback.ts's RetryHintProvenance (kept local to avoid a circular import). */

View File

@@ -172,8 +172,10 @@ export function applySyntxProviderRules(
settings: JsonRecord,
ctx: { modelType: string; fileCount?: number }
): void {
// aiName comes from the caller's model id: only the table's own entries may run, never a
// member inherited from Object.prototype ("constructor", "__proto__", ...). CodeQL #1392.
if (!Object.hasOwn(PROVIDER_RULES, aiName)) return;
const handler = PROVIDER_RULES[aiName];
if (!handler) return;
handler(ctx.modelType || "", ctx.fileCount ?? 0, settings);
}

View File

@@ -435,10 +435,19 @@ export function enforceCacheControlBlockLimit(
body: ClaudeRequestBody,
limit = MAX_CACHE_CONTROL_BLOCKS
): number {
const holders: Array<{ obj: Record<string, unknown> }> = [];
const marked = markedCacheControlBlocks(body);
if (marked.length <= limit) return 0;
const toRemove = marked.length - limit;
for (let i = 0; i < toRemove; i++) delete marked[i].cache_control;
return toRemove;
}
/** Blocks that carry a cache_control marker, in request order (system, tools, messages). */
function markedCacheControlBlocks(body: ClaudeRequestBody): Array<Record<string, unknown>> {
const marked: Array<Record<string, unknown>> = [];
const push = (block: unknown) => {
if (block && typeof block === "object" && "cache_control" in block) {
holders.push({ obj: block as Record<string, unknown> });
if (block && typeof block === "object" && (block as Record<string, unknown>).cache_control) {
marked.push(block as Record<string, unknown>);
}
};
if (Array.isArray(body?.system)) body.system.forEach(push);
@@ -448,11 +457,21 @@ export function enforceCacheControlBlockLimit(
if (Array.isArray(msg?.content)) msg.content.forEach(push);
}
}
const marked = holders.filter((h) => h.obj.cache_control !== undefined);
if (marked.length <= limit) return 0;
const toRemove = marked.length - limit;
for (let i = 0; i < toRemove; i++) delete marked[i].obj.cache_control;
return toRemove;
return marked;
}
/**
* A tool loop ends with the results of the last assistant turn's tool calls, after that
* turn's breakpoint, so they are billed as fresh input. When the 4-marker budget has room,
* mark the final user turn so the next request reads them from cache.
*/
function markFinalToolResults(body: ClaudeRequestBody, ttl?: string): void {
const last = body.messages?.[body.messages.length - 1];
if (last?.role !== "user" || !Array.isArray(last.content)) return;
if (!last.content.some((block) => block.type === "tool_result")) return;
if (last.content.some((block) => block.cache_control)) return;
if (markedCacheControlBlocks(body).length >= MAX_CACHE_CONTROL_BLOCKS) return;
markMessageCacheControl(last, ttl);
}
function markMessageCacheControl(msg: ClaudeMessage, ttl?: string): boolean {
@@ -1049,6 +1068,9 @@ export function prepareClaudeRequest(
// the upstream API, not caching policy, so preserveCacheControl does not
// exempt them (they were the 400 sources on claude 5.x since 2026-09-29).
hoistToolResultCacheControl(body);
if (!preserveCacheControl && supportsPromptCaching) {
markFinalToolResults(body, createClaudeTailCacheControl(provider).ttl);
}
if (supportsPromptCaching) {
enforceCacheControlBlockLimit(body);
}

View File

@@ -384,6 +384,8 @@ export function translateRequest(
/** UA-detected GitHub Copilot client. Forwarded to translators via the
* transient `_copilotClient` credential flag (see openai-responses → openai). */
copilotClient?: boolean;
/** Per-conversation key for the Antigravity upstream sessionId (prompt-cache scope). */
antigravitySessionKey?: string | null;
}
) {
// Only Anthropic holds message-thread state. A `thread` delta (the message-threads beta) omits
@@ -570,10 +572,12 @@ export function translateRequest(
// thoughtSignature on tool-use history (#8979 / #2504 parity with the hub path).
const hasNs = options?.signatureNamespace != null;
const hasProvider = provider != null;
const agySessionKey = options?.antigravitySessionKey || null;
const directCredentials =
hasNs || hasProvider
hasNs || hasProvider || agySessionKey
? {
...(credentials && typeof credentials === "object" ? credentials : {}),
...(agySessionKey ? { _antigravitySessionKey: agySessionKey } : {}),
...(hasProvider ? { _provider: provider } : {}),
...(hasNs
? {
@@ -684,10 +688,17 @@ export function translateRequest(
const hasCopilot = options?.copilotClient === true;
const hasProvider = provider != null;
const videoSensitive = options?.videoTranscriptSensitive === true;
const agySessionKey = options?.antigravitySessionKey || null;
const translationCredentials =
hasNs || hasPreCompression || hasCopilot || hasProvider || videoSensitive
hasNs ||
hasPreCompression ||
hasCopilot ||
hasProvider ||
videoSensitive ||
agySessionKey
? {
...(credentials && typeof credentials === "object" ? credentials : {}),
...(agySessionKey ? { _antigravitySessionKey: agySessionKey } : {}),
...(hasNs
? {
_signatureNamespace: scopeGeminiThoughtSignatureNamespace(

View File

@@ -57,7 +57,7 @@ export function imageUrlToText(value: unknown): string {
}
const CODEX_MAX_EFFORT_MODEL_PATTERN =
/^(?:gpt-5\.6-(?:sol|terra|luna)|gpt-6(?:\.1)?-(?:astra|sol|luna))(?:-(?:none|low|medium|high|xhigh|max|ultra))?$/;
/^(?:gpt-5\.6-(?:sol|terra|luna)|gpt-6(?:\.1)?-(?:astra|sol|terra|luna))(?:-(?:none|low|medium|high|xhigh|max|ultra))?$/;
const KIRO_GPT_5_6_MODEL_PATTERN =
/^(?:kiro|kr)\/gpt-5\.6-(?:sol|terra|luna)(?:-(?:none|low|medium|high|xhigh|max))?$/;
const KIRO_OPUS_5_5_MODEL_PATTERN = /^(?:kiro|kr)\/claude-opus-5(?:\.|-)5(?:-thinking)?$/;

View File

@@ -8,7 +8,7 @@ import {
import {
generateAntigravityRequestId,
getAntigravityEnvelopeUserAgent,
getAntigravitySessionId,
getAntigravityConversationSessionId,
} from "../../services/antigravityIdentity.ts";
import { fixToolPairs } from "../../services/contextManager.ts";
import {
@@ -910,7 +910,10 @@ function wrapInCloudCodeEnvelope(model, cloudCodeRequest, credentials = null) {
project: projectId,
requestId: generateAntigravityRequestId(),
request: {
sessionId: getAntigravitySessionId(credentials),
sessionId: getAntigravityConversationSessionId(
credentials,
(credentials as { _antigravitySessionKey?: string } | null)?._antigravitySessionKey
),
contents: cloudCodeRequest.contents,
systemInstruction: cloudCodeRequest.systemInstruction,
generationConfig: applyAntigravityGenerationDefaults(cloudCodeRequest.generationConfig),

View File

@@ -0,0 +1,42 @@
/**
* Upper bounds for the polling knobs a caller may send to async media jobs
* (`poll_interval_ms`, `timeout_ms`, `poll_timeout_ms`).
*
* Those values feed `sleep()` and the polling deadline. Without a ceiling one request could hold
* a handler for days while the server kept polling the upstream with the operator's credential
* (CodeQL #1389, js/resource-exhaustion). Same pattern as `resolveCursorImageTimeoutMs` in
* handlers/imageGeneration/providers/cursorAgentImage.ts: only the untrusted request value is
* clamped; the fallback (a built-in or operator-configured default) is trusted and kept as is.
*/
/** Longest single wait between two polls; matches MAX_POLL_RETRY_DELAY_MS in pollRetry.ts. */
export const MAX_CALLER_POLL_INTERVAL_MS = 30_000;
/** Longest total polling window a caller may ask for (10 minutes). */
export const MAX_CALLER_POLL_TIMEOUT_MS = 600_000;
/** A whole number of milliseconds ≥ 1 from the request, or null when absent or unusable. */
function positiveWholeMs(value: unknown): number | null {
const n = Number(value);
if (!Number.isFinite(n)) return null;
const ms = Math.floor(n);
return ms >= 1 ? ms : null;
}
/**
* The caller's value clamped to `ceiling`, or `fallback` when the caller sent none. A fallback
* above the ceiling stays reachable, so a ceiling never shortens a default.
*/
export function clampCallerMs(value: unknown, fallback: number, ceiling: number): number {
const requested = positiveWholeMs(value);
if (requested === null) return fallback;
return Math.min(requested, Math.max(ceiling, fallback));
}
export function clampPollIntervalMs(value: unknown, fallback: number): number {
return clampCallerMs(value, fallback, MAX_CALLER_POLL_INTERVAL_MS);
}
export function clampPollTimeoutMs(value: unknown, fallback: number): number {
return clampCallerMs(value, fallback, MAX_CALLER_POLL_TIMEOUT_MS);
}

16
package-lock.json generated
View File

@@ -157,7 +157,7 @@
"dpdm": "^4.3.0",
"esbuild": "0.28.2",
"eslint": "^10.10.0",
"eslint-config-next": "16.4.5",
"eslint-config-next": "16.4.6",
"eslint-plugin-react-hooks": "7.1.1",
"eslint-plugin-sonarjs": "^4.1.0",
"espree": "^11.2.0",
@@ -6332,9 +6332,9 @@
"license": "MIT"
},
"node_modules/@next/eslint-plugin-next": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.5.tgz",
"integrity": "sha512-dNmc4y4En/34tWxaBFF2tG/R9GeiRwVPf7v8Az/Pqk8FcT4Uv0ePmrZKvWBL2nFy1QprPgJW+6XjfyV6jbRV3Q==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.6.tgz",
"integrity": "sha512-HdqERVOafOD8JaUSAkwf9aSu/1rsHlkN8C5GcXYBH3C/z1MxBhZFxB5rz/xqMMRiIj7r9tIv8OCLQ9JWUxCvWA==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -19439,13 +19439,13 @@
}
},
"node_modules/eslint-config-next": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.5.tgz",
"integrity": "sha512-mvh39zYLoNjpT5tVmf8xZu7i5lEOb5jN5cW6qD9OpeCp4GEEOeYta0Z2XyKiD0pYdlvm5/Td6Bi890maPRlIjg==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.6.tgz",
"integrity": "sha512-IBGGrVf9E6pL0NGL0hmeicVGeSyv1VEzIWq6IecDqkw+YFByhEtDJS9u1r6s6a1VxK6rssh69KyNFQUgfaacqw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@next/eslint-plugin-next": "16.4.5",
"@next/eslint-plugin-next": "16.4.6",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.32.0",

View File

@@ -159,7 +159,7 @@
"test:plan3": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/plan3-p0.test.ts",
"test:fixes": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/fixes-p1.test.ts",
"test:security": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/security-fase01.test.ts",
"test:property": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --test --test-force-exit tests/unit/correctness/*.property.test.ts",
"test:property": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./tests/_setup/isolateDataDir.ts --test --test-force-exit tests/unit/correctness/*.property.test.ts",
"check:boundary": "node scripts/quality/measure-boundary.mjs",
"check:boundary:ratchet": "node scripts/quality/measure-boundary.mjs --ratchet",
"check:cycles": "node scripts/check/check-cycles.mjs",
@@ -490,7 +490,7 @@
"dpdm": "^4.3.0",
"esbuild": "0.28.2",
"eslint": "^10.10.0",
"eslint-config-next": "16.4.5",
"eslint-config-next": "16.4.6",
"eslint-plugin-react-hooks": "7.1.1",
"eslint-plugin-sonarjs": "^4.1.0",
"espree": "^11.2.0",

View File

@@ -17,7 +17,9 @@
// `success` on pull_request.head.sha, context APPROVAL_CONTEXTS[kind],
// description "approved by <login>" (App token, so the creator is `<appSlug>[bot]`);
// labeled by a non-approver → comment once (key "not-approver"), no status
// (in shadow mode no comment either: shadow writes nothing on a pull request);
// (in shadow mode no comment either: shadow writes nothing on a pull request). Always the
// App's, whatever config.voice says: this job never receives the owner's token (the tick's
// own "not-approver" comment then finds this one by its marker and posts nothing);
// unlabeled → status `failure` "approval withdrawn by <login>" on the same head/context;
// in shadow mode (config.mode) nothing at all is written for a removal.
//

View File

@@ -8,8 +8,16 @@
//
// Nothing here force-pushes. Candidate refs are unique per SHA (contracts.candidateRef), so a
// push either creates a new ref or finds it already at the same SHA.
//
// SIGNED MERGE COMMITS (config landing.signing "ssh"): composeCandidate signs each merge commit
// with `commit-tree -S`, the SSH key file the workflow writes under RUNNER_TEMP
// (signingKeyPath) given to git as configuration of that one command (gpg.format=ssh,
// user.signingkey=<path>) through the environment, so neither the key nor its path is ever an
// argument, a log line, an event or an error message. A missing key or a signature git cannot
// make never blocks the queue: the commit is composed unsigned, exactly as without signing, and
// the result says so (`signing`), for the tick to report once per batch.
import { existsSync, mkdirSync, readdirSync } from "node:fs";
import { existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
import { join, resolve } from "node:path";
import {
@@ -43,6 +51,55 @@ import {
* test or land; the tick drops it from the queue
*/
/**
* Where the tick job's "Write the merge-commit signing key" step leaves the key, under
* RUNNER_TEMP (.github/workflows/omni-queue.yml; tests/unit/merge-queue/workflows.test.mjs pins
* both). The step removes the directory at the end of the job, failed or cancelled included.
*/
export const SIGNING_KEY_DIR = "omni-queue-signing";
export const SIGNING_KEY_FILE = "signing-key";
/** The signing key file of a job whose RUNNER_TEMP is `runnerTemp`; null without one. */
export function signingKeyPath(runnerTemp) {
if (typeof runnerTemp !== "string" || !runnerTemp) return null;
return join(runnerTemp, SIGNING_KEY_DIR, SIGNING_KEY_FILE);
}
/** Why a batch was composed unsigned although signing is asked for: no key in the job. */
export const SIGNING_KEY_MISSING_CAUSE =
"no signing key file in the job (is the OMNI_QUEUE_SIGNING_KEY secret set?)";
/**
* The signer of one composition: `config` (git configuration of the commit-tree call) while
* signing works, `cause` once it does not. Never holds anything but the path.
* @param {{keyPath: string|null}} signing
*/
function createSigner(signing) {
const keyPath = typeof signing?.keyPath === "string" ? signing.keyPath : null;
let file = false;
try {
file = keyPath !== null && statSync(keyPath).isFile();
} catch {
file = false;
}
const report = { signed: 0, unsigned: 0, cause: file ? null : SIGNING_KEY_MISSING_CAUSE };
return {
report,
/** The configuration that signs, or null once signing is known not to work. */
config: () =>
report.cause === null
? [
["gpg.format", "ssh"],
["user.signingkey", keyPath],
]
: null,
fail(code) {
// The exit code only: git's message would carry the key path.
report.cause = `git could not sign a merge commit (exit ${code})`;
},
};
}
/** Local refs of the scratch repository (never pushed anywhere). */
export const LOCAL_BASE_REF = "refs/omni-queue/base";
export const localPrRef = (n) => `refs/omni-queue/pr/${n}`;
@@ -282,11 +339,19 @@ export function haveCommonAncestor(git, a, b) {
* The merge commits take their author/committer identity from the Git runner (createGit
* `identity`, the App bot). Their message is built only from validated fields.
*
* `signing` (config landing.signing "ssh"; absent = no signing, and no `signing` field in the
* result): each merge commit is signed with the SSH key at `signing.keyPath`. A key that is not
* there, or a signature git cannot make, leaves that commit and the rest of the batch unsigned,
* byte for byte what the composition is without signing; the result's `signing` says how many
* commits were signed and why the others were not ({signed, unsigned, cause}; cause null when
* every one was signed). A signature changes nothing else: same tree, parents, identity, message.
*
* @param {{git: Git, base: string, baseSha: string, prs: PrRef[], batchId: string,
* heads: Object<number, string|null>}} input heads = fetchInputs().heads
* @returns {ComposeResult}
* heads: Object<number, string|null>, signing?: {keyPath: string|null}|null}} input
* heads = fetchInputs().heads
* @returns {ComposeResult & {signing?: {signed: number, unsigned: number, cause: string|null}}}
*/
export function composeCandidate({ git, base, baseSha, prs, batchId, heads }) {
export function composeCandidate({ git, base, baseSha, prs, batchId, heads, signing = null }) {
if (!isSha(baseSha)) throw new Error("composeCandidate: invalid baseSha");
const g = scratchGit(git);
/** @type {ComposeResult} */
@@ -301,6 +366,23 @@ export function composeCandidate({ git, base, baseSha, prs, batchId, heads }) {
alreadyContained: [],
alreadyInBase: [],
};
const signer = signing ? createSigner(signing) : null;
/** commit-tree of one merge commit: signed while the signer works, else as without signing. */
const commitMerge = (tree, ours, theirs, message) => {
const config = signer?.config();
if (config) {
const args = ["commit-tree", tree, "-p", ours, "-p", theirs, "-S", "-F", "-"];
const res = g.run(args, { input: message, config, allowFail: true });
const sha = res.stdout.trim();
if (res.code === 0 && isSha(sha)) {
signer.report.signed += 1;
return sha;
}
signer.fail(res.code);
}
if (signer) signer.report.unsigned += 1;
return g.out(["commit-tree", tree, "-p", ours, "-p", theirs, "-F", "-"], { input: message });
};
let current = baseSha;
for (const pr of prs ?? []) {
const fetched = heads?.[pr.n] ?? null;
@@ -329,9 +411,7 @@ export function composeCandidate({ git, base, baseSha, prs, batchId, heads }) {
continue;
}
const message = buildMergeMessage({ pr, base, baseSha, batchId });
current = g.out(["commit-tree", merged.tree, "-p", current, "-p", pr.head, "-F", "-"], {
input: message,
});
current = commitMerge(merged.tree, current, pr.head, message);
if (!isSha(current)) throw new Error("git commit-tree returned no commit id");
result.included.push(pr);
}
@@ -342,6 +422,7 @@ export function composeCandidate({ git, base, baseSha, prs, batchId, heads }) {
result.candidateSha = current;
result.treeSha = g.out(["rev-parse", `${current}^{tree}`]);
}
if (signer) result.signing = { ...signer.report };
return result;
}

View File

@@ -15,6 +15,14 @@ export const DEFAULT_CONFIG_PATH = join(ROOT, "config", "merge-queue", "config.j
export const LANDING_MODES = Object.freeze(["merge-ff", "squash-api"]);
export const LANDING_ACTORS = Object.freeze(["app", "owner"]);
export const QUEUE_MODES = Object.freeze(["shadow", "live"]);
/**
* Who performs the queue's human-visible writes (comments and label removals on pull requests,
* the dashboard issue and its comments, comments on the base-red issue, the tree-divergence
* issue): the App's token, or the owner's (OMNI_QUEUE_LAND_TOKEN), see voice.mjs.
*/
export const VOICES = Object.freeze(["app", "owner"]);
/** `landing.signing`: "ssh" signs every merge commit the queue composes (compose.mjs). */
export const SIGNING_MODES = Object.freeze(["none", "ssh"]);
const CONFIG_KEYS = [
"schemaVersion",
@@ -38,7 +46,8 @@ const CONFIG_KEYS = [
];
/** Keys that may be left out: each one has a default (applied by validateConfig). */
const OPTIONAL_CONFIG_KEYS = ["flakyReruns", "prChecksRequired", "lanes"];
const OPTIONAL_CONFIG_KEYS = ["flakyReruns", "prChecksRequired", "lanes", "voice"];
const DEFAULT_VOICE = "app";
/** Keys of `lanes` (both required when `lanes` is present). */
const LANE_KEYS = ["hotfixLabel", "baseRepairLabel"];
/** Re-runs of a red candidate's failed jobs before it is classified (tick onRed): once. */
@@ -60,8 +69,9 @@ const STATUS_CONTEXT_RE = /^[A-Za-z0-9._/-]{1,100}$/;
*/
const LAND_STATUS_PREFIX = "omni-queue/";
const NOREPLY_EMAIL_RE = /^[^\s@]+@users\.noreply\.github\.com$/;
const LANDING_KEYS = ["mode", "actor", "identity", "statusContext"];
const LANDING_KEYS = ["mode", "actor", "identity", "statusContext", "signing"];
const DEFAULT_LANDING_ACTOR = "app";
const DEFAULT_SIGNING = "none";
const DEFAULT_LAND_STATUS_CONTEXT = "omni-queue/land";
function stringList(value, path, errors, { min = 0, item = nonEmptyString } = {}) {
@@ -80,8 +90,10 @@ function positiveInt(value, path, errors, { min = 1, max = Number.MAX_SAFE_INTEG
/**
* Validate the `landing` block, push every problem onto `errors` and return the block with its
* defaults applied (`actor: "app"`, `statusContext: "omni-queue/land"`), or null when `raw` is not
* an object. The returned block is only used when `errors` stays empty.
* defaults applied (`actor: "app"`, `statusContext: "omni-queue/land"`, `signing: "none"`), or
* null when `raw` is not an object. The returned block is only used when `errors` stays empty.
* `signing: "ssh"` needs `actor: "owner"`: the signed commits carry `landing.identity`, and only
* that account can hold the key GitHub verifies them with (an App's bot user has no signing keys).
*/
function validateLanding(raw, errors) {
if (!isRecord(raw)) {
@@ -126,7 +138,15 @@ function validateLanding(raw, errors) {
// An approval context as the land status would make a label approval a blessing.
else if (Object.values(APPROVAL_CONTEXTS).includes(statusContext))
errors.push("landing.statusContext: must not equal an approval context");
return { ...raw, actor, statusContext };
const signing = Object.hasOwn(raw, "signing") ? raw.signing : DEFAULT_SIGNING;
if (!SIGNING_MODES.includes(signing))
errors.push(`landing.signing: expected one of ${SIGNING_MODES.join(", ")}`);
else if (signing === "ssh" && actor !== "owner")
errors.push(
'landing.signing: "ssh" needs landing.actor "owner" (the signed merge commits carry ' +
"landing.identity, whose account holds the signing key)"
);
return { ...raw, actor, statusContext, signing };
}
/**
@@ -183,9 +203,11 @@ function validateLanes(raw, errors) {
* startSize (optional, default maxSize), halves after
* a red root batch and grows by one after a full one
* lands; without it every batch is up to maxSize
* @property {{mode: "merge-ff"|"squash-api", actor: "app"|"owner", identity?: {name: string, email: string}, statusContext: string}} landing
* @property {{mode: "merge-ff"|"squash-api", actor: "app"|"owner", identity?: {name: string, email: string}, statusContext: string, signing: "none"|"ssh"}} landing
* actor "owner" lands with `identity` (a noreply address);
* statusContext is the commit status the queue publishes
* statusContext is the commit status the queue publishes;
* signing (optional, default "none"): "ssh" signs every
* merge commit the queue composes (owner actor only)
* @property {string[]} requiredChecks check names that must be `success` on the candidate
* @property {string[]} advisoryChecks check names whose failure is tolerated
* @property {string[]} aggregateChecks always() gate checks that fail whenever a job they
@@ -205,6 +227,8 @@ function validateLanes(raw, errors) {
* FIFO; a base-repair PR alone too, and it is the
* only thing a base-red pause processes
* @property {"shadow"|"live"} mode
* @property {"app"|"owner"} voice optional, default "app": whose token posts the queue's
* comments, removes its labels and writes its issues
*/
/**
@@ -320,6 +344,8 @@ export function validateConfig(raw) {
const lanes = validateLanes(raw, errors);
if (!QUEUE_MODES.includes(raw.mode))
errors.push(`mode: expected one of ${QUEUE_MODES.join(", ")}`);
const voice = Object.hasOwn(raw, "voice") ? raw.voice : DEFAULT_VOICE;
if (!VOICES.includes(voice)) errors.push(`voice: expected one of ${VOICES.join(", ")}`);
return errors.length
? { ok: false, config: null, errors }
: {
@@ -331,6 +357,7 @@ export function validateConfig(raw) {
flakyReruns,
prChecksRequired,
lanes,
voice,
}),
errors: [],
};

View File

@@ -4,6 +4,9 @@
// - Credentials travel in the environment (GIT_CONFIG_COUNT/KEY/VALUE → http extraheader), never
// in argv or in the remote URL, and every error message is redacted before it is thrown. The
// tick's OMNI_QUEUE_TOKEN / OMNI_QUEUE_LAND_TOKEN are removed from every git child's environment.
// - Configuration a single command needs (the signing key of a merge commit: compose.mjs) also
// travels as GIT_CONFIG_* entries of that command's environment (run option `config`), never as
// `-c` arguments: argv is logged, the environment is not.
// - Synchronous: one tick is a short, sequential script.
import { spawnSync } from "node:child_process";
@@ -47,6 +50,25 @@ function withoutTokens(env) {
return out;
}
/**
* `env` plus `entries` ([key, value] pairs) appended to its GIT_CONFIG_COUNT/KEY_n/VALUE_n list
* (the token's http header, when there is one, keeps index 0). Git reads these as command-line
* configuration of that one process.
* @param {object} env
* @param {[string, string][]} entries
*/
export function withConfigEntries(env, entries) {
if (!entries?.length) return env;
const count = Number.parseInt(env.GIT_CONFIG_COUNT ?? "", 10);
const start = Number.isSafeInteger(count) && count > 0 ? count : 0;
const out = { ...env, GIT_CONFIG_COUNT: String(start + entries.length) };
entries.forEach(([key, value], i) => {
out[`GIT_CONFIG_KEY_${start + i}`] = key;
out[`GIT_CONFIG_VALUE_${start + i}`] = value;
});
return out;
}
/**
* @typedef {object} GitResult
* @property {number|null} code
@@ -57,8 +79,11 @@ function withoutTokens(env) {
/**
* @typedef {object} Git
* @property {string} cwd
* @property {(args: string[], opts?: {allowFail?: boolean, input?: string, env?: object}) => GitResult} run
* @property {(args: string[], opts?: {input?: string, env?: object}) => string} out stdout trimmed; throws GitError
* @property {(args: string[], opts?: {allowFail?: boolean, input?: string, env?: object,
* config?: [string, string][]}) => GitResult} run config: git configuration of this
* one command, passed through the environment (withConfigEntries), never logged
* @property {(args: string[], opts?: {input?: string, env?: object,
* config?: [string, string][]}) => string} out stdout trimmed; throws GitError
*/
/**
@@ -88,12 +113,13 @@ export function createGit({ cwd, token, env = {}, identity, log = () => {} }) {
...env,
});
function run(args, { allowFail = false, input, env: extra } = {}) {
function run(args, { allowFail = false, input, env: extra, config } = {}) {
const shown = args.map(redact);
log(`git ${shown.join(" ")}`);
const env = extra ? withoutTokens({ ...baseEnv, ...extra }) : baseEnv;
const res = spawnSync("git", args, {
cwd,
env: extra ? withoutTokens({ ...baseEnv, ...extra }) : baseEnv,
env: withConfigEntries(env, config),
input,
encoding: "utf8",
maxBuffer: 256 * 1024 * 1024,

View File

@@ -81,18 +81,24 @@ export class GitHubError extends Error {
* @property {(n: number) => Promise<{id: number, body: string, author: string,
* createdAt: string}[]>} listIssueComments
* @property {(n: number, body: string) => Promise<{id: number}>} createIssueComment
* @property {(n: number, key: string, body: string) => Promise<{posted: boolean}>} commentOnce
* @property {(n: number, key: string, body: string, opts?: {reader?: GitHubClient|null,
* alsoLogins?: string[]}) => Promise<{posted: boolean}>} commentOnce
* posts `body + "\n\n" + contracts.commentMarker(key)` unless a comment on issue/PR n
* already contains that marker (then {posted:false}). The ONLY way queue code comments.
* After posting it re-reads the comments: when two writers raced (approval job + tick,
* or a POST replayed after a 5xx), the lowest comment id wins and the newer duplicate
* this call created is deleted ({posted:false}).
* this call created is deleted ({posted:false}). opts (owner voice, voice.mjs):
* `reader` = the client that lists the comments (the App's: every read stays the
* App's), the POST and DELETE stay this client's; `alsoLogins` = more logins whose
* markers count next to botLogin (the owner's login, read from the owner's token)
* @property {(commentId: number) => Promise<void>} deleteIssueComment 404 = already gone
* @property {(opts: {labels?: string[], state?: "open"|"closed"|"all"}) => Promise<{number: number,
* title: string, body: string, labels: string[], state: string,
* updatedAt: string}[]>} listIssues issues only (PRs filtered out)
* @property {(input: {title: string, body: string, labels?: string[]}) => Promise<{number: number}>} createIssue
* @property {(n: number, patch: {title?: string, body?: string, state?: string}) => Promise<void>} updateIssue
* @property {() => Promise<string>} getAuthenticatedLogin GET /user: the login of the token's
* own account ("" when the answer names none); voice.mjs reads the owner's with it
*
* — commits / checks / statuses —
* @property {(branch: string) => Promise<string|null>} getBranchSha null when absent
@@ -439,7 +445,9 @@ function errorMessage(data, fallback) {
* baseDelayMs/maxDelayMs/nowMs tune the backoff (tests); maxDelayMs (default 120 s) is also
* the longest Retry-After / rate-limit reset wait honored: a longer one throws at once;
* botLogin, when set, makes commentOnce
* count only markers in comments authored by that login (a third party cannot pre-post one);
* count only markers in comments authored by that login, or by a login its caller adds
* (`alsoLogins`: the owner's, read from the owner's own token): a third party cannot pre-post
* one;
* requestTimeoutMs (default 30 s) aborts a hung request, which then counts as a network error.
* @returns {GitHubClient}
*/
@@ -682,19 +690,25 @@ export function createGitHubClient(options) {
deleteIssueComment,
async commentOnce(n, key, body) {
async commentOnce(n, key, body, { reader = null, alsoLogins = [] } = {}) {
const marker = commentMarker(key);
const ours = (c) => c.body.includes(marker) && (!botLogin || c.author === botLogin);
if ((await listIssueComments(n)).some(ours)) return { posted: false };
// Logins whose markers are the queue's own: the App's, and the owner's under the owner
// voice. Exact logins only, as GitHub returns them; nobody else's marker ever counts.
const trusted = botLogin ? new Set([botLogin, ...alsoLogins.filter(Boolean)]) : null;
const ours = (c) => c.body.includes(marker) && (!trusted || trusted.has(c.author));
// Under the owner voice the App's client reads, this (the owner's) client writes.
const list = reader ? (m) => reader.listIssueComments(m) : listIssueComments;
if ((await list(n)).some(ours)) return { posted: false };
const { id } = await createIssueComment(n, `${body}\n\n${marker}`);
// Read-then-write is not atomic: another writer may have posted the same marker meanwhile,
// and each POST replayed after a 5xx may have left one more copy. The lowest id wins; drop
// every newer copy written by our login (never a comment of someone else).
const found = (await listIssueComments(n)).filter(ours).sort((a, b) => a.id - b.id);
// every newer copy written by a trusted login (never a comment of someone else).
const found = (await list(n)).filter(ours).sort((a, b) => a.id - b.id);
const winner = found[0]?.id;
if (winner === undefined || id === undefined) return { posted: true };
const self = botLogin ?? found.find((c) => c.id === id)?.author;
const extra = found.filter((c) => c.id !== winner && (c.id === id || c.author === self));
const self = found.find((c) => c.id === id)?.author;
const mine = (c) => (trusted ? trusted.has(c.author) : c.author === self);
const extra = found.filter((c) => c.id !== winner && (c.id === id || mine(c)));
for (const c of extra) await deleteIssueComment(c.id);
if (extra.length) {
const ids = extra.map((c) => c.id).join(", ");
@@ -722,6 +736,11 @@ export function createGitHubClient(options) {
await request("PATCH", r(`/issues/${n}`), { body: patch });
},
async getAuthenticatedLogin() {
const { data } = await request("GET", "/user");
return typeof data?.login === "string" ? data.login : "";
},
async getBranchSha(branch) {
const res = await request("GET", r(`/git/ref/heads/${encodePath(branch)}`), {
allowStatuses: [404],

View File

@@ -169,6 +169,10 @@ export function mergedPrsBetween(git, expectedBaseSha, candidateSha) {
* key, in any paragraph, is refused rather than resolved). The chain is read with each commit's
* whole message, as the CI reads it; output that cannot be split into whole commits is a
* mismatch. The subject, the author trailer and the commit identity are not checked.
* Nor is a signature (config landing.signing "ssh"): every read here is of the tree, the parents
* and the message (%B, which never holds the gpgsig header), so a signed candidate verifies
* exactly as the unsigned composition of the same inputs, and a signature never makes a commit
* with another tree, parents or trailers pass.
*
* @param {{git: Git, expectedBaseSha: string, candidateSha: string, prs: PrRef[],
* treeSha?: string|null, trees?: boolean}} input the commits must be in the scratch

View File

@@ -14,10 +14,13 @@
// pull-requests: write is used by a squash-api landing (mergePull) only:
// labels and comments on a PR go through the issues endpoints
// GITHUB_REPOSITORY owner/repo
// OMNI_QUEUE_LAND_TOKEN the repository owner's token, used ONLY by the landing itself (the
// merge-ff push or the squash-api merges) when landing.actor is "owner";
// everything else, the land status included, uses OMNI_QUEUE_TOKEN.
// Optional: without it shadow mode runs and a live landing pauses.
// OMNI_QUEUE_LAND_TOKEN the repository owner's token, used by the landing itself (the
// merge-ff push or the squash-api merges) when landing.actor is "owner",
// and, when config.voice is "owner", by the queue's human-visible writes
// (voice.mjs: comments, label removals, the dashboard and other issues;
// its GET /user names the owner's login). Everything else, the land
// status included, uses OMNI_QUEUE_TOKEN. Optional: without it shadow
// mode runs, a live landing pauses and the voice falls back to the App.
// OMNI_QUEUE_GIT_NAME, OMNI_QUEUE_GIT_EMAIL TESTS/SANDBOX ONLY: identity for queue merge
// commits, over everything else. Without it: landing.identity when
// landing.actor is "owner", else OMNI_QUEUE_BOT_NAME +
@@ -27,7 +30,11 @@
// it (the re-runner of a re-run, whose inputs stay the dispatcher's): a
// bless is honoured only when BOTH are logins of config.approvers
// OMNI_QUEUE_CONFIG optional path to an alternative config file (sandbox)
// RUNNER_TEMP scratch directory for the bare compose repository
// RUNNER_TEMP scratch directory for the bare compose repository; with
// config.landing.signing "ssh", the merge-commit signing key is read
// from compose.signingKeyPath(RUNNER_TEMP), written there by the
// workflow from the OMNI_QUEUE_SIGNING_KEY secret (never this process's
// environment); no file = the batch is composed unsigned, one `error` event
// GITHUB_SERVER_URL, GITHUB_RUN_ID for run links in history/dashboard
// GITHUB_API_URL REST API root (default https://api.github.com; GHES / tests)
// OMNI_QUEUE_REMOTE_URL TESTS/SANDBOX ONLY: git remote of the repository instead of
@@ -142,6 +149,11 @@
// mode would have done is recorded instead: `culprit-found` (with a shadow note) and
// `would-dequeue` events, and the head is remembered in state.shadow.processed so it is not
// batched again. Issues the queue owns (dashboard, base-red notice) are still written.
//
// OWNER VOICE (config.voice "owner", voice.mjs): those two, every issue comment (comment) and the
// dashboard and divergence issues go out with the owner's token, each retried with the App's on a
// missing token or a 401/403, recorded once per tick (voiceFallback). Statuses, refs, the state
// branch, re-runs and every read stay the App's.
import { mkdirSync } from "node:fs";
import { tmpdir } from "node:os";
@@ -190,6 +202,13 @@ import { createGitHubClient } from "./github.mjs";
import * as landModule from "./land.mjs";
import { readQueueRefsProtection } from "./refs-guard.mjs";
import { StateConflictError, createStateStore, updateStateWithRetry } from "./state.mjs";
import {
VOICE_FALLBACK_PREFIX,
createOwnerLoginReader,
createOwnerVoice,
voiceFallbackDetail,
voiceFallbackNote,
} from "./voice.mjs";
import { WATCHDOG_LIMIT_MINUTES } from "./watchdog.mjs";
export { StateConflictError };
@@ -223,6 +242,13 @@ export class UnmanagedBaseError extends Error {}
* OMNI_QUEUE_LAND_TOKEN, or null when that token is not set
* @property {object|null} landGh client of the squash-api landing: gh itself when
* landing.actor is "app"; with "owner", one with OMNI_QUEUE_LAND_TOKEN, or null without it
* @property {object|null} [voiceGh] config.voice "owner": the client with
* OMNI_QUEUE_LAND_TOKEN that performs the human-visible writes (voice.mjs); null otherwise or
* without the token (the App writes, the fallback is recorded)
* @property {(() => Promise<string>)|null} [ownerLogin] the owner's login read from that token
* (voice.createOwnerLoginReader); null without voiceGh
* @property {{keyPath: string|null}|null} [signing] config.landing.signing "ssh": the signing
* key file of every merge commit (compose.composeCandidate `signing`); null = no signing
* @property {string} repoDir scratch dir for the bare compose repository
* @property {string} remoteUrl https://github.com/<owner>/<repo>.git
* @property {string|null} [fetchFilter] partial-clone filter for the scratch repository
@@ -580,6 +606,25 @@ class Tick {
? readOnlyGitHub(landGh, this.violations)
: landGh;
this.landGit = null;
/**
* The client of the human-visible writes: the App's own (config.voice "app"), or the owner
* voice (voice.mjs), whose fallbacks to the App's token are recorded by voiceFallback.
*/
this.voice =
this.config.voice === "owner"
? createOwnerVoice({
app: this.gh,
owner: deps.voiceGh
? this.dryRun
? readOnlyGitHub(deps.voiceGh, this.violations)
: deps.voiceGh
: null,
ownerLogin: deps.ownerLogin ?? null,
onFallback: (cause, what) => this.voiceFallback(cause, what),
})
: this.gh;
/** True once this tick recorded a fallback of the owner voice (voiceFallback). */
this.voiceFellBack = false;
this.m = { ...DEFAULT_MODULES, ...(deps.modules ?? {}) };
this.decisions = [];
/** PRs whose queue label this tick removed (GitHub may still list them for a while). */
@@ -738,10 +783,30 @@ class Tick {
return this.s.history.some(predicate);
}
/** Comment on an issue the queue owns (base-red notice, divergence): written in every mode. */
/**
* Comment on an issue the queue owns (base-red notice, divergence, dashboard): written in every
* mode, with the configured voice (this.voice).
*/
async comment(n, key, body) {
if (this.dryRun) return this.note(`would comment on #${n} (${key})`);
await this.gh.commentOnce(n, key, body);
await this.voice.commentOnce(n, key, body);
}
/**
* The owner voice wrote `what` with the App's token for `cause` (voice.mjs: no owner token, or
* GitHub refused it). Every fallback is a note; the first of the tick is also an `error` event,
* unless the newest such event already says exactly this (a token missing for days must not
* add an event, and with it a dashboard change and one more fallback, on every tick).
*/
voiceFallback(cause, what) {
this.note(voiceFallbackNote(what, cause));
if (this.voiceFellBack || !this.s) return;
this.voiceFellBack = true;
const detail = voiceFallbackDetail(cause);
const last = this.s.history.findLast(
(e) => e.type === "error" && String(e.detail ?? "").startsWith(VOICE_FALLBACK_PREFIX)
);
if (last?.detail !== detail) this.event("error", { detail });
}
/** Comment on a PULL REQUEST: never in shadow mode. */
@@ -755,7 +820,7 @@ class Tick {
if (this.shadow) return this.note(`shadow: label "${label}" kept on #${n}`);
this.touched.add(n);
if (this.dryRun) return this.note(`would remove label "${label}" from #${n}`);
await this.gh.removeLabel(n, label);
await this.voice.removeLabel(n, label);
}
/**
@@ -2407,7 +2472,7 @@ class Tick {
let issue = existing?.number ?? null;
if (existing) await this.comment(existing.number, `divergence:${f.batchId}`, body);
else if (this.dryRun) this.note(`would open issue "${title}"`);
else issue = (await this.gh.createIssue({ title, body, labels: [DASHBOARD_LABEL] })).number;
else issue = (await this.voice.createIssue({ title, body, labels: [DASHBOARD_LABEL] })).number;
this.setPaused({
reason: "tree-divergence",
since: this.now(),
@@ -3283,7 +3348,17 @@ class Tick {
prs,
batchId,
heads,
...(this.deps.signing ? { signing: this.deps.signing } : {}),
});
// Signing asked for and not (fully) done: the batch goes on unsigned (never blocked), and the
// operator is told once per batch. The cause names no key material and no path.
if (result.signing && result.signing.unsigned > 0) {
const detail =
`${batchId}: ${result.signing.unsigned} merge commit(s) composed unsigned: ` +
String(result.signing.cause ?? "unknown cause");
this.event("error", { batchId, detail });
this.note(detail);
}
for (const pr of result.excludedBaseConflict ?? []) {
if (this.shadow) {
this.wouldDequeue(pr, "base-conflict", batchId);
@@ -3851,7 +3926,7 @@ class Tick {
return null;
}
try {
return await this.m.dashboard.upsertDashboard({ gh: this.gh, base: this.base, body });
return await this.m.dashboard.upsertDashboard({ gh: this.voice, base: this.base, body });
} catch (error) {
// Cosmetic: never let the dashboard block the state save of real transitions.
this.note(`dashboard update failed: ${error.message}`);
@@ -4076,7 +4151,7 @@ export async function recordTickFailure(deps, base, detail, warn = () => {}, rec
// A base whose stored withdrawals are its only work is found by the next scheduled tick
// through its open dashboard issue (discoverBases): one is created when none is open.
try {
await dashboardIssueOf(deps, base, saved);
await dashboardIssueOf(deps, base, saved, voiceOf(deps, warn));
} catch (error) {
warn(`dashboard of a base with stored withdrawals not created: ${error.message}`);
}
@@ -4461,7 +4536,7 @@ export function amendFailedTick(state, record, options) {
* @param {QueueState} state
* @returns {Promise<number>}
*/
async function dashboardIssueOf(deps, base, state) {
async function dashboardIssueOf(deps, base, state, voice = deps.gh) {
const issue = await findDashboard({ gh: deps.gh, base });
if (issue !== null) return issue;
const body = renderDashboard({
@@ -4473,7 +4548,23 @@ async function dashboardIssueOf(deps, base, state) {
runUrl: deps.runUrl ?? null,
repository: deps.repository,
});
return createDashboard({ gh: deps.gh, base, body });
return createDashboard({ gh: voice, base, body });
}
/**
* The client of the human-visible writes outside a Tick (main()'s failure path): deps.gh with
* config.voice "app", else the owner voice, whose fallbacks to the App's token go to `warn`.
* @param {TickDeps} deps
* @param {(message: string) => void} warn
*/
function voiceOf(deps, warn) {
if (deps.config.voice !== "owner") return deps.gh;
return createOwnerVoice({
app: deps.gh,
owner: deps.voiceGh ?? null,
ownerLogin: deps.ownerLogin ?? null,
onFallback: (cause, what) => warn(voiceFallbackNote(what, cause)),
});
}
/**
@@ -4492,9 +4583,10 @@ async function dashboardIssueOf(deps, base, state) {
async function deliverStalledAlert(deps, base, state, warn) {
const episode = state.stalled;
const key = stalledKey(episode.since);
const voice = voiceOf(deps, warn);
try {
const issue = await dashboardIssueOf(deps, base, state);
await deps.gh.commentOnce(
const issue = await dashboardIssueOf(deps, base, state, voice);
await voice.commentOnce(
issue,
key,
stalledComment({ base, stalled: episode, config: deps.config })
@@ -4658,8 +4750,9 @@ export function parseArgs(argv) {
/**
* Build the TickDeps exactly as the CLI does, from the environment (see the header). The GitHub
* client counts only comment markers written by `${config.appSlug}[bot]`, so a third party
* cannot pre-post a marker to mute a queue comment.
* client counts only comment markers written by `${config.appSlug}[bot]` (and, with the owner
* voice, by the owner's login read from OMNI_QUEUE_LAND_TOKEN itself), so a third party cannot
* pre-post a marker to mute a queue comment.
* @param {object} env process.env-like
* @param {{now?: () => string, log?: (msg: string) => void, gitEnv?: object}} [overrides]
* tests only: injected clock, logger and extra environment for every git process
@@ -4700,25 +4793,28 @@ export function createTickDeps(env, overrides = {}) {
const remoteUrl = env.OMNI_QUEUE_REMOTE_URL || `${serverUrl}/${repository}.git`;
const gitEnv = overrides.gitEnv ?? {};
const gitFor = (cwd) => createGit({ cwd, token, identity, log, env: gitEnv });
// The owner's token, when landing as the owner: never an error here (shadow runs without it);
// a live landing without it pauses (Tick.landOrWouldLand).
const landToken = owner ? env.OMNI_QUEUE_LAND_TOKEN || null : null;
// The owner's token, when landing as the owner or speaking as the owner: never an error here
// (shadow runs without it, the voice falls back to the App); a live landing without it pauses
// (Tick.landOrWouldLand).
const ownerVoice = config.voice === "owner";
const ownerToken = owner || ownerVoice ? env.OMNI_QUEUE_LAND_TOKEN || null : null;
const landToken = owner ? ownerToken : null;
const landGitFor = !owner
? gitFor
: landToken
? (cwd) => createGit({ cwd, token: landToken, identity, log, env: gitEnv })
: null;
const landGh = !owner
? gh
: landToken
? createGitHubClient({
token: landToken,
repository,
apiUrl: env.GITHUB_API_URL || undefined,
botLogin: `${config.appSlug}[bot]`,
log,
})
: null;
const ownerGh = ownerToken
? createGitHubClient({
token: ownerToken,
repository,
apiUrl: env.GITHUB_API_URL || undefined,
botLogin: `${config.appSlug}[bot]`,
log,
})
: null;
const landGh = !owner ? gh : ownerGh;
const voiceGh = ownerVoice ? ownerGh : null;
return {
config,
gh,
@@ -4726,6 +4822,13 @@ export function createTickDeps(env, overrides = {}) {
gitFor,
landGitFor,
landGh,
voiceGh,
ownerLogin: createOwnerLoginReader(voiceGh),
// The key file the workflow wrote (never the key itself); missing = composed unsigned.
signing:
config.landing.signing === "ssh"
? { keyPath: composeModule.signingKeyPath(env.RUNNER_TEMP) }
: null,
repoDir,
remoteUrl,
// A local or file remote cannot serve a partial clone reliably: fetch everything.

View File

@@ -0,0 +1,156 @@
// scripts/merge-queue/voice.mjs — who performs the queue's human-visible writes (config `voice`).
//
// With `voice: "app"` (the default) the tick uses the App's client for everything, as before; this
// module is not involved. With `voice: "owner"` the writes people read on GitHub go out with the
// owner's token (OMNI_QUEUE_LAND_TOKEN, the token the tick already holds for the landing):
// - every comment the tick posts on a pull request, and every label it removes from one;
// - the dashboard issue: opening it, updating its body, its comments (the stalled alert too);
// - comments on the base-red issue, and the tree-divergence issue if the tick opens one.
// Everything else stays the App's: commit statuses (omni-queue/land, the approvals, a bless),
// candidate branches, the omni-queue-state branch, re-runs of workflow jobs, and every read.
//
// NEVER LOSE A MESSAGE. The owner's token absent, or a 401/403 from GitHub on an owner write (or
// on reading the owner's login): the same write is made with the App's token, and the caller is
// told through `onFallback` (the tick records it once per tick, see Tick.voiceFallback). Any other
// error (a 5xx, a timeout) is thrown as the App's own errors are: the next tick redoes the write,
// whose idempotence (commentOnce markers, an absent label, the dashboard upsert) is unchanged.
//
// The queue recognises its own comments by their marker AND their author (github.commentOnce).
// Under the owner voice the owner's login counts too. That login is read from the owner's token
// itself (GET /user, once per process), never from configuration or any other text.
//
// Zero-dependency on purpose, like every module the queue workflow runs.
import { VOICES } from "./config.mjs";
export { VOICES };
/** Start of the `error` event detail that records a fallback (one per tick, Tick.voiceFallback). */
export const VOICE_FALLBACK_PREFIX = "owner voice unavailable";
/** The `error` event detail of a fallback whose cause is `cause`. */
export const voiceFallbackDetail = (cause) =>
`${VOICE_FALLBACK_PREFIX}, written with the App's token instead: ${cause}`;
/** The one-line note (log, decisions) of the write `what` that fell back for `cause`. */
export const voiceFallbackNote = (what, cause) =>
`owner voice: ${what} written with the App's token (${cause})`;
/** A user login (never a bot's: `[bot]` and anything else is refused). */
const USER_LOGIN_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/;
/** The owner's token is not there: the tick runs without OMNI_QUEUE_LAND_TOKEN. */
export const NO_OWNER_TOKEN_CAUSE = "OMNI_QUEUE_LAND_TOKEN is not set";
/** GitHub's answer that a credential cannot make this call (bad token, missing permission). */
const isRefusal = (error) => error?.status === 401 || error?.status === 403;
/** A reason to write as the App, carried from the login read to the write. */
class Fallback extends Error {}
/**
* The owner's login, read once from the owner's token (GET /user) and remembered for the life of
* the process; a refusal (401/403) is remembered too, so a dead token is not asked again on every
* write. Any other failure (a 5xx, a timeout) is not remembered: the next call reads again.
* @param {{getAuthenticatedLogin: () => Promise<string>}|null} ownerGh
* @returns {(() => Promise<string>)|null} null without a client
*/
export function createOwnerLoginReader(ownerGh) {
if (!ownerGh) return null;
let settled = null;
return () => {
if (!settled) {
settled = ownerGh.getAuthenticatedLogin().catch((error) => {
if (!isRefusal(error)) settled = null;
throw error;
});
}
return settled;
};
}
/**
* The client of the owner voice: the writes listed above with the owner's client, each one
* retried with the App's on a refusal; reads with the App's client.
* @param {{app: object, owner: object|null, ownerLogin: (() => Promise<string>)|null,
* onFallback?: (cause: string, what: string) => void}} input
* app = the App's client (github.mjs); owner = the owner's, null when OMNI_QUEUE_LAND_TOKEN is
* not set; ownerLogin = createOwnerLoginReader(owner)
* @returns {{listIssues: Function, commentOnce: Function, removeLabel: Function,
* createIssue: Function, updateIssue: Function}}
*/
export function createOwnerVoice({ app, owner, ownerLogin, onFallback = () => {} }) {
/** The owner's login, or a Fallback naming why the App writes instead. */
async function login() {
if (!owner || !ownerLogin) throw new Fallback(NO_OWNER_TOKEN_CAUSE);
let value;
try {
value = await ownerLogin();
} catch (error) {
if (!isRefusal(error)) throw error;
throw new Fallback(`GitHub refused the owner's token reading its login (${error.status})`);
}
if (typeof value !== "string" || !USER_LOGIN_RE.test(value)) {
throw new Fallback("the owner's token does not name a user account");
}
return value;
}
/**
* One write: with the owner's client, else (no token, a refusal) with the App's. `asApp`
* receives the owner's login when it is known (null otherwise).
*/
async function write(what, asOwner, asApp) {
let known;
try {
known = await login();
} catch (error) {
if (!(error instanceof Fallback)) throw error;
onFallback(error.message, what);
return asApp(null);
}
try {
return await asOwner(known);
} catch (error) {
if (!isRefusal(error)) throw error;
onFallback(`GitHub refused the owner's token (${error.status})`, what);
return asApp(known);
}
}
return {
listIssues: (...args) => app.listIssues(...args),
commentOnce: (n, key, body) =>
write(
`comment ${key} on #${n}`,
(known) => owner.commentOnce(n, key, body, { reader: app, alsoLogins: [known] }),
// The App's retry still counts the owner's earlier markers when the login is known.
(known) =>
known
? app.commentOnce(n, key, body, { alsoLogins: [known] })
: app.commentOnce(n, key, body)
),
removeLabel: (n, label) =>
write(
`label "${label}" removed from #${n}`,
() => owner.removeLabel(n, label),
() => app.removeLabel(n, label)
),
createIssue: (input) =>
write(
`issue "${input?.title ?? ""}" opened`,
() => owner.createIssue(input),
() => app.createIssue(input)
),
updateIssue: (n, patch) =>
write(
`issue #${n} updated`,
() => owner.updateIssue(n, patch),
() => app.updateIssue(n, patch)
),
};
}

View File

@@ -0,0 +1,118 @@
#!/usr/bin/env node
import { execFileSync, spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { main as validateAcceptance } from "../validate-release-acceptance.mjs";
import { gateKey } from "./types.mjs";
const GATE = "gate-manifest";
const REPORT = "release-acceptance-report.json";
function identifyCheckout(env, cwd) {
const { GITHUB_REPOSITORY, GITHUB_RUN_ID, GITHUB_EVENT_NAME, GITHUB_REF, GITHUB_SHA } = env;
const attempt = Number(env.GITHUB_RUN_ATTEMPT);
if (
!/^[\w.-]+\/[\w.-]+$/.test(GITHUB_REPOSITORY ?? "") ||
!/^[1-9]\d*$/.test(GITHUB_RUN_ID ?? "") ||
!Number.isSafeInteger(attempt) ||
attempt < 1 ||
!GITHUB_REF?.startsWith("refs/heads/") ||
!["push", "workflow_dispatch"].includes(GITHUB_EVENT_NAME) ||
!/^[0-9a-f]{40}$/.test(GITHUB_SHA ?? "")
) {
throw new Error("Release acceptance requires a valid GitHub workflow identity");
}
const tested = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
if (tested !== GITHUB_SHA) throw new Error("Release acceptance checkout SHA mismatch");
execFileSync("git", ["diff", "--quiet", "HEAD", "--"], { cwd });
return {
repository: GITHUB_REPOSITORY,
run_id: GITHUB_RUN_ID,
run_attempt: attempt,
workflow: "release-acceptance.yml",
trigger: GITHUB_EVENT_NAME,
scope: "release",
requested_ref: GITHUB_REF,
base_sha: tested,
candidate_sha: tested,
tested_sha: tested,
};
}
export async function runShadow(out, { env = process.env, cwd = process.cwd() } = {}) {
const identity = identifyCheckout(env, cwd);
const key = gateKey({ gate_id: GATE });
const logs = join(out, "logs");
const manifests = join(out, "manifests");
const plan = join(out, "plan.json");
mkdirSync(logs, { recursive: true });
mkdirSync(manifests, { recursive: true });
const started = performance.now();
const execution = spawnSync(process.execPath, ["scripts/quality/gate-manifest.mjs"], {
cwd,
env,
encoding: "utf8",
});
const duration = Math.round(performance.now() - started);
const output = Buffer.from(
[execution.stdout, execution.stderr, execution.error?.message, execution.signal]
.filter(Boolean)
.join("\n")
);
const status =
execution.error || execution.status == null
? "INFRA_ERROR"
: execution.status === 0
? "PASS"
: "FAIL";
writeFileSync(join(logs, GATE + ".log"), output);
writeFileSync(plan, JSON.stringify({ identity, required_gates: [key], artifact: null }) + "\n");
writeFileSync(
join(manifests, GATE + ".json"),
JSON.stringify({
...key,
tested_sha: identity.tested_sha,
run_id: identity.run_id,
run_attempt: identity.run_attempt,
command_id: "check:gate-manifest",
gate_type: "static",
status,
cause: null,
exit_code: execution.status,
duration_ms: duration,
evidence: [
{
artifact_id: "logs",
member: GATE + ".log",
algorithm: "sha256",
digest: createHash("sha256").update(output).digest("hex"),
},
],
}) + "\n"
);
const code = await validateAcceptance([
process.execPath,
"validate-release-acceptance.mjs",
"--plan",
plan,
"--manifests",
manifests,
"--evidence-root",
out,
"--out",
join(out, REPORT),
]);
console.log(
`Release acceptance shadow validated ${identity.tested_sha} (exit ${code}, gate: ${GATE})`
);
return code;
}
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
const out = process.argv[2];
if (!out) throw new Error("Release acceptance shadow requires an artifact output directory");
process.exitCode = await runShadow(out);
}

View File

@@ -1,7 +1,7 @@
"use client";
import { type ReactNode, useCallback, useEffect, useState } from "react";
import { Button, Card, Select } from "@/shared/components";
import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
import { Badge, Button, Card, Input, Select } from "@/shared/components";
import Icon from "@/shared/components/Icon";
import { Spinner } from "@/shared/components/Loading";
import { useNotificationStore } from "@/store/notificationStore";
@@ -1130,12 +1130,28 @@ function CredentialHealthCheckCard({
);
}
// Mirrors `customBannedSignals: z.array(z.string().max(200))` in
// src/shared/validation/settingsSchemas.ts — keep the two in sync.
const MAX_BANNED_KEYWORD_LENGTH = 200;
export default function ResilienceTab() {
const notify = useNotificationStore();
const t = useTranslations("settings");
const tc = useTranslations("common");
const [data, setData] = useState<ResilienceResponse | null>(null);
const [loading, setLoading] = useState(true);
const [savingSection, setSavingSection] = useState<string | null>(null);
const [bannedKeywords, setBannedKeywords] = useState<string[]>([]);
const [bannedKeywordInput, setBannedKeywordInput] = useState("");
const [bannedKeywordsLoading, setBannedKeywordsLoading] = useState(true);
const [bannedKeywordsLoadFailed, setBannedKeywordsLoadFailed] = useState(false);
const [savingBannedKeywords, setSavingBannedKeywords] = useState(false);
const [bannedKeywordsLoadToken, setBannedKeywordsLoadToken] = useState(0);
// The ref is the single source of truth: it always holds the last list the
// server confirmed. Rapid add/remove clicks therefore cannot build on a
// stale closure value, and a failed PATCH never desyncs UI from server.
const bannedKeywordsRef = useRef<string[]>([]);
const bannedKeywordsSavingRef = useRef(false);
const tx = useCallback(
(key: string, fallback: string) => {
if (typeof t.has === "function" && t.has(key as never)) {
@@ -1146,6 +1162,102 @@ export default function ResilienceTab() {
[t]
);
// Custom banned keywords live in /api/settings, not in the resilience
// payload, so this card loads and saves them independently. It belongs on
// the Resilience page next to AutoDisableCard: it decides when an upstream
// error permanently bans and disables a connection.
useEffect(() => {
let mounted = true;
const load = async () => {
setBannedKeywordsLoading(true);
setBannedKeywordsLoadFailed(false);
try {
const res = await fetch("/api/settings");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const settings = await res.json();
if (!mounted) return;
// The classifier lowercases the error body but NOT the signal itself, so
// uppercase values imported elsewhere would never match. Normalise on
// load (trim + lowercase + dedupe); keep long values rather than
// silently discarding server-side data — adding is guarded separately.
const list: string[] = Array.isArray(settings?.customBannedSignals)
? Array.from(
new Set(
settings.customBannedSignals
.filter((v: unknown) => typeof v === "string")
.map((v: string) => v.trim().toLowerCase())
.filter(Boolean)
)
)
: [];
bannedKeywordsRef.current = list;
setBannedKeywords(list);
} catch (error) {
console.error("Failed to load custom banned signals:", error);
// Never show the "no keywords" empty state when loading failed:
// editing from there would overwrite the real server-side list.
if (mounted) setBannedKeywordsLoadFailed(true);
} finally {
if (mounted) setBannedKeywordsLoading(false);
}
};
void load();
return () => {
mounted = false;
};
}, [bannedKeywordsLoadToken]);
// Commit only after the server accepts the write. The synchronous ref lock
// serialises edits so two quick clicks cannot race on a stale array.
const saveBannedKeywords = async (next: string[]): Promise<boolean> => {
if (bannedKeywordsSavingRef.current) return false;
bannedKeywordsSavingRef.current = true;
setSavingBannedKeywords(true);
try {
const res = await fetch("/api/settings", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ customBannedSignals: next }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
bannedKeywordsRef.current = next;
setBannedKeywords(next);
return true;
} catch (error) {
console.error("Failed to update custom banned signals:", error);
notify.error(tx("saveFailed", "Failed to save banned keywords"));
return false;
} finally {
bannedKeywordsSavingRef.current = false;
setSavingBannedKeywords(false);
}
};
const bannedKeywordsBusy =
bannedKeywordsLoading || bannedKeywordsLoadFailed || savingBannedKeywords;
const addBannedKeyword = async () => {
if (bannedKeywordsBusy || bannedKeywordsSavingRef.current) return;
const keyword = bannedKeywordInput.trim().toLowerCase();
if (!keyword || bannedKeywordsRef.current.includes(keyword)) return;
// Defence in depth for the Input's maxLength: the server rejects strings
// longer than 200 chars (settingsSchemas.ts), which would otherwise be a
// silent failure.
if (keyword.length > MAX_BANNED_KEYWORD_LENGTH) {
notify.error(tx("saveFailed", "Failed to save banned keywords"));
return;
}
const saved = await saveBannedKeywords([...bannedKeywordsRef.current, keyword]);
if (saved) setBannedKeywordInput("");
};
// Remove by value, not by index: with an async save an index can go stale
// between two quick clicks (and makes a stable React key).
const removeBannedKeyword = (keyword: string) => {
if (bannedKeywordsBusy || bannedKeywordsSavingRef.current) return;
void saveBannedKeywords(bannedKeywordsRef.current.filter((k) => k !== keyword));
};
useEffect(() => {
let mounted = true;
@@ -1199,29 +1311,115 @@ export default function ResilienceTab() {
}
};
// The banned-keyword editor reads /api/settings, not /api/resilience.
// Keep it outside the resilience-data guards: if /api/resilience fails,
// keyword management must still work (SecurityTab no longer has an editor).
const bannedKeywordsCard = (
<Card
icon="report"
title={tx("customBannedSignals", "Banned Keywords")}
subtitle={tx(
"customBannedSignalsDesc",
"Additional keywords that trigger permanent account ban detection. Built-in keywords always apply."
)}
>
<div className="flex flex-col gap-4">
<div className="flex flex-col sm:flex-row sm:items-start gap-2">
<Input
className="flex-1"
aria-label={tx("customBannedSignals", "Banned Keywords")}
placeholder={tx("customBannedSignalsPlaceholder", "e.g. api key revoked")}
value={bannedKeywordInput}
maxLength={MAX_BANNED_KEYWORD_LENGTH}
disabled={bannedKeywordsBusy}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setBannedKeywordInput(e.target.value)
}
onKeyDown={(e: React.KeyboardEvent) => {
if (e.key === "Enter") void addBannedKeyword();
}}
/>
<Button
variant="secondary"
size="sm"
icon="add"
onClick={() => void addBannedKeyword()}
disabled={bannedKeywordsBusy || !bannedKeywordInput.trim()}
>
{tc("add")}
</Button>
</div>
{bannedKeywordsLoadFailed ? (
<div className="flex items-center gap-2">
<p className="text-xs text-error">{tx("errorOccurred", "An error occurred")}</p>
<Button
variant="ghost"
size="sm"
icon="refresh"
onClick={() => setBannedKeywordsLoadToken((n) => n + 1)}
>
{tx("retry", "Retry")}
</Button>
</div>
) : bannedKeywordsLoading ? (
<Spinner decorative size="sm" />
) : bannedKeywords.length > 0 ? (
<div className="flex flex-wrap gap-2">
{bannedKeywords.map((keyword) => (
<Badge key={keyword} variant="error" className="gap-1 pr-1">
{keyword}
<Button
variant="ghost"
size="icon-sm"
className="size-5"
disabled={savingBannedKeywords}
onClick={() => removeBannedKeyword(keyword)}
aria-label={`${tx("remove", "Remove")} ${keyword}`}
>
<Icon name="close" size={12} />
</Button>
</Badge>
))}
</div>
) : (
<p className="text-xs text-text-muted">
{tx("noCustomBannedSignals", "No custom keywords. Only built-in keywords are active.")}
</p>
)}
</div>
</Card>
);
if (loading && !data) {
return (
<Card className="p-6">
<div role="status" className="flex items-center gap-2 text-sm text-text-muted">
<Spinner decorative size="sm" />
{tx("loadingResilience", "Loading resilience settings...")}
</div>
</Card>
<div className="space-y-6">
{bannedKeywordsCard}
<Card className="p-6">
<div role="status" className="flex items-center gap-2 text-sm text-text-muted">
<Spinner decorative size="sm" />
{tx("loadingResilience", "Loading resilience settings...")}
</div>
</Card>
</div>
);
}
if (!data) {
return (
<Card className="p-6">
<p className="text-sm text-text-muted">
{tx("failedLoadResilience", "Unable to load resilience settings.")}
</p>
</Card>
<div className="space-y-6">
{bannedKeywordsCard}
<Card className="p-6">
<p className="text-sm text-text-muted">
{tx("failedLoadResilience", "Unable to load resilience settings.")}
</p>
</Card>
</div>
);
}
return (
<div className="space-y-6">
{bannedKeywordsCard}
<AutoDisableCard />
{data.preferredAccountFailover && (
<PreferredAccountFailoverCard

View File

@@ -2,7 +2,7 @@
import { useState, useEffect } from "react";
import { Checkbox, CheckboxGroup } from "@omniroute/ui-kit/checkbox";
import { Card, Button, Input, Toggle, Modal, Badge } from "@/shared/components";
import { Card, Button, Input, Toggle, Modal } from "@/shared/components";
import Icon from "@/shared/components/Icon";
import { AI_PROVIDERS } from "@/shared/constants/providers";
import ProviderIcon from "@/shared/components/ProviderIcon";
@@ -32,7 +32,6 @@ export default function SecurityTab() {
const [requireLoginPassword, setRequireLoginPassword] = useState("");
const [requireLoginError, setRequireLoginError] = useState("");
const [requireLoginLoading, setRequireLoginLoading] = useState(false);
const [newBannedKeyword, setNewBannedKeyword] = useState("");
const t = useTranslations("settings");
const tc = useTranslations("common");
@@ -146,20 +145,6 @@ export default function SecurityTab() {
updateSetting("blockedProviders", updated);
};
const customBannedSignals: string[] = settings.customBannedSignals || [];
const addBannedKeyword = () => {
const keyword = newBannedKeyword.trim().toLowerCase();
if (!keyword || customBannedSignals.includes(keyword)) return;
updateSetting("customBannedSignals", [...customBannedSignals, keyword]);
setNewBannedKeyword("");
};
const removeBannedKeyword = (index: number) => {
const updated = customBannedSignals.filter((_, i) => i !== index);
updateSetting("customBannedSignals", updated);
};
const handlePasswordChange = async (e) => {
e.preventDefault();
if (passwords.new !== passwords.confirm) {
@@ -409,70 +394,6 @@ export default function SecurityTab() {
</div>
</Card>
{/* Custom Banned Keywords */}
<Card
icon="report"
title={getSettingsLabel("customBannedSignals", "Banned Keywords")}
subtitle={getSettingsLabel(
"customBannedSignalsDesc",
"Additional keywords that trigger permanent account ban detection. Built-in keywords always apply."
)}
>
<div className="flex flex-col gap-4">
<div className="flex flex-col sm:flex-row sm:items-start gap-2">
<Input
className="flex-1"
aria-label={getSettingsLabel("customBannedSignals", "Banned Keywords")}
placeholder={getSettingsLabel(
"customBannedSignalsPlaceholder",
"e.g. api key revoked"
)}
value={newBannedKeyword}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setNewBannedKeyword(e.target.value)
}
onKeyDown={(e: React.KeyboardEvent) => {
if (e.key === "Enter") addBannedKeyword();
}}
/>
<Button
variant="secondary"
size="sm"
icon="add"
onClick={addBannedKeyword}
disabled={!newBannedKeyword.trim()}
>
{getSettingsLabel("add", "Add")}
</Button>
</div>
{customBannedSignals.length > 0 ? (
<div className="flex flex-wrap gap-2">
{customBannedSignals.map((keyword, index) => (
<Badge key={index} variant="error" className="gap-1 pr-1">
{keyword}
<Button
variant="ghost"
size="icon-sm"
className="size-5"
onClick={() => removeBannedKeyword(index)}
aria-label={`${getSettingsLabel("remove", "Remove")} ${keyword}`}
>
<Icon name="close" size={12} />
</Button>
</Badge>
))}
</div>
) : (
<p className="text-xs text-text-muted">
{getSettingsLabel(
"noCustomBannedSignals",
"No custom keywords. Only built-in keywords are active."
)}
</p>
)}
</div>
</Card>
<Card
icon="shield"
title={getSettingsLabel("credentialRedaction", "Credential Redaction")}

View File

@@ -11,6 +11,7 @@ import {
getConfiguredLocalCorpusStatus,
resetLocalCorpusIndex,
} from "@/lib/localCorpus/configured";
import { requireOperatorCredential } from "@/lib/api/operatorCredential";
import { isAuthenticated } from "@/shared/utils/apiAuth";
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error";
@@ -20,6 +21,11 @@ const localCorpusSchema = z
})
.strict();
// CodeQL #1371: the root is indexed and served by the MCP local-corpus search tools, so choosing
// it is an operator action. A machine credential (an API key of any scope) gets 403.
const LOCAL_CORPUS_ROOT_FORBIDDEN_MESSAGE =
"Choosing the local corpus root requires a signed-in dashboard session or the local CLI; API keys and access tokens cannot change it.";
export async function GET(request: NextRequest) {
if (!(await isAuthenticated(request))) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
@@ -40,6 +46,10 @@ export async function POST(request: NextRequest) {
if (!(await isAuthenticated(request))) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const operatorVerdict = await requireOperatorCredential(request, {
forbiddenMessage: LOCAL_CORPUS_ROOT_FORBIDDEN_MESSAGE,
});
if (operatorVerdict.ok === false) return operatorVerdict.response;
let body: unknown;
try {

View File

@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import { z } from "zod";
import { isAuthenticated } from "@/shared/utils/apiAuth";
import { requireManagementAuth } from "@/lib/api/requireManagementAuth";
import { requireOperatorCredential } from "@/lib/api/operatorCredential";
import { buildErrorBody } from "@omniroute/open-sse/utils/error";
import {
getObsidianSyncStatus,
@@ -15,6 +16,12 @@ const enableSchema = z
})
.strict();
// CodeQL #1372/#1373: the vault becomes the root of a read/write WebDAV service with freshly
// minted credentials, so choosing it is an operator action. The route is ALWAYS_PROTECTED, so an
// open instance (login disabled) does not make a machine credential the operator either.
const WEBDAV_VAULT_FORBIDDEN_MESSAGE =
"Choosing the WebDAV vault requires a signed-in dashboard session or the local CLI; API keys and access tokens cannot change it.";
export async function GET(request: NextRequest) {
if (!(await isAuthenticated(request))) {
return NextResponse.json(buildErrorBody(401, "Authentication required"), { status: 401 });
@@ -32,8 +39,7 @@ export async function GET(request: NextRequest) {
return NextResponse.json({
webdavEnabled: status.webdavEnabled,
webdavUsername: status.webdavEnabled ? status.webdavUsername : null,
webdavPassword:
status.webdavEnabled && hasManagement ? status.webdavPassword : null,
webdavPassword: status.webdavEnabled && hasManagement ? status.webdavPassword : null,
webdavPasswordSet: status.webdavEnabled && Boolean(status.webdavPassword),
vaultPath: status.vaultPath,
});
@@ -47,6 +53,11 @@ export async function POST(request: NextRequest) {
if (!(await isAuthenticated(request))) {
return NextResponse.json(buildErrorBody(401, "Authentication required"), { status: 401 });
}
const operatorVerdict = await requireOperatorCredential(request, {
forbiddenMessage: WEBDAV_VAULT_FORBIDDEN_MESSAGE,
alwaysRequireAuth: true,
});
if (operatorVerdict.ok === false) return operatorVerdict.response;
let rawBody: unknown;
try {
@@ -57,10 +68,7 @@ export async function POST(request: NextRequest) {
const parsed = enableSchema.safeParse(rawBody);
if (!parsed.success) {
return NextResponse.json(
buildErrorBody(400, "Missing or invalid vaultPath"),
{ status: 400 }
);
return NextResponse.json(buildErrorBody(400, "Missing or invalid vaultPath"), { status: 400 });
}
const result = await enableObsidianVaultSync(parsed.data.vaultPath);

View File

@@ -1,6 +1,8 @@
import { z } from "zod";
import { getCachedSettings } from "@/lib/db/readCache";
import { getImageModelEntry } from "@omniroute/open-sse/config/imageRegistry.ts";
import {
MAX_CODEX_IMAGE_EDIT_REFERENCES,
extractImageEditInputFromJson,
resolveRemoteImageEditReferences,
} from "@/lib/images/imageRouteModel";
@@ -31,6 +33,15 @@ const ImageEditJsonSchema = z
})
.passthrough();
/** Keep larger prefetch only for a registered hosted Codex model, never GPT Image. */
function hostedCodexReferenceLimit(model: string | undefined): number | undefined {
if (!model) return undefined;
const entry = getImageModelEntry(model);
return entry?.provider === "codex" && !/^gpt-image-/i.test(entry.model)
? MAX_CODEX_IMAGE_EDIT_REFERENCES
: undefined;
}
async function readMultipartOptions(formData: FormData): Promise<Record<string, unknown>> {
const options: Record<string, unknown> = {};
for (const [key, value] of formData.entries()) {
@@ -132,8 +143,13 @@ export async function readEditInput(request: Request): Promise<EditInput | null>
log.warn("IMAGE", "Invalid JSON edit body shape");
return null;
}
// Before model routing, only registered hosted Codex models opt in to
// 128 remote references. GPT Image and unresolved combos keep the
// conservative 16-reference prefetch guard.
const hostedMaxReferences = hostedCodexReferenceLimit(parsed.data.model);
const resolved = await resolveRemoteImageEditReferences(parsed.data, {
signal: request.signal,
maxReferences: hostedMaxReferences,
});
const extracted = extractImageEditInputFromJson(resolved);
return extracted

View File

@@ -13,6 +13,7 @@ import {
handleFalAIImageEdit,
isFalImageEditModel,
} from "@omniroute/open-sse/handlers/imageGeneration/providers/fal.ts";
import { handleLeonardoImageGeneration } from "@omniroute/open-sse/handlers/imageGeneration/providers/leonardo.ts";
import { GEMINI_IMAGE_MAX_REFERENCES } from "@omniroute/open-sse/handlers/imageGeneration/providers/geminiInline.ts";
import { createInjectionGuard } from "@/middleware/promptInjectionGuard";
import {
@@ -247,8 +248,8 @@ interface EditComboTarget {
/**
* Decide whether a prefix-resolved combo target can service an image edit, and
* return the credential key to resolve it with. Mirrors postHandler's provider
* branches: codex-responses, fal-ai edit models, adobe-firefly, built-in
* openrouter, and custom OpenAI-compatible nodes are edit-capable; every other
* branches: codex-responses, fal-ai edit models, adobe-firefly, syntx, leonardo,
* built-in openrouter, and custom OpenAI-compatible nodes are edit-capable; every other
* built-in provider is not (it exposes no OpenAI-compatible edit endpoint).
*/
function classifyImageEditTarget(
@@ -261,6 +262,7 @@ function classifyImageEditTarget(
providerConfig.format === "codex-responses" ||
providerConfig.format === "adobe-firefly-image" ||
providerConfig.format === "syntx-image" ||
providerConfig.format === "leonardo-image" ||
(providerConfig.format === "fal-ai" &&
isFalImageEditModel(parsed.model, getFalCompatibilityPreparer() !== null)) ||
providerConfig.id === "openrouter"
@@ -429,6 +431,28 @@ async function dispatchImageEditTarget(
})) as ImageComboDispatchResult;
}
// #18671: Leonardo uploads the reference as an init image and runs image-to-image.
if (providerConfig?.format === "leonardo-image") {
// One init image per generation: reject extra references as the single-model path does,
// rather than editing with the first and dropping the rest.
if (images.length > 1) {
return {
success: false,
status: HTTP_STATUS.BAD_REQUEST,
error: "This image edit provider currently supports only one reference image",
};
}
return (await handleLeonardoImageGeneration({
provider: parsed.provider,
model: parsed.model,
providerConfig,
body: { prompt, size: size ?? undefined },
credentials: credentials as never,
log,
initImage: images[0] ?? null,
})) as ImageComboDispatchResult;
}
if (providerConfig?.id === "openrouter") {
return (await handleOpenRouterImageEdit({
provider: parsed.provider,
@@ -951,6 +975,33 @@ async function postHandler(request: Request, _context?: unknown) {
});
}
// #18671: Leonardo uploads the reference as an init image and runs image-to-image.
if (providerConfig?.format === "leonardo-image") {
const preflight = await syntxEditPreflight(parsed.provider, allowedConnections, resolvedModel);
if (preflight instanceof Response) return preflight;
const result = await runImageRequestWithAccounting(
editAccounting(accounting, parsed.provider, parsed.model, preflight.credentials),
() =>
handleLeonardoImageGeneration({
provider: parsed.provider,
model: parsed.model,
providerConfig,
body: { prompt, size: size ?? undefined },
credentials: preflight.credentials as never,
log,
initImage: images[0] ?? null,
})
);
if (result.success) {
await clearRecoveredProviderState(preflight.credentials);
return jsonResponse(result.data);
}
return jsonResponse(
toJsonErrorPayload(result.error, "Image edit provider error"),
result.status ?? HTTP_STATUS.BAD_GATEWAY
);
}
// Built-in OpenRouter uses its unified Image API for reference-image
// edits: POST /api/v1/images with input_references. Forward through the
// provider-specific adapter (#10197), rather than the multipart
@@ -1083,7 +1134,7 @@ async function postHandler(request: Request, _context?: unknown) {
return errorResponse(
HTTP_STATUS.BAD_REQUEST,
`Image edit is not supported for built-in provider "${parsed.provider}". ` +
`Use adobe-firefly, syntx, codex, or a custom OpenAI-compatible image provider.`
`Use adobe-firefly, syntx, codex, leonardo, or a custom OpenAI-compatible image provider.`
);
}

View File

@@ -0,0 +1,51 @@
export type ReasoningRuleScope = "global" | "apiKey" | "combo" | "model" | "connection";
export type ReasoningEffort = "none" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
export type ReasoningSourceEffort = "any" | "missing" | ReasoningEffort;
export type ReasoningEffortMode = "inherit" | "default" | "force";
export type ReasoningTargetKind = "keep" | "model" | "combo";
export type ReasoningBudgetAction = "preserve" | "remove" | "set";
export interface ReasoningRoutingRule {
id: string;
name: string;
description: string;
scope: ReasoningRuleScope;
apiKeyId: string | null;
comboId: string | null;
connectionId: string | null;
modelPattern: string | null;
sourceEffort: ReasoningSourceEffort;
requestTags: string[];
tagMatchMode: "any" | "all";
effortMode: ReasoningEffortMode;
targetEffort: ReasoningEffort | null;
targetKind: ReasoningTargetKind;
targetModel: string | null;
targetComboId: string | null;
budgetAction: ReasoningBudgetAction;
budgetTokens: number | null;
priority: number;
enabled: boolean;
createdAt: string;
updatedAt: string;
}
export type ReasoningRoutingRuleInput = Omit<
ReasoningRoutingRule,
"id" | "createdAt" | "updatedAt"
>;
/** Persistence only; the DB facade owns caching and external invalidation. */
export interface ReasoningRoutingRuleRepository {
/** Priority descending, then creation time and id ascending; returns independent values. */
list(options?: { enabledOnly?: boolean }): Promise<ReasoningRoutingRule[]>;
findById(id: string): Promise<ReasoningRoutingRule | null>;
/** Rejects invalid owner/target references; normalizes tags and directive fields. */
create(input: ReasoningRoutingRuleInput): Promise<ReasoningRoutingRule>;
/** Merges the patch before validating references; missing ids return null. */
update(
id: string,
patch: Partial<ReasoningRoutingRuleInput>
): Promise<ReasoningRoutingRule | null>;
deleteById(id: string): Promise<boolean>;
}

View File

@@ -106,6 +106,28 @@ export async function ensureDbReadyForBoot(
export { isBackgroundServicesDisabled };
/**
* The batch rate-limit E2E server needs the batch polling worker, but must not
* enable the broad collection of production background schedulers just to get
* it. This is deliberately narrower than the normal startup path: it is only
* available to the development custom server under the existing explicit E2E
* open-bootstrap mode, with a second test-harness-only opt-in.
*/
export function shouldStartE2EBatchProcessor(env: NodeJS.ProcessEnv = process.env): boolean {
return (
isBackgroundServicesDisabled(env) &&
env.NODE_ENV === "development" &&
env.OMNIROUTE_E2E_BOOTSTRAP_MODE === "open" &&
env.OMNIROUTE_E2E_ENABLE_BATCH_PROCESSOR === "1"
);
}
async function startBatchProcessor(): Promise<void> {
const { initBatchProcessor } = await import("@omniroute/open-sse/services/batchProcessor");
initBatchProcessor();
console.log("[STARTUP] Batch processor started");
}
async function ensureSecrets(): Promise<void> {
let getPersistedSecret = (_key: string): string | null => null;
let persistSecret = (_key: string, _value: string): void => {};
@@ -725,9 +747,9 @@ export async function registerNodejs(): Promise<void> {
`[STARTUP] Cloud/model sync background bootstrap ${cloudSyncInitialized ? "initialized" : "skipped"}`
);
}
const { initBatchProcessor } = await import("@omniroute/open-sse/services/batchProcessor");
initBatchProcessor();
console.log("[STARTUP] Batch processor started");
await startBatchProcessor();
} else if (shouldStartE2EBatchProcessor()) {
await startBatchProcessor();
}
try {

View File

@@ -1,138 +1,61 @@
import { randomUUID } from "node:crypto";
import { getDbInstance } from "./core";
import type {
ReasoningRoutingRule,
ReasoningRoutingRuleInput,
} from "@/domain/persistence/reasoningRoutingRuleRepository";
import {
getSqliteReasoningRoutingRuleReferenceErrors,
sqliteReasoningRoutingRuleRepository as repository,
} from "./repositories/sqliteReasoningRoutingRuleRepository";
import { registerDbStateResetter } from "./stateReset";
export type ReasoningRuleScope = "global" | "apiKey" | "combo" | "model" | "connection";
export type ReasoningEffort = "none" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
export type ReasoningSourceEffort = "any" | "missing" | ReasoningEffort;
export type ReasoningEffortMode = "inherit" | "default" | "force";
export type ReasoningTargetKind = "keep" | "model" | "combo";
export type ReasoningBudgetAction = "preserve" | "remove" | "set";
export interface ReasoningRoutingRule {
id: string;
name: string;
description: string;
scope: ReasoningRuleScope;
apiKeyId: string | null;
comboId: string | null;
connectionId: string | null;
modelPattern: string | null;
sourceEffort: ReasoningSourceEffort;
requestTags: string[];
tagMatchMode: "any" | "all";
effortMode: ReasoningEffortMode;
targetEffort: ReasoningEffort | null;
targetKind: ReasoningTargetKind;
targetModel: string | null;
targetComboId: string | null;
budgetAction: ReasoningBudgetAction;
budgetTokens: number | null;
priority: number;
enabled: boolean;
createdAt: string;
updatedAt: string;
}
export type ReasoningRoutingRuleInput = Omit<
export type {
ReasoningBudgetAction,
ReasoningEffort,
ReasoningRoutingRule,
"id" | "createdAt" | "updatedAt"
>;
ReasoningRoutingRuleInput,
ReasoningSourceEffort,
} from "@/domain/persistence/reasoningRoutingRuleRepository";
type RuleRow = Record<string, unknown>;
let cache: { version: number; rules: ReasoningRoutingRule[] } | null = null;
let version = 0;
function parseTags(value: unknown): string[] {
try {
const parsed = typeof value === "string" ? JSON.parse(value) : value;
return Array.isArray(parsed)
? [
...new Set(
parsed
.filter((tag): tag is string => typeof tag === "string")
.map((tag) => tag.trim().toLowerCase())
.filter(Boolean)
),
]
: [];
} catch {
return [];
}
}
function rowToRule(row: RuleRow): ReasoningRoutingRule {
return {
id: String(row.id),
name: String(row.name),
description: typeof row.description === "string" ? row.description : "",
scope: row.scope as ReasoningRuleScope,
apiKeyId: typeof row.api_key_id === "string" ? row.api_key_id : null,
comboId: typeof row.combo_id === "string" ? row.combo_id : null,
connectionId: typeof row.connection_id === "string" ? row.connection_id : null,
modelPattern: typeof row.model_pattern === "string" ? row.model_pattern : null,
sourceEffort: row.source_effort as ReasoningSourceEffort,
requestTags: parseTags(row.request_tags),
tagMatchMode: row.tag_match_mode === "all" ? "all" : "any",
effortMode: row.effort_mode as ReasoningEffortMode,
targetEffort:
typeof row.target_effort === "string" ? (row.target_effort as ReasoningEffort) : null,
targetKind: row.target_kind as ReasoningTargetKind,
targetModel: typeof row.target_model === "string" ? row.target_model : null,
targetComboId: typeof row.target_combo_id === "string" ? row.target_combo_id : null,
budgetAction: row.budget_action as ReasoningBudgetAction,
budgetTokens: typeof row.budget_tokens === "number" ? row.budget_tokens : null,
priority: typeof row.priority === "number" ? row.priority : 0,
enabled: row.enabled === 1 || row.enabled === true,
createdAt: String(row.created_at),
updatedAt: String(row.updated_at),
};
}
const pendingMutations = new Set<Promise<unknown>>();
function invalidate(): void {
version += 1;
cache = null;
}
function referenceExists(table: string, id: string | null): boolean {
if (!id) return false;
const allowedTables = new Set(["api_keys", "combos", "provider_connections"]);
if (!allowedTables.has(table)) return false;
return Boolean(getDbInstance().prepare(`SELECT 1 FROM ${table} WHERE id = ?`).get(id));
async function mutate<T>(operation: () => Promise<T>): Promise<T> {
invalidate();
const pending = operation();
pendingMutations.add(pending);
try {
return await pending;
} finally {
// Fence reads on both sides of persistence, even when a backend writes later.
// Failed/no-op mutations only cost a re-read; their errors stay with the caller.
invalidate();
pendingMutations.delete(pending);
}
}
export function getReasoningRoutingRuleReferenceErrors(rule: ReasoningRoutingRuleInput): string[] {
const errors: string[] = [];
if (rule.scope === "apiKey" && !referenceExists("api_keys", rule.apiKeyId)) {
errors.push("The referenced API key does not exist");
}
if (rule.scope === "combo" && !referenceExists("combos", rule.comboId)) {
errors.push("The referenced source combo does not exist");
}
if (rule.scope === "connection" && !referenceExists("provider_connections", rule.connectionId)) {
errors.push("The referenced provider connection does not exist");
}
if (rule.targetKind === "combo" && !referenceExists("combos", rule.targetComboId)) {
errors.push("The referenced target combo does not exist");
}
return errors;
}
function assertReferences(rule: ReasoningRoutingRuleInput): void {
const errors = getReasoningRoutingRuleReferenceErrors(rule);
if (errors.length > 0) throw new Error(errors.join("; "));
return getSqliteReasoningRoutingRuleReferenceErrors(rule);
}
export async function getReasoningRoutingRules(
options: { enabledOnly?: boolean } = {}
): Promise<ReasoningRoutingRule[]> {
if (!cache || cache.version !== version) {
const rows = getDbInstance()
.prepare(
"SELECT * FROM reasoning_routing_rules ORDER BY priority DESC, created_at ASC, id ASC"
)
.all() as RuleRow[];
cache = { version, rules: rows.map(rowToRule) };
while (pendingMutations.size || !cache || cache.version !== version) {
if (pendingMutations.size) {
// A backend may yield before writing; do not read a pre-write snapshot.
await Promise.allSettled([...pendingMutations]);
continue;
}
const readVersion = version;
const rules = await repository.list();
// A reset or external deletion during the await must not repopulate stale rows.
if (readVersion === version) cache = { version: readVersion, rules };
}
const rules = options.enabledOnly ? cache.rules.filter((rule) => rule.enabled) : cache.rules;
return rules.map((rule) => ({ ...rule, requestTags: [...rule.requestTags] }));
@@ -141,99 +64,24 @@ export async function getReasoningRoutingRules(
export async function getReasoningRoutingRuleById(
id: string
): Promise<ReasoningRoutingRule | null> {
const row = getDbInstance()
.prepare("SELECT * FROM reasoning_routing_rules WHERE id = ?")
.get(id) as RuleRow | undefined;
return row ? rowToRule(row) : null;
}
function ruleParams(
rule: ReasoningRoutingRuleInput,
id: string,
createdAt: string,
updatedAt: string
) {
return {
id,
name: rule.name,
description: rule.description || "",
scope: rule.scope,
apiKeyId: rule.apiKeyId ?? null,
comboId: rule.comboId ?? null,
connectionId: rule.connectionId ?? null,
modelPattern: rule.modelPattern ?? null,
sourceEffort: rule.sourceEffort,
requestTags: JSON.stringify(parseTags(rule.requestTags)),
tagMatchMode: rule.tagMatchMode,
effortMode: rule.effortMode,
targetEffort: rule.effortMode === "inherit" ? null : rule.targetEffort,
targetKind: rule.targetKind,
targetModel: rule.targetKind === "model" ? rule.targetModel : null,
targetComboId: rule.targetKind === "combo" ? rule.targetComboId : null,
budgetAction: rule.targetEffort === "none" ? "remove" : rule.budgetAction,
budgetTokens: rule.budgetAction === "set" ? rule.budgetTokens : null,
priority: rule.priority,
enabled: rule.enabled ? 1 : 0,
createdAt,
updatedAt,
};
return repository.findById(id);
}
export async function createReasoningRoutingRule(
rule: ReasoningRoutingRuleInput
): Promise<ReasoningRoutingRule> {
assertReferences(rule);
const id = randomUUID();
const now = new Date().toISOString();
getDbInstance()
.prepare(
`INSERT INTO reasoning_routing_rules (
id, name, description, scope, api_key_id, combo_id, connection_id, model_pattern,
source_effort, request_tags, tag_match_mode, effort_mode, target_effort, target_kind,
target_model, target_combo_id, budget_action, budget_tokens, priority, enabled, created_at, updated_at
) VALUES (
@id, @name, @description, @scope, @apiKeyId, @comboId, @connectionId, @modelPattern,
@sourceEffort, @requestTags, @tagMatchMode, @effortMode, @targetEffort, @targetKind,
@targetModel, @targetComboId, @budgetAction, @budgetTokens, @priority, @enabled, @createdAt, @updatedAt
)`
)
.run(ruleParams(rule, id, now, now));
invalidate();
return (await getReasoningRoutingRuleById(id))!;
return mutate(() => repository.create(rule));
}
export async function updateReasoningRoutingRule(
id: string,
patch: Partial<ReasoningRoutingRuleInput>
): Promise<ReasoningRoutingRule | null> {
const existing = await getReasoningRoutingRuleById(id);
if (!existing) return null;
const { id: _id, createdAt, updatedAt: _updatedAt, ...base } = existing;
const next = { ...base, ...patch } as ReasoningRoutingRuleInput;
assertReferences(next);
const now = new Date().toISOString();
getDbInstance()
.prepare(
`UPDATE reasoning_routing_rules SET
name=@name, description=@description, scope=@scope, api_key_id=@apiKeyId,
combo_id=@comboId, connection_id=@connectionId, model_pattern=@modelPattern,
source_effort=@sourceEffort, request_tags=@requestTags, tag_match_mode=@tagMatchMode,
effort_mode=@effortMode, target_effort=@targetEffort, target_kind=@targetKind,
target_model=@targetModel, target_combo_id=@targetComboId, budget_action=@budgetAction,
budget_tokens=@budgetTokens, priority=@priority, enabled=@enabled, updated_at=@updatedAt
WHERE id=@id`
)
.run(ruleParams(next, id, createdAt, now));
invalidate();
return getReasoningRoutingRuleById(id);
return mutate(() => repository.update(id, patch));
}
export async function deleteReasoningRoutingRule(id: string): Promise<boolean> {
const result = getDbInstance()
.prepare("DELETE FROM reasoning_routing_rules WHERE id = ?")
.run(id);
if ((result.changes ?? 0) > 0) invalidate();
return (result.changes ?? 0) > 0;
return mutate(() => repository.deleteById(id));
}
export function invalidateReasoningRoutingRuleCache(): void {

View File

@@ -0,0 +1,208 @@
import { randomUUID } from "node:crypto";
import type {
ReasoningBudgetAction,
ReasoningEffort,
ReasoningEffortMode,
ReasoningRoutingRule,
ReasoningRoutingRuleInput,
ReasoningRoutingRuleRepository,
ReasoningRuleScope,
ReasoningSourceEffort,
ReasoningTargetKind,
} from "@/domain/persistence/reasoningRoutingRuleRepository";
import { getDbInstance } from "../core";
type RuleRow = Record<string, unknown>;
function parseTags(value: unknown): string[] {
try {
const parsed = typeof value === "string" ? JSON.parse(value) : value;
return Array.isArray(parsed)
? [
...new Set(
parsed
.filter((tag): tag is string => typeof tag === "string")
.map((tag) => tag.trim().toLowerCase())
.filter(Boolean)
),
]
: [];
} catch {
return [];
}
}
function rowToRule(row: RuleRow): ReasoningRoutingRule {
return {
id: String(row.id),
name: String(row.name),
description: typeof row.description === "string" ? row.description : "",
scope: row.scope as ReasoningRuleScope,
apiKeyId: typeof row.api_key_id === "string" ? row.api_key_id : null,
comboId: typeof row.combo_id === "string" ? row.combo_id : null,
connectionId: typeof row.connection_id === "string" ? row.connection_id : null,
modelPattern: typeof row.model_pattern === "string" ? row.model_pattern : null,
sourceEffort: row.source_effort as ReasoningSourceEffort,
requestTags: parseTags(row.request_tags),
tagMatchMode: row.tag_match_mode === "all" ? "all" : "any",
effortMode: row.effort_mode as ReasoningEffortMode,
targetEffort:
typeof row.target_effort === "string" ? (row.target_effort as ReasoningEffort) : null,
targetKind: row.target_kind as ReasoningTargetKind,
targetModel: typeof row.target_model === "string" ? row.target_model : null,
targetComboId: typeof row.target_combo_id === "string" ? row.target_combo_id : null,
budgetAction: row.budget_action as ReasoningBudgetAction,
budgetTokens: typeof row.budget_tokens === "number" ? row.budget_tokens : null,
priority: typeof row.priority === "number" ? row.priority : 0,
enabled: row.enabled === 1 || row.enabled === true,
createdAt: String(row.created_at),
updatedAt: String(row.updated_at),
};
}
function referenceExists(table: string, id: string | null): boolean {
if (!id) return false;
const allowedTables = new Set(["api_keys", "combos", "provider_connections"]);
if (!allowedTables.has(table)) return false;
return Boolean(getDbInstance().prepare(`SELECT 1 FROM ${table} WHERE id = ?`).get(id));
}
/** SQLite-only synchronous validation retained for the existing public API. */
export function getSqliteReasoningRoutingRuleReferenceErrors(
rule: ReasoningRoutingRuleInput
): string[] {
const errors: string[] = [];
if (rule.scope === "apiKey" && !referenceExists("api_keys", rule.apiKeyId)) {
errors.push("The referenced API key does not exist");
}
if (rule.scope === "combo" && !referenceExists("combos", rule.comboId)) {
errors.push("The referenced source combo does not exist");
}
if (rule.scope === "connection" && !referenceExists("provider_connections", rule.connectionId)) {
errors.push("The referenced provider connection does not exist");
}
if (rule.targetKind === "combo" && !referenceExists("combos", rule.targetComboId)) {
errors.push("The referenced target combo does not exist");
}
return errors;
}
function assertReferences(rule: ReasoningRoutingRuleInput): void {
const errors = getSqliteReasoningRoutingRuleReferenceErrors(rule);
if (errors.length > 0) throw new Error(errors.join("; "));
}
async function list(options: { enabledOnly?: boolean } = {}): Promise<ReasoningRoutingRule[]> {
const rows = getDbInstance()
.prepare("SELECT * FROM reasoning_routing_rules ORDER BY priority DESC, created_at ASC, id ASC")
.all() as RuleRow[];
const rules = rows.map(rowToRule);
return options.enabledOnly ? rules.filter((rule) => rule.enabled) : rules;
}
function findRuleSync(id: string): ReasoningRoutingRule | null {
const row = getDbInstance()
.prepare("SELECT * FROM reasoning_routing_rules WHERE id = ?")
.get(id) as RuleRow | undefined;
return row ? rowToRule(row) : null;
}
async function findById(id: string): Promise<ReasoningRoutingRule | null> {
return findRuleSync(id);
}
function ruleParams(
rule: ReasoningRoutingRuleInput,
id: string,
createdAt: string,
updatedAt: string
) {
return {
id,
name: rule.name,
description: rule.description || "",
scope: rule.scope,
apiKeyId: rule.apiKeyId ?? null,
comboId: rule.comboId ?? null,
connectionId: rule.connectionId ?? null,
modelPattern: rule.modelPattern ?? null,
sourceEffort: rule.sourceEffort,
requestTags: JSON.stringify(parseTags(rule.requestTags)),
tagMatchMode: rule.tagMatchMode,
effortMode: rule.effortMode,
targetEffort: rule.effortMode === "inherit" ? null : rule.targetEffort,
targetKind: rule.targetKind,
targetModel: rule.targetKind === "model" ? rule.targetModel : null,
targetComboId: rule.targetKind === "combo" ? rule.targetComboId : null,
budgetAction: rule.targetEffort === "none" ? "remove" : rule.budgetAction,
budgetTokens: rule.budgetAction === "set" ? rule.budgetTokens : null,
priority: rule.priority,
enabled: rule.enabled ? 1 : 0,
createdAt,
updatedAt,
};
}
async function create(rule: ReasoningRoutingRuleInput): Promise<ReasoningRoutingRule> {
assertReferences(rule);
const id = randomUUID();
const now = new Date().toISOString();
getDbInstance()
.prepare(
`INSERT INTO reasoning_routing_rules (
id, name, description, scope, api_key_id, combo_id, connection_id, model_pattern,
source_effort, request_tags, tag_match_mode, effort_mode, target_effort, target_kind,
target_model, target_combo_id, budget_action, budget_tokens, priority, enabled, created_at, updated_at
) VALUES (
@id, @name, @description, @scope, @apiKeyId, @comboId, @connectionId, @modelPattern,
@sourceEffort, @requestTags, @tagMatchMode, @effortMode, @targetEffort, @targetKind,
@targetModel, @targetComboId, @budgetAction, @budgetTokens, @priority, @enabled, @createdAt, @updatedAt
)`
)
.run(ruleParams(rule, id, now, now));
return (await findById(id))!;
}
async function update(
id: string,
patch: Partial<ReasoningRoutingRuleInput>
): Promise<ReasoningRoutingRule | null> {
// Read, merge and write in one tick: an await here would let an overlapping update read the
// same base row and overwrite this patch with stale fields.
const existing = findRuleSync(id);
if (!existing) return null;
const { id: _id, createdAt, updatedAt: _updatedAt, ...base } = existing;
const next = { ...base, ...patch } as ReasoningRoutingRuleInput;
assertReferences(next);
const now = new Date().toISOString();
getDbInstance()
.prepare(
`UPDATE reasoning_routing_rules SET
name=@name, description=@description, scope=@scope, api_key_id=@apiKeyId,
combo_id=@comboId, connection_id=@connectionId, model_pattern=@modelPattern,
source_effort=@sourceEffort, request_tags=@requestTags, tag_match_mode=@tagMatchMode,
effort_mode=@effortMode, target_effort=@targetEffort, target_kind=@targetKind,
target_model=@targetModel, target_combo_id=@targetComboId, budget_action=@budgetAction,
budget_tokens=@budgetTokens, priority=@priority, enabled=@enabled, updated_at=@updatedAt
WHERE id=@id`
)
.run(ruleParams(next, id, createdAt, now));
return findRuleSync(id);
}
async function deleteById(id: string): Promise<boolean> {
const result = getDbInstance()
.prepare("DELETE FROM reasoning_routing_rules WHERE id = ?")
.run(id);
return (result.changes ?? 0) > 0;
}
// No captured handle/statements: reset/restore reopens the same configured DATA_DIR
// through core on the next operation, including on this retained repository object.
export const sqliteReasoningRoutingRuleRepository: ReasoningRoutingRuleRepository = {
list,
findById,
create,
update,
deleteById,
};

View File

@@ -0,0 +1,79 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
/**
* System directories that must never become the root of a host-filesystem surface (the local
* corpus indexed for the MCP search tools, the read/write Obsidian WebDAV vault). The directory
* itself and everything below it are refused, unless the canonical path lives inside the user's
* home directory (a service account whose home is `/root` or `/var/lib/<app>` keeps its folders).
* POSIX only: on Windows the drive root and the home directory itself are refused.
*/
const POSIX_SYSTEM_DIRECTORIES = [
"/etc",
"/usr",
"/bin",
"/sbin",
"/var",
"/proc",
"/sys",
"/dev",
"/boot",
"/root",
] as const;
/** Fixed refusal message: it never echoes the requested path back to the caller. */
export const DENIED_ROOT_DIRECTORY_ERROR =
"This directory cannot be used as a root: choose a dedicated folder, not the filesystem root, the home directory itself or a system directory";
/** Canonical (symlink-resolved) absolute form of a path; falls back to the lexical resolve. */
function canonicalPath(target: string): string {
const resolved = path.resolve(target);
try {
return fs.realpathSync.native(resolved);
} catch {
return resolved;
}
}
/** True when `child` is `parent` itself or lives anywhere below it. */
function isSameOrInside(parent: string, child: string): boolean {
const rel = path.relative(parent, child);
if (rel === "") return true;
if (path.isAbsolute(rel)) return false; // different drive (win32)
return rel !== ".." && !rel.startsWith(`..${path.sep}`);
}
function isFilesystemRoot(target: string): boolean {
return path.parse(target).root === target;
}
/**
* Is `candidate` a directory that must not be exposed as a corpus or vault root? Both the lexical
* (`path.resolve`) and canonical (`realpath`) forms are checked, so a symlink cannot dodge the
* comparison in either direction. Refused: the filesystem root (`/`, a drive root on Windows), the
* user's home directory itself (its subfolders stay allowed) and the POSIX system directories
* above.
*/
export function isDeniedRootDirectory(candidate: string): boolean {
const lexical = path.resolve(candidate);
const canonical = canonicalPath(candidate);
const forms = lexical === canonical ? [canonical] : [lexical, canonical];
if (forms.some(isFilesystemRoot)) return true;
const homeForms = [path.resolve(os.homedir()), canonicalPath(os.homedir())];
if (forms.some((form) => homeForms.includes(form))) return true;
if (process.platform === "win32") return false;
const canonicalHome = homeForms[1];
if (isFilesystemRoot(canonicalHome) === false && isSameOrInside(canonicalHome, canonical)) {
return false;
}
return POSIX_SYSTEM_DIRECTORIES.some((dir) => {
const dirForms = [dir, canonicalPath(dir)];
return dirForms.some((dirForm) => forms.some((form) => isSameOrInside(dirForm, form)));
});
}

View File

@@ -7,6 +7,7 @@ import { fetchRemoteImage } from "@/shared/network/remoteImageFetch";
import { getGuardedDispatcher } from "@omniroute/open-sse/utils/connectGuardDispatcher";
import { getRuntimePorts } from "@/lib/runtime/ports";
import { resolveSelfLoopBearer } from "@/shared/middleware/chatBodyAdmission";
import { ownListenerSelfHopToken, SELF_HOP_HEADER } from "@omniroute/open-sse/utils/selfHop";
import { getBestVisionModel, getFallbackModels, recordLatency } from "./visionBridgeRouter";
import { combineCredentialChecks } from "./visionBridgeKeyScope";
import { REGISTRY } from "@omniroute/open-sse/config/providers";
@@ -818,10 +819,10 @@ async function callVisionModelSingle(
// When routing through OmniRoute's own API, omit the vision-bridge
// guardrail on the sub-request to prevent infinite recursion.
// OmniRoute's own listener authenticates the self-loop bearer (the env key or the
// per-process secret, both accepted by API-key validation), which the admission
// bypass below also requires. Any other endpoint — api.openai.com, or another
// localhost server set as VISION_BRIDGE_BASE_URL — gets only the provider key and
// never an OmniRoute credential; with no provider key the header is omitted.
// per-process secret, both accepted by API-key validation). Any other endpoint —
// api.openai.com, or another localhost server set as VISION_BRIDGE_BASE_URL — gets
// only the provider key and never an OmniRoute credential; with no provider key the
// header is omitted.
// A bare-id call to our own listener keeps an operator VISION_BRIDGE_API_KEY.
const selfLoopBearer =
isOwnOmniRouteBaseUrl(baseUrl) && (useFullModelId || !resolvedApiKey)
@@ -851,10 +852,13 @@ async function callVisionModelSingle(
// Internal self-loop sub-request: the parent request already holds the
// single heavyweight admission lease (`CHAT_MAX_HEAVY_IN_FLIGHT=1`), so a
// large base64-image describe body would be rejected with 503
// `chat_admission_busy` before it is described. The route only honors
// this header when the bearer is the self-loop bearer (set above), so
// external clients cannot use it to bypass admission.
// `chat_admission_busy` before it is described. The route grants the bypass
// only on the per-process token, never on this header or the bearer (the env
// key is a key clients can hold). Production injects undici fetch, which
// skips proxyFetch's own-listener stamp, so the token is set here; this branch
// only runs for our own listener, so the token never leaves the process.
headers["x-omniroute-admission-bypass"] = "internal";
headers[SELF_HOP_HEADER] = ownListenerSelfHopToken();
// Scope the sub-request to the caller's key: the receiving chat request
// applies that key's connection/model policy (honored only alongside the
// self-loop bearer, so it can only narrow access).

View File

@@ -120,9 +120,11 @@ interface ParsedImageEditInput {
}
export const MAX_CODEX_IMAGE_EDIT_BYTES = 20 * 1024 * 1024;
export const MAX_CODEX_IMAGE_EDIT_REFERENCES = 8;
// GPT Image models use the dedicated Images edits API and allow up to 16 inputs;
// keep the legacy hosted Responses tool bound at eight until independently verified.
// A bounded input guard, NOT the backend's absolute maximum. On 2026-11-10,
// the hosted Codex Responses image_generation edit returned real PNGs with
// 9, 17, 24, 32, 64 and 128 ordered PNG references in isolated OAuth smokes.
export const MAX_CODEX_IMAGE_EDIT_REFERENCES = 128;
// Dedicated GPT Image edits use the separate Images API, documented at 16 inputs.
export const MAX_CODEX_GPT_IMAGE_EDIT_REFERENCES = 16;
export const MAX_CODEX_IMAGE_EDIT_TOTAL_BYTES = 20 * 1024 * 1024;
@@ -219,7 +221,7 @@ function isRemoteImageUrl(value: unknown): value is string {
export type RemoteImageEditFetchOptions = Pick<
RemoteImageFetchOptions,
"fetchImpl" | "lookup" | "signal" | "timeoutMs"
>;
> & { maxReferences?: number };
/**
* Download one caller-supplied http(s) reference as a data URL, or null when it cannot be
@@ -227,22 +229,87 @@ export type RemoteImageEditFetchOptions = Pick<
*/
async function fetchRemoteImageEditReference(
url: string,
options: RemoteImageEditFetchOptions
): Promise<string | null> {
options: RemoteImageEditFetchOptions,
maxBytes = MAX_CODEX_IMAGE_EDIT_BYTES
): Promise<{ dataUrl: string; bytes: number } | null> {
try {
const { buffer } = await fetchUntrustedRemoteImage(url.trim(), {
...options,
maxBytes: MAX_CODEX_IMAGE_EDIT_BYTES,
maxBytes,
});
const mime = Object.entries(REMOTE_IMAGE_EDIT_MIME_MAGIC).find(([, matches]) =>
matches(buffer)
)?.[0];
return mime ? `data:${mime};base64,${buffer.toString("base64")}` : null;
return mime
? { dataUrl: "data:" + mime + ";base64," + buffer.toString("base64"), bytes: buffer.length }
: null;
} catch {
return null;
}
}
/** Extract image candidates without changing the JSON edit input's original shape. */
function inlineImageEditValues(
body: Record<string, unknown>,
imageList: unknown[] | null,
imagesList: unknown[] | null
): unknown[] {
const direct = imageList ?? (body.image !== undefined ? [body.image] : []);
const nested = (imagesList ?? []).map((entry) => {
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return entry;
const object = entry as Record<string, unknown>;
return object.image_url ?? object.url ?? object.b64_json;
});
return [...direct, ...nested];
}
function remainingInlineImageEditBytes(values: readonly unknown[]): number {
let remaining = MAX_CODEX_IMAGE_EDIT_TOTAL_BYTES;
for (const value of values) {
const inline = parseDataUrl(value);
if (inline) remaining -= inline.bytes.length;
}
return remaining;
}
/** The captured budget is shared across sequential fetches of both input arrays. */
function createRemoteImageEditResolver(
options: RemoteImageEditFetchOptions,
initialRemainingBytes: number
): (value: unknown) => Promise<unknown> {
let remainingBytes = initialRemainingBytes;
return async (value) => {
if (!isRemoteImageUrl(value) || remainingBytes <= 0) return value;
const fetched = await fetchRemoteImageEditReference(
value,
options,
Math.min(MAX_CODEX_IMAGE_EDIT_BYTES, remainingBytes)
);
if (!fetched) return value;
remainingBytes -= fetched.bytes;
return fetched.dataUrl;
};
}
async function resolveRemoteImageEditEntry(
entry: unknown,
resolve: (value: unknown) => Promise<unknown>
): Promise<unknown> {
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return resolve(entry);
const e = entry as Record<string, unknown>;
const key = e.image_url != null ? "image_url" : e.url != null ? "url" : null;
return key ? { ...e, [key]: await resolve(e[key]) } : entry;
}
async function resolveImageEditValuesInOrder(
values: readonly unknown[],
resolve: (value: unknown) => Promise<unknown>
): Promise<unknown[]> {
const next: unknown[] = [];
for (const value of values) next.push(await resolve(value));
return next;
}
/**
* Replace public http(s) references in a JSON edit body (`image: "https://..."`,
* `image: ["https://..."]`, `images: [{ image_url | url: "https://..." }]`,
@@ -259,25 +326,29 @@ export async function resolveRemoteImageEditReferences(
const imagesList = Array.isArray(body.images) ? body.images : null;
const referenceCount =
(imageList?.length ?? (body.image !== undefined ? 1 : 0)) + (imagesList?.length ?? 0);
// Over-limit sets are rejected by the route anyway; do not fetch anything for them.
if (referenceCount > MAX_CODEX_GPT_IMAGE_EDIT_REFERENCES) return body;
// Default to the dedicated GPT Image limit. The reader opts in to the
// larger bound only for a registered hosted Codex model.
const maxReferences = Math.min(
options.maxReferences ?? MAX_CODEX_GPT_IMAGE_EDIT_REFERENCES,
MAX_CODEX_IMAGE_EDIT_REFERENCES
);
if (referenceCount > maxReferences) return body;
const resolve = async (value: unknown): Promise<unknown> =>
isRemoteImageUrl(value)
? ((await fetchRemoteImageEditReference(value, options)) ?? value)
: value;
const resolveEntry = async (entry: unknown): Promise<unknown> => {
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return resolve(entry);
const e = entry as Record<string, unknown>;
// Same precedence as `extractImageEditInputFromJson` (`image_url ?? url`).
const key = e.image_url != null ? "image_url" : e.url != null ? "url" : null;
return key ? { ...e, [key]: await resolve(e[key]) } : entry;
};
// Count existing inline bytes before any network I/O, then fetch serially
// under a single 20 MiB aggregate budget.
const remainingBytes = remainingInlineImageEditBytes(
inlineImageEditValues(body, imageList, imagesList)
);
if (remainingBytes < 0) return body;
const resolve = createRemoteImageEditResolver(options, remainingBytes);
const next: Record<string, unknown> = { ...body };
if (imageList) next.image = await Promise.all(imageList.map(resolve));
if (imageList) next.image = await resolveImageEditValuesInOrder(imageList, resolve);
else if (body.image !== undefined) next.image = await resolve(body.image);
if (imagesList) next.images = await Promise.all(imagesList.map(resolveEntry));
if (imagesList)
next.images = await resolveImageEditValuesInOrder(imagesList, (entry) =>
resolveRemoteImageEditEntry(entry, resolve)
);
return next;
}

View File

@@ -6,8 +6,9 @@
export const LITELLM_PROVIDER_MAP: Record<string, string[]> = {
openai: ["openai", "cx"],
anthropic: ["anthropic", "cc"],
vertex_ai: ["gemini"],
"vertex_ai-anthropic_models": ["anthropic"],
vertex_ai: ["gemini", "vertex"],
"vertex_ai-anthropic_models": ["anthropic", "vertex"],
"vertex_ai-anthropic-models": ["anthropic", "vertex"],
google: ["gemini"],
// Registry ALIAS, not registry id — pricingSync writes/reads are keyed by
// alias everywhere else (see getPricingForModel(provider, model) callers).
@@ -29,8 +30,16 @@ export const LITELLM_PROVIDER_MAP: Record<string, string[]> = {
cerebras: ["cerebras"],
nvidia_nim: ["nvidia"],
siliconflow: ["siliconflow"],
"vertex_ai-language_models": ["gemini"],
"vertex_ai-mistral_models": ["mistral"],
"vertex_ai-language_models": ["gemini", "vertex"],
"vertex_ai-language-models": ["gemini", "vertex"],
"vertex_ai-mistral_models": ["mistral", "vertex"],
"vertex_ai-mistral-models": ["mistral", "vertex"],
"vertex_ai-deepseek_models": ["vertex"],
"vertex_ai-deepseek-models": ["vertex"],
"vertex_ai-qwen_models": ["vertex"],
"vertex_ai-qwen-models": ["vertex"],
"vertex_ai-zai_models": ["vertex"],
"vertex_ai-zai-models": ["vertex"],
gemini: ["gemini"],
bedrock_converse: ["kr"],
cloudflare: ["cf"],

View File

@@ -2,6 +2,8 @@ import { createHash } from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
import { DENIED_ROOT_DIRECTORY_ERROR, isDeniedRootDirectory } from "../deniedRootDirectories";
const DEFAULT_ALLOWED_EXTENSIONS = new Set([
".cfg",
".csv",
@@ -278,6 +280,9 @@ export async function canonicalizeLocalCorpusRoot(inputPath: string): Promise<st
} catch {
throw new Error("Local corpus root is not accessible");
}
if (isDeniedRootDirectory(canonical)) {
throw new Error(DENIED_ROOT_DIRECTORY_ERROR);
}
if (!stat.isDirectory()) {
throw new Error("Local corpus root must point to a directory");
}

View File

@@ -1,6 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import { resolveDataDir } from "./dataPaths";
import { DENIED_ROOT_DIRECTORY_ERROR, isDeniedRootDirectory } from "./deniedRootDirectories";
import {
getObsidianVaultPath,
setObsidianVaultPath,
@@ -75,6 +76,12 @@ export async function enableObsidianVaultSync(
): Promise<ObsidianSyncEnableResult> {
const resolvedPath = path.resolve(vaultPath);
// The vault root is served read/write by the WebDAV file service: the filesystem root, the
// home directory itself and system directories are never a vault (CodeQL #1372/#1373).
if (isDeniedRootDirectory(resolvedPath)) {
return { success: false, error: DENIED_ROOT_DIRECTORY_ERROR };
}
if (!fs.existsSync(resolvedPath)) {
return { success: false, error: `Vault directory not found: ${resolvedPath}` };
}

View File

@@ -16,6 +16,7 @@ export type CodexGlobalServiceMode = "none" | CodexServiceTier;
export const CODEX_FAST_TIER_DEFAULT_SUPPORTED_MODELS: readonly string[] = [
"gpt-6.1-sol",
"gpt-6.1-terra",
"gpt-6-astra",
"gpt-6-sol",
"gpt-6-luna",

View File

@@ -615,10 +615,16 @@ export async function checkConnection(conn: any) {
return;
}
if (!conn.isActive) {
// #P0: allow expired connections with retry budget remaining to pass
// through so transient OAuth failures can self-heal instead of being
// permanently skipped. Exhausted retries stay terminal.
if (!(conn.testStatus === "expired" && getExpiredRetryCount(conn) < EXPIRED_RETRY_MAX)) {
// Inactive connections (e.g. disabled due to quota exhaustion, operator pause,
// or rate limit cooldown) must still keep their OAuth credentials refreshed as long as they
// have a usable refresh token and are not permanently banned. Otherwise, resting accounts
// lose their OAuth session and fail with `invalid_grant` (Refresh token consumed) when reactivated.
const isMaintainableOAuth =
conn.authType === "oauth" && Boolean(conn.refreshToken) && conn.testStatus !== "banned";
const isRetryableExpired =
conn.testStatus === "expired" && getExpiredRetryCount(conn) < EXPIRED_RETRY_MAX;
if (!isMaintainableOAuth && !isRetryableExpired) {
return;
}
}

View File

@@ -173,6 +173,10 @@ export async function resolvePricingRow(provider: string, model: string) {
return null;
}
function getGpt6FastMultiplier(modelKey: string, compactModelKey: string): number {
return modelKey === "gpt-6.1-terra" || compactModelKey === "gpt61terra" ? 2 : 2.5;
}
export function getCodexFastCostMultiplier(
provider: string | null | undefined,
model: string | null | undefined,
@@ -194,12 +198,13 @@ export function getCodexFastCostMultiplier(
splitCodexReasoningSuffix(normalizeModelName(String(model || "")).toLowerCase()).baseModel
);
const compactModelKey = modelKey.replace(/-/g, "");
// Codex GPT-6 Fast is 2.5x Standard (https://developers.openai.com/codex/pricing).
// GPT-6 family members share one Fast tier, with the Terra exception.
// https://learn.chatgpt.com/docs/pricing#token-rates
if (
/^gpt-6(?:\.1)?-(?:astra|sol|luna)$/.test(modelKey) ||
/^gpt6(?:\.1)?(?:astra|sol|luna)$/.test(compactModelKey)
/^gpt-6(?:\.1)?-(?:astra|sol|terra|luna)$/.test(modelKey) ||
/^gpt6(?:\.1)?(?:astra|sol|terra|luna)$/.test(compactModelKey)
) {
return 2.5;
return getGpt6FastMultiplier(modelKey, compactModelKey);
}
if (
/^gpt-5\.6-(?:sol|terra|luna)$/.test(modelKey) ||

View File

@@ -11,6 +11,7 @@ export const OMNIROUTE_RESPONSE_HEADERS = {
fallbackAttempts: "X-OmniRoute-Fallback-Attempts",
accountFallbacks: "X-OmniRoute-Account-Fallbacks",
accountFallbackReasons: "X-OmniRoute-Account-Fallback-Reasons",
selectedConnectionPlan: "X-OmniRoute-Selected-Connection-Plan",
sameAccountRetries: "X-OmniRoute-Same-Account-Retries",
routingWaitMs: "X-OmniRoute-Routing-Wait-Ms",
latencyMs: "X-OmniRoute-Latency-Ms",

View File

@@ -172,6 +172,10 @@ export const MODEL_SPECS: Record<string, ModelSpec> = {
...GPT_5_6_MODEL_SPEC,
aliases: ["openai/gpt-6.1-sol"],
},
"gpt-6.1-terra": {
...GPT_5_6_MODEL_SPEC,
aliases: ["openai/gpt-6.1-terra"],
},
// Public model limits; the Codex registry supplies its smaller OAuth window.
// https://developers.openai.com/api/docs/models/gpt-6-astra
"gpt-6-astra": {

View File

@@ -5,6 +5,7 @@
import {
GPT_6_ASTRA_PRICING,
GPT_6_SOL_PRICING,
GPT_6_TERRA_PRICING,
GEMINI_3_7_FLASH_PROMO_PRICING,
GEMINI_4_ARGON_PROMO_PRICING,
GEMINI_4_HYDROGEN_PRICING,
@@ -48,6 +49,7 @@ export const DEFAULT_PRICING_FRONTIER = {
cache_creation: 0.125,
}),
"gpt-6.1-sol": withOpenAiLongContextTier(GPT_6_SOL_PRICING),
"gpt-6.1-terra": withOpenAiLongContextTier(GPT_6_TERRA_PRICING),
"gpt-5.6": withOpenAiLongContextTier(GPT_5_6_SOL_PRICING),
"gpt-5.6-sol": withOpenAiLongContextTier(GPT_5_6_SOL_PRICING),
"gpt-5.6-terra": withOpenAiLongContextTier(GPT_5_6_TERRA_PRICING),
@@ -320,6 +322,71 @@ export const DEFAULT_PRICING_FRONTIER = {
cache_creation: 0.1,
},
},
vertex: {
"gemini-4-argon": GEMINI_4_ARGON_PROMO_PRICING,
"gemini-3.7-flash": GEMINI_3_7_FLASH_PROMO_PRICING,
"gemini-3.1-pro": {
input: 2.0,
output: 12.0,
cached: 0.25,
reasoning: 18.0,
cache_creation: 2.0,
},
"gemini-3-1-pro": {
input: 2.0,
output: 12.0,
cached: 0.25,
reasoning: 18.0,
cache_creation: 2.0,
},
// Gemini 3 Flash is a Flash-tier model: $0.50 in / $3 out (thinking billed as output) /
// $0.05 cached (https://cloud.google.com/vertex-ai/generative-ai/pricing).
"gemini-3-flash-preview": {
input: 0.5,
output: 3.0,
cached: 0.05,
reasoning: 3.0,
cache_creation: 0.5,
},
"gemini-3.1-pro-preview": {
input: 2.0,
output: 12.0,
cached: 0.25,
reasoning: 18.0,
cache_creation: 2.0,
},
// Gemini 2.5 Pro: $1.25 in / $10 out / $0.125 cached for prompts up to 200K tokens;
// prompts over 200K are billed $2.50 / $15 / $0.25 for the whole request.
"gemini-2.5-pro": {
input: 1.25,
output: 10.0,
cached: 0.125,
reasoning: 10.0,
cache_creation: 1.25,
long_context: {
threshold: 200_000,
input: 2.5,
output: 15.0,
cached: 0.25,
reasoning: 15.0,
cache_creation: 2.5,
},
},
"gemini-2.5-flash": {
input: 0.3,
output: 2.5,
cached: 0.03,
reasoning: 3.75,
cache_creation: 0.3,
},
"gemini-2.5-flash-lite": {
input: 0.1,
output: 0.4,
cached: 0.01,
reasoning: 0.6,
cache_creation: 0.1,
},
},
deepseek: {
"deepseek-chat": {
input: 0.28,

View File

@@ -4,6 +4,7 @@
*/
import {
GPT_6_ASTRA_PRICING,
GPT_6_TERRA_PRICING,
CLAUDE_FABLE_5_1_PRICING,
CLAUDE_HAIKU_5_PRICING,
CLAUDE_OPUS_5_5_PRICING,
@@ -123,16 +124,10 @@ const GPT_6_1_SOL_CODEX_PRICING = {
...GPT_6_SOL_CODEX_PRICING,
cached: 0.1,
};
// GPT-6.1 Terra Standard: 25 / 1.25 / 125 credits per MTok (input / cached / output), the same
// 25 credits/USD convention. Matches the API pricing table row $1.00 / $0.05 / $5.00, cache write $1.25.
// GPT-6.1 Terra shares its API price with the Codex credit-equivalent rate:
// 25 / 1.25 / 125 credits per MTok at 25 credits/USD.
// https://learn.chatgpt.com/docs/pricing#token-rates (checked 2026-11-09)
const GPT_6_1_TERRA_CODEX_PRICING = {
input: 1.0,
output: 5.0,
cached: 0.05,
reasoning: 5.0,
cache_creation: 1.25,
};
const GPT_6_1_TERRA_CODEX_PRICING = GPT_6_TERRA_PRICING;
const GPT_6_LUNA_CODEX_PRICING = {
input: 0.1,
output: 0.5,

View File

@@ -19,6 +19,14 @@ export const GPT_6_SOL_PRICING = {
cache_creation: 2.5,
};
export const GPT_6_TERRA_PRICING = {
input: 1.0,
output: 5.0,
cached: 0.05,
reasoning: 5.0,
cache_creation: 1.25,
};
export const GPT_5_3_CODEX_PRICING = {
input: 5.0,
output: 20.0,

View File

@@ -481,15 +481,31 @@ export const AUTH_METHODS = {
apikey: { id: "apikey", name: "API Key", icon: "key" },
};
export function getProviderByAlias(alias: string): AiProviderDefinition | null {
let _PROVIDER_BY_KEY: Map<string, AiProviderDefinition> | null = null;
// One index over every alias and id. The first provider in section order wins a shared
// key, the same rule the old linear scan applied.
function buildProviderByKey(): Map<string, AiProviderDefinition> {
const index = new Map<string, AiProviderDefinition>();
for (const section of _PROVIDER_SECTIONS) {
for (const provider of Object.values(section)) {
if (provider.alias === alias || provider.id === alias) {
return provider as AiProviderDefinition;
for (const provider of Object.values(section) as Array<
AiProviderDefinition & { alias?: string }
>) {
for (const key of [provider.alias, provider.id]) {
if (key && !index.has(key)) index.set(key, provider);
}
}
}
return null;
return index;
}
function getOrCreateProviderByKey(): Map<string, AiProviderDefinition> {
_PROVIDER_BY_KEY ??= buildProviderByKey();
return _PROVIDER_BY_KEY;
}
export function getProviderByAlias(alias: string): AiProviderDefinition | null {
return getOrCreateProviderByKey().get(alias) ?? null;
}
// Helper: Get provider ID from alias

Some files were not shown because too many files have changed in this diff Show More