Repository navigation
fix(cron): return a refused script call's status and gateway code - #13352
Conversation
|
Intent: Let a script-mode cron reach owner-surface gateway routes such as |
Design Review (Opus 5.5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The new Watch
[DESIGN-REVIEWED] 270d9e0 Description read[DESCRIPTION-READ] 9af9c5578752505185108c3f64745ce2d2bb381216ef13ab90c2ca963dae3744 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS This is labelled a fix but adds new fields to a private method's return value, and no in-tree code reads them. Half of the Goal already shipped in #16398. Not justified as shipped
What this change shipsInventory (5 items) — 3 justifiedIntent: a script cron that triggers another job can tell why the gateway refused it. This is an ADDITION framed as a FIX.
[FIRST-PRINCIPLES-REVIEWED] 270d9e0 Description read[DESCRIPTION-READ] 88da80fe1744f9af0c63a19941c4472b25a48686075cd9d3021aefd2fc4cbe6b That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
a253111 to
d279966
Compare
|
|
|
|
d279966 to
158187b
Compare
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
9cc1824 to
82f29c4
Compare
|
self-added: no
[operator: KiroCrewCaptain for bolichen97] |
|
self-added: no
Also on 82f29c4: |
82f29c4 to
d6b28b1
Compare
|
Rebased: main moved in test/test_agent_panel_crew_log.py (imports a file this PR touches) since this head went green (aee834c -> 8c7417e); CI re-running. The patch is unchanged (82f29c4 -> d6b28b1). The E2E red on the previous head was one frontend spec (session-tags-e2e 17b) that passed only on retry; this PR changes no frontend code. |
|
self-added: no
[operator: KiroCrewCaptain for bolichen97] |
ScriptContext._exchange now adds status_code and, when the refusal body
names an identifier-shaped one, the gateway's code beside the unchanged
error text, so a script calling ctx._post itself (POST
/api/crons/{id}/run) can tell 409 member_identity_unavailable from a job
that is already running.
Adds the end-to-end regression test that runs the launcher's token
through the request ScriptContext builds and the gateway's real
session_key_is_attested: attested for the job's own key, not for a
neighbour's, and unattested without the token. The identity tests also
pin KIROCREW_HOME so the launcher's security-event write stays out of
the real data home under --noconftest.
d6b28b1 to
270d9e0
Compare
|
This PR makes a refused |
Problem / Motivation
Goal: A script-mode cron job can trigger another cron job again, and when the gateway refuses one of its calls the script is told why.
A script cron that calls
ctx._post("/api/crons/<id>/run", {})gets back only{"error": "HTTP 409: <raw gateway JSON>"}when the gateway refuses it. Tolearn whether the refusal was an identity problem (
member_identity_unavailable)or a job that is already running, the script has to parse that text. Nothing
in the test suite checks that the token the launcher mints actually attests the
request
ScriptContextbuilds, so a drift between the two would bring theoriginal 409 back with no failing test.
#16398 already sends the launcher's signed token as
X-Session-Tokenon everyScriptContextcall, which is what lets the trigger through. This PR adds thetwo pieces still missing on
main. The requirement is the open suggestion in#11862's closing comment:
surface the refusal body's
codefromctx._post. The caller is a user's ownscript cron that triggers another job, as in #11862; no in-tree caller needs it.
Why it matters
A refused trigger looked like an ordinary result dict, which is how a daily
digest stopped arriving for four days before anyone noticed. A script that can
read
status_codeandcodecan alert on a refused identity instead ofswallowing it. The end-to-end test is what keeps the token, the header and the
gateway's check in agreement.
Not a goal
ScriptContextsends it: both are onmainalready (fix(dashboard): attest a session key before member scope trusts it #12164, fix(cron): let a script cron open and seed a session without a token #16398).errortext: it stays exactly whatmainreturns.What changed (motivation → approach → change)
A refused script call now says, in fields, what the gateway refused and why.
src/kiro_crew/cron_script.py—ScriptContext._exchangestatus_codeand, when the body names one, the gateway'scodebeside the unchangederrorsrc/kiro_crew/cron_script.py—_refusal_codejson_line.parse_json_object_lineand keepscodeonly when it is a short identifier ([a-z0-9_.-]{1,64})docs/system-specs/modules/learn-cron-dashboard.mdtest/test_cron_script_identity.py,test/test_cron_script_sessions.pyThe gateway's refusal body is text this process did not write. So
codeisechoed only when it looks like an identifier, and a body that does not parse,
including one nested past the JSON parser's limit, yields no
code. Atransport failure has no status and keeps the plain
{"error": str(exc)}.The two
_http_error_bodyhelpers inmcp_shared.pyandmcp_core.pydo notfit here. Each reads the
HTTPErrorbody itself, but_exchangeneeds that oneread for its unchanged
errortext too.mcp_shared's returns any stringcode, with no identifier check.mcp_core's rewriteserrorinto its ownshape, and
errormust stay exactly whatmainreturns.The end-to-end test runs the real launcher, which publishes the run's token,
and builds the request
ScriptContextsends from the child's env. It then asksthe gateway's own
member_memory_auth.session_key_is_attestedabout thatrequest: attested for the job's own key, not for a neighbour's, and unattested
when the token is left out. The identity test module also pins
KIROCREW_HOMEto the test's tmp dir, so under
--noconftestthe launcher's writes stay outof the real data home. In that mode it also stubs
cron_script.sel, becausethe root
conftest.pyfixture that gives the process-wide SEL writer asession-scoped directory is not loaded, and the writer must not bind to a
per-test directory. The fixture patches through its own
MonkeyPatch, so atest that calls
monkeypatch.undo()cannot lift these pins.Backwards compatibility
Compatible:
erroris unchanged, sonotify()and the session methods, whichcheck
"error" in resultand raise withresult["error"], behave exactly asbefore.
status_codeandcodeare additive keys on the refusal dict only.Tests
test_cron_script_identity.py::TestLauncherPublishesAVerifiableToken—test_the_gateway_attests_the_request_scriptcontext_buildslocks in that the launcher's token, the headerScriptContextsends and the gateway's check agree;test_the_same_request_without_the_token_is_unattestedis the baseline the original 409 came from.TestBridgePinsIdentityOnTheServerSpawn::test_call_tool_passes_the_jobs_key_to_the_bridgealso checks, under--noconftest, that the audited tool call leaves the SEL singleton unset.test_cron_script_sessions.py::TestARefusalIsStructured— a JSON refusal yieldsstatus_codeandcode; a non-JSON body, an empty body and a too-deeply-nested body still yield the status; a non-identifiercode(markup, spaces, over 64 chars, a number, null, a list) is dropped; a transport failure keeps the plain shape.With the
_exchangechange reverted, everyTestARefusalIsStructuredtestexcept the transport-failure one fails. The two attestation tests pass on
maintoo: they pin behaviour #16398 shipped without a test.Manual verification
N/A — unit coverage sufficient: the attestation test drives the real launcher,
signing primitives and gateway check rather than mocks of them, and the
refusal tests feed
_exchangerealHTTPErrorobjects.Screenshots / video
N/A — no UI change.
Related Issues
no linked issue: #11862 reported the original symptom and is closed; its
closing comment
left "surface the 403 body's
codefromctx._post" as an open suggestion,which
status_code/codecover. #16398 landed the token header this PRfirst carried.
Pattern harvest
Rule candidate: none
Pattern: a refusal dict that carries the gateway's status only inside its
errortext, so a caller has to parse prose to branch.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)