Skip to content

Commit dc0cc1c

Browse files
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] (#524)
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: Michael Parcewski <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 7a73e0d commit dc0cc1c

4 files changed

Lines changed: 182 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,25 @@ Two release tracks share this file, newest entry first regardless of track:
14741474
on the raw text first; cap 4096 kept, not #466's 400 B). A `clis.toml` override that omits
14751475
`[cli.acp]` over a built-in that carries one now warns on stderr (the seat runs wrapped and
14761476
ungoverned; the wholesale-replace rule is unchanged).
1477+
<!-- fixall L4 -->
1478+
- **The opencode seat's harness config denies the `task` tool; a tool call the seat itself refused
1479+
is recorded in the unit transcript (F-W1-002; FIX-IT-ALL L4; BC-75 — proposed, user decision
1480+
owed).** opencode 1.17.18's ACP layer forwards a `permission.asked` only for sessions it opened
1481+
itself (`acp/permission.ts` `process()` → `tryGet(sessionID)` → return when absent; the session
1482+
store holds only `session/new|load|resume|fork`): a `task` (explore) subagent's asks — six
1483+
`external_directory` reads in the wave-1 P6 chat — never reached wicked-core and were never
1484+
rejected either, so the seat sat on a 600 s dead turn until the budget killed it (upstream
1485+
anomalyco/opencode#48232; fix PRs #48326 / #37902 open). One token in the one mechanism that
1486+
already governs the seat: `OPENCODE_CONFIG_CONTENT` `permission` gains `"task":"deny"`
1487+
(`wicked-council` registry) — the subagent is never spawned under ACP; the root session's own
1488+
asks are answered exactly as before. And so the refusal is visible: `handle_update` records
1489+
**any** `tool_call` / `tool_call_update` that ends `status: failed` — on every ACP seat, a seat's
1490+
own refusal or a failed read / shell command alike — as `[tool call failed] <title>: <the seat's
1491+
text>` in the unit transcript (bounded like a chunk; `locations` still collected from the update
1492+
frame only), so the governance token scan over the transcript now also sees tool-error text; the
1493+
text is appended unredacted — transcript redaction is the run-wide policy, not this change.
1494+
Behaviour change register: **BC-75** (proposed — user decision owed: a seat-visible tool denial,
1495+
and every failed tool call now in the transcript).
14771496
- **core-ts 0.7.26** — 2026-09-14 — npm release carrying the eleven engine changes since 0.7.25
14781497
(FIX-IT-ALL wave 1: L4 ①–⑦, L5 1.8, L10-5/-8/-9), all on main tip cad267e (plus #491, the 0.7.25
14791498
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: 122 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,19 +4325,7 @@ fn handle_update(
43254325
"agent_message_chunk" => {
43264326
if let Some(text) = update["content"]["text"].as_str() {
43274327
emit(text);
4328-
let used = output.len();
4329-
if used < max_out {
4330-
// Clamp to remaining capacity at a valid UTF-8 boundary so
4331-
// a single large chunk never pushes output past max_out.
4332-
let remaining = max_out - used;
4333-
let safe = text
4334-
.char_indices()
4335-
.take_while(|(i, c)| *i + c.len_utf8() <= remaining)
4336-
.last()
4337-
.map(|(i, c)| i + c.len_utf8())
4338-
.unwrap_or(0);
4339-
output.push_str(&text[..safe]);
4340-
}
4328+
push_bounded(output, text, max_out);
43414329
}
43424330
}
43434331
"usage_update" => {
@@ -4385,20 +4373,69 @@ fn handle_update(
43854373
});
43864374
}
43874375
}
4388-
"tool_call_update" => {
4389-
// Collect file paths reported by the CLI (e.g. read/edit locations).
4390-
if let Some(locs) = update["locations"].as_array() {
4391-
for loc in locs {
4392-
if let Some(path) = loc["path"].as_str() {
4393-
files.push(path.to_string());
4376+
"tool_call" | "tool_call_update" => {
4377+
// Collect file paths reported by the CLI (e.g. read/edit locations) — from the UPDATE
4378+
// frame only, as before: opencode repeats `locations` on the initial `tool_call`, and
4379+
// `dataUsed.files` goes out without dedup (review of #524, finding 2).
4380+
if kind == "tool_call_update" {
4381+
if let Some(locs) = update["locations"].as_array() {
4382+
for loc in locs {
4383+
if let Some(path) = loc["path"].as_str() {
4384+
files.push(path.to_string());
4385+
}
43944386
}
43954387
}
43964388
}
4389+
// F-W1-002 / BC-75: ANY tool call that ends `status: failed` on the ACP stream — on
4390+
// every ACP seat — is recorded, bounded like a chunk: the call's title and the seat's
4391+
// own text, never the raw input. The case that made it necessary: a tool the SEAT
4392+
// ITSELF refused (opencode's config `permission.task: deny`, registry.rs — the subagent
4393+
// never spawns under ACP) used to leave no trace, so a dead turn and a refusal read the
4394+
// same. A failed `Read` on a missing file or a failed shell command is recorded the same
4395+
// way — better, and said so in the register.
4396+
if update["status"].as_str() == Some("failed") {
4397+
let title = update["title"].as_str().unwrap_or("tool call");
4398+
let note = match failed_tool_call_text(update) {
4399+
Some(text) => format!("\n[tool call failed] {title}: {text}\n"),
4400+
None => format!("\n[tool call failed] {title}\n"),
4401+
};
4402+
push_bounded(output, &note, max_out);
4403+
}
43974404
}
43984405
_ => {}
43994406
}
44004407
}
44014408

4409+
/// Append `text` to `output`, clamped to `max_out` at a valid UTF-8 boundary so a single large
4410+
/// chunk never pushes the transcript past its cap.
4411+
fn push_bounded(output: &mut String, text: &str, max_out: usize) {
4412+
let used = output.len();
4413+
if used >= max_out {
4414+
return;
4415+
}
4416+
let remaining = max_out - used;
4417+
let safe = text
4418+
.char_indices()
4419+
.take_while(|(i, c)| *i + c.len_utf8() <= remaining)
4420+
.last()
4421+
.map(|(i, c)| i + c.len_utf8())
4422+
.unwrap_or(0);
4423+
output.push_str(&text[..safe]);
4424+
}
4425+
4426+
/// The first text the agent attached to a failed tool call — `content[].content.text` per the
4427+
/// ACP schema (a bare `content[].text` is tolerated): the seat's own words for the refusal.
4428+
fn failed_tool_call_text(update: &Value) -> Option<String> {
4429+
update["content"].as_array()?.iter().find_map(|item| {
4430+
item["content"]["text"]
4431+
.as_str()
4432+
.or_else(|| item["text"].as_str())
4433+
.map(str::trim)
4434+
.filter(|t| !t.is_empty())
4435+
.map(str::to_string)
4436+
})
4437+
}
4438+
44024439
/// Parse the authoritative usage object from a `session/prompt` RESULT. All ecosystem
44034440
/// adapters report here (camelCase): official claude/codex, pi-acp, native opencode.
44044441
/// Input counts cached reads/writes alongside fresh input, mirroring the historical
@@ -15717,6 +15754,31 @@ elif behavior == "unknown_request":
1571715754
"stopReason": "end_turn", "usage": {"inputTokens": 1, "outputTokens": 1}
1571815755
}})
1571915756

15757+
elif behavior == "task_denied":
15758+
# F-W1-002 / BC-75: the seat's OWN harness refused a tool (opencode `permission.task: deny`):
15759+
# the call is announced, then ends `failed` with the seat's text. No permission request ever
15760+
# reaches the client — the refusal must still be visible in the transcript.
15761+
w({"jsonrpc": "2.0", "method": "session/update", "params": {
15762+
"sessionId": "mock-session",
15763+
"update": {"sessionUpdate": "tool_call", "toolCallId": "call-task-1", "title": "task",
15764+
"kind": "other", "status": "pending", "rawInput": {"description": "explore"}}
15765+
}})
15766+
w({"jsonrpc": "2.0", "method": "session/update", "params": {
15767+
"sessionId": "mock-session",
15768+
"update": {"sessionUpdate": "tool_call_update", "toolCallId": "call-task-1", "title": "task",
15769+
"status": "failed",
15770+
"content": [{"type": "content", "content": {"type": "text",
15771+
"text": "permission denied: task (permission.task = deny)"}}]}
15772+
}})
15773+
w({"jsonrpc": "2.0", "method": "session/update", "params": {
15774+
"sessionId": "mock-session",
15775+
"update": {"sessionUpdate": "agent_message_chunk",
15776+
"content": {"type": "text", "text": "TASK_DENIED_DONE"}}
15777+
}})
15778+
w({"jsonrpc": "2.0", "id": prompt_id, "result": {
15779+
"stopReason": "end_turn", "usage": {"inputTokens": 3, "outputTokens": 2}
15780+
}})
15781+
1572015782
elif behavior == "elicit_disconnect":
1572115783
# Send elicitation, then close stdout (simulate adapter death mid-suspension).
1572215784
w({"jsonrpc": "2.0", "id": "elicit-disc", "method": "elicitation/create", "params": {
@@ -16342,6 +16404,47 @@ transport = "stdio"
1634216404

1634316405
// ── core#293: agent request ids cross client prompt ids ───────────────────────
1634416406

16407+
/// F-W1-002 / BC-75: a tool call the SEAT ITSELF refused — opencode's `permission.task: deny`
16408+
/// (registry.rs) means the `task` subagent never spawns under ACP, so no permission ask can be
16409+
/// dropped by opencode's ACP layer (anomalyco/opencode#48232). The refusal ends the call
16410+
/// `failed`; the transcript must say so — a denial nobody can see is the 600 s dead turn again.
16411+
#[test]
16412+
#[cfg(unix)]
16413+
fn a_tool_call_the_seat_itself_refused_is_recorded_in_the_transcript() {
16414+
let dir = std::env::temp_dir().join(format!("wicked-fw1-002-{}", std::process::id()));
16415+
std::fs::create_dir_all(&dir).unwrap();
16416+
let mut proc = start_mock_proc(&dir, "task_denied");
16417+
let maps = Arc::new(Mutex::new(ElicitationMaps::new()));
16418+
let (tx, _rx) = std::sync::mpsc::channel();
16419+
let noop: &DeltaSink = &|_: &str| {};
16420+
let turn = exec_turn_acp(
16421+
&mut proc,
16422+
"explore the repo",
16423+
&[],
16424+
noop,
16425+
Duration::from_secs(10),
16426+
Arc::clone(&maps),
16427+
"run-fw1-002",
16428+
0,
16429+
&tx,
16430+
None,
16431+
)
16432+
.unwrap();
16433+
assert_eq!(turn.status, StepStatus::Ok, "{:?}", turn.output);
16434+
assert!(
16435+
turn.output.contains(
16436+
"[tool call failed] task: permission denied: task (permission.task = deny)"
16437+
),
16438+
"the seat's own refusal must reach the transcript: {:?}",
16439+
turn.output
16440+
);
16441+
assert!(
16442+
turn.output.contains("TASK_DENIED_DONE"),
16443+
"the turn still completes after the refused call: {:?}",
16444+
turn.output
16445+
);
16446+
}
16447+
1634516448
/// THE core#293 REGRESSION TEST — two turns on ONE session, driven until the agent's own
1634616449
/// request counter walks into the client's prompt-id space.
1634716450
///

‎src/actor.rs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,32 @@ fn checkpoint_wals(
601601
}
602602
}
603603

604+
/// `dataUsed.files` names each path ONCE, in first-seen order: an ACP seat repeats a call's
605+
/// `locations` across its frames (and a unit reads the same file many times), and the wire used to
606+
/// carry every repeat (review of #524, finding 2).
607+
fn distinct_files(files: &[String]) -> Vec<String> {
608+
let mut seen = HashSet::new();
609+
files
610+
.iter()
611+
.filter(|f| seen.insert(f.as_str()))
612+
.cloned()
613+
.collect()
614+
}
615+
604616
#[cfg(test)]
605617
mod wal_checkpoint_tests {
606618
use super::*;
607619

620+
#[test]
621+
fn data_used_files_are_emitted_once_per_path_in_first_seen_order() {
622+
let files = ["b.rs", "a.rs", "b.rs", "a.rs", "c.rs"].map(String::from);
623+
assert_eq!(
624+
distinct_files(&files),
625+
["b.rs", "a.rs", "c.rs"].map(String::from)
626+
);
627+
assert!(distinct_files(&[]).is_empty());
628+
}
629+
608630
/// Perf #5: the idle-tick helper must empty all three actor-owned WALs via the actor's own
609631
/// connections and leave every store readable. (The `recv_timeout` wiring above is exercised
610632
/// by every existing actor test — this pins the checkpoint work itself.)
@@ -4309,7 +4331,7 @@ fn apply_step_result(
43094331
CoreEvent::DataUsed {
43104332
session: run_id.clone(),
43114333
ord,
4312-
files: output.files.clone(),
4334+
files: distinct_files(&output.files),
43134335
},
43144336
);
43154337
}

0 commit comments

Comments
 (0)