Skip to content

feat(runtime): a reviewer approval records an exact grant that never widens (DA4) - #135

Merged
lg2m merged 1 commit into
feat/eng-862-da1-reviewer-deny-finalfrom
feat/eng-862-da4-delegate-grants
Sep 23, 2026
Merged

lg2m merged 1 commit into
feat/eng-862-da1-reviewer-deny-finalfrom
feat/eng-862-da4-delegate-grants

Conversation

@lg2m

@lg2m lg2m commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

DA4 — exact grants, no durable widening

Spec: docs/plans/delegated-approval.md § DA4 (on #123). Linear: ENG-862. Stacked on: #133 (DA1), which is on #125. The base is the DA1 branch so this diff shows only DA4. Retarget as the stack merges: #125 → #133 → this.

What changed

A configured reviewer_model could approve a held call but had no way to say "and don't ask me about this exact thing again", so an auto session re-consulted the reviewer for every repeat of the same command. The reviewer now records a grant of its own, and that grant is deliberately narrower than anything a human can record:

  • Provenance on every grant. session_grants gains source (human | delegate, default human) and run_id (NULL for a human). Store schema 34 → 35. A pre-35 store's rows all become human, which is what they were; the migration refuses a wrong-shaped column like every other step.
  • A reviewer Approve records its grant in the approval's own transaction: the exact command string for shell, the exact host for fetch, nothing for other classes. SessionGrants gains a delegate: DelegateGrants { commands, hosts } set the evaluator matches byte-for-byte only. The human's tools, shell_prefixes, and hosts keep their wide shapes.
  • The Forbidden floor holds. quotes_exactly reads only human prefixes. A delegate row with the exact text of a forbidden command changes nothing, under all five modes. A human's exact string still lifts it (ADR-0020). docs(plans): delegated approval — plan, contract, and ledger #123 records why this distinction had to exist.
  • Bounded. MAX_DELEGATE_GRANTS_PER_RUN = 64 by run_id, on top of the session-wide 256. The fix(runtime): approve a call once when its grant cannot be stored #125 storage rule applies unchanged: a value that does not fit approves the call once and records nothing; the approval never fails. A human grant with the same (kind, value) is kept and the delegate row is not written.
  • No promotion. Only a human ApproveForWorkspace reaches pending_workspace_grant_promotions. Asserted directly.

Not changed: human once/session/workspace choices including prefix grants; config seeds (human); approved_by_reviewer and the rest of the resolution vocabulary; the reviewer request shape. No protocol bump.

Owned paths

crates/qq-core/src/sessions/approvals.rs, crates/qq-core/src/approval.rs, and the store code those need: sessions/tool_calls.rs (DelegateGrant, the recording), sessions/store.rs (wrapper signature), store/schema.rs (35). docs/design/tools.md § Grant Lifetimes gains the Delegate lifetime.

How verified

  • approval::tests::delegate_grants_match_exactly_and_never_lift_forbidden — evaluator, all modes: exact command covered, -m y and --amend not, subdomain not, delegate exact string does not lift Forbidden while the human's does.
  • sessions/tests/approvals.rs: a_delegate_approval_records_an_exact_command_grant_and_nothing_wider (git commit -m x ×2 + -m y: two holds, two consultations, zero promotion rows), a_delegate_host_grant_covers_the_exact_host_only, a_delegate_grant_that_cannot_be_stored_still_approves_the_call_once (byte cap + per-run cap), a_delegate_grant_never_lifts_forbidden_and_a_forbidden_call_never_reaches_the_reviewer (plan acceptance 2, the reviewer_model half).
  • migrations::version_thirty_four_gains_grant_provenance_and_keeps_old_rows_human; 26 existing migration assertions moved from "34" to "35".
  • cargo test -p qq-core --lib — 630 passed (compaction/streaming skipped locally; approvals, delegation, migrations in full). mcp_session integration; binary reviewer + headless allowlist tests.
  • cargo fmt --all -- --check; cargo clippy --workspace --all-targets --all-features -- -D warnings.

Not run: cargo test --workspace.

Measurements

No named gate. Two indexed lookups and one insert inside a transaction that already exists, only on a reviewer approve. load_approval_policy reads one more column per row.

Docs

docs/design/tools.md in this PR. Ledger entry on #123, which also notes what stays with DA5 (jev vs reviewer identity on a delegate row) and DA6 (the event field).

Review note

Touches sessions/ and bumps the store schema; the plan asks for independent review.

…widens (DA4)

When the configured reviewer_model approves a held call it now records a session grant of its own, in the same transaction as the approval: the exact command string for shell, the exact host for fetch, nothing for other tool classes. Every session_grants row carries `source` (human | delegate) and, for a delegate, the `run_id` that recorded it. Store schema 34 -> 35; pre-35 rows are all `human`.

A delegate grant is narrower than a human one on purpose. It matches only the byte-exact command or host, never a prefix or a `*.suffix`; it does not lift a Forbidden verdict, which only a human's exact string may do (ADR-0020); it is never promoted to workspace configuration; and one run may record at most 64 of them. The #125 storage rule applies unchanged: a value that does not fit approves the call once and records nothing. A human grant with the same (kind, value) is kept and the delegate row is not written.

Human once/session/workspace choices, config seeds, the resolution vocabulary, and the reviewer request shape are unchanged. No protocol bump.

ENG-862
@lg2m
lg2m added this pull request to stack #134 September 23, 2026 04:03
@lg2m
lg2m merged commit d87b887 into main Sep 23, 2026
4 checks passed
@lg2m
lg2m deleted the feat/eng-862-da4-delegate-grants branch September 23, 2026 04:42
lg2m added a commit that referenced this pull request Sep 23, 2026
…d-approval ledger

The plan's status block, task index, and ledger now say what shipped:
#125 grant storage rule, DA1 (#133), DA4 (#135), DA3 (#143), DA5 (#144,
ADR-0041 accepted), DA2 in review (#150). The target contract reflects the
as-built knob name (approval_delegate: by-mode|on|off), the 20 s delegate
backstop, and no server deadline by default; the delegate identity on the
wire is left to DA6. Index rows in docs/README.md and docs/plans/README.md
no longer call the plan proposed.

Refs ENG-862
lg2m added a commit that referenced this pull request Sep 23, 2026
* docs(plans): propose delegated approval

An opt-in delegate settles the calls an approval mode already holds:
Jev when jev_approval is on, otherwise reviewer_model, otherwise the
human. Forbidden, blocked hosts, and ask_user never reach a delegate.

DA1-DA6 in docs/plans/delegated-approval.md; target contract in
docs/design/delegated-approval.md. ADR-0041 reserved for DA5, which
supersedes ADR-0030's "Jev never authorizes side effects" for the
approval lane only. DA2 consumes run-reliability RR9 rather than
re-owning the interactive approval deadline.

ENG-862

* docs(guide): a grant that cannot be stored approves once, and no grant lifts forbidden

The permissions guide offered a session grant for every prompt and the troubleshooting guide told the operator to session-approve an exact forbidden command. Neither is true: a grant past 256 bytes or past the session cap approves the call once and records nothing, and the Forbidden floor is above every grant.

ENG-862

* docs(plans): a delegate grant must not lift Forbidden

An exact-string human grant lifts Forbidden today, and the guide had been corrected to deny that. The guide now states the rule and the 256-byte bound that limits it. DA4 must record a delegate grant so the evaluator can tell it from a human one; otherwise approving an exact forbidden command would open the floor the plan says it does not touch.

ENG-862

* docs(plans): record DA1 in review on the delegated-approval ledger

DA1 (`feat/eng-862-da1-reviewer-deny-final`, stacked on #125) makes a reviewer denial final under `auto` and starts the human wait at the escalation. The ledger records what shipped, what did not, and that DA2 keeps the delegate's own bound while the wait-restart half is done.

ENG-862

* docs(plans): record DA4 in review on the delegated-approval ledger

DA4 (`feat/eng-862-da4-delegate-grants`, stacked on DA1) gives every session grant a `source` and records a reviewer's exact-command or exact-host grant on its Approve, capped per run, never lifting Forbidden and never promoted. Store schema 34 -> 35. The ledger notes that the jev-vs-reviewer identity on a delegate row is DA5's.

ENG-862

* feat(runtime): give the delegate and the human separate approval clocks (DA2)

A held tool call used one wait timer for both the reviewer and the human, so
a prompt left unattended was denied by timeout while the person was away.

- The delegate (reviewer or Jev) gets its own clock, DEFAULT_DELEGATE_TIMEOUT
  (20 s). When it expires the pending review is dropped and the human is asked.
- The human prompt has no server deadline by default
  (DEFAULT_APPROVAL_TIMEOUT = None). With a delegate on, the human clock only
  starts at Escalate, a non-final Deny, or the delegate cut-off.
- approval_timeout_seconds (1..=86400) opts a workspace back into a bounded
  human wait; zero and out-of-range values fail config validation. The key is
  not trust-gated because it can only shorten a wait.
- RuntimeHandler::open_with(factory, approval_timeout) threads the configured
  wait through qq run, the TUI, and qq serve. Headless keeps the 20 s
  REVIEWER_DENY_GRACE for an immediate deny without a delegate.
- explain approval_timeout and show print the setting.

This ships RR9's minimum (no silent timeout denial); the rest of RR9 stays
planned. Tests cover a reviewer that never answers, a stuck reviewer with an
absent human, and the no-deadline default.

Refs ENG-862, ENG-871

* docs(plans): record DA3, DA5 merged and DA2 in review on the delegated-approval ledger

The plan's status block, task index, and ledger now say what shipped:
#125 grant storage rule, DA1 (#133), DA4 (#135), DA3 (#143), DA5 (#144,
ADR-0041 accepted), DA2 in review (#150). The target contract reflects the
as-built knob name (approval_delegate: by-mode|on|off), the 20 s delegate
backstop, and no server deadline by default; the delegate identity on the
wire is left to DA6. Index rows in docs/README.md and docs/plans/README.md
no longer call the plan proposed.

Refs ENG-862
lg2m added a commit that referenced this pull request Sep 24, 2026
Every slice of docs/plans/delegated-approval.md is on main (#125, #133,
#135, #143, #144, #150, #123, #152). The plan's own acceptance 5 says it is
deleted once shipped and the ledger remains as the receipt; this does that.

- Delete docs/plans/delegated-approval.md. The goal, slice table, and
  acceptance checklist move to the head of the ledger so it stands alone;
  index rows in docs/README.md, docs/plans/README.md, and
  docs/plans/progress/README.md point at the as-built text and the receipt.
- Close acceptance 2's blocked-host half, which only had a test under `full`
  with no delegate: `a_blocked_host_never_reaches_the_delegate_even_when_one_would_approve`
  runs under `auto` with `approval_delegate: on` and a Jev-attributed
  reviewer that would approve, and asserts the link-local fetch is denied
  with no hold, no escalation, no reviewer call, and no delegate host grant.
- Acceptance 3 (one week of real use) stays open until 2026-09-30; the
  ledger records the two queries to run and the entry to write.

Verification: cargo test --workspace, fmt --check, clippy -D warnings.

Refs ENG-862
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