← Back to Pull requests

fix(pilot): persist quotas and reserve reviewed spending envelopes #80

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 03, 2026 22:19 UTC
Author

The controlled pilot currently resets run quotas on process restart, and separate clients can bypass a per-client attempt counter. This change requires a private pre-provisioned durable control ledger: two rolling hourly starts plus the reviewed daily limit, one active run/process, and the full run attempt/charge envelope reserved before processing. Every SDK attempt, worker and application retry consumes that reservation; failed calls retain their conservative charge, normal unwinding releases only unstarted attempts, and crashes retain the entire reservation. Paid credential-test/raw POST probes are disabled in pilot mode.

The prepared operator proposal is $250 total, two starts per participant per rolling day, 50 attempts per run and a provisional $1 charge ceiling per attempt ($50 reserved per run). The ledger stores only HMAC-derived identities, random IDs, timestamps, counters and reported token usage. Missing/corrupt/replaced/mismatched stores fail closed; admission never creates or resets a budget. Compose mounts a private web-only control volume and acquires the process lease before listening. A B01–B08 actual-account/host acceptance procedure covers pricing, enforced cutoff, restarts, tabs/retries, storage, active WebSocket limits, operations and metadata deletion.

Validation: 3,021 local tests: 2,986 passed, 35 optional integration skips (148.945 seconds), including 29 new budget/security methods and the 19 native Redis regressions. Configured static checking passes for 79 app files; the fake-model 2,000-page scale simulation passes.

R09 remains open and real-information admission remains NO-GO. The $1 charge ceiling is provisional; actual provider pricing/attempt bounds, independent account/gateway cutoff, deployed storage/ingress behavior and metadata privacy/deletion acceptance are not supplied or tested here. No real records, paid provider calls, account changes or live deployment were used.

<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a href="https://app.greptile.com/api/retrigger?id=74170652"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a>Confidence Score: 4/5</h2>

<!-- greptile-risk -->

The PR should not merge until a digest failure cannot admit another run while earlier provider requests remain in flight.

<h2><a href="https://app.greptile.com/ide/claude-code?prompt=%23%23%23%20Issue%201%0Aapp%2Fpilot_budget.py%3A250%0AIf%20one%20digest%20worker%20raises%20%60PilotBlocked%60%20while%20others%20have%20provider%20requests%20in%20flight%2C%20the%20digest%20pool%20stops%20without%20waiting%20for%20those%20requests.%20The%20run%20then%20reaches%20%60finish%60%2C%20which%20marks%20it%20inactive.%20Another%20participant%20can%20start%20a%20run%20while%20the%20first%20run's%20requests%20are%20still%20active%2C%20breaking%20the%20one-active-run%20limit.%20Keep%20the%20run%20active%20until%20its%20outstanding%20workers%20have%20stopped.%0A%0A%23%23%23%20Issue%202%0Adeploy%2FPILOT_BUDGET_ACCEPTANCE.md%3A119%0AB05%20says%20a%20rolled-back%20store%20must%20cause%20suspension%2C%20but%20this%20procedure%20also%20acknowledges%20that%20an%20in-place%20rollback%20by%20a%20privileged%20administrator%20cannot%20be%20detected%20from%20the%20store.%20This%20makes%20the%20acceptance%20check%20impossible%20to%20satisfy%20as%20written%20and%20could%20leave%20reviewers%20with%20a%20false%20assurance.%20Separate%20detectable%20file%20replacement%20from%20in-place%20rollback%2C%20and%20state%20what%20independent%20control%20or%20reconciliation%20evidence%20covers%20the%20latter.%0A%0A---%0A%0AFor%20each%20issue%20above%2C%20determine%20whether%20it%20is%20valid%20and%20should%20be%20fixed.%20If%20so%2C%20fix%20it%20directly.&repo=richardparslow-commits%2Fvalaystatementevaluator&pr=80&platform=github"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixAllInClaudeDark.svg?v=7"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/FixAllInClaude.svg?v=7"><img alt="Fix All in Claude Code" src="https://greptile-static-assets.s3.amazonaws.com/badges/FixAllInClaude.svg?v=7" align="right"></picture></a>Findings</h2>

1. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top">&nbsp;Run marked inactive too early <a href="https://github.com/richardparslow-commits/VALayStatementEvaluator/pull/80#discussion_r4175138605">▶</a>
2. <img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top">&nbsp;Rollback check promises detection <a href="https://github.com/richardparslow-commits/VALayStatementEvaluator/pull/80#discussion_r4175138615">▶</a>

<details><summary>Fix with agent prompt</summary>

`

### Issue 1
app/pilot_budget.py:250
If one digest worker raises `PilotBlocked` while others have provider requests in flight, the digest pool stops without waiting for those requests. The run then reaches `finish`, which marks it inactive. Another participant can start a run while the first run's requests are still active, breaking the one-active-run limit. Keep the run active until its outstanding workers have stopped.

### Issue 2
deploy/PILOT_BUDGET_ACCEPTANCE.md:119
B05 says a rolled-back store must cause suspension, but this procedure also acknowledges that an in-place rollback by a privileged administrator cannot be detected from the store. This makes the acceptance check impossible to satisfy as written and could leave reviewers with a false assurance. Separate detectable file replacement from in-place rollback, and state what independent control or reconciliation evidence covers the latter.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
`

</details>

<h3>Summary</h3>

The PR adds a private SQLite control ledger for persistent pilot quotas and conservative provider-attempt reservations, wires it into pilot startup and SDK calls, and documents the remaining account-level acceptance gates.

  • A digest failure can release the active-run reservation while other provider calls remain in flight.

  • The storage acceptance checklist overstates what an in-place rollback can be detected to do.
  • <!-- greptile_confidence_score:4 -->

    <sub>Reviews (1) · Last reviewed commit: "fix(pilot): enforce durable run quotas a..."</sub>

    <!-- /greptile_comment -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: greptile-apps[bot] Review duration: 7m
    All Vouch review confidence checks passed
    Residual risk 0.37 = Change Risk (0.52) × (1 − Review Confidence (0.29)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 48% · Reviewer familiarity: 35%
    29%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #80"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 29.3% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 29.3% · Lower = rushed or shallow review
    29.3%
    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: 36.8% · Moderate risk
    36.8%