Skip to content

feat(server): Account.mode + sandbox-authority helpers (#1435 phase 1) - #1436

Merged
bokelley merged 4 commits into
mainfrom
bokelley/issue-1435-account-mode
May 3, 2026
Merged

bokelley merged 4 commits into
mainfrom
bokelley/issue-1435-account-mode

Conversation

@bokelley

@bokelley bokelley commented May 3, 2026

Copy link
Copy Markdown
Contributor

Phase 1 of #1435 — the three-account-mode rollout designed in docs/proposals/lifecycle-state-and-sandbox-authority.md. This PR ships the type + gate primitives so adopters can opt in to authority-based sandbox enforcement today; auto-wiring into the comply controller dispatch lands in phase 2 alongside mock-mode routing.

Also commits the design docs (docs/proposals/lifecycle-state-and-sandbox-authority.md and docs/architecture/adcp-stack.md) so phase 2/3 PRs can reference them as tracked artifacts.

Summary

New surface from @adcp/sdk/server (also re-exported from top-level @adcp/sdk):

  • AccountMode type — 'live' | 'sandbox' | 'mock'. Resolved-account convention; default 'live' when unspecified (fail-closed).
  • getAccountMode(account) — reads mode off any account-shaped value, with back-compat for legacy sandbox: boolean.
  • isSandboxOrMockAccount(account) — predicate: is the account non-production?
  • assertSandboxAccount(account, opts?) — throws AdcpError('PERMISSION_DENIED') (with details: { scope: 'sandbox-gate', tool? }) for live-mode or missing accounts. Use to gate test-only surfaces.

Why phase 1 is helper-only

The proper enforcement point for the comply controller is after account resolution — trust the SDK's resolved account, not the caller-supplied envelope. But the controller registers separately from createAdcpServer's dispatcher (via registerTestController / createComplyController(...).register(server)), so the framework's account-resolution flow doesn't currently see controller calls.

Auto-wiring requires plumbing account resolution into the controller registration, which is a meaningful surgery best paired with phase 2 (mock-mode routing) where we're already touching the dispatch layer. Phase 1 ships the helpers as a public API so adopters can wire assertSandboxAccount(ctx.account, { tool: 'comply_test_controller' }) inside their existing sandboxGate(input) callback if they have account resolution available.

Pure additive

  • Existing account.sandbox === true adopters keep working unchanged — getAccountMode infers 'sandbox' from the legacy flag.
  • No SDK-internal callers invoke the new helpers yet (auto-wiring is phase 2).
  • No behavior changes for shipped code.

Test plan

  • npx tsc --noEmit clean
  • npm run format:check clean
  • npm run test:lib — 6,025 pass, 0 fail
  • test/lib/server-account-mode.test.js — 14 cases covering: explicit mode wins, legacy sandbox: true back-compat, fail-closed defaults, assertSandboxAccount for all combinations + custom message + tool-name in details

🤖 Generated with Claude Code

bokelley and others added 2 commits May 3, 2026 06:21
Two design artifacts that anchor the next chapter of the v6.x state-
management arc:

- `docs/proposals/lifecycle-state-and-sandbox-authority.md` — three
  account modes (live/sandbox/mock), SDK-as-router for compliance,
  authority-gated comply controller. The SDK-side design.
- `docs/architecture/adcp-stack.md` — layered AdCP stack (L0 wire →
  L4 business logic), what each layer contains, what an SDK at each
  layer should provide, two kinds of compliance (spec vs live).
  Written for cross-SDK / cross-language audience; planned to upstream
  to `adcontextprotocol/adcp`.

These land first so #1435 (Phase 1 — Account.mode + dispatch gate)
and the eventual Phase 2/3 PRs can reference them.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Phase 1 of the three-account-mode rollout (see
docs/proposals/lifecycle-state-and-sandbox-authority.md). Establishes
the type and the gate primitive; auto-wiring into the comply
controller dispatch lands alongside mock-mode routing in phase 2.

New surface from @adcp/sdk/server:
- AccountMode: 'live' | 'sandbox' | 'mock' — resolved-account convention
- getAccountMode(account) — reads mode with back-compat for sandbox: true
- isSandboxOrMockAccount(account) — predicate for non-production accounts
- assertSandboxAccount(account, opts?) — throws PERMISSION_DENIED for
  live-mode or missing accounts, with details.scope: 'sandbox-gate'

Pure additive. Legacy sandbox: true adopters keep working — inferred as
sandbox mode by getAccountMode. No shipped behavior changes.

Closes #1435 (phase 1 only)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley and others added 2 commits May 3, 2026 08:51
Read `mode` and `sandbox` via Object.hasOwn rather than bare property
access. Bare access traverses the prototype chain, so an attacker who
reaches a __proto__-via-merge sink upstream (reachable in MCP envelope
handling) could stamp Object.prototype.mode = 'sandbox' and silently
downgrade every account's gate to a no-op. Own-property check makes the
gate immune regardless of upstream hardening.

Add resolver-discipline guidance to assertSandboxAccount JSDoc:
adopters' AccountStore.resolve must not spread untrusted input into the
resolved account, and opts.message must be a static string literal
(echoed on the wire — interpolating user data creates a reflection sink).

Regression test pollutes Object.prototype.{mode,sandbox} and asserts
getAccountMode({}) and getAccountMode({ id: 'acc' }) both return 'live'.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 0dd3ca7 into main May 3, 2026
10 checks passed
@bokelley
bokelley deleted the bokelley/issue-1435-account-mode branch May 3, 2026 13:10
bokelley added a commit that referenced this pull request May 3, 2026
* Revert "docs: layered architecture, decision page, version-adaptation guide (#1437)"

This reverts commit aa85657.

* docs: remove now-redundant adcp-stack.md, point readers at protocol docs

Beyond the strict revert in the previous commit:

- Removes docs/architecture/adcp-stack.md (introduced in #1436). The same
  layered-architecture content now lives canonically at
  /docs/building/sdk-stack on the protocol docs site, language-agnostic.
- Adds a top-of-page pointer in docs/index.md so SDK readers find
  /docs/building/sdk-stack, /where-to-start, /migrate-from-hand-rolled,
  and /version-adaptation on the protocol docs site for protocol-level
  orientation. The remaining pages here stay @adcp/sdk-specific
  (TypeScript/JavaScript).
- Empty changeset (docs-only).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Brian O'Kelley <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant