feat(session): pluggable persistent channel store#563
Open
deodad wants to merge 5 commits into
Open
Conversation
commit: |
55be453 to
31e7906
Compare
Replace the SessionManager's per-manager sessionStore with a pluggable multi-channel ChannelStore on the session method, keyed by payment scope (payee:token:escrow:chainId). The plugin resumes a matching channel after a 402, vouchers against it, and writes it back; the manager only hints a live in-memory channel on cold requests and resumes everything else via the store's entry index after the first 402. - session/sessionManager accept channelStore (get/set/delete) - add createChannelStore (in-memory) and createJsonChannelStore (durable, bigint-safe over a plain string kv), plus entryKey/serializeEntry/ deserializeEntry and ChannelStore/JsonChannelKv/StoredChannel types - remove sessionStore option and SessionStore/StoredSessionChannel types; persistent cold-start hints are gone, durable resume runs through the store after the first 402 Amp-Thread-ID: https://ampcode.com/threads/T-019ed203-0f2e-751f-9a05-aa6610cab7d5 Co-authored-by: Amp <amp@ampcode.com>
Move the client channel store out of CredentialState.ts into a dedicated ChannelStore.ts, mirroring session/server/ChannelStore.ts. CredentialState keeps credential planning; the store owns persistence and serialization. - new src/tempo/session/client/ChannelStore.ts holds ChannelStore, ChannelSink, channelKey/entryKey, createChannelStore, StoredChannel, serializeEntry/deserializeEntry, JsonChannelKv, createJsonChannelStore - drop the store re-export ladder through Session.ts; client barrels import straight from ChannelStore.js - SessionManager and tests import store symbols from the new module Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019ed67a-26f1-725b-8dd8-ad419a893f75
c424ad4 to
667af66
Compare
- unify the two client barrels on one minimal store surface (ChannelStore, createChannelStore, createJsonChannelStore, JsonChannelKv, entryKey); drop serializeEntry/deserializeEntry/StoredChannel from public export since createJsonChannelStore already (de)serializes - inline ChannelNotify into ChannelSink and isReusable into getReusable Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019ed67a-26f1-725b-8dd8-ad419a893f75
- channelKey takes a scope object instead of four positional Address/number args, removing a silent key-transposition footgun (#9) - drop the per-write backing read in the manager's store wrapper: the plugin always reads a key before writing it, so fresh-open detection keys off an in-memory seenExisting set instead of a second store round-trip (#4) - reject concurrent doFetch on one manager with a clear error instead of letting overlapping requests corrupt the shared runtime (A2) Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019ed67a-26f1-725b-8dd8-ad419a893f75
Amp-Thread-ID: https://ampcode.com/threads/T-019ed67a-26f1-725b-8dd8-ad419a893f75 Co-authored-by: Amp <amp@ampcode.com>
7707b9f to
1765d4c
Compare
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
Make session payment channels persist through a pluggable
channelStoreon the session method, keyed by payment scope (payee:token:escrow:chainId), so a consumer (e.g. a wallet) can read and persist channel state.Motivation
An app integrating mppx needs channel state to live alongside its own state about the connected address and access keys. A wallet implementing
wallet_authorizeChallengecan then read channel state to pick the right key to sign vouchers for a given payment scope. Persisting it durably is the secondary win: channels survive restarts instead of being re-opened.Changes
session({ channelStore })andsessionManager({ channelStore })accept aChannelStore(get/set/delete). The plugin resumes a matching channel after a 402, vouchers against it, and writes it back; closed channels are deleted.createChannelStore()(in-memory default) andcreateJsonChannelStore(kv)(durable, bigint-safe over a plain string KV). Public surface is justChannelStore,createChannelStore,createJsonChannelStore,JsonChannelKv,entryKey— identical frommppx/clientandTempo.Session.Client.session/client/ChannelStore.ts(mirroring the server side);CredentialState.tskeeps only credential planning.sessionManagerhintsPayment-Sessiononly for a live in-memory channel; a cold start resumes through the store after the first 402. A stale resumed channel is evicted and the request retried once.channelKeytakes a scope object (no positional-arg footgun); the store wrapper drops a redundant per-write read; concurrent requests on one manager now fail with a clear error instead of corrupting shared state.Breaking: removed the
sessionStoreoption and theSessionStore/StoredSessionChanneltypes. Persistent cold-start hints are gone; durable resume runs through the store after the first 402.Testing
pnpm check:types— cleanpnpm check— clean (lint/format)pnpm test— session client suites pass, including a new concurrent-request guard test