Add single-shot payments - #4000
Conversation
Add `fixed` pricing for live runners: a single payment charged when a request or session is created, rather than payment metered over time or processed pixels. Support fixed prices in dynamic and static registrations, discovery, remote signers, and orchestrator accounting, documentation and tests.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChangesPaid Live Runner proxy flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ProxyLiveRunnerSingleShot
participant reservePaidLiveRunnerSession
participant PaymentMonitor
Client->>ProxyLiveRunnerSingleShot: send single-shot proxy request
ProxyLiveRunnerSingleShot->>reservePaidLiveRunnerSession: reserve paid session with cancel callback
reservePaidLiveRunnerSession->>PaymentMonitor: monitor payment and accounting
PaymentMonitor-->>reservePaidLiveRunnerSession: payment failure or insufficient balance
reservePaidLiveRunnerSession->>Client: cancel request context
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
rickstaa
left a comment
There was a problem hiding this comment.
No comment looks good to me. Nit please add pull request description for historic tracking.
95864fe to
53a6a70
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/ai_http.go (1)
769-804: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftAccount non-fixed single-shot usage before releasing the session.
For non-fixed prices,
AccountPaymentonly runs from the interval ticker. A proxy response that finishes beforeLivePaymentIntervalreaches the deferredReleaseSessionand then cancels the monitor, so the request completes without any debit. Account usage synchronously for this route, or disallow non-fixed pricing until request-level units can be charged.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/ai_http.go` around lines 769 - 804, Ensure the single-shot proxy flow accounts for non-fixed pricing before the deferred ReleaseSession runs. Update the path around proxyLiveRunner and reservePaidLiveRunnerSession to synchronously invoke AccountPayment using the final request usage, or reject non-fixed prices when request-level usage cannot be charged; preserve fixed-price behavior and existing session cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@doc/live-runner.md`:
- Line 541: Update the live-runner endpoint table for the single-shot route to
document the initial 402 payment challenge, including the required challenge and
retry response headers, and add 402 to the listed principal responses. Anchor
the changes to the ANY /apps/{runner_id}/app/{app_path...} entry without
altering the existing non-payment statuses.
In `@server/ai_http.go`:
- Around line 248-250: Update the reservePaidLiveRunnerSession call in the
caller handling paid live runner sessions to pass nil for the new cancelRequest
argument, preserving the existing behavior for persistent reservations and
restoring compilation.
---
Outside diff comments:
In `@server/ai_http.go`:
- Around line 769-804: Ensure the single-shot proxy flow accounts for non-fixed
pricing before the deferred ReleaseSession runs. Update the path around
proxyLiveRunner and reservePaidLiveRunnerSession to synchronously invoke
AccountPayment using the final request usage, or reject non-fixed prices when
request-level usage cannot be charged; preserve fixed-price behavior and
existing session cleanup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f60d440d-5920-4cc8-a6ad-74fee70ebf4c
📒 Files selected for processing (3)
doc/live-runner.mdserver/ai_http.goserver/ai_http_test.go
| | `POST /apps/{runner_id}/session/{session_id}/payment` | Paying client; `Livepeer-Payment` and `Livepeer-Segment` | Adds payment for an active session. The payment manifest must match `session_id`. Fixed-payment sessions do not need to call this. | `200`, `400`, `403`, `404`, `409` | | ||
| | `ANY /apps/{runner_id}/session/{session_id}/app/{app_path...}` | Client; access is by the reserved public URL | Proxies any HTTP method, SSE response, or WebSocket upgrade to a persistent runner. | Upstream status, `404`, `502` | | ||
| | `ANY /apps/{runner_id}/app/{app_path...}` | Client; no application-level authentication | Reserves a single-shot session, proxies one request, then releases it. The current path does not enforce runner payment. | Upstream status, `400`, `404`, `503`, `502` | | ||
| | `ANY /apps/{runner_id}/app/{app_path...}` | Client; no application-level authentication | Reserves a single-shot session, proxies one request, then releases it. | Upstream status, `400`, `404`, `503`, `502` | |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document the paid single-shot challenge.
On-chain single-shot requests now enter reservePaidLiveRunnerSession, which returns 402 without payment material. Document the initial challenge/retry headers here and add 402 to the principal responses; otherwise clients following this table will treat payment enforcement as an unexpected failure.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@doc/live-runner.md` at line 541, Update the live-runner endpoint table for
the single-shot route to document the initial 402 payment challenge, including
the required challenge and retry response headers, and add 402 to the listed
principal responses. Anchor the changes to the ANY
/apps/{runner_id}/app/{app_path...} entry without altering the existing
non-payment statuses.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4000 +/- ##
===================================================
+ Coverage 35.47557% 35.48580% +0.01023%
===================================================
Files 174 174
Lines 45093 45111 +18
===================================================
+ Hits 15997 16008 +11
- Misses 27825 27831 +6
- Partials 1271 1272 +1
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Summary by CodeRabbit