Skip to content

feat(server): Live runner single shot payments#3975

Open
ad-astra-video wants to merge 4 commits into
livepeer:ja/live-runnerfrom
ad-astra-video:live-runner-single-shot-payments
Open

feat(server): Live runner single shot payments#3975
ad-astra-video wants to merge 4 commits into
livepeer:ja/live-runnerfrom
ad-astra-video:live-runner-single-shot-payments

Conversation

@ad-astra-video

@ad-astra-video ad-astra-video commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

What does this pull request do? Explain your changes. (required)

Enables on-chain payments for single-shot live runner calls. Single-shot mode was functional but unpaid: ProxyLiveRunnerSingleShot reserved a session, proxied, and released with no payment gate. This makes single-shot (request/response and short-lived / batch) calls billable, mirroring the existing persistent (ReserveLiveRunnerSession) payment flow. Parity with the persistent path is intentional. The deliberate differences are the single-shot mode guard, release-on-return, the metering-loop lifetime, and the proxy (vs JSON) response.

Specific updates (required)

  • Return a 402 payment challenge on the single-shot path (shared runnerChallenge), carrying ticket params, manifest_id, and payment_interval_ms (the orchestrator's debit interval).
  • Process the inline payment (Livepeer-Payment / Livepeer-Segment headers) with ProcessPayment, reserve the session (manifest_id = session id), proxy to the runner, and release on return.
  • Add a per-session metering loop (startLiveRunnerSessionPaymentLoop) that debits the prepaid balance every LivePaymentInterval while the request is open. Lifetime is set by the caller's context (single-shot: request ctx; persistent: context.WithoutCancel).
  • Keep held-open (SSE / WebSocket) sessions funded via the session-scoped POST /apps/{runner}/session/{id}/payment endpoint.

How did you test each of these updates (required)

Ensured go-livepeer builds, tests pass and ran the new logic against this branch in the app-examples repo confirming payments now work for single-shot runners.

Does this pull request close any open issues?

Fixes #3955

Checklist:


Follow-ups (out of scope, tracked separately)

EDIT: Description updated to explain the PRs behavoir by @rickstaa at 14-07-2026.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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. labels Jul 8, 2026
@ad-astra-video
ad-astra-video marked this pull request as ready for review July 8, 2026 11:40

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

@ad-astra-video, the payment logic and its parity with ReserveLiveRunnerSession make sense to me. I left a couple of comments and opened a pull request to address them: ad-astra-video#35.

Once those changes are applied, please update the pull request description and provide a test script for validating the implementation with the SDK. After that, it should be ready for Josh’s final review.

Comment thread server/ai_http.go Outdated
Comment thread server/ai_http.go Outdated
Comment thread server/ai_http.go Outdated
Comment thread server/ai_http.go
Comment thread server/ai_http.go Outdated
Comment thread server/ai_http.go Outdated
Comment thread server/ai_http.go Outdated
Comment thread server/ai_http.go
Comment thread server/ai_http.go Outdated
* server: simplify single-shot session release lifecycle

Pre-existing working-tree cleanup of ProxyLiveRunnerSingleShot: drop the
reservedID/reservedIDInput split, release the reserved session on return,
and remove the redundant session/manifest recheck.

* server: address single-shot payment review feedback

- Drop the ModifyResponse block (Session-Id/Control/Payment response
  headers). WebSocket clients cannot read upgrade response headers, and
  SSE/HTTP clients derive the session-scoped payment URL from the 402
  challenge (manifest_id + orchestrator), so the headers were redundant.
  Removes the now-unused Session-Payment constant, sessionPaymentURL,
  and the response-header test assertions.
- Surface payment_interval_ms in the 402 challenge so held-open clients
  (SSE/websocket) size their payment cadence below the server tick
  instead of guessing.
- Rename startLiveRunnerSessionPaymentMonitor to ...PaymentLoop to match
  the startAutoConvertLoop convention (a start* method that owns its own
  goroutine); monitorCtx to loopCtx to match.
- Type the payment loop manifestID as core.ManifestID instead of a bare
  string, converting at the single use site, so it cannot be transposed
  with the adjacent runnerID/sessionID params.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* server: bound single-shot payment loop to the request context

The metering loop is now bound to the ctx passed in rather than always
detaching via context.WithoutCancel. Single-shot passes the request ctx
(r.Context()), so the loop stops when the request returns instead of
lingering up to one LivePaymentInterval; the persistent path passes
context.WithoutCancel(ctx) so its loop outlives the reservation request
and stops when the session is released. Matches the startAutoConvertLoop
convention: the caller owns the lifetime via the context.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rickstaa
rickstaa self-requested a review July 14, 2026 04:54
@rickstaa rickstaa linked an issue Jul 14, 2026 that may be closed by this pull request

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

@ad-astra-video thanks for handeling my review comments. Approved from my side. Requested a final review from Josh.

@rickstaa
rickstaa requested a review from j0sh July 14, 2026 07:17
@rickstaa

Copy link
Copy Markdown
Member

@ad-astra-video could you fix the merge conflict. Thanks!

@ad-astra-video

ad-astra-video commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@rickstaa fixed merge conflict on proxyLiveRunner function signature change.

@ad-astra-video ad-astra-video changed the title Live runner single shot payments feat(server): Live runner single shot payments Jul 14, 2026
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. go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: bill payments for single-shot live runner calls

2 participants