mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(orchestration): a paired Orca as a Run's coordinator on the server it placed work on (inert) The server half of remote-owned workers. A paired Orca's call names one of its Runs; the server admits it as a peer caller kind, writes that Run at frame receipt, and holds it to the one access check. Its workers' mail and state queue home under a sequence no reset reuses. Nothing sends the envelope until the coordinator side ships, so this changes nothing today. * fix(orchestration): reserve the peer address, keep conversation kinds apart, queue a correction once with its result * fix(orchestration): hold back a corrected Task's change whatever its latest attempt; rotate pulls in a stable order per database * chore(orchestration): typed field read, cast rationales, a wake test on fake timers * fix(orchestration): a peer's receipts per conversation, its sends only into its Run, a page that fits every conversation, pending adopted Tasks keep their gate * fix(orchestration): a peer's follow-up places where its worker ran * fix(orchestration): a peer's current/new-child start gets the --on placement refusal
129 lines
3.4 KiB
TypeScript
129 lines
3.4 KiB
TypeScript
// Share envelopes across CLI/desktop/non-Electron clients without client-to-client imports.
|
|
import { z } from 'zod'
|
|
import type { OrchestrationCompatibilityEvidence } from './orchestration/orchestration-compatibility-evidence'
|
|
import type { RemoteOwnedPeerRun } from './orchestration/remote-owned-wire'
|
|
|
|
// Independently updated peers may add envelope fields; strip unknown fields while validating known ones.
|
|
const MetaSuccess = z
|
|
.object({
|
|
runtimeId: z.string()
|
|
})
|
|
.strip()
|
|
|
|
const MetaFailure = z
|
|
.object({
|
|
runtimeId: z.union([z.string(), z.null()])
|
|
})
|
|
.strip()
|
|
.optional()
|
|
|
|
const Success = z
|
|
.object({
|
|
id: z.string(),
|
|
ok: z.literal(true),
|
|
result: z.unknown(),
|
|
_meta: MetaSuccess
|
|
})
|
|
.strip()
|
|
|
|
const Failure = z
|
|
.object({
|
|
id: z.string(),
|
|
ok: z.literal(false),
|
|
error: z
|
|
.object({
|
|
code: z.string(),
|
|
message: z.string(),
|
|
data: z.unknown().optional()
|
|
})
|
|
.strip(),
|
|
_meta: MetaFailure
|
|
})
|
|
.strip()
|
|
|
|
const Keepalive = z
|
|
.object({
|
|
_keepalive: z.literal(true)
|
|
})
|
|
.strip()
|
|
|
|
export const RuntimeRpcEnvelopeSchema = z.union([Success, Failure, Keepalive])
|
|
|
|
export type RuntimeRpcSuccess<TResult> = {
|
|
id: string
|
|
ok: true
|
|
result: TResult
|
|
_meta: {
|
|
runtimeId: string
|
|
}
|
|
}
|
|
|
|
export type RuntimeRpcFailure = {
|
|
id: string
|
|
ok: false
|
|
error: {
|
|
code: string
|
|
message: string
|
|
data?: unknown
|
|
}
|
|
_meta?: {
|
|
runtimeId: string | null
|
|
}
|
|
}
|
|
|
|
export type RuntimeRpcResponse<TResult> = RuntimeRpcSuccess<TResult> | RuntimeRpcFailure
|
|
|
|
export type RuntimeOrchestrationEnvelope = {
|
|
orchestrationCapability?: string
|
|
orchestrationContractVersion?: number
|
|
orchestrationRequestId?: string
|
|
/** A paired Orca acting as the coordinator of one of its Runs on this server. */
|
|
orchestrationPeerRun?: RemoteOwnedPeerRun
|
|
compatibilityInvocationId?: string
|
|
orchestrationCompatibilityEvidence?: OrchestrationCompatibilityEvidence
|
|
}
|
|
|
|
/** Which runtime a request is meant for; a host that is not that runtime refuses it before any handler. */
|
|
export const ExpectedRuntimeSourceSchema = z.object({
|
|
sourceId: z.string().min(1).max(4_096),
|
|
runtimeId: z.string().min(1).max(4_096)
|
|
})
|
|
|
|
export type ExpectedRuntimeSource = {
|
|
/** The launching profile's installation id. */
|
|
sourceId: string
|
|
/** The runtime the client verified for this send. */
|
|
runtimeId: string
|
|
}
|
|
|
|
export type RuntimeRpcKeepaliveFrame = z.infer<typeof Keepalive>
|
|
|
|
export function isKeepaliveFrame(frame: unknown): frame is RuntimeRpcKeepaliveFrame {
|
|
return (
|
|
typeof frame === 'object' &&
|
|
frame !== null &&
|
|
'_keepalive' in frame &&
|
|
(frame as { _keepalive: unknown })._keepalive === true
|
|
)
|
|
}
|
|
|
|
/** Same-machine IPC observation only; remote hosts own their own monotonic operation budget. */
|
|
export type RuntimeRpcDispatchObservation = {
|
|
expiresAt: number
|
|
responseTimeoutMs: number
|
|
responseExpiresAt?: number
|
|
}
|
|
|
|
/** Select request params from the status of the socket that will send them. */
|
|
export type RuntimeRequestSelection = {
|
|
paramsForStatus: (status: unknown) => unknown
|
|
onDispatch?: () => void
|
|
}
|
|
|
|
/** Internal preparation on the exact sending socket; never serialized or given credentials. */
|
|
export type RuntimeRequestPreparation = (request: {
|
|
params: unknown
|
|
envelope: RuntimeOrchestrationEnvelope | undefined
|
|
measure: (params: unknown, envelope: RuntimeOrchestrationEnvelope | undefined) => number
|
|
}) => { params: unknown; envelope: RuntimeOrchestrationEnvelope | undefined }
|