← Back to Pull requests

fix(research): refuse re-granting an active grant; add a revoked grant's new budget once #251

Closed
unknown closed this pull request without merging on Nov 21, 2026 18:46 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 05:25 UTC
Author

What and why

Fixes #235.

POST /api/v1/grants returned 200 and kept the old budget when the steward had already granted the researcher the connector, active or revoked: the grant id is reused and BudgetLedger::open only inserts. A steward re-granting an exhausted researcher got 0 remaining with no sign why.

  • Active grant with a budget: refused with 409 and audited (tenant.provisioned denied, reason=already_granted). The body says to raise the budget with POST /api/v1/grants/{grant_id}/budget.

  • Revoked grant: re-activated first, then the new budget is added on top of the old one and audited as research.budget. If re-activation fails, nothing changed and a retry adds its own amount. If funding fails after it, the grant is active with its old budget and a retry gets 409: nothing is added twice or dropped.

  • New grant, or an active one with no budget entry: opens its budget.

  • Approvals fund with one top_up_once that creates the entry if it is missing, so a failed approval leaves no placeholder entry and "has an entry" means "funded". Zero budgets stay grantable.

  • Revokes record the latest time again, so revoked_since still refuses a stale approval retry after a second revoke.

  • Concurrency: direct grants, approvals (from recording the decision), steward top-ups and revokes take one lock, since the grant and its budget live in two stores. This holds in one process. P62 now tracks conditional writes for several instances, finer locks, and a revocation counter in place of the timestamp comparison.

  • Every top-up of an existing budget on a grant path emits research.budget with the actual change.
  • How it was tested

  • Each scenario from the review has a test that failed before the fix:

  • - a re-grant after a failed one adds its own amount (38, not 78);
    - a failed re-grant leaves 28, and a later approval of 5 gives 33;
    - a second revoke still refuses a stale approval retry (404);
    - a failed approval leaves no entry, so a direct grant funds it;
    - a revoke queued before an approval lands before its decision;
    - a steward top-up racing an approval isn't audited as the approval's;
    - a zero re-grant audits nothing.
  • Races: two re-grants of a revoked grant (200 and 409), a revoke racing a grant, a grant racing an approval.

  • The 409 body; a zero-budget grant followed by a direct grant gets 409.

  • audit_coverage.rs: the already_granted denial, the re-grant and follow-up-approval top-ups, and nothing for a retry.

  • cannot_reset_budget_spend_by_regranting (#241) now expects the re-grant's budget to be added and the spend kept (limit 102, spent 1).
  • Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs

  • Fails closed on missing configuration, key material, or attestation: n/a

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made: n/a
  • Diff: 399 lines (+299 / -100) across 4 files Reviewer: abendrothj Review duration: 9441m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 399 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #251"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.7% · Safe to merge
    18.7%