Repository navigation
fix: make claude's own cron and wake-up tools ask crew first - #30270
shubhamkurkure wants to merge 1 commit into
Conversation
861af89 to
099ed85
Compare
099ed85 to
ff12db7
Compare
|
Hi @bolichen97 and @chenmingwei23, when you have a moment, would you mind reviewing this PR? It covers part of #30172: on the Claude backend, Claude Code's own Please let me know if you would like anything changed. Thank you for your time! |
On the claude backend, CronCreate, CronDelete and ScheduleWakeup ran in default and auto mode with no session/request_permission, so Crew's approval path never saw work Claude scheduled for later, and Crew's cron service has no record of it. Every settings payload Crew renders now carries a permissions.ask rule for each, merged with any ask rules already there, so the seed and the exclusion path's inline settings both send these calls to Crew's gate. CronList only reads and stays unprompted. The log lines for a session that runs without Crew's seed now name these rules among what it loses. Part of kirodotdev#30172
ff12db7 to
3560211
Compare
Code change approver recommendation: ApproveWhy: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. The PR adds permissions.ask rules for CronCreate, CronDelete and ScheduleWakeup to every Claude settings payload. That one payload is both the seed file and the inline settings on the exclusion path, so one edit covers both. I checked every reader of the payload: the exclusion merge (adds project rules once, drops none), the session envelope's allowlist and Connection ask merges and the Side Chat merge (all keep existing entries), the shipped-restrictions record, sibling-seed sharing (compares permissions, so an older build's live seed isn't shared), and digest-based adoption of an orphan seed from an older build (re-seeded with the new rules). Nothing in src/ treats a missing permissions key as a signal. No test that still asserts no permissions key on a Claude seed is left. The new tests would fail without the change and cover the seed, deny-plus-model, auto, exclusion, Side Chat, upgrade, no-share and no-seed log paths. The change only tightens the trust boundary, sending calls that ran unasked through Crew's approval. The trade-offs (/loop re-arm prompts, dontAsk now denies, the no-seed gap) are disclosed and consistent with the goal. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
Problem / Motivation
Goal: On the Claude backend, Claude Code's own CronCreate, CronDelete and ScheduleWakeup calls ask Crew for approval before they run, in default and auto mode.
With
agent.acp_backend = claude, in an ordinary chat indefaultmode, Claude can call CronCreate, CronDelete and ScheduleWakeup and they run with nosession/request_permission. Crew's approval path never sees them: nohooks.on_tool_call, no deny rules, no SEL decision row. Crew sends nodisallowedToolsfor them and its settings seed has no ask rules for them, and Crew's cron service has no record of the jobs Claude creates.Why it matters
The Claude provider spec promises "By default, Claude asks and Crew decides". These three tools break that promise: an agent can schedule work that runs later, unattended, without the person ever approving it. A cron created with
durable: trueis written to<work dir>/.claude/scheduled_tasks.json, outlives the session, and can later fire inside another Claude Code session in that project, where Crew has no record of it at all.Not a goal
disallowedToolsorCLAUDE_CODE_DISABLE_CRON. That is a capability removal, not a gate.What changed (motivation → approach → change)
defaultandautowith no permission request.canUseToolunless a rule says to ask, and nothing Crew sends carries such a rule.permissions.askrule makes Claude Code send the call throughcanUseTool, which claude-agent-acp turns intosession/request_permission, so Crew's normal approval path decides. With the rule, all three ask indefaultand inauto, onsession/newand onsession/load: live runs measured CronCreate, and a stub-API oracle measured CronDelete and ScheduleWakeup (see Manual verification). A reject stopped CronCreate and ScheduleWakeup in both modes, and CronDelete indefault. This is smaller thandisallowedTools, which would remove the tools outright._render_claude_settings_payload(src/kiro_crew/acp/client_claude_seed.py) now adds_CLAUDE_SCHEDULER_ASK_RULES(CronCreate,CronDelete,ScheduleWakeup) topermissions.askon every payload. The same payload is the seed file Crew writes and the inlineoptions.settingsthe exclusion path sends when a project owns itssettings.local.json, so one edit covers both. Side Chat's own read ask rules are appended after them as before.toolsSettingsshell and write allowlists, so those keep their place and order, and a rule already in the list is not repeated..claude, a declined share or refused exclusion, a replaced or unrecorded seed) now names the ask rules for Claude's own cron and wake-up tools among what it loses. The lost-items phrase is one shared constant,_CLAUDE_NO_SEED_LOSSES.docs/system-specs/modules/claude-code-provider.mdstates the scheduler ask rules under "By default, Claude asks and Crew decides", the durable-cron fact, and lists the new key where the seed's and the inline settings' keys are listed.Backwards compatibility
Compatible: every settings payload gains one
permissions.asklist, which Claude Code already accepts; nothing that parses or compares the seed reads a fixed key set. The visible effect is that these three calls now show Crew's normal approval for a Claude tool call, as Bash already does.Removes nothing: no key, path, record or function is removed or renamed, and the tools stay available once a call is approved.
Tests
test/test_claude_scheduler_ask_rules.py(new): the rule list names exactly CronCreate, CronDelete and ScheduleWakeup and not CronList; an ordinary chat's seed on disk carries them; a seed whose spec givesdisabledToolsand whose model cache is warm carries them beside thedenyandmodelkeys; a chat that requestedautokeepsdefaultMode: autoand still carries them; the exclusion path carries them inline and records them as shipped; a Side Chat on the exclusion path keeps both rule sets; an orphan seed an older build wrote is adopted and upgraded; a live older seed without the rules is not shared; a session that gets no seed (a project file it cannot leave out, or a.claudeCrew may not write through) logs that it runs without these ask rules.CronCreateappears once. That dedup comes from the exclusion path's existing merge in_exclude_foreign_local_settings, not from the new block, and the test's docstring says so.if not deny_rules:or on a cold model cache, and it is the only test that does.test/test_acp_session_mcp_client_seam.py:test_the_project_tiers_ask_rules_ride_inlineandtest_a_side_read_only_session_keeps_the_exclusions_restrictionspinned the exact inline ask list; it now starts with Crew's scheduler rules.test_a_crew_authored_session_is_not_pinnedasserted the seed had nopermissionskey as a stand-in for "nodefaultMode"; it now asserts nodefaultModedirectly.test/test_acp_session_mcp.py:test_no_permission_mode_leaves_the_adapter_defaultgets the same directdefaultModeassertion.test/test_acp_claude_mode_pin_seam.py(from fix(acp): add an opt-in to move unrequested claude sessions out of auto #30308, now merged):test_a_crew_authored_session_is_pinned_off_an_approving_modeandtest_a_user_auto_start_with_crews_array_is_not_pinnedasserted the unrequested seed had nopermissionskey; they now assert nodefaultModedirectly, the same change.test/test_claude_spec_tool_settings.py(from fix(acp): enforce a spec's toolsSettings allowlists on claude #30108): the seeded ask list for a shell or write allowlist now ends with the scheduler rules, and a spec with no allowlist now seeds only the scheduler rules (test_the_seed_asks_only_about_schedulers_without_an_allowlist). New:test_a_left_out_project_file_keeps_every_ask_rule_oncepins that when a project's own file is left out, the inline settings carry the shell and write rules, then the scheduler rules, then the project's own rule, each once, so neither merge drops the other's rules.permissionskey and an ask list.settings.local.json, every seed or session-settings test file refactor(acp): move the claude-agent-acp session code off AcpClient into ClaudeAcpClient #37484 and feat: show the claude-agent-acp surfaces the dashboard drops #37512 changed, and every importer of the two seed test helpers) passed 3621 tests at-n 4 --dist loadgroupwithKIROCREW_CC_PIN_INHERITED_MODEunset and again with it set to1, and thetest_acp_*andtest_claude_*sweep passed 9972 tests (19 skipped). The new test file passed 20 runs at-n0and 10 runs at-n 4 --dist loadgroupbesidetest_claude_spec_tool_settings.py,test_acp_seed_provenance.pyandtest_cc_permission_mode_seed.py, and the 310 tests of the five touched test files passed in a shuffled order (seed 12269).Proof: PROVEN test/test_acp_session_mcp_client_seam.py::TestClientSeam::test_the_project_tiers_ask_rules_ride_inline, test/test_acp_session_mcp_client_seam.py::TestClientSeam::test_a_side_read_only_session_keeps_the_exclusions_restrictions, test/test_claude_scheduler_ask_rules.py::TestSchedulerAskRules::test_the_rules_name_the_scheduling_tools_and_not_cron_list, test/test_claude_scheduler_ask_rules.py::TestSchedulerAskRules::test_an_ordinary_chat_seed_asks_before_scheduling, test/test_claude_scheduler_ask_rules.py::TestSchedulerAskRules::test_a_seed_with_deny_rules_and_a_model_still_asks (head 3560211)
Gate proof: tree a672b6a56c4c; ran 24; skipped none
Manual verification
Live runs drove Crew's real
AcpClientfrom this branch against claude-agent-acp 0.100.0 (Node 24.20.0) with Claude Code 2.1.318, a scratchCLAUDE_CONFIG_DIRcarrying only the model-access keys, a scratchKIROCREW_HOMEand agent spec, and one prompt per run asking Claude to CronCreate a session-only one-shotecho hifor January 1st and then call CronList. CronCreate permission requests were answered with Crew's ownreject_tool.permissions.ask: ["CronCreate", "CronDelete", "ScheduleWakeup"]; onesession/request_permissiontitled CronCreate arrived; after the reject the tool call endedfailed("User refused permission to run tool") and CronList returned "No scheduled jobs."permissions.defaultMode: autoin the scratch user tier;session/newreportedcurrentModeId: auto): the same single CronCreate request arrived, the reject stopped it, and CronList returned "No scheduled jobs."permissions; no permission request was sent; CronCreate created job83c95a3a(session-only) and CronList listed it. It died with the adapter when the run stopped..claude/scheduled_tasks.json, and no adapter process was left running.Stub-API oracle runs (no model call) cover CronDelete and ScheduleWakeup in
autoand onsession/load. They drove claude-agent-acp 0.100.0 with its bundled Claude Code 2.1.316 over ACP, with a stub Messages API bound to 127.0.0.1 that answered each turn with a scripted tool call, and scratchHOMEandCLAUDE_CONFIG_DIR. Script per session: CronCreate (rejected), CronCreate (allowed), CronDelete of that job (allowed), ScheduleWakeup (rejected), CronList.defaultand inauto(user-tierdefaultMode: autowithcurrentModeId: auto, and aftersession/set_modetoauto), and again onsession/loadin a fresh adapter process: onesession/request_permissioneach for CronCreate (twice), CronDelete and ScheduleWakeup, and none for CronList. The rejected calls endedfailedand CronList then showed no jobs.default, inautoand onsession/load: no permission request was sent.defaultmode rejected a CronDelete of a real job, and CronList still listed the job afterwards.Trade-offs and questions for a maintainer
/loopre-arms, and a whole-tool rule cannot tell a re-arm from a new loop. A/loopthe person started now asks on every re-arm, including turns nobody watches, where an unanswered card times out as a reject and the loop stops. Is that the intended cost?RemoteTrigger(claude.ai remote routines: create, update, run) is not in the list. It needs a claude.ai login, and no run here showed whether it runs without asking, so it is left out rather than guessed at. Should it be added here or in a follow-up?_claude_session_metaoptions.settings(the flag tier) whenever a spec sets an allowlist. The three scheduler rules could join that list on every claude session. That would cover the no-seed paths (a symlinked.claude, a declined project file, a failed seed write) at the cost of puttingoptions.settingson every session. Should that be done here or in a follow-up?defaultMode: dontAsk, an ask becomes a deny, so these three calls are now denied outright instead of running.Related Issues
Part of #30172
Still open in #30172 after this PR: the policy for the sub-agent launch (the Agent tool), Workflow, SendMessage and TaskStop; Crew's cron service still has no record of Claude's crons and wake-ups and cannot list or cancel them; and the comment at
src/kiro_crew/agent_sdk/backends_routing.py(lines 185-190) still says nosession/request_permissionframe carryingparentToolUseIdhas been recorded, which this PR does not change.Sibling sweep
Swept: git grep -n "_render_claude_settings_payload()|options["settings"] =" -- src/
Sibling: src/kiro_crew/acp/client_claude_session.py:609 -- not affected -- the exclusion path ships the rendered payload inline, so it carries the rules; the #30108 allowlist ask rules (line 625) and the ask rules for bridged Crew-owned Connections (line 637) merge into that list without dropping entries and add nothing when the session has neither (see the maintainer question above); Side Chat (line 690) builds on the inline settings and runs only read built-ins; the auto-memory switch (line 702) copies the settings and only adds
envPattern harvest
Not generalizable: the defect is specific to which Claude Code built-in tools skip
canUseToolby default; the fix is a data list beside the deny rules, not a code shape a rule could catch.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.