Repository navigation
feat(server): add InMemoryImplicitAccountStore reference adapter - #1357
Conversation
| import { | ||
| createAdcpServer, | ||
| serve, | ||
| verifyApiKey, | ||
| createIdempotencyStore, | ||
| InMemoryImplicitAccountStore, | ||
| AdcpError, | ||
| type Account, | ||
| } from '@adcp/sdk/server'; |
|
Heads-up from triage of #1364: before this PR merges, consider whether to include the The gap: If scope expansion would materially delay this PR, ship as-is and let #1364 become the follow-on. If the plumbing is small relative to the adapter diff, folding it here keeps the Generated by Claude Code |
|
Two concrete gaps from working a parallel branch on the same issue (#1340) — flagging here rather than opening a competing PR. Happy to fold into this one. 1.
|
|
Addressing both comments — two follow-up commits pushed. Re:
Re: Re: framework-wired storyboard test — leaving deferred. The snippet requires built Generated by Claude Code Generated by Claude Code |
|
Acknowledged — Generated by Claude Code Generated by Claude Code |
|
Acknowledged — marking as ready for human review. Generated by Claude Code Generated by Claude Code |
|
PR promoted from draft to ready for review. The previous triage session declared this intent but didn't complete the API call — doing so now. All addressed feedback is reflected in the current head ( Generated by Claude Code Generated by Claude Code |
Adds a reference implementation of AccountStore for resolution: 'implicit' platforms (sync_accounts-first pattern). Resolves the adopter gap where each implementer independently re-derived key extraction, TTL, and error behavior. https://claude.ai/code/session_01TshCGnKCHQaYhKQQwFgVyw
- upsert(): fail all rows when keyFn returns undefined rather than silently discarding the sync linkage (was: success rows + mystery ACCOUNT_NOT_FOUND on next call) - resolve(): document first-account-wins behavior for multi-ref syncs - docs: add missing refAccountId import to explicit-mode snippet https://claude.ai/code/session_01TshCGnKCHQaYhKQQwFgVyw
- upsert(): guard _store.set with accounts.length > 0 — all-fail batch no longer silently destroys a previously-valid sync linkage - upsert(): suppress buildAccount err.message from wire response; emit fixed string + console.error to avoid leaking upstream credentials/SQL - account.ts refAccountId() JSDoc: fix deprecated clientId reference (same pattern fixed in resolve() JSDoc in prior commit) https://claude.ai/code/session_01TshCGnKCHQaYhKQQwFgVyw
For AccountStore.resolution === 'implicit', the framework's JSDoc promised "Framework refuses inline account_id references" but the resolveAccount closure in from-platform.ts passed them through unconditionally. A naïve adopter resolver doing findById(ref.account_id) would return the requested account regardless of who was calling, enabling cross-tenant reads. Two changes: - from-platform.ts: reject the call with INVALID_PARAMS before reaching platform.accounts.resolve() when resolution === 'implicit' and a non-null ref is present. - create-adcp-server.ts: propagate thrown adcpError envelopes from the resolveAccount catch block (mirrors the existing isThrownAdcpError pattern for handler throws) so enforcement errors surface with the correct code rather than being swallowed into SERVICE_UNAVAILABLE. https://claude.ai/code/session_015sLihxs9oebXhQaYnzmk2G
… (refs #1340) Replaying sync_accounts with the same (brand, operator, sandbox) tuple was calling buildAccount again, which for adopters with non-deterministic resolvers (upstream API calls, DB inserts) would mint a different account_id on each replay. The buyer would see action:'created' on every resync and accumulate duplicate ids in their records. Fix: store AccountReference[] alongside Account[] in StoredEntry, build a natural-key index (brand.domain|operator|sandbox) from existing entries, and return action:'unchanged' with the original account_id when a matching tuple is found. Only new tuples (no prior entry) invoke buildAccount. The "all-fail preserves prior linkage" invariant is maintained — the stored entry is only updated when at least one ref resolved successfully. https://claude.ai/code/session_015sLihxs9oebXhQaYnzmk2G
…1340) The natural-key dedup landed in 99f1d24 made re-sync idempotent on `(brand.domain, operator, sandbox)`, but the test surface for the adapter was empty. Adds the missing coverage and one small fix surfaced by the sandbox test. Tests in `test/in-memory-implicit-account-store.test.js`: - `defaultImplicitKeyFn` namespacing (oauth/api_key/http_sig + missing-credential) - resolution declaration, upsert/resolve round-trip - re-sync idempotency with a non-deterministic adopter `buildAccount` (asserts buildAccount is invoked exactly once across three replays of the same natural key — the contract behind the dedup landed in 99f1d24) - sandbox vs production registered as distinct accounts under one principal - tenant isolation, no-auth resolve returns null (no leak) - upsert without auth + unrecognized credential kind both surface SYNC_FAILED - TTL eviction (expires + clears on resolve) - custom keyFn override (LinkedIn-style org-claim keying) - `clear()` and `authKey()` test-helper coverage - framework-wired storyboard via `dispatchTestRequest`: - `sync_accounts → get_products` resolves the principal's account - cross-tenant: buyer-B cannot see buyer-A's account through the wire Storyboard tests use real `createAdcpServerFromPlatform` so they catch ResolveContext-forwarding bugs (#1310-style) that direct unit tests miss. No upstream YAML changes needed — `dispatchTestRequest` is in the SDK today. Fix: extend `defaultBuildAccount` to encode `sandbox` in its synthesized id (`<brand>:<operator>:sandbox`) and propagate `sandbox: true` onto the returned Account. Without this, a sandbox + production pair under the same `(brand, operator)` collide on derived id even though the natural-key dedup correctly identifies them as different entries. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Acknowledged — PR is now ready for review. The Generated by Claude Code Generated by Claude Code |
2673743 to
adbf881
Compare
|
Understood — noted and standing by. No further action from triage; PR is in human reviewer hands. _Generated by Claude Code Generated by Claude Code |
|
Both gaps addressed — pushed to the branch now. Gap 1 — natural-key dedup: Also fixed Gap 2 — framework-wired tests: Added All 18 new tests pass; no regressions in the broader suite. Reply by Claude Code. Session: https://claude.ai/code/session_012gatTQakEja5jgpqEdz9qr Generated by Claude Code |
Resolves a conflict at create-adcp-server.ts:resolveAccount catch where main (PR #1357) added an `isThrownAdcpError` check; my PR added an `AdcpError instanceof` check. Both are valid for different shapes — combined into one catch block that handles both, with explanatory comment. Also tightens main's overlapping implicit-account-id enforcement at from-platform.ts:resolveAccount (added by PR #1357) to match the expert-review-validated approach: - account_id arm only (was: any non-null ref including brand+operator) - INVALID_REQUEST (was: INVALID_PARAMS — non-canonical AdCP code) - field='account.account_id' (was: 'account') Per the protocol-expert review on this PR: brand+operator is part of the spec's implicit-mode contract — it's the natural-key shape buyers pass during the initial sync_accounts onboarding flow, before any account_id has been assigned. Refusing it would break the documented onboarding path. INVALID_REQUEST is the correct code per schemas/cache/latest/enums/error-code.json (wire-shape violation, correctable) vs INVALID_PARAMS (JSON-RPC-level, not in AdCP catalog). All 242 tests pass across implicit-account-store, implicit-account-id, from-platform, create-adcp-server, and resolve-presets test files.
Refs #1340
Adds a reference
AccountStoreimplementation forresolution: 'implicit'platforms (the sync_accounts-first pattern). Previously each adopter independently re-derived key extraction, TTL semantics, and error handling — and commonly got them wrong (keying onauthInfo.subinstead ofcredential.client_id, returningAUTH_REQUIREDinstead ofACCOUNT_NOT_FOUNDwhen sync hasn't happened).What ships
InMemoryImplicitAccountStore<TCtxMeta>insrc/lib/adapters/implicit-account-store.ts— implementsAccountStorewithresolve()+upsert(). ConfigurablekeyFn(defaults tocredential.client_id/credential.key_id/credential.agent_url), configurablettlMs(default 24h), and abuildAccountfactory. Test helpers:clear(),authKey(),size. Exported from both@adcp/sdk/serverand@adcp/sdk.docs/guides/account-resolution.md— one-pager covering all three resolution modes with a deep dive on'implicit': key derivation rationale, theACCOUNT_NOT_FOUNDvsAUTH_REQUIREDerror contract, TTL/staleness guidance, and a Postgres cross-link.examples/decisioning-platform-implicit-accounts.ts— runnable wiring example.AccountStore.resolve()andrefAccountId()example snippets updated from deprecatedauthInfo?.clientIdtocredential.client_id/credential.key_id.Deferred from issue scope
docs/guides/POSTGRES.mdalready covers the DDL pattern and the doc cross-links it.sync_accounts → create_media_buywithoutaccount_refrequires new phases in themedia_buy_*_sellerstoryboard YAML, which is a spec-side change (adcontextprotocol/adcp). Deferred to a follow-up PR once upstream storyboard support lands.What was tested
npm run format:check— cleannpx tsc --project tsconfig.lib.json --noEmit— only pre-existing TS2688/TS5107 env errors (confirmed onmainbefore branching; not introduced by this diff)tsxnot available in this environment; unit tests require builtdist/— pre-existing environment constraintPre-PR review
upsert()all-fail batch now preserves prior sync entry; (2)buildAccounterr.message suppressed from wire response; (3) secondrefAccountId()JSDoc deprecated-field instance fixedupsert()key-undefined no longer silently succeeds; (2)resolve()first-account-wins behavior documented; (3)refAccountIdimport added to explicit-mode doc snippetNits (not fixed, noted for reviewers):
defaultBuildAccountusesas unknown ascast to paper overTCtxMetavsTCtxMeta & Record<string, unknown>mismatch — safe for the documented test use case; adopters who pass a typed generic without abuildAccountoverride get a runtime{}forctx_metadata. JSDoc warns about this but TypeScript is silent.buildAccountbody manually reconstructs ref fields (same pattern asdefaultBuildAccount); a future pass could simplify the stub to amyPlatform.findOrCreate()call.Session: https://claude.ai/code/session_01TshCGnKCHQaYhKQQwFgVyw
Generated by Claude Code