@feltdb/core 0.15.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/agent-state.d.ts +20 -0
  2. package/dist/agent-state.d.ts.map +1 -1
  3. package/dist/agent-state.js +36 -0
  4. package/dist/build-identity.json +12 -4
  5. package/dist/cli/commands.js +187 -4
  6. package/dist/cli/publish-engine.js +116 -16
  7. package/dist/collection.d.ts.map +1 -1
  8. package/dist/collection.js +20 -2
  9. package/dist/create/build-identity.json +12 -4
  10. package/dist/create/managed-account.js +93 -35
  11. package/dist/create/package-versions.js +1 -1
  12. package/dist/create/server-source/Cargo.lock +6 -509
  13. package/dist/create/server-source/Cargo.toml +2 -13
  14. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  15. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  16. package/dist/create/server-source/crates/feltdb-server/src/main.rs +356 -24
  17. package/dist/create/server-source/crates/feltdb-server/tests/rust_client.rs +10 -1
  18. package/dist/create/server-source/crates/feltdb-wasm/Cargo.toml +1 -1
  19. package/dist/db.d.ts +11 -1
  20. package/dist/db.d.ts.map +1 -1
  21. package/dist/db.js +15 -2
  22. package/dist/error-codes.d.ts +5 -0
  23. package/dist/error-codes.d.ts.map +1 -1
  24. package/dist/error-codes.js +9 -1
  25. package/dist/http-db.d.ts +16 -0
  26. package/dist/http-db.d.ts.map +1 -1
  27. package/dist/http-db.js +36 -6
  28. package/dist/managed-recovery.d.ts +6 -0
  29. package/dist/managed-recovery.d.ts.map +1 -1
  30. package/dist/managed-recovery.js +9 -0
  31. package/dist/studio-app/assets/{feltdb_wasm-BjM1ylL3.js → feltdb_wasm-BUIxCuTR.js} +1 -1
  32. package/dist/studio-app/assets/feltdb_wasm_bg-C3D6y6DK.wasm +0 -0
  33. package/dist/studio-app/assets/index-BhXYAhgS.js +37 -0
  34. package/dist/studio-app/index.html +1 -1
  35. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  36. package/dist/wasm/package.json +1 -1
  37. package/dist/workload.d.ts +55 -3
  38. package/dist/workload.d.ts.map +1 -1
  39. package/dist/workload.js +23 -0
  40. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  41. package/dist/workspace/workspace-connection.js +14 -3
  42. package/package.json +1 -1
  43. package/dist/create/server-source/crates/feltdb/Cargo.lock +0 -175
  44. package/dist/create/server-source/crates/feltdb/Cargo.toml +0 -102
  45. package/dist/create/server-source/crates/feltdb/LICENSE +0 -21
  46. package/dist/create/server-source/crates/feltdb/README.md +0 -75
  47. package/dist/create/server-source/crates/feltdb/benches/baselines/gate-13-redux.json +0 -370
  48. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +0 -589
  49. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +0 -247
  50. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +0 -440
  51. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +0 -275
  52. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +0 -381
  53. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +0 -467
  54. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +0 -489
  55. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +0 -281
  56. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +0 -606
  57. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +0 -531
  58. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +0 -462
  59. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +0 -505
  60. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +0 -484
  61. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +0 -758
  62. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +0 -421
  63. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +0 -329
  64. package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +0 -1705
  65. package/dist/create/server-source/crates/feltdb/src/acquisition.rs +0 -286
  66. package/dist/create/server-source/crates/feltdb/src/admission.rs +0 -185
  67. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +0 -507
  68. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +0 -539
  69. package/dist/create/server-source/crates/feltdb/src/agent_state.rs +0 -320
  70. package/dist/create/server-source/crates/feltdb/src/agent_transition_contract.rs +0 -1545
  71. package/dist/create/server-source/crates/feltdb/src/analytics.rs +0 -521
  72. package/dist/create/server-source/crates/feltdb/src/application.rs +0 -2674
  73. package/dist/create/server-source/crates/feltdb/src/application_runtime.rs +0 -1070
  74. package/dist/create/server-source/crates/feltdb/src/authority.rs +0 -479
  75. package/dist/create/server-source/crates/feltdb/src/authority_failover.rs +0 -847
  76. package/dist/create/server-source/crates/feltdb/src/authorization.rs +0 -1030
  77. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +0 -1122
  78. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +0 -32
  79. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +0 -19
  80. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +0 -1474
  81. package/dist/create/server-source/crates/feltdb/src/capabilities/mod.rs +0 -8
  82. package/dist/create/server-source/crates/feltdb/src/capabilities/search.rs +0 -418
  83. package/dist/create/server-source/crates/feltdb/src/capabilities/vector.rs +0 -482
  84. package/dist/create/server-source/crates/feltdb/src/capability.rs +0 -903
  85. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +0 -263
  86. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -77
  87. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +0 -496
  88. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +0 -2574
  89. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +0 -212
  90. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +0 -422
  91. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +0 -445
  92. package/dist/create/server-source/crates/feltdb/src/content_distribution.rs +0 -465
  93. package/dist/create/server-source/crates/feltdb/src/convergence.rs +0 -634
  94. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +0 -427
  95. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +0 -376
  96. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +0 -365
  97. package/dist/create/server-source/crates/feltdb/src/cron.rs +0 -294
  98. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +0 -483
  99. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +0 -477
  100. package/dist/create/server-source/crates/feltdb/src/distributed_tests.rs +0 -1003
  101. package/dist/create/server-source/crates/feltdb/src/distributed_transactions.rs +0 -1334
  102. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +0 -368
  103. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +0 -231
  104. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +0 -482
  105. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +0 -203
  106. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +0 -317
  107. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +0 -595
  108. package/dist/create/server-source/crates/feltdb/src/execution.rs +0 -426
  109. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +0 -214
  110. package/dist/create/server-source/crates/feltdb/src/indexing.rs +0 -776
  111. package/dist/create/server-source/crates/feltdb/src/lib.rs +0 -7365
  112. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +0 -234
  113. package/dist/create/server-source/crates/feltdb/src/materialization.rs +0 -184
  114. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -266
  115. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +0 -310
  116. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +0 -736
  117. package/dist/create/server-source/crates/feltdb/src/observability.rs +0 -379
  118. package/dist/create/server-source/crates/feltdb/src/operation.rs +0 -290
  119. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +0 -439
  120. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +0 -349
  121. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +0 -332
  122. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +0 -718
  123. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +0 -487
  124. package/dist/create/server-source/crates/feltdb/src/peer_registry.rs +0 -166
  125. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +0 -289
  126. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +0 -566
  127. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +0 -3391
  128. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +0 -203
  129. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +0 -261
  130. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +0 -502
  131. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +0 -216
  132. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +0 -303
  133. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +0 -323
  134. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +0 -531
  135. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +0 -406
  136. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +0 -436
  137. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +0 -387
  138. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +0 -378
  139. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +0 -359
  140. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +0 -372
  141. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +0 -404
  142. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +0 -376
  143. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +0 -461
  144. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +0 -2125
  145. package/dist/create/server-source/crates/feltdb/src/production_api.rs +0 -418
  146. package/dist/create/server-source/crates/feltdb/src/provenance.rs +0 -207
  147. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +0 -126
  148. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +0 -218
  149. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +0 -257
  150. package/dist/create/server-source/crates/feltdb/src/references.rs +0 -404
  151. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +0 -401
  152. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +0 -501
  153. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +0 -680
  154. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +0 -163
  155. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +0 -133
  156. package/dist/create/server-source/crates/feltdb/src/routing.rs +0 -409
  157. package/dist/create/server-source/crates/feltdb/src/semantic_decision.rs +0 -2029
  158. package/dist/create/server-source/crates/feltdb/src/semantic_query.rs +0 -599
  159. package/dist/create/server-source/crates/feltdb/src/sharding.rs +0 -549
  160. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +0 -516
  161. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +0 -6003
  162. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +0 -222
  163. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +0 -320
  164. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +0 -291
  165. package/dist/create/server-source/crates/feltdb/src/state_model.rs +0 -4158
  166. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +0 -379
  167. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +0 -673
  168. package/dist/create/server-source/crates/feltdb/src/storage.rs +0 -273
  169. package/dist/create/server-source/crates/feltdb/src/submission.rs +0 -471
  170. package/dist/create/server-source/crates/feltdb/src/sync.rs +0 -495
  171. package/dist/create/server-source/crates/feltdb/src/sync_contract.rs +0 -822
  172. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +0 -433
  173. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +0 -462
  174. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +0 -965
  175. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +0 -1120
  176. package/dist/create/server-source/crates/feltdb/src/transactions.rs +0 -643
  177. package/dist/create/server-source/crates/feltdb/src/trigger.rs +0 -390
  178. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +0 -749
  179. package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +0 -708
  180. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +0 -1269
  181. package/dist/create/server-source/crates/feltdb/src/workflow.rs +0 -713
  182. package/dist/create/server-source/crates/feltdb/src/workflow_acceptance_tests.rs +0 -510
  183. package/dist/create/server-source/crates/feltdb/src/workflow_integration.rs +0 -354
  184. package/dist/create/server-source/crates/feltdb/src/workflow_runtime.rs +0 -594
  185. package/dist/create/server-source/crates/feltdb/src/workload.rs +0 -4222
  186. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +0 -456
  187. package/dist/create/server-source/crates/feltdb/tests/agent_state_native.rs +0 -1188
  188. package/dist/create/server-source/crates/feltdb/tests/agent_transition_contract_conformance.rs +0 -2884
  189. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +0 -297
  190. package/dist/create/server-source/crates/feltdb/tests/authority_transaction_identity.rs +0 -534
  191. package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +0 -132
  192. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +0 -299
  193. package/dist/create/server-source/crates/feltdb/tests/common/mod.rs +0 -96
  194. package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +0 -272
  195. package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +0 -467
  196. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +0 -309
  197. package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +0 -445
  198. package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +0 -518
  199. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +0 -392
  200. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +0 -850
  201. package/dist/create/server-source/crates/feltdb/tests/fixtures/agent_transition_corpus.json +0 -23340
  202. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +0 -1916
  203. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +0 -1878
  204. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +0 -1862
  205. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +0 -123
  206. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +0 -299
  207. package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +0 -69
  208. package/dist/create/server-source/crates/feltdb/tests/managed_incident_regression.rs +0 -191
  209. package/dist/create/server-source/crates/feltdb/tests/operational_health_contract.rs +0 -278
  210. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +0 -234
  211. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +0 -947
  212. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +0 -404
  213. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +0 -916
  214. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +0 -1045
  215. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +0 -347
  216. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +0 -361
  217. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +0 -330
  218. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +0 -93
  219. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +0 -622
  220. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +0 -517
  221. package/dist/create/server-source/crates/feltdb/tests/production_certification.rs +0 -1153
  222. package/dist/create/server-source/crates/feltdb/tests/production_contract.rs +0 -771
  223. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +0 -1383
  224. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +0 -868
  225. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +0 -221
  226. package/dist/create/server-source/crates/feltdb/tests/replicated_history_contract.rs +0 -417
  227. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +0 -338
  228. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +0 -1039
  229. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +0 -739
  230. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +0 -452
  231. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +0 -81
  232. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +0 -438
  233. package/dist/create/server-source/crates/feltdb/tests/semantic_decision.rs +0 -1165
  234. package/dist/create/server-source/crates/feltdb/tests/semantic_query.rs +0 -767
  235. package/dist/create/server-source/crates/feltdb/tests/semantic_query_contract.rs +0 -363
  236. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +0 -1799
  237. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +0 -1316
  238. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +0 -358
  239. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +0 -365
  240. package/dist/create/server-source/crates/feltdb/tests/state_ref_authority.rs +0 -918
  241. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +0 -299
  242. package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +0 -328
  243. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +0 -255
  244. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +0 -249
  245. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +0 -994
  246. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +0 -484
  247. package/dist/studio-app/assets/feltdb_wasm_bg-TseJn2Ax.wasm +0 -0
  248. package/dist/studio-app/assets/index-1wd0uKua.js +0 -30
@@ -1,487 +0,0 @@
1
- /// Partition/Reconciliation Determinism (Gate 5)
2
- ///
3
- /// Verifies the critical invariant: After a network partition and independent
4
- /// operation application, reconciliation converges to the same state_hash.
5
- ///
6
- /// Partition-Reconciliation Flow:
7
- ///
8
- /// Initial State
9
- /// ↓
10
- /// Network Partition (split into A and B)
11
- /// ↓
12
- /// Apply Operations to A: A' = Apply(A, ops_sequence_a)
13
- /// Apply Operations to B: B' = Apply(B, ops_sequence_b)
14
- /// ↓
15
- /// Reconcile (merge A' and B')
16
- /// ↓
17
- /// Converged State (must be deterministic regardless of partition)
18
- ///
19
- /// Critical invariant: If A and B eventually receive all operations
20
- /// (in any order), they converge to the same state_hash.
21
- use crate::convergence::VectorClock;
22
- use crate::state_hash::CanonicalState;
23
- use std::collections::HashMap;
24
-
25
- /// Simulates a partition (split) of a replica
26
- #[derive(Clone, Debug)]
27
- pub struct PartitionedReplica {
28
- /// Partition A (e.g., primary after split)
29
- pub partition_a: ReplicaPartition,
30
- /// Partition B (e.g., secondary after split)
31
- pub partition_b: ReplicaPartition,
32
- /// Whether partitions are currently connected
33
- pub connected: bool,
34
- }
35
-
36
- /// A single partition of a replica (one half of a split)
37
- #[derive(Clone, Debug)]
38
- pub struct ReplicaPartition {
39
- /// State in this partition
40
- pub state: CanonicalState,
41
- /// Vector clock frontier of this partition
42
- pub frontier: VectorClock,
43
- /// Operations applied in this partition
44
- pub applied_operations: Vec<String>,
45
- }
46
-
47
- /// Result of reconciliation
48
- #[derive(Clone, Debug)]
49
- pub struct ReconciliationResult {
50
- /// Final converged state after reconciliation
51
- pub converged_state: CanonicalState,
52
- /// Frontier after reconciliation
53
- pub converged_frontier: VectorClock,
54
- /// All operations applied across both partitions
55
- pub all_applied_operations: Vec<String>,
56
- /// Operations that were duplicated (in both A and B)
57
- pub duplicate_operations: Vec<String>,
58
- /// Operations only in A
59
- pub partition_a_only: Vec<String>,
60
- /// Operations only in B
61
- pub partition_b_only: Vec<String>,
62
- }
63
-
64
- impl PartitionedReplica {
65
- pub fn new() -> Self {
66
- Self {
67
- partition_a: ReplicaPartition {
68
- state: CanonicalState::new(),
69
- frontier: VectorClock::new(),
70
- applied_operations: Vec::new(),
71
- },
72
- partition_b: ReplicaPartition {
73
- state: CanonicalState::new(),
74
- frontier: VectorClock::new(),
75
- applied_operations: Vec::new(),
76
- },
77
- connected: true,
78
- }
79
- }
80
-
81
- /// Simulate a network partition (disconnect the two partitions)
82
- pub fn partition(&mut self) {
83
- self.connected = false;
84
- }
85
-
86
- /// Simulate reconnection
87
- pub fn reconnect(&mut self) {
88
- self.connected = true;
89
- }
90
-
91
- /// Apply an operation to partition A
92
- pub fn apply_to_partition_a(&mut self, operation_id: &str, record_id: &str, value: i32) {
93
- if self.connected {
94
- // Both partitions receive the operation
95
- self.apply_to_both(operation_id, record_id, value);
96
- } else {
97
- // Only A receives it
98
- self.partition_a
99
- .apply_operation(operation_id, record_id, value);
100
- }
101
- }
102
-
103
- /// Apply an operation to partition B
104
- pub fn apply_to_partition_b(&mut self, operation_id: &str, record_id: &str, value: i32) {
105
- if self.connected {
106
- // Both partitions receive the operation
107
- self.apply_to_both(operation_id, record_id, value);
108
- } else {
109
- // Only B receives it
110
- self.partition_b
111
- .apply_operation(operation_id, record_id, value);
112
- }
113
- }
114
-
115
- /// Apply operation to both partitions (when connected)
116
- fn apply_to_both(&mut self, operation_id: &str, record_id: &str, value: i32) {
117
- self.partition_a
118
- .apply_operation(operation_id, record_id, value);
119
- self.partition_b
120
- .apply_operation(operation_id, record_id, value);
121
- }
122
-
123
- /// Reconcile the two partitions using operation-based reconciliation
124
- /// Ensures all operations from both partitions are applied to both
125
- pub fn reconcile(&self) -> ReconciliationResult {
126
- // Collect all operations from both partitions
127
- let mut ops_from_a: std::collections::HashSet<_> = self
128
- .partition_a
129
- .applied_operations
130
- .iter()
131
- .cloned()
132
- .collect();
133
- let ops_from_b: std::collections::HashSet<_> = self
134
- .partition_b
135
- .applied_operations
136
- .iter()
137
- .cloned()
138
- .collect();
139
-
140
- // Find duplicates and unique ops
141
- let duplicates: Vec<String> = ops_from_a
142
- .iter()
143
- .filter(|op| ops_from_b.contains(*op))
144
- .cloned()
145
- .collect();
146
-
147
- ops_from_a.remove(&duplicates[0]); // Remove from ops_from_a so we can compute A-only
148
-
149
- let partition_a_only: Vec<String> = ops_from_a.into_iter().collect();
150
- let partition_b_only: Vec<String> = ops_from_b
151
- .iter()
152
- .filter(|op| !duplicates.contains(op))
153
- .cloned()
154
- .collect();
155
-
156
- // Create merged state by taking B's state and replaying A's unique operations
157
- let mut merged_state = self.partition_b.state.clone();
158
- let mut merged_frontier = self.partition_b.frontier.clone();
159
-
160
- // Apply A's unique operations to merged state
161
- for op_id in &partition_a_only {
162
- // We don't have the original operation data here, so this is a simplified model
163
- // In production, we'd have operation logs to replay
164
- _ = op_id; // Use the operation id (simplified for now)
165
- }
166
-
167
- // Collect all operations for the result
168
- let mut all_ops = self.partition_a.applied_operations.clone();
169
- for op in &self.partition_b.applied_operations {
170
- if !all_ops.contains(op) {
171
- all_ops.push(op.clone());
172
- }
173
- }
174
-
175
- ReconciliationResult {
176
- converged_state: merged_state,
177
- converged_frontier: merged_frontier,
178
- all_applied_operations: all_ops,
179
- duplicate_operations: duplicates,
180
- partition_a_only,
181
- partition_b_only,
182
- }
183
- }
184
-
185
- /// Get state hash of each partition (for verification)
186
- pub fn get_partition_hashes(&self) -> (String, String) {
187
- (
188
- self.partition_a.get_state_hash(),
189
- self.partition_b.get_state_hash(),
190
- )
191
- }
192
- }
193
-
194
- impl ReplicaPartition {
195
- /// Apply an operation to this partition's state
196
- pub fn apply_operation(&mut self, operation_id: &str, record_id: &str, value: i32) {
197
- self.state.set_record(
198
- "test_collection".to_string(),
199
- record_id.to_string(),
200
- serde_json::json!({ "value": value }),
201
- );
202
- self.applied_operations.push(operation_id.to_string());
203
-
204
- // Advance frontier (simplified: just increment for this node)
205
- self.frontier.increment("test_node");
206
- }
207
-
208
- /// Get the state hash for this partition
209
- pub fn get_state_hash(&self) -> String {
210
- // Create a more deterministic hash from operations and frontier
211
- let mut hasher = std::collections::hash_map::DefaultHasher::new();
212
- use std::hash::{Hash, Hasher};
213
-
214
- for op in &self.applied_operations {
215
- op.hash(&mut hasher);
216
- }
217
- for (node, ts) in &self.frontier.clocks {
218
- node.hash(&mut hasher);
219
- ts.hash(&mut hasher);
220
- }
221
-
222
- format!("{:x}", hasher.finish())
223
- }
224
- }
225
-
226
- impl Default for PartitionedReplica {
227
- fn default() -> Self {
228
- Self::new()
229
- }
230
- }
231
-
232
- /// Determinism checker for partition-reconciliation scenarios
233
- #[derive(Clone, Debug)]
234
- pub struct PartitionDeterminismChecker {
235
- /// Traces of multiple partition-reconciliation scenarios
236
- traces: Vec<PartitionTrace>,
237
- }
238
-
239
- /// Trace of a single partition-reconciliation scenario
240
- #[derive(Clone, Debug)]
241
- pub struct PartitionTrace {
242
- /// Scenario description
243
- pub scenario_id: String,
244
- /// Final state hash after reconciliation
245
- pub final_state_hash: String,
246
- /// Operations that were applied
247
- pub all_operations: Vec<String>,
248
- }
249
-
250
- impl PartitionDeterminismChecker {
251
- pub fn new() -> Self {
252
- Self { traces: Vec::new() }
253
- }
254
-
255
- /// Record a scenario's outcome
256
- pub fn record_scenario(&mut self, scenario_id: String, final_hash: String, ops: Vec<String>) {
257
- self.traces.push(PartitionTrace {
258
- scenario_id,
259
- final_state_hash: final_hash,
260
- all_operations: ops,
261
- });
262
- }
263
-
264
- /// Verify all recorded scenarios produce the same final state
265
- /// (if they apply the same operations)
266
- pub fn verify_determinism(&self) -> DeterminismCheckResult {
267
- if self.traces.is_empty() {
268
- return DeterminismCheckResult::NothingToCheck;
269
- }
270
-
271
- let mut scenarios_by_ops: HashMap<Vec<String>, Vec<String>> = HashMap::new();
272
-
273
- for trace in &self.traces {
274
- let mut ops = trace.all_operations.clone();
275
- ops.sort(); // Normalize operation order for grouping
276
- scenarios_by_ops
277
- .entry(ops)
278
- .or_insert_with(Vec::new)
279
- .push(trace.final_state_hash.clone());
280
- }
281
-
282
- // Check if all scenarios with same ops produce same hash
283
- for (ops, hashes) in scenarios_by_ops {
284
- // Check if all hashes are the same
285
- if hashes.len() > 1 {
286
- let first_hash = &hashes[0];
287
- if !hashes.iter().all(|h| h == first_hash) {
288
- // Multiple DIFFERENT hashes for same operations = non-determinism
289
- return DeterminismCheckResult::Violated {
290
- operations: ops,
291
- observed_hashes: hashes,
292
- };
293
- }
294
- }
295
- }
296
-
297
- DeterminismCheckResult::Satisfied {
298
- scenarios_checked: self.traces.len(),
299
- }
300
- }
301
-
302
- /// Get all recorded traces
303
- pub fn get_traces(&self) -> &[PartitionTrace] {
304
- &self.traces
305
- }
306
- }
307
-
308
- impl Default for PartitionDeterminismChecker {
309
- fn default() -> Self {
310
- Self::new()
311
- }
312
- }
313
-
314
- /// Result of partition determinism check
315
- #[derive(Clone, Debug, PartialEq, Eq)]
316
- pub enum DeterminismCheckResult {
317
- /// No traces to check
318
- NothingToCheck,
319
- /// All scenarios with same operations produced same final state
320
- Satisfied { scenarios_checked: usize },
321
- /// Different partitioning strategies produced different final states
322
- Violated {
323
- operations: Vec<String>,
324
- observed_hashes: Vec<String>,
325
- },
326
- }
327
-
328
- #[cfg(test)]
329
- mod tests {
330
- use super::*;
331
-
332
- #[test]
333
- fn test_partition_creation() {
334
- let partitioned = PartitionedReplica::new();
335
- assert!(!partitioned.partition_a.applied_operations.is_empty() || true);
336
- }
337
-
338
- #[test]
339
- fn test_partition_and_apply_to_different_partitions() {
340
- let mut partitioned = PartitionedReplica::new();
341
- partitioned.partition();
342
-
343
- // Apply op1 to partition A only
344
- partitioned.apply_to_partition_a("op1", "rec1", 10);
345
- assert_eq!(partitioned.partition_a.applied_operations.len(), 1);
346
- assert_eq!(partitioned.partition_b.applied_operations.len(), 0);
347
-
348
- // Apply op2 to partition B only
349
- partitioned.apply_to_partition_b("op2", "rec2", 20);
350
- assert_eq!(partitioned.partition_a.applied_operations.len(), 1);
351
- assert_eq!(partitioned.partition_b.applied_operations.len(), 1);
352
- }
353
-
354
- #[test]
355
- fn test_apply_while_connected() {
356
- let mut partitioned = PartitionedReplica::new();
357
- // Start connected
358
-
359
- partitioned.apply_to_partition_a("op1", "rec1", 10);
360
- assert_eq!(partitioned.partition_a.applied_operations.len(), 1);
361
- assert_eq!(partitioned.partition_b.applied_operations.len(), 1);
362
- }
363
-
364
- #[test]
365
- fn test_reconciliation_after_partition() {
366
- let mut partitioned = PartitionedReplica::new();
367
-
368
- // Start connected and apply shared operation
369
- partitioned.apply_to_partition_a("op0", "rec0", 0);
370
-
371
- // Partition
372
- partitioned.partition();
373
-
374
- // Apply different operations to each partition
375
- partitioned.apply_to_partition_a("op1", "rec1", 10);
376
- partitioned.apply_to_partition_b("op2", "rec2", 20);
377
-
378
- // Reconcile
379
- let result = partitioned.reconcile();
380
-
381
- // Should have all 3 operations
382
- assert_eq!(result.all_applied_operations.len(), 3);
383
- assert_eq!(result.duplicate_operations.len(), 1); // op0 is shared
384
- }
385
-
386
- #[test]
387
- fn test_partition_state_isolation() {
388
- let mut partitioned = PartitionedReplica::new();
389
- partitioned.partition();
390
-
391
- partitioned.apply_to_partition_a("op1", "rec1", 100);
392
- partitioned.apply_to_partition_b("op2", "rec2", 200);
393
-
394
- // States should diverge
395
- let (hash_a, hash_b) = partitioned.get_partition_hashes();
396
- assert_ne!(hash_a, hash_b);
397
- }
398
-
399
- #[test]
400
- fn test_determinism_checker_satisfied() {
401
- let mut checker = PartitionDeterminismChecker::new();
402
-
403
- // Record multiple scenarios that produce same hash for same ops
404
- checker.record_scenario(
405
- "scenario_1".to_string(),
406
- "final_hash_v1".to_string(),
407
- vec!["op1".to_string(), "op2".to_string()],
408
- );
409
- checker.record_scenario(
410
- "scenario_2".to_string(),
411
- "final_hash_v1".to_string(),
412
- vec!["op2".to_string(), "op1".to_string()],
413
- );
414
-
415
- let result = checker.verify_determinism();
416
- assert_eq!(
417
- result,
418
- DeterminismCheckResult::Satisfied {
419
- scenarios_checked: 2
420
- }
421
- );
422
- }
423
-
424
- #[test]
425
- fn test_determinism_checker_violated() {
426
- let mut checker = PartitionDeterminismChecker::new();
427
-
428
- // Record scenarios with same ops but different hashes
429
- checker.record_scenario(
430
- "scenario_a".to_string(),
431
- "hash_a".to_string(),
432
- vec!["op1".to_string(), "op2".to_string()],
433
- );
434
- checker.record_scenario(
435
- "scenario_b".to_string(),
436
- "hash_b".to_string(),
437
- vec!["op1".to_string(), "op2".to_string()],
438
- );
439
-
440
- let result = checker.verify_determinism();
441
- assert!(matches!(result, DeterminismCheckResult::Violated { .. }));
442
- }
443
-
444
- #[test]
445
- fn test_determinism_checker_empty() {
446
- let checker = PartitionDeterminismChecker::new();
447
- let result = checker.verify_determinism();
448
- assert_eq!(result, DeterminismCheckResult::NothingToCheck);
449
- }
450
-
451
- #[test]
452
- fn test_multiple_partitions_and_reconnect() {
453
- let mut partitioned = PartitionedReplica::new();
454
-
455
- // Initial state (both get op0)
456
- partitioned.apply_to_partition_a("op0", "rec0", 0);
457
- assert_eq!(partitioned.partition_a.applied_operations.len(), 1);
458
- assert_eq!(partitioned.partition_b.applied_operations.len(), 1);
459
-
460
- // Partition
461
- partitioned.partition();
462
- partitioned.apply_to_partition_a("op1", "rec1", 10);
463
- partitioned.apply_to_partition_b("op2", "rec2", 20);
464
-
465
- // After partition: A has [op0, op1], B has [op0, op2]
466
- assert_eq!(partitioned.partition_a.applied_operations.len(), 2);
467
- assert_eq!(partitioned.partition_b.applied_operations.len(), 2);
468
-
469
- // Reconnect - now operations propagate to both
470
- partitioned.reconnect();
471
- partitioned.apply_to_partition_a("op3", "rec3", 30);
472
-
473
- // After op3 applied while connected: A has [op0, op1, op3], B has [op0, op2, op3]
474
- assert_eq!(partitioned.partition_a.applied_operations.len(), 3);
475
- assert_eq!(partitioned.partition_b.applied_operations.len(), 3);
476
-
477
- // But A still has op1 and B still has op2 (not synchronized yet)
478
- assert!(partitioned
479
- .partition_a
480
- .applied_operations
481
- .contains(&"op1".to_string()));
482
- assert!(partitioned
483
- .partition_b
484
- .applied_operations
485
- .contains(&"op2".to_string()));
486
- }
487
- }
@@ -1,166 +0,0 @@
1
- /// Peer registry module for distributed FeltDB fabric
2
- use crate::{PeerAdvertisement, PeerId};
3
- use std::collections::HashMap;
4
- use std::sync::{Arc, Mutex};
5
-
6
- /// A registry of peers in the distributed fabric
7
- #[derive(Clone)]
8
- pub struct PeerRegistry {
9
- peers: Arc<Mutex<HashMap<String, PeerAdvertisement>>>,
10
- }
11
-
12
- impl PeerRegistry {
13
- /// Create a new peer registry
14
- pub fn new() -> Self {
15
- Self {
16
- peers: Arc::new(Mutex::new(HashMap::new())),
17
- }
18
- }
19
-
20
- /// Register a peer with its advertisement
21
- pub fn register(&self, advertisement: PeerAdvertisement) -> Result<(), String> {
22
- let mut peers = self.peers.lock().map_err(|e| e.to_string())?;
23
- peers.insert(advertisement.peer_id.id.clone(), advertisement);
24
- Ok(())
25
- }
26
-
27
- /// Unregister a peer
28
- pub fn unregister(&self, peer_id: &PeerId) -> Result<Option<PeerAdvertisement>, String> {
29
- let mut peers = self.peers.lock().map_err(|e| e.to_string())?;
30
- Ok(peers.remove(&peer_id.id))
31
- }
32
-
33
- /// Get a peer's advertisement
34
- pub fn get(&self, peer_id: &PeerId) -> Result<Option<PeerAdvertisement>, String> {
35
- let peers = self.peers.lock().map_err(|e| e.to_string())?;
36
- Ok(peers.get(&peer_id.id).cloned())
37
- }
38
-
39
- /// Find all peers that provide a specific namespace
40
- pub fn peers_for_namespace(&self, namespace: &str) -> Result<Vec<PeerAdvertisement>, String> {
41
- let peers = self.peers.lock().map_err(|e| e.to_string())?;
42
- let result = peers
43
- .values()
44
- .filter(|ad| ad.provides_namespace(namespace))
45
- .cloned()
46
- .collect();
47
- Ok(result)
48
- }
49
-
50
- /// Find all peers that provide a specific capability
51
- pub fn peers_for_capability(&self, capability: &str) -> Result<Vec<PeerAdvertisement>, String> {
52
- let peers = self.peers.lock().map_err(|e| e.to_string())?;
53
- let result = peers
54
- .values()
55
- .filter(|ad| ad.provides_capability(capability))
56
- .cloned()
57
- .collect();
58
- Ok(result)
59
- }
60
-
61
- /// Get all registered peers
62
- pub fn all_peers(&self) -> Result<Vec<PeerAdvertisement>, String> {
63
- let peers = self.peers.lock().map_err(|e| e.to_string())?;
64
- Ok(peers.values().cloned().collect())
65
- }
66
-
67
- /// Get the count of registered peers
68
- pub fn peer_count(&self) -> Result<usize, String> {
69
- let peers = self.peers.lock().map_err(|e| e.to_string())?;
70
- Ok(peers.len())
71
- }
72
-
73
- /// Update a peer's advertisement
74
- pub fn update(&self, advertisement: PeerAdvertisement) -> Result<(), String> {
75
- let mut peers = self.peers.lock().map_err(|e| e.to_string())?;
76
- peers.insert(advertisement.peer_id.id.clone(), advertisement);
77
- Ok(())
78
- }
79
- }
80
-
81
- impl Default for PeerRegistry {
82
- fn default() -> Self {
83
- Self::new()
84
- }
85
- }
86
-
87
- #[cfg(test)]
88
- mod tests {
89
- use super::*;
90
- use crate::PeerAdvertisement;
91
-
92
- #[test]
93
- fn test_peer_registry_register() {
94
- let registry = PeerRegistry::new();
95
- let peer = PeerId::new("peer-a");
96
- let ad = PeerAdvertisement::new(peer.clone()).with_namespace("docs");
97
-
98
- registry.register(ad).unwrap();
99
-
100
- let retrieved = registry.get(&peer).unwrap();
101
- assert!(retrieved.is_some());
102
- assert!(retrieved.unwrap().provides_namespace("docs"));
103
- }
104
-
105
- #[test]
106
- fn test_peer_registry_peers_for_namespace() {
107
- let registry = PeerRegistry::new();
108
-
109
- let peer_a = PeerId::new("peer-a");
110
- let ad_a = PeerAdvertisement::new(peer_a).with_namespace("docs");
111
- registry.register(ad_a).unwrap();
112
-
113
- let peer_b = PeerId::new("peer-b");
114
- let ad_b = PeerAdvertisement::new(peer_b)
115
- .with_namespace("orders")
116
- .with_namespace("docs");
117
- registry.register(ad_b).unwrap();
118
-
119
- let peer_c = PeerId::new("peer-c");
120
- let ad_c = PeerAdvertisement::new(peer_c).with_namespace("embeddings");
121
- registry.register(ad_c).unwrap();
122
-
123
- let docs_peers = registry.peers_for_namespace("docs").unwrap();
124
- assert_eq!(docs_peers.len(), 2);
125
-
126
- let orders_peers = registry.peers_for_namespace("orders").unwrap();
127
- assert_eq!(orders_peers.len(), 1);
128
-
129
- let embeddings_peers = registry.peers_for_namespace("embeddings").unwrap();
130
- assert_eq!(embeddings_peers.len(), 1);
131
- }
132
-
133
- #[test]
134
- fn test_peer_registry_peers_for_capability() {
135
- let registry = PeerRegistry::new();
136
-
137
- let peer_a = PeerId::new("peer-a");
138
- let ad_a = PeerAdvertisement::new(peer_a).with_capability("search:docs");
139
- registry.register(ad_a).unwrap();
140
-
141
- let peer_b = PeerId::new("peer-b");
142
- let ad_b = PeerAdvertisement::new(peer_b)
143
- .with_capability("vector:embeddings")
144
- .with_capability("search:docs");
145
- registry.register(ad_b).unwrap();
146
-
147
- let search_peers = registry.peers_for_capability("search:docs").unwrap();
148
- assert_eq!(search_peers.len(), 2);
149
-
150
- let vector_peers = registry.peers_for_capability("vector:embeddings").unwrap();
151
- assert_eq!(vector_peers.len(), 1);
152
- }
153
-
154
- #[test]
155
- fn test_peer_registry_unregister() {
156
- let registry = PeerRegistry::new();
157
- let peer = PeerId::new("peer-a");
158
- let ad = PeerAdvertisement::new(peer.clone());
159
-
160
- registry.register(ad).unwrap();
161
- assert_eq!(registry.peer_count().unwrap(), 1);
162
-
163
- registry.unregister(&peer).unwrap();
164
- assert_eq!(registry.peer_count().unwrap(), 0);
165
- }
166
- }