Repository navigation
perf(platform): name a foreign-model agent exec for replica cache affinity - #3490
Merged
Merged
Conversation
…inity A self-hosted model served by several replicas keeps each conversation's prompt prefix in one replica's cache. A balancer that picks by load alone sends later turns of the same agent exec to the other replica, which prefills the whole conversation again: one observed 42-turn exec changed replica 20 times and spent about a seventh of its model time re-reading its own context. A managed Claude Code turn on a model that is not Claude now names its exec in every request (ANTHROPIC_CUSTOM_HEADERS carries x-bf-eh-x-tale-cache-affinity: <exec id>). The gateway forwards that header upstream as X-Tale-Cache-Affinity, so a balancer can hash it to keep the turn on one replica; an upstream that ignores it is unaffected. A Claude model, an exec without an id and a bring-your-own credential send nothing new.
Contributor
Author
|
Verification of the client half: Claude Code 2.1.282 run against a local header-recording endpoint with |
yannickmonney
added a commit
that referenced
this pull request
Sep 26, 2026
Brings in #3490 and #3491. chat-surface.tsx takes main's new branch-selection import path and fork comment; chatDraftKey stays in lib/draft-key.ts, unchanged. Main's round added CHAT-F44, NAV-F25, PROJ-F25, SET-F46, TASK-F19 and TASK-B6 while this branch's unmerged boxes held the same IDs. Main's boxes keep theirs; this branch's move to CHAT-F46, NAV-F41, PROJ-F28, SET-F48, TASK-F28 and TASK-B7, and their references follow. The conflicted suites' counts are recounted.
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A self-hosted model served by several replicas keeps each conversation's prompt prefix in one replica's cache. A balancer that picks a replica by load alone (least connections) sends the next turn of the same agent exec to whichever replica is idle, and that replica prefills the whole conversation again.
Measured on a live two-replica deployment: one 42-turn agent exec changed replica 20 times and re-prefilled about 285K tokens, roughly 7 of its 49 minutes of model time.
What
A managed Claude Code turn on a model that is not Claude now names its exec in every request:
ANTHROPIC_CUSTOM_HEADERScarriesx-bf-eh-x-tale-cache-affinity: <exec id>, appended to any header the harness already sends.x-bf-eh-*headers to the provider with the prefix stripped, so the upstream seesX-Tale-Cache-Affinity: <exec id>.lb_policy header X-Tale-Cache-Affinity { fallback least_conn }. An upstream that ignores it is unaffected.Nothing changes for a Claude model, for an exec without an id, or for a bring-your-own credential.
Tests
lib/harnesses/exec-builder.test.ts: the header is set, an existing custom header is kept, and none is sent for a Claude model, an exec without an id, or a BYO credential.golden-exec.test.ts: no golden changes, since no golden case pairs a foreign model with an exec id.@tale/platformlint and typecheck pass,lint:manualpasses, and a row was added totests/manual/reference/automation.md.Whether a multi-replica balancer actually keeps the turn on one replica is a deployment check. It is verified on the router that consumes the header, which hashes it with a least-connections fallback.