Skip to content

feat(primitives): read shared tables across patches - #216

Merged
allisonmahmood merged 2 commits into
mainfrom
sdk/200-shared-tables
Sep 12, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
sdk/200-shared-tables

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Patches can own tables, but cannot yet read another patch's shared data without copying it.

Admit shared-table declarations and resolve them to stable source identities. Shared reads reuse the source's inventory definitions and indexes, checking access and sharing on every call. Publishing warns about older schema stamps, refuses unavailable sources, and reports affected consumers when a table is unshared. Omitting a table or rolling back its source does not change sharing, and deleting/recreating a patch never rebinds consumers.

Stacked on #215 (sdk/199-files). This PR targets that branch and should merge after it.

Closes #200.

Verification

  • Full offline suite: 498 tests passed across 50 files; post-review focused suites: 127 tests passed.
  • Typecheck, lint, and formatting passed.
  • Actual PGlite smoke covered indexed pagination, ordered dangling IDs, source omission, unshare denial, rollback immunity, preserved consumer rows, and stable source identity.
  • Standards and Spec reviews completed; all three findings addressed, including CLI refusal recovery and the file-mode inventory guard.

Implemented with GPT-6 Astra in Oh My Pi.

@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:l 501-1,000 changed lines labels Sep 10, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed git diff origin/sdk/199-files...HEAD: base c00628b0c78b6f4b47f6e8188fb7ceb5f7225377, PR head b4386d9d181b89d12fa1c2f21e08edf12fd76bba, against issue #200. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The shared operations reuse the existing row-read implementations and inventory authority; catalog, builders and generation remain with their owning tickets.

Spec

No merge-blocking intent findings. Checked declaration admission and refusal, stale-revision warnings, source-indexed reads, whole-call access denial, ordered/dangling getMany results, cumulative definitions after omission, unshare counts, rollback independence and stable identity after deletion/recreation.

Verification: 69 tests passed across five focused offline suites: API schemas, Content, PatchesApi, TableOperations (Postgres and PGlite), and Server. No production or live development instance touched.

Surface checks covered wire/server/CLI/docs, vocabulary/product and company-resource locking. No migration, seed, package-layout or rendered-page changes required propagation.

Summary: Standards: 0 blockers (method 0, YAGNI 0); Spec: 0 blockers (intent 0). No worst issue on either axis.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Code review — PR 216 vs #200

Stacked on #215 (c00628b...b4386d9). Reviewed along the repo's two axes (Standards / Spec) plus the method and YAGNI passes requested on this review. Seven read-only agents; this comment is the aggregate.

Issue 200's intent: admit sharedTable declarations by source patch id, resolve them to a stable identity, let consumers read (never write) through shared.* using the source's inventory definition and indexes, re-check openability + inventory.shared on every call, warn on a behind stamp, refuse an unavailable source, report declaring-patch counts on unshare, and never rebind after delete/recreate or change sharing on omit/rollback.

That is what landed.


Standards

Documented standards — no hard violations. Effect service layout / namespace imports / catchTags / yield* deps, ADR-0004 (patch_not_openable → 422, exit 2, attempt cleared, skill hash refreshed), ADR-0009 (LoadedVersions before the company lease; Inventory.read already takes the source patch lock), glossary (declaration / shared table), and the required wire → CLI → docs/ADR → CONTEXT mirrors all hold. Shared-table reads using the inventory lock rather than a file-style name lock is what ADR-0009 now says; that overrides the smell.

Judgement — Feature Envy + Speculative Generality (packages/primitives/src/Tables.ts, packages/patches/src/Patches.ts)

Tables.diff / provision take declaringPatches?: ReadonlyMap<string, number> only to format an unshare warning:

declaringPatches === undefined
  ? `\`${table}\` is no longer shared.`
  : `\`${table}\` is no longer shared; ${declaringPatches.get(table) ?? 0} declaring patches are affected.`

The count is platform patch_versions data (declaringPatchRows in Patches). Plan.sharing already names the tables whose flag flipped; provision always passes a Map (empty if every defined table stays shared: true). The undefined string never ships on publish. Preflight/validate call diff without the map and discard warnings.

Expected: keep the count in Patches; have Tables emit sharing changes; format the caller-visible warning once at record. Require the map or drop the optional.


Spec

No spec-axis findings.

(a) Missing or partial — none. sharedTable uses are admitted and resolved by patch id to <patchId>/<table>; publish refuses with patch_not_openable unless the source is live, same-company, and inventory-shared; a behind stamp warns only. shared.get|getMany|list reuse the owned read surface and source indexes, resolve alias through the loaded manifest, and fail the whole call with access_denied (including empty getMany) when the source is unopenable or unshared, while authorized getMany keeps order and nulls dangling ids. Unshare reports declaring-patch counts (retained versions included); omission and rollback do not change sharing; delete-and-recreate does not rebind. Definition lookup (Patches.sharedTable, runtime reads) uses inventory, not the active manifest. Wire, product, and glossary surfaces match.

(b) Scope creep — none that the issue did not require. File-mode detection, optional LoadedVersions.find, and CLI patch_not_openable attempt-clearing are consequences of admitting declarations and the existing payload-refusal contract. Ticket 10 catalog/generate endpoints are not added.

(c) Implemented but wrong — none. Sharing authority is the live inventory shared flag; public/anonymous primitive access is still refused; writes stay off shared.*.


Method

This is the right method, and it is small.

Identity lives on the consumer version (uses[alias] = { kind, patchId, table, id, revision } with id = patchId/table). Sharing lives as an inventory boolean on the source table. Row SQL is the owned-table engine with a different admission wrapper (withSharedTable, ~45 lines), not a second catalog or binding registry.

Publish verifies the id formula and that the source is live / same-company / inventory-shared; it does not rewrite or rebind. Runtime re-checks the formula, LoadedVersions.find (liveness, before any company lease), same-company, and the live shared flag under the source patch lock, then runs the same getRow / getRows / listRows against p_<sourcePatchId>.<table>. Schema always comes from inventory, so omitting the table from the source's active manifest does not remove access.

shared.* with alias is required by spec §11; folding it into tables.* would only blur the wire. Unshare, omit, rollback, and delete/recreate are one gate with different outcomes, not scattered special cases. Source “openability” is find() (not deleted/disabled/expired) plus company match — that is “can open” under today's company/public scopes; a later private scope would need a source-audience check in this same wrapper.

One lock note, not a defect: sharing is snapshotted under the source lock, the lock is dropped, then the SELECT runs. An unshare can commit in that window and the in-flight read still returns rows. Later calls fail. That matches ADR-0009's “then the same indexed row operations,” the same TOCTOU as file blob I/O.


YAGNI / beautiful code

Runtime reads are the honest model: two resolvers, one SQL path. Do not unify owned binding.manifest.tables with source inventory.

Taste, not merge-blockers:

  1. declaringPatches? on Tables — same as the Standards judgement. The unshare count is in-scope; the optional formatting hook on the provisioning service is not. Format the warning in Patches.
  2. Patches.sharedTable returning a definition — issue 200 does require that catalog/generation/fixtures read the source inventory, so a single inventory lookup is the right seam for ticket 10. The production publish path only uses id and schemaRevision. Keep the helper; drop the comment that talks as if generation and fixtures already exist (Patches.ts:313).
  3. Stamp-behind warning (Patches.ts:827-828): Shared table \alias` was generated at revision … Run patchy refresh.Schema revision is not a release,aliasis not the shared table's identity, andpatchy refreshis ticket 11. Warn with sourcepatchId/table` and the two revision numbers; don't name a command that isn't on this CLI yet.
  4. TableQuery 5-arg callback — every op takes patchId, name; only list uses them. Resolvers returning a handle would read more clearly than lambdas that ignore trailing args. Not worth a rewrite on this PR unless you're already touching it.

TableOperations.ts got moderately harder from callback threading and hoisting listRows, not from a parallel stack. That cost is acceptable for sharing one SQL path.


Surfaces the two axes didn't own

Hit-every-surface is otherwise complete (wire, CLI refusal recovery, ADR-0004, skill + skills-lock.json, product.md, both CONTEXT glossaries, README). Two stale mirrors:

  • docs/DEVELOPMENT.md:504-506 still says /api/runtime/call admits me and the seven tables.* operations, and that a public version “refuses tables.” Should name shared.* and public-version denial of shared-table access.
  • CONTEXT-MAP.md:11 Runtime one-liner still “table/file operations”; the Primitives line was updated, this was not.

Standards: 1 judgement (worst: declaringPatches? warning hook on Tables). Spec: 0 findings. Method is the smallest one that makes the behaviour unsurprising. YAGNI: 3 nits, none of them the wrong architecture.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed the Astra and Grok comments. Neither found blockers. Cheap nits addressed in d871930.

Fixed

  • Removed declaring-patch count parameters and sharing-warning formatting from Tables.diff/provision. Tables reports sharing changes; Patches owns platform counts and warning text, querying counts only when a table becomes unshared.
  • Stale-stamp warnings now identify the stable source patchId/table and both schema revisions. Removed advice to run the not-yet-available patchy refresh command.
  • Corrected the shared-metadata helper comment to describe today's cumulative live inventory metadata rather than imply future consumers exist.
  • Updated the runtime mirrors in docs/DEVELOPMENT.md and CONTEXT-MAP.md to include shared reads and public-access denial.

Kept, with reasons

  • Kept the shared-metadata helper: it exposes real cumulative source metadata and remains useful for the planned consumers; only its misleading comment needed changing.
  • Kept the existing read callbacks and separate owned/shared resolvers over one SQL read engine. A handle refactor would broaden this round without fixing a defect; the two resolvers enforce different authorities.
  • Kept the settled lock scope: an already-admitted read may finish after unshare, while subsequent calls deny access. No new platform-pool dependency or lock-order change.

Verification and disposition

  • Local: 69 tests passed across Tables, TableOperations, PatchesApi, and Content, covering provisioning, shared-read lifecycle, stale revisions, warning counts, replay, and rollback. Typecheck, touched-file ESLint, and formatting passed.
  • Latest-head CI is green: Node 22/24 tests, lint, CLI smoke, live Clerk, dependency review, and label all passed. GitHub reports no configured required-check subset; all seven reported checks passed.
  • No newer review feedback or unresolved blockers. GitHub reports MERGEABLE/CLEAN. Ready to merge in stack order; this PR still targets sdk/199-files (feat(primitives): add persistent files to patches #215). Not merged.

Changes and verification by GPT-6 Astra in Oh My Pi.

Admit shared-table declarations, resolve cumulative source inventory at publish and on runtime reads, and report live declaring patches when sharing is removed.

Closes #200
@allisonmahmood
allisonmahmood merged commit 8b03bc4 into main Sep 12, 2026
7 of 14 checks passed
@allisonmahmood
allisonmahmood deleted the sdk/200-shared-tables branch September 12, 2026 11:57
allisonmahmood added a commit that referenced this pull request Sep 12, 2026
Company admins have no way to connect Postgres databases or publish
patches bound to their discovered schemas.

Adds secure company connections with encrypted credentials, verified TLS
and public-address checks, immutable schema discovery, and publish-time
connection/revision checks. The company pages cover the full
administration lifecycle. Postgres operations remain deferred to ticket
9.

Stacked on #216 (`sdk/200-shared-tables`); this PR targets that branch.
Includes the page polish in `df56d39`. Uses migration
`0007_integrations_baseline`, after the runtime baseline.

Closes #201.

Verified on the complete branch, including the page polish: `pnpm test`
(540 tests), `pnpm typecheck`, and `pnpm lint`.

Implementation and PR prepared with GPT-6 Astra in Oh My Pi; page polish
contributed with Claude Fable 5.1.

---------

Co-authored-by: Claude Fable 5.1 <[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:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(primitives): shared tables, read-only across patches

1 participant