Repository navigation
feat(guardian): Add the ask tool permission with core-run approvals - #3335
sentry-junior[bot] wants to merge 10 commits into
Conversation
Replace approvalMode (approve/review/auto) with permission (allow/review/ask/deny, plus auto). An ask call is stored with its Run context and filed as a Review item for the person. Only that person's Approve answer runs the stored call, once, in a Run with the same Actor, credentials, and Destination. Guardian ask decisions take the same path. Automation runs deny an ask. Refs #3320 Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
19 screenshot changes — 19 changed · 0 added · 0 removed Review screenshots in Frameshift Show 12 more changed screenshots1 more changed screenshot in Frameshift. |
Co-Authored-By: David Cramer <[email protected]>
Drop the junior_tool_approvals table and migration 0107. An ask now appends tool_approval_requested with the exact call. A claim event and an end event, keyed by the tool call id, make the call run at most once. Approvals expire after 24 hours. Co-Authored-By: David Cramer <[email protected]>
|
Need an explainer on the delta here - we have to track historical approvals within the context of the transcript, right? why? etc |
# Conflicts: # packages/docs/src/content/docs/extend/build-a-plugin.md # packages/junior/src/chat/guardian/gate.ts # packages/junior/tests/unit/guardian/gate.test.ts
|
Yes. Each Why a record is needed at all The ask and the approval happen in different Turns, and often in different processes. The asking Turn ends with a rejected result. The answer comes later through the review item. So three facts must survive between those Turns:
The answer itself is not a fourth record. It is the existing The delta from the first version The first version kept those three facts in a new
Why the event log
What it costs At Turn start, and when steering messages arrive, core reads the Conversation's structured events to find approvals that have not ended. Ended ones are skipped. Approvals expire after 24 hours, so the set of open ones stays small. We could do without the history only if the approval were resolved inside the asking Turn, which means parking it. Resuming a parked Turn would make the model issue the call again, and new input ends a parked Turn, so someone else's message would cancel the ask. That's why the asking Turn ends, and the Turn that delivers the answer runs the stored call. |
|
is capturing run_start and finished as events actually needed? why wouldn't it be a request and a decision and nothing more? |
|
Short answer: we need one event beyond the request and the decision, but not two. Why the request and the decision aren't enough. The decision is the item closing with the approver's What
So the minimum design is:
The Turn that runs the call passes the result straight to the model and stores nothing. I can make that change if you want it. It removes |
|
wouldn't "approved, already ran" just have the turn started event or whatever? im still not convinced that our understanding here is correct. you need to be more thorough to make sure we're not bloating the event pipe |
|
You're right that I added more than needed. I traced what's already in the log. Here's the corrected picture. What exists today (checked on this branch)
Can
So to keep the rule "a crash after the run starts means outcome unknown, never retry", one write still has to happen right before the call runs. That's inherent to run-once with side effects, and not specific to this design. Proposal: no new event types for the run
Net: one new native event type instead of three. Per approved call there are two rows, and one of them is the row every tool call already writes. If you're good with this, I'll make the change. The race, replay and crash tests stay, and they then check the |
|
im ok having something thats like "decision made" as an event, but i think we already have that in guardian? so im not sure if we need all these events or just need to improve things holistically? |
|
Good call. I checked
So the holistic version I'd propose is one decision event for every decision point, instead of a separate
Why it fits: saved grants and argument-matching rules later become more Cost: renaming a native event type means a hard cutover. Existing rows stay Which do you want?
I'd go with 1. Separately, I have a local trim ready that I haven't pushed. It merges |
Trim ask approvals to the design and use two events: - action_review_requested: the exact call that waits on a person, from a rule ask or a Guardian ask. - action_decided: every Guardian review, every rule ask or deny, and the person's approve or deny. It replaces guardian_action_reviewed. A person's decision has the key action-decided:person:<toolCallId>, so only the writer that inserts the allow runs the call. Old guardian_action_reviewed rows decode as decider guardian. Stats and cost queries count only Guardian decisions. Co-Authored-By: David Cramer <[email protected]>
This comment has been minimized.
This comment has been minimized.
Identical ask calls share one review item. Two of them could race past the owner check and both store a request for that item, so one Approve ran each of them. Key the request by the item id instead. The event store writes a key at most once under the Conversation's event lock, so an item holds one request and runs at most one call.
Junior never runs an action as another person. An approved call now runs in the Turn that the approver's answer starts, when that Turn's Actor is the approver's Junior user, with that Turn's own credentials. A review desk answer reaches a Slack thread as a web message, so matching the platform Actor never ran a Slack ask there. The review item dedupe key names the approver, so an identical call of another person gets its own item. State the rule in policies/security.md. Also address the review of the action events: record each decider's own decision before asking a person, read action review requests by namespace and name, expire only open items, drop the unread action_decided.reviewItemId, count decisions with literal type predicates so each partial index applies, and share mayNeedReview and canonicalJson from the gate. Co-Authored-By: David Cramer <[email protected]>
# Conflicts: # packages/junior-dashboard/src/client/conversations/TelemetryMetrics.tsx # packages/junior/migrations/meta/0108_snapshot.json # packages/junior/migrations/meta/_journal.json
# Conflicts: # packages/junior-github/src/tools/submit-pull-request-review.ts # packages/junior-github/src/tools/update-issue.ts # packages/junior-google/src/tools/replace-doc-content.ts # packages/junior-google/src/tools/replace-doc-text.ts # packages/junior-memory/src/tools.ts # packages/junior-vercel/src/tools/actions.ts # packages/junior/src/chat/automations/tools/delete.ts # packages/junior/src/chat/automations/tools/run-now.ts # packages/junior/src/chat/plugins/agent-hooks.ts # packages/junior/src/chat/tools/runtime/message-agent.ts # packages/junior/src/chat/tools/runtime/spawn-agent.ts
…in full The approval item cut the input at 2,500 characters, but Approve ran the full stored input, so fields after the cut ran unseen. The gate now denies an ask whose input text is longer than the item shows, and the item shows the input first, so a Slack card that cuts a long body still shows all of it.
|
Closing so we can take a more considered look at Guardian. This PR's concern (a code-enforced ask permission and approvals that run as the approver) goes into the Guardian redesign ticket as an input. |
Implements the
askpermission from #3320. This replaces the droppedconfirmmode in #3319.What changes
Vocabulary. A tool's
approvalMode(approve/review/auto) becomespermission:allow/review/ask/deny.autostill derives one from annotations:destructiveHint: truebecomesask, andreadOnlyHint: truewithoutdestructiveHintskips review (#3332). A plugin tool without the field getsauto. A core tool without one isallow.effectivePermissioninguardian/gate.tsis the one place a call becomes allow / review / ask / deny.Two events.
action_review_requested: written only when a decision waits on a person, for anaskfrom a rule or from Guardian. It holds the exact call: tool, input, the Run's Actor, credential context, Destination, the approver, and the review item id.action_decided: one event per decision, withdecider: guardian | rule | personanddecision: allow | ask | deny. Guardian's ratings and cost stay on it. It replacesguardian_action_reviewed. It is written for every Guardian review, for a rule ask or deny, and for a person's approve or deny. A rule allow writes nothing.Core enforces
ask, not the model. For anaskcall, core files the Review item, then writesaction_review_requested. The model gets a rejected result that names the item and says to wait. The item's dedupe key is the asking thread, the approver, the tool name, and a hash of the canonical input, so an identical retry reuses the open item.Junior never runs an action as another person. A person can approve only an action that runs as them.
policies/security.mdnow states this rule.Approval runs the stored call. The answer is the
messageevent withreviewItemChangesthat review items already append. The Turn that the answer starts settles each open request:allowwith the keyaction-decided:person:<toolCallId>. The event store writes a key at most once, and only the writer whose append inserted the row runs the stored input, without action review. A race or a replayed answer runs the call once. A crash after the write leaves the call decided, so it never runs again.denywith the same key. The call never runs.deny, and the item is closed.askdoes not park the Turn, so another person's message leaves the request pending.Children. A child agent's approver is the root's person, and its item goes on the root's review desk. The answer starts a Turn in the child through an agent invocation, and that Turn runs the call as that person.
No person, no ask. Scheduled and event Automation runs, system Actors, and people with no Junior User get a deny right away.
Old rows. No backfill: an UPDATE over the existing
guardian_action_reviewedrows in a migration is too risky. History decode reads those rows asaction_decidedwithdecider: guardian, and the stats and cost queries count both types with literal type predicates, so each partial index applies. Migration 0109 adds a concurrent partial index onaction_decidednext to the old one. These legacy mappings and the old index all go away together once the old rows age out.First tools on
ask:deleteAutomation,deleteWorkspace, and plugin and MCP calls withdestructiveHint: true. Destructive first-party tools that you can undo now setreviewexplicitly.Breaking
External plugins that set
approvalMode, such as junior-prod, must rename it topermission.Open points
asktool is denied.via @dcramer.
--
View Session [Sentry]