Files
orca/src/shared/runtime-environment-subscription-setup.ts
T
Brennan Benson 0fa5dae2f9 Read who each agent works with: its manager, workers and peers (#34890)
* Nest chat-UI orchestration workers under the agent that started them

Main's lineage projection only walked terminal panes, so workers running
in the chat UI never got a parent link and listed flat in the sidebar.
It now also projects chat workers, keyed by their visible chat row, and
resolves a chat creator or coordinator to that chat's visible row
instead of its handle or private mailbox pane key.

* Fix public worker lineage across assignment and row identities

* Complete terminal lineage provenance and bound active session selection

* Repair lineage test runtime boundaries and SQLite counters

* Provide read-only crew snapshots for each agent

* Batch public lineage verification after exact recency selection

* Derive crew relations once per meaningful host change

* Remove package manager lockfile churn from hook

* Use checked runtime values in lineage integration tests

* Document the trusted Dispatch SQL row boundary

* Keep lineage integration imports within their test programs

* Load native lineage fixtures before test execution

* test: complete lineage inputs in runtime and sidebar fixtures

* test: seed benchmark facts from active dispatches

* test: replace partial orchestration DB casts with typed fixtures

* test: complete stale-leaf mailbox fixture session input

* Derive durable crew parents from retained assignment proof

* fix(test): render worker lineage fixture with production list

* Add scoped terminal identity acquisition and preserve crew source wakes

* Share raw crew identity inputs through scoped production readers

* Exercise crew generation retirement through actual source owners

* Retire crew inputs on consumed ownership and visibility writes

* Use typed crew mutation and fixture access

* Repair crew fixture and RPC type contracts

* Align crew integration fixtures and RPC parameter contracts

* Encapsulate terminal identity mutations and captured reader contracts

* Seed terminal identity fixtures through canonical mutations

* Fix terminal identity fixture return type

* Cover terminal identity lifecycle schedules

* Align terminal fixtures with canonical identity sources

* Repair runtime fixture source contracts

* Use checked database fixtures for federation contracts

* Update crew source inventories and exit fixtures

* Preserve crew setup outcomes at existing subscription owners

* Match managed restore fixture to its nullable async return type

* Keep absent setup observations distinct from undefined failures

* Drive pending Crew questions from existing metadata

* Preserve nested pairing repair outcomes for shared callers

* Route attached workers to explicit local recipients

* Type Crew pending-question measurement receipts

* Match SSH repair fixture target absence to store contract

* Bound cold terminal layout construction and finite pane acquisition

* test: use public runtime identity in pane acquisition fixture

* Avoid repeated searches in cold workspace layout loading

* Verify cold loader fault identity and hook claimant effects

* Revert "Route attached workers to explicit local recipients"

This reverts commit f1335d1c06.

Keep attached workers on the existing Run-home routing path for this change.

* Omit crew peer addresses outside the active home route

* Keep crew retries on the verified runtime session

* Bound cold layout retirement and recorded-key construction

* Verify original cold layout failure identity

* fix: preserve surviving layout split references

* test: use typed retirement instrumentation properties

* test: preserve pane and retirement fixture contracts with checked types

* Prepare Crew record admission and wake identity changes

* Derive Crew recipient actions from current target owners

* Keep nested Crew process facts within selected acquisition

* Defer Crew legacy facts to consumers and complete raw coverage on success

* Use deterministic time in Crew command fixtures

* Document schema-owned Dispatch row assertions

* test: align Crew authority fixtures with typed project boundaries

* test: place Crew CLI integration in cross-surface project

* Type retained identity test meters with canonical source maps

* Document suffix Dispatch row boundary and preserve fixture unbinding

* test: migrate Crew authority arguments and mailbox observations

* Derive Crew attention and actions from complete recipient authority

* Fix Crew public-command fixture type contracts

* Align Crew fixtures with runtime reader and routing contracts

* Narrow receiving fixture calls to unary RPC methods

* Age pending question fixtures from every actual answer timestamp

* Complete Crew public-command workspace fixture result

* Test delegated helper follow-up through Crew advertised address

* Qualify Crew follow-up addresses through shared command admission

* Complete finite follow-up authority and lifetime evidence

* Assert exact remote authority acquisition error identity

* Consolidate Crew SQL test fixture imports

* Trim Crew read-model tests to the high-impact set

Keep the real CLI/RPC/database command paths, one regression per review-found bug, the cross-version contracts and one N vs 10N operation contract per scaling piece. Drop permutation matrices, equivalence oracles, near-duplicate scenarios and diagnostic output, and return the SSH, managed-server and WSL test files to main, since their production changes were reverted earlier in this PR.

* Drop diagnostic output and a duplicate error case from Crew tests

Remove two leftover console.log diagnostics, an unused 2x2 sample matrix and unused return fields in the follow-up cost contract, and the subscription AbortError serialization case that the subscription identity and preload tests already cover.

* Pass the recorded-leaf reader in main's check-details loader test
2026-11-01 13:28:53 -08:00

88 lines
2.4 KiB
TypeScript

import type { RuntimeRpcResponse } from './runtime-rpc-envelope'
/** Local setup facts; remote protocol and saved host records do not carry them. */
type SetupFact =
| { kind: 'cancelled' | 'source-retired' | 'manual-disconnect' | 'input' | 'host-unsupported' }
| { kind: 'remote'; code: string }
| {
kind: 'operation'
operation: 'environment-resolution' | 'subscription'
}
export type CrewSetupFact = Readonly<SetupFact>
export type CrewSubscriptionSetupResult =
| { subscriptionId: string; ok: true }
| {
subscriptionId: string
ok: false
failure: { message: string; code?: string; fact: CrewSetupFact }
}
export type CrewSubscriptionAttemptArgs = {
subscriptionId: string
selector: string
method: 'orchestration.crewSubscribe'
params?: unknown
timeoutMs?: number
expectedEnvironmentPairingRevision: number
expectedEnvironmentRuntimeId: string | null
}
/** A fresh guard's fact belongs to that occurrence, never to a reused external Error. */
export class RuntimeEnvironmentSetupGuardError extends Error {
constructor(
message: string,
readonly setupFact: CrewSetupFact
) {
super(message)
}
}
export type RuntimeEnvironmentSetupFailure = Readonly<{
error: unknown
fact: CrewSetupFact
}>
export function runtimeEnvironmentSetupFailure(
error: unknown,
operation: Extract<CrewSetupFact, { kind: 'operation' }>['operation']
): RuntimeEnvironmentSetupFailure {
return {
error,
fact:
error instanceof RuntimeEnvironmentSetupGuardError
? error.setupFact
: { kind: 'operation', operation }
}
}
export type CrewSubscriptionAttemptCallbacks = {
onResponse: (response: RuntimeRpcResponse<unknown>) => void
onError?: (error: { code: string; message: string }) => void
onClose?: () => void
}
export function isCrewSetupFact(value: unknown): value is CrewSetupFact {
if (typeof value !== 'object' || value === null || !('kind' in value)) {
return false
}
switch (value.kind) {
case 'cancelled':
case 'source-retired':
case 'manual-disconnect':
case 'input':
case 'host-unsupported':
return true
case 'remote':
return 'code' in value && typeof value.code === 'string'
case 'operation':
return (
'operation' in value &&
(value.operation === 'environment-resolution' || value.operation === 'subscription')
)
default:
return false
}
}