Skip to content

prototype(tier2): patchy init --tier 2, server/, dev on the engine and a two-artifact publish - #380

Closed
allisonmahmood wants to merge 14 commits into
mainfrom
prototype/tier2-init
Closed

allisonmahmood wants to merge 14 commits into
mainfrom
prototype/tier2-init

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Prototype, not for merge. Part of #314.

A tier 2 patch has no path today from patchy init to a served version whose page calls server code: no handler contract in the package, no second artifact on publish, no engine beside the runtime. This slice builds the thinnest real thread through every surface so a fresh agent with only the tree and the project skills can be measured against it.

What is here

  • packages/execution: the engine (the Prototype: the execution-service spike on ECS Fargate, a handler bundle in a credential-free task against Neon #311 loader Worker on workerd, bind/invoke/inspect, a loopback callback listener with per-invocation capabilities) and the server.call runtime handler.
  • patchy/server with query/mutation/action, t.object/array/enum/nullable/row, HandlerError; patchy/_generated/server.ts bound to the config; patchy.server.<module>.<export>() typed from server/ itself.
  • The server bundle through the repo's Vite 8 library build, an import-check plugin on both graphs, discovery by loading the exact bytes.
  • Two-artifact publish: the second object stored under its own intent, server_hash on the version, handlers re-derived server-side and compared before the version is recorded.
  • patchy dev on the engine with rebuild-and-rebind and two viewer mounts; the patchy-server project skill; init --tier 2.
  • prototypes/tier2-init/README.md: the file map, measured numbers, the stall list and design notes.

Numbers (2026-09-25, one laptop)

engine spawn 41 ms, bind 7-12 ms, warm invoke 3-5 ms; init --tier 2 8.9 s, scaffold typecheck 1.1 s; publish 1.6 s; served page viewer 121 ms, add-and-relist 66-73 ms, server-side query 5-12 ms and mutation 4-6 ms; patchy dev start 4.6 s, first bind 71 ms, edit-to-rebind 122 ms, two tabs ready 231 ms, simultaneous adds 151/149 ms; disagreeing manifest 422 in 48-104 ms, for(;;){} refused at 5041 ms with the throwaway process gone; sleep(12000) is handler_timeout at 10.01 s.

Stalled or skipped: the Preact scaffold; stopping a CPU-spinning handler in the serving engine (no watchdog by decision); ctx.shared/files/connections/run, the mutation key and subscriptions; one transaction per mutation (a row written before a throw persists, stated in the skill).

Checks on this branch: pnpm typecheck green (38/38); pnpm lint green; pnpm test 935 passed, 2 expected reds (the SDK export-list assertion now sees ./server, the migration-ledger assertion now sees 0009), 3 load-induced timeouts that pass alone, docs/API.md re-rendered.

Fresh agent

Handed to a fresh agent (astra with tools) with only the tree and the project skills: a shared follow-up-calls tool with attributed "mark done", built, run as two people in the two dev mounts and published in about eight minutes with no package reached for; its handlers then answered hosted server.calls on the instance. Stall list, astra's evaluation and the build report are on #314. A first run was invalid because pnpm's store served a stale patchy-0.0.1.tgz by URL; that finding goes to the repo and dev loop ticket.

Round 2

Allison asked for the learning round 1 left out. Same branch, four more commits.

  • Preact scaffold, the The server function contract: queries, mutations, actions, the context object and the generated client #296 point 14 recipe. patchy/preact loads compat once and re-exports what a patch needs; the tier 2 scaffold is src/main.tsx + src/App.tsx with exact pins in dependencies, jsx: react-jsx + jsxImportSource: preact beside oxc.jsx.importSource, modulePreload off; the import check refuses react, react-dom, preact/compat and no longer allows vite/*; a patchy-preact skill is served on tier 1 and 2. Measured: onChange fired 5/5 keystrokes, add through the form 112-114 ms, forwardRef focus works, built document 14.5 KB gzip against 4.8 KB vanilla, scaffold tsc 1.06 s, fresh init 22.3 s on an empty store.
  • One company transaction per mutation. Opened at admission on its own fiber, callbacks are jobs on it (serialised, joined, drained-then-refused at completion), commit only after the validated result, SERIALIZABLE with up to three whole-handler re-invocations on 40001 (statement or commit) and a fresh capability per attempt; queries get a REPEATABLE READ READ ONLY snapshot. Measured on Postgres: writeThenThrow 0 rows, ten-callback mutation p50 14 ms server-side, insert-then-timeout rolled back (0 rows, handler_timeout at 10.01 s), eight concurrent bumps on one row total 8 with 3 serialization retries; on PGlite 0 rows, p50 22 ms, no retries (one connection). Bound: two invocations per company, busy past that, because each callback borrows a second pool slot through the table handlers.
  • Astra's points. t.row validates the pinned row shape ($.createdAt: expected an ISO timestamp), descriptors carry only their own keys, refusal codes come from the host's own record, disagreements name the descriptor path (notes.add.kind: declared "query", bundle says "mutation").
  • Watchdog (stretch). A timed-out invocation makes the engine probe its process; when a spinning isolate stops answering, the process is killed and respawned (kill to healthy replacement 18 ms), in-flight invocations roll back and report handler_timeout; notes.list answered 23 ms after the respawn. Execution compatibility, not containment.

Stalls: the two-invocation bound; the ProcessKilled path was not the one the measured sibling took (its own deadline came first); tier 1 stays vanilla. Checks: pnpm typecheck green (38/38); pnpm lint green; pnpm test 937 passed with the two expected reds (SDK export list, migration ledger) and one load timeout that passes alone; the server test files that had hung since round 1 (engine health poll under the TestClock) pass again.

Round 3

Round 3 has four steps: astra's second-pass enforcement fences, ctx.shared/ctx.connections/ctx.run, load numbers for the limits ticket (#304), and a subscription on a tier 2 query. The README's ## Round 3 has every table. The runs used the worktree's pnpm dev instance (embedded Postgres, one company) unless PGlite is named.

1. Fences.

  • The callback listener rechecks liveness after parsing. Completion revokes admission, joins the running callback, refuses the queued ones, then finalises. The transaction fiber is ready before admission completes and refuses its queue on every exit.
  • A 40001 anywhere makes the attempt abort-only; after that the guest's return value decides nothing.
  • The outcome comes from the commit phase: the transaction is verified before COMMIT, and unknown_outcome is only a lost COMMIT reply.
  • Callbacks reuse the invocation's held connection (Transaction.joiningDatabases, in the execution seam), so four pool slots carry four invocations.
  • One deadline covers admission, retries and settlement, and SET LOCAL statement_timeout bounds a callback in flight.
  • Declared errors are enforced by the host, and descriptor lookup uses own keys.
  • Numbers:
    • writeThenThrow and insert-then-timeout leave 0 rows.
    • The ten-callback mutation has a p50 of 12 ms server-side.
    • A timeout while a callback is blocked on a lock gives handler_timeout at 10.02 s; Postgres cancels the statement in the same millisecond, and 0 rows remain.
    • Of eight concurrent bumps, 7 commit with the counter at 7 and 8-11 retries; 1 exhausts its three attempts.
    • A caught 40001 followed by a valid return never commits: 7 "bumped" replies, counter 7.

2. ctx.shared, ctx.connections, ctx.run. A query reading another patch's shared table through ctx.shared.signups.list takes 9.4 ms p50 wall, and a mutation reaching it gets access_denied. An action running two sibling mutations and a query through ctx.run takes 20.5 ms p50; the sibling's HandlerError is rethrown to the action, and a query's ctx.run is refused. Stall: ctx.connections is unexercised. The embedded Postgres cannot satisfy the connect path's verify-full TLS and non-superuser checks.

3. Load (bounds: 4 invocations per company, 4 pool connections, 10 s deadline, call rate raised to 100,000/min).

Run 4 / 4 8 / 8
20 viewers × 30 calls, 2 list : 1 add 155 calls/s, p50/p95/p99 82 / 343 / 530 ms, 1,269 busy 241 calls/s, 43 / 256 / 598 ms, 451 busy
50 bumps on one row 30 committed = counter 30, 20 exhausted, 70 retries, 982 ms 31 = 31, 19 exhausted, 83 retries, 695 ms
30 s sustained at the slot count 302 calls/s, 12.5 / 16.0 / 18.6 ms, 0 busy 357 calls/s, 21.1 / 25.9 / 32.7 ms
  • Nothing leaked from the registries: connections stay at the bound, and the engine and loader registries return to 0.
  • workerd RSS grows (129 → 451 MB over ~19k calls, flattening, not returned when idle).
  • The Node server is the bound, at about 3.1 ms of CPU per call.
  • A bare busy makes clients retry through full admission, and that halves throughput at 20 viewers.

4. Subscriptions.

  • patchy.server.<module>.<query>.subscribe(args, onSnapshot) returns an unsubscribe. The shell stream and client registry are lifted from Prototype: the reactive query loop across two browsers #313.
  • ServerCall traces the tables each run's callbacks touched, with shared aliases resolved to the owner's key.
  • A tier 2 mutation wakes after its own COMMIT, a tier 1 write from Runtime.dispatch, and a dev rebind with version:<patch>.
  • Numbers:
    • An owner click reaches the colleague's snapshot in 91 ms p50 (two Chromium contexts, published page).
    • 50 writes cause 16 re-runs per subscription.
    • After unsubscribe, writes cause 0 re-runs.
    • A shared-table owner's write reaches the subscriber's snapshot in 42 ms.
    • A mutation subscription is refused and the mutation never runs.
    • In patchy dev, a server/ edit reaches the live subscription on the new bundle in 79 ms without a resync.
  • Stalls: the v1 decisions from Prototype: the reactive query loop across two browsers #313 are not built (durable revisions, the up-to-date watermark fence, desired/admitted reconciliation, a separate re-run bucket, hidden-document suspension, a per-company semaphore with a per-patch cap). There are two wake points where a build wants one.

Checks after round 3: pnpm typecheck is green (38/38) and pnpm lint is green; round 3 fixed two reds that step 2 had left. Targeted suites: runtime 34/35 (only the expected migration-ledger red), serving 31/31, patchy 310/310 (its Operation union assertion gained subscribe | unsubscribe, as #313 did), company-database 30/30. The full pnpm test was not re-run.

Try it

git fetch origin prototype/tier2-init && git checkout prototype/tier2-init && pnpm install
pnpm dev && set -a; . .local/dev/env; set +a   # the release tarball is cached by URL in pnpm's store: use an empty --store-dir for a fresh init
cd /tmp && node <worktree>/packages/patchy/dist/index.js init notes --tier 2 --purpose "Team notes" --json
cd notes && pnpm exec tsc --noEmit
node <worktree>/packages/patchy/dist/index.js dev --json      # url and colleagueUrl
node <worktree>/packages/patchy/dist/index.js publish --json  # open the address signed in

Not breaking: nothing here is deployed anywhere; tier 0 and tier 1 paths are unchanged except for one added runtime operation the broker admits by table, and one additive migration.

Built by Claude Fable 5.1 via Claude Code (subagent)

🤖 Generated with Claude Code

allisonmahmood and others added 6 commits September 25, 2026 21:00
…artifact publish

PROTOTYPE for #314. New packages/execution (workerd loader, Engine service,
server.call handler), handler descriptors and the server.call operation on
the wire, patchy/server builders with t.object/array/enum/nullable/row, the
server bundle build with the import check, tier 2 publish storing a second
object and re-deriving the handler map, tier 2 init scaffold and the
patchy-server skill. Dev runtime wiring follows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…scaffold typechecks

PROTOTYPE for #314. Infer matches descriptor shapes instead of the Column
class (deep instantiation), the generated server client takes the config
type explicitly, tier 2 starter files land last in the scaffold, the Vite
library build uses rolldownOptions.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ts; callback refusals as data

PROTOTYPE for #314. patchy dev binds the server bundle from a Vite library
build-watch, swaps the loaded version per rebuild, and serves a second
loopback listener bound to a fixture colleague. The loader returns
callback refusals as data because Error properties do not survive the RPC
hop into the guest.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…esources keep version; README

PROTOTYPE for #314. The import check's refusal is found through rolldown's
error wrapping on publish and in both watchers, devResources exposes the
initial version as a value again (its tests spread it) beside
currentVersion(), and prototypes/tier2-init/README.md records the file
map, the numbers and the stall list.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:xl Over 1,000 changed lines; review in multiple passes labels Sep 25, 2026
allisonmahmood and others added 8 commits September 25, 2026 22:11
…preact and the patchy-preact skill

PROTOTYPE for #314 round 2. The tier 2 scaffold is the #296 point 14
recipe: empty root, src/main.tsx + src/App.tsx, exact preact and signals
pins in dependencies, jsx react-jsx + jsxImportSource preact beside
oxc.jsx.importSource, modulePreload off, preact/debug behind an awaited
dynamic import. patchy/preact loads compat once and re-exports what a
patch needs; the import check refuses react, react-dom and preact/compat
and no longer allows vite/*. The patchy-preact skill is served on tier 1
and tier 2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… refusal codes; row-shape and path diagnostics

PROTOTYPE for #314 round 2. Transaction.ts opens one SERIALIZABLE company
transaction per mutation at admission (REPEATABLE READ READ ONLY for a
query) on its own fiber; callbacks are jobs on that fiber, so they
serialise on and join it; completion joins the running job, refuses the
rest and commits only after the result validated. A 40001 anywhere,
statement or commit, re-invokes the handler up to three times with a
fresh capability. Two invocations per company, busy past that. t.row
validates the pinned table shape, descriptors carry only their own keys,
refusal codes come from the host's own record, and a publish
disagreement names the descriptor path.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…l; round 2 README

PROTOTYPE for #314 round 2. A timed-out invocation makes the engine probe
its workerd; an unanswered probe after a 1 s margin kills and respawns
the process (18 ms measured), in-flight invocations roll back and report
handler_timeout. The health poll after spawn runs on wall-clock time so
the server's test layers build under the TestClock again. README gains
the Round 2 section; the patchy-server skill states the transaction.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
PROTOTYPE for #314 round 3. The transaction scope is ready before
admission completes and settles queued callbacks on every fiber exit; the
listener parses before the liveness check; a 40001 anywhere (statement,
commit, or caught by the guest) marks the attempt abort-only and retries
up to three times; the outcome is classified from the commit phase with
the transaction verified before COMMIT, so unknown_outcome is only a
COMMIT whose reply failed; SET LOCAL statement_timeout bounds a callback
in flight; the table handlers used for callbacks run over
Transaction.joiningDatabases on the invocation's held connection, so four
pool slots carry four invocations; declared handler errors are enforced,
refusals are correlated with the refusal the host issued, row validation
requires every column, descriptor lookup uses own keys, and the
modulepreload exemption is gone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d ctx.run

PROTOTYPE for #314 round 3. Generation emits the declared shared-table and
connection client factories into _generated/server.ts and types
ctx.shared / ctx.connections from them; the guest entry instantiates them
over the callback stub; the host gates shared reads to queries and
actions, connections to actions, and serves ctx.run from an action by
re-entering the invocation path under the parent's remaining deadline,
each nested mutation its own transaction and slot. isHandlerError is
structural across the two bundled copies of HandlerError. The
patchy-server skill carries the access table and the declaration
pointers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
PROTOTYPE for #314 round 3. The company pool's size is a config
(PATCHY_COMPANY_POOL_CONNECTIONS, default 4) so the load runs can see
what the pool alone changes; the dev runner passes that, the invocation
bound and the runtime call rate through from its shell; the engine logs
its capability and in-flight registries when they change and the loader's
/healthz reports its invocation map, for the soak's leak check. Numbers
are in the README's Round 3 section.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PROTOTYPE for #314 round 3. patchy.server.<module>.<query>.subscribe
(args, onSnapshot) on the core client with #313's refcounted registry;
the shell's SSE stream and the server's stream routes lifted from #313
and narrowed to tier 2 queries. ServerCall traces the tables each run's
callbacks touched (shared aliases keyed on the owner's table), refuses
anything but a query under a subscription, and wakes by key after a
mutation's COMMIT; tier 1 table writes wake from Runtime.dispatch and
the dev loop wakes version:<patch> on rebind. A wake during a run is
kept and checked against the run's new dependencies. The patchy-server
skill teaches .subscribe and says results are readonly; patchy-preact
points at it. Also fixes step 2's lint and tsc reds.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PROTOTYPE for #314 round 3.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant