Repository navigation
Description
Destination
A spec for tier 2 patches, written into docs/product.md, the CONTEXT.md glossaries and ADRs, sharp enough to file as build tickets with no further design conversation, and proven first by prototypes that were actually run: server-side handler code that Patchy executes while a viewer has the patch open, in a runtime inside our own backend; the server function contract agents write against (queries, mutations, actions) and the generated client; reactive queries that keep every open client in sync; the patch identity beside the viewer's; the execution service and its containment; patchy init --tier 2, the two-artifact publish and a local dev loop that runs the production engine; the little things a complete tier 2 patch needs, such as reading another patch's files; and the move of tier 1's scaffold, generated client and skills to Preact, the UI library both tiers now share, so the build tickets can open with it. The acceptance journey is a small reference CRM built from the skills by a fresh agent. The map is done when the spec is filed and the build is filed as sub-issues of it, as the SDK map did with SDK: primitives, integrations, init and the dev loop on tier 1 and the portal map with Portal: finding and managing patches in the deployed stage.
Notes
- Product shape already decided; do not re-decide it.
docs/product.md§ Runtime tiers fixes tier 2 as hosted while a viewer has the patch open, handler-shaped code in a fixedinitlayout, no bring-a-whole-app, two identities, no credential in patch code, nothing leaves except through Patchy, tier per version. The tier grilling, the publish grilling (a second immutable server artifact beside the HTML, described in the manifest) and the integration grilling carry the reasoning. Everything the SDK map and portal map built is the floor. - Research already done, reuse it: tier 2 prior art (isolate / process / microVM across 95 sources) and Daytona (a fit only for bring-a-whole-app). New research starts from those comments.
- Charted from a live grilling on 2026-09-19, three rounds with Allison, each round pressure-tested with a second model (astra, through
omp). The first closed ticket below records every decision from those rounds. - Hosting. Patchy hosts on AWS (
us-east-1, ECS Fargate) with company Postgres on Neon, decided 2026-09-25 on the hosting cloud ticket; the earlier note (Azure now to spend credits, AWS later) is retired. Nothing from this repo was ever deployed, so nothing migrates; the Azure grouprg-patchy-prodis an earlier, separate codebase and PatchPage is a separate product, both stay on Azure and outside this map. Portability means one container image and the pool wake path, not a ban on managed services. Company Postgres and the content store are both on Neon: one project, a database per company, and Neon Object Storage (S3 API, path-style, branch-scoped) instead of an AWS S3 bucket, decided by Allison on 2026-09-25 while the provisioning task ran; the spike's AWS and Neon keys are in~/.config/patchy-cloud/aws-spike.envandneon-spike.env, and the Azure spike group is gone. - Research runs on two models. Each research ticket is resolved by astra with tools (
omp -p --auto-approve --thinking xhigh) and an Opus subagent in parallel; the charting session merges both and fills gaps with its own judgment. Findings land in the ticket's resolution comment, never on a branch and never in the tree. - Prototypes are real and thrown away. A code prototype runs on an Opus 5.5 subagent (Fable orchestrates and never builds; decided by Allison on 2026-09-25 during the init prototype), is pushed to a
prototype/<name>branch and filed as a real PR that is never merged, with a Try it section, updated as the discussion moves. Spikes against cloud services report measured numbers, not benchmarks of an empty handler. Before a prototype is thrown away, astra evaluates it (is the design sound, how does it expand to tier 3) and its verdict is recorded on the ticket beside Allison's. - Skills every session consults:
grillinganddomain-modelingon grilling tickets;researchon research tickets;prototypeon prototype tickets;effect-service-conventionsandnode_modules/effect/AGENTS.mdbefore writing Effect code; Hit every surface inCLAUDE.mdbefore calling any build done. - Every grilling question carries product context, consequences and a recommendation, so a session can be answered from the ticket alone.
- The UI library is Preact, on both tiers, with compat semantics, and it comes through the SDK. Decided 2026-09-21 on the contract ticket:
preact/compatis loaded once bypatchy/preact, so patch code keeps React event and ref idioms with no React package. React Aria Components was retracted, and the reference CRM rejected Zag.js. On 2026-09-28 the allowlist ticket madepatchythe only import root: it bundles exactpreactand@preact/signals, and patch code importspatchy/preact. Skills say "Preact with compat semantics", never React; agents trained on React drift otherwise. - Convex is our reference, not the agents'. Reactive queries and the query/mutation/action split may be compared to it in design notes; skills and product docs never say "like Convex".
Decisions so far
-
The destination: a spec for tier 2 patches, proven by prototypes: a spec for tier 2 patches with build tickets, proven by prototypes; request-scoped handlers with Patchy owning presence and subscriptions; no inbound routes or webhooks (execution without a viewer is tier 3); the patch identity kept at reduced size with three-way attribution; the tier 2 client is server-only, admitted by the served version's tier; handler code runs in a credential-free execution service beside the hosting server with no ambient authority; query, mutation and action with atomic mutations; composition is shared file stores plus authorised file handles; dev runs the production engine; dependencies are
patchyplus a pinned per-release allowlist, settled by research and the reference CRM (the first entry was React; revised to Preact on 2026-09-21, see the contract ticket). -
The server function contract: queries, mutations, actions, the context object and the generated client: handlers are module-qualified exports of
server/*.ts, one level deep, enumerated by the build into manifest descriptors; args and results on a grownt; one context object narrowed per kind (viewer,tables,shared,files,connections,log,run), only actions compose;HandlerErrordistinct from Patchy refusals withhandler_failed,handler_timeoutandbusyadded; a framework-free core client with.subscribeon queries and oneuseQueryinpatchy/preact; handler types by type-only import of the server modules; Preact with compat on both tiers, its ownpatchy-preactskill, no test runner in a patch repo. -
Research: what a CRM-class patch needs beyond the SDK: the allowlist model is Retool's shape;
Intland Web Crypto cover formatting; Temporal is not available everywhere so@internationalized/date; React Aria Components was the accessibility entry, retracted 2026-09-21 as broken under Preact with Zag.js as the replacement candidate; CSV behind an SDK helper on PapaParse; phone vialibphonenumber-js/min; server list empty; grid and decimal libraries wait for the CRM; rich text, charts, PDF, XLSX and HTML sanitisation deferred with named limits; Node compat disabled deliberately. -
Research: Cloudflare Workers for Platforms as the managed execution path: built for the job (per-invocation CPU and subrequest budgets, Outbound Workers as the broker's twin, CPU-time billing so idle is near free, about $25 for 1,000 patches); no rollback surface, code and secrets in every Cloudflare data centre, one account as the blast radius, no credits; Azure placement hints exist but are undocumented for dispatch-namespace Workers. Kept as the managed comparison, spike still runs against the self-hosted one and does not carry the private-cloud promise.
-
Research: how reactive-query systems track reads, invalidate and push: both models converge: a subscription is an existing read marked subscribe, table-granular dependencies from declared resource keys, server re-run through the same dispatch and binding, unchanged results suppressed, keys-only wake, one SSE stream per document over the existing MessageChannel, refuse subscriptions over company Postgres; in-process after-commit event now with durable per-table revisions, NOTIFY when replicas exceed one; per-subscription consistency accepted for v1.
-
Research: one transaction per mutation across an invocation's callbacks: one host-owned company transaction per mutation, opened on the first callback and joined by every later one; five-second deadline enforced in three places; the existing four slots with fail-fast busy; SERIALIZABLE with Patchy re-invoking the whole handler up to three attempts on 40001; abort-only errors with no savepoints per callback; the log row outside the blast radius. Found that the mutation deadline is unenforced today (runtime: the mutation deadline is logged but never enforced #317).
-
Research: a self-hosted execution service on Azure Container Apps, portable to AWS: open-source workerd has the Worker Loader (verified in source): one dynamically loaded Worker per patch version,
globalOutbound: nullplus a loopback gateway carrying the per-invocation capability, limits accepted but unenforced so we write the watchdog; the company is the v1 containment unit, one workerd process per company in an unprivileged scale-to-zero container, escalation gVisor then a Fargate task per company; ACA forbids privileged containers and rootless systrap is unproven there; Dynamic Sessions priced out; Fargate is the AWS target, App Runner closed. -
Prototype: the reactive query loop across two browsers: built on PR prototype(runtime): reactive query loop across two browsers #343 and measured (43 ms two-browser loop, 50 writes to 4 re-runs, revocation and reconnect as modelled); the model holds. Decided: durable per-table revisions in v1 with resume answered by
up-to-datewhen equal; a per-company re-run semaphore plus per-patch cap; hidden documents suspend and resync. Fences carried to the reactive queries ticket:up-to-dateas a commit-watermark fence, desired/admitted reconciliation, HTTP/2 at ingress proven by a seven-document check, fetch-streamed SSE, one frame per subscription with tearing stated, timed session-expiry checks. The authority proof moves to the reference CRM. -
Reactive queries: dependency tracking, invalidation after commit and the stream to every open client: the sync section of the spec and eight glossary terms. Dependencies traced per run from callbacks, table and store grain, row-level the named escalation; one read snapshot per query run beside the kept watermark fence; a per-resource revision vector on the wire, resume answered
up-to-datewhen equal; mutations resolve on commit; a shell-owned reconnecting indicator cleared on reconciliation; resync re-admits and re-runs only where a revision moved, with provisional remount and hidden grace; bounds as plain refusals with numbers on the limits ticket; permanent re-run failures end the subscription with the last value kept; tier 1 getslist/getsubscriptions on the one contract. -
Presence and lifecycle: leases, disconnect grace, in-flight work, retries and a publish under open viewers: the lifecycle section of the spec and seven glossary terms. Presence derived from connected streams, no lease; the stream opens at bootstrap on every company document, both tiers, carrying lifecycle frames; departure gates starting, not finishing, with explicit cancellation the escalation; every mutation call carries a per-call key written in its transaction so
retry()onunknown_outcomeis safe (actions never); timeout aborts only when non-commit is established; a document keeps its loaded version until it closes with a non-stoppingsupersededelement, revocation a stopping notice re-checked at re-admission; unsharing or deleting advances the revision; deadlines, retention and result cap to the limits ticket. -
The patch identity at tier 2: authority, attribution and the served-version rule for direct writes: the identity section of the spec and seven glossary terms. The patch identity adds no resource entitlements in v1, only the execution path and attribution; invocation admission once, callback authorisation per callback with shared and connection checks re-run; while the patch is tier 2 a lower-tier document gets
meand nothing else, refusedserver_required, reopened by rollback with theservedframe clearing the notice; operation rows stay with an invocation row, effective principal and nullableuser_idadded, queries logged only onctx.logor failure; public tier 2 and the admin integration grant ruled out of this map with their room named; the identity is the patch id and survives deactivation and reassignment. -
Provision what the execution-service spike needs on Azure Container Apps:
rg-patchy-tier2-spikein eastus with a Consumption environment, Postgres 17 as an internal container app (managed Postgres is region-restricted on the subscription in eastus and eastus2), a Basic registry with a pull identity, and a service principal scoped to that group only; keys in~/.config/patchy-cloud/tier2-spike.env; about $20 a month left in place; no workload profile exposes KVM or a runtime setting, Confidential DC/EC profiles are an environment-level SEV-SNP boundary. The Cloudflare half was dropped with the managed spike ruled out of scope. -
Research: Neon as the company Postgres host: Neon is AWS-only now (Azure Native retired 2026-03, Azure regions deprecated 2026-04) and no cloud credit pays for it; it fits ADR-0009 unchanged (one project, a database per company, direct connections, no pooler), the held SERIALIZABLE transaction is safe, cold start about 0.7 s,
LISTENnever through the pooler; branch per company rejected, project per company the escalation; eastus-to-us-east-1 latency unmeasured. It forces the cloud decision, filed as the hosting cloud ticket. -
The hosting cloud and the Postgres host: move to AWS early, or stay on Azure for the credits: AWS now, before the spike; ECS Fargate in
us-east-1and Neon for company Postgres with suspend disabled on the production compute and RDS the unprovisioned fallback; the wake path is a pool of pre-started unbound tasks bound to a company on first open and released on idle, so dormant companies cost nothing and first open is a page load; the Azurerg-patchy-prodgroup is an earlier separate codebase and stays untouched, as does PatchPage; an AWS and Neon provisioning task now gates the spike. -
Provision what the execution-service spike needs on AWS and Neon: AWS account
614817375332(Srikar's root with MFA, Allison via Identity Center) with a disposable us-east-1 IAM user for subagents; VPC with public subnets for the ALB and host and a private subnet for execution tasks reached through registry and log endpoints and no secrets endpoint; theexec-bootstrapandexec-sealedsecurity-group pair for the spike to compare; ECS cluster, ECR repo, task roles, and an ALB with a 3600 s idle timeout and a self-signed cert for HTTP/2; Neon projectpatchy-tier2-spikein us-east-1 with suspend on,patchy_adminasneon_superuser, and bucketpatchy-contenton Neon Object Storage; keys in~/.config/patchy-cloud/aws-spike.envandneon-spike.env; about $39 a month idle; Fargate vCPU quota increase pending; Azure spike group and service principal retired. -
Prototype: the execution-service spike on ECS Fargate, a handler bundle in a credential-free task against Neon: built and measured in two rounds on PR prototype(tier2): execution-service spike on ECS Fargate with workerd and Neon #379; the self-hosted service holds: Worker Loader boundary with a tokenless guest, one SERIALIZABLE transaction per mutation on Neon (ten callbacks 92 ms p50), 40001 retries, mutation keys deduplicating across a lost reply and a host replacement, bind 16 ms against a 24 s cold start, epoch-fenced bindings in the database, containment and authorisation probes all refused, seven SSE documents over HTTP/2. Decided: one workerd process per loaded patch version inside the company task with a residency budget (a runaway patch degrades siblings instead of killing their requests, about 45 MB per open patch); a deployment drain is the normal reconnect-and-resync, no goodbye frame, an announced handover later polish. Astra's five ADR contracts carried to the execution service ticket; Neon needs a SET-only grant before CREATE DATABASE … OWNER and DROP DATABASE under SET ROLE.
-
The execution service: engine, containment unit, invocation capability and the callback path: the execution service ADR in decision form and the hosting section. A task serves one company then stops, never reused; a global pool of spares (two to start, target following the wake rate) with a first-party "starting" wait of one cold start then
busy; idle release when zero connected tier 2 documents and no work in flight, admissions fenced first; the controller is host code over the platform database with a housekeeping lease, a per-company binding epoch, process generations and the deployment revision kept distinct, one image with two entrypoints; private listeners both ways, a rotated deployment secret, no fleet admin over the load balancer; metering in three groups (invocation, process, company bound seconds); the tier 2 promise and the boundary statement (the company task is the security boundary, the process per version is availability isolation); eight ADR contracts and the ADR-0009 Neon amendments carried to the spec. -
Prototype: patchy init --tier 2, server/, dev on the production engine and a two-artifact publish: built in three rounds on PR prototype(tier2): patchy init --tier 2, server/, dev on the engine and a two-artifact publish #380 and accepted; a fresh agent reaches a published, hosted, atomic tier 2 patch on the skills alone in under ten minutes (four runs, no package reached for). Decided: the init shape, two-artifact publish with server-side re-derivation and dev on the production engine go into the spec as built; the transaction is host-owned in the execution seam with callbacks as jobs on it and four slots carrying four invocations; refusals cross the loopback as data; declared handler errors enforced host-side with their own log outcome;
optionalon args versus columns, readonly results and the three-attempt rule as skill facts. Astra's remaining fences carried to the execution service ADR, limits, reactive queries, repo/dev-loop, composition and CRM tickets. -
The repo and dev loop on both tiers: the Preact scaffold, init --tier 2, server/, the two-artifact publish and dev on the production engine: the repo, CLI and dev loop section of the spec.
refreshowns the release's managed pins and the generated server module list; dev re-readsserver/live. Tier 1 is the default and tier 2 is for enforced rules, atomic multi-row writes or server-side work. Changing tier either way is a config edit plusrefresh, withtsclisting the calls to rewrite. A server rebuild re-runs open subscriptions, and the colleague mount runs on both tiers. Tier 1 moves to the Preact scaffold with the import check. Also settled: stored versions keep their wire,import_refusedandtier2_not_public, publish--jsonnaming both artifacts and the handlers, a content-addressed release tarball, and dev log lines with no runtime-log rows. -
Composition for a complete tier 2 patch: shared file stores and authorised file handles: the composition section of the spec and four glossary terms. Shared file stores are shared whole, like tables, and read on both tiers with the gate on the consumer, the same live checks and reverse states, and
patchy add shared-store. An authorised file handle records the server's selection and grants no Patchy access: Patchy checks the viewer's reach on mint and every redemption, and which handles to hand out is the patch's own filter. Handles bind to viewer, patch, loaded version, store and exact object, with no page and no clock; they ride on file metadata and pin the bytes.url/download/useFileUrlon the page. Staged uploads are a third shell exception, adopted once by an action'sput. Dev gets fixture directories, with no simulated authority changes. -
Prototype: the reference CRM, built twice by a fresh agent, and where it hit the walls: four fresh-agent runs on PR prototype(tier2): the stack the reference CRM needs, files, handles, shared stores and company Postgres #381, two variants each built by Opus 5.5 and astra, all published, no authority bypass, scored 92–95 against truth data. Decided: no example CRM ships to agents, and the four runs stay as internal reference; access Patchy controls is re-checked on every redemption, while files narrowed by the patch's own filter are cut off by re-putting, which becomes a skill line; the company member directory is a native resource (its own ticket); the allowlist is
patchy,preactand@preact/signalsonly. Carried: a dropped client leaks its company transaction (execution service), two viewers hitbusy(limits), and the stack facts, gaps and skill fixes (spec). -
The dependency allowlist and the helper inventory: what the release lists and what the SDK ships: no third-party allowlist. A patch is the Patchy SDK (Core, Primitives, Integrations, Helpers) plus company code the agent writes or copies in, which Patchy neither versions nor answers for. The import check is a build contract, not a security boundary.
patchyis the only import root and bundles exact Preact and signals, so managed pins arepatchyplusworkerdon tier 2. v1 addspatchy/csv(a sync codec on PapaParse) and a shell-owned generated-file download. The runtime promise is three statuses with a tested server list. v1 supports Chromium desktop only. Skills carry delivery facts, not recipes. -
Native resources: the company member directory and what else Patchy gives patch code: the member directory is a declared company Primitive (
patchy add members, its own skill), not Core and not a new "native resource" kind. Candidates (list, prefixsearch, pages of 50, active users only, narrowed by group sharing later) are separate from resolution (get/getMany, deactivated users flagged). It is live through a platform-side directory revision, on both tiers and refused outside the company. At.member()column is checked by Patchy on insert or change on both tiers, and unchanged values pass. Dev lists the two mount identities. -
Limits and safeguards before billing: CPU, memory, wall time, concurrency and subscriptions: the bounds table and the observability section of the spec, every number a starting value tuned later from data. Contract limits are fixed per release; operating limits are config with per-company overrides; one registry that enforcement reads generates
docs/limits.md. Deadlines are 3/5/60 s by kind, with a kill a second later or after a 6 s stall. A 1 s connection queue replaces a barebusy. Actions have their own cap, and the company admission rate is 100/s. The breaker refusespatch_paused;write_conflictis a new refusal. The task is 0.5 vCPU / 2 GB holding at most 12 processes, with a 40 s empty-pool wait and a 30 min idle release. Logging is wide events, one per hop, unsampled to CloudWatch and PostHog with viewer ids ("readers stay unwatched" retired as a PatchPage leftover), with metering kept separate. The manifest records SDK imports. -
Write the tier 2 spec and file the build tickets: the spec is Tier 2: hosted server code, live sync and the execution service, stated as the effective contract with a supersession table and links to each resolution; one new
executionpackage beside a grown Runtime; exact per-minute query rollups withdb_ms; periodic reconciliation besideNOTIFY; the build is 32 sub-issues with native blocking, a HITL design ticket first and deploy tickets last (CDK, then a first deploy Allison runs); the docs pass closes this map.
Not yet specified
Nothing: the spec is filed and every remaining item is a build ticket or out of scope.
Out of scope
-
A Patchy-staff fleet view of which company is bound to which task, spares, release and drain, over the controller operations. Allison wants it right after v1, so it sits past this map's destination; the spec lists it as the first thing after v1.
-
A Patchy-shipped UI layer beyond Preact (headless components, grids, date pickers). Ruled out on the reference CRM: given Zag.js and TanStack Table, the fresh agents used native elements instead, apart from one dialog. The v1 allowlist is the floor only. Revisit it as a fresh effort once patches ask for components.
-
Tier 3: anything that executes with no viewer present: inbound HTTP routes, webhooks, schedules, unattended imports and automations. Tier 2 alone is an interactive CRM, not an autonomous one; the spec says so plainly. Tier 3 is the map that follows this one.
-
Bring a whole app as a second tier 2 runtime, and Daytona as its substrate; deferred on the tier grilling, unchanged here.
-
Cross-patch writes, a patch calling another patch's server functions, and company-owned tables. Composition on this map is read-only shared file stores beside the shared tables that already exist.
-
Uncontrolled third-party packages. A patch imports only the Patchy SDK. Anything else is company code the agent writes or copies in, which Patchy does not version or support. Settled on the allowlist ticket; a list of audited external packages is not coming back.
-
Complex document generation (PDF, spreadsheets) as a Patchy-executed capability; later, once the runtime exists to host it.
-
Billing, and the end of hard patch quotas.
-
Wide events on the rest of the server, CLI usage headers and SDK install events: server: wide events for every route, CLI usage and SDK installs, filed from the limits ticket; this map covers only the runtime path and the execution service.
-
A declared direct-egress allowlist; deferred on the tier grilling, unchanged here.
-
Cloudflare Workers for Platforms as the managed execution path. Ruled out on 2026-09-23 with the managed spike closed unresolved: it entered at charting as a comparison, never a choice; the destination puts the runtime inside our own backend, and its research found it fails the private-cloud promise with no credits and one account as the blast radius. Open-source workerd on the self-hosted path stays.
-
Public tier 2 patches and the admin grant of a shared integration to a patch. Ruled out on the patch identity ticket: a tier 2 patch cannot be shared publicly and connections are reached as the viewer only; the room kept is a nullable initiating viewer and an effective principal per callback, with a public-context typing contract and a scoped grant surface as the later work.
docs/product.mdmarks both proposals deferred.
Activity
1 remaining item
docs(domain): reconcile the tier 2 map (#454)
allisonmahmood commentedon Oct 21, 2026
Tier 2 is built and live at https://cloud.patchyhq.com. The spec #384 and its build are closed, production has run it on the ECS fleet since the first deploy on 2026-10-05 (#416), and #818 updated the docs to match.
#425 (who revokes a patch version) is the one child still open. It continues as its own grilling and doesn't hold the map open. Tier 3 is next, on #623.