Skip to content

Commit 7303dec

Browse files
mikeparcewskiclaude
andcommitted
fix(acp): the opencode seat denies the task tool; a tool call the seat itself refused reaches the transcript (F-W1-002, BC-75 proposed) [fixall L4]
opencode 1.17.18's ACP layer forwards a `permission.asked` only for sessions it opened itself (`acp/permission.ts` process() → tryGet(sessionID) → return when absent; the session store holds only session/new|load|resume|fork). A `task` (explore) subagent's asks — six external_directory reads in the wave-1 P6 chat — never reached wicked-core and were never rejected either, so the seat sat on a 600 s dead turn until the budget killed it. Upstream: anomalyco/opencode#48232 (fix PRs #48326 / #37902 open). One token in the one mechanism that already governs the seat: OPENCODE_CONFIG_CONTENT `permission` gains `"task":"deny"` (wicked-council registry) — the subagent is never spawned under ACP; the root session's own asks are answered exactly as before. So the refusal is visible, handle_update records a tool_call / tool_call_update that ends `status: failed` as `[tool call failed] <title>: <the seat's text>` in the transcript (bounded like a chunk — `push_bounded` factored out of the chunk arm; `locations` still collected). Tests: the registry pin (task = deny, read/edit/bash still ask, parsed as JSON); a scripted ACP agent (`task_denied`) whose refused call must reach the transcript while the turn still completes. Register: BC-75 — proposed, user decision owed (a seat-visible tool denial). Hand-authored under the disclosed exception. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent b55e1f4 commit 7303dec

3 files changed

Lines changed: 145 additions & 15 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,21 @@ Two release tracks share this file, newest entry first regardless of track:
14581458
on the raw text first; cap 4096 kept, not #466's 400 B). A `clis.toml` override that omits
14591459
`[cli.acp]` over a built-in that carries one now warns on stderr (the seat runs wrapped and
14601460
ungoverned; the wholesale-replace rule is unchanged).
1461+
<!-- fixall L4 -->
1462+
- **The opencode seat's harness config denies the `task` tool; a tool call the seat itself refused
1463+
is recorded in the unit transcript (F-W1-002; FIX-IT-ALL L4; BC-75 — proposed, user decision
1464+
owed).** opencode 1.17.18's ACP layer forwards a `permission.asked` only for sessions it opened
1465+
itself (`acp/permission.ts` `process()` → `tryGet(sessionID)` → return when absent; the session
1466+
store holds only `session/new|load|resume|fork`): a `task` (explore) subagent's asks — six
1467+
`external_directory` reads in the wave-1 P6 chat — never reached wicked-core and were never
1468+
rejected either, so the seat sat on a 600 s dead turn until the budget killed it (upstream
1469+
anomalyco/opencode#48232; fix PRs #48326 / #37902 open). One token in the one mechanism that
1470+
already governs the seat: `OPENCODE_CONFIG_CONTENT` `permission` gains `"task":"deny"`
1471+
(`wicked-council` registry) — the subagent is never spawned under ACP; the root session's own
1472+
asks are answered exactly as before. And so the refusal is visible: `handle_update` records a
1473+
`tool_call` / `tool_call_update` that ends `status: failed` as `[tool call failed] <title>: <the
1474+
seat's text>` in the transcript (bounded like a chunk; `locations` still collected). Behaviour
1475+
change register: **BC-75** (proposed — user decision owed: a seat-visible tool denial).
14611476
- **core-ts 0.7.26** — 2026-09-14 — npm release carrying the eleven engine changes since 0.7.25
14621477
(FIX-IT-ALL wave 1: L4 ①–⑦, L5 1.8, L10-5/-8/-9), all on main tip cad267e (plus #491, the 0.7.25
14631478
platform-lockfile re-stamp). **Behaviour changes, in one place:** **#506** (⑦) — **the

‎crates/wicked-council/src/registry.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,17 @@ pub fn builtin() -> Vec<AgenticCli> {
411411
// with no lockfile.
412412
acp_input_governance: true,
413413
os_sandbox: false,
414+
// `"task":"deny"` (F-W1-002 / BC-75): opencode 1.17.18's ACP layer forwards a
415+
// `permission.asked` only for sessions it opened itself (`acp/permission.ts`
416+
// `process()` → `tryGet(sessionID)` → return when absent; the session store holds
417+
// only `session/new|load|resume|fork`). A `task` subagent's session is never in
418+
// that store, so its asks reach neither the client nor a reject — the seat sits on
419+
// a dead turn until the budget kills it (upstream anomalyco/opencode#48232). The
420+
// seat's own config denies the tool, so no subagent spawns under ACP; the root
421+
// session's asks are answered exactly as before.
414422
acp_governance_env: Some((
415423
"OPENCODE_CONFIG_CONTENT".into(),
416-
r#"{"$schema":"https://opencode.ai/config.json","permission":{"read":"ask","edit":"ask","bash":"ask"}}"#.into(),
424+
r#"{"$schema":"https://opencode.ai/config.json","permission":{"read":"ask","edit":"ask","bash":"ask","task":"deny"}}"#.into(),
417425
)),
418426
verified_version: Some("1.17.18".into()),
419427
}),
@@ -636,6 +644,15 @@ mod tests {
636644
.expect("admitted opencode must carry its forcing-function env var");
637645
assert_eq!(env_key, "OPENCODE_CONFIG_CONTENT");
638646
assert!(env_val.contains("\"read\":\"ask\""));
647+
// F-W1-002 / BC-75: the seat's own harness denies `task` — a subagent session's asks never
648+
// reach an ACP client (anomalyco/opencode#48232), so the subagent must never spawn under
649+
// ACP. The three governed tools still ASK.
650+
let doc: serde_json::Value =
651+
serde_json::from_str(env_val).expect("governance content is a JSON object");
652+
assert_eq!(doc["permission"]["task"], "deny", "{env_val}");
653+
for tool in ["read", "edit", "bash"] {
654+
assert_eq!(doc["permission"][tool], "ask", "{tool}: {env_val}");
655+
}
639656
assert!(env_val.contains("\"edit\":\"ask\""));
640657
assert!(env_val.contains("\"bash\":\"ask\""));
641658
assert_eq!(

‎src/acp_runner.rs‎

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,19 +4248,7 @@ fn handle_update(
42484248
"agent_message_chunk" => {
42494249
if let Some(text) = update["content"]["text"].as_str() {
42504250
emit(text);
4251-
let used = output.len();
4252-
if used < max_out {
4253-
// Clamp to remaining capacity at a valid UTF-8 boundary so
4254-
// a single large chunk never pushes output past max_out.
4255-
let remaining = max_out - used;
4256-
let safe = text
4257-
.char_indices()
4258-
.take_while(|(i, c)| *i + c.len_utf8() <= remaining)
4259-
.last()
4260-
.map(|(i, c)| i + c.len_utf8())
4261-
.unwrap_or(0);
4262-
output.push_str(&text[..safe]);
4263-
}
4251+
push_bounded(output, text, max_out);
42644252
}
42654253
}
42664254
"usage_update" => {
@@ -4308,7 +4296,7 @@ fn handle_update(
43084296
});
43094297
}
43104298
}
4311-
"tool_call_update" => {
4299+
"tool_call" | "tool_call_update" => {
43124300
// Collect file paths reported by the CLI (e.g. read/edit locations).
43134301
if let Some(locs) = update["locations"].as_array() {
43144302
for loc in locs {
@@ -4317,11 +4305,55 @@ fn handle_update(
43174305
}
43184306
}
43194307
}
4308+
// F-W1-002 / BC-75: a tool call the SEAT ITSELF refused — opencode's config
4309+
// `permission.task: deny` (registry.rs), so the subagent never spawns under ACP — ends
4310+
// `failed`. That outcome used to leave no trace: the transcript carried whatever the
4311+
// model said next, or nothing. Record it, bounded like a chunk, so the denial is
4312+
// observable in the unit transcript: the call's title and the seat's own text, never
4313+
// the raw input.
4314+
if update["status"].as_str() == Some("failed") {
4315+
let title = update["title"].as_str().unwrap_or("tool call");
4316+
let note = match failed_tool_call_text(update) {
4317+
Some(text) => format!("\n[tool call failed] {title}: {text}\n"),
4318+
None => format!("\n[tool call failed] {title}\n"),
4319+
};
4320+
push_bounded(output, &note, max_out);
4321+
}
43204322
}
43214323
_ => {}
43224324
}
43234325
}
43244326

4327+
/// Append `text` to `output`, clamped to `max_out` at a valid UTF-8 boundary so a single large
4328+
/// chunk never pushes the transcript past its cap.
4329+
fn push_bounded(output: &mut String, text: &str, max_out: usize) {
4330+
let used = output.len();
4331+
if used >= max_out {
4332+
return;
4333+
}
4334+
let remaining = max_out - used;
4335+
let safe = text
4336+
.char_indices()
4337+
.take_while(|(i, c)| *i + c.len_utf8() <= remaining)
4338+
.last()
4339+
.map(|(i, c)| i + c.len_utf8())
4340+
.unwrap_or(0);
4341+
output.push_str(&text[..safe]);
4342+
}
4343+
4344+
/// The first text the agent attached to a failed tool call — `content[].content.text` per the
4345+
/// ACP schema (a bare `content[].text` is tolerated): the seat's own words for the refusal.
4346+
fn failed_tool_call_text(update: &Value) -> Option<String> {
4347+
update["content"].as_array()?.iter().find_map(|item| {
4348+
item["content"]["text"]
4349+
.as_str()
4350+
.or_else(|| item["text"].as_str())
4351+
.map(str::trim)
4352+
.filter(|t| !t.is_empty())
4353+
.map(str::to_string)
4354+
})
4355+
}
4356+
43254357
/// Parse the authoritative usage object from a `session/prompt` RESULT. All ecosystem
43264358
/// adapters report here (camelCase): official claude/codex, pi-acp, native opencode.
43274359
/// Input counts cached reads/writes alongside fresh input, mirroring the historical
@@ -15455,6 +15487,31 @@ elif behavior == "unknown_request":
1545515487
"stopReason": "end_turn", "usage": {"inputTokens": 1, "outputTokens": 1}
1545615488
}})
1545715489

15490+
elif behavior == "task_denied":
15491+
# F-W1-002 / BC-75: the seat's OWN harness refused a tool (opencode `permission.task: deny`):
15492+
# the call is announced, then ends `failed` with the seat's text. No permission request ever
15493+
# reaches the client — the refusal must still be visible in the transcript.
15494+
w({"jsonrpc": "2.0", "method": "session/update", "params": {
15495+
"sessionId": "mock-session",
15496+
"update": {"sessionUpdate": "tool_call", "toolCallId": "call-task-1", "title": "task",
15497+
"kind": "other", "status": "pending", "rawInput": {"description": "explore"}}
15498+
}})
15499+
w({"jsonrpc": "2.0", "method": "session/update", "params": {
15500+
"sessionId": "mock-session",
15501+
"update": {"sessionUpdate": "tool_call_update", "toolCallId": "call-task-1", "title": "task",
15502+
"status": "failed",
15503+
"content": [{"type": "content", "content": {"type": "text",
15504+
"text": "permission denied: task (permission.task = deny)"}}]}
15505+
}})
15506+
w({"jsonrpc": "2.0", "method": "session/update", "params": {
15507+
"sessionId": "mock-session",
15508+
"update": {"sessionUpdate": "agent_message_chunk",
15509+
"content": {"type": "text", "text": "TASK_DENIED_DONE"}}
15510+
}})
15511+
w({"jsonrpc": "2.0", "id": prompt_id, "result": {
15512+
"stopReason": "end_turn", "usage": {"inputTokens": 3, "outputTokens": 2}
15513+
}})
15514+
1545815515
elif behavior == "elicit_disconnect":
1545915516
# Send elicitation, then close stdout (simulate adapter death mid-suspension).
1546015517
w({"jsonrpc": "2.0", "id": "elicit-disc", "method": "elicitation/create", "params": {
@@ -16080,6 +16137,47 @@ transport = "stdio"
1608016137

1608116138
// ── core#293: agent request ids cross client prompt ids ───────────────────────
1608216139

16140+
/// F-W1-002 / BC-75: a tool call the SEAT ITSELF refused — opencode's `permission.task: deny`
16141+
/// (registry.rs) means the `task` subagent never spawns under ACP, so no permission ask can be
16142+
/// dropped by opencode's ACP layer (anomalyco/opencode#48232). The refusal ends the call
16143+
/// `failed`; the transcript must say so — a denial nobody can see is the 600 s dead turn again.
16144+
#[test]
16145+
#[cfg(unix)]
16146+
fn a_tool_call_the_seat_itself_refused_is_recorded_in_the_transcript() {
16147+
let dir = std::env::temp_dir().join(format!("wicked-fw1-002-{}", std::process::id()));
16148+
std::fs::create_dir_all(&dir).unwrap();
16149+
let mut proc = start_mock_proc(&dir, "task_denied");
16150+
let maps = Arc::new(Mutex::new(ElicitationMaps::new()));
16151+
let (tx, _rx) = std::sync::mpsc::channel();
16152+
let noop: &DeltaSink = &|_: &str| {};
16153+
let turn = exec_turn_acp(
16154+
&mut proc,
16155+
"explore the repo",
16156+
&[],
16157+
noop,
16158+
Duration::from_secs(10),
16159+
Arc::clone(&maps),
16160+
"run-fw1-002",
16161+
0,
16162+
&tx,
16163+
None,
16164+
)
16165+
.unwrap();
16166+
assert_eq!(turn.status, StepStatus::Ok, "{:?}", turn.output);
16167+
assert!(
16168+
turn.output.contains(
16169+
"[tool call failed] task: permission denied: task (permission.task = deny)"
16170+
),
16171+
"the seat's own refusal must reach the transcript: {:?}",
16172+
turn.output
16173+
);
16174+
assert!(
16175+
turn.output.contains("TASK_DENIED_DONE"),
16176+
"the turn still completes after the refused call: {:?}",
16177+
turn.output
16178+
);
16179+
}
16180+
1608316181
/// THE core#293 REGRESSION TEST — two turns on ONE session, driven until the agent's own
1608416182
/// request counter walks into the client's prompt-id space.
1608516183
///

0 commit comments

Comments
 (0)