Public: anyone can read this; the crew can change it.

Look pictures (a person's attachments) archive to the BlobStore #16733

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A person's attached looks now go to the BlobStore instead of the data dir. They are served from the store after the existing access check, and deleted with their rows. It's pushed.

Notes

opened this

A person's attached looks now go to the BlobStore instead of the data dir. They are served from the store after the existing access check, and deleted with their rows. It's pushed. The new tests, tsc and the tests around looks pass. Two tests I ran fail:

  • test/mcp/forks.test.ts: "the private fork's owner sees it" fails with and without my change.
  • The Chromium capture test: this sandbox has no browser, so the real-capture test in test/looks.test.ts can't run here.

I didn't run the whole suite, because scripts/fast.ts named 3,583 files (exit 0), too broad to run here. I ran the tests for this change plus the look, pull-look, MCP and build-shot suites.

What changed

  • Writing: attachLook is now async. It writes the picture with put(key, blob) under looks/<app>/<env>/<sha256>.<w>x<h>.<ext>, and the row's path is blob:<key>.
    • The store is the bucket when S3_* is set, otherwise <data>/look-blobs.
    • The picture's pixel size is in the key's name, so drawing a pull never reads the store.
    • The API and MCP callers now await.
  • Serving: lookImage runs mayFetchLook first, so only writers get an attached picture.
    • On a bucket it then redirects to a 60 s presigned GET with no-store.
    • On a directory it streams the bytes with the same ETag and cache rules as before.
    • Anyone refused gets 404 before anything is signed.
  • Deleting:
    • deleteLooksAndObjects removes the rows and then the objects. The environment-forget and look-pruning paths in service.ts call it.
    • An object is kept while another row still names it, because identical bytes attached twice are one object.
  • Pins: picking looks for a pin reads their bytes through lookBytes, which reads the store or the disk.
  • Docs: docs/BLOBS.md describes the new storage.
  • Tests:
    • New test/look-archive.test.ts covers write by content key, serve (writer 200, stranger 404), and a presign test that never signs for someone the app doesn't let in.
    • It also covers delete through a dirStore, including a shared object that survives one row's deletion.
    • In test/attach-look-refusals.test.ts, the two same-byte attachments are now one object. That test was wrong for the new design, so I changed it.

What I chose not to do

  • Existing attachments: they are not migrated. They stay on the disk and are still served from there, and nothing writes them to the store yet.
  • The forge's own captured looks: they stay files, since they are retaken and aged out by the sweep.
  • Content key: it includes the app and environment, so deletion stays scoped to one environment.

How to try it

  1. As a writer on an app's open pull, POST /api/v1/repos/:owner/:name/pulls/:n/looks with {width, says, image} (base64).
  2. Open the returned url as that writer. A signed-out visitor or another user gets 404.
  3. Close the pull and the object is gone from <data>/look-blobs.

bun test test/look-archive.test.ts runs the new tests.

[
  {"go": "POST /api/v1/repos/:owner/:name/pulls/:n/looks as a writer on a private app's open pull", "look": "201 with a url under /looks/pr-<n>/<head>/…", "expect": "the writer fetches the picture (200, image/png); a signed-out visitor and a non-member get 404"},
  {"go": "the pull page /:owner/:name/pulls/:n?looks=all", "look": "the attached picture's figure", "expect": "it has width and height from the start, so nothing shifts when it loads"}
]

🤖 Generated with Claude Code

Closes #4546

4 earlier comments
commented

A person's attached looks now go to the BlobStore instead of the data dir. They are served from the store after the existing access check, and deleted with their rows. It's pushed. The new tests, tsc and the tests around looks pass. Two tests I ran fail:

  • test/mcp/forks.test.ts: "the private fork's owner sees it" fails with and without my change.
  • The Chromium capture test: this sandbox has no browser, so the real-capture test in test/looks.test.ts can't run here.

I didn't run the whole suite, because scripts/fast.ts named 3,583 files (exit 0), too broad to run here. I ran the tests for this change plus the look, pull-look, MCP and build-shot suites.

What changed

  • Writing: attachLook is now async. It writes the picture with put(key, blob) under looks/<app>/<env>/<sha256>.<w>x<h>.<ext>, and the row's path is blob:<key>.
    • The store is the bucket when S3_* is set, otherwise <data>/look-blobs.
    • The picture's pixel size is in the key's name, so drawing a pull never reads the store.
    • The API and MCP callers now await.
  • Serving: lookImage runs mayFetchLook first, so only writers get an attached picture.
    • On a bucket it then redirects to a 60 s presigned GET with no-store.
    • On a directory it streams the bytes with the same ETag and cache rules as before.
    • Anyone refused gets 404 before anything is signed.
  • Deleting:
    • deleteLooksAndObjects removes the rows and then the objects. The environment-forget and look-pruning paths in service.ts call it.
    • An object is kept while another row still names it, because identical bytes attached twice are one object.
  • Pins: picking looks for a pin reads their bytes through lookBytes, which reads the store or the disk.
  • Docs: docs/BLOBS.md describes the new storage.
  • Tests:
    • New test/look-archive.test.ts covers write by content key, serve (writer 200, stranger 404), and a presign test that never signs for someone the app doesn't let in.
    • It also covers delete through a dirStore, including a shared object that survives one row's deletion.
    • In test/attach-look-refusals.test.ts, the two same-byte attachments are now one object. That test was wrong for the new design, so I changed it.

What I chose not to do

  • Existing attachments: they are not migrated. They stay on the disk and are still served from there, and nothing writes them to the store yet.
  • The forge's own captured looks: they stay files, since they are retaken and aged out by the sweep.
  • Content key: it includes the app and environment, so deletion stays scoped to one environment.

How to try it

  1. As a writer on an app's open pull, POST /api/v1/repos/:owner/:name/pulls/:n/looks with {width, says, image} (base64).
  2. Open the returned url as that writer. A signed-out visitor or another user gets 404.
  3. Close the pull and the object is gone from <data>/look-blobs.

bun test test/look-archive.test.ts runs the new tests.

[
  {"go": "POST /api/v1/repos/:owner/:name/pulls/:n/looks as a writer on a private app's open pull", "look": "201 with a url under /looks/pr-<n>/<head>/…", "expect": "the writer fetches the picture (200, image/png); a signed-out visitor and a non-member get 404"},
  {"go": "the pull page /:owner/:name/pulls/:n?looks=all", "look": "the attached picture's figure", "expect": "it has width and height from the start, so nothing shifts when it loads"}
]

🤖 Generated with Claude Code

commented

<!-- look-pages 484b532fbd91 --> Look pages for 484b532, from the gate:

  • look pages (inferred): this pull changes src/web/pages/looks.ts; the forge pictures / (src/web/pages/looks.ts), /docs (src/web/pages/looks.ts), /explore (src/web/pages/looks.ts) and 28 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

A person's attached looks are now written to the BlobStore by content. They're served only after the access check and deleted along with their rows (#4546).

This push fixes the failed check. The gate's "both doors" rule wanted a terminal screen and a docs/features how-to for the new src/looks/archive.ts. I added a No door: line to a commit message instead. The change only moves where an attached look's bytes are stored, so there is no new page, route or command to give a door to. The same commit has a No look: line, since no page draws differently.

bun scripts/gate.ts no longer reports the both-doors rule. It still prints four similarity notes. archiveBytes and archiveFile differ only in whether the source is bytes or a file on disk. The login and person helpers in test/look-archive.test.ts resemble ones in other tests. I left all of them.

I didn't re-run the tests or the type check this time, because nothing in the code changed; the commit is message-only.

To try it: open a pull of an app you can write, attach a look at /api/v1/repos/:owner/:name/pulls/:n/looks, then open the returned url.

🤖 Generated with Claude Code

commented

The next push fixes two of the four failures. The other two I couldn't reproduce. I haven't seen the new check run yet.

  • module-state: the look store cache was a module-level Map keyed by dataDir. It's now a WeakMap keyed by the app's config object, as the rule asks. lookStore, useLookStore, lookBytes, deleteObjects and deleteLooksAndObjects take the config instead of a dataDir string, and every caller and test is updated.
  • unused-exports: I removed archiveFile, which nothing called. useLookStore is only a test seam, so I added it to scripts/unused-exports-allow.json.
  • The other two: "a job that keeps what it allocates" (test/job-alloc.test.ts) and "a repeat on the same two heads" (test/upstream-counts.test.ts) pass when I run them here. They look like flakes under load; I didn't change anything for them.

tsc is clean, gate.ts has only similarity notes, and the new push has the same commit-message No door: and No look: lines.

Of the 161 look tests I ran, one fails: "a real capture through the grant door, with /usr/bin/chromium". It needs Chromium, which this sandbox doesn't have. I didn't check whether it fails the same way on main.

I didn't run scripts/fast.ts as the pull instructions describe. It said the diff was too broad to name (3,583 files), so I ran the look and build-shots test files directly.

commented

Attached looks are written to the BlobStore by content, served only after the access check, and deleted with their rows (#4546). This round addresses all three of @sentinel's points. In the final run, tsc, the gate (apart from similarity notes) and the test/look-archive.test.ts, test/module-state.test.ts and test/unused-exports.test.ts tests pass here.

  • CSP (high): a bucket-backed look is now streamed by the forge (store.getStream) after the access check, so img-src 'self' holds. I removed the presigned redirect and its LOOK_PRESIGN_S. The bucket test now checks that a stranger gets 404 with no read, and that the owner gets a 200 with the bytes and no Location header.
  • Race (medium):
    • attachLook now does its put and recordLook as one step, run through exclusive() in src/looks/archive.ts. That function is a per-forge queue.
    • deleteObjects runs its row check and delete through the same queue. A delete can no longer land between a new row's put and its row.
    • Test: a new test interleaves a slow delete with a fresh attach of the same bytes. It fails if the queue is removed and passes with it.
  • remove() / forget (low): a new test closes the pull (pull.closed event) and checks that the environment's objects and rows are gone. This covers forget; the remove() call after a full set of looks and in retakeStrangerThumbs has no test of its own.

Where I differ: a look that stays on disk, an older or captured one with a plain path, still goes through the existing path unchanged.

Not tested here: the one test/look* test that needs Chromium, "a real capture through the grant door", fails here because the sandbox has none; I did not check it on main. I never ran the full suite; the forge's check does.

Check log: the last forge check failed on test/job-alloc.test.ts and test/upstream-counts.test.ts. Both pass when I run them here, and I did not change anything for them.

Gate: two earlier pushes this round went up before I had cleared the gate's test rules (a fixed wait, an as never cast). The last commit clears them.

The No door: and No look: lines are in the commit messages.

To try it: open a pull of an app you can write, attach a look at /api/v1/repos/:owner/:name/pulls/:n/looks, then open the returned url.

🤖 Generated with Claude Code

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs