Skip to content

feat(#7326): gRPC vector, hybrid and full-text search run inside the client transaction - #7397

Merged
robfrank merged 1 commit into
mainfrom
feat/7326-grpc-vector-search-in-transaction
Sep 10, 2026
Merged

robfrank merged 1 commit into
mainfrom
feat/7326-grpc-vector-search-in-transaction

Conversation

@robfrank

@robfrank robfrank commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #7326

Problem

The three search RPCs added by #7306 (VectorSearch, HybridSearch, FullTextSearch) carried
database and credentials but no TransactionContext, so a search issued while the client held
an open gRPC transaction ran on a gRPC worker thread instead of the transaction's own thread and
could not observe that transaction's uncommitted writes. The HTTP routes never had the gap:
AbstractVectorSearchHandler extends DatabaseAbstractHandler, which binds the session's
transaction whenever the request carries arcadedb-session-id.

Fix

  1. proto - TransactionContext transaction on VectorSearchRequest (15), HybridSearchRequest
    (15) and FullTextSearchRequest (8); field numbers as the issue specifies, all inside the 1-byte
    tag range.
  2. server - one shared searchInTransaction(...) resolving the transaction exactly as
    lookupByRid / updateRecord already do (resolveAuthorizedTransaction,
    isUnknownSuppliedTransaction -> unknownTransactionStatus, submitToActiveTransaction),
    falling back to getDatabase(...) when no transaction is named. It also unwraps the
    ExecutionException from the transaction executor before toSearchStatus sees it, which is what
    keeps requireTransactionStillActive's FAILED_PRECONDITION and the shared implementation's
    INVALID_ARGUMENT from flattening to INTERNAL.
  3. client - RemoteGrpcDatabase stamps the open transaction on the three search requests the
    same way it already does for executeQuery, lookupByRid, updateRecord and the rest.
File Change
grpc/src/main/proto/arcadedb-server.proto the three new transaction fields
grpcw/.../ArcadeDbGrpcService.java new searchInTransaction(...); the three handlers route through it
grpc-client/.../RemoteGrpcDatabase.java the three search methods stamp the open transaction
grpc-client/src/test/.../Issue7326GrpcSearchInTransactionIT.java new, 8 tests

Residual risk, measured

The dense vector index does not resolve a row created in the open transaction; the full-text
index does. Measured on both protocols, inside one transaction, before any commit (the query
vector is exactly the new row's embedding, so it would rank first if it were a candidate):

gRPC  vector   count=1  names=[seed]            <- new row NOT a candidate
gRPC  fulltext count=1  names=[created-in-tx]   <- new row IS found
HTTP  vector   count=1  (only the seed rid)     <- same as gRPC
HTTP  fulltext count=1                          <- same as gRPC

So the protocol parity this issue is about does hold: HTTP with a session id behaves identically.
The vector gap is an index-layer limit (the graph is populated at commit replay), filed as #7378,
and httpAndGrpcAgreeOnARecordCreatedInsideTheTransaction pins the current behaviour on both
protocols so that whichever way #7378 is resolved the test fails and names the claim to revisit.
fullTextSearchInsideATransactionFindsARecordCreatedInIt asserts the issue's own proposed
verification on the path where it is achievable.

Everything the search does with the candidates it gets is transactional either way: the vector
leg's filter and the database.lookupByRID that materializes each hit. Neither search
implementation forks work off the calling thread (no executor, stream, future or thread use in
HybridSearch, VectorSearch, FullTextQuery, VectorLeg), so nothing escapes the transaction's
executor once the body is dispatched. arcadedb-server.proto is the only proto in the tree and no
generated stubs for other languages are checked in, so the new fields need no companion regeneration.

Verification

Tests run: 8, Failures: 0, Errors: 0, Skipped: 0 -- Issue7326GrpcSearchInTransactionIT

Proof the tests can fail. With searchInTransaction temporarily reverted to the pre-fix body
(return body.apply(getDatabase(databaseName, credentials));) and only that changed, all six tests
that existed at that point failed:

Tests run: 6, Failures: 6, Errors: 0, Skipped: 0
  vectorSearchInsideATransactionSeesItsUncommittedUpdate
  theVectorFilterIsEvaluatedInsideTheTransaction
  fullTextSearchInsideATransactionSeesItsUncommittedUpdate
  hybridSearchInsideATransactionSeesItsUncommittedUpdate
  aSearchNamingAnUnknownTransactionIsRejected
  httpAndGrpcAgreeOnWhatATransactionalSearchSees

Regression: grpc-client 150 unit tests green; grpcw and grpc-client IT suites green (25/25 and
27/27) after re-running three classes in isolation whose only errors were
Failed to bind to address 0.0.0.0:50051 from a parallel build holding the fixed gRPC test port.
Issue7306GrpcVectorSearchIT, the suite this is layered on, 5/5. mvn -o -pl grpc,grpcw,grpc-client package -DskipTests clean on the committed tree.

One run errored once in teardown with ABORTED: Rollback failed: graph
(DatabaseIsClosedException) inside that same port-contention window and did not reproduce in 10
subsequent runs; BaseGraphServerTest restarts the server on fixed ports per method, so a start
racing a previous shutdown is an exposure every IT in this module shares and rollbackTransaction is
untouched here. Recorded so a future occurrence is not mistaken for a new symptom.

Argued, no change needed

  • OpenAPI - HTTP behaviour is unchanged, and arcadedb-session-id is documented on no route in
    server/src/main/java/com/arcadedb/server/http/handler/openapi/, so documenting it on these three
    alone would make the spec less consistent.
  • MCP - no session or transaction surface exists to plumb through.

Follow-ups filed

Process caveat

Phase 1.5's adversarial pass could not be delegated to an isolated subagent - no Task tool was
exposed in that environment - so it ran inline, which lacks the not-already-convinced property. It
still caught two real things: that the suite never asserted the issue's own proposed verification
(now added), and that the first residual-risk paragraph was wrong about full-text (corrected by
measurement above).

🤖 Generated with Claude Code

https://claude.ai/code/session_01GwTsBYjyoDn2vKXQGmt5bK

Summary by CodeRabbit

  • New Features

    • Vector, hybrid, and full-text searches now support execution within an active transaction.
    • Searches performed during a transaction can see that transaction’s uncommitted changes.
    • Search results remain consistent with transaction outcomes, including rollback behavior.
  • Bug Fixes

    • Invalid or unavailable transaction identifiers now return a clear precondition error instead of executing outside the requested transaction.

…client transaction

The three search RPCs added by #7306 carried `database` and `credentials` but no
`TransactionContext`, so a search issued while the client held an open gRPC transaction ran on a
gRPC worker thread instead of the transaction's own thread and could not observe that
transaction's uncommitted writes. The HTTP routes never had the gap: `AbstractVectorSearchHandler`
extends `DatabaseAbstractHandler`, which binds the session's transaction whenever the request
carries `arcadedb-session-id`.

Adds an optional `transaction` field to `VectorSearchRequest`, `HybridSearchRequest` and
`FullTextSearchRequest`, and routes the three handlers through a shared `searchInTransaction(...)`
that resolves the transaction exactly as `lookupByRid` and `updateRecord` already do: authorize it
against the transaction's own database, refuse a non-blank id the server no longer knows with
FAILED_PRECONDITION rather than reading outside the transaction, and dispatch the body onto the
transaction's executor. `RemoteGrpcDatabase` stamps the open transaction on all three requests the
way it already does for every other transaction-scoped RPC.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GwTsBYjyoDn2vKXQGmt5bK
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d2651551-5cd1-4b52-bf39-e002cce9f95c

📥 Commits

Reviewing files that changed from the base of the PR and between 6e6f2b8 and 4919bbc.

📒 Files selected for processing (4)
  • grpc-client/src/main/java/com/arcadedb/remote/grpc/RemoteGrpcDatabase.java
  • grpc-client/src/test/java/com/arcadedb/remote/grpc/Issue7326GrpcSearchInTransactionIT.java
  • grpc/src/main/proto/arcadedb-server.proto
  • grpcw/src/main/java/com/arcadedb/server/grpc/ArcadeDbGrpcService.java

Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds transaction context to gRPC vector, hybrid, and full-text searches. The server executes searches on the active transaction thread and rejects unknown transaction IDs. Integration tests verify uncommitted data visibility, rollback behavior, error handling, and HTTP equivalence.

Changes

Transactional gRPC search

Layer / File(s) Summary
Request transaction context
grpc/src/main/proto/arcadedb-server.proto, grpc-client/src/main/java/com/arcadedb/remote/grpc/RemoteGrpcDatabase.java
Search requests accept transaction context. The client attaches the active database, credentials, and transaction ID.
Transaction-aware search execution
grpcw/src/main/java/com/arcadedb/server/grpc/ArcadeDbGrpcService.java
Search RPCs resolve and authorize transaction IDs. Active transactions execute on their dedicated executor and database handle. Unknown transaction IDs return FAILED_PRECONDITION.
Transactional search integration coverage
grpc-client/src/test/java/com/arcadedb/remote/grpc/Issue7326GrpcSearchInTransactionIT.java
Tests cover uncommitted updates and inserts, rollback, unknown transaction IDs, and equivalent gRPC and HTTP results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant RemoteGrpcDatabase
  participant ArcadeDbGrpcService
  participant TransactionExecutor
  participant TransactionDatabase
  RemoteGrpcDatabase->>ArcadeDbGrpcService: send search with transaction context
  ArcadeDbGrpcService->>TransactionExecutor: resolve and submit active transaction
  TransactionExecutor->>TransactionDatabase: run search against transaction database
  TransactionDatabase-->>RemoteGrpcDatabase: return transactional search results
Loading

Suggested reviewers: lvca

Merge Risk: ⚪ Minimal · up to 4919b

This change makes gRPC vector, hybrid, and full-text searches honor the caller’s active transaction and reject unknown transaction IDs. The supplied coverage exercises transactional visibility, rollback, validation, and HTTP parity, with no concrete merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 65.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: running gRPC vector, hybrid, and full-text searches inside the client transaction.
Description check ✅ Passed The description is detailed and covers the problem, implementation, related issue, verification, regression results, residual risks, and follow-up work. It does not use the template headings or includ…
Linked Issues check ✅ Passed The changes satisfy issue #7326. They add the required transaction fields, resolve and authorize transactions, reject unknown transaction IDs, dispatch searches on the transaction executor, stamp clie…
Out of Scope Changes check ✅ Passed All code and test changes support the linked issue. The proto updates, server transaction dispatch, client request changes, and integration tests are directly related to transactional search behavior.…
Full details: Docstring Coverage

Explanation

Docstring coverage is 65.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/7326-grpc-vector-search-in-transaction

Warning

Some tools did not complete. Review the errors below.

🔧 Buf (1.72.0)
grpc/src/main/proto/arcadedb-server.proto

fatal: unable to access 'https://github.com/ArcadeData/arcadedb.git/': Failed to connect to github.com port 443 via 127.0.0.1 after 0 ms: Could not connect to server
fatal: could not fetch 851587e477b94ae61da1a45fe2e3af89c4b094b1 from promisor remote


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

codacy-production Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

🟢 Coverage 73.68% diff coverage · -6.48% coverage variation

Metric Results
Coverage variation ✅ -6.48% coverage variation
Diff coverage ✅ 73.68% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (6e6f2b8) 175566 144513 82.31%
Head commit (4919bbc) 207998 (+32432) 157722 (+13209) 75.83% (-6.48%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7397) 38 28 73.68%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@claude

claude Bot commented Sep 10, 2026

Copy link
Copy Markdown

Review

Reviewed the diff (proto, ArcadeDbGrpcService, RemoteGrpcDatabase, and the new IT). Overall this is a clean, well-scoped fix that closes a real protocol-parity gap, and it reuses the existing transaction-resolution machinery rather than inventing a parallel path.

Code quality / design

  • searchInTransaction(...) in ArcadeDbGrpcService.java correctly mirrors the lookupByRid/updateRecord pattern: resolveAuthorizedTransaction → isUnknownSuppliedTransaction → unknownTransactionStatus → submitToActiveTransaction, with the ExecutionException unwrap so toSearchStatus sees the real cause instead of flattening everything to INTERNAL. Good reuse per the project's "reuse existing components" guideline.
  • Client-side openTransaction() helper and the if (transactionId != null) builder.setTransaction(...) guard in vectorSearch/hybridSearch/fullTextSearch match the exact shape already used for updateRecord, deleteRecord, createRecord, etc. in RemoteGrpcDatabase.java — consistent with the rest of the file rather than a new convention.
  • Proto field numbering: reusing 15 for the transaction field on both VectorSearchRequest and HybridSearchRequest (last field is 1-byte-tag range), and 8 on FullTextSearchRequest (which had fewer prior fields) is a reasonable, deliberate choice, and it's explained in the PR description.
  • The TransactionContext name collision between the proto message and the pre-existing nested ArcadeDbGrpcService.TransactionContext static class (same package) is worth a second look. It compiles fine here since the proto type is never referenced by its bare name in this file, but a future edit that tries to use com.arcadedb.server.grpc.TransactionContext unqualified inside ArcadeDbGrpcService will silently resolve to the wrong type. Not a blocker, but maybe worth a one-line comment near the nested class noting the shadowing, since it's a sharp edge for the next person touching this file.

Correctness

  • The fallback path (txCtx == null → getDatabase(databaseName, credentials)) preserves prior behavior exactly, so non-transactional callers are unaffected.
  • isUnknownSuppliedTransaction/unknownTransactionStatus correctly distinguish "no transaction supplied" (blank/null id) from "a non-blank id the server no longer knows," matching the fail-loud contract already established for writes.
  • The residual-risk section in the PR description (dense vector index not resolving in-transaction-created rows, vs. full-text which does) is honestly documented and pinned by httpAndGrpcAgreeOnARecordCreatedInsideTheTransaction, rather than silently glossed over. Filing Dense vector index search does not see rows created in the open transaction (full-text does) #7378 for the underlying index-layer gap instead of trying to fix it here keeps this PR properly scoped.

Performance

  • No new allocations or synchronous work on the hot path beyond what other transaction-scoped RPCs already do (one Future.get() on the transaction's dedicated executor). Non-transactional callers pay nothing extra beyond the hasTransaction() check.

Security

  • authorizeTransactionAccess (called via resolveAuthorizedTransaction) authorizes against txCtx.db.getName() — the transaction's real database — not the request-supplied database field, so a search naming a transaction still can't be used to read a different database than the one the transaction was opened on. This matches the existing anti-hijack guard for the other transaction-scoped RPCs.

Test coverage

  • The new Issue7326GrpcSearchInTransactionIT (8 tests) is thorough: uncommitted-update visibility for all three search types, the vector filter predicate evaluated in-transaction, the unknown-transaction-id rejection path, and two HTTP/gRPC parity tests. The PR description's "proof the tests can fail" (reverting searchInTransaction to the pre-fix body and confirming 6/6 failures) is good rigor — genuinely demonstrates the tests are exercising the fix rather than trivially passing.
  • One minor gap: there's no test asserting that a request with a blank/absent transaction field still resolves against getDatabase(...) when a different transaction happens to be active server-side for another connection (i.e., isolation between the fallback path and unrelated transactions). Probably low risk given the existing per-transaction dedicated-executor design, but not explicitly covered here.

No blocking issues found. Nice work keeping the PR description's residual-risk and follow-up sections honest about what this does and doesn't fix.

@robfrank
robfrank merged commit 2359c83 into main Sep 10, 2026
32 checks passed
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.68421% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.76%. Comparing base (6e6f2b8) to head (4919bbc).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
.../com/arcadedb/server/grpc/ArcadeDbGrpcService.java 54.54% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7397      +/-   ##
==========================================
- Coverage   73.77%   73.76%   -0.01%     
==========================================
  Files        1932     1932              
  Lines      175566   175595      +29     
  Branches    37179    37186       +7     
==========================================
+ Hits       129517   129524       +7     
- Misses      31091    31140      +49     
+ Partials    14958    14931      -27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

gRPC vector search RPCs cannot run inside a client transaction

1 participant