Skip to content

fix(governance): give cron turns their agent at the governance gate - #29412

Merged
bolichen97 merged 1 commit into
mainfrom
crew/slack/cron-turn-agent-scope
Nov 4, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
crew/slack/cron-turn-agent-scope

Conversation

@buluoray

@buluoray buluoray commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A governance profile bound to an agent governs that agent's cron turns, the same as its chat turns

A cron turn hands the PreToolUse gate its cron:<job> session key and unattended=True, but no agent. resolve_active_scope looks up a task bind on the agent name only when it is given one, so a profile an administrator binds to an agent (Bind(type="task", id="researcher")) is skipped on that agent's cron turns. The turn is judged by the cron surface profile or the policy ceiling instead.

Why it matters

An administrator who scopes an agent tightly gets that scope on its chat turns only. Its unattended cron runs, the ones nobody is watching, are governed more loosely than they set.

Not a goal

What changed (motivation → approach → change)

Both cron stream calls in cron_turn.py hand the gate the agent's alias or crew record name, the same name every chat surface (dashboard, Slack, messaging channels) hands it. The template that name collapses to stays on session acquisition and message build only:

Path agent=
_cron_run_sequence each step's alias
_cron_run_single a member capture: the member's live alias (the record dispatch resolves through member_config_for_id), else its captured selection_name, whatever the job's agent names; otherwise the job's agent_id, else the agent that runs. Read in cron_fire.py before a crewmate's worker swap

_cron_stream_with_posttoken_resume forwards it to stream_and_collect, which already takes agent and hands it to the gate. The governance spec names the agent in its unattended-turns paragraph.

Backwards compatibility

Compatible: a cron turn whose agent has no task bind resolves exactly as before. Only an agent with a bound task profile now gets that profile on its cron turns, which is what the bind already means for its chat turns.

Removes nothing: no key, path or record is removed.

Tests

Proof: PROVEN test/test_cron_sequence_member_alias.py::test_each_sequence_step_hands_the_gate_its_alias_not_its_template (head 615a844)

  • test_each_sequence_step_hands_the_gate_its_alias_not_its_template: each sequence step streams with its own session key, its alias (not the kiro_agent template it runs) and unattended=True.
  • test_cron_turn_hands_the_gate_its_alias_not_its_template: on the single-agent path the session runs the template while the gate gets the alias.
  • test_a_member_cron_hands_the_gate_the_member_alias[member|crewmate-worker]: a cron captured from a member's chat, with no agent_id, hands the gate the member alias, also after a crewmate's capture is swapped to the worker template.
  • test_a_member_capture_hands_the_gate_its_live_alias_whatever_the_job_names[dashboard-template-agent|other-member-agent|renamed-member]: a member schedule whose agent holds a template (the dashboard's create/edit shape) or another member's name (a cron_update) still hands the gate the member's live alias, and follows a rename; dispatch stays on the member's template. Restoring job.agent_id priority fails the first two; dropping the live lookup fails the third.
  • test_a_task_profile_bound_to_the_cron_agent_governs_its_turn: with a cron: session key, a task bind on the agent wins.
  • Removing either agent= line alone fails its own test.
  • Determinism: the three new tests 20/20 green at -n0; both files (35 tests) green in three shuffled orders, seeds 11, 22, 33.
  • The cron and governance test files plus every test that drives cron_turn.py (182 files), single process in batches: 5,861 passed. One failure, test_cron_run_scratch.py::TestUnderTheRealSandbox::test_script_cron_writes_into_its_temp_dir, fails the same way on a clean origin/main: the real sandbox cannot pin this host's temp path.
  • flake8, isort, black, mypy, comment-history, brand name, flake-pattern ratchet and docs lint: pass.

Manual verification

N/A - unit coverage pins the keyword at both call sites and the resolver's task-bind lookup.

Related Issues

Closes #29411

Sibling sweep

Swept: git grep -n "unattended=True" -- src/kiro_crew/
Sibling: src/kiro_crew/messaging/dispatch.py:1037 -- not affected -- a channel monitor wake passes agent=agent and unattended
Sibling: src/kiro_crew/slack/gateway_runtime/nudge_channel_fire.py:269 -- tracked in #29411
Sibling: src/kiro_crew/slack/gateway_runtime/heartbeat_turns.py:211 -- tracked in #29411

The Slack-thread nudge's stream_and_collect path and the heartbeat task stream with unattended=True but no session key or agent; the nudge's TurnDriver path passes both. They are listed on #29411 rather than changed here, to keep this PR to the cron turn.

Pattern harvest

Rule candidate: review-prompt
Pattern: an unattended stream_and_collect(unattended=True) call that passes no session_key=/agent=, so the gate cannot resolve the session's or agent's profile.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 4, 2026 00:44
@buluoray
buluoray enabled auto-merge (squash) November 4, 2026 00:44
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7b7b95464aedc8418cd700bc08d39083bdcb5e99 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 7b7b95464aedc8418cd700bc08d39083bdcb5e99 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: this closes a governance gap by naming the agent at the gate, the same way chat already does, and takes nothing away.

Notes

  • _cron_capture now works out the gate's agent name a second time, apart from _resolve_cron_agent's dispatch lookup through member_config_for_id. If those two drift, the gate governs one agent while another one runs. Having dispatch return the alias it resolved would leave a single place that decides this.

[DESIGN-REVIEWED] 7b7b954

Description read

[DESCRIPTION-READ] c735177ebfadbd55b7e2d71caa4ec16d770b03b1137d196a81a1252b5a97cccb

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7b7b95464aedc8418cd700bc08d39083bdcb5e99 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Every item is part of handing the cron turn's gate the agent name a chat turn already hands it, and the member lookup reuses member_config_for_id.

What this change ships

Inventory (5 items) — 5 justified

Intent: an administrator's task profile bound to an agent also governs that agent's unattended cron turns. FIX.

  1. Each agent_sequence step's cron turn now gets a governance profile bound to that step's alias — justified
  2. A single-agent cron turn now gets a governance profile bound to the job's alias, not to the template that alias runs as — justified
  3. A schedule captured from a member's chat is governed by that member's current alias, even when the job names a template or another member, and even after a crewmate's worker swap — justified
  4. The cron capture record carries a new gate_agent field, read before the worker swap — justified
  5. The governance spec's unattended-turns paragraph now names the agent the gate receives — justified

[FIRST-PRINCIPLES-REVIEWED] 7b7b954

Description read

[DESCRIPTION-READ] 74b8b9f7eaabf2635948febccad61e11aa99fe0fb637aeee0026e2fcbfa83fd7

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

buluoray added a commit that referenced this pull request Nov 4, 2026
A cron turn handed the PreToolUse gate its cron:<job> session key but
no agent, so resolve_active_scope skipped the task bind on the agent
name. A profile an administrator binds to an agent governed its chat
turns but not its cron turns.

Pass the dispatched template as agent= at both stream calls: each
step's dispatch_agent on an agent_sequence, _dispatch_agent on the
single-agent path. That is the id a chat turn hands the gate.

Mirrors #29412 on main.
(cherry picked from commit 2012f5e)

Forward-port conflict: test/test_cron_sequence_member_alias.py. On
main the new test follows tests from #28410, which this branch does
not carry. Kept the release file and appended only the new test.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 7b7b95464aedc8418cd700bc08d39083bdcb5e99 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 7b7b954

Verdict parsed from the review's SHA-scoped output markers for commit 7b7b95464aedc8418cd700bc08d39083bdcb5e99.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 7b7b95464aedc8418cd700bc08d39083bdcb5e99 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 7b7b95464aedc8418cd700bc08d39083bdcb5e99 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7b7b954

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 7b7b95464aedc8418cd700bc08d39083bdcb5e99 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 4, 2026
@buluoray
buluoray force-pushed the crew/slack/cron-turn-agent-scope branch from 2012f5e to f6c0486 Compare November 4, 2026 00:59
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 4, 2026
@buluoray

buluoray commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: cron gate agent= kwarg at both cron_turn.py stream calls

  • BLOCKING src/kiro_crew/slack/gateway_runtime/cron_turn.py:274 span=c7b2d075a53e: gate gets the dispatched template, chat gives it the alias

fixed in f6c0486: both cron calls hand the gate the alias or crew record name (step.alias; cron_agent or ""). The template stays on session acquisition and build_message only.
Verified every chat surface agrees: dashboard tool_approval.py passes slot.agent (the alias), Slack transport_dispatch.py passes the record name, messaging dispatch.py passes the unresolved agent.
Tests now set a template that differs from the alias and assert the gate gets the alias; reverting either line alone fails its own test.

buluoray added a commit that referenced this pull request Nov 4, 2026
A cron turn handed the PreToolUse gate its cron:<job> session key but
no agent, so resolve_active_scope skipped the task bind on the agent
name. A profile an administrator binds to an agent governed its chat
turns but not its cron turns.

Pass the agent's alias or crew record name as agent= at both stream
calls: each step's alias on an agent_sequence, cron_agent on the
single-agent path. That is the name every chat surface hands the gate;
the template it collapses to stays on session acquisition and message
build.

Mirrors #29412 on main.
(cherry picked from commit f6c0486)

Forward-port conflict: test/test_cron_sequence_member_alias.py. On
main the new test follows tests from #28410, which this branch does
not carry. Kept the release file and appended only the new test.
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 4, 2026
@buluoray
buluoray force-pushed the crew/slack/cron-turn-agent-scope branch from f6c0486 to 47efc8f Compare November 4, 2026 01:25
@buluoray

buluoray commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: cron gate agent= kwarg at both cron_turn.py stream calls

  • BLOCKING src/kiro_crew/slack/gateway_runtime/cron_turn.py:697 span=a2fb0acdf09b: member cron turns use the runtime template's governance profile

fixed in 47efc8f: the single-agent gate gets the captured member alias, recorded before a crewmate's worker swap, so a task profile bound to the template name no longer outranks the member's or the cron surface's.
Worker executions are covered: the alias is read before cron_worker_execution rewrites the selection to the worker template.
test_a_member_cron_hands_the_gate_the_member_alias[member|crewmate-worker] pins both; reverting the gate line to cron_agent fails both.

@buluoray

buluoray commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: cron gate agent= kwarg at both cron_turn.py stream calls

  • BLOCKING src/kiro_crew/slack/gateway_runtime/cron_turn.py:697 span=c7b2d075a53e: single-agent member cron hands the gate the template, not the alias

fixed in 47efc8f: _cron_capture records the gate agent before the worker swap (job.agent_id, else the member capture's selection_name, else the agent that runs); _cron_run_single hands the gate cap.gate_agent. cron_agent stays dispatch-only.
selection_name is the config.agents key for a member capture (execution_context.py resolve_member_execution), the name chat hands the gate.
test_a_member_cron_hands_the_gate_the_member_alias[member|crewmate-worker] fails with the gate line reverted to cron_agent.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 4, 2026
buluoray added a commit that referenced this pull request Nov 4, 2026
A cron turn handed the PreToolUse gate its cron:<job> session key but
no agent, so resolve_active_scope skipped the task bind on the agent
name. A profile an administrator binds to an agent governed its chat
turns but not its cron turns.

Hand the gate the alias or crew record name a chat turn on that agent
hands it: each step's alias on an agent_sequence; on a single-agent job
the job's agent_id, else the member the capture selected, read before
a crewmate's worker swap, else the agent that runs. The dispatched
template stays on session acquisition and message build.

Mirrors #29412 on main.
(cherry picked from commit 47efc8f)

Forward-port conflict: test/test_cron_sequence_member_alias.py. On
main the new test follows tests from #28410, which this branch does
not carry. Kept the release file and appended only the new test.
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 4, 2026
@buluoray
buluoray force-pushed the crew/slack/cron-turn-agent-scope branch from 47efc8f to 615a844 Compare November 4, 2026 01:47
@buluoray

buluoray commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: cron gate agent= kwarg; single-agent gate name chosen in _cron_capture

  • BLOCKING src/kiro_crew/slack/gateway_runtime/cron_fire.py:474 span=df10b6f7e50e: dashboard member schedules select the template's governance profile

fixed in 615a844: when the capture selected a member (member_id set or selection_kind member), the gate gets the member's live alias via member_config_for_id, the record dispatch resolves through, else its captured selection_name; job.agent_id is used only for a capture that selected no member.
A dashboard schedule saving member_id beside a template-valued agent now hands the gate the member's alias, so the template's task profile no longer replaces the member's or the cron surface's.
test_a_member_capture_hands_the_gate_its_live_alias_whatever_the_job_names[dashboard-template-agent] pins it; restoring job.agent_id priority fails it.

@buluoray

buluoray commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: cron gate agent= kwarg; single-agent gate name chosen in _cron_capture

  • BLOCKING src/kiro_crew/slack/gateway_runtime/cron_fire.py:474 span=c9075f224b10: member schedule whose agent_id names another agent gives the gate that name

fixed in 615a844: a member capture hands the gate the member's live alias (member_config_for_id on the captured member_id, the same lookup _resolve_cron_agent dispatches through), else its captured selection_name; job.agent_id counts only when no member was selected.
A cron_update that sets agent to another member's name no longer moves the gate to that member's task profile while the turn runs as the captured member.
test_a_member_capture_hands_the_gate_its_live_alias_whatever_the_job_names[other-member-agent|renamed-member] pins it; restoring job.agent_id priority fails other-member-agent, dropping the live lookup fails renamed-member.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 4, 2026
A cron turn handed the PreToolUse gate its cron:<job> session key but
no agent, so resolve_active_scope skipped the task bind on the agent
name. A profile an administrator binds to an agent governed its chat
turns but not its cron turns.

Hand the gate the alias or crew record name a chat turn on that agent
hands it: each step's alias on an agent_sequence. On a single-agent
job whose capture selected a member, the member's live alias (the record
dispatch resolves through member_config_for_id), else its captured
selection_name, whatever the job's agent names; otherwise the job's
agent_id, else the agent that runs. Read before a crewmate's worker
swap. The dispatched template stays on session acquisition and message
build.
@buluoray
buluoray force-pushed the crew/slack/cron-turn-agent-scope branch from 615a844 to 7b7b954 Compare November 4, 2026 07:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 4, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[operator: bolichen97] Approving at 7b7b954.

Both cron paths now pass the gate agent to stream_and_collect: _cron_run_sequence uses the step alias, and _cron_run_single uses gate_agent, computed in cron_fire.py before the crewmate worker swap. In turn_stream.py, agent is only forwarded to the governance gate, so session and dispatch behavior do not change. The new _CronCapture field has a default, so existing constructors still work. A failed member lookup falls back to selection_name instead of crashing the cron. The effect is a tightening: an agent with a task bind now gets that profile on its cron turns, as chat turns already do. This is not on main yet. #29386 added only session_key=/unattended= on the 0.12 branch.

Minor, non-blocking:

  • The except Exception: _gate_alias = "" in cron_fire.py falls back silently. A debug log there would make wrong-profile cases easier to diagnose.
  • cap.gate_agent or "" is redundant, because the capture already falls back to cron_agent.

AI-assisted, approved by bolichen97

@bolichen97
bolichen97 merged commit 46af64f into main Nov 4, 2026
96 checks passed
@bolichen97
bolichen97 deleted the crew/slack/cron-turn-agent-scope branch November 4, 2026 09:24
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 4, 2026
buluoray added a commit that referenced this pull request Nov 4, 2026
…29412) (#29565)

A cron turn handed the PreToolUse gate its cron:<job> session key but
no agent, so resolve_active_scope skipped the task bind on the agent
name. A profile an administrator binds to an agent governed its chat
turns but not its cron turns.

Hand the gate the alias or crew record name a chat turn on that agent
hands it: each step's alias on an agent_sequence. On a single-agent
job whose capture selected a member, the member's live alias (the record
dispatch resolves through member_config_for_id), else its captured
selection_name, whatever the job's agent names; otherwise the job's
agent_id, else the agent that runs. Read before a crewmate's worker
swap. The dispatched template stays on session acquisition and message
build.

(cherry picked from commit 46af64f)

Forward-port conflict: test/test_cron_sequence_member_alias.py. On
main the new test follows tests from #28410, which this branch does
not carry. Kept the release file and appended only the new test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cron turns skip a task governance profile bound to their agent

2 participants