Skip to content

feat(runtime): let patches read shared file stores - #440

Merged
allisonmahmood merged 2 commits into
mainfrom
tier2/407-shared-stores
Oct 1, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
tier2/407-shared-stores

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Patches can share tables, but could not read another patch's file store. This adds read-only access to shared stores on tiers 1 and 2, with live source authorization and recovery after reshare or restore.

Includes shared-store discovery and declarations, CLI add/remove, generated SDK support, local fixtures, and documentation. Query subscriptions track source files and lifecycle changes; fixture reloads invalidate subscriptions even when the last file is removed.

Stacked on tier2/406-fleet-ecs in #439. This PR intentionally targets that branch and contains only the shared-store change.

Closes #407. Implements the shared-store requirements in #384, using the agreed UI from #385.

Verification

  • pnpm test: 134 files and 1,500 tests passed.
  • pnpm typecheck and pnpm lint passed.
  • Chromium verified both tiers, downloads, fresh URL authorization, rollback, served-tier gating, lifecycle recovery, and subscription invalidation/recovery.
  • Real CLI and dev flows verified add/remove and empty-fixture reloads.
  • Standards and spec reviews completed with no unresolved findings.

Implemented with GPT-6 Astra using the omp harness.

@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 area:primitives Patch tables and files area:ui Portal and first-party browser pages, shared rendering and styles size:xl Over 1,000 changed lines; review in multiple passes labels Sep 30, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed a065795 against origin/tier2/406-fleet-ecs using git diff origin/tier2/406-fleet-ecs...HEAD, against #407 and the shared-store requirements in #384. One pass, no subagents; merge blockers only.

Standards

Blocker: bound shared-store Blob URL retention [method]

packages/patchy/src/client.ts:185-197

Every url(name) call creates a new Blob URL and adds it to an append-only Set. Nothing revokes an earlier URL until the entire client closes. A long-lived tool that refreshes a preview or revisits the same files therefore retains another full copy on every read, even when the file is unchanged. The existing owned-file implementation tracks URLs by filename instead.

I exercised the actual createClient/createSharedStore code with a transport supplying one unchanged 1 MiB file: 64 successive url("same-image.png") calls left 64 distinct, resolvable Blob URLs holding 64 MiB. They were released only by client.close().

Keep the fresh broker authorization on every request, but give URLs bounded ownership, such as per-name replacement with revocation of superseded URLs, rather than retaining every result for the document's lifetime. Do not fix this by returning cached bytes without the required live check.

Spec

No blocking intent or YAGNI findings against #407. File handles and staged uploads belong to later tickets, not this PR.

Summary: Standards 1 blocker, unbounded Blob retention; Spec 0 blockers.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Opus review

1. Dev stores every shared-store fixture as application/octet-stream (correctness, dev loop)

packages/patchy/src/devResources.ts:250 loads each file under fixtures/shared-<alias>/ with a hard-coded contentType: "application/octet-stream". That type is what dev then serves back. list/stat report it, and tier 1 url(name) builds its blob from it (packages/patchy/src/client.ts, createSharedStore.url).

What breaks: the skill's own example (packages/sdk/skills/patchy-shared-stores/SKILL.md, tier 1 patchy.shared.assets.url(...) under logos/, and logos/company.svg in server.types.ts) renders nothing in dev for SVGs. <img> does not sniff SVG from an application/octet-stream blob. Any code that branches on contentType (show images, pick a viewer) also sees every fixture as opaque bytes in dev but real types in production. Owned-store dev files keep the type the page supplies, so only shared-store fixtures diverge. The agent has no workaround either: neither the fixture README nor the skill gives a way to set a fixture's type.

Fix: derive the type from the file extension with a small map (svg, png, jpg, gif, webp, pdf, txt, csv, json, html), falling back to application/octet-stream. Mention it in the generated fixture README, and add a dev test that checks a .svg fixture's stat().contentType.


Checked and found sound:

  • Authority on both tiers. Tier 1 shared.files.* goes through runtime admission. A tier 2 consumer document or an older tier 1 document gets server_required. Tier 2 kinds are gated in CallbackGateway.allowed: queries get list/stat, only actions get bytes, mutations get nothing. The live viewer is reauthorized through viewerAuthority, and withSharedStore rechecks liveness and cumulative sharing on every read, url and download.
  • Reverse states. Unshare, retire and delete refuse through the shared dependantRows query, which now covers stores. putStore advances the store revision and adds a store: wake. Publish advances the lifecycle revision. Omission and rollback leave sharing alone. Restore recovers consumers, and binding is by patch id, so a reused name never rebinds.
  • Subscriptions. Dependencies are recorded before access checks, the store:/patch: resume keys are allowed, and the query snapshot reserves authority for store declarations.
  • Lock order. Liveness is read on the platform database before the company lease. Shared bytes use the source's per-name file lock, with blob I/O outside the lease.
  • The idempotent inventory upgrade is tested against an already-initialised database. No platform migration is needed.
  • Surfaces: docs/API.md, ADR-0004, the CLI README, the global skill with a matching lock hash, the new project skill with patchy-loop cleaned up, the glossaries, docs/product.md and the portal copy.

@allisonmahmood

allisonmahmood commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner Author

Resolved both review findings in 9e05446.

  • Astra: unbounded shared-store Blob URLs (finding). The client now owns one URL per filename and revokes its predecessor after a successful fresh read. Different filenames remain independent; closing the client revokes every retained URL. Added coverage for replacement, concurrent reads, authorization refusal and close cleanup.
  • Opus: fixture media types (finding). Dev fixtures now infer common image, document and text media types from case-insensitive extensions. SVG list/stat/get metadata is covered alongside unknown-extension fallback and preserved fixture bytes. Updated the generated fixture README, CLI/dev docs and project skill.
  • CI cli-smoke: migrated stale packed-CLI discovery assertions from not_shareable to not_shared and included the current shared, declarable, reason and hint contract fields. The complete packed CLI smoke now passes locally.

Kept intentionally: every URL call still goes through broker authorization; a failed read leaves the previous URL intact. Unknown extensions remain application/octet-stream rather than sniffing or changing bytes. Existing authored fixture directories remain untouched. File handles/staged uploads stay outside this PR, as the review noted. No finding was dismissed. Review bodies and inline comments were empty when triaged; both findings were conversation comments.

Verification: both regressions failed before their fixes; all 35 affected tests, typecheck, lint, packed CLI E2E and packed Preact E2E pass. A real isolated patchy dev session in Chromium rendered the uppercase-extension SVG at 240×80 with image/svg+xml; three refreshes retained one usable Blob URL and client close left zero. Unknown-extension metadata remained application/octet-stream. Disposable services, browser and fixture repo were cleaned up.

Final readiness: all nine reported checks pass on 9e0544601b5e4b49f69830373f502b941024b79e: Node 22 and 24 full suites, CLI smoke, lint/typecheck/format, live Clerk, Postgres concurrency, image, dependency review and labels (CI run). Node 24 initially hit two timing failures and passed when only that job was rerun, with no code or deadline changes. The unrestricted local full suite also hit timing failures; all four affected files passed with one worker (261 tests), and the inherited Fleet scenario passed independently on Node 24.20.0. No timeout or assertion was weakened.

Final recheck found no new conversation feedback, review bodies or inline comments. GitHub reports no configured required checks; every reported check is green. The PR is open and mergeable into its requested base, tier2/406-fleet-ecs. No remaining review blocker; no merge performed.

Base automatically changed from tier2/406-fleet-ecs to main October 1, 2026 05:02
@allisonmahmood
allisonmahmood force-pushed the tier2/407-shared-stores branch from 9e05446 to 2425926 Compare October 1, 2026 05:02
@allisonmahmood
allisonmahmood merged commit 478e70f into main Oct 1, 2026
15 of 16 checks passed
@allisonmahmood
allisonmahmood deleted the tier2/407-shared-stores branch October 1, 2026 05:32
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:primitives Patch tables and files area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles size:xl Over 1,000 changed lines; review in multiple passes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(primitives): shared file stores on both tiers and patchy add shared-store

1 participant