Skip to content

feat(approvals): expiring command-scoped trust grants - #19220

Merged
cruisercohen merged 2 commits into
mainfrom
fix/10136-expiring-trust-grants
Oct 13, 2026
Merged

cruisercohen merged 2 commits into
mainfrom
fix/10136-expiring-trust-grants

Conversation

@cruisercohen

@cruisercohen cruisercohen commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 git commands") 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 "trust aws 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

  • Timed variants of "Trust read-only commands" or "Trust all tools for this session". Those keep their current lifetimes; auto-approve-all keeps its own configured duration.
  • Grants that apply across chats, a gateway-wide grant store, or a list/revoke screen for grants.
  • Persisting grants across a restart. Every per-chat grant, timed or not, stays in memory as it does today.
  • The channels page approval card and other approval surfaces. Only the chat approval prompt offers timed rows.

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:

  • Chosen: expiry on the existing per-chat command grants. The Trust menu gains "for an hour" and "until midnight" next to each command-scoped tier. The grant stays on the chat that made it and is checked by the existing fail-closed decision path.
  • Rejected: close the issue as delivered, pointing at the existing tiers. It leaves the one concrete ask (a time-bound grant for one command) unanswered.
  • Rejected: gateway-wide, cross-chat per-tool grants with expiry, a management list and revocation. It is a new standing-privilege surface that outlives the chat, which is a wider approval boundary than the issue needs.

Why a decision-time deadline, not a timer. App worker leases already expire patterns on the same chat with a call_later timer. 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_ttl accepts only a plain integer from 1 to 86400.
    • GrantDeadline holds a wall-clock and a monotonic deadline.
    • record_trust_grant puts 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_patterns drops every timed grant past either deadline and returns the chat-long patterns plus the live timed ones.
    • timed_grant_deadline gives the deadline an approval rests on: None when 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.
    • GrantEnded is what a transport raises instead of answering when that deadline has passed, and grant_deadline_guard is the under-lock check that raises it.
  • The chat slot carries _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_approve reads an optional ttl_seconds. It is honoured on trust_command and trust_base only. Any other decision carrying it is refused with ttl_unsupported, and an unreadable value with ttl_invalid, both before any side effect: no pattern is recorded, no session policy is touched, and the pending call stays pending.
  • The runner matches each call against live_trusted_patterns(...) instead of the bare set, so an expired grant never approves anything and the call prompts again.
  • When the match rests on a timed grant, the runner calls 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 (AcpClient and AcpSessionHandle) turn it into a check (grant_deadline_guard) that they hand to the existing before_write hook 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), and GrantEnded is 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 pass deadline on only when one is given. An approval with no timed grant behind it calls approve_tool(request_id) exactly as on main, hands no check to the write, and never reads a clock.

Frontend

  • TrustDropdown gains an opt-in timedGrants prop. When set:
    • the command tier and the family tier each get two more rows, "for an hour (until 7:58 AM)" and "until midnight (12:00 AM)", each naming the local clock time its grant would end;
    • their chat-long rows say "for this session", so no row reads as permanent;
    • the three family rows read "Trust any ls command …", and wrap rather than truncate so the lifetime is never clipped;
    • onAction receives the lifetime in seconds.
    • Without the prop (channels page, other surfaces) labels and rows are unchanged.
  • The lifetime is computed at the click: an hour is 3600 seconds; the rest of today is the seconds until the user's local midnight, rounded up so the grant lasts until midnight and clamped to 1..86400 (utils/grantDuration.ts). grantEndsAt gives the end time the rows show.
  • The chat approval prompt passes timedGrants and sends ttl_seconds with 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".
  • Eight new catalog keys, translated into all eleven shipped languages, with translator context; the pseudolocale is regenerated.

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_seconds is 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 any ls command for this session"; the grants they record are unchanged.

approve_tool on the provider interface, both providers and both ACP transports gains an optional keyword deadline, and the transports' response sends (AcpClient._send_response, AcpRuntime.send_response and its session-runtime protocol) gain an optional keyword before_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_seconds validation: 1, 3600 and 86400 are accepted; 0, negative, over a day, bools, floats, strings, None and lists are refused.
    • A timed grant lands only in the timed store; a later chat-long grant moves it to the shared set.
    • The deadline counts on both clocks.
    • live_trusted_patterns keeps chat-long and live timed grants and drops expired ones.
    • Wall-clock expiry ends a grant whose monotonic deadline has not passed (suspended host); monotonic expiry ends one whose wall-clock deadline has not passed (clock set backwards).
    • A timed grant expiring leaves a pattern another writer holds; another writer withdrawing its pattern leaves a live timed grant.
    • Endpoint: a timed command grant and a timed family grant record both deadlines and nothing in the shared set; a grant without a lifetime records none.
    • Endpoint: a timed grant lands only on the chat that made it, and another chat's pending call is untouched.
    • Endpoint: an unreadable lifetime returns 400 ttl_invalid with no grant and the call still pending; a lifetime on trust, trust_reads, approved or yolo returns 400 ttl_unsupported with no trust flag, no policy write and the call still pending.
  • test/test_chat_runner_coverage.py:
    • A live timed grant auto-approves.
    • A grant past its wall-clock deadline is dropped before the matcher runs (the matcher sees only the chat-long pattern).
    • With only an expired grant (monotonic) the matcher is never called.
    • A grant that expires during the awaited program-name check prompts instead of auto-approving.
    • A live timed grant's approval carries its deadline; a call the chat-long patterns cover is approved with approve_tool("req") and nothing else, whether or not a timed grant also matches.
    • With the real AcpClient underneath, 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.
    • These fail without the runner change.
  • 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:
    • A deadline that passes before the write writes nothing, keeps the floor event and recorded options, and the later approval answers with the recorded option.
    • A deadline still live at the write is answered; one passed on either clock is not.
    • With a real write lock held by another frame, a grant that ends while the answer waits for the lock writes nothing and keeps the request; the later approval writes once. This fails without the under-lock check.
    • An approval with no deadline is answered with the same send call (no write check) however long the floor takes.
    • The providers pass deadline on only when one is given.
    • The reviewed list of approval call sites counts the new calls.
  • TrustDropdown.test.tsx:
    • No timed rows without the prop, and the unqualified labels are kept there.
    • With the prop: the exact row order and labels, and each timed row naming the end time the click would grant (11:30 PM and midnight at 22:30).
    • The hour row sends 3600; at 22:30 local the rest-of-today row sends 5400.
    • Chat-long rows still send no lifetime, and the session-wide and reads tiers get no timed row.
    • The family rows wrap instead of truncating.
  • ChatInput.approval.test.tsx: the timed command row sends ttl_seconds: 3600 and the status line names the command and carries the clock icon, not the lock; the timed family row sends ttl_seconds and 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

  • Captured the real chat composer through the repo's isolated approval-prompt capture entry, with the approve endpoint intercepted. The capture asserted:
    • all eight menu rows, in order;
    • that the menu fits the viewport at 900px and 360px;
    • that no row label is clipped (scroll width vs client width on every row);
    • that the hour row posts {"action": "trust_command", "ttl_seconds": 3600, ...};
    • that the status line reads "Trusted “…” until …, then it asks again" and carries the clock icon.
  • Not exercised end to end against a live agent past an actual one-hour deadline; the decision-time expiry, including the suspended-host case, is covered by the tests above.

Screenshots / video

Trust menu on the chat approval prompt, dark and light:

Trust menu with timed rows, dark

Trust menu with timed rows, light

Narrow viewport (360px) and the status lines after a timed command grant and a timed family grant

Trust menu with timed rows at 360px

The status line alone, as it renders after the hour row is chosen:

Status line after choosing the hour row

The status line after choosing the family hour row:

Status line after choosing the family hour row

Related Issues

Fixes #10136

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 57e82d7bca4ee2a93ee79aeccd9a0501520376b1 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The transport-level deadline re-check threads a new deadline/before_write parameter through six approval signatures for one caller, to close a window the decision-time check already bounds.

Not justified as shipped

  • Item 6 — oversized: the description justifies it by saying the awaited hops "can span a host suspend of any length". The call was matched while its grant was live, so the harm is an approval that a human already authorised for that command and that is written late. The Goal says nothing about it: "after which the approval prompt comes back on its own". deadline has one caller (chat_runner._run_chat), yet it is plumbed through LLMProvider, AcpProvider, AcpSessionProvider, AcpSessionHandle, AcpClient and AcpRuntime, along with the restore-on-GrantEnded branches.
    Subtraction: delete GrantEnded, grant_deadline_guard, timed_grant_deadline, every deadline=/before_write= parameter and the restore blocks. Keep only live_trusted_patterns at decision time.
    Clears when: the transport check is removed, or a reproduction shows a late approval reaching a command the user did not trust.

What this change ships

Inventory (8 items) — 7 justified

Intent: let a user trust one command or command family for an hour or until midnight, after which the prompt returns. ADDITION.

  1. The chat Trust menu gains "for an hour" and "until midnight" rows on the command and family tiers — justified
  2. The chat-long command and family rows now read "for this session" when the timed rows are present — justified
  3. Family rows read "Trust any ls command" and wrap instead of truncating — justified
  4. A clock-tinted status line confirms a timed grant and when it ends — justified
  5. The approve API accepts ttl_seconds and refuses it with ttl_unsupported/ttl_invalid before any side effect — justified
  6. Each transport re-checks the timed grant's deadline under its write lock and restores the request if it has passed — oversized
  7. Each chat slot keeps a separate in-memory store of timed grants on two clocks, pruned at decision time — justified
  8. TrustDropdown gains an opt-in timedGrants prop; other surfaces are unchanged — justified

[FIRST-PRINCIPLES-REVIEWED] 57e82d7

Description read

[DESCRIPTION-READ] 42e3eb527baf9ad4d5893ab115671b838c730abbc1cb2ee0e4fa0cd1cabcc90e

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 57e82d7bca4ee2a93ee79aeccd9a0501520376b1 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that a person can still answer the fallback prompt after GrantEnded on both AcpClient and AcpSessionHandle, because both restore the request's floor event and options.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — 🟡 CONCERNS

UX-level review of 57e82d7bca4ee2a93ee79aeccd9a0501520376b1 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • "For this session" is unexplained. The PR adds trust_this_command_session and trust_all_base_session ("…for this session") so the long-lived rows state how long they last. The menu never says what a session is. The blind reader said: "I don't know when a 'session' ends: closing the window, logging out, or something else." The PR's own description calls this lifetime "the whole chat." This hits every user who compares the three lifetimes in the menu. The smallest fix is "for this chat" in the two new keys.
  • "Trust read-only commands" now reads as permanent. Every other row now names a lifetime, so this row stands out by having none. The blind reader: "it might last forever -> no, I can't tell how long it lasts." The PR set out to make sure no row reads as permanent, and this row now does. Give it the same lifetime suffix as the session-long rows, without adding a timed version (timed variants are a stated non-goal).
  • The "any ls command" rows were only guessed at. The blind reader understood all three, but only as "a guess." For the session-long row they added "probably not, because I don't know how wide 'any ls' is." This family-of-commands scope is half of the PR's goal.

Suggestions

  • TrustDropdown now shows 8 flat rows, and the full command repeats three times. On a narrow screen (shot-03), break-all splits the path mid-word ("…/doc" / "s") on every one of those three rows. Show the full command once as a header, with "for this session / for an hour (until …) / until midnight (…)" as the rows under it.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 57e82d7bca4ee2a93ee79aeccd9a0501520376b1 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 57e82d7

Verdict parsed from the review's SHA-scoped output markers for commit 57e82d7bca4ee2a93ee79aeccd9a0501520376b1.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 57e82d7bca4ee2a93ee79aeccd9a0501520376b1: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 57e82d7bca4ee2a93ee79aeccd9a0501520376b1 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 57e82d7

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 57e82d7bca4ee2a93ee79aeccd9a0501520376b1: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 12, 2026
@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from 63846eb to 33d435e Compare October 12, 2026 01:31
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Review follow-up on 33d435eeb7:

Design: deadline on the monotonic clock only. Fixed. A timed grant now carries a GrantDeadline(wall, mono) and is dropped once EITHER passes (live_trusted_patterns). test_wall_clock_expiry_covers_a_suspended_host freezes the monotonic clock before its deadline and moves wall time past it: the grant is dropped. test_monotonic_expiry_covers_a_clock_set_backwards covers the reverse. The runner test test_expired_timed_pattern_is_dropped_before_matching now expires the grant on the wall clock only.

Design / First Principles: two expiry mechanisms on one pattern set. Fixed by separation rather than by sharing. Timed grants no longer write _trusted_patterns at all: they live in their own per-chat store and are unioned in at decision time. The worker-lease timer and chat-long grants keep sole ownership of the shared set, so neither mechanism can end or extend the other's patterns. Tests:

  • test_expiry_never_touches_a_pattern_another_writer_holds
  • test_a_writer_withdrawing_its_pattern_leaves_a_timed_grant_live

Why not reuse the lease's call_later timer (now in the description): it runs on the loop's monotonic clock, which is the suspended-host defect above, and it would be a second remover on the shared set.

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.

@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from 33d435e to 236151e Compare October 12, 2026 01:54
@cruisercohen

Copy link
Copy Markdown
Contributor Author

UX follow-up on 236151ea6f:

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. ChatInput.approval.test.tsx asserts that the notice carries the clock and not the lock.

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 ls / ls * pair as on main; this PR only adds a lifetime to it.

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.

@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from 236151e to e07ba12 Compare October 12, 2026 02:08
@cruisercohen

Copy link
Copy Markdown
Contributor Author

GPT follow-up on e07ba1277b:

Recheck timed trust after the awaited program-name check. Fixed at the root. After _name_grant_refusal_off_loop returns, the runner re-derives the live set with live_trusted_patterns and matches the command again. There is no await between that match and approve_tool, so the approval rests on a grant that is live at the moment it is sent. When no live grant covers the command, the call falls through to the normal prompt.

test_timed_grant_expiring_during_the_program_check_prompts expires the grant inside the stubbed check. Without the recheck it fails: the call was auto-approved, prompted == []. With the recheck the call prompts.

@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from e07ba12 to 0884f8d Compare October 12, 2026 02:27
@cruisercohen

Copy link
Copy Markdown
Contributor Author

UX follow-up on 0884f8dc08:

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:

  • "Trust ls with any arguments for this session"
  • "Trust ls with any arguments for an hour"
  • "Trust ls with any arguments for the rest of today"

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 truncate clipped "for the rest of t…", and the capture checks every row for a clipped label. The confirmation reads "Trusted ls with any arguments until …, then it asks again". Translations and screenshots are refreshed.

"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.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 12, 2026
@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from 0884f8d to 5e5f05f Compare October 12, 2026 02:53
@cruisercohen

Copy link
Copy Markdown
Contributor Author

UX follow-up on 5e5f05fead:

Blocker: the family rows don't make their reach clear. Taken as suggested. The rows now read "Trust every ls command for this session / for an hour / for the rest of today". That states the grant in plain words: every run of that program, whatever follows it. The confirmation quotes the program so it reads as code: "Trusted every “ls” command until …, then it asks again". The menu and both confirmations are re-shot on this head.

"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.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@cruisercohen

Copy link
Copy Markdown
Contributor Author

First Principles follow-up on 5e5f05fead: the second match after the program-name check stays. The harm it stops is now named in the description. The awaited hop can span a host suspend of any length. A call matched before the suspend would then be approved hours after its grant's deadline: the same stretched-grant case the two-clock deadline exists for. The GPT lane raised this as a blocking security finding on the previous head.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@cruisercohen

cruisercohen commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

GPT follow-up on 5e5f05fead (fix rebased onto current main):

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 approve_tool. Both ACP transports check it after their security-floor hop, with no await before the answer. If the deadline has passed, they send nothing, put the request back as it was (floor event and recorded options), and raise GrantEnded. The runner then falls through to the normal prompt. An approval with no timed grant behind it passes no deadline and takes the existing path unchanged.

test_timed_grant_ending_before_the_send_prompts_and_sends_nothing runs the real AcpClient under the runner, with a floor check that lasts an hour on the transport's clocks. Without the fix, the call is answered without a prompt (['sent']). With the fix, it is prompted first (['prompted', 'sent']). The transport tests cover both transports: a deadline passing during the floor, either clock passing, a still-live deadline, and a deadline-less approval answered with the same frame however long the floor takes.

@cruisercohen
cruisercohen enabled auto-merge (squash) October 12, 2026 07:29
@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from f202bab to 0f33ac5 Compare October 12, 2026 08:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 12, 2026
@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from 0f33ac5 to 156678c Compare October 12, 2026 17:42
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 12, 2026
@cruisercohen
cruisercohen force-pushed the fix/10136-expiring-trust-grants branch from 156678c to b72c570 Compare October 12, 2026 20:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 12, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Maintainer review on head b72c570da3 (full diff read before merge). Holding the merge on one concrete defect; everything else looked right, including the sensitive-change questions (a timed grant cannot outlive either clock, cannot widen the matched command, and the no-ttl_seconds path is byte-identical to main).

Defect — the write-redirect check reads the chat-long set, not the live set.

src/kiro_crew/dashboard/chat_runner.py ~L14392-14398:

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 _tp_live (chat-long + still-live timed grants), but _redirect_outside_grant is still handed slot._trusted_patterns. So a timed exact grant such as "Trust echo hi > out.txt for an hour" matches, the redirect check then finds no pattern spelling the > in the chat-long set, returns True, and the call is declined with "Trusted pattern not applied — the command writes to a file through an output redirect" and re-prompted on every repeat for the hour. The chat-long row for the same command works, so the two rows behave differently for the same command.

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 _tp_live to _redirect_outside_grant. Worth one runner test with a timed exact grant on a redirecting command (the existing runner tests all use ls -la).

Two notes, no change needed: secondsUntilEndOfDay clamps to 86400 so on a 25-hour DST fall-back day "until midnight" ends an hour early; and trusted_patterns_count in the slot projection excludes timed grants.

Once the fix is pushed and CI is green I will approve and merge.

@cruisercohen

cruisercohen commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

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 en.context.json, and both sets are kept.

1. The write-redirect check read the chat-long set (fixed)

  • chat_runner.py: _redirect_outside_grant now gets _tp_live, the same set the match uses, so a live timed grant that spells the redirect covers it.
  • I checked the rest of the trusted-pattern rung for the same mistake. One more place had it: timed_grant_deadline in trust_patterns.py. It treated a part as covered by the chat-long set whenever a chat-long pattern matched it, ignoring the redirect rule. So with chat-long echo * plus a timed exact echo hi > out.txt, the approval rested on the timed grant for the redirect but carried no deadline, and the send-time re-check never ran. A part that writes through a redirect now counts as covered only under the rule redirect_outside_grant uses. Both functions share one helper, _covers_write_redirect, so the two rules cannot drift apart. Non-shell keys (mcp-trust:v1:<hex>:<hex>) never contain >, so nothing changes for them.
  • Runner tests in test_chat_runner_coverage.py. Each one asks the same echo hi > out.txt call twice with a zero approval timeout, so any prompt fails the test:
    • test_timed_exact_grant_covers_its_own_write_redirect: both calls are approved with the grant's deadline and no prompt. It fails on b72c570 (no approval, the decline notice).
    • test_chat_long_exact_grant_covers_its_own_write_redirect: the mirror test. Both calls are approved with no deadline; it passes before and after.
    • test_timed_redirect_grant_under_a_chat_long_base_grant_carries_its_deadline: chat-long echo/echo * plus the timed exact grant. Both calls are approved with the timed deadline. It fails on b72c570, and it still fails with only the first fix.
  • Unit tests in test_trust_timed_grants.py: three timed_grant_deadline cases. A redirect only a timed grant spells carries its deadline (fails on b72c570). A redirect a chat-long exact grant spells gives no deadline. A discard redirect under a chat-long base grant gives no deadline.

2. secondsUntilEndOfDay 86400 clamp on a 25-hour DST day: acknowledged, no change.

3. trusted_patterns_count excludes timed grants: acknowledged, no change.

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 iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

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.

Granular permission grants — scope tool approvals by type, duration, and session (not just "Allow once")

3 participants