doubled-graph 3.0.0__tar.gz → 3.0.1__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 (150) hide show
  1. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/PKG-INFO +2 -1
  2. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/README.md +1 -0
  3. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/pyproject.toml +1 -1
  4. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/health.py +8 -1
  5. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/integrations/cgc.py +96 -16
  6. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/analyze.py +12 -0
  7. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_cgc_backend.py +142 -1
  8. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_smoke.py +28 -1
  9. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/.gitignore +0 -0
  10. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/ARTICLE.md +0 -0
  11. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/INDEX.md +0 -0
  12. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/LICENSE +0 -0
  13. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/for-ai-existing-project/README.md +0 -0
  14. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/for-ai-maintenance/README.md +0 -0
  15. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/for-ai-new-project/README.md +0 -0
  16. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/for-humans/FAQ.md +0 -0
  17. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/for-humans/deep-dive.md +0 -0
  18. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/for-humans/getting-started.md +0 -0
  19. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/README.md +0 -0
  20. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/approval-checkpoints.md +0 -0
  21. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/artifacts.md +0 -0
  22. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/auto-scaling.md +0 -0
  23. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/ci-templates/github-actions.yml +0 -0
  24. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/ci-templates/gitlab-ci.yml +0 -0
  25. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/drift-and-priority.md +0 -0
  26. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/_template.md +0 -0
  27. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/csharp.md +0 -0
  28. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/go.md +0 -0
  29. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/java.md +0 -0
  30. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/python.md +0 -0
  31. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/rust.md +0 -0
  32. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/swift.md +0 -0
  33. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/language-adapters/typescript.md +0 -0
  34. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/principles.md +0 -0
  35. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/roles.md +0 -0
  36. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/_template.md +0 -0
  37. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/claude-code.md +0 -0
  38. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/codex.md +0 -0
  39. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/continue.md +0 -0
  40. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/cursor.md +0 -0
  41. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/local-llm.md +0 -0
  42. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/runtime-adapters/windsurf.md +0 -0
  43. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/tools.md +0 -0
  44. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/methodology/workflow.md +0 -0
  45. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/maintenance/on-after-edit.md +0 -0
  46. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/maintenance/on-before-edit.md +0 -0
  47. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/maintenance/on-drift-detected.md +0 -0
  48. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/maintenance/on-user-manual-edit.md +0 -0
  49. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/00-entry-prompt.md +0 -0
  50. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/01-discover.md +0 -0
  51. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/02-reconstruct-intent.md +0 -0
  52. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/03-draft-plan.md +0 -0
  53. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/04-markup-codebase.md +0 -0
  54. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/05-verification-and-logs.md +0 -0
  55. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/migrate-existing-project/06-validation-gates.md +0 -0
  56. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/00-entry-prompt.md +0 -0
  57. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/01-intent-interview.md +0 -0
  58. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/02-requirements.md +0 -0
  59. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/03-technology.md +0 -0
  60. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/04-development-plan.md +0 -0
  61. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/05-verification-plan.md +0 -0
  62. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/06-generate.md +0 -0
  63. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/new-project/07-post-init-sync.md +0 -0
  64. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/upgrade-methodology/00-entry-prompt.md +0 -0
  65. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/prompts/upgrade-methodology/01-content-gaps.md +0 -0
  66. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/__init__.py +0 -0
  67. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/__main__.py +0 -0
  68. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/cli.py +0 -0
  69. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/config.py +0 -0
  70. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/daemon/__init__.py +0 -0
  71. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/daemon/main.py +0 -0
  72. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/daemon/server.py +0 -0
  73. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-after-edit/SKILL.md +0 -0
  74. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-before-edit/SKILL.md +0 -0
  75. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-drift/SKILL.md +0 -0
  76. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-guide/SKILL.md +0 -0
  77. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-manual-edit/SKILL.md +0 -0
  78. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-refactor/SKILL.md +0 -0
  79. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/data/skills/doubled-graph-verify/SKILL.md +0 -0
  80. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/graphs/__init__.py +0 -0
  81. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/graphs/anchors.py +0 -0
  82. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/graphs/crossref.py +0 -0
  83. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/graphs/declared.py +0 -0
  84. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/graphs/grace4.py +0 -0
  85. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/hooks_installer.py +0 -0
  86. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/integrations/__init__.py +0 -0
  87. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/integrations/grace_cli.py +0 -0
  88. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/integrations/graphd.py +0 -0
  89. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/integrations/service.py +0 -0
  90. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/migrations/__init__.py +0 -0
  91. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/migrations/grace3_to_grace4.py +0 -0
  92. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/policy/__init__.py +0 -0
  93. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/policy/agents_md.py +0 -0
  94. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/policy/phase.py +0 -0
  95. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/server.py +0 -0
  96. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/setup.py +0 -0
  97. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/storage/__init__.py +0 -0
  98. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/storage/paths.py +0 -0
  99. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/__init__.py +0 -0
  100. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/_meta.py +0 -0
  101. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/context.py +0 -0
  102. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/detect_changes.py +0 -0
  103. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/impact.py +0 -0
  104. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/post_tool.py +0 -0
  105. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/tools/provenance.py +0 -0
  106. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/src/doubled_graph/uninstall.py +0 -0
  107. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/__init__.py +0 -0
  108. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/conftest.py +0 -0
  109. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_anchors.py +0 -0
  110. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_bom_support.py +0 -0
  111. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_cgc_contract.py +0 -0
  112. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_cgc_lifecycle.py +0 -0
  113. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_cli_daemon.py +0 -0
  114. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_cli_entrypoint.py +0 -0
  115. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_cli_surface.py +0 -0
  116. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_crossref_drift.py +0 -0
  117. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_daemon.py +0 -0
  118. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_daemon_main.py +0 -0
  119. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_declared_coverage.py +0 -0
  120. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_e2e_acceptance.py +0 -0
  121. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_grace4_artifacts.py +0 -0
  122. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_grace_cli_coverage.py +0 -0
  123. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_grace_cli_engine.py +0 -0
  124. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_graphd_client.py +0 -0
  125. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_health.py +0 -0
  126. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_hook_public_coverage.py +0 -0
  127. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mcp_transport.py +0 -0
  128. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mcp_validation.py +0 -0
  129. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_migration_coverage.py +0 -0
  130. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_migration_grace3_to_grace4.py +0 -0
  131. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_gate_script.py +0 -0
  132. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_analyze.py +0 -0
  133. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_cgc_edges.py +0 -0
  134. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_cgc_fallback.py +0 -0
  135. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_cgc_misc.py +0 -0
  136. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_context.py +0 -0
  137. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_crossref.py +0 -0
  138. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_hooks.py +0 -0
  139. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_kill_impact.py +0 -0
  140. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_mutation_probes.py +0 -0
  141. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_packaging.py +0 -0
  142. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_platform_branches.py +0 -0
  143. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_provenance.py +0 -0
  144. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_release_script.py +0 -0
  145. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_repo_hygiene.py +0 -0
  146. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_service.py +0 -0
  147. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_setup_artifacts.py +0 -0
  148. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_setup_coverage.py +0 -0
  149. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_setup_failure_semantics.py +0 -0
  150. {doubled_graph-3.0.0 → doubled_graph-3.0.1}/tests/test_uninstall.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: doubled-graph
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: MCP facade over CodeGraphContext + GRACE 4 (.grace artifacts): impact, context, drift-detect, migration for LLM-driven codebases.
5
5
  Project-URL: Homepage, https://github.com/rour/doubled-graph-mcp
6
6
  Project-URL: Repository, https://github.com/rour/doubled-graph-mcp
@@ -229,6 +229,7 @@ doubled-graph migrate check --repo . # map_pending / placeholders — что
229
229
  Если `project_kind` = `grace3` — артефакты ещё не перенесены: `doubled-graph setup --repo .`.
230
230
  Если `upgrade_required` = `true` — движок старее 4.x: `npm install -g @osovv/grace-cli@4.2.1`, затем `setup` повторно.
231
231
  Если `daemon.running` = `false`, а `health.cgc.ok` = `false` — демон не запущен: выполните `doubled-graph setup` в обычном шелле (из песочницы `launchctl`/`systemctl` могут быть запрещены), затем `daemon status`. Без демона графовые команды возвращают `CGC_BACKEND_FAIL` и rc=1 — это не «пустой граф».
232
+ Если `health.cgc.diagnostic` = `FalkorDB Lite previously failed to start…` — в 3.0.0 это была памятка о прошлой неудаче, а не причина. В 3.0.1 кэш сбрасывается перед каждой попыткой, а мёртвый `falkordb.sock` и осиротевший `graph.settings` удаляются автоматически: первый `analyze`/`setup` чинит репозиторий сам, `health.cgc.repaired` перечисляет удалённое. Если ошибка осталась — это настоящий сбой движка: `daemon logs` и `cgc.backend`.
232
233
  Если `lint` вернул `markup.module-map-missing` — это содержательная работа, промпт `prompts/upgrade-methodology/01-content-gaps.md`.
233
234
 
234
235
  Полная проверка (ruff + unit + real-CGC E2E + diff/version): `bash scripts/verify.sh`; критерии готовности — [docs/VERIFICATION.md](docs/VERIFICATION.md).
@@ -188,6 +188,7 @@ doubled-graph migrate check --repo . # map_pending / placeholders — что
188
188
  Если `project_kind` = `grace3` — артефакты ещё не перенесены: `doubled-graph setup --repo .`.
189
189
  Если `upgrade_required` = `true` — движок старее 4.x: `npm install -g @osovv/grace-cli@4.2.1`, затем `setup` повторно.
190
190
  Если `daemon.running` = `false`, а `health.cgc.ok` = `false` — демон не запущен: выполните `doubled-graph setup` в обычном шелле (из песочницы `launchctl`/`systemctl` могут быть запрещены), затем `daemon status`. Без демона графовые команды возвращают `CGC_BACKEND_FAIL` и rc=1 — это не «пустой граф».
191
+ Если `health.cgc.diagnostic` = `FalkorDB Lite previously failed to start…` — в 3.0.0 это была памятка о прошлой неудаче, а не причина. В 3.0.1 кэш сбрасывается перед каждой попыткой, а мёртвый `falkordb.sock` и осиротевший `graph.settings` удаляются автоматически: первый `analyze`/`setup` чинит репозиторий сам, `health.cgc.repaired` перечисляет удалённое. Если ошибка осталась — это настоящий сбой движка: `daemon logs` и `cgc.backend`.
191
192
  Если `lint` вернул `markup.module-map-missing` — это содержательная работа, промпт `prompts/upgrade-methodology/01-content-gaps.md`.
192
193
 
193
194
  Полная проверка (ruff + unit + real-CGC E2E + diff/version): `bash scripts/verify.sh`; критерии готовности — [docs/VERIFICATION.md](docs/VERIFICATION.md).
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "doubled-graph"
7
- version = "3.0.0"
7
+ version = "3.0.1"
8
8
  description = "MCP facade over CodeGraphContext + GRACE 4 (.grace artifacts): impact, context, drift-detect, migration for LLM-driven codebases."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -215,7 +215,14 @@ def build_health_report(repo: Path) -> dict[str, Any]:
215
215
  for item in declared.issues
216
216
  ],
217
217
  },
218
- "cgc": {"ok": cgc_diag is None, "diagnostic": cgc_diag, "daemon": daemon},
218
+ "cgc": {
219
+ "ok": cgc_diag is None,
220
+ "diagnostic": cgc_diag,
221
+ "daemon": daemon,
222
+ # Engine files the backend removed because a previous start died
223
+ # halfway: the repair must be visible, not silent.
224
+ "repaired": list(getattr(cgc, "last_repair", []) or []),
225
+ },
219
226
  "modules": {
220
227
  "total": len(declared.modules),
221
228
  "verified": len(verified_module_ids & set(declared.modules.keys())),
@@ -16,6 +16,7 @@ import hashlib
16
16
  import importlib.util
17
17
  import os
18
18
  import re
19
+ import socket
19
20
  import subprocess
20
21
  import sys
21
22
  import tempfile
@@ -326,11 +327,16 @@ def _manager_backend_type(manager: Any) -> str | None:
326
327
 
327
328
 
328
329
  def _clear_falkordb_failed_config(db_path: str) -> None:
329
- """Drop CGC's cached start-failure for *db_path* before a lock retry.
330
-
331
- ``FalkorDBManager.get_driver`` remembers a failed configuration; without
332
- clearing it, the second attempt would immediately raise "previously
333
- failed" even though the first failure was transient lock contention.
330
+ """Drop CGC's cached start-failure for *db_path* before every attempt.
331
+
332
+ ``FalkorDBManager.get_driver`` remembers a failed configuration and then
333
+ refuses to try again ("previously failed") for the rest of the process.
334
+ That memo is a footnote of one attempt, not a property of the database: a
335
+ long-lived daemon that hit one transient failure (stale socket, another
336
+ process still exiting, a full disk for a second) would otherwise report
337
+ the cached message forever, and the user would see "previously failed"
338
+ instead of the real reason. The cache is therefore cleared before each
339
+ attempt so the next one starts from facts.
334
340
  """
335
341
  try:
336
342
  from codegraphcontext.core.database_falkordb import FalkorDBManager # type: ignore
@@ -344,6 +350,49 @@ def _clear_falkordb_failed_config(db_path: str) -> None:
344
350
  failed.discard(key)
345
351
 
346
352
 
353
+ #: Files an interrupted FalkorDB start leaves next to ``db_path``. The graph
354
+ #: data itself lives inside ``db_path`` and is never touched here: deleting a
355
+ #: socket/settings pair costs one restart, deleting the data costs the index.
356
+ _STALE_ENGINE_FILES = ("falkordb.sock", "graph.settings")
357
+
358
+
359
+ def _dead_unix_socket(path: Path) -> bool:
360
+ """True when *path* is a socket file that nobody is listening on."""
361
+ probe = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
362
+ probe.settimeout(0.2)
363
+ try:
364
+ probe.connect(str(path))
365
+ return False
366
+ except OSError:
367
+ return True
368
+ finally:
369
+ probe.close()
370
+
371
+
372
+ def _repair_stale_engine_state(db_path: str) -> list[str]:
373
+ """Remove leftovers of an interrupted FalkorDB start; keep graph data.
374
+
375
+ A socket nobody listens on, and a settings file written by a start that
376
+ died halfway, are enough to make every later attempt fail. Removing them
377
+ is safe: a live engine is never touched (the socket answers), and the
378
+ database directory itself is left alone.
379
+ """
380
+ directory = Path(db_path).parent
381
+ removed: list[str] = []
382
+ for name in _STALE_ENGINE_FILES:
383
+ candidate = directory / name
384
+ try:
385
+ if not candidate.exists():
386
+ continue
387
+ if candidate.suffix == ".sock" and not _dead_unix_socket(candidate):
388
+ continue # a live engine owns it
389
+ candidate.unlink()
390
+ removed.append(str(candidate))
391
+ except OSError:
392
+ continue
393
+ return removed
394
+
395
+
347
396
  def _create_db_manager(db_path: str, db_type: str) -> Any:
348
397
  """Create exactly the requested backend; never accept a silent fallback.
349
398
 
@@ -360,6 +409,10 @@ def _create_db_manager(db_path: str, db_type: str) -> Any:
360
409
  """
361
410
  attempt = 0
362
411
  while True:
412
+ if db_type == "falkordb":
413
+ # A memo of an earlier failure must not outlive that attempt; see
414
+ # `_clear_falkordb_failed_config` for why the daemon depends on it.
415
+ _clear_falkordb_failed_config(db_path)
363
416
  try:
364
417
  if db_type == "falkordb":
365
418
  from codegraphcontext.core import FalkorDBManager # type: ignore
@@ -388,8 +441,6 @@ def _create_db_manager(db_path: str, db_type: str) -> Any:
388
441
  if not _is_backend_lock_error(exc) or attempt >= _BACKEND_INIT_ATTEMPTS - 1:
389
442
  raise
390
443
  attempt += 1
391
- if db_type == "falkordb":
392
- _clear_falkordb_failed_config(db_path)
393
444
  time.sleep(_BACKEND_RETRY_BASE_DELAY_S * (2 ** (attempt - 1)))
394
445
 
395
446
 
@@ -465,6 +516,10 @@ class CGC:
465
516
  #: Last ``close`` failure. ``close`` never raises (a failed teardown
466
517
  #: must not break process exit); the reason is kept for diagnostics.
467
518
  self.last_close_error: str | None = None
519
+ #: Engine files removed because a previous start died halfway. A
520
+ #: non-empty list means the backend healed itself; surfaced by
521
+ #: `analyze`/`health` so the repair is visible, not silent.
522
+ self.last_repair: list[str] = []
468
523
  self._atexit_registered = False
469
524
  self._register_atexit()
470
525
 
@@ -556,15 +611,40 @@ class CGC:
556
611
  except CGCUnavailable:
557
612
  raise
558
613
  except Exception as e:
559
- raise CGCUnavailable(
560
- f"CGC backend {db_type!r} failed to initialise at {db_path}: "
561
- f"{type(e).__name__}: {e}\n"
562
- "No fallback to another backend is attempted: an embedded "
563
- "fallback would open the same per-repo directory with a "
564
- "different engine, which can lock or corrupt it. Fix the "
565
- "backend, or set `cgc.backend` explicitly "
566
- "(falkordb/kuzu/neo4j) and retry."
567
- ) from e
614
+ # A start that died halfway leaves a dead socket and/or a
615
+ # half-written settings file next to the database; every later
616
+ # attempt then fails for good. Repair once and retry: `setup` and
617
+ # `analyze` must heal this without asking the user to delete
618
+ # `~/.codegraphcontext` by hand.
619
+ repaired = (
620
+ _repair_stale_engine_state(db_path) if db_type == "falkordb" else []
621
+ )
622
+ if repaired:
623
+ self.last_repair = repaired
624
+ try:
625
+ self._db = _create_db_manager(db_path, db_type)
626
+ except Exception as retry_exc:
627
+ raise CGCUnavailable(
628
+ f"CGC backend {db_type!r} failed to initialise at {db_path} "
629
+ f"even after removing stale engine files "
630
+ f"({', '.join(repaired)}): "
631
+ f"{type(retry_exc).__name__}: {retry_exc}\n"
632
+ "No fallback to another backend is attempted: an embedded "
633
+ "fallback would open the same per-repo directory with a "
634
+ "different engine, which can lock or corrupt it. Fix the "
635
+ "backend, or set `cgc.backend` explicitly "
636
+ "(falkordb/kuzu/neo4j) and retry."
637
+ ) from retry_exc
638
+ else:
639
+ raise CGCUnavailable(
640
+ f"CGC backend {db_type!r} failed to initialise at {db_path}: "
641
+ f"{type(e).__name__}: {e}\n"
642
+ "No fallback to another backend is attempted: an embedded "
643
+ "fallback would open the same per-repo directory with a "
644
+ "different engine, which can lock or corrupt it. Fix the "
645
+ "backend, or set `cgc.backend` explicitly "
646
+ "(falkordb/kuzu/neo4j) and retry."
647
+ ) from e
568
648
  finally:
569
649
  if previous_db_type is None:
570
650
  os.environ.pop("CGC_RUNTIME_DB_TYPE", None)
@@ -520,6 +520,18 @@ def _analyze_unlocked(
520
520
  with suppress(AttributeError):
521
521
  cgc.close()
522
522
 
523
+ # The backend may have healed a half-written engine state (dead socket,
524
+ # orphaned settings) before this run produced any data. Report it: a silent
525
+ # repair looks like "it just worked", and the next real failure would be
526
+ # investigated from scratch.
527
+ for repaired in getattr(cgc, "last_repair", []) or []:
528
+ warnings.append(
529
+ AnalyzeWarning(
530
+ code="CGC_ENGINE_REPAIRED",
531
+ detail=f"removed stale engine file after a failed start: {repaired}",
532
+ )
533
+ )
534
+
523
535
  result = AnalyzeResult(
524
536
  mode_used=resolved_mode,
525
537
  duration_ms=int((time.monotonic() - t0) * 1000),
@@ -180,7 +180,10 @@ def test_create_db_manager_falkordb_lock_retry_clears_cached_failure(
180
180
 
181
181
  assert manager.get_backend_type() == "falkordb"
182
182
  assert calls["count"] == 2
183
- assert cleared == ["/repo/graph"]
183
+ # Cleared before *every* attempt: the memo of a failed start must not
184
+ # outlive that attempt (3.0.1: a long-lived daemon otherwise reports
185
+ # "previously failed" forever).
186
+ assert cleared == ["/repo/graph", "/repo/graph"]
184
187
 
185
188
 
186
189
  def test_clear_falkordb_failed_config_drops_only_matching_keys() -> None:
@@ -430,3 +433,141 @@ def test_close_tears_down_driver_and_falls_back_without_teardown_kwarg(
430
433
  cgc._db = _NoClose()
431
434
  cgc.close()
432
435
  assert cgc._db is None
436
+
437
+
438
+ # ---------------------------------------------------------------------------
439
+ # 3.0.1 — cached failure and stale engine state
440
+ # ---------------------------------------------------------------------------
441
+
442
+
443
+ def test_cached_failure_is_cleared_before_the_first_attempt(monkeypatch) -> None:
444
+ """A memo from an earlier run must not block the next one.
445
+
446
+ The daemon is long-lived: without clearing before the first attempt, one
447
+ transient failure makes every later request answer "previously failed"
448
+ until the process is restarted.
449
+ """
450
+ cleared: list[str] = []
451
+
452
+ monkeypatch.setattr(
453
+ cgc_mod, "_clear_falkordb_failed_config", lambda path: cleared.append(path)
454
+ )
455
+ monkeypatch.setattr(
456
+ "codegraphcontext.core.FalkorDBManager",
457
+ lambda db_path=None: _Manager("falkordb", db_path),
458
+ )
459
+
460
+ _create_db_manager("/repo/graph", "falkordb")
461
+
462
+ assert cleared == ["/repo/graph"]
463
+
464
+
465
+ def test_repair_removes_a_dead_socket_and_settings_but_keeps_data(tmp_path) -> None:
466
+ db_dir = tmp_path / "repo-abc"
467
+ (db_dir / "graph").mkdir(parents=True)
468
+ (db_dir / "falkordb.sock").write_text("", encoding="utf-8")
469
+ (db_dir / "graph.settings").write_text("{}", encoding="utf-8")
470
+ (db_dir / "graph" / "data").write_text("payload", encoding="utf-8")
471
+
472
+ removed = cgc_mod._repair_stale_engine_state(str(db_dir / "graph"))
473
+
474
+ assert sorted(Path(item).name for item in removed) == [
475
+ "falkordb.sock",
476
+ "graph.settings",
477
+ ]
478
+ assert not (db_dir / "falkordb.sock").exists()
479
+ assert not (db_dir / "graph.settings").exists()
480
+ # The database itself is never touched: deleting it costs the index.
481
+ assert (db_dir / "graph" / "data").read_text(encoding="utf-8") == "payload"
482
+
483
+
484
+ def test_repair_keeps_a_socket_that_still_answers() -> None:
485
+ import socket
486
+ import tempfile
487
+
488
+ directory = Path(tempfile.mkdtemp(prefix="dg-live-", dir="/tmp"))
489
+ socket_path = directory / "falkordb.sock"
490
+ server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
491
+ try:
492
+ server.bind(str(socket_path))
493
+ server.listen(1)
494
+
495
+ removed = cgc_mod._repair_stale_engine_state(str(directory / "graph"))
496
+
497
+ assert removed == []
498
+ assert socket_path.exists()
499
+ finally:
500
+ server.close()
501
+ for leftover in directory.iterdir():
502
+ leftover.unlink()
503
+ directory.rmdir()
504
+
505
+
506
+ def test_ensure_repairs_stale_state_once_and_reports_it(tmp_path, monkeypatch) -> None:
507
+ repo = tmp_path / "repo"
508
+ repo.mkdir()
509
+ calls = {"n": 0}
510
+ repaired: list[str] = []
511
+
512
+ def fake_create(db_path: str, db_type: str):
513
+ calls["n"] += 1
514
+ if calls["n"] == 1:
515
+ raise RuntimeError("FalkorDB Lite failed to start")
516
+ return _Manager("falkordb")
517
+
518
+ monkeypatch.setattr(cgc_mod, "_create_db_manager", fake_create)
519
+ monkeypatch.setattr(
520
+ cgc_mod,
521
+ "_repair_stale_engine_state",
522
+ lambda path: repaired.append(path) or ["/x/falkordb.sock"],
523
+ )
524
+ monkeypatch.setattr("codegraphcontext.core.jobs.JobManager", lambda: object())
525
+ monkeypatch.setattr(
526
+ "codegraphcontext.tools.graph_builder.GraphBuilder", lambda *args: object()
527
+ )
528
+ monkeypatch.setattr(
529
+ "codegraphcontext.tools.code_finder.CodeFinder", lambda *args: object()
530
+ )
531
+
532
+ cgc = CGC(repo, backend="falkordb")
533
+ try:
534
+ cgc._ensure()
535
+ finally:
536
+ cgc.close()
537
+
538
+ assert calls["n"] == 2
539
+ assert repaired and repaired[0].endswith("/graph")
540
+ assert cgc.last_repair == ["/x/falkordb.sock"]
541
+
542
+
543
+ def test_ensure_reports_the_reason_when_repair_does_not_help(tmp_path, monkeypatch) -> None:
544
+ repo = tmp_path / "repo"
545
+ repo.mkdir()
546
+
547
+ monkeypatch.setattr(
548
+ cgc_mod,
549
+ "_create_db_manager",
550
+ lambda db_path, db_type: (_ for _ in ()).throw(RuntimeError("still broken")),
551
+ )
552
+ monkeypatch.setattr(
553
+ cgc_mod, "_repair_stale_engine_state", lambda path: ["/x/falkordb.sock"]
554
+ )
555
+
556
+ cgc = CGC(repo, backend="falkordb")
557
+ try:
558
+ with pytest.raises(CGCUnavailable, match="after removing stale engine files"):
559
+ cgc._ensure()
560
+ finally:
561
+ cgc.close()
562
+
563
+
564
+ def test_repair_tolerates_files_it_cannot_remove(tmp_path) -> None:
565
+ """An unremovable leftover must not crash the repair; the retry decides."""
566
+ db_dir = tmp_path / "repo"
567
+ db_dir.mkdir()
568
+ (db_dir / "graph.settings").write_text("{}", encoding="utf-8")
569
+ db_dir.chmod(0o500)
570
+ try:
571
+ assert cgc_mod._repair_stale_engine_state(str(db_dir / "graph")) == []
572
+ finally:
573
+ db_dir.chmod(0o700)
@@ -9,7 +9,7 @@ import os
9
9
  import subprocess
10
10
  import sys
11
11
  from pathlib import Path
12
- from typing import Any
12
+ from typing import Any, ClassVar
13
13
 
14
14
  import pytest
15
15
 
@@ -4408,3 +4408,30 @@ def test_phase_set_appends_block_to_file_without_trailing_newline(tmp_path: Path
4408
4408
 
4409
4409
  body = (tmp_path / "AGENTS.md").read_text(encoding="utf-8")
4410
4410
  assert body.startswith("# Project\nlast line no newline\n\n<!-- doubled-graph:phase:start -->")
4411
+
4412
+
4413
+ def test_analyze_reports_a_repaired_engine_state(tmp_path: Path, monkeypatch):
4414
+ """A backend that healed a half-written start must say so."""
4415
+ from types import SimpleNamespace
4416
+
4417
+ from doubled_graph.tools import analyze as analyze_mod
4418
+
4419
+ class _RepairedCGC:
4420
+ last_repair: ClassVar[list[str]] = ["/tmp/repo/falkordb.sock"]
4421
+
4422
+ def __init__(self, *_args, **_kw):
4423
+ pass
4424
+
4425
+ def analyze_full(self):
4426
+ return SimpleNamespace(
4427
+ files_processed=0, files_deleted=0, symbols_added=0, edges_added=0
4428
+ )
4429
+
4430
+ def close(self):
4431
+ pass
4432
+
4433
+ monkeypatch.setattr(analyze_mod, "CGC", _RepairedCGC)
4434
+
4435
+ result = analyze_mod.analyze(repo_path=tmp_path, mode="full")
4436
+
4437
+ assert any(w.code == "CGC_ENGINE_REPAIRED" for w in result.warnings)
File without changes
File without changes
File without changes
File without changes