8000 Introduce active_conditions wire format by robacourt · Pull Request #3966 · electric-sql/electric · GitHub
[go: up one dir, main page]

Skip to content

Introduce active_conditions wire format#3966

Open
robacourt wants to merge 1 commit intomainfrom
rob/active_conditions
Open

Introduce active_conditions wire format#3966
robacourt wants to merge 1 commit intomainfrom
rob/active_conditions

Conversation

@robacourt
Copy link
Contributor

Summary

Introduces the active_conditions wire format as a backward-compatible protocol addition, extracted from #3791. This allows clients to be updated to the new protocol before the server adds complex OR/NOT subquery support.

Part of the work toward supporting arbitrary boolean expressions in WHERE clauses (#3791).

Changes

Elixir Client (taken from #3791)

  • Tag format: Tags become {position, hash} tuples with slash-delimited wire format (e.g. "hash_a/hash_b", "hash_a/", "/hash_b")
  • active_conditions tracking: Headers now include active_conditions: [boolean()] indicating which disjuncts are satisfied
  • DNF visibility: Row visibility evaluated as OR of ANDs over positions — a row is visible if at least one disjunct is fully satisfied
  • disjunct_positions: Derived once from the first tagged message and reused for all subsequent messages in the shape

Server (minimal changes for current simple case)

  • Add active_conditions field to NewRecord, UpdatedRecord, DeletedRecord structs
  • Include active_conditions in JSON response headers when present (via put_if_true)
  • For shapes with subqueries, set active_conditions: [true, ...] (always all-true in the simple single-subquery case)
  • Include active_conditions in snapshot SQL queries alongside tags
  • Read Electric-Protocol-Version header from HTTP requests into params schema

Test updates

  • 26 new/updated tag_tracker unit tests covering position-based tags, DNF visibility, orphan cleanup, mixed rows
  • Removed one integration test that used an unrealistic tag format incompatible with the new wire protocol

Compatibility

  • v1 clients (old): Will receive active_conditions in headers but ignore it (unknown field). No regression.
  • v2 clients (new Elixir client): Will use active_conditions for DNF visibility. For the simple case (single subquery), behavior is identical to v1 but through the new code path.

Test Plan

  • Elixir client: 10 doctests, 206 tests, 0 failures
  • Sync service: 382 doctests, 8 properties, 1433 tests, 0 failures
  • Router integration: 76 tests, 0 failures

Generated with Claude Code

Add active_conditions support to the sync protocol as a
backward-compatible change, preparing for OR/NOT in WHERE clauses.

Elixir client (from #3791):
- Tags become {position, hash} tuples with slash-delimited wire format
- active_conditions tracking and DNF visibility evaluation
- disjunct_positions derived once per shape, shared across keys

Server (minimal changes for simple case):
- Add active_conditions field to NewRecord/UpdatedRecord/DeletedRecord
- Include active_conditions in JSON headers when present
- Compute active_conditions: [true, ...] for shapes with subqueries
- Include active_conditions in snapshot SQL queries
- Read Electric-Protocol-Version header from HTTP requests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 95.12195% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.31%. Comparing base (cea4c13) to head (2524b76).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...s/elixir-client/lib/electric/client/tag_tracker.ex 94.59% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3966      +/-   ##
==========================================
+ Coverage   75.75%   77.31%   +1.56%     
==========================================
  Files          11       37      +26     
  Lines         693     1671     +978     
  Branches      174      173       -1     
==========================================
+ Hits          525     1292     +767     
- Misses        167      378     +211     
  Partials        1        1              
Flag Coverage Δ
elixir 78.42% <95.12%> (?)
elixir-client 78.42% <95.12%> (?)
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/y-electric 56.05% <ø> (ø)
typescript 75.75% <ø> (ø)
unit-tests 77.31% <95.12%> (+1.56%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@robacourt robacourt self-assigned this Mar 11, 2026
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

0