Skip to content

feat(runtime): approval_delegate chooses who settles a held call (DA3) - #143

Merged
lg2m merged 1 commit into
mainfrom
feat/eng-862-da3-delegate-opt-in
Sep 23, 2026
Merged

lg2m merged 1 commit into
mainfrom
feat/eng-862-da3-delegate-opt-in

Conversation

@lg2m

@lg2m lg2m commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

DA3 of docs/plans/delegated-approval.md: a configuration key, approval_delegate: on | off, decides whether the configured reviewer_model is consulted for the calls a session's approval mode already holds. The mode stays the ceiling; the setting only picks who decides inside it.

  • Absent (the default) keeps every mode's prior behavior: reviewer under auto and supervised, human under ask. A configuration that never mentions it is unchanged.
  • on extends the reviewer to ask-mode holds. Its approve settles the call; its deny is advice — the human is still asked with the reason and their wait restarts at the denial. Under auto/supervised a deny stays final (DA1).
  • off withdraws the reviewer everywhere: every held call waits for a human even under auto. This is the strict profile.
  • read-only and full hold nothing a delegate may decide, so the setting is inert there. Forbidden, blocked hosts, managed deny_*, and ask_user never reach the reviewer under any setting.

Set it at the top level, per profile (Profile(approval_mode: ask, approval_delegate: on)), or with QQ_APPROVAL_DELEGATE. A project file that sets it needs trust like jev_routing. qq config show and qq config explain approval_delegate report it.

Design

  • qq_core::ApprovalDelegate { ByMode, On, Off } with consults_reviewer(mode) and deny_is_final(mode); plumbed Runtime → AgentProfile → CompiledAgentPlan → SessionToolGate exactly like network and turn_recovery. Not part of the plan digest: it changes who is asked, never what the model may do.
  • qq_config::ApprovalDelegateSetting { On, Off }; the composition root translates Option<Setting> to ApprovalDelegate. qq-core learns no configuration type (ADR-0004).
  • The gate's reviewer arm now matches Deny only when deny_is_final(mode); otherwise it falls through to the escalate arm and restarts the human deadline.
  • Reviewer system prompt and the "Session mode" line now describe ask honestly (deny escalates there).
  • No protocol change: the wire ApprovalMode enum does not grow. No store change.

Verification

  • 5 new gate tests in sessions/tests/approvals.rs: ask+on approve settles; ask+on deny escalates and the human's answer inside the restarted wait stands; auto+off never consults the reviewer; full+on executes without a reviewer round trip; the mode×setting table.
  • 2 new config tests: absent/on/off/override/provenance, invalid values rejected; workspace-file and profile declarations require trust and re-trust on change.
  • 1 new root test: config → profile → override reaches the plan, the cache keys on the override, and the digest is unchanged by the choice.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace all clean.

Stack

Based on main (DA1 #133 and DA4 #135 merged). DA5 (Jev as the delegate) stacks on this branch.

ENG-862

A new configuration key, approval_delegate: on | off, decides whether the configured reviewer_model is consulted for the calls a session's approval mode already holds. The mode stays the ceiling; the setting only picks who decides inside it. Absent keeps every mode's prior default: the reviewer under auto and supervised, the human under ask. `on` extends the reviewer to ask-mode holds; `off` withdraws it everywhere so every hold waits for a human. read-only and full hold nothing a delegate may decide, so the setting is inert there.

Under ask a reviewer deny is advice, not a verdict: the hold stays open, the human is asked with the reason, and their wait restarts at the denial. Under auto and supervised a deny remains final (DA1). Forbidden shapes, blocked hosts, managed deny_*, and ask_user never reach the reviewer.

The setting is a top-level key, a per-profile key, and the QQ_APPROVAL_DELEGATE override; a project file that sets it needs trust like jev_routing. It is plumbed Runtime -> AgentProfile -> CompiledAgentPlan -> SessionToolGate as ApprovalDelegate and is not part of the plan digest. qq-core learns no configuration type; the root translates.

No protocol change; the mode enum on the wire does not grow.

ENG-862
@lg2m
lg2m added this pull request to stack #145 September 23, 2026 20:46
@lg2m
lg2m merged commit 2d906a0 into main Sep 23, 2026
4 checks passed
@lg2m
lg2m deleted the feat/eng-862-da3-delegate-opt-in branch September 23, 2026 22:16
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