Skip to content

feat(guardian): Add the ask tool permission with core-run approvals - #3335

Closed
sentry-junior[bot] wants to merge 10 commits into
mainfrom
feat/tool-ask-permission
Closed

sentry-junior[bot] wants to merge 10 commits into
mainfrom
feat/tool-ask-permission

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Implements the ask permission from #3320. This replaces the dropped confirm mode in #3319.

What changes

Vocabulary. A tool's approvalMode (approve / review / auto) becomes permission: allow / review / ask / deny. auto still derives one from annotations: destructiveHint: true becomes ask, and readOnlyHint: true without destructiveHint skips review (#3332). A plugin tool without the field gets auto. A core tool without one is allow. effectivePermission in guardian/gate.ts is 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 an ask from 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, with decider: guardian | rule | person and decision: allow | ask | deny. Guardian's ratings and cost stay on it. It replaces guardian_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 an ask call, core files the Review item, then writes action_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.md now states this rule.

  • The approver is the Junior User of the asking Run's Actor, and the item's only assignee. A Run whose Actor has no Junior User gets a deny right away.
  • An approved call runs as the approver, in the Turn their answer starts. That Turn must belong to the approver's Junior User and have the same Destination. It runs the exact stored tool and input with that Turn's own credentials. The event keeps ids and context, not credentials.
  • A review desk answer reaches a Slack thread as a web message, so the Turn it starts has the approver's web Actor. Matching by Junior User, not by platform Actor, is what lets a Slack ask run there.
  • An answer from anyone else never runs the call.
  • Later fix: one identity per person (Resolve actor identity once and store it explicitly #2439) removes the split between a person's Slack and web Actors.

Approval runs the stored call. The answer is the message event with reviewItemChanges that review items already append. The Turn that the answer starts settles each open request:

  • Approved by the approver: core writes a person allow with the key action-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.
  • Dismissed, declined, or closed any other way: a person deny with the same key. The call never runs.
  • Not approved within 24 hours: a person deny, and the item is closed.
  • An ask does 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_reviewed rows in a migration is too risky. History decode reads those rows as action_decided with decider: 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 on action_decided next 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 with destructiveHint: true. Destructive first-party tools that you can undo now set review explicitly.

Breaking

External plugins that set approvalMode, such as junior-prod, must rename it to permission.

Open points

  • Slack people need a Junior User to approve. Without one, an ask tool is denied.
  • If the process crashes after the item is filed and before the request is written, approving that item runs nothing.

via @dcramer.

--

View Session [Sentry]

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]>
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 14, 2026 12:49am UTC

Request Review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

19 screenshot changes — 19 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automation Skill Editor · Desktop
Automation Skill Editor · Desktop
Changed
Automations Runs Filters · Desktop
Automations Runs Filters · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Show 12 more changed screenshots
Conversation Memory List Jump · Desktop
Conversation Memory List Jump · Desktop
Changed
Conversation Memory List Jump · Mobile
Conversation Memory List Jump · Mobile
Changed
Conversation Object Links Light · Desktop
Conversation Object Links Light · Desktop
Changed
Conversation Question Picks And Text · Desktop
Conversation Question Picks And Text · Desktop
Changed
Conversation Recalled Memories Popover · Desktop
Conversation Recalled Memories Popover · Desktop
Changed
Conversation Recalled Memories Popover · Mobile
Conversation Recalled Memories Popover · Mobile
Changed
Conversation Share Details · Desktop
Conversation Share Details · Desktop
Changed
Conversation Stop Active · Mobile
Conversation Stop Active · Mobile
Changed
Conversation Task Line · Desktop
Conversation Task Line · Desktop
Changed
Conversation Text Attachment · Desktop
Conversation Text Attachment · Desktop
Changed
Memories · Mobile
Memories · Mobile
Changed
Push Notifications Tip · Desktop
Push Notifications Tip · Desktop
Changed

1 more changed screenshot in Frameshift.

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]>
@dcramer

dcramer commented Nov 13, 2026

Copy link
Copy Markdown
Member

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
@sentry-junior

sentry-junior Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Yes. Each ask call leaves a record in the Conversation's event log. It does not go into the model's transcript: model history is built from message events, and these are structured events.

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:

  1. The exact call. The tool, the input, and the Run context (Actor, credential context, Destination). Core runs this stored call. The model does not issue it again, so nothing the model writes can change or approve the input. The model's memory can't hold this either: compaction can drop it (one of the gaps in feat(github): Create repositories from operator profiles #3319).
  2. The claim. A replayed answer, two Turns that start at the same time, or a retried Turn must not run a delete twice. Something durable has to say "a Turn has started this call."
  3. The end. completed, failed, or declined. Later Turns then skip the call. A retried Turn can show its result again, or record "outcome unknown" if it crashed after its claim, and never run the call again.

The answer itself is not a fourth record. It is the existing message event with reviewItemChanges, plus the item's answer and closedBy.

The delta from the first version

The first version kept those three facts in a new junior_tool_approvals table, created by migration 0107. This version keeps them as three structured events in the asking Conversation, each keyed by the tool call id:

  • tool_approval_requested: the exact call, the approver, and the review item id
  • tool_approval_run_started: the claim, with the Turn id
  • tool_approval_finished: the end, with the result text

Why the event log

  • The run-once guarantee carries over. The event store writes an idempotency key at most once, under the Conversation's event lock, with a unique index. So the first claim append wins, and any other append writes nothing. That is the same atomic claim the table gave.
  • The approval follows the Conversation's lifecycle. Purge deletes it with the Conversation, and a fork doesn't copy it.
  • The dashboard timeline shows it. You can see "asked for approval to run X" and its outcome.
  • No migration and no second store. A child's events stay in the child Conversation. The item's dedupe key names the child and the tool call, so the answer finds the request.

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.

@dcramer

dcramer commented Nov 13, 2026

Copy link
Copy Markdown
Member

is capturing run_start and finished as events actually needed? why wouldn't it be a request and a decision and nothing more?

@sentry-junior

sentry-junior Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Short answer: we need one event beyond the request and the decision, but not two. finished can go. run_started can't.

Why the request and the decision aren't enough. The decision is the item closing with the approver's Approve. It's final as soon as the person answers. Every later Turn sees the same approved item, and the decision can't tell "approved, not run yet" from "approved, already ran". So without another record, the next Turn would run the delete again. That covers a replayed answer, two Turns racing, a retried Turn, or just the next message in the thread. The record also has to be written before the call runs, and only once. That's run_started. Its idempotency key makes the first append win, so only one Turn runs the call.

What finished buys, and why it's optional.

  • The declined outcome. Without it, each Turn checks the item of each open request again. That's cheap, and the 24h expiry caps it: older requests are just ignored.
  • The result text, so a retried Turn can show it again. Without it, a Turn that ran the call and then crashed sees only its own claim on retry, and reports "outcome unknown". That's safe, because the call never runs twice, but it's less informative.
  • Telling "done" from "crashed mid-call". Same as above: both become "claimed", which reads as unknown on a retry.

So the minimum design is:

  • tool_approval_requested
  • the existing review-item answer as the decision
  • one claim event, written before execution

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 tool_approval_finished and the replay branch in run.ts, and the crash case keeps its test.

@dcramer

dcramer commented Nov 13, 2026

Copy link
Copy Markdown
Member

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

@sentry-junior

sentry-junior Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

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)

  • turn_started is written once per Turn, with key turn:<turnId>:started (conversations/turn-lifecycle.ts). It lists inputMessageIds. A retry of the Turn keeps the same turnId, so no new row is written.
  • The answer is a message event with reviewItemChanges, plus message_handled (review-items/messages.ts). A submit starts a Turn whose input is that message.
  • tool_execution_started (toolCallId, toolName) is written before every ordinary parent tool call (agent/index.ts → recordToolExecutionStarted). The dashboard already renders it. Today it's best-effort and has no idempotency key.

Can turn_started stand for "approved, already ran"? Partly, and that's the gap.

  • It works if we run the call only in the Turn whose inputMessageIds include the answer message. Two different Turns can't both run it, assuming the mailbox gives a message to one Turn. I haven't verified that.
  • It can't tell crash-before-the-call from crash-after-the-call. A retried Turn has the same turnId and the same turn_started. So it either runs the delete again or always reports "unknown", even when the call never ran.
  • It doesn't cover an answer that a running Turn drains as a steering message. That message isn't in that Turn's inputMessageIds.
  • It doesn't cover a child's run. That happens in a different Conversation, keyed by its agent-invocation input.

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

  1. tool_approval_requested: keep it. It's the only place the exact call (input, Actor, credential context, Destination) lives. The asking Turn's tool result is just the rejection, and compaction can drop it.
  2. The decision: the existing answer message and the review item. Nothing new.
  3. The run marker: the existing tool_execution_started, written for the approved call with idempotency key tool-approval:<toolCallId>. This write is not best-effort: if it doesn't write a row, the call doesn't run. That's the same event any ordinary tool call already writes. So an approved call costs the request event plus what a normal call costs.
  4. Drop tool_approval_finished. A decline or an expiry is derived from the item's state and the request time, and requests older than 24h are ignored. The result goes to the model in the Turn that ran it, as it does now. A retried Turn that finds its own marker reports "outcome unknown". That's safe, but it loses the result text if the crash came after the call.
  5. Drop tool_approval_run_started and the replay branch in run.ts.

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 tool_execution_started key instead.

@dcramer

dcramer commented Nov 13, 2026

Copy link
Copy Markdown
Member

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?

@sentry-junior

sentry-junior Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Good call. I checked guardian_action_reviewed and it's close, but not the same record today:

  • It's Guardian's verdict on a proposal, written before anything runs: allow | ask | deny, plus risk, user authorization and cost (history.ts, projection.ts → recordGuardianActionReviewed).
  • It has no idempotency key. It's appended once per review, so a retry can write it twice. That makes it unusable as the run-once claim as it stands.
  • stats.query.ts counts every row of that type as a Guardian request and sums its costUsd. Person decisions in the same type would skew those numbers unless the query filters them out.
  • A permission-rule ask/deny writes nothing today, because Guardian never runs for it.

So the holistic version I'd propose is one decision event for every decision point, instead of a separate tool_approval_decided:

action_decided {
  toolCallId, toolName,
  decider: "guardian" | "rule" | "person",
  decision: "allow" | "ask" | "deny",
  riskLevel?, userAuthorization?, costUsd?   // Guardian only
}
  • Guardian review: same data as today, with decider: "guardian".
  • Permission rule: decider: "rule", decision: "ask" | "deny". This record is new; there's none today.
  • Person's answer: decider: "person", decision: "allow" | "deny", with idempotency key tool-approval:<toolCallId>. The row that inserts is the claim, and the Turn that wrote it runs the call. Decline, dismiss and expiry write deny.
  • tool_approval_requested stays as the only extra event, because it's the only place the exact call (input, Actor, credentials, Destination) is stored. Your earlier note said not to put the input on the Guardian event.

Why it fits: saved grants and argument-matching rules later become more decider values on the same event, not new event types. The dashboard and stats also get one place to show "who decided what".

Cost: renaming a native event type means a hard cutover. Existing rows stay guardian_action_reviewed, so we'd either keep reading that type or migrate the rows. The stats query also needs decider = 'guardian'. The cheaper alternative is to keep the guardian_action_reviewed name, add decider, and make the Guardian-only fields optional. That's smaller, but the name is then wrong for person and rule decisions.

Which do you want?

  1. Rename to action_decided and cut over.
  2. Extend guardian_action_reviewed in place.
  3. Keep tool_approval_decided as it is now.

I'd go with 1.

Separately, I have a local trim ready that I haven't pushed. It merges tool-approvals/ into one file, removes the separate pending lookup, item auto-close on expiry, the replay/unknown branch and the test fixture, and cuts TERMINOLOGY to one entry. I'm holding it until you pick, so the event shape changes only once.

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]>
@blacksmith-sh

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

sentry-junior Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

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.

@sentry-junior sentry-junior Bot closed this Nov 23, 2026

This branch was successfully deployed

1 active deployment
Preview – junior-docs — b409f216 Deployed Nov 14, 2026 by vercel[bot]
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.

1 participant