Skip to content

fix(cron): let a crew member manage its schedules from any of its sessions - #19359

Open
akushonkamen wants to merge 2 commits into
kirodotdev:mainfrom
akushonkamen:fix/19295-member-scoped-cron-ownership
Open

akushonkamen wants to merge 2 commits into
kirodotdev:mainfrom
akushonkamen:fix/19295-member-scoped-cron-ownership

Conversation

@akushonkamen

@akushonkamen akushonkamen commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A crew member can see and manage the cron schedules it created from any of its sessions, not only the one that happened to create them.

The bug (#19295): a crew member creates a cron job from its pinned-DM session. In any of the member's later sessions, cron_list no longer shows the job, and every mutating verb answers the shared "job not found" refusal — while the job keeps firing on schedule. Creating a schedule and deleting the same schedule are therefore reachable from different scopes: only the CLI or the Schedule page can still manage it.

Why it matters

Every pinned-DM conversation with a crew member presents a new session key, so this hits the common case, not an edge: the member's very next session loses sight of its own schedule while the schedule keeps firing. An agent on the MCP surface has no fallback surface (the CLI and the dashboard are outside its reach), so the member can neither audit nor clean up schedules it authored.

Not a goal

  • No change to delivery: a job still posts its runs to the session that created it. cron_job.session_key keeps its delivery meaning untouched.
  • No cross-member or cross-session sharing: another member, or a session that names no member, still reaches nothing.
  • No change for ownerless rows (kirocrew cron add, the onboarding importer): the CLI and the Schedule page remain their only management surface.

What changed

Root cause: the MCP cron ownership gate authorized a row by exact session_key equality only — _owned_by (the one scope function gating BOTH reads and writes, pre-fix mcp_cron.py:3279) and _check_cron_job_ownership (all six mutating verbs, pre-fix :3099). One field carried two meanings: cron_job.session_key is both the authorization owner and the delivery target. Delivery is genuinely per-session; authorization inherited that per-session narrowing, so a member's later session — a different key — was locked out of its own job.

The fix adds a second arm to the gate:

  • New mcp_cron._authz_member_id (src/kiro_crew/mcp_cron.py:2890) reads the member SLOT a vouched key names off the key's own structure (member-<slug>[.memory-<store>] under the dashboard_/dashboard: layer prefixes). The match is by SLOT, not slug: only the layer prefix is stripped, so the .memory-<store> suffix stays part of the compared identity and a different memory store of the same member stays out of scope (read_dm_binding_for_slot keeps store generations apart on purpose). This is the same derivation execution_context.revouch_at_verified_admission trusts at gate-verified admission, and it never consults a session record (the record is what the subject session writes, so it decides nothing here). The same derivation is applied on the row side to the row's recorded owner session_key, so both sides of the member match are key structure the gateway authors — never a caller-writable field.
  • _owned_by (the ONE scope — reads and writes widen together) and _check_cron_job_ownership (all six verbs) accept a second way to reach a row: the member the ROW's own recorded session_key names — _authz_member_id applied to the stored owner key — equal to the member the caller's vouched key names (src/kiro_crew/mcp_cron.py:3366, :3159). job.member_id is never consulted for authorization: it is the execution member cron_add lets the CALLER choose, so it records who a job RUNS AS, never who owns it.
  • Everything else stands verbatim: exact-key matches still win; an ownerless row stays outside every session's scope in both directions even when it names a member it runs as; an empty caller key still reaches nothing; keys that name no member (channel/Slack keys, cron: run keys, ordinary chat- slots) gain nothing; the anti-enumeration refusal and its SEL audit lines are unchanged; delivery still posts to the creating session.

Spec updated in the same commit: docs/system-specs/modules/learn-cron-dashboard.md ("Session scoping" bullet).

Security review response (push 2, 6ed1f8fa)

Three blocking reviews on the first push (Design, First-Principles, and the GPT security review) all made the same point, and they were right: the first cut matched the member arm on job.member_id, but that field is the execution member cron_add lets the caller choose ("Crew Member responsible for this schedule… Omit to inherit", mcp_cron.py:2011; bind_cron_memory persists that pick beside the creator's session). A field any creating session may fill is a "runs-as" label, not an ownership record — a dashboard:chat-… session or another member's DM could create a row labelled member_id="alice" and Alice's sessions would then reach it (cron_list, every mutating verb, cron_remove_all).

The fix keeps the second arm but re-anchors both of its sides on key structure the gateway authors:

  • The row side now reads the member off the ROW's own recorded session_key (_authz_member_id(job.session_key)) instead of off job.member_id. A member-created row carries that member in its own key, so the issue's goal is unchanged; a row created outside the member's sessions stays out of reach however it is labelled.
  • job.member_id is never read for authorization anywhere; it keeps only its execution meaning.
  • Exact-key access, ownerless-row refusals, the no-member-key rule and the anti-enumeration wording are all unchanged.

New negative coverage (the attack's own shape): test_a_row_created_elsewhere_stays_out_of_the_member_it_names seeds member_id="alice" from OUTSIDE the creating session on rows created by an ordinary chat session, another member's session, and the other prefix spelling, and asserts Alice's session gets none of them — list, every mutating verb, and the bulk sweep, with the shared refusal text. test_the_row_reaches_the_member_on_its_own_key_not_the_labelled_field pins the positive half: the widening follows the row's key, not the labelled field.

Revision for bolichen97's correctness review (2026-10-18, 36c7d60fb)

All three points from the 2026-10-12 review are addressed:

  1. Store generations no longer match. The member arm previously went through slug_from_dm_slot_key, which drops the .memory-<store> suffix, so a job created from member-alice.memory-alpha was reachable from any other store of the member. The comparison now strips only the dashboard_ / dashboard: prefix and keeps the store suffix — a different store of the same member (and the storeless spelling) stays out of scope, both directions. New pinning test: test_a_different_store_of_the_same_member_stays_out_of_scope (creator dashboard:member-alice.memory-alpha vs callers dashboard_member-alice.memory-beta and dashboard:member-alice; cron_list, every mutating verb, cron_remove_all, plus the reverse direction; verified to FAIL on the previous comparison and pass on this one).
  2. Concrete key pair from the Cron ownership should be scoped to the crew member, not the creating session #19295 repro. The repro records no literal key strings (checked the issue body and its whole timeline), so here is the pair as the code on current main actually presents it: the pinned-DM slot is always member-<slug>[.memory-<store>] (members.py dm_slot_key), traveling as the chat session key dashboard_member-<slug> and the canonical session-map alias dashboard:member-<slug>. So the repro's creator key vs later caller key differ — when they differ — only by that layer-prefix spelling of the SAME slot; nothing in the repro turns on a .memory-<store> change (the store suffix is generation-scoped, and a resumed conversation keeps its slot). That puts the repro in the "only the prefix spelling" branch of the review's item 2, which is exactly what the narrowed comparison ships — and the store suffix stays in the comparison as hardening.
  3. Stale description text fixed. The mechanism bullet above now describes the slot match off each key's own structure; job.member_id is read for authorization nowhere (kept only its "runs as" meaning), and the spec bullet ("Session scoping") was updated in the same commit.

Evidence on the rebased HEAD (base 96c95887 = current origin/main, rebase resolved one spec conflict in favor of main's "Job execution" bullet plus this PR's "Session scoping" bullet; branch stays at 2 commits):

  • .venv/bin/pytest test/test_mcp_cron_caller_identity.py -q → 48 passed (47 before + the new store test).
  • Cron ownership subset → 641 passed: test_mcp_cron_security.py test_cron_session_scope.py test_cron_owner_caveats.py test_cron_member_selection_capture.py test_r12_cron_owner_gate.py test_cron_adopt_ownerless.py test_mcp_cron.py test_cron_refactor_contract.py.
  • flake8 and isort --check-only on the changed Python files exit 0; scripts/check_black_formatting.py PASS; mypy src/kiro_crew/mcp_cron.py src/kiro_crew/cron.py → "Success: no issues found in 2 source files".
  • Note: this local run is Python 3.14 in a fresh venv; the two capture tests initially errored on a missing markdown_it until it was installed — environment-only, not a diff failure.

Backwards compatibility

Compatible: this only widens who may reach an existing row — a member reaching its own job. Nothing that works today stops working: exact-key matches keep winning, ownerless rows and unidentifiable callers keep today's refusals in both directions, and the stored CronJob shape is untouched (member_id was already recorded at creation; no field renamed, removed, or revalidated).

Removes nothing: the diff widens two authorization predicates and their spec documentation; no key, field, path, or command is renamed, rejected, or taken away.

Tests

Seven new cases in test/test_mcp_cron_caller_identity.py, one per contract edge:

  • test_a_member_reaches_its_own_job_from_a_later_session — the issue's shape: a new session of the same member lists and manages the job a prior session created.
  • test_cron_remove_all_sweeps_the_member_rows_from_any_of_its_sessions — the write-side sweep covers member-bound rows from any of the member's sessions.
  • test_another_member_stays_outside_the_scope — a different member still sees nothing.
  • test_a_key_that_names_no_member_gains_nothing — channel/Slack keys, cron: run keys and ordinary chat- slots gain no access.
  • test_the_row_reaches_the_member_on_its_own_key_not_the_labelled_field — the widening follows the row's OWN session key: a row that records no execution member at all still belongs to the member whose session created it.
  • test_a_row_created_elsewhere_stays_out_of_the_member_it_names (×3 creator spellings) — the security negative: a row created by an ordinary chat session, another member's session, or the other prefix spelling, labelled member_id="alice" from OUTSIDE the creating session, stays out of Alice's scope for cron_list, every mutating verb and cron_remove_all, with the shared anti-enumeration refusal.
  • test_an_ownerless_row_stays_out_of_scope_even_when_member_bound — an ownerless row is outside every session's scope in both directions even when it names a member.
  • test_an_unidentifiable_caller_still_reaches_nothing — an empty caller key still reaches nothing.

Evidence (re-run this session on HEAD 6ed1f8fa, base 0a4702109 = current origin/main; branch is 2 commits, within the checklist limit):

  • timeout 240 .venv/bin/pytest test/test_mcp_cron_security.py -q --no-header → 534 passed (7.51s).
  • .venv/bin/pytest test/test_mcp_cron_caller_identity.py -q → 47 passed on HEAD 6ed1f8fa (44 on the first push + 4 new/reworked − 1 replaced). The new security negative, test_a_row_created_elsewhere_stays_out_of_the_member_it_names, ran failed before this commit under the first cut's job.member_id arm (Alice reached rows other sessions had labelled with her id) and passes now.
  • .venv/bin/pytest test/ -q -k 'cron and not slow' → 4955 passed / 34 skipped / 1 failed (624.63s). The one failure (test_cron.py::TestCronService::test_mutation_after_deeply_nested_load_does_not_overwrite_the_store, DID NOT RAISE CronStoreUnreadable) reproduces identically on pristine origin/main 0a4702109 (verified in a clean worktree of the base commit) — a pre-existing environment failure touching the store loader this diff never reads.
  • Cron ownership subset → 750 passed: test_mcp_cron_security.py test_cron_session_scope.py test_cron_owner_caveats.py test_cron_member_selection_capture.py test_r12_cron_owner_gate.py test_cron_adopt_ownerless.py test_mcp_cron.py test_cron_refactor_contract.py.
  • The four CI check gates, each with CI's own base ref (BRAND_BASE_REF / COMMENT_HISTORY_BASE_REF / HARNESS_BASE_REF = 0a470210903bf500a796e8bbf7bcca8bd3579803): check_black_formatting PASS ("nothing in scope is unformatted outside the baseline"), check_brand_name PASS ("no misspellings of 'Kiro Crew' in the lines added since ..."), check_comment_history PASS ("no history narration on the lines this change adds", 3 changed files), check_harness_parity PASS ("Kiro identity tested positively in the lines added since ...").
  • Local gates: flake8 on the three changed Python files exit 0; isort exit 0; scripts/check_black_formatting.py exit 0; mypy src/kiro_crew/mcp_cron.py src/kiro_crew/cron.py → "no issues found in 2 source files"; scripts/check_harness_parity.py, scripts/check_subprocess_encoding.py, scripts/check_sync_io_in_async.py, scripts/check_brand_name.py all exit 0; COMMENT_HISTORY_BASE_REF=origin/main scripts/check_comment_history.py exit 0.
  • scripts/local-gate.py (timeout 240) exceeds its wall-clock budget on this box (xdist worker budget: 1 worker; 666 related backend test files; exit 124) — the cron-named regression above (4953 tests) is the strictly larger equivalent coverage. Ruff: the repo pins flake8==7.1.0 + black + isort and carries no ruff dependency or configuration (pyproject.toml; no ruff step in ci.yml), so the repo's own lint gates above are the lint signal.

Manual verification

N/A — unit coverage sufficient: the gate is exercised end-to-end through the MCP tool inner dispatcher (_call_tool_inner) with vouched caller keys, the same surface a chat session drives; this diff touches no UI surface.

Related Issues

Fixes #19295

Process note: I claimed this issue in #19295 (comment) (with an AI disclosure); afterwards the KiroCrewCaptain triage bot auto-assigned the issue to a maintainer account. No one else has opened a PR for it — the only claim on the timeline is mine. Opening this PR now; happy to hand it to the assigned maintainer if they'd rather carry it.

Pattern harvest

Rule candidate: review-prompt
Pattern: an authorization predicate must derive the principal from a field dedicated to identity; when one row field carries two meanings (here cron_job.session_key — authz owner AND delivery target), every gate built on it silently narrows to the narrower meaning's scope.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (fix(cron): ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines (flake8/isort/black/mypy and the repo check gates above all clean)
  • Documentation updated (docs/system-specs/modules/learn-cron-dashboard.md "Session scoping")
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license (see the Licensing section of CONTRIBUTING.md); this contribution is made under those terms.


Transparency: this fix was authored with AI assistance (Claude, via an automated contributor workflow), reviewed and tested by me as recorded above — disclosed voluntarily; CONTRIBUTING.md sets no disclosure requirement.

@akushonkamen
akushonkamen requested review from a team and KiroCrewCaptain as code owners October 12, 2026 08:55
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@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 Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision ff52061cbe8698a3f6be139039416b8d1e5c68be touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — 🟡 CONCERNS

Design-level review of ff52061cbe8698a3f6be139039416b8d1e5c68be via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The fix depends on an unproven cause: the #19295 repro records no keys, and this change only joins the dashboard_/dashboard: spellings of one slot.

Watch

  • The "member arm" is really a prefix fold, applied to member slots only. The description says "every pinned-DM conversation … presents a new session key". The revision note then says the two keys "differ — when they differ — only by that layer-prefix spelling of the SAME slot". Because _authz_member_id keeps the store suffix, the "member principal" arm only treats dashboard_member-X and dashboard:member-X as the same owner. If the lockout comes from a different slot or store, a member's later session is still locked out and the bug stays open. If it comes from prefix spelling, the cause is generic: ledger_wake.py:174, work_ledger.py:1748 and others already try both spellings for any slot. An ordinary chat- slot that flips spelling would still lose its jobs.
    Clears when: a test reproduces Cron ownership should be scoped to the crew member, not the creating session #19295 from the real pinned-DM entry point, showing which two keys _authz_session_key vouches for the creating turn and the later turn, and the fix matches what that test shows.
  • The release path still uses exact spellings. The patched cron.py docstring still says non-cron owners "have ONE spelling each". cron_owner_matches (history-delete release) still compares exactly, so it can skip a row the gate now treats as owned by the same principal.
    Clears when: either the release path folds the same prefixes, or the docstring and spec say why the gate and the release path compare owners differently.

Suggestions

  • Normalize the vouched key and the stored owner key in one place, either one canonical prefix at cron_add/the gate or a shared helper that cron_owner_matches also uses. Do this instead of a member-only arm.

[DESIGN-REVIEWED] ff52061

Description read

[DESCRIPTION-READ] ad7ce6f8f2702f4f0070d9c9ff41356ccbb253bee63c7a3ea54f7387d6fb714e

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 Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🟡 CONCERNS

Premise-level review of ff52061cbe8698a3f6be139039416b8d1e5c68be via the fork AI-review pipeline — 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The member arm only joins the dashboard_/dashboard: spellings of one slot, which affects every dashboard slot, yet the fix is gated to member keys.

Not justified as shipped

  • Item 1 — symptom-level: after the store-suffix narrowing, _authz_member_id only removes the prefix. The cause is that the gate compares two spellings of one slot without normalizing them. Grepping f"dashboard_{ and f"dashboard:{ turns up both spellings for ordinary slots too (_shared.py:3603, slot_builders.py:481), so dashboard_chat-* and dashboard:chat-* rows stay split (item 4). The description also says "Every pinned-DM conversation … presents a new session key", but its own item 2 says the keys "differ … only by that layer-prefix spelling".
    Subtraction: replace the member arm with one prefix fold applied to both keys in _owned_by and _check_cron_job_ownership, and drop the member concept from the gate.
    Clears when: the gate folds prefixes for all dashboard keys, or a repro shows member keys differing by more than the prefix.
  • Item 3 — duplicate of the inline ("dashboard_", "dashboard:") strip loop: the pattern already appears 4 times (members.py:140, members.py:1534, eventlog_hooks.py:825, execution_context.py:692), and this is the fifth.
    Subtraction: delete the loop in _authz_member_id and reuse an existing strip.
    Clears when: no new copy of the loop ships.

What this change ships

Inventory (5 items) — 2 justified

Intent: a crew member can manage the cron jobs it created from its later sessions. This is a FIX.

  1. A member session reaches jobs created under the slot's other prefix spelling — symptom-level
  2. cron_remove_all from a member session also sweeps those jobs — justified
  3. New key-to-slot helper _authz_member_id — duplicate of the inline prefix-strip loop
  4. Ordinary chat sessions still lose jobs created under the other prefix spelling — symptom-level (unfixed sibling)
  5. Spec and docstring rewrites for the widened scope — justified

[FIRST-PRINCIPLES-REVIEWED] ff52061

Description read

[DESCRIPTION-READ] 8f437dc3e96efa9b728bd33c064568db4f2770ff90e8036c5ca2376222b95f47

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.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed ff52061cbe8698a3f6be139039416b8d1e5c68be via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] ff52061

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed ff52061cbe8698a3f6be139039416b8d1e5c68be via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ff52061

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@akushonkamen

Copy link
Copy Markdown
Contributor Author

Response to the three BLOCK verdicts — fixed on push 6ed1f8fa

All three blocking reviews (Design, First Principles, and the GPT security review) converge on one finding, and it was correct: job.member_id is the execution member cron_add lets the caller choose ("Crew Member responsible for this schedule… Omit to inherit", mcp_cron.py:2011; split_cron_agent_member sets it from a plain agent=<member>; bind_cron_memory persists that pick beside the creator's own session). The first cut's arm j.member_id == member_id and j.session_key therefore let any creating session hand a row to any member, and every session whose key names that member then reached it — list, update, remove, cron_remove_all. A "runs-as" label is not an ownership record. Agreed and fixed.

Fix (the remedy the security review itself named)

Both authorization predicates now derive the member-owner match from the creating job.session_key, preserving exact-key access, and never authorize through the caller-selectable execution member_id:

  • _owned_by (src/kiro_crew/mcp_cron.py:3362): j.session_key == session_key or (j.session_key and _authz_member_id(j.session_key) == member_id)
  • _check_cron_job_ownership (src/kiro_crew/mcp_cron.py:3159): if not (member_id and _authz_member_id(job.session_key) == member_id)

Both sides of the match are key structure the gateway authors — is_member_session_key + slug_from_dm_slot_key under the dashboard_/dashboard: prefixes, the same derivation execution_context.revouch_at_verified_admission trusts at verified admission — applied to the caller's vouched key and to the row's recorded owner key. job.member_id is read for authorization nowhere and keeps only its execution "runs as" meaning.

On the First-Principles premise (that the issue's repro differs only by the layer prefix): the issue text says "a crew member's conversation spans many sessions over its life, and each resumed session gets a new key", so the arm is kept — but it is now anchored exclusively on key structure on both sides, which is the stricter shape that review's own remedy (exact match after the prefix strip _authz_member_id already performs) allows. A row created outside the member's sessions stays out of reach however it is labelled.

Negative coverage — the attack's own shape

test_a_row_created_elsewhere_stays_out_of_the_member_it_names (test/test_mcp_cron_caller_identity.py) seeds member_id="alice" from outside the creating session on rows created by (a) an ordinary dashboard:chat-4242 session, (b) dashboard:member-bob, (c) dashboard_member-bob.memory-alpha, then asserts Alice's dashboard:member-alice session reaches none of them: cron_list withholds the row, cron_remove_all does not take it, and every mutating verb answers the shared anti-enumeration refusal (byte-identical to the absent-id answer). The positive half is pinned separately: test_the_row_reaches_the_member_on_its_own_key_not_the_labelled_field — a member-created row with no execution member recorded at all still follows its creator's member.

Evidence on HEAD 6ed1f8fa (base 0a4702109 = current origin/main; branch = 2 commits)

  • .venv/bin/pytest test/test_mcp_cron_caller_identity.py -q → 47 passed (44 on the first push, +4 new/reworked, −1 replaced by the key-anchored positive).
  • Cron ownership subset → 750 passed: test_mcp_cron_security.py test_cron_session_scope.py test_cron_owner_caveats.py test_cron_member_selection_capture.py test_r12_cron_owner_gate.py test_cron_adopt_ownerless.py test_mcp_cron.py test_cron_refactor_contract.py.
  • Full cron selection .venv/bin/pytest test/ -q -k 'cron and not slow' → 4955 passed / 34 skipped / 1 failed (624.63s). The one failure (test_cron.py::TestCronService::test_mutation_after_deeply_nested_load_does_not_overwrite_the_store, DID NOT RAISE CronStoreUnreadable) reproduces identically on pristine origin/main 0a4702109 (verified in a clean worktree of the base commit) — a pre-existing environment failure in the store loader this diff never reads.
  • The four CI check gates with CI's own base-ref env (BRAND_BASE_REF / COMMENT_HISTORY_BASE_REF / HARNESS_BASE_REF = 0a470210903bf500a796e8bbf7bcca8bd3579803): check_black_formatting PASS, check_brand_name PASS ("no misspellings of 'Kiro Crew' in the lines added since …"), check_comment_history PASS ("no history narration on the lines this change adds", 3 changed files), check_harness_parity PASS ("Kiro identity tested positively in the lines added since …").
  • flake8 and isort --check-only on the three changed Python files exit 0; mypy src/kiro_crew/mcp_cron.py src/kiro_crew/cron.py → "Success: no issues found in 2 source files".

Spec updated in the same commit (docs/system-specs/modules/learn-cron-dashboard.md, "Session scoping"): the second arm is described as widening through the row's own recorded owner key, never through job.member_id.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Thanks for picking this up. I read the diff at 6ed1f8fa for correctness only. Two points:

  1. The member arm also crosses memory-store slots. _authz_member_id goes through slug_from_dm_slot_key, which drops the .memory-<store> suffix. So a job created from member-alice.memory-alpha becomes reachable from member-alice (and from any other store of the same member). read_dm_binding_for_slot keeps those slots apart on purpose. The tests only exercise dashboard:member-alice vs dashboard_member-alice, which are the same slot under its two layer prefixes. If that prefix difference is the real cause, comparing the two keys after stripping only the dashboard_ / dashboard: prefix (keeping the store suffix) fixes the report without widening across stores. A test that pins "a different store of the same member stays out of scope" would lock it in.

  2. Which key does the later session actually present? On main the pinned DM key is always member-<slug>[.memory-<store>], so a resumed conversation should present the same slot. Could you add the concrete key pair from the Cron ownership should be scoped to the crew member, not the creating session #19295 repro (creator key vs later caller key) to the description? If it is only the prefix spelling, item 1's narrower comparison is enough. If it is something else, the test should use that real pair.

The description still says the arm reads job.member_id, while the code (correctly) does not. Aligning it would help the next reviewer.

@akushonkamen

Copy link
Copy Markdown
Contributor Author

Thanks for the careful correctness read, @bolichen97 — both points land. 1) Agreed: the member arm should not widen across memory-store slots; comparing the two keys after stripping only the dashboard_ / dashboard: prefix (keeping the .memory-<store> suffix) fixes the report without widening, and we'll add the test pinning that a different store of the same member stays out of scope. 2) We'll pull the concrete creator/caller key pair from the #19295 repro into the description — if it turns out to be only the prefix spelling, item 1's narrower comparison settles it. Also updating the stale description line about job.member_id. Pushing a revision shortly.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 15, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Status check (2026-10-17 PT): the bug in #19295 still reproduces on main 8c4a3d9 (_owned_by in src/kiro_crew/mcp_cron.py still matches by exact session key). This PR now conflicts with main (labelled 2026-10-15) and still needs the two changes agreed on 2026-10-13: keep the .memory-<store> suffix in the comparison so a different store of the same member stays out of scope (with a test), and put the concrete creator/caller key pair from the repro in the description. Once rebased with those, it goes back through review. Because this widens who may change a job, it will also need a non-bolichen97 maintainer's approval.

@akushonkamen

Copy link
Copy Markdown
Contributor Author

Thanks for the status check. Agreed on both outstanding items: we'll rebase onto current main and push a revision that strips only the dashboard_ / dashboard: prefix while keeping the .memory-<store> suffix in the comparison (with the test pinning that a different store of the same member stays out of scope), and add the concrete creator/caller key pair from the #19295 repro to the description along with the corrected job.member_id line. We also understand the widened-authorization approval needs to come from a maintainer other than you — no action expected from you on that.

@akushonkamen
akushonkamen force-pushed the fix/19295-member-scoped-cron-ownership branch from 6ed1f8f to 36c7d60 Compare October 18, 2026 06:11
@akushonkamen

Copy link
Copy Markdown
Contributor Author

Thanks for the status check, @bolichen97 — rebased onto current main (96c95887) and pushed as 36c7d60fb (still 2 commits; the rebase hit one conflict in the spec's "Session scoping" area, resolved as main's "Job execution" bullet plus this PR's rewritten "Session scoping" bullet). Both agreed items are in:

1. The comparison now keeps the .memory-<store> suffix. You were right that going through slug_from_dm_slot_key let the member arm cross memory-store generations. _authz_member_id (src/kiro_crew/mcp_cron.py:2890) now strips only the dashboard_ / dashboard: layer prefix and compares the SLOT — member-<slug>[.memory-<store>] — so a different store of the same member, and the storeless spelling, stay out of scope in both directions. New pinning test: test_a_different_store_of_the_same_member_stays_out_of_scope (test/test_mcp_cron_caller_identity.py:766) — creator dashboard:member-alice.memory-alpha, callers dashboard_member-alice.memory-beta and dashboard:member-alice; asserts cron_list withholds the row, every mutating verb answers the shared refusal, cron_remove_all does not take it, and the reverse direction (storeless creator vs store caller) behaves the same. Verified it fails on the previous comparison and passes on this one.

2. The concrete key pair from the #19295 repro. The repro records no literal key strings (we checked the issue body and its full timeline), so here is the pair as current main actually presents it: the pinned-DM slot is always member-<slug>[.memory-<store>] (members.py dm_slot_key), traveling as the chat session key dashboard_member-<slug> and the canonical session-map alias dashboard:member-<slug>. So the creator key vs the later caller key differ — when they differ at all — only by that layer-prefix spelling of the SAME slot; nothing in the repro turns on a .memory-<store> change. That puts the repro in your item-2 "only the prefix spelling" branch, which is exactly what the narrowed comparison ships, with the store suffix kept as hardening. Added to the PR description.

3. Stale description text. The description's mechanism bullet now describes the member/slot match read off each key's own structure; job.member_id is read for authorization nowhere, and the spec bullet was corrected in the same commit.

Evidence on the rebased HEAD (36c7d60fb, base 96c95887 = current origin/main): test_mcp_cron_caller_identity.py → 48 passed; cron ownership subset (test_mcp_cron_security.py test_cron_session_scope.py test_cron_owner_caveats.py test_cron_member_selection_capture.py test_r12_cron_owner_gate.py test_cron_adopt_ownerless.py test_mcp_cron.py test_cron_refactor_contract.py) → 641 passed; flake8/isort clean on the changed files, scripts/check_black_formatting.py PASS, mypy on mcp_cron.py + cron.py clean. Environment note: fresh venv on Python 3.14; the two capture tests initially errored on a missing markdown_it dependency until installed — environment-only, not a diff failure. We understand the widened-authorization approval needs to come from a maintainer other than you.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 18, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Holding at 36c7d60. No definite defect found, but this PR cannot be approved by an automated reviewer yet.

  1. Policy: the member arm in _owned_by and _check_cron_job_ownership widens who may read, update and remove a cron job (
    def _owned_by(jobs: list[CronJob], session_key: str) -> list[CronJob]:
    """The jobs *session_key* may reach -- for reading and for writing alike.
    ONE scope, deliberately. Read and write widen together or not at all: a wider
    read scope would disclose rows (see :data:`_UNOWNED`) to a principal who may
    not be the operator, and two scopes are two chances to use the wrong one --
    ``cron_remove_all`` had already picked the wider one once. Callers of this
    function are exactly the read paths and the write path, so a caller whose
    read reaches a row can also write it, and vice versa.
    Two ways to reach a row, both naming the same principal:
    - the row's ``session_key`` equals the caller's key -- the row this exact
    session created; or
    - the row's own ``session_key`` names the same crew member the caller's key
    names. A member is one principal across all the keys its pinned DM thread
    presents, so the member's later sessions manage the schedule a member
    session created. The member is read off KEY structure on both sides
    (:func:`_authz_member_id`) -- the caller key the gateway vouches, and the
    row's recorded owner key -- never off ``job.member_id``: that field is the
    execution member ``cron_add`` lets the CALLER choose (``bind_cron_memory``
    persists the pick beside the creator's session), so it records who a job
    runs as, and a field any caller may fill is no evidence of who owns a row.
    Ownerless rows take part in neither arm: the member arm widens through the
    row's recorded owner key, so a row with no session stays outside every scope
    (see :data:`_UNOWNED`) even when it names a member it runs as.
    An empty *session_key* returns nothing rather than every ownerless row, which
    is what ``j.session_key == session_key`` would otherwise mean: an
    unidentifiable caller can be sharing a pooled backend with identified ones, so
    it gets nothing at all.
    """
    if not session_key:
    return []
    member_id = _authz_member_id(session_key)
    if not member_id:
    return [j for j in jobs if j.session_key == session_key]
    return [
    j
    for j in jobs
    if j.session_key == session_key
    or (j.session_key and _authz_member_id(j.session_key) == member_id)
    ]
    ). That is an authorization change and needs a human maintainer other than bolichen97, as already requested.
  2. Conflict: the branch conflicts with main. Please rebase.
  3. Unanswered AI findings on this head: Design CONCERNS (root cause inferred, not observed), First Principles CONCERNS (member-only prefix folding, stale spec paths), the Opus finding that learn-cron-dashboard.md:520 restores stale gateway.py paths, and the GPT finding that the is_member_session_key import at mcp_cron.py:2854 is function-local. Fix or post one disposition per item.

The store-suffix narrowing agreed on 2026-10-13 is in place and pinned by a test. A rebased head needs a fresh review.

— crew-pr-reviewer (r111)

…sions

The MCP cron ownership gate matched a row's owner by exact session-key
equality only, so a job a crew member created read as owned by a stranger
from the member's own later sessions: `cron_list` omitted it and every
mutating verb answered the shared "job not found" string. The job kept
firing, manageable only from the CLI or the Schedule page - creating a cron
and deleting it were reachable from different scopes.

One field carried two meanings: `cron_job.session_key` is both the
authorization owner and the delivery target. Delivery is genuinely
per-session and stays untouched; authorization now also reads the
crew-member binding the creation capture already records
(`bind_cron_memory` -> `job.member_id`):

- New `mcp_cron._authz_member_id` reads the member a vouched key names off
  the key's own structure (`member-<slug>` under the `dashboard_`/
  `dashboard:` layer prefixes - the slug IS the member id, the same
  derivation `execution_context.revouch_at_verified_admission` trusts at
  gate-verified admission). No session record is consulted: the record is
  what the subject session writes, so it decides nothing here.
- `_owned_by` (the ONE scope, reads and writes widening together) and
  `_check_cron_job_ownership` (all six mutating verbs) accept a second way
  to reach a row: a non-empty `member_id` naming the caller's own member.
- Everything else stands verbatim. Exact-key matches still win; an
  ownerless row stays outside every session's scope in both directions even
  when it names a member it runs as (the CLI and the Schedule page remain
  its surface); an empty caller key still reaches nothing; the
  anti-enumeration refusal and its SEL audit lines are unchanged; delivery
  still posts to the creating session.

The member arm requires a session owner to widen through, so a channel or
Slack key, a `cron:` run key and an ordinary `chat-` slot - keys that name
no member - gain nothing.

Tested: test/test_mcp_cron_caller_identity.py (44 passed; the 7 new
member-scope cases ran 2 failed / 5 passed before the fix, the failures
being the issue's own shape - the member's later session could not list or
sweep its earlier job), test/test_mcp_cron_security.py 534 passed, and the
suite's cron-named subset 4947 passed / 34 skipped with 3 failures in
test_app_cron_timeout_manifest.py that fail identically on pristine
origin/main. flake8, isort, black, mypy (changed files), harness parity,
brand name, subprocess encoding, sync-io-in-async and the comment-history
gate all clean.
…t the runs-as member_id

The member arm of the cron ownership gate matched job.member_id, but that
field is the execution member cron_add lets the CALLER choose ("Crew Member
responsible for this schedule... Omit to inherit"); bind_cron_memory persists
that pick beside the creator's session. A caller-chosen label is no evidence
of who owns a row: Bob's or a dashboard chat session could create a row
labelled member_id="alice" and Alice's sessions would then reach it -- list,
update, remove, cron_remove_all.

Both authorization predicates (_owned_by, _check_cron_job_ownership) now
read the member off KEY structure on both sides: the caller's gateway-vouched
key and the row's recorded owner session_key, via _authz_member_id
(is_member_session_key + slug_from_dm_slot_key under the dashboard_
/dashboard: prefixes). job.member_id is never consulted for authorization.
Exact session-key access is unchanged, ownerless rows stay outside every
scope, and the issue's goal -- a member manages its own schedule from any of
its sessions -- is preserved: a row a member session created carries that
member in its own key.

Negative coverage: rows created by an ordinary chat session, another member's
session, and the other prefix spelling, each labelled member_id="alice" from
outside, stay unreachable from alice's session across cron_list, every
mutating verb and cron_remove_all, with the shared anti-enumeration refusal.
@akushonkamen
akushonkamen force-pushed the fix/19295-member-scoped-cron-ownership branch from 36c7d60 to ff52061 Compare October 20, 2026 04:21
@akushonkamen

Copy link
Copy Markdown
Contributor Author

Rebased onto main (790326957) to clear the merge conflicts — branch force-pushed (36c7d60fb → ff52061cb).

Conflict resolution (both conflicts were in one spec bullet in docs/system-specs/modules/learn-cron-dashboard.md): main had renamed the files the Session-scoping bullet cites (dashboard/handlers/cron.py → dashboard/handlers/cron_jobs.py, slack/gateway.py → slack/gateway_runtime/cron_delivery.py / result_egress.py + turn_approvals.py) while this PR rewrote the same bullet's _owned_by description to add the member-scoping second arm. I kept main's updated file citations and both commits' semantic additions (commit 2's wording — the arm derived from each row's own session_key slot rather than job.member_id — supersedes commit 1's, as intended by the follow-up commit). No code conflicts; cron.py / mcp_cron.py / the test file merged cleanly.

Verification: uv run python -m pytest test/test_mcp_cron_caller_identity.py test/test_r12_cron_owner_gate.py test/test_cron_owner_caveats.py test/test_cron_adopt_ownerless.py test/test_script_cron_owner_bootstrap.py → 166 passed.

Re: the 4 AI findings from crew-pr-reviewer — not addressed in this pass (kept this push to the rebase only); they still need per-item dispositions plus maintainer approval before the HOLD lifts.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 20, 2026
@akushonkamen

akushonkamen commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @iamwhatever — acknowledged on all three points at the current head (ff52061cb, rebased onto 790326957):

  1. Policy / approval: agreed this is an authorization widening and needs a human maintainer other than bolichen97. That approval is not something the author side can produce, so we are waiting on a maintainer to pick it up — no further code change is planned for this item.
  2. Conflict: resolved — rebased onto main 790326957 and force-pushed as ff52061cb (spec-bullet conflict in learn-cron-dashboard.md only; no code conflicts, 166 passed on the rebased head).
  3. The 4 AI findings: these need per-item dispositions plus a fresh review of the rebased head. We will follow up with one disposition per item (Design root-cause inference, First-Principles prefix-folding scope, the stale gateway paths in learn-cron-dashboard.md, and the function-local is_member_session_key import) as a separate revision rather than mixing them into the rebase push.

Both of bolichen97's agreed items from 2026-10-13 are already in place on this head (store-suffix kept in the comparison with the pinning test, and the concrete key pair in the description).

@akushonkamen

Copy link
Copy Markdown
Contributor Author

CI status at head ff52061cb: the only two red checks are Backend Tests (3.12, 2) and the Coverage Gate, and the gate failure is a knock-on of the shard, not a coverage shortfall.

  • Shard 2's only failure is test/test_facade_mirror_guards.py::test_every_name_the_test_trees_patch_through_a_facade_reaches_its_readers, which timed out (>120s) mid repo-tree scan — the other 7 shards, the IPv6/sandbox/container lanes, and Backend Lint & Type Check (3.12) all passed on the same head.
  • The Coverage Gate log confirms it failed closed on backend-test=failure, not on a coverage number.

This looks like the same flaky/over-budget tree-scan test rather than our diff (the shard passed at the pre-rebase heads). We can't rerun the upstream run from the fork side, so: would a maintainer mind hitting "Re-run failed jobs" on run 39369122164 (or letting us know if the timeout should be raised for that corpus gate)? Happy to follow up if it reproduces.

On @iamwhatever's policy point, no change from our 2026-10-21 note: the _owned_by member arm is an authorization widening and we agree it needs a human maintainer's approval — that's the one item parked awaiting review.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cron ownership should be scoped to the crew member, not the creating session

3 participants