fix(orchestration): correct paired terminal parity cells, check thrown refusal codes, catch more kind-branch spellings

This commit is contained in:
Jinwoo-H
2026-11-09 05:15:21 -05:00
parent 03f2b62bdf
commit ff61f5d796
5 changed files with 80 additions and 25 deletions
@@ -3,9 +3,17 @@ valid:
- const party = resolveOrchestrationParty(address, db)
- if (party.terminalHandle === undefined) { return }
- const local = target.startsWith('run:')
- const id = party.orcaSessionId ?? fallback
- 'send({ handle: party.terminalHandle })'
invalid:
- if (to.startsWith(ORCA_SESSION_ADDRESS_PREFIX)) { return }
- const session = parseOrcaSessionAddress(to)
- if (party.orcaSessionId !== null) { notify() }
- if (agent.kind === 'structured') { inject() }
- const chat = !isTuiAgent(agent)
- if (agent.kind !== 'structured') { inject() }
- if (party.orcaSessionId) { inject() }
- if (party.orcaSessionId != null) { inject() }
- const terminal = !party.orcaSessionId
- const handle = party.terminalHandle && pointer(party.terminalHandle)
- "const route = caller.orcaSessionId ? 'chat' : 'terminal'"
@@ -28,11 +28,26 @@ rule:
# Party shape
- pattern: $P.orcaSessionId !== null
- pattern: $P.orcaSessionId === null
- pattern: $P.orcaSessionId != null
- pattern: $P.orcaSessionId == null
- pattern: $P.terminalHandle === null
- pattern: $P.terminalHandle !== null
- pattern: $P.terminalHandle != null
- pattern: $P.terminalHandle == null
# Party shape tested for truthiness: `if (p.orcaSessionId)`, `!p.x`, `p.x && …`, `p.x ? …`
- all:
- kind: member_expression
- has: { field: property, regex: '^(orcaSessionId|terminalHandle)$' }
- any:
- inside: { kind: parenthesized_expression, inside: { kind: if_statement } }
- inside: { kind: unary_expression, has: { field: operator, regex: '^!$' } }
- inside: { kind: binary_expression, has: { field: operator, regex: '^(&&|\|\|)$' } }
- inside: { kind: ternary_expression, field: condition }
# Kind and mode literals
- pattern: $K.kind === 'structured'
- pattern: $K.kind !== 'structured'
- pattern: $K.mode === 'structured'
- pattern: $K.mode !== 'structured'
- pattern: isTuiAgent($$$)
# Caller kind read from the environment
- pattern: readInjectedAgentSessionId($$$)
+15 -2
View File
@@ -4,14 +4,22 @@
2 src/cli/handlers/orchestration/message-send-handler.ts
4 src/cli/handlers/orchestration/terminal-identity.ts
1 src/main/runtime/orchestration/crew/crew-parent-inputs.ts
1 src/main/runtime/orchestration/crew/crew-parent-relations.ts
4 src/main/runtime/orchestration/crew/crew-parties.ts
2 src/main/runtime/orchestration/crew/crew-party-snapshot.ts
7 src/main/runtime/orchestration/crew/crew-party-snapshot.ts
1 src/main/runtime/orchestration/crew/crew-query.ts
11 src/main/runtime/orchestration/crew/crew-recipient-availability.ts
6 src/main/runtime/orchestration/crew/crew-recipient-inputs.ts
1 src/main/runtime/orchestration/crew/crew-recipient-owner-queries.ts
1 src/main/runtime/orchestration/crew/crew-recipient-worker-facts.ts
3 src/main/runtime/orchestration/db/dispatch-context/worker-follow-up-lineage.ts
3 src/main/runtime/orchestration/db/legacy/legacy-compatibility-candidates.ts
1 src/main/runtime/orchestration/db/runs/run-lookup.ts
1 src/main/runtime/orchestration/db/schema/structured-worker-orca-session-backfill.ts
1 src/main/runtime/orchestration/mailbox/routing/structured-session-mail-address.ts
3 src/main/runtime/orchestration/mailbox/routing/structured-session-mail-target.ts
2 src/main/runtime/orchestration/mailbox/senders/accepted-answer-sender.ts
4 src/main/runtime/orchestration/mailbox/senders/agent-message-relation.ts
1 src/main/runtime/orchestration/mailbox/senders/agent-message-sender.ts
2 src/main/runtime/orchestration/terminal-authority/structured-sessions/structured-worker-authority.ts
1 src/main/runtime/orchestration/terminal-authority/structured-sessions/structured-worker-custody.ts
@@ -25,13 +33,18 @@
1 src/main/runtime/orchestration/workers/turn-stops/chat-worker-error-escalation.ts
1 src/main/runtime/rpc/methods/orchestration/caller-show.ts
1 src/main/runtime/rpc/methods/orchestration/federation/federated-worker-start.ts
1 src/main/runtime/rpc/methods/orchestration/messaging/finished-worker-mail.ts
3 src/main/runtime/rpc/methods/orchestration/messaging/recipient-routing.ts
1 src/main/runtime/rpc/methods/orchestration/messaging/send-methods.ts
6 src/main/runtime/rpc/methods/orchestration/messaging/session-recipient.ts
1 src/main/runtime/rpc/methods/orchestration/messaging/settled-worker-follow-through.ts
1 src/main/runtime/rpc/methods/orchestration/runs/dispatch-creator.ts
3 src/main/runtime/rpc/methods/orchestration/runs/dispatch-creator.ts
1 src/main/runtime/rpc/methods/orchestration/worker/deliver-worker-dispatch-preamble.ts
1 src/main/runtime/rpc/methods/orchestration/worker/local-worker-start-dispatch.ts
1 src/main/runtime/rpc/methods/orchestration/worker/worker-configured-agent-preflight.ts
1 src/main/runtime/rpc/methods/orchestration/worker/worker-control.ts
1 src/main/runtime/rpc/methods/orchestration/worker/worker-earlier-work.ts
1 src/main/runtime/rpc/methods/orchestration/worker/worker-follow-up-placement.ts
1 src/main/runtime/rpc/methods/orchestration/worker/worker-start-validation.ts
1 src/main/runtime/rpc/orchestration-legacy-compatibility.ts
2 src/main/runtime/rpc/orchestration-legacy-coordinator-authority.ts
@@ -21,16 +21,14 @@ const CELL = /^(?:supported(?:: .+)?|refused `([a-z_]+)`: .+|n\/a: .+)$/
// Both catalog lists are generated from the registry: methods with shared params, then those without.
export function registeredMethods(catalogText) {
return new Set(
[...catalogText.matchAll(/^\s*'(orchestration\.[A-Za-z]+)'[:,\n]/gm)].map((m) => m[1])
)
return new Set([...catalogText.matchAll(/^\s*'(orchestration\.[^']+)'[:,\n]/gm)].map((m) => m[1]))
}
/** Each `## \`orchestration.x\`` section, as its `- <label>: <cell>` lines. */
export function declaredSections(markdown) {
const sections = []
for (const line of markdown.split('\n')) {
const method = /^## `(orchestration\.[A-Za-z]+)`$/.exec(line)?.[1]
const method = /^## `(orchestration\.[^`]+)`$/.exec(line)?.[1]
if (method) {
sections.push({ method, cells: [] })
continue
@@ -43,7 +41,7 @@ export function declaredSections(markdown) {
return sections
}
/** `codeExists` says whether a refusal code is a real string literal in the source. */
/** `codeExists` says whether Orca throws a refusal code. */
export function censusProblems(methods, sections, codeExists) {
const problems = []
const declared = new Set()
@@ -66,7 +64,7 @@ export function censusProblems(methods, sections, codeExists) {
`${method}: "${value}" is not supported, refused \`<code>\`: <reason>, or n/a: <reason>.`
)
} else if (match[1] && !codeExists(match[1])) {
problems.push(`${method}: refusal code ${match[1]} appears nowhere in src.`)
problems.push(`${method}: Orca never throws refusal code ${match[1]}.`)
}
}
}
@@ -78,12 +76,33 @@ export function censusProblems(methods, sections, codeExists) {
return problems
}
// Codes Orca throws: an OrchestrationError's code, an RPC errorResponse's code, or a shared orchestration code table.
const THROWN_CODE = [
/OrchestrationError\(\s*'([a-z_]+)'/g,
/errorResponse\(\s*[^,()]+,\s*[^,()]+,\s*'([a-z_]+)'/g
]
export function thrownRefusalCodes(sources) {
const codes = new Set()
for (const [rel, text] of sources) {
const patterns = /^src\/shared\/orchestration\/.+-codes\.ts$/.test(rel)
? [...THROWN_CODE, /:\s*'([a-z_]+)'/g]
: THROWN_CODE
for (const pattern of patterns) {
for (const match of text.matchAll(pattern)) {
codes.add(match[1])
}
}
}
return codes
}
export function main(root = process.cwd()) {
const read = (rel) => readFileSync(path.join(root, rel), 'utf8')
const sources = [
...readTrackedSources(root, ['src/main', 'src/shared'], (rel) => rel.endsWith('.ts')).values()
]
const codeExists = (code) => sources.some((text) => text.includes(`'${code}'`))
const codes = thrownRefusalCodes(
readTrackedSources(root, ['src/main', 'src/shared'], (rel) => /(?<!\.test)\.ts$/.test(rel))
)
const codeExists = (code) => codes.has(code)
const problems = censusProblems(
registeredMethods(read(CATALOG)),
declaredSections(read(DECLARATION)),
@@ -30,7 +30,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported: refused `session_caller_not_live` while the chat is released
- Terminal · Paired: refused `stable_pane_required`: the mailbox lives on the caller's own Orca
- Terminal · Paired: supported: only `--peek`, which reads the paired Orca's mailbox; a consuming check is refused `stable_pane_required`, since that mailbox can never receive this caller's mail
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -43,7 +43,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot find its Run
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -105,7 +105,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot find its Run
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -114,7 +114,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: reads the paired Orca's own records
- Terminal · Paired: supported: only with `--run`; without it the paired Orca refuses `stable_pane_required`, having no pane for this caller
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -123,7 +123,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot find its Run
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -180,7 +180,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot bind a Run to it
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -189,7 +189,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: reads the paired Orca's own records
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot find its Run
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -220,7 +220,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot bind a Run to it
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -242,7 +242,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot find its Run
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -251,7 +251,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: reads the paired Orca's own records
- Terminal · Paired: supported: only with `--run`; without it the paired Orca refuses `stable_pane_required`, having no pane for this caller
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -260,7 +260,7 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: runs on the paired Orca, which records a caller it cannot reach
- Terminal · Paired: refused `stable_pane_required`: the paired Orca has no pane for this caller, so it cannot find its Run
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL
@@ -335,8 +335,8 @@ Each line is `supported` (or `supported: <note>`), ``refused `<code>`: <reason>`
- Terminal · Local: supported
- Chat · Local: supported
- Terminal · Paired: supported: `--on` starts it from the caller's own Orca and reports come home
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca; `--on` starts it from the caller's own Orca
- Terminal · Paired: supported: runs on the paired Orca, which records a coordinator it cannot reach (`worker-start --on` is the route that brings reports home)
- Chat · Paired: refused `session_caller_host_boundary`: a session id names a caller only on its own Orca (`worker-start --on` is the route that brings reports home)
- Terminal · SSH/WSL: supported
- Chat · SSH/WSL: refused `session_caller_host_boundary`: chat agents do not run in SSH or WSL