Repository navigation
feat(gateway): port the Gateway residue and record the port on the progress map - #15237
Conversation
…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.
|
📈 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 Ratchets: 8 core-internal imports (base 8); shared patches by rung 16 seam, 1 patch (base 16 seam, 1 patch).
47 cells closed
12 cells dropped
|
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The incremental change at Both previous findings were re-checked at this HEAD and remain fixed: 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 Files Reviewed (6 files)
Targeted re-verification of previous findings (unchanged files): 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 Files Reviewed (8 files)
Previous review (commit 55e36a3)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (24 files)
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 Reviewed by deepseek-v4.1-flash-1017 · Input: 77K · Output: 10.3K · Cached: 1M Review guidance: REVIEW.md from base branch |
…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.
What Problem This Solves
The
gatewaybox on the v2 progress map showed 12/87 while most of the Kilo Gateway behavior is onv2. 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
fb7e96eda540and 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.embeddingModelsinkilo-gateway-core/src/models.tsand themodels.embeddingsmethod of thekilocode.gatewayRPC. The route is public, so no token is sent. It refuses redirects and retries network errors and transient statuses up to 3 attempts, as v1fetchKiloEmbeddingModelCatalogdid.buildMercuryEditPromptand its blocks inkilo-gateway-core/src/autocomplete.ts, ported from v1edit-prompt.ts. The v2 package hadextractFencedBodybut not the prompt builder.KiloErrors.rewriteHttpResponsesetsx-should-retry: falsewhenparsemarks the error as not retryable. The upstream retry policy (isRetryableinpackages/ai/src/provider-error.ts) reads this header. Before this change, a 429PROMOTION_MODEL_LIMIT_REACHEDwas 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(fromkilo-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
Placement
kilo-gateway-core/src/models.ts,core/src/kilocode/gateway.tsRPC handlerkilo-gateway-core/src/autocomplete.tskilo-gateway-core/src/errors.ts,kilo_port(gateway:1995b11b5cdd)kilo.tsimport, settings and headers, Kilo SDKcore/src/kilocode/gateway.ts,kilo_port(gateway:e8673ed1650b),kilo_port(gateway:73ba28ce78a5),kilo_port(gateway:742c02b40457)request.tsproject, machine and parentcore/src/kilocode/gateway.ts,kilo_port(gateway:50352226b43c)kilo-plugin/src/index.ts,kilo_port(gateway:17e39e074eaf)transform.tsprovider options key, variants, per-SDK optionscore/src/kilocode/gateway.ts,kilo_port(gateway:0278ba0eb6aa),kilo_port(gateway:59f57027c538),kilo_port(gateway:f983d8f993c8)core/test/kilocode/gateway.test.ts,kilo_port(gateway:5187eb3f1516),kilo_port(gateway:d29cb22ad5f6)kilo-gateway-corestill imports nothing from@opencode/*.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.tsimport, settings and headers, and Kilo SDK, and the v1transform.tsprovider options key, server variants and per-SDK options ->core/src/kilocode/gateway.ts(provider transform,packageFor,toModelInfowithVariant.resolveon the Gatewayreasoning_options);request.tsproject, machine and parent -> themodel.requesthook; plugin registration ->KiloPlugins;retry.ts->x-should-retry: falseinKiloErrors.rewriteHttpResponse(ported here); two v1 test cells -> the dialect and variant assertions incore/test/kilocode/gateway.test.ts.dispositions.json. Examples:api/url.ts->server.ts,fim.ts,edit.tsandmistral-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) andembedding-models.ts(catalog and RPC). The twopackage.jsonhunks are the dependency on@kilocode/gateway-core.autocomplete,edit-prompt,edit,fimandmistral-fim-endpointtests.00d34e8d5cd7, variants fromreasoning_optionsthrough upstreamVariant.resolve.Mixed hunks:
17e39e074eafalso imports the Atomic Chat and Anaconda Desktop plugins, and1995b11b5cddalso importsSessionNetwork. Their use is in other open cells.50352226b43calso resolved the per-session platform attribution, which needs the sessionplatformfield (patch:unattributed:session:142910b3fc8c). v2 follows the live v1 CLI for token precedence (environment token first,acd3d1ff9b), not v1core/src/plugin/provider/kilo.ts.Dropped, and why it is not needed:
server/routes.ts,server/fim.ts,server/edit.ts: Hono routes;createKiloRouteshad no caller on v1. The live v1 routes are inopencode/src/kilocode/server/httpapi/handlers/kilo-gateway.ts(server box, which keeps FIM and Next Edit execution open). v2 serves the Gateway through thekilocode.gatewayRPC.types/jsx.d.ts,types/tui.d.ts: type shims for TUI code outside the TUI package; the v2 TUI code is inpackages/tui.auth/device-auth.ts: console login that v1 marked as not used; the live flow is ported todevice.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.core/src/v1/config/provider.tshunks: config fieldsprompt,isFree,ai_sdk_provider. v2 reads dialect andisFreefrom the Gateway catalog;promptis 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-exportunit.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/usagedialog and VS Code cards; v2 has only the raw usage RPC.gateway-metadata.tsand its test: v2 drops the Gateway cost metadata (marketCost,generationId) that v1 attached for the session cost.transform.tscells 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 gotkilo_portbecause Kilo adapter code provides them (forretry.ts,retryable: falsehad to be wired first), and 8 stay open with gaps. Cloud sessions,server/handlers.tsand the event service client were planned as dropped but have plan units, so they stay open.edit-prompt.tswas not on v2, so it was ported.provider-usage.tsandgateway-metadata.tshave gaps, so they stay open. The secondretry.tshunk and theX-KILOCODE-*header hunk sit inunattributed:sessionbecause the map generator readsgit cat-file --batchoutput as text with byte offsets; fixing that needs its own PR, because it moves cells in most boxes.Evidence
bun testinpackages/kilo-gateway-core: 72 pass, 0 fail.bun test test/kilocodeinpackages/core(isolated home): 11 pass, 0 fail.bun typecheckinpackages/kilo-gateway-core,packages/core,packages/tui,packages/kilo-plugin,packages/kilo-cli: pass.bun run checkfrom the root: pass.bun script/upstream/progress.tstwice with identical output, then--check: up to date.bun script/upstream/placement.ts --imports:kilo-gateway-core0@opencodeimports; 4 distinct core-internal modules (unchanged).bun script/check-shared-patches.tsandbun script/check-opencode-annotations.ts: ok.https://ai-gateway.kilo.ai/api/v1/embedding-modelsreturns the catalog shape thatembeddingModelsdecodes.Self-test (CLI through the Kilo host, fresh profile each):
bun dev models --standalone, signed out: lists 16kilo/*free models. Pass.bun dev run --standalone -m kilo/kilo-auto/free "Reply with only the word PONG.": answersPONG.. Pass./kilo-account, signed in withKILO_API_KEYandKILO_ORG_ID: shows name, account, scope, balance and team modes; no errors in the log. Pass.Limits: the 429
PROMOTION_MODEL_LIMIT_REACHEDpath cannot be triggered on demand, so it is covered by a unit test and by a test that runs the rewritten response through the upstreamhttpFailureandisRetryable. 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.