-
Notifications
You must be signed in to change notification settings - Fork 957
feat(remote): phase 1 — runtime roles, /readyz protocol negotiation, data-plane /v1/catalog #2772
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
d25cbc0
feat(remote): add protocol metadata and runtime role
3d983d5
feat(remote): serve authenticated catalog snapshots
1bb9828
fix(remote): derive management origin from request host
825800e
test(remote): cover phase one protocol and catalog contract
8980430
fix(remote): type catalog bytes over ArrayBuffer and scope the key-id…
4fdd54d
fix(remote): reconcile the phase-one catalog contract with the landed…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import type { OcxConfig } from "../types/config"; | ||
|
|
||
| export const REMOTE_HUB_PROTOCOL = 1; | ||
| export const MINIMUM_REMOTE_CLIENT_PROTOCOL = 1; | ||
|
|
||
| export interface RemoteReadyMetadata { | ||
| protocol: number; | ||
| minimumClientProtocol: number; | ||
| managementUrl: string; | ||
| } | ||
|
|
||
| export type RemoteProtocolCompatibility = | ||
| | { ok: true; metadata: RemoteReadyMetadata } | ||
| | { ok: false; reason: "invalid" | "hub-too-new" | "hub-too-old"; message: string }; | ||
|
|
||
| const INVALID_REMOTE_PROTOCOL_MESSAGE = | ||
| "OpenCodex hub returned invalid remote protocol metadata; upgrade or repair ocx on the hub."; | ||
|
|
||
| function positiveSafeInteger(value: unknown): value is number { | ||
| return typeof value === "number" && Number.isSafeInteger(value) && value > 0; | ||
| } | ||
|
|
||
| function managementOrigin(value: unknown): string | null { | ||
| if (typeof value !== "string") return null; | ||
| try { | ||
| const parsed = new URL(value); | ||
| if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null; | ||
| if (parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash) return null; | ||
| return parsed.origin; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function observedManagementOrigin(req: Request): string | null { | ||
| try { | ||
| const requestUrl = new URL(req.url); | ||
| const host = req.headers.get("Host") ?? requestUrl.host; | ||
| return managementOrigin(`${requestUrl.protocol}//${host}`); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function readyProtocolMetadata(config: OcxConfig, req: Request): RemoteReadyMetadata { | ||
| // Phase 2 will consult config.hub.managementPublicOrigin here. Keeping the | ||
| // parameter now fixes the consumer signature without changing Phase 1 behavior. | ||
| void config; | ||
| const managementUrl = observedManagementOrigin(req); | ||
| if (!managementUrl) throw new Error("Readiness request does not have an HTTP(S) management origin"); | ||
| return { | ||
| protocol: REMOTE_HUB_PROTOCOL, | ||
| minimumClientProtocol: MINIMUM_REMOTE_CLIENT_PROTOCOL, | ||
| managementUrl, | ||
| }; | ||
| } | ||
|
|
||
| export function parseRemoteReadyMetadata(value: unknown): RemoteReadyMetadata | null { | ||
| if (!value || typeof value !== "object" || Array.isArray(value)) return null; | ||
| const raw = value as Record<string, unknown>; | ||
| if (!positiveSafeInteger(raw.protocol) || !positiveSafeInteger(raw.minimumClientProtocol)) return null; | ||
| if (raw.minimumClientProtocol > raw.protocol) return null; | ||
| const parsedManagementOrigin = managementOrigin(raw.managementUrl); | ||
| if (!parsedManagementOrigin) return null; | ||
| return { | ||
| protocol: raw.protocol, | ||
| minimumClientProtocol: raw.minimumClientProtocol, | ||
| managementUrl: parsedManagementOrigin, | ||
| }; | ||
| } | ||
|
|
||
| export function checkRemoteProtocolCompatibility( | ||
| value: unknown, | ||
| client: { protocol: number; minimumHubProtocol: number } = { | ||
| protocol: REMOTE_HUB_PROTOCOL, | ||
| minimumHubProtocol: MINIMUM_REMOTE_CLIENT_PROTOCOL, | ||
| }, | ||
| ): RemoteProtocolCompatibility { | ||
| const metadata = parseRemoteReadyMetadata(value); | ||
| if (!metadata || !positiveSafeInteger(client.protocol) || !positiveSafeInteger(client.minimumHubProtocol)) { | ||
| return { ok: false, reason: "invalid", message: INVALID_REMOTE_PROTOCOL_MESSAGE }; | ||
| } | ||
| if (client.protocol < metadata.minimumClientProtocol) { | ||
| return { | ||
| ok: false, | ||
| reason: "hub-too-new", | ||
| message: `OpenCodex hub requires remote protocol ${metadata.minimumClientProtocol}; this client supports protocol ${client.protocol}. Upgrade ocx on this client.`, | ||
| }; | ||
| } | ||
| if (metadata.protocol < client.minimumHubProtocol) { | ||
| return { | ||
| ok: false, | ||
| reason: "hub-too-old", | ||
| message: `OpenCodex hub provides remote protocol ${metadata.protocol}; this client requires at least ${client.minimumHubProtocol}. Upgrade ocx on the hub.`, | ||
| }; | ||
| } | ||
| return { ok: true, metadata }; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the readiness documentation alongside this response change:
docs-site/src/content/docs/reference/cli/lifecycle.md:158-160still describes the sanitized identity as exactly{service, version, uptime, pid, port, status}, and the translated lifecycle pages repeat that obsolete shape. Operators and API consumers therefore cannot discover the new protocol-negotiation fields from the public docs; documentprotocol,minimumClientProtocol, andmanagementUrlin the English source and synchronize the locales.AGENTS.md reference: src/AGENTS.md:L28-L28
Useful? React with 👍 / 👎.