Aequora Sync — Part 07
Subscription, Scope, Filter, and Dynamic Dataset Architecture
Implementation status (2026-08-20): Complete at the reusable repository boundary. Canonical scope identity, resolver/filter/projection contracts, filtered watermarks, subscriptions, atomic transitions, reference-counted membership, pending-intent quarantine, Stoolap durability, client integration, diagnostics, and invariants are mapped in
docs/subscription-scope-dynamic-dataset-completion.md. Application membership policy and live authorization/revocation acceptance remain host gates.
1. Purpose
Aequora is not always intended to synchronize an entire tenant database to every client.
Real applications need subsets.
Examples:
teacher device:
assigned classes
current academic year
attendance module
accountant desktop:
finance module
selected campuses
student app:
own profile
own timetable
own fee records
branch office:
one branch
one operational region
Therefore Aequora needs a formal architecture for:
subscriptions
sync scopes
filters
dynamic dataset membership
permission-driven expansion
permission-driven contraction
revocation
scope versioning
scope-specific cursors
filtered tombstones
multi-scope clients
The central rule is:
A cursor is only meaningful within the exact scope definition and authority generation for which it was issued.
A scope change is a synchronization state transition, not merely a different SQL WHERE clause.
2. Goals
The scope system should provide:
least-data synchronization
tenant isolation
module-based sync
branch/campus sync
user-specific datasets
dynamic membership
permission revocation
safe dataset contraction
safe expansion
scope-specific bootstrap
bounded journal reads
multi-scope clients
clear cursor semantics
3. Non-Goals
The scope system must not become:
an arbitrary client query engine
SQL-over-sync
a mechanism for clients to bypass authorization
a general federated database query planner
Clients request declared scope types/parameters.
Server decides actual authorized dataset.
4. Terminology
Use distinct concepts:
ScopeDefinition
ScopeInstance
Subscription
ScopeVersion
ScopeGeneration
ScopeCursor
Membership
Filter
5. ScopeDefinition
A reusable application-declared type.
Examples:
TeacherWorkspace
FinanceWorkspace
StudentSelf
CampusOperations
Conceptually:
pub struct ScopeDefinitionId(u32);
This is stable across releases.
6. ScopeInstance
A concrete authorized dataset for one client/device/user.
Example:
TeacherWorkspace {
teacher_id = T1,
campus = C3,
academic_year = 2026
}
It receives:
pub struct ScopeId(Uuid);
or a deterministic opaque identifier.
7. Scope Is Server-Issued
Client may request:
"I want TeacherWorkspace for academic year 2026"
Server resolves:
what this authenticated principal is actually permitted to receive
The client must never define authoritative filter predicates itself.
8. ScopeResolver
Application implements:
pub trait ScopeResolver {
async fn resolve(
&self,
auth: &AuthContext,
request: &ScopeRequest,
) -> Result<ResolvedScope, ScopeError>;
}
Aequora then handles cursor/bootstrap mechanics.
9. ResolvedScope
Conceptually:
pub struct ResolvedScope {
pub scope_id: ScopeId,
pub definition: ScopeDefinitionId,
pub version: ScopeVersion,
pub generation: ScopeGeneration,
pub descriptor: ScopeDescriptor,
}
10. ScopeDescriptor
Contains server-owned canonical parameters.
Examples:
tenant
campus set
class set
module set
date range
entity families
Do not necessarily expose internal raw predicates to the client.
11. ScopeVersion
Define:
pub struct ScopeVersion(u64);
Increment when the logical scope membership rules change for the same scope instance.
Examples:
teacher assigned a new class
campus removed
module permission added
12. ScopeGeneration
Define:
pub struct ScopeGeneration(u64);
Increment on incompatible timeline/reset events.
Examples:
PITR
scope history discarded
filter semantics changed incompatibly
server cannot continue old cursor lineage
This is stronger than normal ScopeVersion.
13. ScopeCursor
Use:
pub struct ScopeCursor {
pub scope_id: ScopeId,
pub scope_version: ScopeVersion,
pub generation: ScopeGeneration,
pub sequence: Sequence,
}
A bare global sequence is insufficient.
14. Cursor Validation
Server validates:
scope ID matches
scope version compatible
generation matches
cursor within retained history
Possible outcomes:
Valid
ScopeChanged
ResyncRequired
UpgradeRequired
Forbidden
15. Scope Membership
A record/event is in scope when application-defined membership rules say so.
Membership may depend on:
tenant
entity fields
relationships
permissions
module
time range
assignment
16. Membership Must Be Deterministic
For a given authoritative state and scope version:
membership(entity, scope)
must be deterministic.
Otherwise reconciliation becomes impossible.
17. Membership vs Authorization
Membership says:
this entity belongs in this dataset
Authorization says:
this principal may receive/use it
Server scope resolver combines both.
18. Scope Request Is Not Authorization
Client can ask for:
Campus C5
Server may resolve:
Campus C2 only
or reject.
Never trust requested IDs.
19. Subscription
A subscription is the client's durable relationship to one scope.
Conceptually:
pub struct Subscription {
pub subscription_id: SubscriptionId,
pub scope_id: ScopeId,
pub state: SubscriptionState,
}
20. Subscription States
pub enum SubscriptionState {
Bootstrapping,
Active,
Expanding,
Contracting,
Suspended,
Revoked,
ResyncRequired,
}
21. Client Can Have Multiple Subscriptions
Example:
CoreSchool
Finance
Documents
Notifications
Each may have its own:
ScopeId
cursor
generation
bootstrap state
22. Do Not Force One Global Cursor
A single client-wide cursor breaks when datasets have different:
permissions
retention
journal history
bootstrap lifecycle
Use scope-specific cursors.
23. Independent Failure
If:
Documents scope requires resync
the client should not necessarily wipe:
CoreSchool scope
Each subscription is independently recoverable where architecture allows.
24. Scope Registry
Server application registers:
ScopeDefinition
resolver
membership evaluator
snapshot projector
journal filter
25. ScopeDefinition Trait
Conceptually:
pub trait ScopeDefinition {
fn id(&self) -> ScopeDefinitionId;
async fn resolve(
&self,
auth: &AuthContext,
request: &ScopeRequest,
) -> Result<ResolvedScope, ScopeError>;
fn event_membership(
&self,
scope: &ResolvedScope,
event: &AuthoritativeEvent,
) -> MembershipDecision;
}
26. MembershipDecision
pub enum MembershipDecision {
Include,
Exclude,
RequiresProjection,
}
27. Projection
Sometimes client should not receive the entire authoritative entity.
Example:
server Student contains sensitive internal notes
student app may receive only public/self fields
Scope can select a projection.
28. Scope Projection
Server emits:
ScopeProjectedChange
not necessarily raw authoritative event payload.
The journal remains authoritative internally.
The client receives an authorized projection.
29. Projection Version
Projection schema should be versioned separately if needed.
pub struct ProjectionVersion(u32);
This protects compatibility.
30. Filtered Journal
There are two broad strategies.
Strategy A — Filter Global Journal at Read Time
global journal
↓
scope membership filter
↓
client
Strategy B — Maintain Scope-Specific Feed
authoritative event
↓
scope feed index
↓
client
31. Recommended Initial Strategy
Start with:
global authoritative journal
+
indexed scope filtering
for moderate scale.
Add precomputed scope feeds only when profiling shows need.
32. Cursor Semantics With Filtered Events
Suppose global journal:
100 entity A in scope
101 entity X out of scope
102 entity B in scope
Client can safely advance scope cursor to:
102
even though it only received events 100 and 102, because server confirms that 101 was intentionally filtered.
33. Scope Cursor as Watermark
sequence = 102 means:
All authoritative journal entries through 102 have been evaluated against this scope version, and all required resulting changes have been delivered/applied.
This is stronger than:
last event received = 102
34. Filter Stability
If scope membership rules change, old filtered watermark may no longer be sufficient.
That is why ScopeVersion matters.
35. Scope Expansion
Example:
teacher assigned Class B
Old scope:
Class A
New scope:
Class A + B
The client needs historical state for B that was previously filtered.
Normal incremental pull from current sequence cannot reconstruct it.
36. Expansion Strategies
Use one of:
delta bootstrap for added membership
partial snapshot
full scope bootstrap
Recommended initial safe strategy:
partial bootstrap for added partition if supported
otherwise full scope bootstrap
37. Scope Expansion State Machine
Active v5
↓ server detects membership expansion
Expanding v6
↓ bootstrap newly added dataset
Install
↓ reconcile journal changes after bootstrap boundary
Active v6
38. Expansion Boundary
Server issues:
new scope version
bootstrap boundary N
The added dataset snapshot represents state through N.
Then incremental events:
> N
are applied.
39. Existing Dataset During Expansion
Existing scope data can remain usable.
If architecture supports partitioned bootstrap:
old membership remains active
new partition staged
This improves UX.
40. Scope Contraction
Example:
teacher loses Class A assignment
Client must stop receiving and generally remove data no longer authorized.
This is a security-sensitive transition.
41. Contraction Is Not Ordinary Delete
An entity can leave scope without being deleted globally.
Example:
Student still exists
teacher no longer assigned
The client needs:
ScopeRemoval
not an authoritative domain tombstone.
42. ScopeRemoval
Define a distinct change:
pub struct ScopeRemoval {
pub scope_id: ScopeId,
pub entity: EntityRef,
pub reason: ScopeRemovalReason,
}
43. ScopeRemoval vs Tombstone
Tombstone:
entity deleted from authoritative domain
ScopeRemoval:
entity still exists but no longer belongs in this client's dataset
Never confuse them.
44. Client Apply
On ScopeRemoval:
remove authoritative replica data from that scope
unless another active scope still references the same shared local entity.
45. Multi-Scope Reference Problem
Example:
Student S1 present in TeacherScope
and FinanceScope
TeacherScope contracts.
Do not physically delete S1 if FinanceScope still needs it.
46. Scope Reference Tracking
Client needs local membership metadata:
EntityRef
↔
ScopeId set
Physical replica state can be removed only when:
no active scope references entity
and no local-only requirement needs it.
47. Membership Table
Logical:
aequora_scope_membership
Fields:
scope_id
entity_type
entity_id
membership_version
state
48. Shared Entity Storage
Recommended:
store entity once
+
track membership in multiple scopes
rather than duplicate full row per scope, unless adapter/project intentionally isolates stores.
49. Scope-Specific Projection Conflict
Two scopes may expose different projections of same server entity.
Example:
student app projection
admin projection
If one local store contains both, use:
projection namespaces
or select a canonical superset permitted to local principal.
Do not merge unauthorized fields accidentally.
50. Projection Security Rule
A more privileged scope must never leak fields into a less privileged account/session sharing the same local store unless the application intentionally permits it.
Multi-user shared-device designs need stronger profile isolation.
51. Revocation
Revocation is stronger than ordinary contraction.
Examples:
device revoked
user removed from tenant
subscription permission revoked
Client may receive:
ScopeRevoked
52. Revocation Behavior
On scope revocation:
stop push for that scope
stop pull
remove unauthorized replicated data
quarantine/handle pending operations
invalidate cursor
53. Pending Operations During Revocation
A client may have pending edits for now-revoked data.
Do not silently upload them.
Mark:
AuthorizationLost
or:
ScopeRevokedPending
and stop transmission.
54. Preserve Pending Payload?
Policy depends on security and UX.
Options:
quarantine encrypted/local
discard after explicit policy
export for admin support
Do not retain indefinitely if policy requires data erasure.
55. Permission Downgrade
If user still has some access:
scope contracts
rather than full revocation.
56. Permission Upgrade
If user gains access:
scope expands
with partial/full bootstrap.
57. Dynamic Relationship Membership
Membership can depend on relationships.
Example:
teacher sees students in assigned classes
When assignment changes, many entities may enter/leave scope.
Need efficient membership diff.
58. Membership Diff
Server computes:
old authorized membership
vs
new authorized membership
for dynamic transition.
For large datasets, avoid storing massive explicit sets if a deterministic query can generate them efficiently.
59. Scope Version Transition Record
Server may persist:
scope_id
old_version
new_version
change_kind
boundary
for diagnostics and resync behavior.
60. Scope Identity Stability
If the same logical subscription changes incrementally:
ScopeId stays same
ScopeVersion increments
If semantics are fundamentally replaced:
new ScopeId
may be cleaner.
61. Filter Identity
Do not hash raw SQL.
Canonical filter identity should derive from:
scope definition
normalized parameters
server policy version
projection version
62. Opaque Scope Token
Client can carry:
opaque scope token
issued by server.
It should not need to understand internal filter details.
63. Signed Scope Token
Optional future optimization:
signed serialized scope descriptor
can reduce DB lookup.
But authorization freshness still matters.
Do not let a long-lived token override current revocation state.
64. Scope Refresh
Client periodically or on sync obtains:
scope status
Server may report:
unchanged
expanded
contracted
revoked
generation changed
65. Efficient Change Detection
Server can return:
ScopeVersion
in every sync response.
If client version differs:
perform transition protocol
66. Scope Change During Sync
Suppose permission changes while request is running.
Server transaction/response must use a coherent authorization decision.
Safe approach:
resolve scope version at request start
validate again before sensitive commit where needed
return newer scope version hint if changed
67. Push Operations and Scope
Outgoing operation must be authorized independently.
Being subscribed to an entity does not automatically grant write permission.
68. Write Scope
Read scope and write authority are distinct.
Example:
student can read fee record
cannot edit it
Operation handler authorization remains authoritative.
69. Scope Removal of Locally Dirty Entity
If an entity leaves scope while unsent local operations exist:
do not simply delete entity and pending intent
Transition to explicit state:
ScopeRemovedWithPendingIntent
Policy decides whether operation can still be submitted.
70. Default Security Rule
If write authorization is no longer valid:
do not transmit
Pending operation becomes authorization conflict/quarantine.
71. Scope Expansion and Pending Local Creation
A locally created entity may not yet be server-authoritative.
Membership logic for pending local entities is application-specific.
Outbox remains source of unsynced intent.
Scope bootstrap must not accidentally overwrite local pending creation.
72. Bootstrap + Pending Operations
Reuse Part 04:
preserve outbox
install authoritative scope state
rebase eligible pending ops
73. Scope Transition + Anti-Entropy
Part 03 anti-entropy must compare within:
exact ScopeId
ScopeVersion
ScopeGeneration
Never compare root hashes across different scope versions.
74. Scope-Specific Integrity Root
Integrity manifest:
scope_id
scope_version
generation
boundary
root
75. Scope Transition + Part 05
Only local coordinator leader performs:
bootstrap
scope contraction
membership rewrite
Follower processes observe local generation/status changes.
76. Scope Transition + Part 06
QoS scheduler prioritizes:
security-sensitive contraction/revocation
above routine background work.
Large expansion bootstrap may be:
interactive if required for UI
bulk otherwise
77. Scope Change Notifications
Future push hint can notify:
scope version changed
but client still verifies with server.
78. Time-Bounded Scopes
Example:
current academic year only
When year changes:
scope parameters/version change
Old data retention is application policy.
79. Historical Offline Access
A client may intentionally retain historical data after it leaves active sync scope.
This must be explicit.
Distinguish:
NotActivelySynced
from:
NoLongerAuthorized
80. Retention Policy
Scope contraction can specify:
pub enum LocalRetentionPolicy {
RemoveImmediately,
RetainReadOnly,
RetainUntil(Date),
ApplicationManaged,
}
Security-sensitive revocation should normally force removal.
81. Retained Read-Only Historical Data
If allowed:
remove from active membership
keep local archival copy
mark non-authoritative/stale
Do not continue presenting it as current synced state.
82. Scope Tombstone
Do not overload domain tombstone.
Use:
MembershipRemoved
or ScopeRemoval.
83. Entity Re-Enters Scope
If an entity previously left and later returns:
server sends current authoritative representation
Do not rely on stale retained copy.
84. Re-Entry Version
If client retained version 5 and server is version 11:
replace/update to 11
normal authoritative rules apply.
85. Scope-Local Sequence
The simplest implementation can still use global server sequence as watermark within scope cursor.
Alternative future:
scope-specific sequence
for large-scale optimized feeds.
86. Global Sequence Pros
simple authoritative ordering
one journal
easy debugging
87. Global Sequence Cons
many filtered entries
large sparse scans
high-cost membership evaluation
88. Scope Feed Pros
efficient tenant/module-specific reads
dense feed
89. Scope Feed Cons
more storage
more transaction/index complexity
90. Evolution Strategy
Start:
global sequence + filter
Later:
precomputed scope feed/index
without changing client semantics.
91. Scope Feed Index
Derived table may store:
scope_partition
global_sequence
entity
change type
It must remain recoverable from authoritative journal.
92. Dynamic Scope Explosion
Do not materialize a separate feed for every user if millions of unique dynamic scopes exist.
Use shared partitions where possible.
Examples:
campus
class
tenant
module
compose into user scope.
93. Scope Partitioning
Scope can reference deterministic partitions.
Example:
Tenant T
Campus C
Class K
Module Attendance
This supports reuse.
94. PartitionId
Define:
pub struct DatasetPartitionId(UuidOrStableKey);
A scope may be:
set of partitions + projection policy
95. Partition Advantages
Makes:
expansion
contraction
bootstrap
Merkle integrity
retention
more efficient.
96. Avoid Arbitrary Per-Row Filter Logic
For high-scale deployments, favor scope predicates that map to indexed partition keys.
Application should design sync boundaries intentionally.
97. Scope Design Guidance
Good scope dimensions:
tenant
campus
branch
class
module
user-owned
time bucket
Bad:
arbitrary client-provided expression
98. Multi-Tenant Safety
Every scope belongs to exactly one trusted tenant context unless explicitly cross-tenant administrative.
Cross-tenant scope requires dedicated privileged design.
99. Scope IDs Are Not Secrets
Knowing ScopeId does not grant access.
Every sync request authenticates and reauthorizes scope use.
100. Device-Specific Scope
Server may bind subscription to:
DeviceId
for policies like:
maximum devices
offline access
device trust
101. Actor-Specific Scope
Some scope membership is actor-specific.
If actor changes on same device:
old subscriptions may need revoke/remove
new subscriptions bootstrap
102. Shared Device
For multiple users on one physical device, safest design:
separate local profile store per user/tenant
This avoids cross-user data leakage.
103. Subscription Lifecycle
Requested
↓
Resolved
↓
Bootstrapping
↓
Active
├─ Expanding
├─ Contracting
├─ Suspended
├─ ResyncRequired
└─ Revoked
104. Suspended
Used when:
temporary policy
billing state
maintenance
and data may remain locally.
Do not confuse with revocation.
105. Revoked
Means:
access no longer valid
typically requires local data removal.
106. Server Response
Every exchange can include:
pub struct ScopeStatus {
pub scope_id: ScopeId,
pub version: ScopeVersion,
pub generation: ScopeGeneration,
pub state: ScopeServerState,
}
107. Transition Instructions
Server may return:
Continue
ExpandWithBootstrap
ContractWithRemovals
FullResync
Revoke
Suspend
108. Atomic Contraction Apply
Client should transactionally:
apply scope removals
update membership table
preserve/mark affected pending ops
update scope version
commit
109. Cursor Advance During Contraction
New scope version and membership changes must be installed coherently.
Do not set:
scope_version = new
before removals are durably applied.
110. Expansion Install Atomicity
For large expansion:
stage added partition
verify
atomically activate membership
update scope version/cursor
111. Scope Transition ID
Define:
pub struct ScopeTransitionId(Uuid);
Useful for resumable expansion/contraction and diagnostics.
112. Idempotent Scope Transition
Retrying same transition must not duplicate/delete incorrectly.
Persist:
transition_id
from version
to version
state
113. Interrupted Expansion
On restart:
resume staged transition
or discard staging and restart safely.
Old active scope remains coherent until activation.
114. Interrupted Contraction
Contraction is security-sensitive.
Prefer transactional or partitioned idempotent removal with transition progress.
Do not leave client claiming new version while old unauthorized data remains.
115. Urgent Revocation
For severe revocation:
stop presenting affected data immediately
even if physical cleanup continues in background.
Use logical access gate first.
116. Logical Access Gate
Client UI/repositories consult active membership.
When revoked:
membership inactive immediately
Physical deletion can follow.
This prevents data display during cleanup.
117. Local Query Safety
Application repositories should query through:
active scope/profile context
rather than raw local tables if data from multiple scopes/users coexist.
118. Scope Membership API
Client SDK may expose:
aequora.is_entity_active_in_scope(entity, scope)
for advanced use.
Ordinary app code should rely on repositories.
119. Search Index Cleanup
When data leaves scope:
local FTS/search index
cache
derived projections
must also remove or deactivate it.
Scope removal should emit local maintenance hooks.
120. Blob Cleanup
If entity leaves all scopes:
BlobRef membership count may drop
Unreferenced local blob can be cleaned according to policy.
121. Scope-Aware Blob Authorization
Blob fetch must validate active scope/entity authorization.
Possessing old BlobRef must not grant access after revocation.
122. Scope-Aware Outbox
Every outgoing operation should record:
origin scope/subscription if applicable
for diagnostics.
But write authorization is independently rechecked server-side.
123. Cross-Scope Operation
Some operations touch entities across scopes.
Example:
move student between classes
This is domain operation semantics, not two client scopes controlling authority.
Server handles transaction and resulting membership transitions.
124. Membership-Changing Operation
An accepted operation may itself change scope membership.
Example:
AssignTeacherToClass
Server emits:
domain event
+
scope version changes for affected teachers
125. Scope Recalculation
Do not synchronously recompute millions of user scopes inside one business transaction.
Use:
durable scope-change job/feed
where scale requires.
126. Strong Immediate Revocation
For security-critical revocation, authorization is checked at request time immediately even if scope transition feed lags.
Thus stale local data cannot be used to perform unauthorized server writes.
127. Read Revocation Lag
Local offline client may still possess previously authorized data while disconnected.
No sync architecture can remotely erase a physically offline device instantly.
Document this threat model.
128. Offline Revocation Reality
Guarantee:
once device reconnects and receives revocation,
Aequora stops exposing/syncing revoked scope and removes according to policy
For stronger protection, use:
encrypted local data with revocable keys
covered later in cryptographic/security parts.
129. Scope Privacy
Do not expose server-internal membership rationale unnecessarily.
Client needs:
scope ID
version
state
transition instructions
not confidential policy details.
130. Scope Diagnostics
Admin should inspect:
scope owner
definition
version
generation
active partitions
last cursor
transition state
subject to RBAC.
131. Client Diagnostics
Expose:
subscription state
scope version
generation
cursor
last bootstrap
pending transition
132. Metrics
Server:
scope_resolution_total
scope_expansion_total
scope_contraction_total
scope_revocation_total
scope_bootstrap_bytes
scope_transition_duration
Client:
active_scope_count
scope_transition_pending
scope_removal_entities
scope_expansion_entities
133. Alerting
Alert on:
repeated scope transition failure
revocation cleanup failure
scope resolver errors
mass unexpected expansion
membership diff explosion
134. Scope Change Storm
Example:
new academic year
could update thousands of scopes.
Use:
partitioned background recomputation
rate limiting
staggered client bootstrap
135. Bulk Scope Transition
Server can prepare:
new partition snapshots
once and reuse across many eligible clients where projections match.
136. Shared Snapshot Artifact
Example:
Campus C / Class A / Attendance module
snapshot can be reused by many teacher devices, with authorization checked before delivery.
137. Snapshot Cache Key
dataset partition
projection version
boundary
schema version
not user identity unless data truly user-specific.
138. Scope Resolver Caching
Cache resolved membership carefully.
Invalidation triggers:
role change
assignment change
tenant policy change
module permission change
Stale cache must not override authoritative authorization.
139. Fail-Closed Rule
If scope authorization cannot be determined safely:
do not expand access
Return retryable/error.
For existing scope, application policy decides whether reads remain local while server unavailable.
140. Schema and Scope Evolution
If a schema upgrade changes which fields/entities belong to scope:
increment ScopeVersion
or ScopeGeneration if incremental transition is unsafe.
141. Protocol Evolution
Scope transition messages are versioned capabilities.
Older clients may receive:
ResyncRequired
instead of complex partial transitions.
That is a safe compatibility fallback.
142. Minimal v1 Scope System
The first production implementation should support:
one or more named server-defined scopes
scope-specific cursor
full bootstrap per scope
server-detected version change
full resync on scope change
revocation
This is simpler and correct.
143. Phase 2 Scope Optimization
Then add:
partial expansion
incremental contraction
scope removals
shared partition snapshots
144. Phase 3 Scale Optimization
Later:
precomputed scope feeds
partition indexes
large-scale dynamic membership
145. Why Start Conservatively
A wrong partial-scope transition can leak or orphan data.
A full scope rebootstrap is more expensive but much easier to reason about.
Correctness first.
146. Scope Adapter Requirements
Authoritative adapter/server layer must support:
scope-filtered journal read
consistent scope snapshot
membership transition metadata
scope cursor validation
147. Local Adapter Requirements
Client adapter must support:
scope subscription metadata
entity-to-scope membership
scope cursor
scope transition state
atomic activation/removal
148. Universal DB Interoperability
Scope semantics remain canonical.
Physical implementations may differ:
SQL:
membership table
KV:
scope/entity keys
document:
metadata collection
No database-pair-specific protocol.
149. Scope Compliance Suite
Test:
full bootstrap
filtered pull
expansion
contraction
revocation
multi-scope shared entity
cursor mismatch
generation mismatch
interrupted transition
150. Correctness Invariants
Add to Part 01.
A scope cursor is interpreted only with matching ScopeId, ScopeVersion, and ScopeGeneration.
Client never receives data outside server-authorized scope.
Scope contraction removes/deactivates data no longer authorized before activating the new scope version.
ScopeRemoval never implies authoritative domain deletion.
An entity referenced by another active local scope is not physically removed solely because one scope contracts.
Pending operations are never silently transmitted after their originating authorization/scope is revoked.
Expansion does not activate incomplete bootstrap data.
151. Property Tests
Generate:
scope expansion
scope contraction
entity moves between partitions
multiple overlapping scopes
revocation with pending operation
Assert:
no unauthorized active data
correct membership refcounts
cursor/version coherence
152. Model Checking
Extend abstract model with:
scope membership
permission changes
transition states
Explore:
scope changes while response lost
revocation during pending operation
expansion interrupted
multi-scope removal
153. Fault Injection
Inject crash:
during expansion staging
before activation
during contraction
before membership-version commit
after logical revoke before physical cleanup
154. Example — Teacher Scope Expansion
Initial:
Teacher T
Classes: A
ScopeVersion 4
Cursor 900
Assignment adds Class B.
Server:
ScopeVersion 5
added partition B
bootstrap boundary 950
Client:
stage Class B through 950
apply journal >950
activate B
set scope version 5
155. Example — Teacher Scope Contraction
Initial:
Classes A+B
Teacher loses B.
Server sends:
ScopeTransition v5→v6
Remove partition B
Client:
deactivate B membership
remove entities only referenced by B
preserve shared entities needed by A
update scope version
156. Example — Student Self Scope
Scope:
own StudentId
own fee records
own timetable
own results
Server determines identity from AuthContext.
Client never supplies another StudentId as authoritative scope identity.
157. Example — Finance Module Scope
Accountant receives:
finance entities
selected campus
current + previous fiscal period
A change in campus assignment triggers scope transition.
158. Recommended Modules
aequora-core/
└── scope/
├── id.rs
├── version.rs
├── cursor.rs
├── subscription.rs
└── transition.rs
aequora-server/
└── scope/
├── resolver.rs
├── membership.rs
├── filter.rs
├── projection.rs
└── transition.rs
aequora-client/
└── scope/
├── subscription.rs
├── membership.rs
├── bootstrap.rs
├── contraction.rs
└── state.rs
159. Logical Client Tables
aequora_subscription
aequora_scope_cursor
aequora_scope_membership
aequora_scope_transition
160. Logical Server Tables
Optional, depending on application:
aequora_scope_instance
aequora_scope_transition
aequora_scope_device_state
Many scope definitions can be computed rather than fully materialized.
161. Public Client API
Conceptual:
let sub = aequora
.subscribe(TeacherWorkspaceRequest { ... })
.await?;
Most applications should establish subscriptions automatically after authentication.
162. Server Registration
ScopeRegistry::builder()
.register(TeacherWorkspaceScope::new(...))
.register(StudentSelfScope::new(...))
.register(FinanceWorkspaceScope::new(...))
.build()?;
163. Plug-and-Play Defaults
For simple projects:
DefaultTenantScope
can mean:
all authorized syncable data in current tenant
Developers need not design fine-grained scopes initially.
164. Progressive Adoption
Start project with:
one tenant-wide scope
Later split into:
core
finance
documents
campus
user-specific
without rewriting the synchronization core.
165. Completion Criteria
Part 07 is complete when:
[x] ScopeDefinitionId defined
[x] ScopeId defined
[x] ScopeVersion defined
[x] ScopeGeneration defined
[x] ScopeCursor defined
[x] ScopeResolver defined
[x] subscription lifecycle defined
[x] filtered cursor semantics defined
[x] full bootstrap per scope defined
[x] expansion architecture defined
[x] contraction architecture defined
[x] ScopeRemoval distinct from Tombstone
[x] multi-scope membership reference tracking defined
[x] revocation and pending-op handling defined
[x] projection rules defined
[x] scope transition atomicity defined
[x] anti-entropy/bootstrap/QoS integrations defined
[x] adapter compliance tests defined
[x] correctness invariants added
166. Final Architecture
AUTHENTICATED CLIENT
│
▼
Scope Request
│
▼
Scope Resolver
│
server authorization/policy
│
▼
Resolved Scope v7
│
┌────────────┼────────────┐
▼ ▼ ▼
Snapshot Journal Projection
Builder Filter Policy
│ │ │
└────────────┼────────────┘
▼
Scope Cursor
│
▼
Client
│
┌────────────────┼────────────────┐
▼ ▼ ▼
Subscription Membership Local Data
State Map
│
├── expansion -> partial/full bootstrap
├── contraction -> ScopeRemoval
├── revocation -> deactivate/remove
└── generation change -> ResyncRequired
The architectural principle is:
Aequora synchronizes an authorized, versioned dataset—not an arbitrary query result. Scope identity, scope version, authority generation, membership, and cursor must move together as one coherent synchronization contract.
This gives Aequora a safe foundation for tenant-aware, module-aware, branch-aware, user-specific, dynamically changing datasets without leaking data or corrupting cursor semantics.