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
615 changes: 483 additions & 132 deletions apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const mcpRules = (name: string) => [
{ action: "t3-code-*", resource: "*", effect: "deny" },
{ action: `t3-code-thread_${name}_*`, resource: "*", effect: "allow" },
];
const FULL_ACCESS = [{ action: "*", resource: "*", effect: "allow" }];
const FULL_ACCESS = [
{ action: "*", resource: "*", effect: "allow" },
{ action: "browser", resource: "*", effect: "deny" },
{ action: "skill", resource: "browser", effect: "deny" },
];

const t3Rules = (name: string) => [...FULL_ACCESS, ...mcpRules(name)];

Expand Down Expand Up @@ -113,12 +117,13 @@ const autoEditRules = (name: string) => [
{ action: "shell", resource: "*", effect: "ask" },
{ action: "edit", resource: "*", effect: "allow" },
{ action: "external_directory", resource: "*", effect: "ask" },
...FULL_ACCESS.slice(1),
...BUILD_PATHS,
...mcpRules(name),
];

const planRules = (name: string) => [
{ action: "*", resource: "*", effect: "allow" },
...FULL_ACCESS,
{ action: "edit", resource: "*", effect: "deny" },
...PLAN_PATHS,
...mcpRules(name),
Expand Down Expand Up @@ -752,8 +757,9 @@ describe("OpenCode 2 through the orchestrator", () => {
"settles a background subagent whose end was lost with the stream, and takes the next turn",
() =>
Effect.gen(function* () {
const name = "opencode2-background-lost";
const { result, projection } = yield* backgroundReconnect({
name: "opencode2-background-lost",
name,

cut: "session.step.started.3",
reconnect: (parent) => [
Expand Down Expand Up @@ -789,6 +795,13 @@ describe("OpenCode 2 through the orchestrator", () => {
],
cursor: {},
}),
out("session.get", { sessionID: parent }),
reply("session.get", {
data: {
...sessionInfo("<work>", t3Rules(name), name).data,
id: parent,
},
}),
out("session.prompt", { sessionID: parent, id: "<any>", text: "<any>" }),
reply("session.prompt", {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{"type": "emit_inbound", "label": "message.list.synthetic.response", "frame": {"type": "sdk.response", "operation": "message.list", "data": {"data": [], "cursor": {}}}}
{"type": "expect_outbound", "label": "session.fork", "frame": {"type": "session.fork", "input": {"sessionID": "ses_f1484ea8affe5aTo8CcgbGIszj", "before": "msg_0eb7b1f9f001g95Bduh3bi8syS"}}}
{"type": "emit_inbound", "label": "session.fork.response", "frame": {"type": "sdk.response", "operation": "session.fork", "data": {"data": {"id": "ses_f1484db83ffeLGtrRCFimo1H0e", "fork": {"sessionID": "ses_f1484ea8affe5aTo8CcgbGIszj", "boundary": {"type": "before", "messageID": "msg_0eb7b1f9f001g95Bduh3bi8syS"}}, "projectID": "global", "model": {"id": "big-pickle", "providerID": "opencode", "variant": "default"}, "cost": 0, "tokens": {"input": 0, "output": 0, "reasoning": 0, "cache": {"read": 0, "write": 0}}, "time": {"created": 1790657111165, "updated": 1790657111165}, "title": "spike fork (fork #1)", "location": {"directory": "<work>"}, "permissions": [{"action": "*", "resource": "*", "effect": "allow"}, {"action": "subagent", "resource": "*", "effect": "deny"}]}}}}
{"type": "expect_outbound", "label": "session.update", "frame": {"type": "session.update", "input": {"sessionID": "ses_f1484db83ffeLGtrRCFimo1H0e", "permissions": [{"action": "*", "resource": "*", "effect": "allow"}, {"action": "t3-code-*", "resource": "*", "effect": "deny"}, {"action": "t3-code-thread_opencode2-fork_target_*", "resource": "*", "effect": "allow"}]}}}
{"type": "expect_outbound", "label": "session.update", "frame": {"type": "session.update", "input": {"sessionID": "ses_f1484db83ffeLGtrRCFimo1H0e", "permissions": [{"action": "*", "resource": "*", "effect": "allow"}, {"action": "browser", "resource": "*", "effect": "deny"}, {"action": "skill", "resource": "browser", "effect": "deny"}, {"action": "t3-code-*", "resource": "*", "effect": "deny"}, {"action": "t3-code-thread_opencode2-fork_target_*", "resource": "*", "effect": "allow"}]}}}
{"type": "emit_inbound", "label": "session.update.response", "frame": {"type": "sdk.response", "operation": "session.update", "data": null}}
{"type": "emit_inbound", "label": "session.forked", "frame": {"type": "sdk.event", "event": {"id": "evt_0eb7b247d001fXzFroPg5P0bps", "created": 1790657111165, "type": "session.forked", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f1484db83ffeLGtrRCFimo1H0e", "parentID": "ses_f1484ea8affe5aTo8CcgbGIszj", "boundary": {"type": "before", "messageID": "msg_0eb7b1f9f001g95Bduh3bi8syS"}, "instructions": {"core/environment": "db4a793a05fec32fdfa985a3432125a86d6cb42debc8b9ee8f6a99fbfcf2f93b", "core/date": "bf08b8486572ab3eef677a3c9ee12468e411ae41a8f4d2fb6cf02a6ca73f1986", "core/codemode": "616a7ad8b8e40e8a71eab238dfbbe9eaf0f4a9e6fdad853226d075bfe602e1e6", "core/skill-guidance": "0d001919496102654717308c72635523bf7c3cd99c81e058cc79f2947104f9a5"}, "instructionEntries": []}, "durable": {"aggregateID": "ses_f1484db83ffeLGtrRCFimo1H0e", "seq": 0, "version": 2}}}}
{"type": "expect_outbound", "label": "session.update.title", "frame": {"type": "session.update", "input": {"sessionID": "ses_f1484db83ffeLGtrRCFimo1H0e", "title": "<any>"}}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"type": "transcript_start", "provider": "opencode", "protocol": "opencode2-http.sse", "version": "2.0.18", "scenario": "opencode2_nested_background", "metadata": {"source": "OpenCode 2.0.18 live run, openrouter/deepseek/deepseek-v4-flash, experimental.subagent_depth 2", "capturedAt": "2026-10-01", "nativeSessionId": "ses_f08c08821ffefFAD3sMjkyP0Fd", "description": "A real OpenCode 2.0.18 session recorded at the HTTP and SSE boundary: a foreground subagent launches its own background subagent and returns at once, so the thread's turn ends while that grandchild still runs. When the grandchild ends, OpenCode reports it to the foreground subagent's session and wakes that session to answer the report. Nesting needs experimental.subagent_depth 2. T3's per-turn instructions entry (answered 204, as 2.0.18 does) is written before the thread's first turn."}}
{"type": "transcript_start", "provider": "opencode", "protocol": "opencode2-http.sse", "version": "2.0.18", "scenario": "opencode2_nested_background", "metadata": {"source": "OpenCode 2.0.18 live run, openrouter/deepseek/deepseek-v4-flash, experimental.subagent_depth 2", "capturedAt": "2026-10-01", "nativeSessionId": "ses_f08c08821ffefFAD3sMjkyP0Fd", "description": "A real OpenCode 2.0.18 session recorded at the HTTP and SSE boundary: a foreground subagent launches its own background subagent and returns at once, so the thread's turn ends while that grandchild still runs. When the grandchild ends, OpenCode reports it to the foreground subagent's session and wakes that session to answer the report. Nesting needs experimental.subagent_depth 2. T3's per-turn instructions entry (answered 204, as 2.0.18 does) is written before the thread's first turn. Child sessions that inherit full access are denied the browser before they run; those session.update exchanges are replay expectations, not captured native traffic."}}
{"type": "expect_outbound", "label": "event.subscribe", "frame": {"type": "event.subscribe"}}
{"type": "expect_outbound", "label": "model.list", "frame": {"type": "model.list", "input": {"location[directory]": "<any>"}}}
{"type": "emit_inbound", "label": "model.list.response", "frame": {"type": "sdk.response", "operation": "model.list", "data": {"location": {"directory": "<work>"}, "data": [{"id": "deepseek/deepseek-v4-flash", "modelID": "deepseek/deepseek-v4-flash", "providerID": "openrouter", "family": "deepseek-flash", "name": "DeepSeek V4 Flash", "compatibility": {"reasoningField": "reasoning_content"}, "package": "@opencode/ai/providers/openrouter", "settings": {"baseURL": "https://openrouter.ai/api/v1"}, "headers": {"HTTP-Referer": "https://opencode.ai/", "X-Title": "opencode"}, "capabilities": {"tools": true, "input": ["text"], "output": ["text"]}, "variants": [{"id": "none", "settings": {"reasoning": {"enabled": false}}}, {"id": "high", "settings": {"reasoning": {"effort": "high"}}}, {"id": "xhigh", "settings": {"reasoning": {"effort": "xhigh"}}}], "time": {"released": 1776988800000}, "cost": [{"input": 0.04186, "output": 0.08372, "cache": {"read": 0.008372, "write": 0}}], "status": "active", "enabled": true, "limit": {"context": 1048576, "output": 131072}}]}}}
Expand Down Expand Up @@ -37,6 +37,8 @@
{"type": "emit_inbound", "label": "session.tool.called", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f91d2001Z0SmwHjjebCK4a", "created": 1790854533586, "type": "session.tool.called", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c08821ffefFAD3sMjkyP0Fd", "assistantMessageID": "msg_0f73f7b54001L2fnmF6VSokmbn", "id": "call_3d90a8b7d44c49f6ae053fd7", "input": {"agent": "general", "description": "Chain subagents with background", "prompt": "Use the subagent tool with background set to true to delegate to the general subagent with the prompt: Run the shell command `sleep 25` with the shell tool, then reply exactly GRANDCHILD_OK. As soon as it is launched, reply exactly MIDDLE_OK and end your turn without waiting for it."}, "executed": false}, "durable": {"aggregateID": "ses_f08c08821ffefFAD3sMjkyP0Fd", "seq": 10, "version": 1}}}}
{"type": "emit_inbound", "label": "session.step.streamed", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f91d5001vrzflyt1WQFGva", "created": 1790854533589, "type": "session.step.streamed", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c08821ffefFAD3sMjkyP0Fd", "assistantMessageID": "msg_0f73f7b54001L2fnmF6VSokmbn"}, "durable": {"aggregateID": "ses_f08c08821ffefFAD3sMjkyP0Fd", "seq": 11, "version": 1}}}}
{"type": "emit_inbound", "label": "session.created.2", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f91dd001BBDOI1lGk77sTL", "created": 1790854533597, "type": "session.created", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "slug": "kind-forest", "version": "2.0.18", "projectID": "3b9597874c088ee0849b0d68c211296e47876139", "parentID": "ses_f08c08821ffefFAD3sMjkyP0Fd", "location": {"directory": "<work>"}, "subpath": "", "title": "Chain subagents with background", "agent": "general", "permissions": [{"action": "*", "resource": "*", "effect": "allow"}], "model": {"id": "deepseek/deepseek-v4-flash", "providerID": "openrouter", "variant": "default"}}, "durable": {"aggregateID": "ses_f08c06e25ffeF0asx24ydmo3oy", "seq": 0, "version": 1}}}}
{"type": "expect_outbound", "label": "session.update.dmo3oy", "frame": {"type": "session.update", "input": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "permissions": [{"action": "*", "resource": "*", "effect": "allow"}, {"action": "browser", "resource": "*", "effect": "deny"}, {"action": "skill", "resource": "browser", "effect": "deny"}]}}}
{"type": "emit_inbound", "label": "session.update.dmo3oy.response", "frame": {"type": "sdk.response", "operation": "session.update", "data": null}}
{"type": "emit_inbound", "label": "session.tool.progress", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f91e00015k1c4ULxR6t2Sb", "created": 1790854533600, "type": "session.tool.progress", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c08821ffefFAD3sMjkyP0Fd", "assistantMessageID": "msg_0f73f7b54001L2fnmF6VSokmbn", "id": "call_3d90a8b7d44c49f6ae053fd7", "metadata": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "status": "running"}}}}}
{"type": "emit_inbound", "label": "session.inbox.enqueued.2", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f91e200143nPcVfCFMVD3q", "created": 1790854533602, "type": "session.inbox.enqueued", "location": {"directory": "<work>"}, "data": {"inboxID": "msg_0f73f91e0002lgRNb7FtMzcoQu", "sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "item": {"type": "user", "payload": {"text": "You are a subagent spawned by another session.\nUse the subagent tool with background set to true to delegate to the general subagent with the prompt: Run the shell command `sleep 25` with the shell tool, then reply exactly GRANDCHILD_OK. As soon as it is launched, reply exactly MIDDLE_OK and end your turn without waiting for it."}, "delivery": "steer"}}, "durable": {"aggregateID": "ses_f08c06e25ffeF0asx24ydmo3oy", "seq": 1, "version": 1}}}}
{"type": "emit_inbound", "label": "session.execution.started.2", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f91e4001B2I7Jd3RFqZj5q", "created": 1790854533604, "type": "session.execution.started", "data": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy"}, "durable": {"aggregateID": "ses_f08c06e25ffeF0asx24ydmo3oy", "seq": 2, "version": 1}}}}
Expand All @@ -54,6 +56,8 @@
{"type": "emit_inbound", "label": "session.tool.called.2", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f9a9c001cLUHqUYgc8Zqn2", "created": 1790854535836, "type": "session.tool.called", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "assistantMessageID": "msg_0f73f91f80010gHxZ9GpYK99C8", "id": "call_8272fb6a288c4f94869b6ce6", "input": {"agent": "general", "description": "Run sleep 25 and reply GRANDCHILD_OK", "prompt": "Run the shell command `sleep 25` with the shell tool, then reply exactly GRANDCHILD_OK.", "background": true}, "executed": false}, "durable": {"aggregateID": "ses_f08c06e25ffeF0asx24ydmo3oy", "seq": 10, "version": 1}}}}
{"type": "emit_inbound", "label": "session.step.streamed.2", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f9a9e0010vdKL0cnaLnGmC", "created": 1790854535838, "type": "session.step.streamed", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "assistantMessageID": "msg_0f73f91f80010gHxZ9GpYK99C8"}, "durable": {"aggregateID": "ses_f08c06e25ffeF0asx24ydmo3oy", "seq": 11, "version": 1}}}}
{"type": "emit_inbound", "label": "session.created.3", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f9aa50016B9Hd1m1bEAc0t", "created": 1790854535845, "type": "session.created", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c0655dffeXJa3hcJz6wum9I", "slug": "glowing-engine", "version": "2.0.18", "projectID": "3b9597874c088ee0849b0d68c211296e47876139", "parentID": "ses_f08c06e25ffeF0asx24ydmo3oy", "location": {"directory": "<work>"}, "subpath": "", "title": "Run sleep 25 and reply GRANDCHILD_OK", "agent": "general", "permissions": [{"action": "*", "resource": "*", "effect": "allow"}], "model": {"id": "deepseek/deepseek-v4-flash", "providerID": "openrouter", "variant": "default"}}, "durable": {"aggregateID": "ses_f08c0655dffeXJa3hcJz6wum9I", "seq": 0, "version": 1}}}}
{"type": "expect_outbound", "label": "session.update.6wum9I", "frame": {"type": "session.update", "input": {"sessionID": "ses_f08c0655dffeXJa3hcJz6wum9I", "permissions": [{"action": "*", "resource": "*", "effect": "allow"}, {"action": "browser", "resource": "*", "effect": "deny"}, {"action": "skill", "resource": "browser", "effect": "deny"}]}}}
{"type": "emit_inbound", "label": "session.update.6wum9I.response", "frame": {"type": "sdk.response", "operation": "session.update", "data": null}}
{"type": "emit_inbound", "label": "session.tool.progress.2", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f9aa8001oExBPMb8eSiZZZ", "created": 1790854535848, "type": "session.tool.progress", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "assistantMessageID": "msg_0f73f91f80010gHxZ9GpYK99C8", "id": "call_8272fb6a288c4f94869b6ce6", "metadata": {"sessionID": "ses_f08c0655dffeXJa3hcJz6wum9I", "status": "running"}}}}}
{"type": "emit_inbound", "label": "session.inbox.enqueued.3", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f9aa90011WInpdfGI7KKg2", "created": 1790854535849, "type": "session.inbox.enqueued", "location": {"directory": "<work>"}, "data": {"inboxID": "msg_0f73f9aa8002Ljjv27sm66EBoB", "sessionID": "ses_f08c0655dffeXJa3hcJz6wum9I", "item": {"type": "user", "payload": {"text": "You are a subagent spawned by another session.\nRun the shell command `sleep 25` with the shell tool, then reply exactly GRANDCHILD_OK."}, "delivery": "steer"}}, "durable": {"aggregateID": "ses_f08c0655dffeXJa3hcJz6wum9I", "seq": 1, "version": 1}}}}
{"type": "emit_inbound", "label": "session.tool.success", "frame": {"type": "sdk.event", "event": {"id": "evt_0f73f9aad0012MAYhIH05xebgp", "created": 1790854535853, "type": "session.tool.success", "location": {"directory": "<work>"}, "data": {"sessionID": "ses_f08c06e25ffeF0asx24ydmo3oy", "assistantMessageID": "msg_0f73f91f80010gHxZ9GpYK99C8", "id": "call_8272fb6a288c4f94869b6ce6", "content": [{"type": "text", "text": "The subagent is working in the background (sessionID: ses_f08c0655dffeXJa3hcJz6wum9I). You will be notified automatically when it finishes.\nDO NOT sleep, poll for progress, ask the subagent for status, or duplicate this subagent's work; avoid working with the same files or topics it is using.\nWork on non-overlapping tasks, or briefly tell the user what you launched and end your response."}], "metadata": {"sessionID": "ses_f08c0655dffeXJa3hcJz6wum9I", "status": "running", "truncated": false}, "executed": false}, "durable": {"aggregateID": "ses_f08c06e25ffeF0asx24ydmo3oy", "seq": 12, "version": 2}}}}
Expand Down
Loading
Loading