feat: add tempo session hint reconciliation#260
Draft
brendanjryan wants to merge 1 commit intomainfrom
Draft
Conversation
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This keeps the session flow backward-compatible while making client channel maintenance simpler and more server-authoritative.
request.methodDetails:requiredCumulative,acceptedCumulative,spent, anddepositrequest.channelIdpoints at a reusable stored channelrequiredCumulativewhen present, and reconcile runtime state fromPayment-ReceiptchannelIdis availablefetchflows by letting client methods observe successful responsesCurrent Request-Response Flow
sequenceDiagram participant Client participant Server participant Chain as On-chain channel Client->>Server: GET /resource Server-->>Client: 402 + optional channelId reuse hint alt channelId present Client->>Chain: recover by channelId Chain-->>Client: settled amount Client->>Client: local cumulative = settled else no channelId Client->>Client: create new local channel state end Client->>Client: advance local cumulative by request amount Client->>Server: retry with open/voucher credential Server-->>Client: 200 + Payment-Receipt Client->>Client: mostly keep local countersProposed Request-Response Flow
sequenceDiagram participant Client participant Server participant Chain as On-chain channel Client->>Server: GET /resource Server-->>Client: 402 + channelId + accepted/spent/deposit/required hints when known alt server hints present Client->>Client: hydrate runtime snapshot from server state else only channelId present Client->>Chain: recover by channelId Chain-->>Client: settled amount Client->>Client: fallback snapshot from chain else no reusable channel Client->>Client: open new channel end alt requiredCumulative present Client->>Client: sign exact server target else no target hint Client->>Client: fall back to local cumulative + amount end Client->>Server: retry with open/voucher credential Server-->>Client: 200 + Payment-Receipt(channelId, acceptedCumulative, spent) Client->>Client: overwrite runtime snapshot from receiptClient Control Flow
flowchart TD A[Need credential for session request] --> B{Challenge includes session hints?} B -->|Yes| C[Hydrate snapshot from channelId acceptedCumulative spent deposit] B -->|No| D{Challenge includes channelId?} D -->|Yes| E[Fallback recovery from on-chain settled amount] D -->|No| F[Open new channel using deposit or suggestedDeposit] C --> G{requiredCumulative present?} E --> G G -->|Yes| H[Sign exact server target] G -->|No| I[Advance local cumulative by request amount] I --> H F --> J[Receive Payment-Receipt] H --> J J --> K[Reconcile local runtime state from receipt] K --> L[Next request starts from reconciled snapshot]Server Control Flow
flowchart TD A[Session route receives request] --> B[Resolve chainId escrow and normalized request] B --> C{request.channelId maps to reusable stored channel?} C -->|Yes| D[Author challenge hints acceptedCumulative spent deposit requiredCumulative] C -->|No| E[Emit standard challenge fields only] D --> F{Credential supplied?} E --> F F -->|No| G[Return 402 Payment challenge] F -->|Yes| H[Verify open topUp voucher or close action] H --> I[Keep legacy acceptance: any valid advancing voucher still works] I --> J[Emit Payment-Receipt with channelId acceptedCumulative spent] J --> K[Return management response or user content response]Why This Rollout Is Safe
requiredCumulativeTesting
pnpm test src/tempo/Methods.test.ts src/tempo/client/Session.test.ts src/client/internal/Fetch.test.ts src/tempo/server/Session.test.tspnpm check:typespnpm check