Repository navigation
feat(cron): bind scheduled jobs to a project's agents - #17554
kyleseaman wants to merge 2 commits into
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The precedence override takes a crewmate's memory away on every backend, though it's only shown to hold on kiro-cli, and the description misstates what triggers it. Not justified as shipped
What this change shipsInventory (10 items) — 6 justifiedIntent: a scheduled job runs as the agent you picked, or skips and says why, and can use a checkout's own agents. This is mostly an ADDITION, with a fix included.
[FIRST-PRINCIPLES-REVIEWED] 627a6b0 Description read[DESCRIPTION-READ] 75d460528c30d8b26fb7e32bb2b20332e75b30205a112a2812fd709d78bd7d4a That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/dashboard/chat_api/slot_summary.py:65 -- Cron-summary authorization decisions are not audited
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 is fenced, so it keeps blocking whatever I write here. My only choice was between upholding the finding as written and flagging it as too rare to matter. I upheld it, for three reasons:
False positive or not applicable? A repository writer can comment: |
bb7bfaf to
b49ce28
Compare
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The Backwards compatibility section falls past the 8,000-byte truncation, so nobody can check its reader list against the precedence change, the new 400 and the owner gates. Watch
[DESIGN-REVIEWED] 627a6b0 Description read[DESCRIPTION-READ] 28ac0be027f14089543e65235f64fe89aab79e9a1c6cb3063902899401c72411 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings that block the merge. FINDING — src/kiro_crew/cron.py:2254 — the 500-char [OPUS-REVIEWED] bf2132f Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- 🟡 CONCERNSWhich legitimate operations does Verdict basis: the reviewer's own judgement; no confirmed regression. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: CONCERNS TIGHTENING: Owner gating and re-validation of a cron job's project-directory binding -- this refuses a non-owner (including an allow-listed messaging user) who tries to bind, run, re-enable or read a job tied to an arbitrary absolute directory. The messaging hunk in ADJUDICATED: 15 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: Rows cover posix, windows and any. The diff assumes UNADJUDICATED: The classifier cannot reach any of the guards this diff tightens. Each guard, its call path, and the legitimate inputs I would have submitted:
[SCOPE-REVIEWED] 3a6f741 |
b49ce28 to
cced20c
Compare
cced20c to
522202f
Compare
522202f to
5d46378
Compare
5d46378 to
8cd2e0e
Compare
873ed66 to
472c3ff
Compare
472c3ff to
5dbe807
Compare
5dbe807 to
8d1f4a0
Compare
8d1f4a0 to
77692f9
Compare
A scheduled job could name an agent that no longer resolved and run under the default one instead, silently. Point a job at a project directory and its .kiro/agents are offered alongside the configured ones; an agent that does not resolve at fire time is now a named skip rather than a substitution. On a name collision the project's agent answers, matching the precedence kiro-cli already applies in that directory. The roster endpoint used to subtract configured names from project names, so the colliding project row never reached the picker at all -- the form offered the configured agent while dispatch ran the project file. The project row is emitted instead, marked "overrides global" with the reason on the row, and the shadowed configured agent is suppressed. The field is called "Project directory", matching the folder-settings field that uses the same picker; "working directory" already means the process cwd elsewhere in the dashboard. Closes #8952 Review repairs folded in: Review repairs on one head, keeping this PR at two commits. DISCLOSURE -- project-bound cron output reached non-owners on several paths. Notification and chat rows carry a real boolean project_bound stamp, and HTTP, SSE, WebSocket and slot-detail delivery admit a row to a non-owner only when that stamp is exactly False; a malformed stamp or an unstamped cron row is unknown provenance and is withheld. Only a dict frame can carry provenance, so only a dict frame is judged -- a list or scalar payload is structural, and withholding it would deny every non-owner frame while protecting nothing. The to-chat replay filter took a whole-transcript shortcut whenever no bound run was on record. Retention keeps 100 records per job, so pruning removes a bound run's RECORD while its transcript rows survive, after which "no bound windows" meant "nothing to hide" when it had to mean "cannot prove safe". A row is served only when a retained unbound run's window positively covers it, explicit row provenance outranks that window fallback, and the bound-run flag the deleted-job branch gates on now reports the run records rather than a constant. Clearing a bound job's directory no longer carries its protected last_result into the next prompt: that run would stamp derived output unbound. A deleted job's notification body is taken newest-first and only when its own stamp proves an unbound run. A project-bound sequence step dispatches under its own template again, so its spawn allowlist is its own rather than the job-level floor. The shared predicate lives in handlers/source_providers because a messaging_api owner's functions run on the facade's namespace, where a name the owner merely defines is never bound. PRECEDENCE -- the earlier change let a project file displace an explicit Kiro Crew alias that merely shared its NAME, and deleted the pin saying it must not. On base an alias dispatches its kiro_agent, and kiro-cli looks up the project file only when that TEMPLATE name matches a project agent, so the symptom the description gave does not occur in the pinned case. Alias-first precedence is restored and test_alias_still_wins_over_a_project_agent is back verbatim; the project file wins only where it declares the alias's own kiro_agent template. Raised by the GPT 6.1, Opus 5.5 and First Principles review lanes. learn-cron-dashboard gains disclosure rows 2c and 2d, which the adjudication noted were absent, and its precedence section reads alias-first.
…d jobs - Slot list: a cron- slot's text previews (last_message, prompt_preview, options) now stay inside the owner boundary unless its newest turn is explicitly unbound, matching the owner-only rule the notification and chat frames already apply. The owner view is re-projected for those rows only. - Pool decision log: report the requested cwd as its relation to the pool's (none/pool/other) instead of the path, since the INFO line reaches every dashboard-user socket through the log replay. - Single-agent fire: replace a stale durable execution identity this job itself published (same member/store/app, or the Global project-override shape) before acquisition, so a binding change no longer makes every later fire fail with "session already belongs to another execution". Co-authored-by: mbajaj92 <mbajaj.92@gmail.com>
|
Thanks @kyleseaman for taking this over, and @mbajaj92 for the original work in #9201. We're closing this stack (#17554, #17580 and #9201) for now. Together it is over 17,000 lines, it has fallen behind main where cron agent identity has been reworked several times since, and a security-class review finding is still open. The need is still real and stays tracked in #8952. We'd welcome it again as two small PRs on current main: one that makes a job whose agent does not resolve skip loudly instead of running as the default agent, and one that lets the Schedule page pick a project's agents. The branch is left untouched, so you can reopen this PR at any time, or open a fresh one on current main, if you want to pick it back up. |
Problem / Motivation
Goal: A scheduled job runs as the agent you picked -- or skips and says why -- and can use the agents a checkout ships.
A scheduled job names an agent. If that name stopped resolving, the job did not
fail — it ran under the default agent instead, and said nothing. The Schedule
page kept showing the name you picked, so a job could run as the wrong agent for
weeks and look green the whole time.
There was also no way to point a job at a checkout. A repo that ships its own
.kiro/agents/could not lend those agents to a job, so the agent that knows arepo was unreachable from the schedule.
Why it matters
Silent substitution is the worse half. A job that runs the wrong agent produces
plausible output, so nobody looks. The failure is invisible exactly when it
matters most — an unattended job, running while you are not there.
Not a goal
(a project's agent beats a same-named configured alias) does reach a chat slot
that is bound to a directory; see Backwards compatibility.
on
kiro-cli, whose project-first lookup the change matches.ships; it does not create, edit or install one.
What changed (motivation → approach → change)
A job now has a Project directory. Set it, and that directory's agents join
the picker beside your configured ones, and the job fires with that directory as
its working directory.
An agent that does not resolve is now a named skip, not a substitution. The
job goes red and says which agent and which directory. This covers jobs bound to
a directory — where a project definition can shadow the name — and unbound
delete-after-run one-shots, whose vanished agent must not consume scheduled work
that never ran. An unbound recurring job keeps firing on its captured template
by design: an app-registered or un-aliased crew name is not a
config.agentsalias, so re-resolving it would strand jobs that work today.
On a name collision, the directory's agent answers, matching the layer
underneath: kiro-cli searches
<project>/.kiro/agentsbefore the user-levelregistry, with the bound directory as cwd. That was also the picker's bug — the
roster endpoint computed
project_names - config.agents, so a colliding projectname never became a row, and the form offered the configured agent while
dispatch ran the project file.
flowchart LR subgraph before["Before — the picker disagreed with dispatch"] B1["job names<br/>release-checklist"] --> B2["picker shows<br/>CONFIGURED row"] B1 --> B3["dispatch runs<br/>PROJECT file"] end subgraph after["After — one answer"] A1["job names<br/>release-checklist"] --> A2["picker shows<br/>PROJECT row<br/>+ overrides global"] A2 --> A3["dispatch runs<br/>PROJECT file"] end class B2 removed class B3 ctx class A2 added class A3 ctx class B1,A1 ctx classDef added fill:#DCFCE7,stroke:#16A34A classDef changed fill:#FEF3C7,stroke:#D97706 classDef removed fill:#FEE2E2,stroke:#DC2626,stroke-dasharray:4 3 classDef ctx fill:#E0F2FE,stroke:#0284C7🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged
The endpoint now emits the project row, suppresses the shadowed configured one,
and says
overrides global. The winner lands ondefault_agent's bindings, notthe shadowed alias's: a
.kiro/agents/*.jsonis writable by anyone who can landa branch, so inheriting a named crew's private store would turn landing a branch
into a read of that crew's memory.
ResolvedBindingsgainsresolved_source.Two callers keep their lineage via
selection_kind: a member-bound job,since a same-named project definition would re-base it and trip
parent_identity_changed; and a caller that named a provider template onpurpose. An imported job's
project_pathis re-validated on this host, asensitive or unresolvable binding cleared, and a bound job restored paused.
A crew alias and the provider template it dispatches are two different
backend-visible names, so the member opt-out judges both — once, as
agent_discovery.py:agent_binding_is_shadowed, whichagent.py'sfork-governance refusal calls too, so neither name sees a stale snapshot.
The fire path's per-job binding cache is evicted on job removal through one
chokepoint and length-checked per string; its size already mirrors the live job
list. A stateless job mints a fresh key per fire, so the prune matches on the
job-id prefix.
A bound job is owner-only to read: a non-owner sees neither the directory nor
its output, replayed chat rows included.
The reset notice beside the Agent field now outlives the roster settling:
emptying the directory ran the clear-on-unbind effect twice, and the second pass
erased the first's notice.
The field is Project directory, matching the folder-settings field that uses
this picker. Three smaller fixes ride along, each a harm this work exposed:
ProjectPickergains Radix scroll/dismiss handling; the enable route rejects anon-boolean
enabledwith a 400 instead of coercing it; and the roster resolvesscope from
requesting_slot_project, so a request no longer answers for whicheverunrelated tab happened to be focused.
src/kiro_crew/configResolvedBindingssrc/kiro_crew/cron.pysrc/kiro_crew/cron_servicemodel.pycarriesproject_path,fields.pyvalidates it,store.pypersists and re-validates it on import, andexecution.pyresolves the agent at fire timesrc/kiro_crew/cron_history.pysrc/kiro_crew/session_agent_selection.pyselection_kind, the field the two preserved-lineage callers ride so neither needs a second switchsrc/kiro_crew/execution_context.pysrc/kiro_crew/slackcron.fire.project_bound_job); skip log lines readredact_log_via_context; and the three binding pending-work probes are awaited through_subagent_work_pending, whose store read runs off the event loopsrc/kiro_crew/dashboardsrc/kiro_crew/security+portability.pyresolve_project_pathverdictdocs.github/black-baseline.txtTakeover fixes (second commit)
Three blocking findings from #9201's GPT review, each traced in the code:
slotslist is deliberately unfiltered, but each row quotes its newest turn (last_message,prompt_preview,options). A visible project-bound job's output therefore reached every dashboard user.DashboardState.serialize_slotnow blanks those fields outside the owner boundary (include_check_status) for acron-slot whose newest turn is not explicitlyproject_bound: False, the same unknown-is-withheld ruleproject_output_visible_to_non_ownerapplies to frames._reproject_slotsrestores them on the owner view for those rows only, so the single-pass serialization holds.session_allocation'sPool decisionline loggedcwd, and the log-ring replay admits any dashboard-user socket, exposing the path the cron API withholds. It now logs the cwd's relation to the pool (none/pool/other), which is what the pool decision turns on. Chose redaction at emission over making the log stream owner-only, matching the redaction this PR already applies to its other project-path log lines._cron_session_binding_requires_resetresets the live session but nothing rewrote the durable execution record, so the single-agent path's plainbind_session_executionraisedsession already belongs to another executionon every later fire.cron_service.identity.rebind_own_cron_executionnow replaces the record before acquisition (compare-and-set against a fresh read, like the sequence path), only when the record is one this job published: same member, store and app, or the Global project-override shape. A record naming another member or app is still refused. Not conditioned on "reset on this fire", so a fire that reset and then failed to acquire is repaired on the next one.Backwards compatibility
handlers/side.py:_run_side_turn-- chat -- slot dirchat_threads.py:_run_thread_turn-- chat -- slot dirchat_handlers.py:api_chat-- chat -- stored dirsession_agent_selection.py:record_provider_agent_switch-- chathandlers/cron.py:_resolve_cron_bindings-- cron -- opt-outThose are every reader of the chat-slot precedence flip; all live under
src/kiro_crew/. One behaviour change on upgrade:project_winsis new here andallow_project_overridedefaults true, so the flip is NOT confined to this PR'scron bindings -- any already-bound session whose project directory declares an
agent sharing a configured alias's name resolves the project's file after upgrade
where it resolved the alias before. Each reader above is a chat caller passing a
project directory, except the cron one, the only caller that opts out
(
allow_project_override=not member_id).That flip is the intended correction: kiro-cli already resolves
<project>/.kiro/agentsfirst with the project as cwd, so the alias rowadvertised one answer while another ran, and inheriting the shadowed crew's
private store would let anyone who can land a branch read that crew's memory.
Outside the project directory the alias is untouched, pinned by
test_config_loader.py::test_the_alias_is_untouched_outside_the_project.Otherwise compatible. The alias-plus-template pair check reaches only the member
opt-out (
allow_project_override=False), which no caller on main passes; anordinary resolution receives an empty effective name, so its probe and its answer
are unchanged, and
agent.py's fork-governance refusal keeps its existingalias-or-declared-name semantics through the shared helper. A job that stops
resolving is one whose project directory declares the crew alias's provider
template, and it takes the same named skip as any other unresolved name rather
than running the project's spec under the member's private memory store.
Takeover commit:
website/src/hooks/useAgentSync.ts,website/src/components/commandPalette/providers/recentsProvider.ts,website/src/pages/members/*(last_message/prompt_preview) -- chat / crew page -- a non-owner sees an empty preview for a project-boundcron-slot, the same shape every fresh slot already has; the owner view is unchanged (test_cron_project_bound_slot_previews.py)options/has_optionson a non-owner's view of that slot -- chat -- the option chips are not offered to a non-owner there; the owner still gets themPool decisionINFO line (cwd=,pool_cwd=) -- log stream -- now reportscwd=none|pool|otherand drops both paths; nothing parses the line (test_session_pool.py::...::test_pool_decision_log_names_no_cwd_path)Release note: a job whose agent no longer resolves now skips with a named reason instead of quietly running the default agent, and a one-shot in that state is parked disabled. Jobs that relied on the silent fallback stop running after upgrade.
Tests
Backend, in
test/:with the non-colliding rows on both sides untouched
config.agentsname, notits persisted
member_id. The two are different key spaces —resolve_crew_identityreturnscrew_agentverbatim and its consumers look itup by name, while
member_idis a lossy slug stored as a field — so passing theid lost the crew's pinned model, effort and watchdog windows, and made
session_capabilitiesfail closed. Pinned on single AND sequence dispatch witha member whose display name is deliberately NOT slug-shaped, since a
slug-shaped fixture is exactly what hid this. A deleted member still fires,
falling back to the resolved alias rather than raising.
resolved_sourcedistinguishes the case the other fields cannotown message, and neither spends an auto-pause strike — and a one-shot is
parked disabled rather than left enabled, in memory and on disk, because a
past-due
atjob is due again on every scan and would refire with no delay. Apool-starved one-shot is deliberately not parked: that condition self-heals
the store write commits, so a failed save cannot erase the one handle that
canceland the reaper use to reach a live sessionresolves as a project agent instead of reporting the member unavailable, and
records no private store under a name the project file answers
owner gate is audited on both outcomes — including a clear, which removes
the project scope and is the same privileged field transition as setting one,
so it is audited by the field's presence rather than by its value
GET /api/cronsreturnsproject_pathonly to the owner view, on the sameboundary as the secret-grant metadata beside it; a non-owner's save of that
blanked field is refused 403 and leaves the owner's binding intact
src/kiro_crew/messaging/commands.pyrefuses acron resumeof aproject-bound job: a channel allow-list says who may type, not who owns the
folder, so the shared messaging layer — which carries no authenticated owner
identity — reuses the dashboard's own atomic
expect_project_pathprecondition, names the refusal, and points the caller at the owner dashboard
or the CLI.
cron pausestays open because it removes execution permissionrather than granting it
string — including a pin that a maximal legitimate composed key is still
admitted, since a refused admission would defer that job's fire silently and
permanently
fresh-per-fire key cannot accumulate
and a project-won member keeps the unowned execution rather than the job's.
Deliberately runs the real resolver: every other sequence test stubs it with
one return value, so a per-member resolution bug is invisible to them
sink that raises leaves the refusal intact rather than letting the fire
dispatch
from all three skip log lines
roster is populated
the synchronous entry is asserted never called, at both fire paths and in the
prune, so a double that models only the sync method cannot silently pass
Frontend tests moved with the UI to #17580.
Takeover commit:
test/test_cron_rebind_own_execution.py: the plain bind refuses a moved identity (the old failure, pinned); the project-override and capture shapes each replace the other; a template move on the same store is replaced; another member's or app's record is left for the bind to refuse; a matching, absent or unattributable record is not rewrittentest/test_cron_project_bound_slot_previews.py: a project-bound row is blank on the bare and dashboard-user views and full on the owner view, across both direct serialization and the broadcast's derived views; an unstamped cron row and a follow-up typed into a project-bound slot are withheld; an explicitly unbound cron row and an ordinary chat slot are unchangedtest/test_session_pool.py::test_pool_decision_log_names_no_cwd_path: the requested folder never appears in the linetest/test_execution_context.py::test_every_binder_declares_whether_it_vouches: registers the new binder asvouch=False(acron:key is never an own-store caller slot)Manual verification
Walked the whole surface on an isolated gateway against two fixture checkouts —
one declaring a colliding agent plus a project-only one, one declaring a
different agent — covering the field, the merged picker, the collision marker,
the A→B directory switch, all three save rejections, and both fire-time skips.
Takeover commit: unit coverage only. The three fixes are backend serialization, a log format and an identity-record write, each exercised against the real
DashboardState,SessionManagerandbind_session_execution; no UI changed.Related Issues
Closes #8952
Supersedes #9201 (same work, re-opened in-repo; author @mbajaj92)
UI half: #17580 (stacked on this PR)
Checklist
feat|fix|docs|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.