Repository navigation
feat(vertex): run Claude Code on Vertex AI through bili - #3323
Conversation
…fake
- WC-019/020/021 join the ledger with provenance: the API version is a body field on this wire, the publisher path is the model's only source, stream errors arrive array-wrapped
- all three are lane-scoped (lane: "vertex-anthropic"), so the shared anthropic validator stays unwidened — WC-013 already forbids what WC-017 requires on another lane
- startFakeUpstream accepts { lane: "vertex-anthropic" }: its validators are written from the captured client bytes, which the first test replays verbatim, so the capture validates the fake rather than the reverse
- no rule for a body `model` field: Vertex's tolerance is unverified, and a constraint without provenance would reject legitimate traffic; a test pins the tolerance instead
- fixture pair in tests/fixtures/vertex-anthropic/: captured request byte-exact, response doc-derived and marked as such in the manifest, deliberately outside the golden wire-contract inventory
- lane probe table in tests/wire-contract.test.ts gives each new rule a live clause — the ledger gate fails without it
- tests: vertex-fake-upstream 8/8, vertex-wire-fixture 8/8, wire-contract 36/36 (97 across all fake importers)
Under CLAUDE_CODE_USE_VERTEX=1 the plain ANTHROPIC_BASE_URL is inert: Claude Code
dials <ANTHROPIC_VERTEX_BASE_URL>/projects/…:rawPredict|streamRawPredict and
appends that path to the base URL verbatim, so the launcher was rewriting a
variable nothing reads and Vertex traffic never reached bili.
- src/vertex.ts (new): vertexEnabled, vertexHostForLocation (explicit override →
global → us/eu multi-region → <loc>-aiplatform), vertexBaseUrlForLocation
(host + /v1, because the client appends /projects/… and Vertex 404s the
version-less path), normalizeVertexModelId, and the region guard ported with
the host derivation — the value is interpolated into a hostname, and a
percent-encoded # reaches the metadata endpoint (headroom's recorded payload)
- wrapUpstream/unwrapUpstream take an optional protocol, so the emitted form is
<origin>/bili/anthropic/<vertex host>/v1 and survives re-wrapping; the
parameter is optional, leaving all 51 existing call sites byte-identical
- buildClientEnv resolves a rewrite per key: the claude preset gains
ownBaseUrlKeys, because fanning baseUrlKeys[0]'s value out to a new key would
write api.anthropic.com into the Vertex variable, while iFlow's alias pair
keeps relying on that fan-out (regression pinned)
- discoverRoutes registers a second relayWrapRoute under ANTHROPIC_VERTEX_BASE_URL
with protocol "anthropic" (":rawPredict" matches no suffix in the ladder, so the
explicit marker is what classifies it); extractHttpsHosts reports the Vertex
host on that lane instead of api.anthropic.com
- buildClaudePluginEnv, buildClaudeSettingsArg (inline payload and win32 temp
file) and the native-install override emit both variables; the managed install
block pins and recognises the Vertex key (isBiliClaudeBaseUrl gained the
optional protocol segment), never clobbering a foreign value
- the plain key stays emitted and untouched (inert under Vertex, so flipping the
provider off still works) and nothing is emitted at all with Vertex off
- docs: manual-mode Vertex subsection plus the redirect/discovery table rows in
CONFIGURATION.md and CONFIGURATION.zh-CN.md, and a CHANGELOG [Unreleased] bullet
Tests: vertex.test.ts (host table incl. SSRF-shaped inputs, id normalisation),
launcher.test.ts (discovery, two-key resolution, iFlow regression, wrap/unwrap
round trip), launcher-plugin-mode.test.ts, claude-native.test.ts (managed block
writes and preserves the key), fix-1292-windows-claude-settings.test.ts (the
settings payload carries the second key). Full suite: 7214 tests, 7173 pass,
10 fail — all 10 reproduced at HEAD d6fb6af, none introduced here.
- read the model off the publisher path on the Vertex anthropic wire (`vertexAnthropicModelFromPath`), resolve it once (`bodyModel ?? googleModel ?? vertexPathModel ?? v1Model`) and normalise the `@version` tag out of the path-derived id, logging once per raw id - thread the resolved model into `resolveKnownOutputCeiling`, `prepareAnthropic` and `Prepared`, which is what the relay's compress-loop rebuild reads - map `aiplatform.googleapis.com` and both location-shaped host families to the `anthropic` provider - keep `anthropic_version` in the incremental-lane parameter allowlist and its `src/agent/incremental-client.ts` mirror - report `bypassed` for a Vertex session in `claudeNativeRoutingCheck`, where the plain `ANTHROPIC_BASE_URL` signal is inert - tests: `tests/e2e-vertex-anthropic.test.ts` drives the captured fixture at the path the launcher emits (classified, compressed, Vertex fields intact, and verbatim passthrough without the protocol marker), plus the registry, native-routing and incremental-lane cases
…ake it bite - the path parser's unit table: both method suffixes, the protocol-qualified path the launcher actually emits, a dated id returned raw (stripping stays normalizeVertexModelId's job, asserted separately), :countTokens and non-Anthropic publishers yielding nothing, a query or fragment tolerated, percent-encoding decoded, an undecodable escape falling back to the raw match instead of throwing - Lane gains optional protocol/lane, so a contract row can carry the /bili/<protocol>/<url> marker and a lane-scoped fake; a Vertex row posts the captured 45 KB client body at the publisher path, which runs WC-019/020/021 through the proxy for the first time - no golden snapshot: the four committed ones are layer-level tool surfaces and this lane adds none, so the golden inventory is a deliberate no-op rather than a regenerated diff - three mutations (the path-derived model arm, the parser, the location guard) were applied, observed failing named tests, and reverted
…x URL - stripBiliWrappers (src/vertex.ts) collapses nesting of bili's own /bili/ wrapper until the value is no longer one of ours; the single-shot unwrapBiliBaseUrl stays as it is (ANTHROPIC_BASE_URL's writer cannot nest). - claudeNativeVertexBaseUrl (src/plugin-install.ts) and claudeVertexUpstream (src/launcher.ts) unwrap the configured value before deriving, so install and the SessionStart repin are idempotent: derived == current means the managed block writes nothing. Before this, a launch or a start added a /bili/anthropic/ layer each time, and the added hop targeted the proxy's own port — denied by the tunnel guard (403 detail:"self"). - stripClaudeManagedBlock takes ANTHROPIC_VERTEX_BASE_URL back when it is ours, so `bili plugin remove claude` no longer leaves the client dialing a dead /bili/ URL; a foreign endpoint is left alone, as at install. - tests: stripBiliWrappers unit table (tests/vertex.test.ts); idempotent derivation, nested-value collapse and the installer round trip on the Vertex key (tests/claude-native.test.ts); discovery unwraps an already-managed base URL instead of nesting it (tests/launcher.test.ts).
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 open/closed issue+PR 全量检索 开始按 PR Review 规范审查:方向 → 回归 → 代码 → 测试有效性 → diff 整洁度。外部提交按 ⑤b 硬标准从严。结论将用结构化八问给出。 |
…anxianglei#3323 review fixups) Review fixups on the Vertex port, one defect class: unfilled issue references and pointers at a provenance doc that was never committed. - CHANGELOG: the ranxianglei#3266 bullet had been glued onto the end of the new Vertex bullet on one line — split it back into its own entry. - #NNNN / (#vertex) placeholders -> ranxianglei#3323 (tests/vertex-wire-fixture.test.ts, tests/registry.test.ts, tests/claude-native.test.ts, src/registry.ts). - reference/billion-context-vertex-grounding.md is not in this repo, so the four citations pointing at it (src/vertex.ts, tests/vertex-fake-upstream.test.ts, tests/wire-contract-fakes.ts WC-021 provenance, fixture README) now stop where the in-repo provenance (WIRE_RULES + fixture manifest) carries the record.
(ai: vllm-qwen/qwen3.8-27b) Review 完成。代码已逐文件读完(36 个文件全量 diff),定向测试本地跑绿,CI 状态核对完毕,发现的小问题已直接修掉推回分支。结论:质量达标,可合并(待 CI 的既有红清掉或 owner 判断后人工合并)。 结构化八问
审核细节
我直接修掉的小问题(已推回你的分支,commit
|
# Conflicts: # CHANGELOG.md # src/server/prepare-anthropic.ts # src/server/relay.ts
(ai: vllm-qwen/qwen3.8-27b) Cross-note from the CI-flake triage in #3449: your windows-latest shard fails deterministically (not a flake) in Root cause: Git-for-Windows checks text files out as CRLF ( One-line fix on your branch, same pattern as the existing entries: Reference: run 38982246862, job 117245612451 ( |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.499-master.774da9b # this exact build
npm install -g billion-context@master # always the newest merged build
|
Adds GCP Vertex AI as a supported backend for the
claudelane: a session launched withCLAUDE_CODE_USE_VERTEX=1routes its Claude traffic through bili and gets the same compression as an Anthropic session — no MITM, no classifier change, no new wire.Commits
d6fb6af693032cf3ANTHROPIC_VERTEX_BASE_URLthrough bili, pin it in the managed install block8b3d23b50592ee4af943b629Wire facts this rests on — measured, not inferred
ANTHROPIC_VERTEX_BASE_URLverbatim:/v1/projects/<p>/locations/<loc>/publishers/anthropic/models/<id>:streamRawPredict. Two consequences the code depends on: the emitted value must end in/v1(/v1/projects/…:rawPredict429s where/projects/…:rawPredict404s), and it must be the protocol-qualified form<bili>/bili/anthropic/https://aiplatform.googleapis.com/v1— the bare/bili/<url>form classifiesprotocol = null(:rawPredictmatches no suffix in the ladder) and forwards uncompressed.anthropic_version: "vertex-2023-10-16"and nomodelfield at all, so the id has to come off the path or the window/headroom decisions silently fall back to the floor.anthropic_versionis body-borne and survives the rebuild (the spread drops onlyprompt_cache_key); it was missing from the incremental-turn allowlist, which serves the native-extension lanes.:countTokens, and a publisher body must not carrymodel.Verification
tests/vertex.test.ts,tests/wire-contract.test.ts,tests/vertex-fake-upstream.test.ts,tests/vertex-wire-fixture.test.ts,tests/e2e-vertex-anthropic.test.ts,tests/claude-native.test.ts,tests/launcher.test.ts,tests/registry.test.ts,tests/incremental-lane.test.ts(the e2e drives the captured bytes through the real proxy against a lane-scoped fake upstream, and asserts the compression round trip).undefinedfails four; loosening the location regex fails the SSRF cases.npm run typecheck,scripts/check-unused-exports.mjs,scripts/check-test-import-graph.mjs: clean.#1086 T5, omp-native host, opencode-native, opencode-v2 ×3,#2443), plus#1292 runLaunch claude posix— which fails at HEAD as well when the shell exportsCLAUDE_CODE_USE_VERTEX/CLOUD_ML_REGION, as this one does; CI remains the verdict per §7.2.CI
The
testlane's shard 3 is red on all four runners (storage-render golden×4 and#1086 T5), and those five already fail onmasterat6ee4a2ac— the run for that commit (38767006158) has 9 of 12 shards red, withstorage-render golden4 fail / 5 pass in four of them and#1086 T5failing in three; both reproduce on a clean worktree at that commit. Every other check on this PR is green (39 passed).Not touched
tests/golden/wire-contract/*.json— no regeneration, because the inventory (tests/wire-contract-inventory.ts) snapshots layer-level tool surfaces, so this lane adds no snapshot. The ledger still grew (WC-019/020/021 with provenance and theirlaneProbesenforcement entries).kernel/,pi-subagents/, the MITM path, the suffix ladder,src/server/prepare-anthropic.ts's rebuild.Config surface
CONFIGURATION.mdandCONFIGURATION.zh-CN.mddocument the Vertex keys, the two variables bili writes (ANTHROPIC_VERTEX_BASE_URL,ANTHROPIC_BASE_URL) and the values they get;CHANGELOG.mdcarries an[Unreleased]entry.