Repository navigation
feat(cron): add ScriptContext.set_session_mode for cron sessions - #16681
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merge, confirm that a cron's admitted [DESIGN-REVIEWED] d413298 Description read[DESCRIPTION-READ] 10da7cbe801302f083f0d351e01083493a66c1218ddfb666cd24607805b18200 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check one thing before merge: a cron's Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: let an unattended script cron give the session it opened
[FIRST-PRINCIPLES-REVIEWED] d413298 Description read[DESCRIPTION-READ] de007c99492db98c1bf1b29712dacd5c74c9efa118c5152472d34dc2b86e72e7 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
|
CI note on head 700ae28: The two shared ones are inherited from The third Windows failure, |
700ae28 to
e8f7d52
Compare
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
self-added: yes
|
|
mechanism:
|
|
Rebased: |
|
CI note on head e8f7d52: five checks are red, all for the two failures
|
e8f7d52 to
1aaa404
Compare
|
mechanism: wording only, in the
|
|
Rebased: |
1aaa404 to
1b4e094
Compare
|
Rebased: |
|
|
Reviewed, not approving from my side: this lets a script cron set trust or trust_reads (auto-approve tools) on a session it opened, via POST /api/chat/mode. The scoping looks careful (one slot the cron created, yolo and normal refused, cron_mode_refusal), but granting auto-approval from an unattended job is a permission decision, and #16653 is still needs-human. That needs a maintainer and a security owner's sign-off. CI is green. |
1b4e094 to
605475f
Compare
605475f to
005fe2b
Compare
005fe2b to
4eded49
Compare
A script cron that opens and seeds its own session could not set that session's approval mode, so unattended work in it waited on each tool prompt. set_session_mode(slot, mode) posts the slot and mode to the mode route with the cron's own credential, and the gateway holds a caller that presents an attested cron: key to one rule set: trust or trust_reads only, on one named slot that same cron created, refused while agent.session_control is off. An admitted call is recorded under the cron's key; each refusal is recorded as a chat.control denial attributed to internal, naming the route, slot and mode. Owner and app callers are unchanged. The allowlist is the handler's own slot-scoped tuple, moved where both readers import it, so a non-string mode is refused rather than raised. A cron's admitted trust never deactivates the global grant, declared or not, which is what the method promises. Closes #16653
4eded49 to
d413298
Compare
|
|
Re-reviewed at d413298. The new commit keeps cron-set trust from marking the linked Slack channel as trusted, and a regression test covers it. That's a good fix. My hold is still in place, though: a script cron can still turn on auto-approve (trust/trust_reads) for a session it opened. #16653 is still needs-human, and I haven't seen a maintainer or security owner accept that an unattended job may grant auto-approval. Once that sign-off is on #16653 or here, I'm happy to approve. CI and scoping look fine. |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-10-06): full diff read, callers verified against current main, readiness passed, required checks green, no blocking review threads. Policy sign-off on the owner's behalf (#16653): a script cron may set trust/trust_reads on the one dashboard session it created. Main already let an internal-credential cron post ANY mode to /api/chat/mode unfenced, so this merge narrows the gateway (yolo/normal, foreign slots and switch-off are now refused and SEL-audited) while documenting the one supported shape. A cron script is operator-authored code running as the operator, so no privilege is gained that the operator did not already hold. Approving and merging.
Problem / Motivation
Goal: A script cron can set the approval mode of a dashboard session it opened, to
trustortrust_reads, so unattended work in that session does not wait on each tool prompt.A script cron can open and seed its own dashboard session with the four
ScriptContextmethods #16398 added, but it cannot set that session's approval mode. The new session then stops at the first tool approval with nobody at the keyboard. Issue #16653 records the gap and the approved shape: a fifth method,ScriptContext.set_session_mode(slot, mode).Why it matters
Every dispatcher cron that opens a worker session today produces a session that stalls on its first tool call. Left alone, authors will reach for a wider credential to set the mode, which is the escalation #16398 refused on purpose.
Not a goal
yoloornormalfor a cron.yolois the process-global grant andnormalis the off-switch at any scope; neither is a creation-time posture for one unattended session.approval_modesgovernance scope.What changed (motivation → approach → change)
ScriptContext.set_session_mode(slot, mode)incron_script.pyPOST /api/chat/modewith{slot, mode}and the cron's own credential; returns{ok, mode}; raisesRuntimeErrorcarrying the gateway's code on a refusal/api/chat/modein_CRON_SESSION_CONTROL_PATHS(dashboard/handlers/_shared.py)cron:key on the mode route with 403session_control_disabledwhileagent.session_controlis offcron_mode_refusalindashboard/handlers/_shared.pycron:key getstrustortrust_readsonly: any other mode, a non-string one included, answers 403mode_not_allowed, an unnamed slot answers 400slot_required. The allowlist is the handler's own_SLOT_SCOPED_TRUST_MODEStuple, now defined here and imported bychat_handlers.py, so one constant names the slot-scoped modescron_creator_refusal, called fromapi_chat_mode(dashboard/chat_handlers.py)not_creator_audit_cron_chat_denialindashboard/handlers/_shared.pyaudit_callerinapi_chat_modemode_change:<mode>under the cron'scron:<job id>keyand not cron_creatoron the override revoke inapi_chat_modetrustortrust_readsnever deactivates the global grant, declared in owner config or not, as the method's docstring promises; the owner's slot-scopedtruststill ends a declared grant as beforemcp_cron.pycron_adddescriptionctx.set_session_mode()beside the open and seed methodsA cron sets one posture on one session it created, and nothing else. The method presents the same credential the four sibling methods present and calls the existing mode route, so there is one mode writer. The gateway holds a caller that presents an attested
cron:key to three checks, in this order: the switch, the mode rule, the creator fence. The mode rule runs before theapproval_modesgovernance read and beforesafety_override, so a cron'syolois refused as a cron's whatever the policy says and nothing is armed or revoked. The fence runs on the slot the handler resolved, with no await between the resolution and the read, so it judges the slot object the grant is written to. A slot that is not live gets the handler's ordinary400 unknown slot, because the mode route mints nothing.An admitted call is the ordinary slot-scoped grant:
trustortrust_readsis set on that slot and the session policy propagates as it does for the owner. The global grant is left alone whether it was armed ad hoc or declared in owner config: a scheduled run asking for auto-approval on its own session is not the operator selecting another mode, so the declared-grant exemption that applies to the owner does not reach a cron. Like the checks #16398 added onPOST /api/chat/slotsandPOST /api/chat, these key on thecron:key the caller presents, so they are a courtesy forScriptContextcallers. The method sends the mode as given and keeps no allowlist of its own: a client-side refusal would leave no audit record, and the gateway is the one place the rule lives.No in-tree caller other than
ScriptContextpresents acron:key to the mode route, so no existing call changes. The audit keeps the shape #16398 used:chat.controldenials naming the route, the slot and, for the mode rule, the mode. The three specs record the method, the rules and the pinning tests.Backwards compatibility
Compatible: no existing in-tree caller presents a
cron:key toPOST /api/chat/mode, so no call that works today changes. Owner, dashboard and app-token requests are not judged by the three checks and keep every mode they have.ScriptContext's existing methods keep their signatures and results. The two merged refusals write the same audit fields through the shared helper.Removes nothing: the diff adds one method, one helper, one shared audit write and two path entries; no route, key, field or function is removed or renamed.
Tests
test/test_cron_script_sessions.py:set_session_modeposts{slot, mode}to/api/chat/modewith the cron's credential and returns the receipt; amode_not_allowed,not_creatororsession_control_disabledrefusal raisesRuntimeErrornaming the code; the mode reaches the gateway as sent.test/test_chat_routes_cron_switch.py: with the switch off acron:key onPOST /api/chat/modegets 403session_control_disabledand the denial is audited naming the path; with the switch on it is not refused;cron_mode_refusaladmitstrustandtrust_reads, refusesyolo,normal, a blank, a different case,None, a number and a non-hashable value such as a list or a dict with an auditedmode_not_allowedrather than aTypeError, is the facade's own_SLOT_SCOPED_TRUST_MODEStuple and not a second constant, still answers the 403 when the SEL write for the denial raises, refuses an unnamed slot with an auditedslot_required, answers the mode before the missing slot, and judges nothing for a caller with no cron key.test/test_chat_mode_cron.py, the real handler through aTestClient: a cron setstrustandtrust_readson its own slot and the record names its key; an unrelated slot is untouched; a slot-scoped crontrustleaves a live global grant alone, and a declared one too, while the owner's slot-scopedtruststill ends a declared grant; a non-stringmodesuch as a list is refused with the audited 403, never a crash; every other mode is refused with the posture, the policy and the override unchanged; a cronyolonever reaches governance; an absent mode is refused; an unnamed slot is refused; the owner's slot and another job's slot are refused withnot_creator; a dead key getsunknown slot; the fence receives the resolved slot; the owner still sets every mode, on every slot at once and on a cron-created slot, and still armsyolo.test/integration/test_script_cron_sessions.py, on a booted gateway: a realScriptContextopens a session and setstrustthentrust_readson it, both on the SEL record under its key, with the override still off;yoloandnormaleach raisemode_not_allowedwith the grant it held unchanged and the denial audited; a cron key is refused on the owner's slot, on another job's slot and with no slot named; with the switch off the route and the method answersession_control_disabledwhile the owner still sets the cron's slot; the owner sets and clears every mode on a cron-opened slot.mainbefore the change, 37 of the new unit tests and 7 of the 8 new booted-gateway tests fail, and the nine added for the declared grant and the non-string mode fail against the first revision of this branch; the rest pin the owner path and the standing slot-scoped rule.Manual verification
The sandboxed end-to-end run of a script cron did not run here, for the reason #16398 records: this host refuses
unshare(CLONE_NEWUSER), so the cron sandbox cannot start. The booted-gateway tests present exactly the credential a sandboxed child holds, through aScriptContextbuilt from the runner's environment contract.Related Issues
Closes #16653
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)