Skip to content

Support ctx.storage.store and ctx.storage.get in mutations - #166

Draft
reeceyang wants to merge 1 commit into
mainfrom
ry/mutation-storage-store-get
Draft

reeceyang wants to merge 1 commit into
mainfrom
ry/mutation-storage-store-get

Conversation

@reeceyang

Copy link
Copy Markdown
Contributor

Starting in convex 1.47, mutations can call ctx.storage.store(blob) and ctx.storage.get(id), which go through the new 1.0/storageStore and 1.0/storageGet async syscalls. convex-test throws does not support async syscall on these. This PR emulates them, following the backend implementation in crates/isolate/src/environment/udf/async_syscall.rs:

  • 1.0/storageStore base64-decodes the blob, computes its sha256, and rejects with Sha256 mismatch. Expected: … Actual: … when the caller's sha256 option doesn't match. It then inserts a _storage document with size, sha256, and contentType (left out when the blob has no type). The insert goes through the mutation's transaction, so a mutation that throws also rolls back the file.
  • 1.0/storageGet returns { blob: <base64>, contentType }, or null when the file is missing or was deleted. A file stored earlier in the same mutation can be read back.

Per-transaction file read/write limits (TooManyFilesWritten, FilesReadTooLarge, …) aren't emulated, because convex-test's metrics tracker doesn't track file storage yet.

Bumps the convex devDependency to 1.47.0 so the tests use the new client code. The peer dependency stays at ^1.43.0.

npm run build passes (lint, typecheck, all tests).

🤖 Generated with Claude Code

Emulates the 1.0/storageStore and 1.0/storageGet async syscalls that
convex 1.47 mutations use for ctx.storage.store/get.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="index.ts">

<violation number="1" location="index.ts:1828">
P2: `db.storeFile` mutates the committed file map before the surrounding mutation commits, so a later mutation error rolls back only `_storage` metadata and leaves the Blob retained. Stage file writes with the transaction and apply or discard them during commit/rollback to avoid leaking every file from a failed mutation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread index.ts
...(type !== undefined ? { contentType: type } : {}),
});
});
db.storeFile(storageId, file);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: db.storeFile mutates the committed file map before the surrounding mutation commits, so a later mutation error rolls back only _storage metadata and leaves the Blob retained. Stage file writes with the transaction and apply or discard them during commit/rollback to avoid leaking every file from a failed mutation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At index.ts, line 1828:

<comment>`db.storeFile` mutates the committed file map before the surrounding mutation commits, so a later mutation error rolls back only `_storage` metadata and leaves the Blob retained. Stage file writes with the transaction and apply or discard them during commit/rollback to avoid leaking every file from a failed mutation.</comment>

<file context>
@@ -1807,6 +1807,39 @@ function asyncSyscallImpl() {
+            ...(type !== undefined ? { contentType: type } : {}),
+          });
+        });
+        db.storeFile(storageId, file);
+        return JSON.stringify(convexToJson(storageId));
+      }
</file context>

@reeceyang
reeceyang marked this pull request as draft October 15, 2026 22:39
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.

1 participant