brainlayer 1.5.69__tar.gz → 1.5.71__tar.gz

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 (264) hide show
  1. {brainlayer-1.5.69 → brainlayer-1.5.71}/PKG-INFO +1 -1
  2. {brainlayer-1.5.69 → brainlayer-1.5.71}/pyproject.toml +2 -1
  3. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/hotlane_brainbar_daemon.py +29 -11
  4. {brainlayer-1.5.69 → brainlayer-1.5.71}/server.json +2 -2
  5. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/__init__.py +1 -1
  6. brainlayer-1.5.71/src/brainlayer/_build.py +1 -0
  7. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/backup_daily.py +232 -50
  8. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/badge_state.py +51 -27
  9. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/cli/__init__.py +102 -31
  10. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/cli_jobs.py +10 -1
  11. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/dedupe.py +75 -27
  12. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/drain.py +73 -20
  13. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/drive_credentials.py +3 -1
  14. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/embeddings.py +26 -3
  15. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/health_check.py +135 -11
  16. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/index_budget.py +10 -0
  17. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/index_new.py +15 -3
  18. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/maintenance_calendar.py +107 -10
  19. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/store_handler.py +7 -0
  20. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/observability_surface.py +67 -33
  21. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/queue_io.py +81 -4
  22. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/service_supervisor.py +84 -17
  23. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/store.py +29 -14
  24. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/supervisor_guard.py +15 -3
  25. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/supervisor_jobs.py +40 -0
  26. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/vector_store.py +27 -11
  27. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/watcher.py +2 -0
  28. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/watcher_bridge.py +23 -12
  29. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/writer_telemetry.py +214 -7
  30. brainlayer-1.5.69/src/brainlayer/_build.py +0 -1
  31. {brainlayer-1.5.69 → brainlayer-1.5.71}/.gitignore +0 -0
  32. {brainlayer-1.5.69 → brainlayer-1.5.71}/LICENSE +0 -0
  33. {brainlayer-1.5.69 → brainlayer-1.5.71}/README.md +0 -0
  34. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/backup-daily.sh +0 -0
  35. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/brainlayer-env-run.sh +0 -0
  36. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/brainlayer.env.example +0 -0
  37. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.backup-daily.plist +0 -0
  38. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.daemon.plist +0 -0
  39. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.decay.plist +0 -0
  40. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.drain.plist +0 -0
  41. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.health-check.plist +0 -0
  42. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.hotlane-brainbar.plist +0 -0
  43. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.index.plist +0 -0
  44. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.jsonl-backup.plist +0 -0
  45. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.log-cap.plist +0 -0
  46. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.maintenance-nightly.plist +0 -0
  47. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.maintenance-weekly.plist +0 -0
  48. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.maintenance.plist +0 -0
  49. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.observability.plist +0 -0
  50. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.p0-counter.plist +0 -0
  51. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.repair-fts.plist +0 -0
  52. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.t3-ingest.plist +0 -0
  53. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.throughput-watchdog.plist +0 -0
  54. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.tier0-watchdog.plist +0 -0
  55. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.wal-checkpoint.plist +0 -0
  56. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.brainlayer.watch.plist +0 -0
  57. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/com.etanhey.brainlayer-fleet-watchdog.plist +0 -0
  58. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/fleet-watchdog.sh +0 -0
  59. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/install.sh +0 -0
  60. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/jsonl-backup.sh +0 -0
  61. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/launchd/throughput-watchdog.py +0 -0
  62. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/release-verify-signatures.sh +0 -0
  63. {brainlayer-1.5.69 → brainlayer-1.5.71}/scripts/tier0-watchdog.sh +0 -0
  64. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/__main__.py +0 -0
  65. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/_helpers.py +0 -0
  66. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/agent_profiles.py +0 -0
  67. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/agent_provenance.py +0 -0
  68. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/alarm.py +0 -0
  69. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/archive_collapse.py +0 -0
  70. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/archive_lifecycle.py +0 -0
  71. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/backup_retention_invariant.py +0 -0
  72. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/bitemporal.py +0 -0
  73. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/brainbar_activation.py +0 -0
  74. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/brainbar_auto_activation.py +0 -0
  75. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/brainbar_hybrid_helper.py +0 -0
  76. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/brainbar_identity.py +0 -0
  77. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/cachedelete_purge.swift +0 -0
  78. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/calibrate.py +0 -0
  79. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/chunk_origin.py +0 -0
  80. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/chunk_origin_backfill.py +0 -0
  81. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/chunk_origin_wipe.py +0 -0
  82. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/chunk_write.py +0 -0
  83. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/classify.py +0 -0
  84. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/claude_paths.py +0 -0
  85. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/cli/wizard.py +0 -0
  86. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/cli_new.py +0 -0
  87. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/cloud_backfill.py +0 -0
  88. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/clustering.py +0 -0
  89. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/component_jobs.py +0 -0
  90. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/config.py +0 -0
  91. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/consolidation_plan.py +0 -0
  92. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/content_class.py +0 -0
  93. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/correction_judge.py +0 -0
  94. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/data/agents_registry.yaml +0 -0
  95. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/data/sandbox_seeds/skill-eval-baseline.json +0 -0
  96. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/db_shrink.py +0 -0
  97. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/decay.py +0 -0
  98. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/decay_backfill.py +0 -0
  99. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/decay_job.py +0 -0
  100. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/dedupe_merge.py +0 -0
  101. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/deploy_drift.py +0 -0
  102. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/doctor.py +0 -0
  103. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/drain_liveness.py +0 -0
  104. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/engine.py +0 -0
  105. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/enrichment_replay.py +0 -0
  106. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/__init__.py +0 -0
  107. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/abcde_enrich_runner.py +0 -0
  108. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/abcde_variants.py +0 -0
  109. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/abcde_variants.yaml +0 -0
  110. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/benchmark.py +0 -0
  111. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/enrichment_gold.py +0 -0
  112. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/enrichment_graders.py +0 -0
  113. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/enrichment_judge.py +0 -0
  114. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/enrichment_llm_judge.py +0 -0
  115. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/enrichment_quality_benchmark.py +0 -0
  116. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/experiment_store.py +0 -0
  117. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/fixtures/README.md +0 -0
  118. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/labeling/enrichment-labeler.html +0 -0
  119. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/__init__.py +0 -0
  120. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/__main__.py +0 -0
  121. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/baseline_store.py +0 -0
  122. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/cli.py +0 -0
  123. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/models.py +0 -0
  124. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/phoenix_client.py +0 -0
  125. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/regression_gate.py +0 -0
  126. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/phoenix_gate/triggers.py +0 -0
  127. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/eval/pilot_artifact_report.py +0 -0
  128. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/fallback_replay.py +0 -0
  129. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/git_learning.py +0 -0
  130. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/hook_python.py +0 -0
  131. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/hooks/__init__.py +0 -0
  132. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/hooks/indexer.py +0 -0
  133. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/import_sweep.py +0 -0
  134. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/index_admission.py +0 -0
  135. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/index_completeness.py +0 -0
  136. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/index_watchdog.py +0 -0
  137. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/ingest/__init__.py +0 -0
  138. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/ingest/codex.py +0 -0
  139. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/ingest/t3.py +0 -0
  140. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/ingest_denylist.py +0 -0
  141. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/ingest_guard.py +0 -0
  142. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/isolation_proof.py +0 -0
  143. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/job_alerts.py +0 -0
  144. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/job_lifecycle_health.py +0 -0
  145. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/jobs.py +0 -0
  146. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/jsonl_backup.py +0 -0
  147. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg/__init__.py +0 -0
  148. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_cleanup.py +0 -0
  149. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_judge.py +0 -0
  150. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_promotion.py +0 -0
  151. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_repo.py +0 -0
  152. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_review_session.py +0 -0
  153. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_session_finish.py +0 -0
  154. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/kg_session_harvest.py +0 -0
  155. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/launchd_consolidation.py +0 -0
  156. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/launchd_install.py +0 -0
  157. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/launchd_primitive.py +0 -0
  158. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/launchd_revert.py +0 -0
  159. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/lexical_defense.py +0 -0
  160. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/lexical_defense_dictionary.json +0 -0
  161. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/log_cap.py +0 -0
  162. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/maintenance.py +0 -0
  163. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/maintenance_control.py +0 -0
  164. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/__init__.py +0 -0
  165. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/_format.py +0 -0
  166. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/_shared.py +0 -0
  167. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/enrich_handler.py +0 -0
  168. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/entity_handler.py +0 -0
  169. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/palette.py +0 -0
  170. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/search_handler.py +0 -0
  171. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp/tags_handler.py +0 -0
  172. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp_socket_config.py +0 -0
  173. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/mcp_stdio_bridge.py +0 -0
  174. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/memory_types.py +0 -0
  175. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/migrate.py +0 -0
  176. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/migration_custody.py +0 -0
  177. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/migration_journal.py +0 -0
  178. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/migration_runtime.py +0 -0
  179. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/notification_policy.py +0 -0
  180. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/observability_backup.py +0 -0
  181. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/observability_transport.py +0 -0
  182. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/p0_longitudinal_count.py +0 -0
  183. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/parent_death.py +0 -0
  184. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/paths.py +0 -0
  185. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pause.py +0 -0
  186. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/phonetic.py +0 -0
  187. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/__init__.py +0 -0
  188. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/agent_enrichment.py +0 -0
  189. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/analyze_communication.py +0 -0
  190. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/batch_extraction.py +0 -0
  191. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/brain_graph.py +0 -0
  192. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/chat_tags.py +0 -0
  193. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/chunk.py +0 -0
  194. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/classify.py +0 -0
  195. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/cloud_scrub.py +0 -0
  196. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/cluster_sampling.py +0 -0
  197. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/code_intelligence.py +0 -0
  198. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/correction_detection.py +0 -0
  199. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/correction_mining.py +0 -0
  200. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/digest.py +0 -0
  201. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/enrichment_prompts.py +0 -0
  202. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/enrichment_results.py +0 -0
  203. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/enrichment_tiers.py +0 -0
  204. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/entity_extraction.py +0 -0
  205. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/entity_resolution.py +0 -0
  206. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/extract.py +0 -0
  207. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/extract_claude_desktop.py +0 -0
  208. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/extract_corrections.py +0 -0
  209. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/extract_markdown.py +0 -0
  210. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/extract_whatsapp.py +0 -0
  211. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/frustration_mining.py +0 -0
  212. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/git_overlay.py +0 -0
  213. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/kg_extraction.py +0 -0
  214. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/kg_extraction_groq.py +0 -0
  215. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/longitudinal_analyzer.py +0 -0
  216. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/obsidian_export.py +0 -0
  217. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/operation_grouping.py +0 -0
  218. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/plan_linking.py +0 -0
  219. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/rate_limiter.py +0 -0
  220. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/relation_backfill.py +0 -0
  221. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/relation_verification.py +0 -0
  222. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/sanitize.py +0 -0
  223. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/secret_scrub.py +0 -0
  224. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/semantic_style.py +0 -0
  225. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/sentiment.py +0 -0
  226. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/session_history.py +0 -0
  227. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/style_embed.py +0 -0
  228. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/style_index.py +0 -0
  229. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/tag_entity_promotion.py +0 -0
  230. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/temporal_chains.py +0 -0
  231. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/time_batcher.py +0 -0
  232. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/unified_timeline.py +0 -0
  233. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/pipeline/write_queue.py +0 -0
  234. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/provenance.py +0 -0
  235. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/provenance_autosupersede.py +0 -0
  236. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/provenance_integration.py +0 -0
  237. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/queue_merge.py +0 -0
  238. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/reembed_backfill.py +0 -0
  239. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/retired_services.py +0 -0
  240. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/runtime_store.py +0 -0
  241. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/sandbox_db.py +0 -0
  242. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/scoping.py +0 -0
  243. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/scrub_at_rest.py +0 -0
  244. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/search_fanout.py +0 -0
  245. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/search_profile.py +0 -0
  246. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/search_repo.py +0 -0
  247. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/session_repo.py +0 -0
  248. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/setup.py +0 -0
  249. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/socket_hygiene.py +0 -0
  250. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/source_class_migration.py +0 -0
  251. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/spotlight.py +0 -0
  252. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/storage.py +0 -0
  253. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/supervisor_adapters.py +0 -0
  254. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/supervisor_child.py +0 -0
  255. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/system_prompt_guard.py +0 -0
  256. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/t3_linkage_alarm.py +0 -0
  257. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/t3_provenance.py +0 -0
  258. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/t3_sources.py +0 -0
  259. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/tag_normalization.py +0 -0
  260. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/taxonomy.json +0 -0
  261. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/telemetry.py +0 -0
  262. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/timestamp_iso.py +0 -0
  263. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/types.py +0 -0
  264. {brainlayer-1.5.69 → brainlayer-1.5.71}/src/brainlayer/wal_checkpoint.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: brainlayer
3
- Version: 1.5.69
3
+ Version: 1.5.71
4
4
  Summary: Persistent local memory for AI agents — 16 BrainBar MCP tools, semantic search, knowledge graph, SQLite
5
5
  Project-URL: Homepage, https://brainlayer.etanheyman.com
6
6
  Project-URL: Repository, https://github.com/EtanHey/brainlayer
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "brainlayer"
3
- version = "1.5.69"
3
+ version = "1.5.71"
4
4
  description = "Persistent local memory for AI agents — 16 BrainBar MCP tools, semantic search, knowledge graph, SQLite"
5
5
  license = {text = "Apache-2.0"}
6
6
  readme = "README.md"
@@ -124,6 +124,7 @@ norecursedirs = ["*.egg", ".*", "_darcs", "build", "CVS", "dist", "node_modules"
124
124
  # tests/conftest.py routes default and explicit basetemps beneath <worktree>/.build.noindex/pytest/ before fixtures start.
125
125
  tmp_path_retention_policy = "failed"
126
126
  markers = [
127
+ "recovery_oracle: disposable seeded queue, SQLite, FTS and vector recovery acceptance gate",
127
128
  "crash_sweep: exhaustive migration/revert SIGKILL cuts (separate required CI gate; retained by local pre-push)",
128
129
  "retired_enrichment: retirement tests that forbid cloud-client construction and inet sends",
129
130
  "engine: pure-library engine tests (excludes CLI, dashboard, BrainBar, launchd, and root orchestration surfaces)",
@@ -11,6 +11,7 @@ from __future__ import annotations
11
11
 
12
12
  import argparse
13
13
  import inspect
14
+ import json
14
15
  import logging
15
16
  import os
16
17
  import signal
@@ -27,7 +28,7 @@ from brainlayer.embeddings import get_embedding_model
27
28
  from brainlayer.paths import get_db_path
28
29
  from brainlayer.store import embed_hot_chunk, embed_pending_chunks
29
30
  from brainlayer.vector_store import VectorStore
30
- from brainlayer.writer_telemetry import start_writer_span
31
+ from brainlayer.writer_telemetry import IngestMetrics, start_writer_span
31
32
 
32
33
  LOGGER = logging.getLogger("brainlayer.hotlane_brainbar")
33
34
  STOP = False
@@ -619,6 +620,7 @@ def _write_embedded_vectors(store_or_path: VectorStore | Path | str, vectors: li
619
620
  count = 0
620
621
  try:
621
622
  for vector_index, (chunk_id, content, embedding) in enumerate(vectors):
623
+ metrics = IngestMetrics("hotlane", "vector")
622
624
  transaction_started = False
623
625
  telemetry_span = start_writer_span(
624
626
  cursor.connection if hasattr(cursor, "connection") else (conn or store.conn),
@@ -629,11 +631,13 @@ def _write_embedded_vectors(store_or_path: VectorStore | Path | str, vectors: li
629
631
  rows_planned=1,
630
632
  )
631
633
  try:
632
- cursor.execute("BEGIN IMMEDIATE")
634
+ metrics.run("begin", cursor.execute, "BEGIN IMMEDIATE")
633
635
  transaction_started = True
634
- still_eligible = cursor.execute(
636
+ still_eligible = metrics.run(
637
+ "apply",
638
+ cursor.execute,
635
639
  """
636
- SELECT 1
640
+ SELECT 1, c.metadata
637
641
  FROM chunks c
638
642
  LEFT JOIN chunk_vectors_rowids r ON c.id = r.id
639
643
  WHERE c.id = ?
@@ -649,10 +653,18 @@ def _write_embedded_vectors(store_or_path: VectorStore | Path | str, vectors: li
649
653
  ).fetchone()
650
654
  rows_touched = 0
651
655
  if still_eligible:
652
- upsert_chunk_vector(cursor, chunk_id, embedding)
656
+ metrics.run("apply", upsert_chunk_vector, cursor, chunk_id, embedding)
653
657
  rows_touched = 1
654
- cursor.execute("COMMIT")
658
+ metrics.run("commit", cursor.execute, "COMMIT")
655
659
  transaction_started = False
660
+ if rows_touched:
661
+ try:
662
+ metadata = json.loads(still_eligible[1]) if len(still_eligible) > 1 else {}
663
+ except (TypeError, ValueError):
664
+ metadata = {}
665
+ metadata = metadata if isinstance(metadata, dict) else {}
666
+ metrics.committed([{"queued_at": metadata.get("ingest_queued_at"), "metadata": metadata}])
667
+ metrics.finish("commit")
656
668
  count += rows_touched
657
669
  telemetry_span.finish("commit", rows_touched=rows_touched)
658
670
  if vector_index < len(vectors) - 1:
@@ -660,6 +672,7 @@ def _write_embedded_vectors(store_or_path: VectorStore | Path | str, vectors: li
660
672
  except Exception as exc:
661
673
  if transaction_started:
662
674
  cursor.execute("ROLLBACK")
675
+ metrics.finish("error")
663
676
  telemetry_span.finish("rollback", error=f"{type(exc).__name__}: {exc}")
664
677
  if isinstance(exc, (apsw.BusyError, apsw.LockedError)):
665
678
  raise
@@ -739,6 +752,7 @@ def _run_split_cycle(
739
752
  pending_rows_fn: Callable[..., list[EmbedCandidate]] = _pending_chunk_rows_with_resume,
740
753
  write_vectors_fn: Callable[..., int] = _write_embedded_vectors,
741
754
  ) -> CycleResult:
755
+ metrics = IngestMetrics("hotlane", "hotlane")
742
756
  embedded = 0
743
757
  hot_rows: list[EmbedCandidate] = []
744
758
  pending_rows: list[EmbedCandidate] = []
@@ -756,19 +770,21 @@ def _run_split_cycle(
756
770
  read_store = _open_store(vector_store_cls, db_path, readonly=True)
757
771
  try:
758
772
  if recent_limit > 0:
759
- hot_rows = candidate_rows_fn(read_store, limit=recent_limit)
773
+ hot_rows = metrics.run("candidate", candidate_rows_fn, read_store, limit=recent_limit)
760
774
  if backlog_batch > 0:
761
- pending_rows = pending_rows_fn(read_store, limit=backlog_batch)
775
+ pending_rows = metrics.run("candidate", pending_rows_fn, read_store, limit=backlog_batch)
762
776
  finally:
763
777
  read_store.close()
764
778
 
765
779
  seen_hot_ids = {candidate.chunk_id for candidate in hot_rows}
766
780
  pending_rows = [candidate for candidate in pending_rows if candidate.chunk_id not in seen_hot_ids]
767
- vectors = _embed_candidates(hot_rows, embed_fn=embed_fn, embed_batch_fn=embed_batch_fn)
768
- vectors.extend(_embed_candidates(pending_rows, embed_fn=embed_fn, embed_batch_fn=embed_batch_fn))
781
+ vectors = metrics.run("encode", _embed_candidates, hot_rows, embed_fn=embed_fn, embed_batch_fn=embed_batch_fn)
782
+ vectors.extend(
783
+ metrics.run("encode", _embed_candidates, pending_rows, embed_fn=embed_fn, embed_batch_fn=embed_batch_fn)
784
+ )
769
785
  if vectors:
770
786
  try:
771
- embedded += write_vectors_fn(db_path, vectors)
787
+ embedded += metrics.run("write", write_vectors_fn, db_path, vectors)
772
788
  except Exception as exc:
773
789
  is_lock_error = isinstance(exc, (apsw.BusyError, apsw.LockedError))
774
790
  if is_lock_error and pending_scan_checkpoint is not None and pending_scan_state is not None:
@@ -782,9 +798,11 @@ def _run_split_cycle(
782
798
  [candidate.chunk_id for candidate in pending_rows],
783
799
  type(exc).__name__,
784
800
  )
801
+ metrics.finish("error")
785
802
  raise
786
803
 
787
804
  _warn_retired_enrichment(enrich_limit, enrich_since_hours, enrich_fn)
805
+ metrics.finish()
788
806
  return CycleResult(embedded=embedded)
789
807
 
790
808
 
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.etanhey/brainlayer",
4
4
  "title": "BrainLayer",
5
5
  "description": "Persistent local memory for AI agents \u2014 semantic search, knowledge graph, and 16 BrainBar MCP tools with ToolAnnotations over SQLite.",
6
- "version": "1.5.69",
6
+ "version": "1.5.71",
7
7
  "websiteUrl": "https://brainlayer.etanheyman.com",
8
8
  "repository": {
9
9
  "url": "https://github.com/EtanHey/brainlayer",
@@ -14,7 +14,7 @@
14
14
  "registryType": "pypi",
15
15
  "registryBaseUrl": "https://pypi.org",
16
16
  "identifier": "brainlayer",
17
- "version": "1.5.69",
17
+ "version": "1.5.71",
18
18
  "runtimeHint": "pipx",
19
19
  "transport": {
20
20
  "type": "stdio"
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- __version__ = "1.5.69"
5
+ __version__ = "1.5.71"
6
6
  # Git sha the distributed package was built from; stamped by the release build, None in a source tree.
7
7
  # scripts/sprint_gate.py reads it in "keg" mode to prove the served package is the code under test.
8
8
  # No runtime `str | None` annotation: launchd/install.sh imports this under /usr/bin/python3 (3.9).
@@ -0,0 +1 @@
1
+ BUILD_SHA = "bdd90a907a55d35bba00b0618e2458dd21249c2d"
@@ -40,7 +40,7 @@ from urllib.parse import urlsplit
40
40
  import requests
41
41
 
42
42
  from . import drive_credentials
43
- from .paths import get_db_path
43
+ from .paths import get_db_path, resolve_db_path
44
44
  from .socket_hygiene import refuse_production_brainbar_socket
45
45
 
46
46
  _sleep = time.sleep
@@ -397,6 +397,33 @@ class BrainBarSnapshotBusyError(RuntimeError):
397
397
  BRAINBAR_SNAPSHOT_BUSY_MESSAGE = "A BrainBar backup snapshot is already in progress."
398
398
 
399
399
 
400
+ class BrainBarDatabaseIdentityError(RuntimeError):
401
+ """BrainBar serves a different database than the one this backup was aimed at."""
402
+
403
+
404
+ # MCPRouter.handleBrainBackupVacuumInto refuses with this before any VACUUM INTO when the
405
+ # request's expected_db_path does not identify the database BrainBar serves.
406
+ BRAINBAR_DB_IDENTITY_MISMATCH = "BrainBar database identity mismatch"
407
+
408
+
409
+ class BackupTargetConflictError(FileExistsError):
410
+ """A peer's dated raw appeared while this run's snapshot ran; it is never replaced."""
411
+
412
+
413
+ def _file_identity(path: str | os.PathLike[str]) -> tuple[int, int] | None:
414
+ try:
415
+ info = os.stat(path)
416
+ except OSError:
417
+ return None
418
+ return info.st_dev, info.st_ino
419
+
420
+
421
+ def _same_database_file(a: str | os.PathLike[str], b: str | os.PathLike[str]) -> bool:
422
+ """Both paths exist and name the same dev/inode; a missing path never matches."""
423
+ identity = _file_identity(a)
424
+ return identity is not None and identity == _file_identity(b)
425
+
426
+
400
427
  def _is_brainbar_snapshot_busy(response: dict[str, Any]) -> bool:
401
428
  error = response.get("error")
402
429
  return isinstance(error, dict) and error.get("message") == BRAINBAR_SNAPSHOT_BUSY_MESSAGE
@@ -1113,6 +1140,52 @@ def _copy_with_raw_floor(source: Any, destination: Any, output_dir: Path) -> Non
1113
1140
  _require_raw_floor(output_dir)
1114
1141
 
1115
1142
 
1143
+ def _refuse_foreign_db_on_production_socket(db_path: Path, socket_path: Path | str | None) -> None:
1144
+ """The production BrainBar serves the configured DB; never aim it at any other one.
1145
+
1146
+ 2026-10-19: an ad-hoc probe outside pytest passed a temp db_path with no socket, fell
1147
+ through to /tmp/brainbar.sock, and received a 20 GB production copy. Pass an isolated
1148
+ socket_path (or BRAINBAR_SOCKET_PATH) to back up a different database.
1149
+ """
1150
+ resolved_socket = _brainbar_socket_path(socket_path)
1151
+ if os.path.realpath(resolved_socket) != os.path.realpath(DEFAULT_BRAINBAR_SOCKET_PATH):
1152
+ return
1153
+ configured_db = resolve_db_path()
1154
+ if not _same_database_file(db_path, configured_db):
1155
+ raise BrainBarDatabaseIdentityError(
1156
+ f"{BRAINBAR_DB_IDENTITY_MISMATCH}: refusing to snapshot {db_path} through the production BrainBar "
1157
+ f"socket {resolved_socket}, which serves the configured database {configured_db}; "
1158
+ "pass an isolated socket_path to back up any other database"
1159
+ )
1160
+
1161
+
1162
+ def _remove_owned_raw(raw: Path, owned: tuple[int, int]) -> None:
1163
+ """Remove raw only if it is still the file this run promoted.
1164
+
1165
+ The rename aside is atomic, so the inode checked is the inode removed. A peer's file that
1166
+ took the name is linked back create-exclusive, or left aside and reported, never deleted.
1167
+ """
1168
+ aside = raw.with_name(f".{raw.name}.orphan-{uuid.uuid4().hex}")
1169
+ try:
1170
+ os.rename(raw, aside)
1171
+ except FileNotFoundError:
1172
+ return
1173
+ captured = os.lstat(aside)
1174
+ if (captured.st_dev, captured.st_ino) == owned:
1175
+ aside.unlink()
1176
+ print(f"Backup removed unverified raw from non-canonical staging: {raw}", flush=True)
1177
+ return
1178
+ try:
1179
+ os.link(aside, raw)
1180
+ aside.unlink()
1181
+ except FileExistsError:
1182
+ print(f"Backup left a peer's raw aside, its name was retaken: {aside}", flush=True)
1183
+
1184
+
1185
+ def _is_canonical_staging(output_dir: Path) -> bool:
1186
+ return os.path.realpath(output_dir) == os.path.realpath(Path(DEFAULT_STAGING_DIR).expanduser())
1187
+
1188
+
1116
1189
  def _snapshot_suffix(name: str) -> str | None:
1117
1190
  """The compressed-snapshot suffix of `name`, or None for anything else."""
1118
1191
  return next((suffix for suffix in DB_SNAPSHOT_SUFFIXES if name.endswith(suffix)), None)
@@ -1279,6 +1352,7 @@ def create_sqlite_backup_artifact(
1279
1352
 
1280
1353
  if not db_path.exists():
1281
1354
  raise FileNotFoundError(f"BrainLayer database not found: {db_path}")
1355
+ _refuse_foreign_db_on_production_socket(db_path, socket_path)
1282
1356
 
1283
1357
  output_dir.mkdir(parents=True, exist_ok=True)
1284
1358
  if _parse_uncompressed_snapshot_date(f"{date_stamp}.db") is None or output_dir.is_symlink():
@@ -1398,47 +1472,64 @@ def create_sqlite_backup_artifact(
1398
1472
  if final_raw.exists() or final_raw.is_symlink():
1399
1473
  raise FileExistsError(f"Retaining existing raw snapshot without a verified archive: {final_raw}")
1400
1474
 
1401
- with tempfile.TemporaryDirectory(prefix="brainlayer-backup-", dir=output_dir) as tmp:
1402
- (Path(tmp) / ".backup-date").write_text(date_stamp, encoding="ascii")
1403
- raw_snapshot = final_raw
1404
- snapshot_created_at = dt.datetime.now(dt.UTC).isoformat()
1405
- request_brainbar_vacuum_into(
1406
- raw_snapshot,
1407
- socket_path=socket_path,
1408
- attempt_dir=output_dir,
1409
- retry_capacity_check=require_retry_capacity,
1410
- )
1411
- _require_raw_floor(output_dir)
1412
- sentinel_chunks = _validate_backup_target(raw_snapshot)
1413
- pragma = (
1414
- "integrity_check"
1415
- if (integrity_full if integrity_full is not None else _should_run_full_verify(date_stamp))
1416
- else "quick_check"
1417
- )
1418
- integrity_started = time.monotonic()
1419
- try:
1420
- integrity = _sqlite_pragma_check(raw_snapshot, pragma)
1421
- except sqlite3.Error as exc:
1422
- integrity = f"{type(exc).__name__}: {exc}"
1423
- integrity_duration = time.monotonic() - integrity_started
1424
- if integrity_status_callback is not None:
1425
- integrity_status_callback(integrity, pragma, integrity_duration)
1426
- if integrity != "ok":
1427
- raise RuntimeError(f"Raw snapshot {pragma} failed: {integrity}; retaining raw snapshot")
1428
-
1429
- temp_archive = Path(tmp) / final_archive.name
1430
- compress_started = time.monotonic()
1431
- if zstd_binary is not None:
1432
- _compress_zstd(zstd_binary, raw_snapshot, temp_archive, output_dir)
1433
- else:
1434
- with raw_snapshot.open("rb") as src, gzip.open(temp_archive, "wb", compresslevel=6) as dst:
1435
- _copy_with_raw_floor(src, dst, output_dir)
1436
- compress_duration = time.monotonic() - compress_started
1437
- shutil.move(str(temp_archive), final_archive)
1438
- print(f"Backup compressed: compressor={compressor} seconds={compress_duration:.1f}", flush=True)
1439
-
1440
- _remove_raw_with_verified_archive(output_dir, final_raw, own_run=True, archive_name=final_archive.name)
1441
- deleted.append(final_raw.name)
1475
+ # A raw this run promoted into non-canonical (temp/test/harness) staging is removed if the run
1476
+ # exits before verification: nothing else ever reclaims it there (2026-10-19, 19 GiB in $TMPDIR).
1477
+ # Ownership is the promoted dev/inode, never the dated name: a peer's raw is never touched.
1478
+ orphan_cleanup = not _is_canonical_staging(output_dir)
1479
+ raw_settled = False
1480
+ owned_raw: tuple[int, int] | None = None
1481
+ try:
1482
+ with tempfile.TemporaryDirectory(prefix="brainlayer-backup-", dir=output_dir) as tmp:
1483
+ (Path(tmp) / ".backup-date").write_text(date_stamp, encoding="ascii")
1484
+ raw_snapshot = final_raw
1485
+ snapshot_created_at = dt.datetime.now(dt.UTC).isoformat()
1486
+ promoted = request_brainbar_vacuum_into(
1487
+ raw_snapshot,
1488
+ socket_path=socket_path,
1489
+ attempt_dir=output_dir,
1490
+ retry_capacity_check=require_retry_capacity,
1491
+ expected_db_path=db_path,
1492
+ )
1493
+ if isinstance(promoted, os.stat_result):
1494
+ owned_raw = (promoted.st_dev, promoted.st_ino)
1495
+ _require_raw_floor(output_dir)
1496
+ sentinel_chunks = _validate_backup_target(raw_snapshot)
1497
+ pragma = (
1498
+ "integrity_check"
1499
+ if (integrity_full if integrity_full is not None else _should_run_full_verify(date_stamp))
1500
+ else "quick_check"
1501
+ )
1502
+ integrity_started = time.monotonic()
1503
+ try:
1504
+ integrity = _sqlite_pragma_check(raw_snapshot, pragma)
1505
+ except sqlite3.Error as exc:
1506
+ integrity = f"{type(exc).__name__}: {exc}"
1507
+ integrity_duration = time.monotonic() - integrity_started
1508
+ if integrity_status_callback is not None:
1509
+ integrity_status_callback(integrity, pragma, integrity_duration)
1510
+ # Past this point a raw is either verified or retained on purpose; the existing
1511
+ # retained-raw rules own it, never the orphan cleanup below.
1512
+ raw_settled = True
1513
+ if integrity != "ok":
1514
+ raise RuntimeError(f"Raw snapshot {pragma} failed: {integrity}; retaining raw snapshot")
1515
+
1516
+ temp_archive = Path(tmp) / final_archive.name
1517
+ compress_started = time.monotonic()
1518
+ if zstd_binary is not None:
1519
+ _compress_zstd(zstd_binary, raw_snapshot, temp_archive, output_dir)
1520
+ else:
1521
+ with raw_snapshot.open("rb") as src, gzip.open(temp_archive, "wb", compresslevel=6) as dst:
1522
+ _copy_with_raw_floor(src, dst, output_dir)
1523
+ compress_duration = time.monotonic() - compress_started
1524
+ shutil.move(str(temp_archive), final_archive)
1525
+ print(f"Backup compressed: compressor={compressor} seconds={compress_duration:.1f}", flush=True)
1526
+
1527
+ _remove_raw_with_verified_archive(output_dir, final_raw, own_run=True, archive_name=final_archive.name)
1528
+ deleted.append(final_raw.name)
1529
+ except BaseException:
1530
+ if orphan_cleanup and not raw_settled and owned_raw is not None:
1531
+ _remove_owned_raw(final_raw, owned_raw)
1532
+ raise
1442
1533
 
1443
1534
  return SQLiteBackupArtifact(
1444
1535
  gzip_path=final_archive,
@@ -1478,6 +1569,33 @@ def _brainbar_socket_path(socket_path: Path | str | None = None) -> Path:
1478
1569
  return Path(os.environ.get("BRAINBAR_SOCKET_PATH", DEFAULT_BRAINBAR_SOCKET_PATH)).expanduser()
1479
1570
 
1480
1571
 
1572
+ def _completed_attempt_ownership(path: Path) -> tuple[tuple[int, int], tuple[int, int]] | None:
1573
+ """Accept only a writer receipt binding this attempt name to its created raw inode."""
1574
+ marker = _backup_attempt_completion_marker(path)
1575
+ try:
1576
+ descriptor = os.open(marker, os.O_RDONLY | os.O_CLOEXEC | os.O_NOFOLLOW | os.O_NONBLOCK)
1577
+ with os.fdopen(descriptor, "rb") as stream:
1578
+ marker_info = os.fstat(stream.fileno())
1579
+ if not stat.S_ISREG(marker_info.st_mode) or marker_info.st_size > 4096:
1580
+ return None
1581
+ receipt = json.loads(stream.read(4097))
1582
+ raw_info = path.lstat()
1583
+ if (
1584
+ marker.is_symlink()
1585
+ or not stat.S_ISREG(raw_info.st_mode)
1586
+ or not isinstance(receipt, dict)
1587
+ or type(receipt.get("schema_version")) is not int
1588
+ or receipt["schema_version"] != 1
1589
+ or receipt.get("target_path") != os.path.abspath(path)
1590
+ or any(type(receipt.get(key)) is not int for key in ("target_dev", "target_ino"))
1591
+ or (receipt["target_dev"], receipt["target_ino"]) != (raw_info.st_dev, raw_info.st_ino)
1592
+ ):
1593
+ return None
1594
+ return (raw_info.st_dev, raw_info.st_ino), (marker_info.st_dev, marker_info.st_ino)
1595
+ except (OSError, ValueError, UnicodeError):
1596
+ return None
1597
+
1598
+
1481
1599
  def request_brainbar_vacuum_into(
1482
1600
  target_path: Path,
1483
1601
  socket_path: Path | str | None = None,
@@ -1486,8 +1604,21 @@ def request_brainbar_vacuum_into(
1486
1604
  retry_backoff_seconds: int = 60,
1487
1605
  attempt_dir: Path | None = None,
1488
1606
  retry_capacity_check: Callable[[list[Path]], None] | None = None,
1489
- ) -> None:
1607
+ expected_db_path: Path | str | None = None,
1608
+ ) -> os.stat_result:
1609
+ """Ask BrainBar to VACUUM INTO an attempt path, then promote it to target_path.
1610
+
1611
+ Promotion is create-exclusive and returns the stat of the promoted file, which is how a
1612
+ caller proves later that a raw at target_path is still the one this run created.
1613
+
1614
+ With expected_db_path, BrainBar must serve exactly that database: it refuses a mismatch
1615
+ before any VACUUM, and a response that does not confirm the same file (an older BrainBar
1616
+ ignores the argument) is deleted and refused. Identity refusals never retry.
1617
+ """
1490
1618
  target_path = Path(target_path).expanduser()
1619
+ resolved_expected_db = (
1620
+ os.path.realpath(Path(expected_db_path).expanduser()) if expected_db_path is not None else None
1621
+ )
1491
1622
  if max_attempts < 1:
1492
1623
  raise ValueError("max_attempts must be at least 1")
1493
1624
  if target_path.exists():
@@ -1502,7 +1633,16 @@ def request_brainbar_vacuum_into(
1502
1633
  resolved_attempt_dir.mkdir(parents=True, exist_ok=True)
1503
1634
  last_error: Exception | None = None
1504
1635
  unconfirmed_attempt_paths: list[Path] = []
1636
+ completed_attempts: dict[Path, tuple[tuple[int, int], tuple[int, int]]] = {}
1505
1637
  for attempt in range(1, max_attempts + 1):
1638
+ for prior_path in unconfirmed_attempt_paths:
1639
+ if prior_path in completed_attempts:
1640
+ continue
1641
+ ownership = _completed_attempt_ownership(prior_path)
1642
+ if ownership is not None:
1643
+ completed_attempts[prior_path] = ownership
1644
+ else:
1645
+ print(f"Backup retaining attempt without writer-bound ownership: {prior_path}", flush=True)
1506
1646
  if attempt > 1 and retry_capacity_check is not None:
1507
1647
  # Re-measure before every retry: an unresolved request may still grow to full size
1508
1648
  # beside the next one, even if its target has not appeared yet.
@@ -1514,7 +1654,10 @@ def request_brainbar_vacuum_into(
1514
1654
  "method": "tools/call",
1515
1655
  "params": {
1516
1656
  "name": "brain_backup_vacuum_into",
1517
- "arguments": {"target_path": str(attempt_path)},
1657
+ "arguments": {
1658
+ "target_path": str(attempt_path),
1659
+ **({"expected_db_path": resolved_expected_db} if resolved_expected_db else {}),
1660
+ },
1518
1661
  },
1519
1662
  }
1520
1663
  terminal_response_received = False
@@ -1539,10 +1682,32 @@ def request_brainbar_vacuum_into(
1539
1682
  if response.get("error"):
1540
1683
  raise RuntimeError(f"BrainBar backup request failed: {response['error']}")
1541
1684
  result = response.get("result") or {}
1685
+ content = result.get("content") or []
1686
+ text = content[0].get("text") if content and isinstance(content[0], dict) else None
1542
1687
  if result.get("isError"):
1543
- content = result.get("content") or []
1544
- text = content[0].get("text") if content and isinstance(content[0], dict) else result
1545
- raise RuntimeError(f"BrainBar backup request failed: {text}")
1688
+ if isinstance(text, str) and BRAINBAR_DB_IDENTITY_MISMATCH in text:
1689
+ raise BrainBarDatabaseIdentityError(f"BrainBar refused the backup before VACUUM: {text}")
1690
+ raise RuntimeError(f"BrainBar backup request failed: {text if text is not None else result}")
1691
+ if resolved_expected_db is not None:
1692
+ # BrainBar echoes the dev/inode of the file its connection has OPEN; a pathname
1693
+ # cannot prove that (the path may have been replaced under the live connection).
1694
+ try:
1695
+ echo = json.loads(text) if isinstance(text, str) else None
1696
+ except ValueError:
1697
+ echo = None
1698
+ echo = echo if isinstance(echo, dict) else {}
1699
+ served_identity = (echo.get("db_dev"), echo.get("db_ino"))
1700
+ expected_identity = _file_identity(resolved_expected_db)
1701
+ if not all(isinstance(v, int) for v in served_identity) or served_identity != expected_identity:
1702
+ # Terminal response: BrainBar has stopped writing this attempt. Whatever it
1703
+ # vacuumed is not the configured database, so it must not survive here.
1704
+ attempt_path.unlink(missing_ok=True)
1705
+ _backup_attempt_completion_marker(attempt_path).unlink(missing_ok=True)
1706
+ raise BrainBarDatabaseIdentityError(
1707
+ f"{BRAINBAR_DB_IDENTITY_MISMATCH}: expected {resolved_expected_db} {expected_identity}, "
1708
+ f"BrainBar reported {echo.get('db_path')!r} {served_identity}; deleted the unconfirmed "
1709
+ "snapshot. A BrainBar without open-database identity support must be upgraded."
1710
+ )
1546
1711
  if not attempt_path.exists():
1547
1712
  raise RuntimeError(f"BrainBar backup did not create snapshot: {attempt_path}")
1548
1713
  try:
@@ -1552,13 +1717,29 @@ def request_brainbar_vacuum_into(
1552
1717
  attempt_path.unlink(missing_ok=True)
1553
1718
  _backup_attempt_completion_marker(attempt_path).unlink(missing_ok=True)
1554
1719
  raise
1555
- os.replace(attempt_path, target_path)
1720
+ promoted = os.stat(attempt_path)
1721
+ try:
1722
+ # Create-exclusive: a peer's dated raw that appeared meanwhile is never replaced.
1723
+ os.link(attempt_path, target_path)
1724
+ except FileExistsError:
1725
+ attempt_path.unlink(missing_ok=True)
1726
+ _backup_attempt_completion_marker(attempt_path).unlink(missing_ok=True)
1727
+ raise BackupTargetConflictError(
1728
+ f"Backup target appeared while this snapshot ran; not replacing it: {target_path}"
1729
+ ) from None
1730
+ attempt_path.unlink()
1556
1731
  _backup_attempt_completion_marker(attempt_path).unlink(missing_ok=True)
1557
1732
  for prior_path in unconfirmed_attempt_paths:
1558
1733
  prior_path.unlink(missing_ok=True)
1559
1734
  _backup_attempt_completion_marker(prior_path).unlink(missing_ok=True)
1560
- return
1561
- except BackupTimeoutError:
1735
+ return promoted
1736
+ except BrainBarDatabaseIdentityError:
1737
+ for prior_path, (owned_raw, owned_marker) in completed_attempts.items():
1738
+ _remove_owned_raw(prior_path, owned_raw)
1739
+ if not prior_path.exists() and not prior_path.is_symlink():
1740
+ _remove_owned_raw(_backup_attempt_completion_marker(prior_path), owned_marker)
1741
+ raise
1742
+ except (BackupTimeoutError, BackupTargetConflictError):
1562
1743
  raise
1563
1744
  except BrainBarSnapshotBusyError as exc:
1564
1745
  if unconfirmed_attempt_paths:
@@ -1598,6 +1779,7 @@ def request_brainbar_vacuum_into(
1598
1779
  _sleep(retry_backoff_seconds)
1599
1780
  if last_error is not None:
1600
1781
  raise last_error
1782
+ raise RuntimeError("BrainBar vacuum snapshot made no attempt")
1601
1783
 
1602
1784
 
1603
1785
  def _send_brainbar_json_request(
@@ -28,27 +28,12 @@ DATA_LOSS_CODES = frozenset(
28
28
  }
29
29
  )
30
30
 
31
- # This is the only badge-suppression gate. The interim marker is deliberately
32
- # absent from this module and retires when the badge ships. Data-loss codes are
33
- # excluded structurally, so no configuration file can silence them.
34
- SUPPRESSIBLE_CODES = frozenset(
35
- {
36
- "brain_search_canary_failed",
37
- "drain_no_progress",
38
- "drain_unloaded",
39
- "health_check_unloaded",
40
- "hotlane_backlog_disabled",
41
- "hotlane_dead",
42
- "lock_holder_wedge",
43
- "missing_embeddings_climbing",
44
- "missing_embeddings_not_draining",
45
- "observability_unloaded",
46
- "pause_sentinel_stale",
47
- "queue_backed_up",
48
- "watch_unloaded",
49
- "watcher_stalled",
50
- }
51
- )
31
+ # Eligibility alone never suppresses an issue. A trusted producer must attach a
32
+ # current owned episode with a fixed deadline. Backlog/age and data-loss faults
33
+ # cannot be excused by snapshot activity or by positive throughput alone.
34
+ SUPPRESSIBLE_CODES = frozenset({"brain_search_canary_failed"})
35
+ EPISODE_MAX_SECONDS = 3600
36
+ EPISODE_FRESH_SECONDS = 300
52
37
 
53
38
  if DATA_LOSS_CODES & SUPPRESSIBLE_CODES:
54
39
  raise RuntimeError("data-loss badge codes must never be suppressible")
@@ -73,12 +58,51 @@ def _issue_payload(issue: HealthIssue) -> dict[str, str]:
73
58
  return {"code": issue.code, "severity": issue.severity, "message": issue.message}
74
59
 
75
60
 
76
- def build_badge_state_document(result: HealthCheckResult) -> dict[str, Any]:
77
- """Build schema v1 from one completed health-check result."""
61
+ def _episode_time(value: str) -> datetime:
62
+ parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
63
+ if parsed.tzinfo is None:
64
+ raise ValueError("episode timestamps require a timezone")
65
+ return parsed
66
+
67
+
68
+ def _expected_episode(issue: HealthIssue, now: datetime) -> dict[str, Any] | None:
69
+ episode = issue.expected_episode
70
+ if issue.severity != "critical" or issue.code not in SUPPRESSIBLE_CODES or not isinstance(episode, dict):
71
+ return None
72
+ try:
73
+ started, observed, deadline = (_episode_time(episode[key]) for key in ("started_at", "observed_at", "deadline"))
74
+ valid = (
75
+ episode["kind"] in ("snapshot", "maintenance")
76
+ and all(isinstance(episode[key], str) and episode[key].strip() for key in ("owner", "episode_id"))
77
+ and isinstance(episode["expected_codes"], list)
78
+ and issue.code in episode["expected_codes"]
79
+ and started <= observed <= now < deadline
80
+ and (deadline - started).total_seconds() <= EPISODE_MAX_SECONDS
81
+ and (now - observed).total_seconds() <= EPISODE_FRESH_SECONDS
82
+ )
83
+ except (KeyError, TypeError, ValueError, AttributeError):
84
+ return None
85
+ if not valid:
86
+ return None
87
+ return {
88
+ key: episode[key]
89
+ for key in ("kind", "owner", "episode_id", "started_at", "observed_at", "deadline", "expected_codes")
90
+ }
91
+
92
+
93
+ def build_badge_state_document(result: HealthCheckResult, *, now: datetime | None = None) -> dict[str, Any]:
94
+ """Keep all alerts; only explicit bounded evidence can excuse a critical."""
78
95
 
79
- critical = [issue for issue in result.issues if issue.severity == "critical"]
80
- active = [_issue_payload(issue) for issue in critical if issue.code not in SUPPRESSIBLE_CODES]
81
- suppressed = [_issue_payload(issue) for issue in critical if issue.code in SUPPRESSIBLE_CODES]
96
+ now = now or datetime.fromisoformat(result.checked_at.replace("Z", "+00:00"))
97
+ if now.tzinfo is None:
98
+ now = now.replace(tzinfo=UTC)
99
+ active, suppressed = [], []
100
+ for issue in result.issues:
101
+ payload = _issue_payload(issue)
102
+ if episode := _expected_episode(issue, now):
103
+ suppressed.append({**payload, "episode": episode})
104
+ else:
105
+ active.append(payload)
82
106
  return {
83
107
  "schema_version": SCHEMA_VERSION,
84
108
  "generated_at": _iso_utc(result.checked_at),
@@ -86,7 +110,7 @@ def build_badge_state_document(result: HealthCheckResult) -> dict[str, Any]:
86
110
  "state": "measured",
87
111
  "reason": "",
88
112
  "inputs": [],
89
- "badge_on": bool(active),
113
+ "badge_on": any(issue["severity"] != "warning" for issue in active),
90
114
  "active": active,
91
115
  "suppressed": suppressed,
92
116
  },