Skip to content

feat(gateway): port the Gateway residue and record the port on the progress map - #15237

Merged
marius-kilocode merged 4 commits into
v2from
gateway-finish
Oct 19, 2026
Merged

marius-kilocode merged 4 commits into
v2from
gateway-finish

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

The gateway box on the v2 progress map showed 12/87 while most of the Kilo Gateway behavior is on v2. Most v1 modules were ported under other file names, which the map cannot match by name, and no v1 patch cell carried a done-proof. A small part of the behavior was also missing: the embedding model catalog, the Mercury Next Edit prompt, and the v1 rule that Kilo errors which need user action are not retried.

Why This Change Was Made

Each cell was checked against the v1 hunk at fb7e96eda540 and the v2 code before it got a proof or a disposition. A cell is closed only when v2 has the behavior. Cells with a real gap stay open, with the reason below.

Code (Kilo-owned paths only):

  • KiloModels.embeddingModels in kilo-gateway-core/src/models.ts and the models.embeddings method of the kilocode.gateway RPC. The route is public, so no token is sent. It refuses redirects and retries network errors and transient statuses up to 3 attempts, as v1 fetchKiloEmbeddingModelCatalog did.
  • buildMercuryEditPrompt and its blocks in kilo-gateway-core/src/autocomplete.ts, ported from v1 edit-prompt.ts. The v2 package had extractFencedBody but not the prompt builder.
  • KiloErrors.rewriteHttpResponse sets x-should-retry: false when parse marks the error as not retryable. The upstream retry policy (isRetryable in packages/ai/src/provider-error.ts) reads this header. Before this change, a 429 PROMOTION_MODEL_LIMIT_REACHED was classified as a rate limit and retried; v1 did not retry it (kilo-errors.test.ts).

Tests ported into kilo-gateway-core/test/: autocomplete.test.ts, edit-prompt.test.ts, edit.test.ts, fim.test.ts, mistral-fim-endpoint.test.ts, headers.test.ts (from kilo-gateway-headers.test.ts), plus the v1 URL, Kilo Pass, tRPC and request body assertions that the existing v2 tests did not have.

User Impact

  • A Kilo error that needs sign-up or credits now stops at once with its message, also when the Gateway sends HTTP 429. Before, the session retried it with backoff.
  • Clients can read the embedding model catalog through the RPC (the indexing feature uses it later).
  • No change to the TUI or to model requests otherwise.

Placement

Change Rung Why not lower Proof
Embedding catalog 1 n/a kilo-gateway-core/src/models.ts, core/src/kilocode/gateway.ts RPC handler
Mercury Next Edit prompt 1 n/a kilo-gateway-core/src/autocomplete.ts
No retry for Kilo errors that need user action 1 n/a kilo-gateway-core/src/errors.ts, kilo_port(gateway:1995b11b5cdd)
v1 kilo.ts import, settings and headers, Kilo SDK 1 n/a core/src/kilocode/gateway.ts, kilo_port(gateway:e8673ed1650b), kilo_port(gateway:73ba28ce78a5), kilo_port(gateway:742c02b40457)
v1 request.ts project, machine and parent 1 n/a core/src/kilocode/gateway.ts, kilo_port(gateway:50352226b43c)
v1 plugin registration 1 n/a kilo-plugin/src/index.ts, kilo_port(gateway:17e39e074eaf)
v1 transform.ts provider options key, variants, per-SDK options 1 n/a core/src/kilocode/gateway.ts, kilo_port(gateway:0278ba0eb6aa), kilo_port(gateway:59f57027c538), kilo_port(gateway:f983d8f993c8)
v1 tests for the Kilo SDK and server variants 1 n/a core/test/kilocode/gateway.test.ts, kilo_port(gateway:5187eb3f1516), kilo_port(gateway:d29cb22ad5f6)
  • Shared upstream files changed: none.
  • Core-internal imports added: none (the count stays 4). kilo-gateway-core still imports nothing from @opencode/*.
  • Mirrored files: none.

Progress map

gateway: 12/87 to 59/75 (12 dropped). module 9/44 to 30/35, patch 0/20 to 12/18, test 3/23 to 17/22; landed 11 plugin. Whole map: 0.1% to 0.6%.

Done, and why:

  • kilo_port (11): the v1 kilo.ts import, settings and headers, and Kilo SDK, and the v1 transform.ts provider options key, server variants and per-SDK options -> core/src/kilocode/gateway.ts (provider transform, packageFor, toModelInfo with Variant.resolve on the Gateway reasoning_options); request.ts project, machine and parent -> the model.request hook; plugin registration -> KiloPlugins; retry.ts -> x-should-retry: false in KiloErrors.rewriteHttpResponse (ported here); two v1 test cells -> the dialect and variant assertions in core/test/kilocode/gateway.test.ts.
  • ported (30): modules and tests renamed in v2, each with its v2 path in dispositions.json. Examples: api/url.ts -> server.ts, fim.ts, edit.ts and mistral-fim-endpoint.ts -> autocomplete.ts, kilo-errors.ts -> errors.ts, tui/* -> tui/src/kilocode/gateway.tsx. Two gaps were ported here: edit-prompt.ts (Mercury prompt) and embedding-models.ts (catalog and RPC). The two package.json hunks are the dependency on @kilocode/gateway-core.
  • by file name (5): the ported autocomplete, edit-prompt, edit, fim and mistral-fim-endpoint tests.
  • native (1): 00d34e8d5cd7, variants from reasoning_options through upstream Variant.resolve.

Mixed hunks: 17e39e074eaf also imports the Atomic Chat and Anaconda Desktop plugins, and 1995b11b5cdd also imports SessionNetwork. Their use is in other open cells. 50352226b43c also resolved the per-session platform attribution, which needs the session platform field (patch:unattributed:session:142910b3fc8c). v2 follows the live v1 CLI for token precedence (environment token first, acd3d1ff9b), not v1 core/src/plugin/provider/kilo.ts.

Dropped, and why it is not needed:

  • server/routes.ts, server/fim.ts, server/edit.ts: Hono routes; createKiloRoutes had no caller on v1. The live v1 routes are in opencode/src/kilocode/server/httpapi/handlers/kilo-gateway.ts (server box, which keeps FIM and Next Edit execution open). v2 serves the Gateway through the kilocode.gateway RPC.
  • types/jsx.d.ts, types/tui.d.ts: type shims for TUI code outside the TUI package; the v2 TUI code is in packages/tui.
  • auth/device-auth.ts: console login that v1 marked as not used; the live flow is ported to device.ts.
  • loader.ts, provider-debug.ts: no caller on v1.
  • auth/legacy-migration.ts: import of the pre-v1 Kilo CLI login at each start; v2 signs in with the device method and imports v1 data through U-E3-01.
  • test/provider.test.ts: tested that request headers replace Kilo defaults. v2 merges Kilo headers last on purpose, so that they replace the OpenCode referer and title of the upstream KiloPlugin. A config header can no longer override a Kilo header.
  • Two core/src/v1/config/provider.ts hunks: config fields prompt, isFree, ai_sdk_provider. v2 reads dialect and isFree from the Gateway catalog; prompt is tracked by Support backend opencode.family and prompt overrides for aliased Gateway models in v2 prompt selection (U-E1-05) #15108.

Still open:

  • session/llm.ts:269: session export capture for free Kilo models, session-export unit.
  • cloud-sessions.ts, its test, server/handlers.ts (getCloudSessions): cloud session list and import, U-E3-04.
  • event-service/client.ts: event service client for presence, U-E4-06.
  • provider-usage.ts: quota window formatter for the TUI /usage dialog and VS Code cards; v2 has only the raw usage RPC.
  • gateway-metadata.ts and its test: v2 drops the Gateway cost metadata (marketCost, generationId) that v1 attached for the session cost.
  • 5 transform.ts cells and 3 test cells: default request settings for Gateway models (GPT-5.6 cache breakpoints, Gemini 3 effort, GPT-5 effort, summary and verbosity, reasoning on small requests). They need their own unit with checks against paid models.

Corrections to the planned classification: of 15 cells planned as native, 1 is native, 6 got kilo_port because Kilo adapter code provides them (for retry.ts, retryable: false had to be wired first), and 8 stay open with gaps. Cloud sessions, server/handlers.ts and the event service client were planned as dropped but have plan units, so they stay open. edit-prompt.ts was not on v2, so it was ported. provider-usage.ts and gateway-metadata.ts have gaps, so they stay open. The second retry.ts hunk and the X-KILOCODE-* header hunk sit in unattributed:session because the map generator reads git cat-file --batch output as text with byte offsets; fixing that needs its own PR, because it moves cells in most boxes.

Evidence

  • bun test in packages/kilo-gateway-core: 72 pass, 0 fail.
  • bun test test/kilocode in packages/core (isolated home): 11 pass, 0 fail.
  • bun typecheck in packages/kilo-gateway-core, packages/core, packages/tui, packages/kilo-plugin, packages/kilo-cli: pass.
  • bun run check from the root: pass.
  • bun script/upstream/progress.ts twice with identical output, then --check: up to date.
  • bun script/upstream/placement.ts --imports: kilo-gateway-core 0 @opencode imports; 4 distinct core-internal modules (unchanged).
  • bun script/check-shared-patches.ts and bun script/check-opencode-annotations.ts: ok.
  • Live: https://ai-gateway.kilo.ai/api/v1/embedding-models returns the catalog shape that embeddingModels decodes.

Self-test (CLI through the Kilo host, fresh profile each):

  • bun dev models --standalone, signed out: lists 16 kilo/* free models. Pass.
  • bun dev run --standalone -m kilo/kilo-auto/free "Reply with only the word PONG.": answers PONG.. Pass.
  • TUI /kilo-account, signed in with KILO_API_KEY and KILO_ORG_ID: shows name, account, scope, balance and team modes; no errors in the log. Pass.

Limits: the 429 PROMOTION_MODEL_LIMIT_REACHED path cannot be triggered on demand, so it is covered by a unit test and by a test that runs the rewritten response through the upstream httpFailure and isRetryable. A Kilo error inside a stream (no HTTP status) is still classified by upstream and can be retried.

Refs #14991. Builds on #15064, #15065, #15067, #15072, #15116.

…ogress map

- Add KiloModels.embeddingModels and the models.embeddings RPC method.
- Port the Mercury Next Edit prompt builder into KiloAutocomplete.
- Set x-should-retry: false on Kilo errors that need user action, so that
  a 429 PROMOTION_MODEL_LIMIT_REACHED is not retried, as on v1.
- Port the v1 autocomplete, FIM, edit, edit prompt, Mistral FIM endpoint
  and header tests, and the missing URL, Kilo Pass, tRPC and request body
  assertions.
- Put kilo_port annotations on the code that replaces 11 v1 patch cells,
  and record 30 ported, 1 native and 12 dropped cells in dispositions.json.
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📈 v2 migration progress: 0.4% → 0.9% (+47 done, -12 total, +12 dropped; 86/9829 cells)

Placement: 0 new marked lines in shared files, 11 new kilo_port annotations, 0 new core-internal imports.

Ratchets: 8 core-internal imports (base 8); shared patches by rung 16 seam, 1 patch (base 16 seam, 1 patch).

Feature Before After Change
gateway 12/87 59/75 +21 modules done, -9 modules total; +12 patches done, -2 patches total; +14 tests done, -1 test total; +12 dropped
47 cells closed
  • module:packages/kilo-gateway/src/api/constants.ts
  • module:packages/kilo-gateway/src/api/embedding-models.ts
  • module:packages/kilo-gateway/src/api/kilo-pass.ts
  • module:packages/kilo-gateway/src/api/url.ts
  • module:packages/kilo-gateway/src/auth/device-auth-tui.ts
  • module:packages/kilo-gateway/src/auth/polling.ts
  • module:packages/kilo-gateway/src/auth/token.ts
  • module:packages/kilo-gateway/src/edit-prompt.ts
  • module:packages/kilo-gateway/src/edit.ts
  • module:packages/kilo-gateway/src/fim.ts
  • module:packages/kilo-gateway/src/mistral-fim-endpoint.ts
  • module:packages/kilo-gateway/src/plugin.ts
  • module:packages/kilo-gateway/src/provider.ts
  • module:packages/kilo-gateway/src/responses.ts
  • module:packages/kilo-gateway/src/tui.ts
  • module:packages/kilo-gateway/src/tui/context.ts
  • module:packages/kilo-gateway/src/tui/helpers.ts
  • module:packages/kilo-gateway/src/tui/types.ts
  • module:packages/kilo-gateway/src/types.ts
  • module:packages/kilo-gateway/test/api/embedding-models.test.ts
  • module:packages/kilo-gateway/test/api/kilo-pass.test.ts
  • module:packages/kilo-gateway/test/api/trpc.test.ts
  • module:packages/kilo-gateway/test/api/url.test.ts
  • module:packages/kilo-gateway/test/autocomplete.test.ts
  • module:packages/kilo-gateway/test/edit-prompt.test.ts
  • module:packages/kilo-gateway/test/edit.test.ts
  • module:packages/kilo-gateway/test/fim.test.ts
  • module:packages/kilo-gateway/test/mistral-fim-endpoint.test.ts
  • module:packages/kilo-gateway/test/responses.test.ts
  • module:packages/opencode/src/kilocode/balance-refresh.ts
  • module:packages/opencode/src/kilocode/kilo-errors.ts
  • module:packages/opencode/test/kilocode/kilo-errors.test.ts
  • module:packages/opencode/test/kilocode/kilo-gateway-headers.test.ts
  • patch:gateway:00d34e8d5cd7
  • patch:gateway:0278ba0eb6aa
  • patch:gateway:17e39e074eaf
  • patch:gateway:1995b11b5cdd
  • patch:gateway:50352226b43c
  • patch:gateway:5187eb3f1516
  • patch:gateway:59f57027c538
  • patch:gateway:6f5d1599021c
  • patch:gateway:73ba28ce78a5
  • patch:gateway:742c02b40457
  • patch:gateway:a120a4aeb745
  • patch:gateway:d29cb22ad5f6
  • patch:gateway:e8673ed1650b
  • patch:gateway:f983d8f993c8
12 cells dropped
  • module:packages/kilo-gateway/src/auth/device-auth.ts
  • module:packages/kilo-gateway/src/auth/legacy-migration.ts
  • module:packages/kilo-gateway/src/loader.ts
  • module:packages/kilo-gateway/src/provider-debug.ts
  • module:packages/kilo-gateway/src/server/edit.ts
  • module:packages/kilo-gateway/src/server/fim.ts
  • module:packages/kilo-gateway/src/server/routes.ts
  • module:packages/kilo-gateway/src/types/jsx.d.ts
  • module:packages/kilo-gateway/src/types/tui.d.ts
  • module:packages/kilo-gateway/test/provider.test.ts
  • patch:gateway:0468bd6d3d9e
  • patch:gateway:d783ce7945b8

v2 migration progress map at this commit

Full map · how cells close

Comment thread packages/kilo-gateway-core/src/errors.ts Outdated
Comment thread packages/kilo-gateway-core/src/models.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The incremental change at d7aa522 is the regenerated progress history: README.md and history.svg now record the 2026-10-19 first-parent snapshot as 39/9841 (0.4%) and the current state as 86/9829 (0.9%), which matches progress.json after the origin/v2 merge that brought in the agent cells. The generated artifacts are internally consistent: summary totals reconcile (31+0+34+21 of 3547+39+3445+2798 = 86/9829), dropped stays at 25 dispositions, the gateway box is 59/75 with 11 plugin proofs, and the ratchets are 8 core-internal imports and 16 seam + 1 patch. The files outside this final commit came from the base merge and are not changes of this PR.

Both previous findings were re-checked at this HEAD and remain fixed: errors.ts only sets x-should-retry: false when parsed.code !== "api_error", so generic 408/409 bodies keep the upstream decision, and models.ts uses retryableEmbedding, which now includes HTTP 425. The two old inline comments are outdated (line: null) rather than open findings. No memory leaks or resource-retention issues are introduced; the change is generated tracking data only.

One note, not counted as a finding: the PR body still says the whole map moves from 0.1% to 0.6%, while the regenerated map at this HEAD reads 0.9% after the base merge.

Validation commands were not executed in this read-only review; the PR body reports bun run check, typecheck, tests, and progress.ts --check passing.

Files Reviewed (6 files)
  • migration-tracking/progress/README.md
  • migration-tracking/progress/badge.svg
  • migration-tracking/progress/dispositions.json
  • migration-tracking/progress/history.svg
  • migration-tracking/progress/progress.json
  • migration-tracking/progress/progress.svg

Targeted re-verification of previous findings (unchanged files): packages/kilo-gateway-core/src/errors.ts, packages/kilo-gateway-core/src/models.ts.

Previous Review Summaries (2 snapshots, latest commit c2470ef)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c2470ef)

Status: No Issues Found | Recommendation: Merge

The incremental change at c2470ef was reviewed: the embedding catalog schema is now shared between the HTTP decoder and the RPC contract, the retry header is scoped so generic bodies keep the upstream 408/409 decision, and HTTP 425 is retried for the embedding catalog. The matching tests (gateway.test.ts, requests-errors.test.ts, models.test.ts) cover the new branches. Findings from the previous review were re-checked against this HEAD and are resolved. No memory leaks or resource-retention issues were introduced; the new Bun.serve fixture is stopped in finally and the shared schema module adds only the effect import. Validation commands were not executed in this read-only review; the PR body reports bun run check, typecheck, and tests passing.

Files Reviewed (8 files)
  • packages/core/src/kilocode/gateway-rpc.ts
  • packages/core/test/kilocode/gateway.test.ts
  • packages/kilo-gateway-core/package.json
  • packages/kilo-gateway-core/src/embedding-catalog.ts
  • packages/kilo-gateway-core/src/errors.ts
  • packages/kilo-gateway-core/src/models.ts
  • packages/kilo-gateway-core/test/models.test.ts
  • packages/kilo-gateway-core/test/requests-errors.test.ts

Previous review (commit 55e36a3)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-gateway-core/src/errors.ts 85 x-should-retry: false is applied to every parsed non-retryable body, so generic 408/409 Gateway responses (previously retried as ProviderInternalError) become terminal. Scope the header to recognized Kilo codes instead of the api_error fallback.

SUGGESTION

File Line Issue
packages/kilo-gateway-core/src/models.ts 342 The shared retryable predicate omits HTTP 425, which the v1 fetchKiloEmbeddingModelCatalog retried (408/425/429/5xx), contrary to the PR body's claim that the port matches v1.
Files Reviewed (24 files)
  • migration-tracking/progress/README.md
  • migration-tracking/progress/badge.svg
  • migration-tracking/progress/dispositions.json
  • migration-tracking/progress/history.svg
  • migration-tracking/progress/progress.json
  • migration-tracking/progress/progress.svg
  • packages/core/src/kilocode/gateway-rpc.ts
  • packages/core/src/kilocode/gateway.ts
  • packages/core/test/kilocode/gateway.test.ts
  • packages/kilo-gateway-core/src/autocomplete.ts
  • packages/kilo-gateway-core/src/errors.ts - 1 issue
  • packages/kilo-gateway-core/src/models.ts - 1 issue
  • packages/kilo-gateway-core/src/testing.ts
  • packages/kilo-gateway-core/test/account.test.ts
  • packages/kilo-gateway-core/test/autocomplete.test.ts
  • packages/kilo-gateway-core/test/edit-prompt.test.ts
  • packages/kilo-gateway-core/test/edit.test.ts
  • packages/kilo-gateway-core/test/enterprise-rpc.test.ts
  • packages/kilo-gateway-core/test/fim.test.ts
  • packages/kilo-gateway-core/test/headers.test.ts
  • packages/kilo-gateway-core/test/mistral-fim-endpoint.test.ts
  • packages/kilo-gateway-core/test/models.test.ts
  • packages/kilo-gateway-core/test/requests-errors.test.ts
  • packages/kilo-plugin/src/index.ts

The Mercury prompt port, RPC wiring, progress-map arithmetic/dispositions, and the new tests were checked against the implementation and (for the port) v1. No memory leaks or resource-retention issues were introduced; the new Bun.serve fixtures are stopped in finally and no new caches or timers exist. Validation commands were not executed in this read-only review; the PR body reports bun run check, typecheck, and tests passing.

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 77K · Output: 10.3K · Cached: 1M

Review guidance: REVIEW.md from base branch v2

…schema

- Set x-should-retry: false only for Kilo codes, so a generic Gateway 408
  or 409 keeps the upstream retry decision.
- Retry HTTP 425 for the embedding catalog, as v1 did.
- Move the EmbeddingCatalog schema to one module that both the HTTP
  decoder and the kilocode.gateway RPC contract use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli CLI, TUI and core engine area:gateway Kilo Gateway and auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants