Skip to content

Publish for a patch repo: build, manifest, tier check, provisioning order and wire versions #182

Closed

Description

@allisonmahmood

Question

What happens between patchy publish in a repo and the new version serving? To decide: who builds (the CLI runs the repo's Vite build; the server never executes uploaded code or config); the manifest format and its version, produced by executing patchy.config.ts locally; the tier check against the tree (script present means at least tier 1; server code means at least tier 2, refused here); the order of operations so nothing serves before its shape exists (validate manifest, diff schema against the current revision, refuse destructive changes, provision additively under a per-patch lock, upload the tree, then advance the pointer); what a failed provision leaves behind; how the runtime wire protocol version is recorded on the version so a future breaking change can find affected versions; and what happens to today's single-file patchy upload <file> path and existing tier 0 patches.

Context: Tables are real Postgres tables, additive-only on publish, Latest-only tooling, a stable wire contract for deployed patches, the tables surface decision, and the init prototype's publish path.

Recommendation: publish is one API call with the manifest and the tree, provisioning is idempotent per schema revision, and upload <file> survives as the tier 0 no-repo path until init --tier 0 exists.

Activity

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

    @allisonmahmood
    OwnerAuthor

    Evidence to build on from Research: a Postgres database per company on Azure, pooling and budgets: run a patch's additive DDL under pg_advisory_xact_lock(stablePatchKey) inside the same company transaction as the schema inspection and the revision ledger update, so competing publishes serialise and a failed provision rolls back whole. CREATE INDEX CONCURRENTLY cannot join that transaction; ordinary CREATE INDEX blocks writers for its duration, which is acceptable at this scale and should be said in the spec.

  3. allisonmahmood commented on Sep 9, 2026

    @allisonmahmood
    OwnerAuthor

    Inherited from What init pulls from the server, resolved 2026-09-09: patchy is one package at one release, pinned as one devDependency; publish checks the pin against the instance's current release before typecheck and build and refuses below it; the manifest carries the release and the generated declaration stamps, and publish refuses stale generated files; first-publish recovery of patchy.json (provisioning succeeded, the write failed) and release races across the non-transactional steps are this ticket's to decide; the release is recorded on the version the way the wire version is.

  4. allisonmahmood commented on Sep 10, 2026

    @allisonmahmood
    OwnerAuthor

    Resolved 2026-09-10 with Allison. One round of seven questions plus two follow-ups, each pressure-tested with astra in two rounds first (its review is summarised at the end). Everything here is on top of the decisions the ticket cites, none of which moved except one reinterpretation on the tables decision, called out below.

    The bundle

    One self-contained HTML file per version: the CLI runs the repo's Vite build with the single-file plugin, assets inlined. Same object-per-version content store as today, one content response carrying the sandbox CSP, one URL for the frame. The build fails loudly when Vite leaves anything outside the HTML (a public/ asset, a dynamic import, a worker) and reports the largest contributors when over the cap. The cap is on the final HTML bytes, separate from the request cap; a spec value, starting at 10 MiB for tier ≥ 1.

    Into later tiers (Allison's question): the bundle is only ever the client half of a version. Tier 1 "dynamic" is script in the frame reaching Patchy through the broker; the delivered file is still static. From tier 2 a version gains a second immutable artifact beside it, the server bundle built from server/ by the same CLI, described in the manifest as handler descriptors, never as functions imported into browser config. Page serving does not change; each tier adds an artifact rather than changing this one. Routes inside a patch are client-side under the shell path the frame prototype settled. A multi-file tree is a later widening the manifest can name; not needed until a real workload needs independent asset delivery.

    One verb, one route

    patchy publish [file] replaces patchy upload; POST /api/publish replaces /api/uploads. Allison's rule: with a file, it is a static HTML page (verify against the safe-HTML policy, publish, manifest synthesised as tier 0); without one, it must be a repo created by patchy init, at any tier, and the repo process runs. upload is removed, not aliased (astra: a hidden alias is migration debt); the skills, README and ADR-0004 move in the same change. Existing versions are backfilled as tier 0, true by construction since every one passed the policy at upload.

    • File mode never reads patchy.json; it targets the file's cached patch or --patch, as today, and never falls back to file mode because a repo's build or config failed.
    • File mode is refused onto a patch that has any inventory (tables or file stores): has_primitives, "this patch has tables; publish from its repo". Checked against the cumulative inventory, not the current version's manifest, since a rollback may sit on a version that predates them.
    • A file-born patch is adopted into a repo by putting its id in patchy.json; ownership is checked as it is today (an id that is not yours answers 404).
    • An omitted scope preserves the patch's sharing, as today.

    The manifest and the version record

    { manifestVersion, release, tier, tables, files, uses }, produced by executing patchy.config.ts locally; uses carries the resolved binding ids and the revision stamps from the generated directory. The server accepts exactly the current manifest version (free, since tooling is exact-current) and keeps a reader for every manifest version a stored version still carries, or migrates them in place, because rollback and old-version serving read stored manifests and never pass through admission again.

    The version row records tier, release, manifestVersion, wireVersion, schemaRevision and the manifest JSON, beside what it records today. The wire version is stamped by the server from what it knows that release speaks, never trusted from the client; it holds because the CLI that built the bundle is the SDK inside it (one package, one pin, and the release check covers the executing CLI). "Find every version a wire break affects" is one query on wire_version. The running bundle also identifies its wire version to the broker at bootstrap; that is Tier 1 serving's.

    Tier is about code; the manifest lists what is used

    The tier check is about code only, split as the prototype proved: the CLI sees the tree (server/ means tier 2, refused until it exists; script means at least 1), the server sees the bundle (a tier 0 bundle must pass the safe-HTML policy). Claiming more than the tree needs is fine. A tier 0 repo may define and provision tables; primitives are orthogonal to tier, as docs/product.md says.

    The manifest lists what this version uses, not everything the patch ever made (Allison). This reinterprets one line of the tables decision: "dropping a table, column, index or store is refused" now reads as nothing is ever physically dropped; omitting one from the config is allowed and reported, never silent and never destructive:

    • Table or file store omitted: it stays in the inventory with every row and byte; this version cannot reach it; publish prints "notes is no longer defined; its data is kept and this version cannot reach it." Redefining it later with a compatible definition makes it reachable again with no DDL. Old open tabs keep reaching it through the version they loaded. Allison: "warn the agent to be aware, but if a patch used something it doesn't need to anymore we shouldn't break things."
    • Column omitted: allowed and reported when the column is optional or defaulted (the column stays, new rows fill it by default); refused when it is required, since the new bundle's inserts would fail, with the fix "keep the column".
    • Index omitted: the index stays; reported. A unique index still enforces; reported as "uniqueness on x still applies".
    • Rename is therefore an add plus a reported omission, and the message is the safety rail against the classic agent mistake (an empty memos beside a quiet notes). Astra proposed silent omission, withdrew it on that footgun, and now agrees the message is the model. The CLI must never restore omitted definitions on the agent's behalf, which would suppress the message.

    Refusals otherwise stay exactly as the tables decision lists them, before any DDL runs.

    Order, lock, and what a failure leaves behind

    CLI: release check → execute the config into the manifest → compare its stamps with the generated directory (stale → refuse, "run patchy refresh") → typecheck → build → evident tier against the declared tier → write the publish key → call → write the id to patchy.json on a create → clear the key → print URL, tier, version, what was provisioned and what is now unused.

    Server: auth and per-minute limits → release check → manifest schema → tier check against the bundle → resolve declarations (connection connected and snapshot revision current, refuse otherwise; shared table exists and is shared, refuse otherwise; stamp behind, warn) → diff against the inventory and refuse not_additive before any DDL → upload the bytes under a fresh version id → one platform transaction with a deadline that locks the patch row FOR UPDATE (on a create it inserts the row in that transaction, invisible until it commits with the version) → inside it, the company transaction: pg_advisory_xact_lock on the patch, re-diff against the inventory, DDL one statement per call, inventory rows, schema revision bumped only if something changed, commit → version row, create accounting and the pointer commit together → respond. Rollback and delete take the same row lock, so publications are serialised whole, not only their DDL (closes the race where an earlier publish activates after a later one).

    Failures. Before the bytes: nothing happened. Company transaction fails: DDL is transactional, nothing happened; the unreferenced object is swept. Platform commit fails after the company commit: on an update, the tables exist and the inventory says so, so the retry's diff finds nothing to do and records a version; on a create, a namespace exists for an id no patch row will ever name (ids are random, never reused, and a retry mints a fresh one), and a sweep drops namespaces older than a day that have no patch row, safe because the platform transaction's deadline is far below a day and the check runs on the primary with a fresh snapshot. No pending-publication table, no journal. The bytes are uploaded before the transaction opens, so a slow upload never holds the lock.

    The publish key

    The transaction cannot tell the CLI "failed" from "committed but the acknowledgement never arrived" (Ctrl-C, laptop sleep, an agent's command timeout, a proxy reset). On an update a retry would make a harmless duplicate version; on a create it would make a second patch and the agent never learns the first one's id. So, the smallest key: the CLI writes a per-attempt key under .patchy/ before sending and clears it once the id is in patchy.json; the server stores the key and a payload digest on the version under a unique index per user; a replay with the same key returns the original result without re-activating; the same key with a different payload is publish_key_conflict. Allison: hard patch limits are going away because companies pay for their patches, and the key is exactly so they do not pay for a retry's mistake. Astra argued for the key; I had leaned on yagni until the agent-timeout case.

    The company database

    Created lazily, on the first publish that needs company-database resources (tables or file stores, not a tier number), never at company creation. The platform row per company from the pooling research (serverId, databaseName, placementVersion, status) is the claim: inserted first so concurrent first publishes serialise on it; ready means created, owned, granted and the inventory schema initialised; an interrupted create resumes from the row rather than trusting a database of that name in pg_database. One more non-transactional step on some first publishes, covered by the same retry rule.

    Stated, following from earlier decisions

    • A bundle resolves its table and connection names through the manifest of the version the frame loaded, which holds immutable resolved binding ids, with live authorisation on every call, including the already-decided failure when a declaration is removed. Version pinning never resurrects revoked access.
    • File store contents are keyed by patch and store, never by version. Version bundles are keyed by version. Rollback and version cleanup never touch stored files. Provisioning a store is an inventory row, no bucket, so no extra recovery boundary.
    • The inventory lives in the company database, committed with the DDL; moving it to the platform database would lose that atomicity without fixing acknowledgement.

    Wire, for the spec

    POST /api/publish with { manifest, html, patchId?, scope?, publishKey, metadata }, answering PublishCreated (201) or PublishUpdated (200) with provisioned (tables, columns, indexes, stores), unused (what this version no longer defines) and warnings. Refusals keep { ok: false, error } and gain code: release_mismatch, invalid_manifest, tier_mismatch, stale_generated, connection_not_connected, patch_not_openable, not_additive (each object, change and fix listed), has_primitives, publish_key_conflict, beside today's 401, 404, 413 and 429. The patch_versions table gains tier, release, manifest_version, wire_version, schema_revision, manifest, publish_key and payload_digest.

    Astra's review, in short

    Two rounds. Agreed on single-file with the asset check and a byte cap on the final HTML; on one verb and no alias; on server-stamped wire versions with readers kept for stored manifests; on tier 0 provisioning; on the long platform transaction with a deadline; on lazy database creation with a claim row and a readiness definition; on the loaded-version resolution rule and the store-contents lifetime. Disagreed and moved: silent omission (withdrawn on the rename footgun; Allison then chose reported omission). Disagreed and kept: it wanted the publish key and age-plus-absence not to be the only orphan evidence; both adopted. Its remaining items (public tier 1 identity, frame-to-version binding at the broker, bootstrap wire identification) go to Tier 1 serving.

    What other tickets inherit

    • Tier 1 serving: the frame is bound to its patch and loaded version by the shell, never by frame-supplied ids; the bundle identifies its wire version at bootstrap; whose identity authorises data access on a public tier 1 patch (scope: public must not implicitly grant table or connection access); historical version URLs serve with that version's tier and CSP.
    • Write the SDK spec: everything above; the glossary's Upload contract becomes the publish contract and gains manifest, inventory, bundle, publish key, unused definition; the CLI's Hit every surface entries (README, ADR-0004, the patchy skill and its lock hash) for the upload → publish rename; the tables decision's refusal list amended as above.

    Side note for the map: Allison said hard patch quotas are going away because companies pay for their patches. Billing is out of this map's scope; the live-patch quota stays as built until billing is designed.

    Graduates two fog entries on the map: today's single-file tier 0 uploads and provisioning inventory and publish recovery.

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

Metadata

Metadata

Labels

wayfinder:grilling

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions