Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions docs/runtimes/claude.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,13 @@ and reports `model_refused`. [Failures](#failures).

### Observation, children, and history

Claude Code 2.1.330 sent two completed `assistant` frames from a scripted
Task child. Both named the spawning call in `parent_tool_use_id` and the
same model in `message.model`. OAR emits the first observed model and any
change on that full child path. CLI-synthesized errors contribute no model.
The root still reads its selection from `system/init`. A 2.1.292 child that
reported Haiku is also covered by [recorded replay](../../tests/replay/fixtures/claude-usage-subagent-compact.projected.txt).

**Mapped:** every JSON frame enters the stream verbatim in `native` (of a
Frame, or of the response record for a control reply), except the effort
read-back answer the adapter consumes at open, so message identity, input
Expand Down Expand Up @@ -910,8 +917,8 @@ result carries the running total. [sym]
written, [replay](../../tests/replay/fixtures/claude-background-tasks.projected.txt)).
- `unattributed` is the rest: the subagents', sidechains' and compaction's
calls. A subagent gets no entry, because the stream does not say what it
spent: only its first `assistant` frame carries `parent_tool_use_id`, and
that frame's `message.usage` is the stream-start value (3 output tokens
spent. In the 2.1.292 usage recording only the first assistant frame
carried the parent call ID. Its `message.usage` is the stream-start value (3 output tokens
in the recording), not the request's final usage, which claude's schema
says "arrive[s] on the result message". [env 2.1.292]
- A result with a zeroed `modelUsage` (claude's crash and startup-error
Expand Down
9 changes: 9 additions & 0 deletions docs/runtimes/codex.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,15 @@ or translate these controls into text commands for other runtimes.

### Observation, children, and history

Codex 0.171.0 reported the resolved child model on the parent's
`subAgentActivity` creation item. Its completed item produces
`task_started.model`. In the scripted spawn, the child emitted
`turn/started` with no model and no child `thread/started` arrived. When
the latter notification does arrive, its `thread.id` scopes its optional
`model` and `reasoningEffort`; subsequent `thread/settings/updated` reports
the current selection. The root open reply already supplies root selection.
The collaboration tool's input model describes a request. [Codex creation item](https://github.com/openai/codex/blob/ccf9be8cc458bd6b8336fe84d68d8893f2691a5e/codex-rs/app-server-protocol/src/protocol/v2/item.rs#L484-L494)

**Mapped:** native thread read/list operations expose stored state, and
resume can return history; OAR exposes none of those and does not hydrate the
stream from the resume or fork result (`thread/fork` is mapped as
Expand Down
8 changes: 8 additions & 0 deletions docs/runtimes/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ a retry, so no `retry` event is read.

### Children

The child's version 3 `subagent/descriptor` can report `agentProvider`,
`agentModel` and `agentReasoningEffort` immediately. A measured child
reported `deepseek-official/deepseek-flash` and `high` at sequence 0.
Its `request/header` at sequence 12 confirmed both. OAR emits changes to
model and effort independently under that child session ID. The descriptor's
`provider: "spawn"` describes its origin. The parent catalog supplies the
relationship and carries no model.

`capabilities.attribution` is `nested`. Child session frames carry the child's own
`sessionId`; the parent's durable `subagent/catalog` names the child and is the
only lineage edge (`session_linked`, `via: "tool_call"`), which `graph()` holds.
Expand Down
6 changes: 6 additions & 0 deletions docs/runtimes/grok.md
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,12 @@ See [reader environments](../spec/orientation.md#environment).

## Native task control

In a scripted Grok 1.0.92 foreground spawn, the parent
`_x.ai/session_notification` carried `subagent_spawned.model` and
`child_session_id`. OAR exposes the selected model as `task_started.model`
on that parent frame. The child's text and usage frames in this run supplied
no separate model selection. [Native effective model at spawn](https://github.com/xai-org/grok-build/blob/2bdd1d6a6369de0e8c68132ea4539e9abd9e14a8/crates/codegen/xai-grok-shell/src/agent/subagent/handle_request.rs#L1049-L1063)

The parent's `_x.ai/session_notification` stream reports
`subagent_spawned` and `subagent_finished`; OAR maps these to `task_started`
(type agent) and `task_ended` (completed, failed or stopped), keyed by
Expand Down
9 changes: 9 additions & 0 deletions docs/runtimes/kimi.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ when the executable reports version `>= 2.7.2-botiverse.1` or `>= 2.7.3` and
`/api/v1/meta` advertises all required KAP capabilities, and falls back to
`kimi acp` on earlier builds or missing capabilities.

KAP reports a child's model on its subscribed WebSocket `type: "agent"`
metadata frame. Model changes use the child's path within the parent
session. The live 2.7.2 foreground task had distinct `task_id` and
`child_agent_id`, and its `parent_tool_call_id` matched the spawning tool
item. The child's subscribed `agent` frame reported the model `fixture`.
The child path ends in the spawning tool call ID. When KAP omits it and no
tool-item reference established the call, OAR uses the task ID. The child
agent ID selects the subscription. [Recorded KAP frames](../../experiments/kimi-kap-wire/wire-samples.jsonl)

## Independent skill discovery

`skills()` starts `kimi web --no-open --host 127.0.0.1 --port 0` with the
Expand Down
7 changes: 7 additions & 0 deletions docs/runtimes/opencode.md
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,13 @@ checks both runtime and descendant termination. See

### Observation, children, and history

OpenCode v2's `opencode/session/child_update` creation status identifies
the child and parent sessions, depth and optional title. The recorded
status and child text update supplied no selected model. A subsequent
model-bearing ACP update is attributed to the child session. [Recorded
child updates](../../experiments/opencode-child-background/enabled.json) ·
[2.3.2 child envelope](https://github.com/anomalyco/opencode/blob/c0ad18b402eb2827fc1ee71c171b1177b3fc02d1/packages/cli/src/acp/child.ts)

Text, reasoning (`agent_thought_chunk`), tool calls and `usage_update` arrive
as `session/update`. A tool call's opening `tool_call` carries its name as
`title` and no arguments: a shell call has `title` `bash`, `kind` `execute`
Expand Down
7 changes: 7 additions & 0 deletions docs/runtimes/qoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ installation fallbacks use the supplied home directory on each call. See

## Native task control

Qoder's published agent SDK 1.0.60 allows an optional `message.model` on
assistant frames with a `parent_tool_use_id`. The retained task capture
establishes the task lifecycle but does not establish a resolved model on a
child assistant frame. A 1.1.95 local fake-response run ended with a synthetic
error before the Task call started. OAR leaves the child selection unknown.
[SDK assistant schema](https://unpkg.com/@qoder-ai/qoder-agent-sdk@1.0.60/dist/protocol/messages.d.ts) · [Recorded task control](../../experiments/task-controls/evidence/qoder-1.1.83.json)

Qoder 1.1.83 emits `system/task_started`, `task_updated.patch`, changed
`task_progress.description`, and `task_notification`. OAR projects the three
existing task events, reads `local_agent` as agent and `killed` as stopped,
Expand Down
7 changes: 7 additions & 0 deletions docs/runtimes/qwen.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,13 @@ fallback from that map on each call; the model query uses it too. See

## Native task control

In 0.28.4 scripted foreground and background agent runs, the only frame
under the spawning call's path was a `user` frame. The root assistant
messages reported the configured model. Qwen's output adapter reads that
field from the process configuration even when formatting an assistant
message with a parent call ID. Child model selection remains unknown.
[Qwen output adapter](https://github.com/QwenLM/qwen-code/blob/e8424c88ddd463c56602063efde57c328b917cd4/packages/cli/src/nonInteractive/io/BaseJsonOutputAdapter.ts#L270-L285)

Qwen 0.26.8 emits structured task lifecycle in stream-json:
`system/task_started` and `system/task_notification`, with fields under
`data`. OAR maps `system/task_started` (with a nonempty string `data.task_id`)
Expand Down
29 changes: 26 additions & 3 deletions docs/spec/attribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ seq=91 ✓ frame path=["a1"] tool_call {id:"call_1", …}
([],"call_1"). See hard spot 1 in runtime-matrix.md
```

## Associating a task with its child model

A host can display the child's model as soon as the runtime identifies it.
Seed the task with `task_started.model` when the native start reports a
resolved child model. Otherwise the initial value is unknown. Apply each
attributed `model` event in record order to fill or replace that value.
The two forms of attribution use different joins:

- **Child session.** Match `event.sessionId === task.childSessionId` and
`event.agentPath.length === 0`. DSH's parent `subagent/catalog` identifies
the child session. Its model is on the child's `subagent/descriptor` and
subsequent `request/header` frames.
- **Same session.** Match the task's session ID and the exact path
`[...task.agentPath, task.toolCallId ?? task.taskId]`. The final segment
identifies the spawning call (or the task when the call ID is absent).
Comparing the prefix keeps sibling and nested calls in their own scope.

Keep observations keyed by session and path if a child frame arrives before
the task is linked. Missing fields leave the selection unknown until a source
reports it. Root selection comes from the root session's own empty path.
A tool's requested model, a parent default and a token ledger are separate
observations.

## The attribution spectrum: a protocol responsibility, not app-layer improvisation

If attribution is not in the protocol, every app reimplements parent
Expand All @@ -86,9 +109,9 @@ already show the degeneration (adapter red lines in
- claude: `parent_tool_use_id` (linkage) → `agentPath`; the session total
is `result.modelUsage` (every model call, subagents and compaction
included), the root's entry the main loop's `result.usage`, and the
subagents' spend unattributed: only a subagent's first `assistant` frame
carries `parent_tool_use_id`, its usage the stream-start value. [sym]
[env 2.1.292]
subagents' spend unattributed. In the 2.1.292 usage recording, its first
child assistant frame carried the stream-start usage. In 2.1.330 multiple
assistant blocks carried the same spawning call ID and model. [env]
- codex: child threads → derived child sessions, with per-thread usage.
[env]
- grok (ACP): nested sessions; child has its own sessionId + per-child
Expand Down
8 changes: 7 additions & 1 deletion docs/spec/record-stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ interface FrameBody {
// compaction_started {compactionId?, trigger?} |
// compaction_ended {outcome: completed | aborted | failed, compactionId?, requestId?, trigger?, reason?} |
// retry {attempt, maxAttempts?, delayMs?, reason?} |
// task_started {taskId, taskType, nativeType?, description?, toolCallId?, childSessionId?, background?, ambient?} |
// task_started {taskId, taskType, nativeType?, description?, toolCallId?, childSessionId?, model?, background?, ambient?} |
// task_updated {taskId, status?, background?, description?, error?} | // status: pending | running | paused | completed | failed | stopped
// task_ended {taskId, status: completed | failed | stopped, summary?, output?, outputFile?}
// TurnOutcome: {kind: completed, structuredOutput?: unknown} | {kind: aborted} | FailedTurn, tagged by `failure`:
Expand Down Expand Up @@ -1234,6 +1234,12 @@ Which runtimes say which kinds (runtime pages hold the evidence):
`llm_retry` with its native attempt and reason, and Kimi KAP projects
`turn.updated` `retry` frames. The community Morph
adapter reads its own retry notice.
- `task_started.model?: string` is the resolved child model on the native
start frame (Codex or Grok). This is a creation-time observation. Later
child-scoped `model` events update the host's selection. Both replay and
live delivery preserve the parent's envelope on the task start and the
child's envelope on its model reports. See [child model attribution](attribution.md#associating-a-task-with-its-child-model).

- `task_started` / `task_updated` / `task_ended`: work the runtime tracks
beside the turn that started it. claude `system/task_started`,
`task_updated` (its `patch`) and `task_notification` [env 2.1.284]:
Expand Down
2 changes: 2 additions & 0 deletions packages/oar/src/contracts/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export type TaskEventBody =
readonly description?: string;
readonly toolCallId?: string;
readonly childSessionId?: string;
/** Resolved child model reported by the native task start. Later child model events supersede it. */
readonly model?: string;
/** True when the task runs without holding the call that started it. */
readonly background?: boolean;
readonly ambient?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/oar/src/observe/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface TaskView {
readonly ambient?: boolean;
readonly toolCallId?: string;
readonly childSessionId?: string;
/** Initial selection reported by the native task start. */
readonly model?: string;
readonly summary?: string;
readonly output?: string;
readonly outputFile?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/oar/src/runtimes/claude/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function assistantAnchor(previous: string | null, message: JsonRecord): string |

export const claudeProjectionProfile: StreamJsonProjectionProfile<ClaudeProjectionState> = {
name: "claude",
childAssistantModel: true,
compactingStatus: true,
duplicateReason: "claude ignored the input: its inputId was already used in this session",
isAssistantError: claudeSyntheticAssistant,
Expand Down
35 changes: 18 additions & 17 deletions packages/oar/src/runtimes/codex/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,14 @@ function toolViews(method: string, item: JsonRecord | null): RuntimeEventBody[]
return [codexToolEnd(item, itemId)];
}

/**
* `thread/settings/updated` is codex's own report of the thread's settings
* after a change ([env] 0.155.1: pushed when a turn/start carries an `effort`
* or `model` override, "for this turn and subsequent turns"):
* `threadSettings.model` and `threadSettings.effort` (null: no explicit
* level) are the model and effort now in effect.
*/
function settingsViews(params: JsonRecord): RuntimeEventBody[] {
const settings = asRecord(params.threadSettings);
const events: RuntimeEventBody[] = [...codexServiceTierEvents(settings)];
if (typeof settings?.model === "string" && settings.model.length > 0) {
events.push({ kind: "model", model: settings.model });
/** Effective selection from thread/started or thread/settings/updated. A null effort means the model default. */
function modelAndEffort(model: unknown, effort: unknown): RuntimeEventBody[] {
const events: RuntimeEventBody[] = [];
if (typeof model === "string" && model.length > 0) {
events.push({ kind: "model", model });
}
if (typeof settings?.effort === "string" && settings.effort.length > 0) {
events.push({ kind: "effort", effort: settings.effort });
if (typeof effort === "string" && effort.length > 0) {
events.push({ kind: "effort", effort });
}
return events;
}
Expand Down Expand Up @@ -194,6 +187,11 @@ function viewsFor(state: CodexProjectionState, reporter: string, method: string,
if (typeof params.threadId !== "string" || params.threadId.length === 0 || typeof params.name !== "string" || params.name.length === 0) { return []; }
return codexMcpStartup(params.name, params.status);
}
case "thread/started": {
const thread = asRecord(params.thread);
if (reporter === state.rootThreadId || thread?.id !== reporter) { return []; }
return modelAndEffort(thread.model, thread.reasoningEffort);
}
case "thread/goal/updated":
case "thread/goal/cleared":
return codexGoalEvents(method, params);
Expand Down Expand Up @@ -243,8 +241,10 @@ function viewsFor(state: CodexProjectionState, reporter: string, method: string,
}
case "thread/tokenUsage/updated":
return codexUsageViews(params, reporter === state.rootThreadId ? baselineTokens(state.tokenBaseline) : noTokens);
case "thread/settings/updated":
return settingsViews(params);
case "thread/settings/updated": {
const settings = asRecord(params.threadSettings);
return [...codexServiceTierEvents(settings), ...modelAndEffort(settings?.model, settings?.effort)];
}
default:
return [];
}
Expand All @@ -256,7 +256,8 @@ export function foldCodexNotification(
method: string,
params: JsonRecord,
): { readonly state: CodexProjectionState; readonly commands: readonly ProjectionCommand[] } {
const threadId = typeof params.threadId === "string" ? params.threadId : previous.rootThreadId;
const reported = method === "thread/started" ? (asRecord(params.thread)?.id ?? params.threadId) : params.threadId;
const threadId = typeof reported === "string" && reported.length > 0 ? reported : previous.rootThreadId;
// Before the views: a re-reported total is read against itself (zero).
const tokenBaseline = threadId === previous.rootThreadId ? nextTokenBaseline(previous.tokenBaseline, method, params) : previous.tokenBaseline;
const input = threadId === previous.rootThreadId ? foldCodexInputs(previous.inputs, method, params) : { inputs: previous.inputs, events: [] };
Expand Down
1 change: 1 addition & 0 deletions packages/oar/src/runtimes/codex/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function codexTaskViews(item: JsonRecord): TaskEventBody[] {
nativeType: "subAgent",
childSessionId: taskId,
background: true,
...(typeof item.model === "string" && item.model.length > 0 ? { model: item.model } : {}),
...(typeof item.agentPath === "string" ? { description: item.agentPath } : {}),
...(typeof item.id === "string" ? { toolCallId: item.id } : {}),
}];
Expand Down
Loading
Loading