Skip to content

Open binary file URL as a card without 415#4832

Open
richardhjtan wants to merge 3 commits into
mainfrom
CS-11147-binary-415-fallback
Open

Open binary file URL as a card without 415#4832
richardhjtan wants to merge 3 commits into
mainfrom
CS-11147-binary-415-fallback

Conversation

@richardhjtan
Copy link
Copy Markdown
Contributor

@richardhjtan richardhjtan commented May 14, 2026

Summary

Opening a binary file URL (an uploaded .png, .jpg, …) as a card — by pasting it into the operator-mode URL bar, or via any code path that routes through getCardInstance — fails today: realm-server returns 415 Unsupported Media Type, or the host "Loading card…" spinner hangs with no surfaced error. Three coordinated changes get the file-meta load path taken end-to-end.

Linear: CS-11147

Changes

  1. Realm-server returns file-meta JSON for binary GETs with Accept: application/vnd.card+json instead of 415. Callers can discriminate via data.type === "file-meta". card+markdown on a binary still 415s — markdown can't represent a binary. Touches the three nonJsonFileExists branches in getCard in packages/runtime-common/realm.ts.
  2. Host stack-item infers type:"file" from the URL extension when none is provided. New isFileDefExtension() helper exported from packages/runtime-common/file-def-code-ref.ts, backed by the existing FILEDEF_CODE_REF_BY_EXTENSION map so the set of recognized extensions stays in one place. Pasting a .png URL into the URL bar now takes the file-meta load path from the first request.
  3. Safety net in store.getCardInstance — if anything still asks getCardInstance for a URL that turns out to be a binary, the file-meta JSON is rerouted through getFileMetaInstance and the in-flight card deferred resolves with that result. No hung spinner, no cryptic error.

Files

  • packages/runtime-common/realm.ts
  • packages/runtime-common/file-def-code-ref.ts — new isFileDefExtension export
  • packages/host/app/lib/stack-item.ts
  • packages/host/app/services/store.ts
  • packages/realm-server/tests/card-endpoints-test.ts — asserts file-meta JSON return for card+json on a binary, retains 415 for card+markdown, retains 415 for PATCH/DELETE

Test plan

  • pnpm lint:types green across runtime-common and host (it is).
  • Manual: paste an uploaded .png URL from a realm into a fresh tab. Pre-fix → hang or 415. Post-fix → the FileDef renders as an image.
  • Same URL opened via code-mode → interact: unchanged (already worked because the stack item carried type:"file").
  • Re-run the 7-day staging log classification after deploy; 415-on-binary count drops to ~0.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts realm card read handling so GET requests for non-JSON files made with card-oriented Accept headers can fall through to the normal file-serving path instead of returning 415.

Changes:

  • Routes missing card JSON index entries for existing non-JSON files through fallbackHandle.
  • Applies the same fallback behavior to card markdown reads.
  • Leaves write/delete card handlers unchanged for binary files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/runtime-common/realm.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

Preview deployments

Host Test Results

    1 files  ±0      1 suites  ±0   1h 49m 54s ⏱️ - 3m 1s
2 712 tests ±0  2 697 ✅ +1  15 💤 ±0  0 ❌ ±0 
2 731 runs  ±0  2 716 ✅ +2  15 💤 ±0  0 ❌  - 1 

Results for commit 6855110. ± Comparison against earlier commit ee6d0b3.

Realm Server Test Results

    1 files  ±0      1 suites  ±0   8m 28s ⏱️ +57s
1 453 tests  - 1  1 453 ✅ ±0  0 💤 ±0  0 ❌  - 1 
1 544 runs   - 1  1 544 ✅ ±0  0 💤 ±0  0 ❌  - 1 

Results for commit 6855110. ± Comparison against earlier commit ee6d0b3.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread packages/runtime-common/realm.ts Outdated
Comment thread packages/runtime-common/realm.ts Outdated
@richardhjtan richardhjtan force-pushed the CS-11147-binary-415-fallback branch from a54b7f5 to 5668884 Compare May 18, 2026 03:34
@richardhjtan richardhjtan changed the title Realm: GET binary file with card Accept falls through to file handler Open binary file URL as a card without 415 or hung spinner May 18, 2026
@richardhjtan richardhjtan force-pushed the CS-11147-binary-415-fallback branch 2 times, most recently from 3a5e473 to 3d547b6 Compare May 19, 2026 10:12
@richardhjtan richardhjtan requested a review from Copilot May 19, 2026 10:19
@richardhjtan richardhjtan marked this pull request as ready for review May 19, 2026 10:19
@richardhjtan richardhjtan requested a review from a team May 19, 2026 10:19
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d547b67bc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/host/app/lib/stack-item.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread packages/host/app/lib/stack-item.ts Outdated
@richardhjtan richardhjtan changed the title Open binary file URL as a card without 415 or hung spinner Open binary file URL as a card without 415 May 20, 2026
@richardhjtan richardhjtan force-pushed the CS-11147-binary-415-fallback branch from 3d547b6 to 9d74e2e Compare May 20, 2026 06:40
richardhjtan and others added 2 commits May 20, 2026 14:44
…handler

A GET request with Accept: application/vnd.card+json (or
.card+markdown) targeting a path that holds a non-JSON file
(typically an uploaded binary like .png) used to return 415
Unsupported Media Type. Callers that produced this mismatch
ended up with a broken image / unusable response.

Route these through fallbackHandle, which serves the file with
inferContentType(...) on the response. Read-only handlers only:
PATCH (3910) and DELETE (4507) still 415 because writing or
deleting a binary as a card is genuinely wrong.

CS-11147

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The existing regression test asserted GET /greeting.txt with
Accept: application/vnd.card+json returned 415. After the fallback
change, GET should serve the file with its native content-type
instead. Splits the test in two: GET is the new positive case;
PATCH/DELETE still 415.

CS-11147

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@richardhjtan richardhjtan force-pushed the CS-11147-binary-415-fallback branch from 9d74e2e to ee6d0b3 Compare May 20, 2026 06:50
A caller that asks store.getCardInstance for a URL the realm-server now
serves as a non-JSON file (file-meta JSON document) used to throw a
confusing "bug: server returned a non card document" error. Reroute
through getFileMetaInstance so the caller transparently gets a FileDef.

The store test is updated to assert this behavior end-to-end: a card
read for a binary URL returns a FileDef and neither bucket caches an
error.

CS-11147

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@richardhjtan richardhjtan force-pushed the CS-11147-binary-415-fallback branch from ee6d0b3 to 6855110 Compare May 20, 2026 07:29
@richardhjtan richardhjtan requested review from a team and lukemelia and removed request for a team May 20, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants