Skip to content

Add single-shot payments - #4000

Merged
j0sh merged 3 commits into
masterfrom
ja/singleshot-payments
Jul 24, 2026
Merged

Add single-shot payments#4000
j0sh merged 3 commits into
masterfrom
ja/singleshot-payments

Conversation

@j0sh

@j0sh j0sh commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Single-shot live runner requests now support paid reservations when payment is required.
  • Bug Fixes
    • Improved cancellation handling now stops continued processing/billing when payment fails due to insufficient balance.
  • Documentation
    • Updated Live runners documentation to clarify payment challenge behavior and single-shot proxy endpoint semantics.
  • Tests
    • Added coverage to verify paid-session monitoring cancels the request when available balance is insufficient.

j0sh added 2 commits July 23, 2026 22:37
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.
@j0sh
j0sh requested review from ad-astra-video and rickstaa July 24, 2026 06:14
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e4bf18c-a2d0-4d0a-b511-e4de3149b0ad

📥 Commits

Reviewing files that changed from the base of the PR and between 95864fe and 53a6a70.

📒 Files selected for processing (1)
  • server/ai_http.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/ai_http.go

📝 Walkthrough

Walkthrough

Changes

Paid Live Runner proxy flow

Layer / File(s) Summary
Paid reservation cancellation
server/ai_http.go, server/ai_http_test.go
Paid reservation monitoring can cancel the request when payment fails or balance is insufficient, with tests covering the behavior.
Single-shot paid proxy integration
server/ai_http.go
Single-shot proxy requests use paid reservations when payment information exists and proxy a request cloned with the cancelable context.
Payment and API documentation
doc/live-runner.md
Payment challenge and single-shot proxy endpoint descriptions are updated.

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
Loading

Possibly related PRs

Suggested reviewers: emranemran, ad-astra-video, seanhanca

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main change: enabling payments for the single-shot proxy path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ja/singleshot-payments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added go Pull requests that update Go code AI Issues and PR related to the AI-video branch. docs labels Jul 24, 2026
@j0sh
j0sh requested review from emranemran and seanhanca July 24, 2026 15:30

@rickstaa rickstaa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment looks good to me. Nit please add pull request description for historic tracking.

Base automatically changed from ja/fixed-payments to master July 24, 2026 21:07
@j0sh
j0sh force-pushed the ja/singleshot-payments branch from 95864fe to 53a6a70 Compare July 24, 2026 21:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lift

Account non-fixed single-shot usage before releasing the session.

For non-fixed prices, AccountPayment only runs from the interval ticker. A proxy response that finishes before LivePaymentInterval reaches the deferred ReleaseSession and 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2183b67 and 95864fe.

📒 Files selected for processing (3)
  • doc/live-runner.md
  • server/ai_http.go
  • server/ai_http_test.go

Comment thread doc/live-runner.md
| `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` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Comment thread server/ai_http.go
@j0sh
j0sh enabled auto-merge (squash) July 24, 2026 21:40
@j0sh
j0sh merged commit a6ad0f3 into master Jul 24, 2026
18 checks passed
@j0sh
j0sh deleted the ja/singleshot-payments branch July 24, 2026 21:40
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.48580%. Comparing base (2183b67) to head (53a6a70).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
server/ai_http.go 78.26087% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 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     
Files with missing lines Coverage Δ
server/ai_http.go 46.91456% <78.26087%> (+0.12483%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2183b67...53a6a70. Read the comment docs.

Files with missing lines Coverage Δ
server/ai_http.go 46.91456% <78.26087%> (+0.12483%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Issues and PR related to the AI-video branch. docs go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants