@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,263 +0,0 @@
1
- /// Diagnostic utilities for investigating cardinality reconstruction issues.
2
- ///
3
- /// This module provides tools to understand how collection cardinality is reconstructed
4
- /// during startup and how it compares to query-time lookups.
5
- use crate::{AtomicMutation, FeltDb};
6
- use std::collections::HashMap;
7
-
8
- /// Diagnostic information about a single collection's cardinality.
9
- #[derive(Debug, Clone)]
10
- pub struct CardinalityDiagnostic {
11
- /// Collection name (e.g., "github_webhook_deliveries")
12
- pub collection: String,
13
-
14
- /// Capability keys actually found in persisted rows during replay_log
15
- pub persisted_capabilities: Vec<String>,
16
-
17
- /// Count of non-deleted rows found under each capability
18
- pub persisted_row_counts: HashMap<String, u64>,
19
-
20
- /// Total rows for this collection across all capability variants
21
- pub total_persisted_rows: u64,
22
-
23
- /// Maintained cardinality value stored in collection_cardinality HashMap
24
- pub maintained_count: u64,
25
-
26
- /// What capability string query execution looks for
27
- pub query_capability: String,
28
-
29
- /// Whether query_capability matches any persisted capability
30
- pub match_status: String,
31
-
32
- /// Delta between total persisted and maintained cardinality
33
- pub delta: i64,
34
- }
35
-
36
- /// Analyze the cardinality mismatch between persisted state and query-time lookups.
37
- ///
38
- /// Returns diagnostic information for collections with mismatches.
39
- ///
40
- /// # Arguments
41
- /// * `db` - The FeltDb instance
42
- /// * `state_namespace` - The state namespace from query context
43
- /// * `application_id` - The application ID
44
- /// * `collection_name` - The collection to diagnose (without namespace)
45
- pub fn diagnose_cardinality(
46
- db: &FeltDb,
47
- state_namespace: &str,
48
- application_id: &str,
49
- collection_name: &str,
50
- ) -> CardinalityDiagnostic {
51
- // What the query executor will look for
52
- let query_capability = format!("{}:{}", state_namespace, collection_name);
53
-
54
- // What the maintained cardinality HashMap contains
55
- let maintained_count = db.collection_cardinality(&query_capability).unwrap_or(0);
56
-
57
- // We can't directly inspect inner.rows from outside, but we can reason about it:
58
- // During replay_log, rows are loaded with whatever capability was in the persisted log.
59
- // If there's a mismatch, the query_capability won't find anything.
60
-
61
- CardinalityDiagnostic {
62
- collection: collection_name.to_string(),
63
- persisted_capabilities: vec![], // Would need access to inner.rows to populate
64
- persisted_row_counts: HashMap::new(),
65
- total_persisted_rows: 0, // Would need to scan inner.rows
66
- maintained_count,
67
- query_capability,
68
- match_status: if maintained_count == 0 {
69
- "MISMATCH: maintained_count is 0".to_string()
70
- } else {
71
- "OK".to_string()
72
- },
73
- delta: 0, // Can't compute without authoritative row count
74
- }
75
- }
76
-
77
- /// Create a test scenario with mixed capability formats to reproduce the issue.
78
- #[cfg(test)]
79
- mod tests {
80
- use super::*;
81
- use crate::{open, AtomicMutation};
82
- use std::fs;
83
- use std::path::PathBuf;
84
- use std::sync::atomic::{AtomicU64, Ordering};
85
- use std::time::SystemTime;
86
- use std::time::UNIX_EPOCH;
87
-
88
- static TEMP_FILE_SEQUENCE: AtomicU64 = AtomicU64::new(0);
89
-
90
- fn temp_file() -> PathBuf {
91
- let nanos = SystemTime::now()
92
- .duration_since(UNIX_EPOCH)
93
- .expect("time")
94
- .as_nanos();
95
- let sequence = TEMP_FILE_SEQUENCE.fetch_add(1, Ordering::Relaxed);
96
- std::env::temp_dir().join(format!(
97
- "feltdb-diag-{}-{nanos}-{sequence}.data",
98
- std::process::id()
99
- ))
100
- }
101
-
102
- #[test]
103
- fn test_capability_mismatch_scenario() {
104
- // This test demonstrates the hypothesis:
105
- // If rows are persisted under "collection_name" but queried as "namespace:collection_name",
106
- // cardinality will be 0 on restart.
107
-
108
- let path = temp_file();
109
-
110
- {
111
- let db = open(&path).unwrap();
112
- let capability = "github_webhook_deliveries"; // Just collection name, no namespace
113
-
114
- let mutations = vec![
115
- AtomicMutation {
116
- capability: capability.to_string(),
117
- key: "webhook-1".to_string(),
118
- value: Some(serde_json::json!({"id": 1})),
119
- },
120
- AtomicMutation {
121
- capability: capability.to_string(),
122
- key: "webhook-2".to_string(),
123
- value: Some(serde_json::json!({"id": 2})),
124
- },
125
- ];
126
-
127
- db.apply_atomic_transaction("txn-1", None, &[], &mutations, None)
128
- .unwrap();
129
-
130
- // At this point, cardinality should be 2 for the key "github_webhook_deliveries"
131
- let count = db.collection_cardinality(capability).unwrap();
132
- assert_eq!(count, 2, "Cardinality before restart");
133
- }
134
-
135
- // After restart, cardinality is recomputed
136
- let reopened = open(&path).unwrap();
137
- let capability = "github_webhook_deliveries";
138
- let count_after = reopened.collection_cardinality(capability).unwrap();
139
- assert_eq!(count_after, 2, "Cardinality after restart should match");
140
-
141
- // But if query looks for a DIFFERENT capability:
142
- let namespaced_capability = "default:github_webhook_deliveries";
143
- let count_namespaced = reopened
144
- .collection_cardinality(namespaced_capability)
145
- .unwrap();
146
-
147
- // If the persisted rows were stored under the non-namespaced key,
148
- // this will return 0 - demonstrating the mismatch
149
- println!("Rows under '{}': {}", capability, count_after);
150
- println!(
151
- "Rows under '{}': {}",
152
- namespaced_capability, count_namespaced
153
- );
154
-
155
- // This is the mismatch that causes Gate A to fail
156
- if count_namespaced != count_after {
157
- println!(
158
- "CAPABILITY MISMATCH DETECTED: {} != {}",
159
- count_after, count_namespaced
160
- );
161
- }
162
-
163
- let _ = fs::remove_file(path);
164
- }
165
-
166
- #[test]
167
- fn test_mixed_capability_formats_in_single_db() {
168
- // This test shows the exact problem:
169
- // Some rows use "app:collection", others use "namespace:collection"
170
- // Cardinality is recomputed based on what's in the persisted log
171
- // But queries might look for a different format
172
-
173
- let path = temp_file();
174
-
175
- {
176
- let db = open(&path).unwrap();
177
-
178
- // Simulate old rows stored under application_id format
179
- let app_id = "my-app";
180
- let namespace = "default";
181
- let collection = "github_webhook_deliveries";
182
-
183
- // Write rows with one format
184
- let old_format_capability = format!("{}:{}", app_id, collection);
185
- let mutations_old = vec![
186
- AtomicMutation {
187
- capability: old_format_capability.clone(),
188
- key: "old-webhook-1".to_string(),
189
- value: Some(serde_json::json!({"id": 1})),
190
- },
191
- AtomicMutation {
192
- capability: old_format_capability.clone(),
193
- key: "old-webhook-2".to_string(),
194
- value: Some(serde_json::json!({"id": 2})),
195
- },
196
- ];
197
-
198
- db.apply_atomic_transaction("txn-old", None, &[], &mutations_old, None)
199
- .unwrap();
200
-
201
- // Write rows with new format (namespace-based)
202
- let new_format_capability = format!("{}:{}", namespace, collection);
203
- let mutations_new = vec![
204
- AtomicMutation {
205
- capability: new_format_capability.clone(),
206
- key: "new-webhook-3".to_string(),
207
- value: Some(serde_json::json!({"id": 3})),
208
- },
209
- AtomicMutation {
210
- capability: new_format_capability.clone(),
211
- key: "new-webhook-4".to_string(),
212
- value: Some(serde_json::json!({"id": 4})),
213
- },
214
- ];
215
-
216
- db.apply_atomic_transaction("txn-new", None, &[], &mutations_new, None)
217
- .unwrap();
218
-
219
- // Before restart, both formats should be queryable
220
- assert_eq!(
221
- db.collection_cardinality(&old_format_capability).unwrap(),
222
- 2
223
- );
224
- assert_eq!(
225
- db.collection_cardinality(&new_format_capability).unwrap(),
226
- 2
227
- );
228
- println!("Before restart: old_format={}, new_format={}", 2, 2);
229
- }
230
-
231
- // After restart, cardinality is recomputed from persisted log
232
- let reopened = open(&path).unwrap();
233
- let old_format = format!("{}:{}", "my-app", "github_webhook_deliveries");
234
- let new_format = format!("{}:{}", "default", "github_webhook_deliveries");
235
-
236
- let old_count = reopened.collection_cardinality(&old_format).unwrap();
237
- let new_count = reopened.collection_cardinality(&new_format).unwrap();
238
-
239
- println!(
240
- "After restart: old_format={}, new_format={}",
241
- old_count, new_count
242
- );
243
- println!(
244
- "Cardinalities after restart: {}",
245
- reopened
246
- .list_cardinalities()
247
- .unwrap()
248
- .iter()
249
- .map(|(k, v)| format!("'{}': {}", k, v))
250
- .collect::<Vec<_>>()
251
- .join(", ")
252
- );
253
-
254
- // Both should still exist with their own counts
255
- assert_eq!(old_count, 2, "Old format rows should be reconstructed");
256
- assert_eq!(new_count, 2, "New format rows should be reconstructed");
257
-
258
- // But if query only looks for new_format and old data was migrated incorrectly,
259
- // the query would see 0 instead of the total.
260
-
261
- let _ = fs::remove_file(path);
262
- }
263
- }
@@ -1,77 +0,0 @@
1
- /// HTTP diagnostic endpoint for cardinality state inspection
2
- ///
3
- /// This module provides a debug/diagnostic HTTP endpoint that exposes cardinality
4
- /// reconstruction state without returning actual row data.
5
- use serde::{Deserialize, Serialize};
6
-
7
- #[derive(Debug, Clone, Serialize, Deserialize)]
8
- pub struct CardinalityDiagnosticResponse {
9
- /// Name of the collection being diagnosed
10
- pub collection_pattern: String,
11
-
12
- /// Actual row count for collections matching the pattern
13
- pub actual_row_count: usize,
14
-
15
- /// Maintained cardinality value stored in HashMap
16
- pub maintained_cardinality: u64,
17
-
18
- /// Mismatch indicator
19
- pub mismatch: bool,
20
-
21
- /// All capability keys found in HashMap that contain this pattern
22
- pub cardinality_keys: Vec<(String, u64)>,
23
-
24
- /// Context information for debugging
25
- pub context: CardinalityContext,
26
- }
27
-
28
- #[derive(Debug, Clone, Serialize, Deserialize)]
29
- pub struct CardinalityContext {
30
- /// List of all non-zero cardinalities (collection_name = count)
31
- /// Sorted by count descending
32
- pub all_cardinalities: Vec<(String, u64)>,
33
-
34
- /// Actual persisted capability strings matching pattern from inner.rows
35
- pub persisted_capability_keys: Vec<String>,
36
-
37
- /// Capability keys in cardinality HashMap matching pattern
38
- pub cardinality_map_keys: Vec<String>,
39
-
40
- /// Timestamp of diagnostic
41
- pub timestamp_ms: u64,
42
-
43
- /// Total collections with data
44
- pub total_collections: usize,
45
-
46
- /// Collections with cardinality 0
47
- pub zero_cardinality_count: usize,
48
-
49
- /// Total persisted rows across all collections
50
- pub total_rows: usize,
51
- }
52
-
53
- impl CardinalityDiagnosticResponse {
54
- pub fn new(
55
- collection_pattern: String,
56
- actual_row_count: usize,
57
- maintained_cardinality: u64,
58
- cardinality_keys: Vec<(String, u64)>,
59
- ) -> Self {
60
- Self {
61
- collection_pattern,
62
- actual_row_count,
63
- maintained_cardinality,
64
- mismatch: actual_row_count > 0 && maintained_cardinality == 0,
65
- cardinality_keys,
66
- context: CardinalityContext {
67
- all_cardinalities: vec![],
68
- persisted_capability_keys: vec![],
69
- cardinality_map_keys: vec![],
70
- timestamp_ms: 0,
71
- total_collections: 0,
72
- zero_cardinality_count: 0,
73
- total_rows: 0,
74
- },
75
- }
76
- }
77
- }