Repository navigation
feat(approvals): expiring command-scoped trust grants - #19220
Conversation
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The transport-level deadline re-check threads a new Not justified as shipped
What this change shipsInventory (8 items) — 7 justifiedIntent: let a user trust one command or command family for an hour or until midnight, after which the prompt returns. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] 57e82d7 Description read[DESCRIPTION-READ] 42e3eb527baf9ad4d5893ab115671b838c730abbc1cb2ee0e4fa0cd1cabcc90e That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that a person can still answer the fallback prompt after [DESIGN-REVIEWED] 57e82d7 Description read[DESCRIPTION-READ] 1ab6c837486346f239f498caecf2aa3ed2ad1bfea1f839dc0b3d86a1bfa1400e 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 |
UX Review (Opus 5.5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS The new timed rows read clearly, but the lifetime words around them don't. "For this session" is never explained, and "Trust read-only commands" now looks permanent. Watch
Suggestions
[UX-REVIEWED] 57e82d7 Description read[DESCRIPTION-READ] d6665a7fd29d05752b40f5b80efd8811cec7cb098682076f9d8b043bb8c8c122 That sha256 names everything this verdict read: the PR description, plus the 8 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 |
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: |
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: |
63846eb to
33d435e
Compare
|
Review follow-up on Design: deadline on the monotonic clock only. Fixed. A timed grant now carries a Design / First Principles: two expiry mechanisms on one pattern set. Fixed by separation rather than by sharing. Timed grants no longer write
Why not reuse the lease's UX: the untimed row reads as permanent. Fixed. With timed rows present, the chat-long rows read "Trust “cmd” for this session" and "Trust all ls commands for this session". Surfaces without timed rows keep their labels. Screenshots are refreshed. UX: the confirmation does not say what was trusted. Fixed. It now reads "Trusted “ls -la …” until 2:30 AM, then it asks again", or "Trusted all ls commands until …, then they ask again" for a family grant. UX: how far "all ls commands" reaches; grouping lifetimes under one command. Not changed here. The family row's scope wording is the existing tier label, unchanged by this PR. Each row stays a whole consent sentence because the exact-command row's text is the grant itself, and splitting the lifetime into a separate control would make the scope and the lifetime two clicks the user could mismatch. |
33d435e to
236151e
Compare
|
UX follow-up on The confirmation looks like a block. Fixed. A landed timed grant uses its own notice kind, with a clock icon and the ok tint. The warning lock stays for refusals only. The answered prompt looks ambiguous (faded buttons above the confirmation). That was the capture fixture, which keeps the slot marked as waiting on approval. In the app the decision resolves the pending card exactly as every existing Trust choice does. The status screenshot is now the status line alone. "For this session" can't be compared with the timed rows. Not changed. "for this session" matches the existing "Trust all tools for this session" row in the same menu, so the menu uses one word for one lifetime. Renaming the session lifetime across every tier is a wording change beyond this PR's goal. The family scope ("all ls commands"). Not changed. That label is the existing tier's, and its grant is the same Name the picked lifetime in the confirmation. Not taken. The clock time is the lifetime the user picked, stated in the one unit that cannot be misread. |
236151e to
e07ba12
Compare
|
GPT follow-up on Recheck timed trust after the awaited program-name check. Fixed at the root. After
|
e07ba12 to
0884f8d
Compare
|
UX follow-up on Blocker: people can't tell what the timed family grant covers. Fixed. On the chat prompt the three family rows now say exactly what the grant matches:
That is the grant itself: the program alone or followed by any arguments. The family rows also wrap now instead of truncating. At 360px the old "for this session" next to the timed rows. Kept. It is the same word the existing "Trust all tools for this session" row uses in this menu, so one lifetime has one name. Separators between the eight rows. Not added. They would make the menu taller on the phone width the concern is about. Each row now states its scope and its lifetime, which is what the grouping was meant to show. |
0884f8d to
5e5f05f
Compare
|
UX follow-up on Blocker: the family rows don't make their reach clear. Taken as suggested. The rows now read "Trust every "for this session" / the read-only row's lifetime. Kept. The session-wide row on main already says "for this session", so one lifetime keeps one name in this menu. Renaming that lifetime, or the read-only row, would reword existing tiers outside this PR's goal. |
|
First Principles follow-up on |
|
GPT follow-up on Timed trust can expire before the transport sends approval. Fixed at the root in 1ce5f49. When the match rests on a timed grant, the runner passes that grant's deadline to
|
f202bab to
0f33ac5
Compare
0f33ac5 to
156678c
Compare
156678c to
b72c570
Compare
|
Maintainer review on head Defect — the write-redirect check reads the chat-long set, not the live set.
matched = _matches_trusted_pattern(_tp_command, _tp_live) if _tp_command else None
if (
matched
and event.is_shell
and _tp_command
and _redirect_outside_grant(_tp_command, slot._trusted_patterns) # <- chat-long only
):The match two lines above uses Direction is fail-closed (over-prompting, not over-approving), so this is a functional gap in the new rows rather than a security hole — but it does make the feature not work for any command with a redirect. Fix: pass Two notes, no change needed: Once the fix is pushed and CI is green I will approve and merge. |
|
Thanks for the review. Fixed on head 57e82d7. The fix is folded into the PR's second commit to stay within the two-commit limit. The branch is also rebased onto current main to clear a conflict: both sides appended keys at the end of 1. The write-redirect check read the chat-long set (fixed)
2. 3. Local checks: black, isort, flake8 and mypy on the touched files pass, as do the wait-discipline ratchet and the comment-history gate. The runner, trust-pattern and approval suites show no new failures. |
The chat approval prompt offers each command-scoped trust tier ("this
command", "every <base> command") for an hour or for the rest of today,
beside the grant that lasts for the session, which now says so.
- The approve endpoint accepts ttl_seconds (1..86400) on trust_command
and trust_base only; any other value, or a lifetime on another
decision, is refused before any side effect.
- A timed grant lives in its own per-chat store, apart from the
chat-long patterns other writers share, with a deadline on both the
wall and monotonic clocks. It is checked at decision time and dropped
once either deadline passes, so the next call prompts again.
- After a timed grant lands, a status line with a clock icon names what
was trusted and until when.
- Grants stay per chat and in memory; existing tiers and "Allow once"
are unchanged.
Fixes #10136
An approval that rests on a timed command-scoped grant now carries the grant's deadline down to the ACP transport. Both transports hand a check to the existing under-lock before_write hook of their response write, so it runs after the security floor and the wait for the stdin write lock, right before the frame is written. Once the deadline has passed, nothing is written, the request is put back as it was (floor event, recorded options), and GrantEnded sends the chat runner to the normal prompt. An approval with no timed grant behind it passes no deadline and takes the existing path unchanged. timed_grant_deadline works out the deadline from the parts of the command the chat-long patterns leave uncovered, so a call the chat-long grants cover alone carries none. The same deadline covers the awaited program-name check before it, so the runner matches once and does not re-derive the live set after that check. The trusted-pattern redirect check reads the same live set the match uses, so a live timed exact grant such as "echo hi > out.txt" covers the write redirect it spells instead of being declined and re-prompted on every repeat. timed_grant_deadline applies the same redirect rule, so an approval whose redirect only a timed grant covers carries that grant's deadline to the send even when a chat-long base grant matches the rest of the command.
iamwhatever
left a comment
There was a problem hiding this comment.
This PR lets a user trust one command, or one command family, for an hour or until midnight on the chat approval prompt, after which the prompt comes back. It is built at the right place: timed grants live in their own per-slot store (_trusted_pattern_deadlines), so no other writer of _trusted_patterns can end or extend one. They are pruned at decision time against a two-clock GrantDeadline, so a suspended laptop or a clock set backwards cannot stretch them, and the transport re-checks the deadline under the stdin write lock right before the answer goes out. I read every backend hunk and tried to break the boundary. parse_grant_ttl refuses bools, floats, strings and anything outside 1..86400, and ttl_seconds on any action other than trust_command/trust_base is refused before any side effect. The granted pattern is still derived from the canonical pending command, so a timed grant can never be wider or longer-lived than the existing chat-long one. timed_grant_deadline uses the same split_command_segments + _tool_matches rule as matches_trusted_pattern, so an approval that rests on a timed grant always carries its deadline, and an uncovered part returns _ENDED and prompts. GrantEnded is not an AcpRuntimeError, so _guarded lets it through to the runner's fallback. Both transports restore the floor event and recorded options, so the person can still answer. The maintainer's open defect (bolichen97: _redirect_outside_grant read the chat-long set) is fixed at head 57e82d7: it now gets _tp_live, the same rule is shared with timed_grant_deadline via _covers_write_redirect, and runner tests were added that fail on the old head. The no-ttl_seconds path is byte-identical to main, every failure direction is fail-closed, and the remaining First Principles/UX CONCERNS (transport plumbing weight, "for this session" wording) are advisory and were answered in the thread, so it is safe to merge. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Goal: Let a user trust one command, or one command family, for an hour or for the rest of today, after which the approval prompt comes back on its own.
The chat approval prompt already scopes a grant by type ("Trust read-only commands"), by command ("Trust “cmd”", "Trust all
gitcommands") and by session ("Trust all tools for this session"), and auto-approve-all already expires after its configured duration. What a user cannot do today is give ONE command or command family a time limit: every command-scoped grant lasts for the whole chat, so "trustaws describe-*for the next hour" means either clicking Allow once over and over or granting it for the rest of the chat and remembering to stop.Why it matters
Long tasks repeat the same safe command many times. Today the choice is approval fatigue (Allow once on every call) or a grant that outlives its intent (until the chat ends). A grant that expires by itself lets the user match trust to the job in front of them without leaving standing permission behind.
Not a goal
What changed (motivation → approach → change)
Design summary. The issue asks for grants scoped by type, session and time. Type (
trust_reads), session (per-chat Trust tiers) and an expiring global grant (auto-approve duration) already ship; the missing dimension is expiry on a scoped grant. Three shapes were considered:Why a decision-time deadline, not a timer. App worker leases already expire patterns on the same chat with a
call_latertimer. That timer runs on the event loop's monotonic clock, which stops while the host is suspended, so a laptop closed overnight would wake with an "hour" grant still live; and its callback is a second writer that removes patterns from the set the user's own grants live in. A comparison at decision time, against a deadline on both clocks, is exact at the only moment a grant can act and needs no handle to cancel. Timed grants live in their own store, so the two mechanisms never touch each other's patterns. Between the match and the answer sit three awaited waits: the program-name check that precedes a shell auto-approval, the ACP transport's own security-floor check, and the wait for the transport's stdin write lock. Any of them can span a host suspend of any length, and an answer written after it would rest on a grant whose deadline had passed, the same stretched-grant harm the two-clock deadline exists to stop. So an approval that rests on a timed grant carries that grant's deadline down to the transport, which checks it under its write lock, right before it writes the answer; the runner matches once.Backend
trust_patterns.py:parse_grant_ttlaccepts only a plain integer from 1 to 86400.GrantDeadlineholds a wall-clock and a monotonic deadline.record_trust_grantputs a chat-long grant in the shared pattern set (clearing any timed entry it outlasts) and a timed grant only in the timed store.live_trusted_patternsdrops every timed grant past either deadline and returns the chat-long patterns plus the live timed ones.timed_grant_deadlinegives the deadline an approval rests on:Nonewhen the chat-long patterns cover the whole command, otherwise the earliest end, on each clock, of the timed grants covering the parts they leave. A part nothing covers gives a deadline that has already passed.GrantEndedis what a transport raises instead of answering when that deadline has passed, andgrant_deadline_guardis the under-lock check that raises it._trusted_pattern_deadlines(pattern → deadline) beside_trusted_patterns, which is unchanged: no other writer of that set (worker leases, chat-long grants) can end or extend a timed grant, and a timed grant expiring never removes a pattern another writer holds.api_chat_slot_approvereads an optionalttl_seconds. It is honoured ontrust_commandandtrust_baseonly. Any other decision carrying it is refused withttl_unsupported, and an unreadable value withttl_invalid, both before any side effect: no pattern is recorded, no session policy is touched, and the pending call stays pending.live_trusted_patterns(...)instead of the bare set, so an expired grant never approves anything and the call prompts again.approve_tool(request_id, deadline=...); that deadline covers the awaited program-name check as well as the floor and the write-lock wait. Both ACP transports (AcpClientandAcpSessionHandle) turn it into a check (grant_deadline_guard) that they hand to the existingbefore_writehook of their response write. The framing helper runs that hook under the stdin write lock, right before the frame is written; the shared runtime runs it after its own dead-runtime check. If the deadline has passed, nothing is written, the request is put back as it was (its floor event and recorded options), andGrantEndedis raised; the runner then falls through to the normal prompt, and the person's answer goes through the floor as usual. The two provider adapters passdeadlineon only when one is given. An approval with no timed grant behind it callsapprove_tool(request_id)exactly as on main, hands no check to the write, and never reads a clock.Frontend
TrustDropdowngains an opt-intimedGrantsprop. When set:lscommand …", and wrap rather than truncate so the lifetime is never clipped;onActionreceives the lifetime in seconds.utils/grantDuration.ts).grantEndsAtgives the end time the rows show.timedGrantsand sendsttl_secondswith the grant. After the grant lands it shows a status line, with a clock icon and the ok tint rather than the warning lock refusals use, naming what was trusted and until when in the app locale: "Trusted “ls -la …” until 2:30 AM, then it asks again", or "Trusted any “ls” command until …, then it asks again".Docs: the security deep dive's interactive trust section describes timed command grants, their separate store, the two-clock deadline and the check at the send.
Backwards compatibility
Compatible:
ttl_secondsis a new optional field. A request without it behaves exactly as on main, so every existing grant, the "Allow once" default and every other surface keep their behaviour. The only new refusals are for requests that carry the new field. On the chat approval prompt the chat-long command row gains "for this session" and the family row reads "Trust anylscommand for this session"; the grants they record are unchanged.approve_toolon the provider interface, both providers and both ACP transports gains an optional keyworddeadline, and the transports' response sends (AcpClient._send_response,AcpRuntime.send_responseand its session-runtime protocol) gain an optional keywordbefore_write. Every existing caller passes neither and takes the same path as on main.Removes nothing: the diff adds a field, a keyword argument, helpers, one slot attribute, menu rows and labels; no key, path, validator or capability that main accepts is narrowed or removed.
Tests
test/test_trust_timed_grants.py(new):ttl_secondsvalidation: 1, 3600 and 86400 are accepted; 0, negative, over a day, bools, floats, strings,Noneand lists are refused.live_trusted_patternskeeps chat-long and live timed grants and drops expired ones.ttl_invalidwith no grant and the call still pending; a lifetime ontrust,trust_reads,approvedoryoloreturns 400ttl_unsupportedwith no trust flag, no policy write and the call still pending.test/test_chat_runner_coverage.py:approve_tool("req")and nothing else, whether or not a timed grant also matches.AcpClientunderneath, a call approved while its grant was live whose floor check outlasts the deadline is prompted first and answered only after the person allows it.test/test_trust_timed_grants.py,timed_grant_deadline: no deadline when chat-long patterns cover the command, a timed grant's own deadline, only the uncovered parts counted, the earliest end on each clock across parts, the later of two grants covering one part, and a passed deadline for an uncovered or unsplittable command.test/test_transport_permission_floor.py, for both transports:deadlineon only when one is given.TrustDropdown.test.tsx:ChatInput.approval.test.tsx: the timed command row sendsttl_seconds: 3600and the status line names the command and carries the clock icon, not the lock; the timed family row sendsttl_secondsand the status line names the family; the tier-count guard is updated to the eight rows.grantDuration.test.ts: hour, rest of today, the 1..86400 clamp, the end time of each, and a grant made mid-second lasting until midnight rather than a second short.Manual verification
{"action": "trust_command", "ttl_seconds": 3600, ...};Screenshots / video
Trust menu on the chat approval prompt, dark and light:
Narrow viewport (360px) and the status lines after a timed command grant and a timed family grant
The status line alone, as it renders after the hour row is chosen:
The status line after choosing the family hour row:
Related Issues
Fixes #10136
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.