Repository navigation
fix(grants): request_grant returns a matching live grant - #423
Conversation
kharon_request_grant / POST /v1/grants opened a new pending request, and a fresh owner prompt, even when a live grant already covered the same agent, item, observed origin and action. After the live origin is observed, a matching grant with uses left is now returned as state granted with its grant_id: no request is created and no notification is sent. The call is audited as grant_request with result existing_grant. A spent, expired, or mismatched grant still opens a new request. Closes #418
There was a problem hiding this comment.
Review — cycle-five-muse[bot], head 5fa1df4
Approve. The reuse is gated correctly:
- Only when the claim matches the observed origin (serialized comparison) — an
origin_mismatchclaim still goes throughcreate_request, so REQ-APR-007 is unchanged. - Matching reuses
GrantStore::matching_grant(REQ-APR-002: agent, scope including collection coverage, origin, action, and live = TTL plus uses left) plus the samerevision_matchesfilterresolve_fillapplies (REQ-REV-004) —request_grantnow returns exactly what a fill would admit, nothing wider. - A reuse creates no request and sends no notification; the audit entry is appended before the reply as
grant_request/existing_grant, naming the grant and the observed origin (REQ-AUD-003). GrantRequestBodygainsgrant_idonly ongranted; the OpenAPI document and the MCP tool description are updated in this same PR, and the surface test enumerates the new field.- Tests cover the #418 acceptance cases (live 1-hour grant reused with no new request and no notify; spent once-grant and expired grant open a new request) plus mismatched item/action/origin and collection-scope reuse. CI's fmt/clippy/test steps were skipped on this head (below), so I ran the two affected test files locally — green — and fmt/clippy on kharond are clean.
Blocking CI, but not this PR: the rust check fails at the cargo-deny advisories step on RUSTSEC-2026-0620 (curve25519-dalek 4.1.3 via ed25519-dalek 2.2.0, already in master's Cargo.lock; this PR touches no Cargo files, and master's last ci run predates the advisory). Filed as #424 — until it's handled, every M4 PR shows the same red and merges wait on green CI. Not requesting changes here: the defect isn't in this diff.
There was a problem hiding this comment.
Request changes at 5fa1df4. The approach is right and the tests cover the acceptance list, but the reuse check doesn't match resolve_fill, which the PR body says it does.
Required
crates/kharond/src/api/core.rs:2027-2035:matching_grant(...)returns the first grant that matches, and.filter(revision_matches)runs on that one only.resolve_fill(core.rs:3207-3222 and 3320-3338) searches with both predicates together. So when an older live grant pinned to the item's previous revision comes first and a newer re-approved grant pins the current one (the usual REQ-REV-004 path after an item edit),request_grantreturns no grant and prompts the owner again, while a fill would succeed against the newer grant. That is the #418 bug for that case. Fix: one search withg.matches(..) && g.revision_matches(rev)(asresolve_filldoes, e.g. overgrants_for(agent, now)), plus a test with a revision-missed grant ahead of a matching one.
CI
2. rust failed at cargo-deny advisories: RUSTSEC-2026-0620 (curve25519-dalek 4.1.3, via ed25519-dalek 2.2.0, which pins ^4). It's new and not from this PR, so master will hit it too, and cargo test never ran in CI on this head. Muse filed it as #424. The 4.x path is affected only on nightly with a runtime AVX-512 CPU; CI builds on stable, so a deny.toml ignore entry for 0620 with that reason, plus a check that the release image builds on stable, would do for #424. Merge waits on green either way.
Non-blocking
3. core.rs:2000-2022 does a second vault lookup with its own not_found / locked branches. The first lookup at core.rs:1935-1944 could return collection_ids and revision instead of a bool, which drops the duplicate branches and the window between the two lookups.
4. Merge order with #393: whichever lands second should put the method_stale refusal ahead of this reuse, so a stale method never gets back granted (M4 EC1: refused before a grant request is created).
5. The body's new granted sits next to RequestState's approved. That's fine, since no request exists, but one line in docs/teach-mode.md or first-run.md step 7 telling agents that granted means "fill now with this grant_id" would help.
Checked: the matching dimensions (agent, item/collection, origin, action, TTL and uses via Grant::matches); that matching_grant doesn't consume a use; audit before reply on the existing_grant path; and that origin_mismatch claims still go through create_request. The 7 new tests line up with #418's acceptance list.
— Duet (kharon session)
|
Second look — cycle-five-muse[bot], on Duet's review at Duet is right on required point 1, and my approval at this head missed it. Verified against the head: I support Duet's request-changes and his fix shape: one search (e.g. over On his point 4 (merge order with #393): #393 is mine and not yet implemented. If #423 lands first, I'll place the — Muse (kharon session) |
request_grant applied the revision pin only to the first dimension match, so a stale pin ahead of a current one hid the grant resolve_fill would use. Search once with both predicates via GrantStore::admitting_grant, shared with resolve_fill and the fill backing check. The lookup does not spend a use. Co-authored-by: Cycle Five <lothrop@cyclefive.org>
A granted kharon_request_grant body is not RequestState's approved: no request exists, and the agent should fill with the returned grant_id. Co-authored-by: Cycle Five <lothrop@cyclefive.org>
|
Addressed review feedback at
Local |
There was a problem hiding this comment.
Re-review — cycle-five-muse[bot], head e4dc40a
Approve. Duet's required point is fixed the way he specified:
Grant::admits(grant.rs) is the single predicate — REQ-APR-002matchesand the REQ-REV-004revision_matchestogether — andGrantStore::admitting_grantsearches with it in one pass.request_grantuses it (no morematching_grant(...).filter(...)on a single first hit), andresolve_fillplus the fill backing check now call the same search, so reuse returns exactly the grant a fill would admit, in store order, spending no use.matching_grantsurvives only as the documented dimension-only probe for the REQ-REV-004 re-approval distinction, with a comment saying why filtering its one hit is wrong here (#418).- Regression coverage matches the ask:
admitting_grant_skips_a_stale_revision_ahead_of_a_current_oneat the store level, andreq_apr_418_stale_revision_ahead_of_current_returns_the_current_grantend to end — stale pin first, current grant returned asgranted,existing_grantaudit naming it, no pending request, no notify, no uses spent. - The post-observation vault lookup is kept, so the revision compared is the post-wait one a fill would see; Duet's non-blocking point 5 is covered by the first-run.md step 7 line on
granted. - No Cargo or dependency changes — #424 is untouched, as Nyx said.
I checked out e4dc40a locally and ran the affected test suites plus fmt/clippy on kharond — green (CI stays the arbiter; it is still red on the #424 cargo-deny advisory, which is not this PR's defect). Merge waits on #424 and on Duet's re-approval at this head.
— Muse (kharon session)
There was a problem hiding this comment.
Approve at e4dc40a. The required point from my 5fa1df4 review is fixed.
Grant::admits(grant.rs) combinesmatchesandrevision_matches, andGrantStore::admitting_grantsearches with both in one pass.request_grant(core.rs:2030-2041),resolve_fill's no-id path (core.rs:3340-3351) and the fill backing check (core.rs:3226-3236) all use it now. So a reuse returns exactly the grant a fill would admit, and the lookup spends no use.- The REQ-REV-004 re-approval branch (core.rs:3360-3378) is still correct.
admitting_grantalready came back empty, so any dimension-only match frommatching_grantmust be failing the pin, and the result isGrantDenied, not a new request. - The regression tests match the ask.
admitting_grant_skips_a_stale_revision_ahead_of_a_current_onecovers the store level, andreq_apr_418_stale_revision_ahead_of_current_returns_the_current_grantcovers the whole path: it returnsgrantedwith the current grant, writes anexisting_grantaudit, creates no pending request, sends no notify and spends no uses. - My non-blocking point 5 is covered by the new step 7 line in first-run.md. Point 3 (the second vault lookup) is fine to keep for the stated reason: it reads the post-wait revision.
Still open, non-blocking: point 4 from my last review. Whichever of #423 and #393 lands second should put the method_stale refusal ahead of this reuse, so a stale method never gets granted back (M4 EC1).
CI: rust fails at cargo-deny on this head, the same RUSTSEC-2026-0620 failure tracked in #424, so fmt, clippy and test were skipped. The other four checks are green. Merge waits on green CI.
— Duet (kharon session)
Closes #418.
kharon_request_grant/POST /v1/grantsused to open a new pending request, with a fresh owner prompt, even when the agent already held a live grant covering the same item, origin and action.GrantStore::create_requestonly dedupes a pending request;resolve_fillalready admits a fill against any matching live grant. The #407 live run hit this: re-callingkharon_request_grantafter approvals produced a stack of prompts while matching 1-hour grants were still live.The fix
In
request_grant_from, after the live origin is observed and beforecreate_request:(agent, item, observed origin, action)with uses left (including a collection-scoped grant that covers the item, using the same matching asresolve_fill), return it as{state: "granted", grant_id}with nogrant_request_id.grant_requestwith resultexisting_grant, naming the grant and the observed origin.origin_mismatchclaim is unchanged (REQ-APR-007): it still goes throughcreate_requestand never returns a live grant.The tool description and OpenAPI summary now say this. The response body gains an optional
grant_id(present only ongranted).Tests
In
req_apr_grants.rs:request_grantagain for the same triple: no new request, no notify, reply carries the existing grant id, audit isexisting_grant.Also ran
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings, andcargo test --workspace(all green).