Skip to content

SDK map — primitives, integrations, init and the dev loop on tier 1 #164

Closed
20 of 20 issues completed
Closed

Description

@allisonmahmood

Destination

The SDK era, written into docs/product.md, the CONTEXT.md glossaries and ADRs, sharp enough that each of these can be built from its own ready-for-agent ticket with no further design conversation: patchy init for a patch repo, the code-first config and its manifest, the tables and files primitives on a database per company, the integrations framework with Postgres as its first integration, shared tables read across patches, the local dev loop on real code with fixtures, and a minimal tier 1 (tier 0 with script allowed, inside a sandboxed frame) that exercises all of it. The map is done when the spec is filed and the build is filed as sub-issues of it, as the auth map did with Auth map — Clerk, companies and machine tokens on tier 0.

Notes

  • Product shape already decided; do not re-decide it. docs/product.md § Patches, § Runtime tiers and § Integrations fix: a patch is a file tree in a patch repo with an explicit tier; init lays down the SDK; the first publish creates the patch and writes its id back; primitives are patch-scoped (own tables, own files) or company-scoped (connections, the company database); tier 1 code acts as the viewer and reaches everything only through Patchy; integrations are Patchy-built, connections carry handles, patches declare them, code gets a typed client, no credential ever reaches patch code, every call is logged. One paragraph is reversed by this map: the dev loop no longer reaches real connections as the user; see Dev is local, on real code, with fixtures; the dev runtime is pinned in the repo in Decisions so far.
  • Convex is the reference for how the SDK reads: code-first schema, typed client, one command that runs the dev loop. Not for its storage model: tables here are real Postgres tables.
  • Charted from a live grilling on 2026-09-06, four rounds with Allison, each round pressure-tested with a second model (astra, through omp). Every closed ticket below records its reasoning in its resolution comment.
  • Prototypes get a second-model review. When a prototype ticket resolves, ask astra (omp -p --thinking xhigh, without no tools restriction, the prototype's files attached with @) whether the design is sound and how it expands to tier 2 and beyond, and record its verdict on the ticket next to Allison's. The prototype is thrown away; the learning is kept.
  • Skills every session consults: grilling and domain-modeling on grilling tickets; research on research tickets, findings in the ticket's resolution comment, never on a branch; prototype on prototype tickets; effect-service-conventions and node_modules/effect/AGENTS.md before writing Effect code; Hit every surface in CLAUDE.md before calling any build done.
  • Every grilling question carries context, consequences and a recommendation, so a session can be answered from the ticket alone.
  • Sequencing. patches: drop expiry, add retire and delete is not this map's; the spec assumes it lands independently.

Decisions so far

  • The destination: a spec for the SDK era, with a minimal tier 1 to prove it: a spec, not a build, with prototypes along the way; a minimal tier 1 (tier 0 with script allowed) is in scope so the SDK has a consumer; files, tables, Postgres and shared tables only.
  • Tables are real Postgres tables, additive-only on publish: real tables in the company database, never a document store; publish may add tables, optional or defaulted columns and indexes, and refuses renames, retypes and drops; old open tabs keep working, old writers included.
  • Definition versus declaration; shared tables are read-only across patches: a patch defines what it owns and declares what it uses; cross-patch access is a declaration of a shared table, read-only; extending is an own table keyed by the source's ids plus a join; declarations resolve to stable ids at publish; a removed dependency fails like a revoked connection.
  • One Postgres database per company: a Postgres database per company with patch namespaces inside it, platform tables in the platform database; bound pools per company, serialised DDL per patch, stable ids in physical names.
  • Dev is local, on real code, with fixtures; the dev runtime is pinned in the repo: patchy dev runs the real capability services over PGlite and a local file store as the machine token's user; metadata from the cloud, rows never; connections and shared tables bind to fixtures, every integration ships one; the dev runtime is a pinned dev dependency of the repo. Reverses the "no mocks" dev paragraph in product.md.
  • Open a patch and you can read and write its tables and files: whoever can open a patch reads and writes all of it, every row; no write scopes, no row rules; shared tables read-only; anonymous readers get nothing; personal-connection data may land in company tables.
  • Paths for addresses, a sandboxed frame on the same host for tier 1 script: addresses are paths on one host; tier 1 script runs in a sandboxed frame the shell renders at that path, served from the same host with a sandbox CSP on the content response; the SDK reaches Patchy through the shell broker; the API requires the shell Origin on mutations; the tier 1 promise is "credentials never reach patch code, every data call goes through Patchy".
  • Latest-only tooling, a stable wire contract for deployed patches: init pins, one refresh bumps SDK and dev runtime together, publish refuses outdated tooling; deployed bundles speak a stable wire contract and are never taken down for an old SDK; a breaking wire change is an explicit decision behind a "needs rebuild" door; four things versioned separately.
  • Code-first config, skills and context served per company, Postgres first: patchy.config.ts executed locally into a manifest the server validates; skills and a generated typed directory fetched per company and per declaration, a catalog for discovery; Postgres first with a runtime row decoder.
  • Vocabulary: definition, declaration, shared table, environment, fixture: definition, declaration, shared table, environment, fixture, acting identity versus owning patch; connection stays what it is.
  • Research: PGlite parity with Postgres for the dev runtime: amend. PGlite 0.5.8 runs Postgres 18.3 on one exclusive connection, so transactions serialise and it cannot show multi-session lost updates, lock waits or deadlocks; real-Postgres CI for concurrency and publish-versus-writer races is mandatory. Effect ships an official PgliteClient for the same SqlClient contract, but it rejects multi-statement sql.unsafe (the migrators use that form) and its row codecs differ from pg's (int8, DATE), so emit one statement per call and normalise codecs. Additive DDL probes passed; CREATE INDEX CONCURRENTLY cannot run in the transactional migrator. 33 bundled contrib extensions, no postgres_fdw; fixtures may need extension types, so allow-list mappings and reject the rest. ~9 MB tarball, ~25 MB unpacked, Node 20–24 tested; startup ~1 s fresh, ~0.2 s reopen; fsync is off by default, so persisted fixtures must be recreatable.
  • Research: a Postgres database per company on Azure, pooling and budgets: amend. Billing is per server; GP D2ds_v5 (2 vCores, 8 GiB, 844 user connections, PgBouncer-capable) is the floor at ≈ $134/mo with the 32 GiB minimum; Burstable is not for production. Azure documents no cap on databases per server, but its PgBouncer metrics cover only 30 databases. Built-in PgBouncer 1.25.2 pools per (database, user), defaults 50 backends per pair, and Azure's own guidance is 2–5 × vCores; budget idle backends fleet-wide across replicas. Transaction pooling forbids SQL PREPARE, session advisory locks and LISTEN; use pg_advisory_xact_lock(stablePatchKey) inside the same company transaction as the additive DDL. CREATE DATABASE needs a provisioning login with CREATEDB, runs outside a transaction against a maintenance database, and cannot commit atomically with the platform row. PITR is server-wide to a new server, so a company restore is restore-then-dump-then-load; keep companyId → {serverId, databaseName, placementVersion, status} in the platform database so a company can move by dump and restore with a deliberate cutover. Effect's PgClient builds a pg.Pool; a scoped RcMap registry with capacity and idle TTL fits; its cancellation uses pg_cancel_backend(processID), which is wrong behind PgBouncer, so start direct until that is fixed. Supplement on the ticket carries the pricing ladder and the lock-inference caveat.
  • Prototype: the sandboxed frame and the shell broker on the same host: holds in Chromium and Firefox on the whole ergonomics list; Allison's hand-check passed 2026-09-08; Safari still untested until someone has a Mac, not blocking. Frame gets allow-modals so patch code prints its own document; connect-src 'none' on tier 1 content, egress only as a later declared permission; the broker rides a document-bound MessageChannel so a navigated frame inherits nothing; identifiers validated at the shell, declarations enforced at the server; envelope lifecycle and a nonce-bound bootstrap carried into Tier 1 serving. Prototype on PR proto(serving): sandboxed frame and shell broker on one host (#175) #185, not for merge.
  • Prototype: patchy init --tier 1, code-first config, first table and file over PGlite, first publish: holds; keep the design with ten named changes. list filters by a declared index and update by id exist; defaulted is not nullable; uniqueness sits outside "additive" and diff rejects what it does not implement; provisioning authority is a server-owned cumulative inventory per patch with publishes serialised and bytes uploaded first; the generated client imports the config's type and the manifest's value; the runtime operations are a versioned contract with HTTP and postMessage adapters and per-request binding; a regenerated context file sits beside an agent-owned AGENTS.md; init leaves a tree that typechecks; patchy dev is non-blocking with start, status and stop. A fresh agent on the laid-down tree got to publish without touching the database, generated files or production. Prototype on PR prototype(sdk): patchy init --tier 1, dev over PGlite, publish with manifest #187, not for merge.
  • The tables surface: definitions, queries, joins, ids, and what additive-only refuses: own builders, no Effect in the patch's SDK; kinds text/integer/number/boolean/timestamp/json/ref, refs are indexed typed ids with no FK constraint; reserved id (UUIDv7), createdAt, updatedAt and a built-in index; list names an index (equality prefix, one range, keyset cursor), get, getMany; joins are two explicit steps with a null-per-missing, fail-on-revoked merge contract; insert, atomic insertMany, update, idempotent delete, null and missing-row semantics fixed; unique only at creation; the exact additive allowlist with unsharing reported as an access change; dev applies production's rules once published; server-assigned schema revision with warn-not-refuse for stale consumers; bounds as spec values; per-operation schemas in packages/api with error codes. Skills must not say "like Convex".
  • The integration definition, the Postgres integration and its fixture: a plain four-part definition (credentials, optional metadata with discovery, operations, generate, dev binding); connections carry a handle plus an admin description, encrypted with a keyring, connected on /company only, with test, rotate, retarget, disconnect and reconnect; declarations bind to the connection id and snapshot revision at publish, refused when stale; reads run read-only over the extended protocol as "constrained reads through the role you supplied"; the agent gets a generated per-relation surface (sales.customers.list({ eq, range, orderBy, select }), get({ id }), getMany) with raw query(sql, params, shape) as the escape hatch; one type mapping (int8 and numeric as strings) drives types, projection and validation; generated errors per method with a guard; fixture is one PGlite per connection with agent-authored rows; call log keeps the SQL, admin-only. Reverses "introspected warehouse types later" on the config decision.
  • What init pulls from the server: skills, generated types, context and the refresh command: one npm package patchy (CLI, browser client, config builders, dev runtime) at one release, pinned as one devDependency, served from the instance until public launch; patchy refresh (never git words) bumps the pin and regenerates as one transaction; dev (new starts) and publish refuse a pin that is not exact-current; the generated directory and the project skills are committed, per-user state stays in .patchy/; the server generates finished files; a global skill (what Patchy is, sign in, init) versus project skills (core: loop, tables, files; on demand: per integration and shared tables), presence sticky and config-implied skills added automatically; patchy catalog shows what is connected with --all for every offered integration; patchy add inserts the declaration and brings the skill, remove reverses it; shared tables declared by patch id; dev start regenerates, publish refuses stale; patchy dev is detached with status, stop, logs, reset. Graduates the cross-patch typing and dev runner fog.
  • Publish for a patch repo: build, manifest, tier check, provisioning order and wire versions: patchy publish [file] replaces upload and /api/publish replaces /api/uploads; a file is a static page, no file means a repo from init; one self-contained HTML per version at every tier, a server bundle added beside it from tier 2; manifest { manifestVersion, release, tier, tables, files, uses } accepted exact-current with readers kept for stored versions, the version row stamped with tier, release, manifest, wire and schema versions, wire stamped by the server; tier is about code only, a tier 0 repo may provision; the manifest lists what is used, omission is reported and never destructive (a required column omitted is refused); bytes first, then one platform transaction with a deadline locking the patch row around the company DDL transaction, rollback and delete on the same lock, orphan namespaces swept after a day; a per-attempt publish key so a lost acknowledgement never makes a second patch; the company database created lazily behind a claim row. Graduates the single-file uploads and publish recovery fog.
  • Tier 1 serving: the frame, the broker's operations, files inside the frame, and the promise: addresses are /<company>/<patch>[/route] at every tier now, /~v/<n> for versions, /d/* removed; one per-company namespace for patch names and future user and group handles; a name per patch (config in repo mode, derived with suffixes in file mode, rename redirects until the name is taken); content served by id from an internal URL bound to the loaded version; tier 0 keeps srcdoc; stable operation names with identifier arguments validated in the shell with the server's schemas and forwarded to one POST /api/runtime/call, bytes transferred beside JSON; me is a server-answered op with an admin hint; a public tier 1 patch gets no company capability for anyone; access-class refusals get a shell notice, the principal is bound at bootstrap and refused before execution when it changes, no replay, unknown_outcome for a lost reply; the unsupported list with frame-src 'self' on the shell as the egress containment to verify; the promise "acts as you, only through Patchy, never holds your login, every write logged"; no transport version, three stale states; dev serves the production bundle in the production sandbox and reloads the whole shell; mutations logged for admins; bounds as spec values at shell and server.
  • Write the SDK spec and file the build tickets: the spec is SDK: primitives, integrations, init and the dev loop on tier 1, reviewed twice by a second model before filing (frozen connection snapshots, a log row before every mutation, immutable file objects, the replay lookup, admission headers, per-operation caps and the inventory as sharing authority are its corrections); the build is sixteen ready-for-agent sub-issues of the spec with native blocking, four startable now. The map closes with the docs pass.

Not yet specified

  • Transactions and idempotency. Whether a patch needs atomic writes across its own tables and an idempotency key so a retried insert after an ambiguous response does not double-insert. v1 has neither; waits on evidence from a tier 1 patch in use. Carried into the spec's Out of Scope; it returns as its own effort, not a ticket on this map.

Out of scope

  • An authenticated mode of a public patch (a member getting company data through a public tier 1 patch). Tier 1 serving fixed "no company capability for anyone" and Allison expects to revisit it later, as its own decision.
  • Owner-only and group addresses (company/user/patch, company/group/patch); they arrive with those sharing scopes and inherit the shared per-company namespace rule from Tier 1 serving.
  • Writes through the Postgres integration; v1 is read-only, and writes are an explicit later decision, not fog on this map.
  • Credential key rotation as a job, call-log retention policy and a fuller log reader, a pasted CA for self-signed TLS, and connections on private networks; the integration ticket names each as later.
  • Cross-patch writes; a patch mutates only its own tables and files.
  • Destructive schema changes (rename, retype, drop) and the migration tooling they need. Publish refuses them. Adding uniqueness to an existing table is refused for the same reason. Migrations are a future effort of their own; Allison flagged on the tables ticket that v1's refusals will pinch in the long term.
  • Row-level or per-user access rules inside a patch; every readable row is readable by whoever can open the patch.
  • Raw SQL against the company database itself; a later SQL surface would expose authorised views, never the physical layout.
  • OAuth-connected integrations (Salesforce, Gmail, GitHub); the connect door is designed so they follow without a redesign, but none ships here.
  • Tier 2 (server handlers, live connections, the patch identity) and tier 3. The frame and broker are designed to carry a tier 2 transport later, not to build it now.
  • Cloud-hosted dev environments and hosted collaboration; dev is local.
  • A bring-your-own source, MCP servers or a generic REST escape hatch (already ruled out in docs/product.md).
  • A Patchy-run source-control tool for people without GitHub; Allison flagged it as a later idea on the init ticket. The only constraint carried now is that CLI commands avoid git vocabulary (refresh, not pull).
  • Billing and the end of hard patch quotas. Allison said on Publish for a patch repo that companies pay for their patches, so hard limits go; the live-patch quota stays as built until billing is designed, which is its own effort.
  • Publishing the patchy package to npm; it happens at public launch and changes only the pin string, so the init ticket designed for it without building it.

Sub-issues

Sub-issues

20 of 20 Issues completed
Loading 20 sub-issues

Activity

  1. added
    wayfinder:map
    on Sep 6, 2026
  2. allisonmahmood commented on Sep 11, 2026

    @allisonmahmood
    OwnerAuthor

    SDK map complete: the design decisions are implemented across the sixteen build tickets below. The build is still a PR stack; this comment does not claim the stack has merged. #209 reconciles the product, context map, owning glossaries, ADRs, API/CLI guides and agent skills against that stack.

    Build ticket Implementation PR
    #194 — replay-safe publish and version manifest #210
    #195 — names and company addresses #211
    #196 — company databases, pools and inventory #212
    #197 — runtime binding, admission and log #213
    #198 — additive tables #214
    #199 — file stores #215
    #200 — read-only shared tables #216
    #201 — connections, credentials and discovery #217
    #202 — Postgres execution, generation and fixtures #218
    #203 — one patchy package and release #219
    #204 — catalog, generation, project skills and repo commands #220
    #205 — tier 1 shell, sandbox and broker #221
    #206 — repo publishing #222
    #207 — local dev runtime over PGlite and fixtures #223
    #208 — packed SDK e2e and real-Postgres concurrency #224
    #209 — final documentation reconciliation #225

    The prototype PRs #185 and #187 remain closed, now with pointers to #205 and #207/#204 respectively. Their remote branches proto/frame-broker and prototype/init-tier1 have been deleted; local branches and worktrees were untouched.

    Reconciled facts: the platform migrator has seven records, including companies’ 0004 invites-expiry; the SDK records landed as 0005 company-database, 0006 runtime, 0007 integrations. The migrator never backfills gaps. The packed e2e runs inside cli-smoke. DEVELOPMENT.md now records the durable rule that main must require postgres-concurrency and cli-smoke; no ruleset was changed here.

    The docs reflect two existing implementation differences from §4 of #193: adding a file store also advances schema revision, and owned inventory is fetched at dev start rather than by refresh. This reconciliation does not change those behaviors. Patch identity, personal/OAuth integrations and hosted tiers remain future work; local declarations use fixtures, never production rows.

    Opus cross-family review clarification: #193 §15's “six records” line is stale, as is its company-database → integrations → runtime tail order. The docs follow the seven records in the code: 0001 companies, 0002 auth, 0003 patches, 0004 companies invites-expiry, 0005 company-database, 0006 runtime, 0007 integrations. Preserve that count and landing order rather than changing the correct docs back to the stale spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wayfinder:map

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions