Skip to content

fix(cron): probe the store before deciding a secret grant - #22824

Merged
iamwhatever merged 1 commit into
mainfrom
fix/21358-cron-grant-unreadable-probe
Oct 21, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/21358-cron-grant-unreadable-probe

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: When the cron store cannot be read, approving, denying or revoking a script job's secret grant answers the same "cron store unreadable" 409 every other cron change answers, instead of "job not found".

An unreadable crons.json loads as an empty job list without raising. The secret-grant route (PUT /api/crons/{id}/secrets) and its promotion path look the job up, find nothing, and answer 404 job_not_found. The owner is told the job is gone while it is still on disk, and gets no hint that the store needs repair.

Why it matters

The owner acts on the answer. "Job not found" over a corrupt store hides the real fault and its fix ("Move the unreadable file aside"). Every other read-decide-write cron route already answers the unreadable 409; these two were missed because a test skip hid them.

Not a goal

  • No change to what a grant decision does on a readable store.
  • No change to the unreadable-store probe or the 409 body themselves.
  • No new exemptions in the boundary test.

What changed (motivation → approach → change)

Symptom: on an unreadable store, the secret-grant route says "job not found". Cause: api_cron_secret_grant and _promote_pending_grant read the job and then write it, but never call raise_if_store_unreadable(). The boundary test that requires that call skipped every file named cron.py, and after the #21672 split it also skipped cron_secret_grants.py by name. So it never saw them.

Change:

  • Both functions now call state.crons.raise_if_store_unreadable() right after their job read and return the shared unreadable 409.
  • The boundary test now skips only the store module src/kiro_crew/cron.py, matched on its full path. With the old skip and without the probes, it names exactly these two functions.

Backwards compatibility

Compatible: on a readable store nothing changes; on an unreadable store a 404 becomes the 409 the other cron routes already send.

Removes nothing: the change adds a refusal branch and narrows a test skip; no route, field or record is removed.

Tests

  • test_store_unreadable_on_read_is_409_not_job_not_found: approve, deny and revoke on a corrupt store each answer 409 cron_store_unreadable (not 404), and the store bytes stay untouched.
  • test_store_unreadable_at_promotion_read_is_409: the store turns unreadable between the route's read and the promotion's own re-read; the answer is the 409 and nothing is promoted.
  • test_every_read_decide_write_caller_probes_or_is_exempt now scans cron_secret_grants.py and dashboard/handlers/cron.py.

Proof: with cron_secret_grants.py reverted to origin/main, both new route tests fail and the boundary test names _promote_pending_grant and api_cron_secret_grant. With the fix all pass.

Determinism: the two new tests passed 20/20 at -n0; the whole grant-endpoint file passed 10/10 at -n 4; both changed files (67 tests) passed in a seeded shuffled order (seed 21358).

Manual verification

N/A — unit coverage sufficient: the route tests drive the real aiohttp handler over a real corrupt store file.

Related Issues

Closes #21358
Part of #20192

Pattern harvest

Rule candidate: review-prompt
Pattern: a test skip matched on a bare file name (path.name == "x.py") hides every same-named file; match on the full package path.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 21, 2026 16:43
@iamwhatever
iamwhatever requested a review from buluoray October 21, 2026 16:43
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision cd0407ba034f2cd326cf0d79452dd1ac28b11380 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 Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] cd0407b

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of cd0407ba034f2cd326cf0d79452dd1ac28b11380 — 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

This fix reuses the probe and 409 helper that already exist. It points the boundary test at the real cause: a skip matched on the bare file name, which hid both handlers.

What this change ships

Inventory (3 items) — 3 justified

Intent: when crons.json is unreadable, approving, denying or revoking a secret grant answers the store-unreadable 409 instead of a false "job not found" (#21358). This is a FIX.

  1. On an unreadable store, approve, deny and revoke on PUT /api/crons/{id}/secrets answer 409 cron_store_unreadable instead of 404. — justified
  2. If the store turns unreadable during promotion, the response is the same 409 and nothing is promoted. — justified
  3. The read-decide-write boundary test now skips only src/kiro_crew/cron.py, so it now also scans dashboard/handlers/cron.py and cron_secret_grants.py. — justified

[FIRST-PRINCIPLES-REVIEWED] cd0407b

Description read

[DESCRIPTION-READ] 8adcf841784536b897cd229a237c81870dec4b5f742d068156238cb0da7b4841

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns. The fix adds the shared unreadable-store probe to the two grant handlers that lacked it. The fix also stops the boundary scan from skipping files by bare name, which is what hid those handlers.

[DESIGN-REVIEWED] cd0407b

Description read

[DESCRIPTION-READ] 4d729f506c6a4cdcec793a594afd774ca34db8f18028ed44f3f8553d752b1121

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] cd0407b

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable cd0407ba034f2cd326cf0d79452dd1ac28b11380: <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 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/21358-cron-grant-unreadable-probe branch from 64aeb69 to 294e808 Compare October 21, 2026 17:30
@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 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/21358-cron-grant-unreadable-probe branch from 294e808 to cd0407b Compare October 21, 2026 18:48
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/dashboard/server.py (import) and test/test_dashboard_dist_file_response.py (test-stem) since this head went green (54c45a3 -> 622844a); new head cd0407b. Related tests pass locally (79 passed); CI re-running.

🤖 AI-assisted comment 🤖

@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: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready at head cd0407b: pr_status.py exited 0 (rollup: total=104 running=0 failing=0; PR Readiness success; label: readiness: passed). GPT and Opus lanes are fresh on this head; Design and First Principles both PASS; no unresolved threads.

Main has moved since this head went green (base +13 commits (622844a -> c428ea0), overlap: src/kiro_crew/dashboard/chat_runner.py (import), test/test_dashboard_origin.py (test-stem), test/test_safe_read_file_bytes_descriptor.py (import), test/test_slack_gateway_more_coverage.py (import), test/test_spawn_backend.py (import), test/test_spawn_release_queued.py (import)). None of these are files this PR edits. This PR has been rebased three times already, so I am holding the head here rather than rebasing again; the maintainer can rebase before merging if wanted.

Waiting on maintainer review. I will not merge, approve, or arm auto-merge.

🤖 AI-assisted comment 🤖

@buluoray buluoray 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 at cd0407b. Approving.

The probe reads only the _load_failed flag that the preceding get_job_async just set (store_sync.py:498-516), so it adds no IO on the event loop, and both call sites put it after the read as its docstring requires. The window between read and probe is harmless: if the flag flips after a successful read the answer is a conservative 409, and if the store recovers in between the answer is the same 404 as main. The grant writes themselves still pass update_job_async's write-time guard, which already maps to the same 409, so the probe makes the error answer accurate and does not replace the safety guard. The vault and epoch side effects all come after the job check, so an unreadable store never reaches them.

Mutation check: removing either probe turns its named test red (test_store_unreadable_on_read_is_409_not_job_not_found, test_store_unreadable_at_promotion_read_is_409). Narrowing the boundary-test skip to the full path is a good catch.

Nit: the commit has a title but no body; the PR description covers the why.

@iamwhatever
iamwhatever enabled auto-merge (squash) October 21, 2026 21:49
@iamwhatever
iamwhatever merged commit f9c74af into main Oct 21, 2026
105 checks passed
@iamwhatever
iamwhatever deleted the fix/21358-cron-grant-unreadable-probe branch October 21, 2026 21:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 21, 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: two secret-grant handlers skip the unreadable-store probe, hidden by a name-based test skip

2 participants