Repository navigation
feat(remote): name the serving Home in x-opencodex-served-by (OCX-2) #7490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
42b6dc7
feat(remote): name the serving Home in x-opencodex-served-by (OCX-2)
lidge-jun d53054c
refactor(remote): keep the served-by stamping in served-by.ts
lidge-jun f39e5ae
fix(remote): keep instanceId on the package-tree-fenced /healthz
lidge-jun 9c7d7a1
test(remote): make the opacity check chance-proof; document rotation …
lidge-jun 340578c
test(remote): assert the /v1/models refusal status in the served-by case
lidge-jun 79f248e
test(remote): the keyless loopback refusal is 403 origin_rejected
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,57 @@ | ||
| /** | ||
| * The served-by response header and whether this build sends it. | ||
| * The served-by response header, the Home instance id it carries, and whether this build sends it. | ||
| * | ||
| * Relayed and Hub-served responses are meant to name the Home that served them in | ||
| * `x-opencodex-served-by`, so a peer can prove which Home answered without reading logs. This module | ||
| * is the emitter's descriptor: `SERVED_BY_HEADER_EMITTED` is true only in a build whose responses | ||
| * carry the header, and the change that starts sending it flips the flag in the same commit. | ||
| * `/readyz` advertises `served-by-header` from this flag (`src/remote/features.ts`), and | ||
| * `tests/server/readyz-features.test.ts` fails if the advertisement and live responses disagree. | ||
| * Every `GET /v1/models` response the server answers itself names the serving Home in | ||
| * `x-opencodex-served-by`, and `GET /healthz` publishes the same value as `instanceId`, so a peer | ||
| * (GOAT's parity check P4) can prove which Home answered without reading logs. A Remote Link Child | ||
| * never answers `/v1/models` itself: its relay copies the Home's response headers, so the value a | ||
| * Child returns is the Home's. A Hub-mode client's Codex calls the Hub's data listener directly, so | ||
| * the Hub stamps its own response. | ||
| * | ||
| * The instance id is the install's `homeId` from `src/quota-pool/identity.ts`: a random | ||
| * `home_<32 hex>` minted once per install, persisted owner-only, and stable across restarts. It is | ||
| * never a hostname and is not derived from one. Until the identity exists (it is created in the | ||
| * background after the listener starts) or when its file is unreadable, the header and the | ||
| * `/healthz` field are omitted; an empty or malformed value is never sent. | ||
| * | ||
| * `SERVED_BY_HEADER_EMITTED` tells `/readyz` to advertise `served-by-header` | ||
| * (`src/remote/features.ts`); `tests/server/readyz-features.test.ts` fails if the advertisement | ||
| * and live responses disagree. | ||
| */ | ||
| import { readQuotaPoolIdentity } from "../quota-pool/identity"; | ||
|
|
||
| export const SERVED_BY_HEADER = "x-opencodex-served-by"; | ||
|
|
||
| /** Whether responses from this build carry {@link SERVED_BY_HEADER}. */ | ||
| export const SERVED_BY_HEADER_EMITTED: boolean = false; | ||
| export const SERVED_BY_HEADER_EMITTED: boolean = true; | ||
|
|
||
| const INSTANCE_ID = /^home_[0-9a-f]{32}$/; | ||
|
|
||
| /** This Home's opaque instance id, or undefined while the install identity is unavailable. */ | ||
| export function homeInstanceId(): string | undefined { | ||
| let homeId: unknown; | ||
| try { homeId = readQuotaPoolIdentity()?.homeId; } catch { return undefined; } | ||
| return typeof homeId === "string" && INSTANCE_ID.test(homeId) ? homeId : undefined; | ||
| } | ||
|
|
||
| /** Stamp {@link SERVED_BY_HEADER} with this Home's instance id; leaves the response alone without one. */ | ||
| export function withServedBy(response: Response, instanceId = homeInstanceId()): Response { | ||
| if (!instanceId) return response; | ||
| try { | ||
| response.headers.set(SERVED_BY_HEADER, instanceId); | ||
| return response; | ||
| } catch { | ||
| const headers = new Headers(response.headers); | ||
| headers.set(SERVED_BY_HEADER, instanceId); | ||
| return new Response(response.body, { status: response.status, statusText: response.statusText, headers }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The server's last step for every answered request: `GET /v1/models` names the serving Home, | ||
| * whichever branch produced the response. `pathname` is the dispatch path the router matched. | ||
| */ | ||
| export function stampServedBy(method: string, pathname: string, response: Response): Response { | ||
| if (!response || method !== "GET" || pathname !== "/v1/models") return response; | ||
| return withServedBy(response); | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.