Repository navigation
feat(runtime): admit browser calls as the patch viewer - #213
Conversation
Astra reviewReviewed Standards
No separate merge-blocking YAGNI finding: the dispatcher and runtime-log foundation are explicitly requested by #197. SpecNo additional merge-blocking intent findings. The Verification
Summary: Standards: 1 blocker, worst: silently skipped reserved migration on upgrade. Spec: 0 blockers, none. |
allisonmahmood
left a comment
There was a problem hiding this comment.
Code review vs #197
#197 asked for the runtime door: bind a browser call to the loaded version and the viewer, admit only me, log mutations before they run, and leave file routes reserved. That is the product promise behind this PR — a patch never holds a login, never switches acting users mid-page, and every write that later tickets add already has a place to be attributed.
What shipped matches that intent. packages/runtime owns admission, binding, host-supplied dispatch, and runtime_calls. Only me is on the wire. File GET/PUT exist so later tickets walk the same door rather than inventing a second one. The shell, broker, tables, files, and integrations were correctly left to their tickets.
Method
The package cut is the right one. Runtime declares LoadedVersions and never imports Patches; Patches provides the layer; the server wires Runtime.layer({ me }). Admission lives in Runtime.call, not copied across three HTTP handlers, which is what patchy/dev will need to compose later.
That method is sound, with three caveats:
ApiGuardclassifies runtime routes aspublic. Behaviour is correct (skip the bearer guard and the address-level API limiter so Runtime can use 300/viewer/patch). The name is a lie. A later “treat all public/apialike” change would misfire. Aruntimekind that still falls through to the app would be the honest twin ofpublish.- File routes synthesise a
RuntimeEnvelopewithprincipal: null. Header principal is still the authority (body matching is POST-only), so #197’s “principal and wire travel as headers” holds. Ticket 6 will feel this:Handler.runonly hasBindinginR, so PUT bytes are not inargsand cannot be read from the request without widening the handler. Name that split before files land. RequireSession.admission+ capturedviewerContext. Keepsruntime → authwithout importing Companies. Fragile: Auth’s HTML door/deactivation results are now load-bearing for a JSON API and get flattened tosession_expired/access_denied.
Inlining admission into RuntimeApi and dropping Binding / handler() would scatter the invariant, not shrink it. Keep this shape.
YAGNI
The door, me, reserved file refusals, the log table, and every §11 error code are the right size. A few things are not.
Cut
RuntimeLog.recentandruntime_calls_connection_recent_idx. No production caller. Spec §11’s reader is the/companyrecent-calls list, which is the integrations ticket. #197’s done-when isfindby correlation. Delete both; the recent/isolation tests go with them.- File success codec in
RuntimeApi.file(decodeBytes→uint8Array). Reserved routes must admit and refuse. They must not pretend a{ me }handler map can return file bytes. Keep Origin / size / fetch-site refusals. - Write-side
postgres.querySQL truncation inRuntimeLog.begin.Runtime.callnever passessql. The column CHECK already enforces 8 KB. Wait for postgres.
Keep
runtime_callscolumns includingcredential_kind,connection_id,sql,resource— that is the §11 table, not a hidden discovery API. Production writes'session'only.- Per-op
bodyLimit/ config defaults from §12, even though onlymeis admitted. - Two
LoadedVersionsfiles (tag vs layer). Spec, not duplication. Runtime.callas one request lifecycle. Splitting admit/dispatch/log would threadBindingthrough extra functions with one consumer.
LoggedFailure is the one piece that is both extra machinery and a conventions miss: it exists to stamp correlationId onto an error that is already in the channel. Fail with the original OperationError after setting that field; wrap only untagged defects as SourceUnavailable.
Standards
Hard — LoggedFailure (packages/runtime/src/Runtime.ts ~140–157, used ~360–367).
.agents/skills/effect-service-conventions/SKILL.md (Errors): pass through a structured domain error already in the target channel; wrap only unknown/lower-level failures; derive message from the wrapper’s own attributes, never cause.message. LoggedFailure wraps OperationError (already in RuntimeError), re-exposes code / status / retryAfterSeconds from cause, and does return this.cause.message. Every OperationError already has optional correlationId. Expected: fail with the original error after setting that field; wrap only untagged defects as SourceUnavailable.
Hard — packages/sql/CONTEXT.md Migration glossary.
Hit every surface (vocabulary): a ledger change follows through to the owning glossary. The entry still names owners of 1–5 only. Runtime added 0007_runtime_baseline (DEVELOPMENT.md records the reserved 0006 gap). The three migrator spreads were updated; this glossary was not.
Judgement — packages/runtime/src/RuntimeApi.ts success encoding.
ADR-0002: the server encodes /api/* bodies through the api schemas. Failures use encodeSync(RuntimeFailure); success is jsonUnsafe({ ok: true, value }) and never RuntimeSuccess. Inner handler encode is not the envelope schema.
Judgement — packages/patches/src/LoadedVersions.ts.
Effect service conventions: a module that owns construction should export a real make, then layer. Construction is inlined in Layer.effect.
UI consistency: N/A. ADR-0004: N/A (no CLI command). ADR-0009: N/A (platform runtime_calls, no company transaction). Effect imports/layers/it.layer look in line.
Baseline smells (judgement)
- Middle Man — same
LoggedFailurehunk; it mostly delegates tocause. - Duplicated Code — two
decodeWires, different strictness (Runtime.tsrequires a positive int;RuntimeApi.tsisNumberFromStringonly, for file headers). - Speculative Generality —
RuntimeLog.recenthas no production caller.bodyLimitspecial-casestables.*/postgres.*thoughruntimeOperationsis onlyme; those caps are spec §12, so the repo standard wins over the smell.
Spec
(a) Missing or partial
No #197 merge requirement is missing. me on company/public, admission, LoadedVersions, Runtime.layer({ me }), log pending→finish / pending-past-deadline as unknown, HttpApiTest of the stated rules, docs/API.md, CONTEXT.md / CONTEXT-MAP.md / README are present.
File byte I/O is deferred as specified (“ticket 6 fills the handlers”). Reserved PUT/GET share Runtime.call and then invalid_request / not_available_on_public. PUT does not read the raw body (only store / name / Content-Type in args). That is ticket 6, not a hole in #197.
(b) Scope creep
RuntimeLog.recent (and its tests) implement spec §11 “Reader in v1: the recent-calls list per connection on /company”. #197 did not ask for that reader; there is no /company route (correct). Admin/discovery rows (credential_kind: "admin", null patch/version) are the same extra log surface.
Production still wires only me. Test-only tables.insert / postgres.query handlers are for Origin/log coverage, not admitted ops.
(c) Looks implemented but wrong
Nothing material on the admitted me path.
Hardcoded file principal: null does not violate “on the bytes routes principal and wire travel as headers”. Envelope principal: null is only because there is no JSON body. Company admission uses X-Patchy-Principal; body vs header is compared only on POST. Company GET with a matching header principal is admitted (then invalid_request); header null is principal_changed. Wire is X-Patchy-Wire. Content-Type is copied into args, not required (API.md says PUT “requires” it; #197 only says it travels as Content-Type).
0007_runtime_baseline is the coordinated number, not a miss of “migration 0006_runtime_baseline … ticket 8 holds 0005”. Ticket 3 took 0005_company_database_baseline; 0006 is reserved for Integrations.
Tests and surfaces
Admission is covered on both the wrong and right paths for me, including public me null without a session and unknown ops on a public version before principal checks. Handler failure leaves a row that the response correlationId finds; a hang is pending then unknown after the deadline. Historical public versions re-checked as company-scoped on the real server.
Gaps, not merge-blockers: company non-me with principal: null is implemented (principal_changed) but not HttpApiTest’d; unknown version (vs unknown patch) is only on the server suite; successful me is not asserted to leave runtime_calls empty. File routes skip missing-headers / bearer / rate on PUT.
Surfaces: wire, docs/API.md (rendered, not hand-written), migrators (server / dev / vitest), README layout, product.md, patchy-dev-loop, DEVELOPMENT.md are complete. CLI N/A. Stale parentheticals in AGENTS.md and docs/agents/domain.md still list contexts without Runtime. packages/sql/CONTEXT.md as above.
Standards: 2 hard + 3 judgements; worst is LoggedFailure wrapping an in-channel error. Spec: 1 scope-creep finding (RuntimeLog.recent); worst is that unread recent-calls reader, not a miss of #197.
|
Reviewed Grok’s submitted review and Astra’s PR comment against #197 and the source. Fixed
Kept as-is, with reasons
VerificationFix commit:
Latest-commit CI: all seven checks passed — GitHub reports MERGEABLE / CLEAN; no unresolved review threads or additional required branch-protection gates were found. No unresolved blockers. The PR remains stacked on #212 with base |
079fda4 to
ec83a86
Compare
Implements #197 with me-only dispatch and 0007_runtime_baseline.
d18e4f9 to
abcb732
Compare
Patches need structured data that survives new published versions without breaking older open versions. This adds patch-owned tables with additive provisioning at publish, cumulative owner-visible inventory, and seven viewer-bound runtime operations. Incompatible changes are refused before content writes and rechecked under the patch lock. Indexed list queries use storage-column ordering, and reads enforce the 8 MiB limit before materialization. Index-size feasibility checks run at publish only; runtime writes rely on PostgreSQL's own B-tree limit, mapped to `too_large`, without additional CHECK constraints. Stacked on #213 (`sdk/197-runtime`); this PR intentionally targets that branch, not `main`. Files, shared-table uses, and higher tiers remain outside this change. Closes #198. ### Verification - `pnpm lint` - `pnpm typecheck` - `pnpm test` — 461 tests across 48 files - `pnpm format:check` - Actual-handler `EXPLAIN ANALYZE` over 100,000 rows: default pagination uses a backward index scan reading 101 rows; equality lookup uses an index scan reading one row. - Postgres/PGlite contracts cover additive provisioning, old-version writes after omission/index addition, native index-key overflow and rollback, bounded reads, readiness upgrades, and claimed-placement refusals. UUIDv7 coverage checks timestamp, version, variant, and random fields. - Real HTTP + CLI smoke over disposable Postgres during implementation. Implemented with OpenAI GPT-6 Astra in Oh My Pi.
Patches need a browser-only operation path that cannot switch acting users mid-page and records mutations before execution.
Adds runtime admission, loaded-version binding, host-supplied dispatch and durable runtime logging. Only
meis admitted now; file routes are reserved for the Files ticket. Includes0006_runtime_baseline, migration wiring, admission/outcome coverage and updated API/domain documentation.Stacked on #212 (
sdk/196-company-database), which is the base branch for this PR.Closes #197.
Verification
pnpm typecheck,pnpm lintandpnpm format:checkpassed.Implemented with OpenAI GPT-6 Astra in the Oh My Pi harness.