Skip to content

fix(cron): rebind a cron session record whose selection a tab agent switch moved - #23150

Merged
bolichen97 merged 1 commit into
mainfrom
fix/cron-rebind-selection-fields
Oct 23, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/cron-rebind-selection-fields

Conversation

@JLargent42

@JLargent42 JLargent42 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A scheduled job keeps running after someone switches the agent on its dashboard tab, instead of failing every fire with "session already belongs to another execution".

A persistent single-agent cron fails on every fire with UnknownMemoryStore: Execution memory is unavailable: session already belongs to another execution; Global was not used. A gateway restart does not clear it, and changing the job's agent does not clear it either. The only ways out today are archiving the session or recreating the schedule.

Why it matters

Any operator who touches the agent picker on a cron's tab silently breaks that schedule for good. Each fire logs an error, and the job can walk itself into auto-pause. The remedy the log offers (recreate the schedule) loses the job's history and configuration.

Not a goal

  • Deciding whether a cron tab's agent picker should write the cron:<id> record at all. That is a separate UX/design question.
  • Repairing a record whose member, store, memory mode or app differs from the capture. That difference is still refused, exactly as before.

What changed (motivation → approach → change)

The cron tab runs under the schedule's own cron:<id> key. Switching its agent rewrites that record with a new template, the picked name, and a fresh selection_revision. Before each fire, rebind_cron_session_template in src/kiro_crew/cron_service/identity.py restores the record to the job's capture, but only when the two differ in template_id alone. So it declined this record. The plain bind_session_execution at dispatch then refused it on every fire.

Now the rebind treats every selection field as the schedule's own:

Field Restored to the capture?
template_id, selection_revision always (never identity; the revision is a publication guard)
selection_kind, selection_name when a member_id names the member, or both sides select a template
member_id, store, memory_mode, app never: a difference is still left alone and refused

The middle row has one exception. A legacy member with no persisted member_id is named by its selection_kind and selection_name, so those two still must match. The rewrite stays a compare-and-set against the value just read, unvouched. It only ever moves the record toward the job's own capture, which is what dispatch runs anyway. The per-agent cron section of docs/system-specs/modules/learn-cron-dashboard.md states the same rule.

Backwards compatibility

Compatible: the rebind accepts strictly more records than before (a superset of the template-only case), and every record it refused for an identity difference is still refused.

Removes nothing: no key, path, validator or record is removed; one more record shape is repaired instead of left alone.

Tests

test/test_cron_update_agent_capture.py:

  • test_a_dashboard_agent_switch_on_the_cron_tab_does_not_wedge_the_schedule[other-agent|same-agent] is the reporter's sequence: a fire publishes, the tab switches agent (another one, or the same one, which differs by revision alone), then cron update and the next fire. It asserts that the record equals the capture and the plain bind succeeds. It fails on main (2/2 red with the fix reverted) and passes with the fix.
  • test_a_session_record_on_another_store_is_left_alone checks that a store difference is still left alone and still refused at dispatch.
  • test_a_legacy_member_named_only_by_selection_is_left_alone checks that a member identified only by selection_kind/selection_name is not rewritten.

Determinism: the file is 20/20 green on repeats, green in reversed order, and green under -n 4. The tests use only tmp_path stores, with no clock, network or ordering dependence.

Manual verification

N/A: unit coverage drives the same functions the fire calls (rebind_cron_session_template then bind_session_execution) and the same writer the tab switch calls (record_agent_selection(replace=True)).

Related Issues

Closes #23134

Pattern harvest

Rule candidate: review-prompt
Pattern: a "repair if only X differs" compare that enumerates one field while another writer to the same record changes sibling fields (replace(current, x=...) != expected). The repair's field set must match what every writer of that record can change.

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

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision afedb1a78cba506a42aa480dc485d35a9daffe89 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 added the readiness: checking Automated validation is still running label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of afedb1a78cba506a42aa480dc485d35a9daffe89 — 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 to check.

What this change ships

Inventory (5 items) — 5 justified

Intent: keep a scheduled job firing after someone switches the agent on its dashboard tab (closes #23134). This is a FIX.

  1. A cron whose tab agent was switched to another agent now repairs itself before the next fire, instead of failing on every fire. — justified
  2. Re-picking the same agent on the tab (only the revision differs) no longer wedges the schedule. — justified
  3. A session record on a different member, store, memory mode or app is still left alone and refused at dispatch. — justified
  4. A legacy member named only by its selection is still not rewritten. — justified
  5. The per-agent cron section of the cron/dashboard spec now states the repair rule for "differs in selection only". — justified

[FIRST-PRINCIPLES-REVIEWED] afedb1a

Description read

[DESCRIPTION-READ] 2d6b60afd04d630c8005f99c2dd8e8c0656aa5994e0b3e40d88c3513c8dcf2c0

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 22, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the repair now covers every field the tab-switch writer changes, and identity fields are still refused.

Notes

  • Picking a crew member on a cron tab, which writes a member_id, still wedges the schedule permanently. The "Not a goal" scope keeps that case, but the fix that removes the whole class (the tab picker not writing cron:<id>) should be filed as the follow-up.
  • After this change a tab pick is silently undone on the next fire, so the picker can show an agent the job never runs. Say so in the spec section this PR edits, so the next reader treats it as decided.

[DESIGN-REVIEWED] afedb1a

Description read

[DESCRIPTION-READ] 748f2d7bbfebf6916ab106f62f54ba64d28926928d87a84aa6cd17aa56a17702

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 22, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] afedb1a

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable afedb1a78cba506a42aa480dc485d35a9daffe89: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] afedb1a

False positive or not applicable? A repository writer can comment:
/ai-review override gpt afedb1a78cba506a42aa480dc485d35a9daffe89: <one-sentence reason>

@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 Oct 22, 2026
@JLargent42
JLargent42 force-pushed the fix/cron-rebind-selection-fields branch from fa1b05e to 9917c88 Compare October 22, 2026 18:02
@JLargent42

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=e58ee26efa2a: fixed in 9917c88

The spec at docs/system-specs/modules/learn-cron-dashboard.md still said the rebind repairs a record that differs "in the template ALONE"; it now states the selection-only rule (_differs_in_selection_only: template_id and selection_revision always, selection_kind/selection_name unless a legacy member is named by them alone; member, store, mode and app must match) and names the dashboard-tab agent switch as the case it covers.
The same stale wording in the _reconcile_legacy_cron_session docstring (src/kiro_crew/cron_service/identity.py) is corrected in the same commit. No behaviour change; docs-lint and the spec-referencing tests pass.

@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 22, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/ (artifacts.md, crew-mode.md, security.md; same directory as learn-cron-dashboard.md) since this head went green (69b2e50 -> b2b87b0); CI re-running.

@JLargent42
JLargent42 force-pushed the fix/cron-rebind-selection-fields branch 2 times, most recently from f78fa66 to 5ef3228 Compare October 22, 2026 21:05
@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/learn-cron-dashboard.md (same file) and siblings crew-log-emitter.md, security.md, workflows.md since this head went green (b2b87b0 -> 66b3698); CI re-running.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Shared cause for the shard-3 reds (from chat-46, which is leading on #23146): Backend Tests (Windows) (3) and Backend Tests (3.12, 3) fail on the same 8 cases in test/test_chat_runner_redact_across_tool_boundary.py: 6 in TestHarmlessTextAcrossABoundary and 2 in TestCredentialSplitAcrossABoundary, at lines 316, 417, 430 and 504. Main fails on exactly those cases too: push CI run 39856142785 on 5c32cf32 and run 39850535493 on 66b36986, both Windows (3) and 3.12 (3). This is the main red tracked in #23200. #22914 introduced it and #23201 (fdd621be) fixes it. The two main CI runs after the fix were cancelled and the current one, on 41708c96, is still queued, so main has not yet gone green on CI. Locally, all 47 cases pass on 41708c96. This change did not cause it. Re-run the failed job once after the workflow run completes; no rebase is needed unless the PR is DIRTY.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Not caused by this PR: Backend Tests (Windows) (3) fails on 8 tests in test/test_chat_runner_redact_across_tool_boundary.py (TestCredentialSplitAcrossABoundary / TestHarmlessTextAcrossABoundary). main was red there after #22914 met #23111; #23201 (fdd621b) fixed the test. This run tested merge 940d848 onto base 66b3698, which predates #23201. The same 8 fail locally on that base and all 47 pass on current origin/main (41708c9). This PR touches only cron_service/identity.py, its test, and the cron spec.

@JLargent42
JLargent42 force-pushed the fix/cron-rebind-selection-fields branch from 5ef3228 to 63d6571 Compare October 22, 2026 23:05
@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased once to pick up #23201 (main-red #23200); no code change.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Neither remaining red is from this diff. Backend Tests (Windows) (7): 33 failures in test/test_sibling_list_check.py, which is main-red on Windows since #22957; the same 33 fail on #23146 and #23153. Filed as #23259 (tier:T1). Backend Tests (Windows) (5): a single test_cache_dict_is_bounded PathResolutionStalled runner stall, logged in flake ledger #23251 and re-run once.

@JLargent42
JLargent42 force-pushed the fix/cron-rebind-selection-fields branch from 63d6571 to afedb1a Compare October 23, 2026 06:32
@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased once onto main for the #23264 Windows fix.

@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 Oct 23, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) October 23, 2026 17:26

@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.

Reviewed current head afedb1a78cba506a42aa480dc485d35a9daffe89 as Tier 2. Deep review found no blocking issue.

Security check: member identity, store, memory mode, and app equality remain required. The CAS-bound rebind does not grant cross-member access. Auto-merge remains subject to branch protection.

@bolichen97
bolichen97 merged commit a3c860b into main Oct 23, 2026
105 of 106 checks passed
@bolichen97
bolichen97 deleted the fix/cron-rebind-selection-fields branch October 23, 2026 17:27
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 23, 2026
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 refused every fire after its dashboard tab's agent is switched: "session already belongs to another execution"

2 participants