Skip to content

feat(primitives): let tier 2 pages show and download files - #447

Merged
allisonmahmood merged 3 commits into
mainfrom
tier2/408-file-handles
Oct 1, 2026
Merged

allisonmahmood merged 3 commits into
mainfrom
tier2/408-file-handles

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

What changed

Tier 2 handlers could read file metadata, but their pages could not safely display or download the selected files. This adds viewer-bound authorised handles, live redemption, blob URLs and useFileUrl, plus the shell download card selected in #385. Replaced files invalidate old handles; each redemption rechecks access.

Stacked on tier2/407-shared-stores. This PR targets that branch and contains only the file-handle work and download-card refinement. Implements #408 against spec #384.

Closes #408

How it was verified

  • Added or updated coverage for binding, replacement, unsharing, byte limits, URL cleanup and downloads.
  • pnpm test: 1,503 tests across 134 files passed on b85f065.
  • Typecheck, lint, 71 focused regressions and the packed SDK check passed on b85f065.
  • Rebuilt the current branch and reran the hosted Chromium suite after the download-card refinement: all four scenarios passed.
  • Standards and spec reviews completed; corrected the stale README availability statements.

Release impact

  • Breaking
  • Not breaking

Tier 1 name-based file APIs stay unchanged. The company signing key and lookup index use idempotent inventory upgrades; no manual migration or configuration is required.

Implemented with GPT-6 Astra via omp. Download-card refinement by Claude Opus 5.5 via Claude Code.

@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:core Touches the core 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 origin/tier2/407-shared-stores...HEAD, base 9e0544601b5e4b49f69830373f502b941024b79e and PR head 824111b5776752ebf2264d27b8d00fb6b41afbbf, against #408 and the applicable contracts in #384. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The change extends the existing file handlers, runtime byte routes, broker and shared shell components. I found no added future-facing machinery that warrants blocking this issue.

Spec

No merge-blocking intent findings. The reviewed paths cover deterministic viewer/document-bound handles, pointer-before-source-access refusal ordering, live redemption, frame-local URLs, hook cleanup and shell download offers. The selection and re-put/delete rule is documented in the requested skills and product/glossary surfaces. The download card follows the D-1 decision recorded in #385.

Verification performed:

  • pnpm exec vitest run packages/primitives/src/Files.test.ts packages/primitives/src/FilesApi.test.ts packages/primitives/src/QuerySnapshot.test.ts: 34 tests passed across three files.
  • Isolated Chromium smoke using the current download component and shared CSS: three visible offers with overflow disclosure, synthetic-click refusal, dismissal returning focus to the frame, 400 px layout and held-byte cleanup. This was a component smoke, not a hosted end-to-end run.

Summary: Standards 0 blockers, worst issue none; Spec 0 blockers, worst issue none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Opus review

Checked against #408, spec §10 and §15, the D-1 pick on #385, effect-service-conventions and ui-consistency. The core is sound. Minting (HMAC over company, viewer, consuming patch, loaded version and the company-unique object locator), the placeholder that counts handle bytes in the page bound, redemption order (admission, MAC, pointer → not_found, shared access → access_denied), no byte reuse in the SDK or broker, blob-only url(), useFileUrl release and stale-drop, the tier gates in Runtime.ts, and files.redeem staying off the callback allowlist all hold. The two findings below are both in how the change was built. Nothing in the handle contract is wrong.

1. The download card's copy is wrong for every download this PR can make (intent, UI)

packages/serving/src/downloads.ts:87 titles each card ${frame.title} made a file, and ui-consistency/SKILL.md:52 and ADR-0010 write that copy into the spec. D-1 was drawn for #411's generated files. In this PR the only way to reach the card is patchy.files.download(handle), which returns a stored file, and often one from another patch's shared store. So the card tells the viewer the consuming patch made a file it only selected. This is first-party chrome, so the claim has to be true. Pick copy that fits both a stored and a generated file, or leave the title for #411 to decide. Either way, #411 should reuse this card, not add a second one.

The default filename also drifts from tier 1. downloads.ts:114 sets download: name, and name is the full stored name (broker.ts:667, downloadFilename ?? file.name). Tier 1's download(name) strips the name to its last segment (broker.ts:692, file.name.split("/").at(-1)). So logos/company.svg downloads as logos_company.svg on tier 2 and as company.svg on tier 1. filename is also decoded as any Schema.String (broker.ts:36), so "" gets through and the browser falls back to a UUID filename. Decode filename with FileName, and use the same last-segment default as tier 1.

2. Redemption keeps a second copy of the shared-store access rule (method)

packages/primitives/src/Files.ts:418-444 re-implements the check in withSharedStore (Files.ts:229-272): a declared sharedStore use with a matching sharedStoreId, the source found in the same company, and the store still shared in the live inventory. #303 point 2 says reads and redemptions re-check the same thing. Two copies of an authority rule drift, and they have already started to: the redeem copy drops the explicit identity.company.id check, and today only admission covers that. Extract one sharedSourceAccess(binding, patchId, store) helper and call it from both paths, so a later rule change (retire, owner-only sharing) lands in one place.

In the same code, the new live parameter on withCompany (Files.ts:190, passed at :416 and :442) is dead. files.redeem is not on the callback allowlist (runtime/src/CallbackGateway.ts:66-71), so it never runs under a ReadSnapshot. Drop the parameter.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Resolved the review findings in cb2283e, pushed to tier2/408-file-handles.

Fixes

  • Opus — download card: changed the title to “ has a file to download”. It identifies the offering patch without claiming it created a stored/shared file. The existing D-1 card and layout remain the reuse point for generated files.
  • Opus — filenames: tier 2 defaults to the stored name’s last segment, matching tier 1. Explicit overrides use FileName; empty, malformed and oversized names return invalid_request. The hosted browser regression checks a nested Unicode stored name, the actual downloaded filename/bytes, invalid overrides and custom overrides.
  • Opus — authority duplication: metadata/byte reads and redemption now share sharedSourceAccess, including the explicit same-company viewer check. Redemption still checks MAC, then pointer, then source access.
  • Opus — unused flag: removed the withCompany snapshot-bypass flag. The snapshot regression now redeems outside the query snapshot, as the page does; callback tests explicitly refuse redemption for query, mutation and action guests.
  • Updated the UI review spec, ADR-0010, product docs and release-bound files skill. Runtime wire routes, CLI contracts, migrations and global skill wiring are unchanged.

Kept as-is

  • Astra: no blockers reported; no corrective change needed for that review.
  • Kept deterministic viewer/document binding, replacement-before-access error precedence, live reauthorization, URL cleanup and the selected D-1 interactions: both reviews found those contracts sound, and the affected tests still exercise them.
  • Grok: no Grok feedback was present in conversation comments, review bodies or inline comments. Checked all three channels again after CI completed; no new review feedback appeared. This is absence of a review, not a claimed approval.

Verification

  • pnpm typecheck and pnpm lint: passed.
  • Files, FilesApi and CallbackGateway suites passed; the corrected QuerySnapshot suite passed all 7 tests on its final run.
  • pnpm exec playwright test --config playwright.tier1.config.ts test/browser-tier1/server-subscriptions.spec.ts --project=chromium: all 4 hosted scenarios passed.
  • Separate Chromium smoke of the actual download component/shared CSS: visually confirmed neutral copy and exercised dismissal; temporary server and tab closed.
  • All nine checks on cb2283e passed: Node 22/24 tests, lint, Postgres concurrency, Clerk live, CLI smoke, dependency review, image and labels. CI run, image run. GitHub reports no required-check configuration for this stack target; all published checks were awaited anyway.

Ready to merge into the preserved base tier2/407-shared-stores: GitHub reports CLEAN / MERGEABLE, with no unresolved findings. Not merged.

Changes made with GPT-6 Astra via omp.

@allisonmahmood
allisonmahmood force-pushed the tier2/407-shared-stores branch from 9e05446 to 2425926 Compare October 1, 2026 05:02
Base automatically changed from tier2/407-shared-stores to main October 1, 2026 05:32
allisonmahmood and others added 3 commits October 1, 2026 07:32
Each file is a D-1 corner card titled "<patch> made a file" with the
filename in code, its size, Download and Not now. Older files fold into
an "N more files" status-chip. Between 481 and 1364 px the stack sits
above any page state so it never collides with the centred bar; under
480 px the cards are bottom sheets above the page state. The base code
style moves into the shell subset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the tier2/408-file-handles branch from cb2283e to 4c3a86f Compare October 1, 2026 05:32
@allisonmahmood
allisonmahmood merged commit de7b10f into main Oct 1, 2026
9 checks passed
@allisonmahmood
allisonmahmood deleted the tier2/408-file-handles branch October 1, 2026 05:45
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:core Touches the core 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): authorised file handles: minting on metadata, redemption, url/download/useFileUrl

1 participant