Skip to content

runner: Add fixed pricing - #3999

Merged
j0sh merged 2 commits into
masterfrom
ja/fixed-payments
Jul 24, 2026
Merged

runner: Add fixed pricing#3999
j0sh merged 2 commits into
masterfrom
ja/fixed-payments

Conversation

@j0sh

@j0sh j0sh commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

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.

Summary by CodeRabbit

  • New Features

    • Added support for fixed-price live runner sessions, including per-session price snapshots.
    • Remote signer payments now support fixed billing (bills once).
  • Bug Fixes

    • Improved reservation and payment conflict handling for fixed-price sessions.
    • Enhanced payment lookup/validation error reporting with clearer HTTP status behavior.
    • Prevented recurring billing from continuing after reservation cancellation.
  • Documentation

    • Updated live-runner, remote discovery, and remote signer docs for fixed units and additional HTTP response codes.
  • Tests

    • Added coverage for fixed-price debit once, mismatched payment rejection, and cancellation stopping further billing.

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 a review from rickstaa July 24, 2026 06:14
@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
@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: ff6480be-5b82-464d-aa19-a684ce4b5dc0

📥 Commits

Reviewing files that changed from the base of the PR and between 10ba11a and 922932a.

📒 Files selected for processing (2)
  • ai/runner/live_runner_test.go
  • server/ai_http.go
💤 Files with no reviewable changes (1)
  • server/ai_http.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • ai/runner/live_runner_test.go

📝 Walkthrough

Walkthrough

Live-runner pricing now supports fixed units, stores pricing per session, and exposes session pricing lookup. Reservation and payment flows bill fixed sessions once, while remote signing, validation, tests, and documentation support the new unit.

Changes

Fixed live-runner billing

Layer / File(s) Summary
Session pricing and conversion
ai/runner/live_runner.go, ai/runner/live_runner_test.go
Fixed pricing is normalized and converted without time or pixel scaling; sessions retain their initial pricing snapshot through SessionPriceInfo.
Session reservation and payment flow
server/ai_http.go, server/ai_http_test.go
Paid reservation logic is centralized, fixed sessions are billed once, recurring billing stops on cancellation, and follow-up fixed-session payments return 409.
Remote fixed payment support
server/remote_signer.go, server/remote_signer_test.go, server/remote_discovery.go
Remote payment generation supports the fixed type as one billable unit, and runner-price validation accepts fixed units.
Pricing and API documentation
doc/live-runner.md, doc/remote-signer.md
Documentation describes fixed pricing, one-time payment behavior, discovery rules, and expanded response codes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant LiveRunnerAPI
  participant LiveRunnerRegistry
  participant Orchestrator
  Client->>LiveRunnerAPI: Reserve fixed-price session
  LiveRunnerAPI->>LiveRunnerRegistry: Fetch session price snapshot
  LiveRunnerRegistry-->>LiveRunnerAPI: Return fixed pricing
  LiveRunnerAPI->>Orchestrator: Process one-unit payment
  Orchestrator-->>LiveRunnerAPI: Return payment result
  LiveRunnerAPI-->>Client: Return session endpoint
Loading

Possibly related PRs

Suggested reviewers: emranemran, seanhanca

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding fixed pricing support for runners.
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/fixed-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.

Comment thread server/ai_http.go Fixed

@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: 1

🤖 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 `@server/ai_http.go`:
- Around line 539-547: The payment flow in PaymentForLiveRunnerSession must
verify runner readiness before accepting follow-up payments. Add the same
ready-runner gate used by RunnerEndpointForSession before
processPaymentAndSegmentHeaders, ensuring non-ready sessions return 404 and do
not reach ProcessPayment; keep the existing SessionPriceInfo fixed-price
validation afterward.
🪄 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: 060d5118-3ead-4a3c-88e4-a1385b064eef

📥 Commits

Reviewing files that changed from the base of the PR and between b4b9053 and 10ba11a.

📒 Files selected for processing (9)
  • ai/runner/live_runner.go
  • ai/runner/live_runner_test.go
  • doc/live-runner.md
  • doc/remote-signer.md
  • server/ai_http.go
  • server/ai_http_test.go
  • server/remote_discovery.go
  • server/remote_signer.go
  • server/remote_signer_test.go

Comment thread server/ai_http.go
Comment on lines +539 to +547
priceInfo, err := manager.SessionPriceInfo(runnerID, sessionID)
if err != nil {
respondWithLiveRunnerError(w, err)
return
}
if strings.EqualFold(strings.TrimSpace(priceInfo.Unit), "fixed") {
respondWithError(w, "fixed-price live runner sessions do not accept follow-up payments", http.StatusConflict)
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect isReadyStatus usage and the two lookup helpers to confirm the gate difference.
rg -nP -C3 'func \(r \*LiveRunnerRegistry\) (SessionPriceInfo|RunnerEndpointForSession)\b' ai/runner/live_runner.go
rg -nP -C2 'isReadyStatus' ai/runner/live_runner.go

Repository: livepeer/go-livepeer

Length of output: 2617


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== server/ai_http.go payment handling context =="
rg -n -C 10 'func .*Payment|ProcessPayment|SessionPriceInfo|RunnerEndpointForSession|follow-up payments' server/ai_http.go

echo "== ai/runner/live_runner.go relevant lock helpers =="
sed -n '930,1095p' ai/runner/live_runner.go | cat -n -v

echo "== Programmatic check: readiness guard presence in helper bodies =="
python3 - <<'PY'
from pathlib import Path
p=Path('ai/runner/live_runner.go')
s=p.read_text()
for name in ['lockLiveRunnerLocked','lockLiveRunner','liveRunnerSessionLocked','SessionPriceInfo','RunnerEndpointForSession','IsLiveRunnerReady']:
    print(f'-- {name} --')
    idx=s.find(f'func {name}')
    if idx==-1:
        print('not found')
        continue
    # crude body extraction until next top-level func
    end=s.find('\nfunc ', idx+1)
    body=s[idx: (end if end!=-1 else len(s))].splitlines()
    print('\n'.join(f'{i+1:4}: {line}' for i,line in enumerate(body) if 'isReady' in line or 'liveRunnerSessionLocked' in line or 'StatusCode' in line))
PY

Repository: livepeer/go-livepeer

Length of output: 19316


Add a runner readiness check before accepting live-runner follow-up payments.

SessionPriceInfo delegates to lockLiveRunner, then liveRunnerSessionLocked; that session lookup only checks the runner status inside liveRunnerSessionLocked after the runner has already been selected. PaymentForLiveRunnerSession should gate on a ready runner before processPaymentAndSegmentHeaders, just like the earlier RunnerEndpointForSession path did, so non-ready sessions return 404 instead of proceeding to ProcessPayment.

🤖 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 539 - 547, The payment flow in
PaymentForLiveRunnerSession must verify runner readiness before accepting
follow-up payments. Add the same ready-runner gate used by
RunnerEndpointForSession before processPaymentAndSegmentHeaders, ensuring
non-ready sessions return 404 and do not reach ProcessPayment; keep the existing
SessionPriceInfo fixed-price validation afterward.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.41860% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.47779%. Comparing base (b4b9053) to head (922932a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
server/ai_http.go 78.40909% 13 Missing and 6 partials ⚠️
ai/runner/live_runner.go 66.66667% 9 Missing and 3 partials ⚠️
server/remote_signer.go 50.00000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #3999         +/-   ##
===================================================
+ Coverage   35.44849%   35.47779%   +0.02930%     
===================================================
  Files            174         174                 
  Lines          45040       45093         +53     
===================================================
+ Hits           15966       15998         +32     
- Misses         27810       27827         +17     
- Partials        1264        1268          +4     
Files with missing lines Coverage Δ
server/remote_discovery.go 85.52036% <100.00000%> (ø)
server/remote_signer.go 65.19722% <50.00000%> (-0.14236%) ⬇️
ai/runner/live_runner.go 76.87266% <66.66667%> (-0.96879%) ⬇️
server/ai_http.go 46.78973% <78.40909%> (+0.56641%) ⬆️

... and 3 files 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 b4b9053...922932a. Read the comment docs.

Files with missing lines Coverage Δ
server/remote_discovery.go 85.52036% <100.00000%> (ø)
server/remote_signer.go 65.19722% <50.00000%> (-0.14236%) ⬇️
ai/runner/live_runner.go 76.87266% <66.66667%> (-0.96879%) ⬇️
server/ai_http.go 46.78973% <78.40909%> (+0.56641%) ⬆️

... and 3 files with indirect coverage changes

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

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

Code and coverage looks good. Two small nits.

}
if sessionPriceInfo.Price.String() != "10" || sessionPriceInfo.Unit != "fixed" {
t.Fatalf("unexpected static session price snapshot: %+v", sessionPriceInfo)
}

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.

nit: message says what it got but not what it wanted or why.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 922932a

Comment thread server/ai_http.go Fixed
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