Skip to content

Add transactional success completion for queries - #239

Open
ianmacartney wants to merge 2 commits into
ian/transactional-completionfrom
ian/transactional-query-completion
Open

ianmacartney wants to merge 2 commits into
ian/transactional-completionfrom
ian/transactional-query-completion

Conversation

@ianmacartney

@ianmacartney ianmacartney commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Allow completeTransactionally: true on enqueueQuery and enqueueQueryBatch to commit the selected success callback and completion bookkeeping together. Queries always read independent snapshots without adding read dependencies to the completion transaction. Their results may be stale when the callback commits; callbacks should read any data whose freshness they require.

Stacked on #238. Opted-in queries are individually scheduled through the existing mutation wrapper, including queries enqueued in a batch. The wrapper calls the query with transaction headroom reserved and invokes completion directly, without another wrapper UDF. Every query call in the mutation wrapper uses useStaleSnapshot: true, even if transactional completion is false or omitted. Queries without the flag keep their existing action-batch execution. Actions continue to reject transactional completion.

Callback or bookkeeping errors roll back completion and fail the scheduled wrapper; existing recovery later finalizes the job as failed and dispatches any selected failure callback. The job holds its concurrency slot until recovery. Query execution errors retain the normal failure-completion path. Existing stored and scheduled argument shapes already support queries, so no schema or generated component API shape changes are needed.

Requires Convex 1.42 or newer for useStaleSnapshot; the existing ^1.43 peer requirement from main covers this. README and client documentation describe the snapshot semantics and include queries in maxParallelism.

Validation: build, typecheck, lint, formatting, and all 282 tests pass after restacking onto #238 on current main. The local Convex deployment smoke check (npm run test:e2e) also passes, with generated component API files unchanged. Coverage includes default versus transactional routing, independent wrappers for query batches, query results and large payloads, skipped success callbacks, query errors, rollback after callback and late bookkeeping errors, recovery without duplicate callbacks, and single/batch client execution. Three snapshot regression cases verify that queries ignore uncommitted writes with transactional completion enabled, disabled, or omitted; all fail if stale snapshots are disabled. Client failure tests distinguish transactional execution from an ignored flag. Type tests cover query context and result inference plus continued action rejection.

Test limitations: convex-test 0.0.67 supports nested transaction limits, enabled in component wrapper tests, but does not simulate production OCC. Recovery tests supply the error text it omits from failed scheduled-job records after testing actual scheduled failures and rollback.

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/workpool@239

commit: 2b4a41c

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@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.

All reported issues were addressed across 9 files

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

Re-trigger cubic

Comment thread README.md Resolved
@ianmacartney
ianmacartney force-pushed the ian/transactional-query-completion branch from 94dd77b to cb7a6b3 Compare September 11, 2026 03:55
@ianmacartney
ianmacartney force-pushed the ian/transactional-completion branch 2 times, most recently from b304b6c to 50482e2 Compare September 11, 2026 20:37
@ianmacartney
ianmacartney force-pushed the ian/transactional-query-completion branch 2 times, most recently from bcd1caa to f077bbf Compare September 11, 2026 20:54
@reeceyang

Copy link
Copy Markdown
Contributor

Test limitations: convex-test does not simulate OCC or enforce nested transaction limits. Recovery tests supply the error text it omits from failed scheduled-job records after testing actual scheduled failures and rollback.

I thought convex-test does enforce nested transaction limits?

ianmacartney added a commit that referenced this pull request Sep 11, 2026
Callers who only need failure or cancellation handling can now reuse one `onComplete` handler with `onCompleteExcludeKinds: ["success"]`. 

Mutation-only transactional success is a separate stacked change in #238, and for queries in #239.
@ianmacartney
ianmacartney force-pushed the ian/transactional-completion branch 2 times, most recently from de31804 to a8d4623 Compare September 11, 2026 23:29
@ianmacartney
ianmacartney force-pushed the ian/transactional-query-completion branch 2 times, most recently from afb7089 to a1c0d6e Compare September 11, 2026 23:36
@ianmacartney
ianmacartney force-pushed the ian/transactional-completion branch from a8d4623 to 32e5f21 Compare September 11, 2026 23:36
@ianmacartney
ianmacartney force-pushed the ian/transactional-query-completion branch from a1c0d6e to 411af9d Compare September 11, 2026 23:41
@ianmacartney

Copy link
Copy Markdown
Member Author

convex-test can be provided with transaction limits to enforce. i can't recall if it does so by default, but it's certainly capable (though not sure if that's well documented)

@ianmacartney
ianmacartney force-pushed the ian/transactional-completion branch from bec8e66 to 2e19056 Compare November 12, 2026 21:44
@ianmacartney
ianmacartney force-pushed the ian/transactional-query-completion branch from 411af9d to 2b4a41c Compare November 12, 2026 21:44
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