doubled-graph 3.1.3__tar.gz → 3.1.5__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 (179) hide show
  1. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/PKG-INFO +1 -1
  2. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/pyproject.toml +1 -1
  3. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/integrations/service.py +175 -41
  4. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/setup.py +34 -1
  5. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/uninstall.py +25 -2
  6. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/launchd_stub/fake_launchctl.py +45 -10
  7. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_service.py +108 -1
  8. doubled_graph-3.1.5/tests/test_service_async_unload.py +268 -0
  9. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_service_start_fallback.py +8 -1
  10. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_setup_coverage.py +49 -0
  11. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_setup_launchd_e2e.py +72 -1
  12. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_uninstall.py +68 -1
  13. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/.gitignore +0 -0
  14. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/ARTICLE.md +0 -0
  15. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/INDEX.md +0 -0
  16. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/LICENSE +0 -0
  17. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/README.md +0 -0
  18. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/for-ai-existing-project/README.md +0 -0
  19. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/for-ai-maintenance/README.md +0 -0
  20. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/for-ai-new-project/README.md +0 -0
  21. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/for-humans/FAQ.md +0 -0
  22. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/for-humans/deep-dive.md +0 -0
  23. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/for-humans/getting-started.md +0 -0
  24. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/README.md +0 -0
  25. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/approval-checkpoints.md +0 -0
  26. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/artifacts.md +0 -0
  27. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/auto-scaling.md +0 -0
  28. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/ci-templates/github-actions.yml +0 -0
  29. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/ci-templates/gitlab-ci.yml +0 -0
  30. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/drift-and-priority.md +0 -0
  31. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/_template.md +0 -0
  32. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/csharp.md +0 -0
  33. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/go.md +0 -0
  34. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/java.md +0 -0
  35. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/python.md +0 -0
  36. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/rust.md +0 -0
  37. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/swift.md +0 -0
  38. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/language-adapters/typescript.md +0 -0
  39. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/principles.md +0 -0
  40. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/roles.md +0 -0
  41. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/_template.md +0 -0
  42. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/claude-code.md +0 -0
  43. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/codex.md +0 -0
  44. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/continue.md +0 -0
  45. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/cursor.md +0 -0
  46. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/local-llm.md +0 -0
  47. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/runtime-adapters/windsurf.md +0 -0
  48. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/tools.md +0 -0
  49. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/methodology/workflow.md +0 -0
  50. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/maintenance/on-after-edit.md +0 -0
  51. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/maintenance/on-before-edit.md +0 -0
  52. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/maintenance/on-drift-detected.md +0 -0
  53. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/maintenance/on-user-manual-edit.md +0 -0
  54. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/00-entry-prompt.md +0 -0
  55. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/01-discover.md +0 -0
  56. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/02-reconstruct-intent.md +0 -0
  57. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/03-draft-plan.md +0 -0
  58. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/04-markup-codebase.md +0 -0
  59. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/05-verification-and-logs.md +0 -0
  60. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/migrate-existing-project/06-validation-gates.md +0 -0
  61. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/00-entry-prompt.md +0 -0
  62. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/01-intent-interview.md +0 -0
  63. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/02-requirements.md +0 -0
  64. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/03-technology.md +0 -0
  65. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/04-development-plan.md +0 -0
  66. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/05-verification-plan.md +0 -0
  67. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/06-generate.md +0 -0
  68. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/new-project/07-post-init-sync.md +0 -0
  69. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/upgrade-methodology/00-entry-prompt.md +0 -0
  70. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/prompts/upgrade-methodology/01-content-gaps.md +0 -0
  71. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/__init__.py +0 -0
  72. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/__main__.py +0 -0
  73. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/artifacts_repair.py +0 -0
  74. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/cli.py +0 -0
  75. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/config.py +0 -0
  76. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/contracts.py +0 -0
  77. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/daemon/__init__.py +0 -0
  78. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/daemon/index_store.py +0 -0
  79. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/daemon/main.py +0 -0
  80. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/daemon/server.py +0 -0
  81. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-after-edit/SKILL.md +0 -0
  82. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-before-edit/SKILL.md +0 -0
  83. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-drift/SKILL.md +0 -0
  84. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-guide/SKILL.md +0 -0
  85. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-manual-edit/SKILL.md +0 -0
  86. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-refactor/SKILL.md +0 -0
  87. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/data/skills/doubled-graph-verify/SKILL.md +0 -0
  88. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/graphs/__init__.py +0 -0
  89. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/graphs/anchors.py +0 -0
  90. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/graphs/crossref.py +0 -0
  91. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/graphs/declared.py +0 -0
  92. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/graphs/grace4.py +0 -0
  93. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/health.py +0 -0
  94. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/hooks_installer.py +0 -0
  95. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/__init__.py +0 -0
  96. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/discovery.py +0 -0
  97. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/linker.py +0 -0
  98. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/manifest.py +0 -0
  99. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/parse_cache.py +0 -0
  100. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/parser.py +0 -0
  101. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/index/snapshot.py +0 -0
  102. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/integrations/__init__.py +0 -0
  103. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/integrations/cgc.py +0 -0
  104. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/integrations/grace_cli.py +0 -0
  105. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/integrations/graphd.py +0 -0
  106. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/migrations/__init__.py +0 -0
  107. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/migrations/grace3_to_grace4.py +0 -0
  108. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/policy/__init__.py +0 -0
  109. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/policy/agents_md.py +0 -0
  110. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/policy/phase.py +0 -0
  111. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/server.py +0 -0
  112. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/storage/__init__.py +0 -0
  113. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/storage/paths.py +0 -0
  114. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/__init__.py +0 -0
  115. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/_meta.py +0 -0
  116. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/analyze.py +0 -0
  117. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/analyze_sync.py +0 -0
  118. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/check_drift.py +0 -0
  119. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/context.py +0 -0
  120. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/impact.py +0 -0
  121. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/index_status.py +0 -0
  122. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/post_tool.py +0 -0
  123. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/src/doubled_graph/tools/provenance.py +0 -0
  124. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/__init__.py +0 -0
  125. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/conftest.py +0 -0
  126. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/launchd_stub/launchctl +0 -0
  127. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_analyze_sync.py +0 -0
  128. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_anchors.py +0 -0
  129. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_artifacts_repair.py +0 -0
  130. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_bom_support.py +0 -0
  131. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_cgc_backend.py +0 -0
  132. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_cgc_contract.py +0 -0
  133. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_cgc_lifecycle.py +0 -0
  134. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_check_drift.py +0 -0
  135. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_cli_daemon.py +0 -0
  136. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_cli_entrypoint.py +0 -0
  137. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_cli_surface.py +0 -0
  138. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_command_surface.py +0 -0
  139. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_contracts.py +0 -0
  140. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_crossref_drift.py +0 -0
  141. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_daemon.py +0 -0
  142. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_daemon_main.py +0 -0
  143. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_declared_coverage.py +0 -0
  144. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_doc_contract.py +0 -0
  145. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_e2e_acceptance.py +0 -0
  146. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_grace4_artifacts.py +0 -0
  147. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_grace_cli_coverage.py +0 -0
  148. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_grace_cli_engine.py +0 -0
  149. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_graphd_client.py +0 -0
  150. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_health.py +0 -0
  151. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_hook_public_coverage.py +0 -0
  152. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_index_core.py +0 -0
  153. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_index_graph.py +0 -0
  154. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_index_manifest.py +0 -0
  155. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_integration_daemon_cgc.py +0 -0
  156. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mcp_transport.py +0 -0
  157. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mcp_validation.py +0 -0
  158. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_migration_coverage.py +0 -0
  159. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_migration_grace3_to_grace4.py +0 -0
  160. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_gate_script.py +0 -0
  161. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_cgc_edges.py +0 -0
  162. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_cgc_fallback.py +0 -0
  163. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_cgc_misc.py +0 -0
  164. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_context.py +0 -0
  165. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_crossref.py +0 -0
  166. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_hooks.py +0 -0
  167. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_kill_impact.py +0 -0
  168. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_mutation_probes.py +0 -0
  169. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_packaging.py +0 -0
  170. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_platform_branches.py +0 -0
  171. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_protocol_v2.py +0 -0
  172. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_provenance.py +0 -0
  173. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_release_edges.py +0 -0
  174. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_release_script.py +0 -0
  175. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_repo_hygiene.py +0 -0
  176. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_setup_artifacts.py +0 -0
  177. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_setup_failure_semantics.py +0 -0
  178. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_smoke.py +0 -0
  179. {doubled_graph-3.1.3 → doubled_graph-3.1.5}/tests/test_snapshot_oracle.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: doubled-graph
3
- Version: 3.1.3
3
+ Version: 3.1.5
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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "doubled-graph"
7
- version = "3.1.3"
7
+ version = "3.1.5"
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" }
@@ -53,6 +53,19 @@ DEFAULT_WAIT_TIMEOUT_S = 60.0
53
53
  #: `daemon.json`, not thousands.
54
54
  MAX_WAIT_INTERVAL_S = 2.0
55
55
 
56
+ #: `launchctl bootout` returns before launchd actually removes the job and
57
+ #: before the daemon process exits. Bootstrapping in that window fails with
58
+ #: "Bootstrap failed: 5: Input/output error", and a retry started immediately
59
+ #: hits the same window. Poll the supervisor instead of trusting the exit code.
60
+ #: Five seconds is enough for a normal unload. A wait that times out is
61
+ #: reported (``stop`` as failed, a bootstrap as its real refusal), never as a
62
+ #: silent success.
63
+ STOP_TIMEOUT_S = 5.0
64
+ STOP_POLL_INTERVAL_S = 0.05
65
+ #: One short pause after a refused bootstrap, for launchd's throttle of a job
66
+ #: that was booted out moments ago.
67
+ BOOTSTRAP_RETRY_DELAY_S = 0.25
68
+
56
69
  #: Statuses each restart step may report without making the restart a failure.
57
70
  #: ``stop`` accepts ``not_installed``: a first `setup` has nothing to stop, and
58
71
  #: that is not an error. Everything else must be the real supervisor action.
@@ -371,6 +384,82 @@ class ServiceManager:
371
384
  step["removed"] = removed
372
385
  return step
373
386
 
387
+ def _wait_until_unloaded(self, timeout: float | None = None) -> bool:
388
+ """Wait until the supervisor no longer reports the job as loaded.
389
+
390
+ ``bootout``/``disable --now`` return before the supervisor has
391
+ finished; a bootstrap in between is refused. Polling is the only
392
+ portable signal available through the manager API.
393
+ """
394
+ deadline = time.monotonic() + (STOP_TIMEOUT_S if timeout is None else timeout)
395
+ while True:
396
+ if not self._loaded():
397
+ return True
398
+ if time.monotonic() >= deadline:
399
+ return False
400
+ time.sleep(STOP_POLL_INTERVAL_S)
401
+
402
+ def _wait_until_running(self, timeout: float | None = None) -> bool:
403
+ """Wait until the supervisor reports the daemon as running."""
404
+ deadline = time.monotonic() + (STOP_TIMEOUT_S if timeout is None else timeout)
405
+ while True:
406
+ if self._running():
407
+ return True
408
+ if time.monotonic() >= deadline:
409
+ return False
410
+ time.sleep(STOP_POLL_INTERVAL_S)
411
+
412
+ def _wait_until_stopped(self, timeout: float | None = None) -> bool:
413
+ """Wait until the supervisor reports the daemon as no longer running.
414
+
415
+ ``bootout`` returns before launchd finishes; reporting ``stopped`` on
416
+ the exit code alone made a subsequent ``bootstrap`` race the unload.
417
+ Recorded foreground PIDs are deliberately not waited for here:
418
+ ``cleanup`` keeps their state files, and they are not ours to kill.
419
+ """
420
+ deadline = time.monotonic() + (STOP_TIMEOUT_S if timeout is None else timeout)
421
+ while True:
422
+ if not self._running():
423
+ return True
424
+ if time.monotonic() >= deadline:
425
+ return False
426
+ time.sleep(STOP_POLL_INTERVAL_S)
427
+
428
+ def _wait_after_stop(self) -> bool:
429
+ """Backend-specific post-stop wait.
430
+
431
+ ``launchctl bootout`` only removes the job asynchronously, so a
432
+ generic "state != running" check is not enough for launchd. systemd
433
+ keeps the unit enabled after ``stop``, so waiting for ``_loaded()``
434
+ there would be wrong. Subclasses override this when their supervisor
435
+ has an extra asynchronous step.
436
+ """
437
+ return True
438
+
439
+ def _bootstrap_fresh(self) -> CommandResult:
440
+ """Load the unit, healing a refused bootstrap after an async unload.
441
+
442
+ This is the repair for the launchd race behind the cross-project
443
+ incident: repo B's ``setup`` booted out the shared job, then
444
+ ``bootstrap`` in the unload window failed with code 5. If the first
445
+ load is refused while the old job is still in the table, drop it and
446
+ poll until the supervisor has really finished before retrying.
447
+ """
448
+ result = self._bootstrap()
449
+ if result.ok:
450
+ return result
451
+ if self._loaded():
452
+ # The bootstrap was refused because the old job is still in the
453
+ # table. Drop it and wait for the unload, not just for the process.
454
+ self._bootout()
455
+ if not self._wait_until_unloaded():
456
+ return result
457
+ return self._bootstrap()
458
+ # launchd also throttles a job that was booted out moments ago; one
459
+ # short retry distinguishes throttling from a real unit error.
460
+ time.sleep(BOOTSTRAP_RETRY_DELAY_S)
461
+ return self._bootstrap()
462
+
374
463
  def _loaded(self) -> bool:
375
464
  raise NotImplementedError
376
465
 
@@ -411,7 +500,7 @@ class ServiceManager:
411
500
  except OSError:
412
501
  return
413
502
  if previous is not None and was_loaded:
414
- self._bootstrap()
503
+ self._bootstrap_fresh()
415
504
 
416
505
  # -- public API -----------------------------------------------------
417
506
 
@@ -435,9 +524,7 @@ class ServiceManager:
435
524
  self._write_unit(desired)
436
525
  except OSError as exc:
437
526
  return self._report("failed", detail=f"{type(exc).__name__}: {exc}")
438
- if loaded:
439
- self._bootout()
440
- result = self._bootstrap()
527
+ result = self._bootstrap_fresh()
441
528
  if not result.ok:
442
529
  if "already" in result.output.lower() or "loaded" in result.output.lower():
443
530
  result = self._kickstart()
@@ -465,6 +552,17 @@ class ServiceManager:
465
552
  )
466
553
  report["returncode"] = result.returncode
467
554
  return report
555
+ if not self._wait_until_unloaded():
556
+ # `bootout` returned 0 but launchd still has the job. Deleting
557
+ # the plist now would leave a loaded service with no unit to
558
+ # inspect or unload; keep it and report the real state.
559
+ return self._report(
560
+ "failed",
561
+ detail=(
562
+ "the supervisor accepted bootout, but the job is still "
563
+ f"loaded after {STOP_TIMEOUT_S:g}s; unit kept"
564
+ ),
565
+ )
468
566
  if path is not None:
469
567
  try:
470
568
  path.unlink()
@@ -532,33 +630,34 @@ class ServiceManager:
532
630
  # unloaded (after `daemon stop`) must still be startable.
533
631
  if not self.unit_present():
534
632
  return self._report("not_installed")
535
- loaded = self._loaded()
536
- result = self._kickstart() if loaded else self._bootstrap()
537
- if not result.ok and loaded:
633
+ first: CommandResult | None = None
634
+ if self._loaded():
635
+ result = self._kickstart()
636
+ if result.ok:
637
+ return self._report("started")
538
638
  # `bootout` can return 0 while launchd still has the job in its
539
- # table ("stale" job). `kickstart` against that half-unloaded job
540
- # fails, and a plain retry of `bootstrap` is refused because the
541
- # job is "already loaded". Drop the stale job first and load the
542
- # unit from scratch; this is the repair launchd needs.
639
+ # table ("stale" job), and `kickstart` against that half-unloaded
640
+ # job fails. Drop the stale job, wait for the unload to finish,
641
+ # then load the unit from scratch; bootstrapping immediately is
642
+ # what produced "Bootstrap failed: 5" in the incident.
543
643
  first = result
544
- self._bootout()
545
- result = self._bootstrap()
546
- if not result.ok:
547
- # Name both supervisor refusals: the kickstart failure is the
548
- # reason the fallback ran, not noise to discard.
549
- detail = "; ".join(
550
- part
551
- for part in dict.fromkeys((first.output, result.output))
552
- if part
553
- )
554
- stderr = "\n".join(
555
- part
556
- for part in dict.fromkeys((first.stderr, result.stderr))
557
- if part
558
- )
559
- return self._report("failed", detail=detail, stderr=stderr)
644
+ result = self._bootstrap_fresh()
560
645
  if not result.ok:
561
- return self._report("failed", detail=result.output, stderr=result.stderr)
646
+ if first is None:
647
+ return self._report("failed", detail=result.output, stderr=result.stderr)
648
+ # Name both supervisor refusals: the kickstart failure is the
649
+ # reason the fallback ran, not noise to discard.
650
+ detail = "; ".join(
651
+ part
652
+ for part in dict.fromkeys((first.output, result.output))
653
+ if part
654
+ )
655
+ stderr = "\n".join(
656
+ part
657
+ for part in dict.fromkeys((first.stderr, result.stderr))
658
+ if part
659
+ )
660
+ return self._report("failed", detail=detail, stderr=stderr)
562
661
  return self._report("started")
563
662
 
564
663
 
@@ -572,6 +671,22 @@ class ServiceManager:
572
671
  result = self._stop_command()
573
672
  if not result.ok:
574
673
  return self._report("failed", detail=result.output, stderr=result.stderr)
674
+ if not self._wait_until_stopped():
675
+ return self._report(
676
+ "failed",
677
+ detail=(
678
+ "the supervisor accepted the stop, but the daemon is still "
679
+ f"running after {STOP_TIMEOUT_S:g}s"
680
+ ),
681
+ )
682
+ if not self._wait_after_stop():
683
+ return self._report(
684
+ "failed",
685
+ detail=(
686
+ "the supervisor accepted the stop, but the job is still "
687
+ f"loaded after {STOP_TIMEOUT_S:g}s"
688
+ ),
689
+ )
575
690
  return self._report("stopped")
576
691
 
577
692
  def restart(
@@ -594,7 +709,9 @@ class ServiceManager:
594
709
  Since 3.0.3 the operation is also **self-healing**, because a plist on
595
710
  disk is not a loaded job:
596
711
 
597
- 1. ``stop`` — bootout/stop/``/End`` the old process, if any;
712
+ 1. ``stop`` — bootout/stop/``/End`` the old process and wait until the
713
+ supervisor reports it as no longer running (``bootout`` returns
714
+ before launchd finishes);
598
715
  2. ``cleanup`` — delete ``daemon.json``/``daemon.sock``/``graphd.pid``
599
716
  and the stale ``graphd.lock`` *only* when every recorded owner PID
600
717
  is dead (a live foreground daemon keeps its files);
@@ -602,8 +719,10 @@ class ServiceManager:
602
719
  systemd unit, the state that turns ``bootstrap`` into
603
720
  ``Bootstrap failed: 5`` or ``Could not find service``;
604
721
  4. ``install`` — rewrite the unit for this interpreter/``--home``;
605
- 5. ``start`` — bootstrap the job, then (when ``wait_timeout`` > 0)
606
- wait for ``ping`` and require the daemon's package version.
722
+ 5. ``start`` — bootstrap the job only after any previous job is
723
+ really unloaded (refused bootstraps are retried after polling
724
+ ``print``), then (when ``wait_timeout`` > 0) wait for ``ping`` and
725
+ require the daemon's package version.
607
726
 
608
727
  Every step is reported with its own ``status``; a failure keeps the
609
728
  real supervisor ``stderr`` and a diagnostic ``hint`` (``log show`` on
@@ -853,6 +972,9 @@ class LaunchdManager(ServiceManager):
853
972
  "</plist>\n"
854
973
  )
855
974
 
975
+ def _wait_after_stop(self) -> bool:
976
+ return self._wait_until_unloaded()
977
+
856
978
  def _loaded(self) -> bool:
857
979
  return self.run(["launchctl", "print", self._target]).ok
858
980
 
@@ -1095,11 +1217,17 @@ class TaskSchedulerManager(ServiceManager):
1095
1217
 
1096
1218
  def start(self) -> dict[str, Any]:
1097
1219
  result = self.run(["schtasks", "/Run", "/TN", WINDOWS_TASK])
1098
- return self._report(
1099
- "started" if result.ok else "failed",
1100
- detail=result.output,
1101
- stderr=result.stderr,
1102
- )
1220
+ if not result.ok:
1221
+ return self._report("failed", detail=result.output, stderr=result.stderr)
1222
+ if not self._wait_until_running():
1223
+ return self._report(
1224
+ "failed",
1225
+ detail=(
1226
+ "schtasks accepted /Run, but the task is not Running after "
1227
+ f"{STOP_TIMEOUT_S:g}s"
1228
+ ),
1229
+ )
1230
+ return self._report("started")
1103
1231
 
1104
1232
  def stop(self) -> dict[str, Any]:
1105
1233
  if not self._query().ok:
@@ -1110,11 +1238,17 @@ class TaskSchedulerManager(ServiceManager):
1110
1238
  # treat this as a refused stop.
1111
1239
  return self._report("not_running")
1112
1240
  result = self.run(["schtasks", "/End", "/TN", WINDOWS_TASK])
1113
- return self._report(
1114
- "stopped" if result.ok else "failed",
1115
- detail=result.output,
1116
- stderr=result.stderr,
1117
- )
1241
+ if not result.ok:
1242
+ return self._report("failed", detail=result.output, stderr=result.stderr)
1243
+ if not self._wait_until_stopped():
1244
+ return self._report(
1245
+ "failed",
1246
+ detail=(
1247
+ "schtasks accepted /End, but the task is still Running after "
1248
+ f"{STOP_TIMEOUT_S:g}s"
1249
+ ),
1250
+ )
1251
+ return self._report("stopped")
1118
1252
 
1119
1253
 
1120
1254
  class UnsupportedServiceManager(ServiceManager):
@@ -335,6 +335,11 @@ def _process_command(pid: str) -> str | None:
335
335
  return result.stdout.strip()
336
336
 
337
337
 
338
+ #: SIGKILL is observable only after the process is reaped; give the kernel a
339
+ #: short window before claiming the old MCP server is gone.
340
+ _MCP_SIGKILL_WAIT_S = 2.0
341
+
342
+
338
343
  def kill_running_mcp_servers(dry_run: bool = False) -> dict[str, Any]:
339
344
  """Find and SIGTERM (then SIGKILL) any `python -m doubled_graph serve` processes.
340
345
 
@@ -428,10 +433,30 @@ def kill_running_mcp_servers(dry_run: bool = False) -> dict[str, Any]:
428
433
  except (ProcessLookupError, ValueError, PermissionError):
429
434
  continue # already dead, fine
430
435
 
436
+ # SIGKILL is asynchronous for our purposes: a zombie/reaping process can
437
+ # still answer `kill(0)`. Verify death before telling `setup` that the old
438
+ # MCP server is gone (otherwise pip install continues over a live process).
439
+ survived: list[str] = []
440
+ deadline = time.monotonic() + _MCP_SIGKILL_WAIT_S
441
+ pending = set(killed_term)
442
+ while True:
443
+ for pid in list(pending):
444
+ try:
445
+ os.kill(int(pid), 0)
446
+ except (ProcessLookupError, ValueError):
447
+ pending.discard(pid)
448
+ except PermissionError:
449
+ # It exists and is not ours to reap: do not claim it is gone.
450
+ continue
451
+ if not pending or time.monotonic() >= deadline:
452
+ break
453
+ time.sleep(0.05)
454
+ survived = sorted(pending)
431
455
  return {
432
- "status": "killed",
456
+ "status": "killed" if not survived else "failed",
433
457
  "sigterm": killed_term,
434
458
  "sigkill": killed_kill,
459
+ "survived": survived,
435
460
  "hint": "Your IDE will re-spawn the MCP server on next tool call (or after a `/mcp` reconnect).",
436
461
  }
437
462
 
@@ -1643,6 +1668,14 @@ def run_setup(
1643
1668
  elif kill_report["status"] == "dry_run":
1644
1669
  n = len(kill_report.get("would_kill", []))
1645
1670
  _log(f"{prefix}[pre] Would kill {n} running MCP server(s).")
1671
+ elif kill_report["status"] == "failed":
1672
+ survived = ", ".join(kill_report.get("survived", []))
1673
+ warning = (
1674
+ "mcp_servers_survived: the old MCP server process(es) "
1675
+ f"{survived} survived SIGKILL; the IDE may keep serving stale code"
1676
+ )
1677
+ report.setdefault("warnings", []).append(warning)
1678
+ _log(f"{prefix}[pre] WARNING: {warning}")
1646
1679
 
1647
1680
  # 1. Grace CLI — slow: subprocess to a JS package manager can take 10–30s.
1648
1681
  _log(f"{prefix}[1/{total}] Installing @osovv/grace-cli (may take 10–30s)…")
@@ -78,6 +78,10 @@ _CONTAINER_DIRS: tuple[str, ...] = (
78
78
  #: Grace period between SIGTERM and SIGKILL for a daemon whose supervisor can
79
79
  #: no longer control it (foreground `daemon run`, crashed supervisor, ...).
80
80
  DAEMON_STOP_TIMEOUT_S = 5.0
81
+ #: SIGKILL is not synchronously observable: the process can still be a zombie
82
+ #: (or not yet reaped) when `kill(0)` answers. Confirm its death before
83
+ #: reporting "killed", otherwise uninstall removes state under a dying DB owner.
84
+ SIGKILL_WAIT_S = 2.0
81
85
  _POLL_INTERVAL_S = 0.1
82
86
 
83
87
  #: Commands that identify a per-repository embedded engine. ``falkor_worker``
@@ -137,11 +141,17 @@ def _terminate(
137
141
  pid: int,
138
142
  *,
139
143
  timeout: float = DAEMON_STOP_TIMEOUT_S,
144
+ kill_timeout: float = SIGKILL_WAIT_S,
140
145
  alive: Callable[[int], bool] | None = None,
141
146
  sleep: Callable[[float], None] | None = None,
142
147
  monotonic: Callable[[], float] | None = None,
143
148
  ) -> dict[str, Any]:
144
- """SIGTERM *pid*, wait up to *timeout*, then SIGKILL if it is still alive."""
149
+ """SIGTERM *pid*, wait up to *timeout*, then SIGKILL and wait *kill_timeout*.
150
+
151
+ ``killed`` is returned only after the process is observed dead. Sending
152
+ SIGKILL and returning immediately made ``stop_orphaned_engines`` inspect a
153
+ still-dying process and remove its database/state while it was alive.
154
+ """
145
155
  alive = alive or _pid_alive
146
156
  sleep = sleep or time.sleep
147
157
  monotonic = monotonic or time.monotonic
@@ -162,7 +172,20 @@ def _terminate(
162
172
  return {"status": "stopped", "pid": pid}
163
173
  except OSError as exc:
164
174
  return {"status": "failed", "pid": pid, "detail": f"{type(exc).__name__}: {exc}"}
165
- return {"status": "killed", "pid": pid}
175
+ if kill_timeout <= 0:
176
+ return {"status": "killed", "pid": pid}
177
+ deadline = monotonic() + kill_timeout
178
+ while monotonic() < deadline:
179
+ if not alive(pid):
180
+ return {"status": "killed", "pid": pid}
181
+ sleep(_POLL_INTERVAL_S)
182
+ if not alive(pid):
183
+ return {"status": "killed", "pid": pid}
184
+ return {
185
+ "status": "failed",
186
+ "pid": pid,
187
+ "detail": "SIGKILL was sent but the process is still alive",
188
+ }
166
189
 
167
190
 
168
191
  def stop_daemon(probe: Callable[[], dict[str, Any]] | None = None) -> dict[str, Any]:
@@ -16,16 +16,20 @@ State model (deterministic, no timing races):
16
16
  ``running``;
17
17
  * ``kickstart`` on a stale job fails with no output (the incident's
18
18
  ``start: failed`` with no detail);
19
- * a **second** ``bootout`` removes the stale job and returns 0. This models
20
- launchd completing the unload on the retry, and is what makes the fixed
21
- setup able to bootstrap a fresh daemon.
19
+ * with ``FAKE_LAUNCHCTL_UNLOAD_DELAY`` the stale job stays in the table for
20
+ that many seconds; ``bootstrap`` is refused until the delay expires, and a
21
+ repeated ``bootout`` does not shorten it. Production code must poll
22
+ ``print`` instead of bootstrapping immediately;
23
+ * without the delay the next ``bootout`` removes the stale job immediately.
22
24
 
23
25
  Environment (all provided by the test):
24
26
 
25
27
  ``FAKE_LAUNCHCTL_STATE``
26
28
  directory for ``job.json``, ``started-pids.log`` and ``launchctl.log``;
27
29
  ``FAKE_LAUNCHCTL_LOG``
28
- invocation log (defaults to ``$FAKE_LAUNCHCTL_STATE/launchctl.log``).
30
+ invocation log (defaults to ``$FAKE_LAUNCHCTL_STATE/launchctl.log``);
31
+ ``FAKE_LAUNCHCTL_UNLOAD_DELAY``
32
+ seconds the supervisor keeps a stale job loaded (default 0).
29
33
 
30
34
  The real ``launchd`` is never contacted: the test asserts that
31
35
  ``shutil.which("launchctl")`` resolves to this file before and after the run.
@@ -86,6 +90,29 @@ def _remove_job() -> None:
86
90
  pass
87
91
 
88
92
 
93
+ def _unload_delay() -> float:
94
+ raw = os.environ.get("FAKE_LAUNCHCTL_UNLOAD_DELAY", "0")
95
+ try:
96
+ return max(float(raw), 0.0)
97
+ except ValueError:
98
+ return 0.0
99
+
100
+
101
+ def _visible_job() -> dict[str, Any] | None:
102
+ """The job launchd still reports; a delayed unload finishes on read."""
103
+ job = _read_job()
104
+ if job is None:
105
+ return None
106
+ if (
107
+ job.get("stale")
108
+ and job.get("unload_at") is not None
109
+ and time.monotonic() >= float(job["unload_at"])
110
+ ):
111
+ _remove_job()
112
+ return None
113
+ return job
114
+
115
+
89
116
  def _append_pid(pid: int) -> None:
90
117
  with open(_state_dir() / "started-pids.log", "a", encoding="utf-8") as handle:
91
118
  handle.write(f"{pid}\n")
@@ -196,7 +223,7 @@ def handle(argv: list[str]) -> tuple[int, str]:
196
223
  if verb == "bootstrap":
197
224
  if len(argv) < 3:
198
225
  return 2, "bootstrap: domain and plist are required"
199
- if _read_job() is not None:
226
+ if _visible_job() is not None:
200
227
  # A stale job is still in the table; launchd refuses a second load.
201
228
  return 5, "Bootstrap failed: 5: Input/output error"
202
229
  try:
@@ -207,23 +234,31 @@ def handle(argv: list[str]) -> tuple[int, str]:
207
234
 
208
235
  if verb == "print":
209
236
  target = _target(argv[1:])
210
- job = _read_job()
237
+ job = _visible_job()
211
238
  if job is None:
212
239
  return 3, f'Could not find service "{target}" in domain'
213
240
  return _print_job(target, job), ""
214
241
 
215
242
  if verb == "bootout":
216
243
  target = _target(argv[1:])
217
- job = _read_job()
244
+ job = _visible_job()
218
245
  if job is None:
219
246
  return 3, f'Could not find service "{target}" in domain'
247
+ delay = _unload_delay()
220
248
  if job.get("stale"):
221
- # The supervisor finishes the unload on the retry.
222
- _remove_job()
249
+ # The supervisor is already unloading; a repeated bootout does
250
+ # not make it instantaneous.
251
+ if delay > 0 and job.get("unload_at") is None:
252
+ job["unload_at"] = time.monotonic() + delay
253
+ _write_job(job)
254
+ elif delay <= 0:
255
+ _remove_job()
223
256
  return 0, ""
224
257
  pid = job.get("pid")
225
258
  _terminate(pid)
226
259
  job["stale"] = True
260
+ if delay > 0:
261
+ job["unload_at"] = time.monotonic() + delay
227
262
  _write_job(job)
228
263
  # Record the incident transition: rc=0, process dead, job still loaded.
229
264
  with open(_state_dir() / "stale-events.log", "a", encoding="utf-8") as event:
@@ -232,7 +267,7 @@ def handle(argv: list[str]) -> tuple[int, str]:
232
267
 
233
268
  if verb == "kickstart":
234
269
  target = _target(argv[1:])
235
- job = _read_job()
270
+ job = _visible_job()
236
271
  if job is None:
237
272
  return 3, f'Could not find service "{target}" in domain'
238
273
  if job.get("stale"):
@@ -887,7 +887,14 @@ class _StubManager(service.ServiceManager):
887
887
  def _bootstrap(self) -> CommandResult:
888
888
  return CommandResult(0 if self.start_ok else 1, "", "" if self.start_ok else "denied")
889
889
 
890
+ def _bootout(self) -> CommandResult:
891
+ if self.stop_ok:
892
+ self.loaded = False
893
+ return CommandResult(0 if self.stop_ok else 1, "", "" if self.stop_ok else "denied")
894
+
890
895
  def _stop_command(self) -> CommandResult:
896
+ if self.stop_ok:
897
+ self.loaded = False
891
898
  return CommandResult(0 if self.stop_ok else 1, "", "" if self.stop_ok else "denied")
892
899
 
893
900
 
@@ -1033,6 +1040,97 @@ def test_task_scheduler_reports_failures(home: Path, tmp_path: Path) -> None:
1033
1040
  assert delete_failed.uninstall()["status"] == "failed"
1034
1041
 
1035
1042
 
1043
+ def test_task_scheduler_start_waits_for_the_running_state(
1044
+ home: Path, tmp_path: Path, monkeypatch
1045
+ ) -> None:
1046
+ state = TaskState()
1047
+ state.exists = True
1048
+ manager = TaskSchedulerManager(home=home, runner=state.runner, unit_dir=tmp_path)
1049
+ seen: list[bool] = []
1050
+ answers = iter([False, False, True])
1051
+
1052
+ def running() -> bool:
1053
+ value = next(answers)
1054
+ seen.append(value)
1055
+ return value
1056
+
1057
+ monkeypatch.setattr(manager, "_running", running)
1058
+
1059
+ report = manager.start()
1060
+
1061
+ assert report["status"] == "started"
1062
+ assert len(seen) == 3
1063
+
1064
+
1065
+ def test_task_scheduler_stop_waits_for_the_ready_state(
1066
+ home: Path, tmp_path: Path, monkeypatch
1067
+ ) -> None:
1068
+ state = TaskState()
1069
+ state.exists = True
1070
+ manager = TaskSchedulerManager(home=home, runner=state.runner, unit_dir=tmp_path)
1071
+ seen: list[bool] = []
1072
+ answers = iter([True, True, False])
1073
+
1074
+ def running() -> bool:
1075
+ value = next(answers)
1076
+ seen.append(value)
1077
+ return value
1078
+
1079
+ monkeypatch.setattr(manager, "_running", running)
1080
+
1081
+ report = manager.stop()
1082
+
1083
+ assert report["status"] == "stopped"
1084
+ assert len(seen) == 3
1085
+
1086
+
1087
+ def test_task_scheduler_start_reports_run_failure_and_timeout(
1088
+ home: Path, tmp_path: Path, monkeypatch
1089
+ ) -> None:
1090
+ state = TaskState()
1091
+ state.exists = True
1092
+
1093
+ def denied(args: list[str]) -> CommandResult:
1094
+ if args[1] == "/Run":
1095
+ return CommandResult(1, "", "Access denied")
1096
+ return state.runner(args)
1097
+
1098
+ manager = TaskSchedulerManager(home=home, runner=denied, unit_dir=tmp_path)
1099
+ assert manager.start()["status"] == "failed"
1100
+
1101
+ manager = TaskSchedulerManager(home=home, runner=state.runner, unit_dir=tmp_path)
1102
+ monkeypatch.setattr(manager, "_running", lambda: False)
1103
+ monkeypatch.setattr(service, "STOP_TIMEOUT_S", 0.01)
1104
+ monkeypatch.setattr(service, "STOP_POLL_INTERVAL_S", 0.001)
1105
+ report = manager.start()
1106
+ assert report["status"] == "failed"
1107
+ assert "not Running" in report["detail"]
1108
+
1109
+
1110
+ def test_task_scheduler_stop_reports_end_failure_and_timeout(
1111
+ home: Path, tmp_path: Path, monkeypatch
1112
+ ) -> None:
1113
+ state = TaskState()
1114
+ state.exists = True
1115
+ state.running = True
1116
+
1117
+ def denied(args: list[str]) -> CommandResult:
1118
+ if args[1] == "/End":
1119
+ return CommandResult(1, "", "Access denied")
1120
+ return state.runner(args)
1121
+
1122
+ manager = TaskSchedulerManager(home=home, runner=denied, unit_dir=tmp_path)
1123
+ assert manager.stop()["status"] == "failed"
1124
+
1125
+ manager = TaskSchedulerManager(home=home, runner=state.runner, unit_dir=tmp_path)
1126
+ monkeypatch.setattr(manager, "_running", lambda: True)
1127
+ monkeypatch.setattr(service, "STOP_TIMEOUT_S", 0.01)
1128
+ monkeypatch.setattr(service, "STOP_POLL_INTERVAL_S", 0.001)
1129
+ report = manager.stop()
1130
+ assert report["status"] == "failed"
1131
+ assert "still Running" in report["detail"]
1132
+
1133
+
1036
1134
  def test_task_scheduler_stop_is_idempotent_when_not_running(
1037
1135
  home: Path, tmp_path: Path
1038
1136
  ) -> None:
@@ -1149,6 +1247,7 @@ def test_failed_update_restores_the_previous_unit_and_reloads_it(
1149
1247
  recorder = Recorder(state.runner)
1150
1248
  manager = LaunchdManager(home=home, runner=recorder, unit_dir=unit_dir)
1151
1249
  assert manager.install()["status"] == "installed"
1250
+ recorder.calls.clear()
1152
1251
 
1153
1252
  plist = unit_dir / f"{service.SERVICE_LABEL}.plist"
1154
1253
  previous = "previous-unit-bytes"
@@ -1159,8 +1258,16 @@ def test_failed_update_restores_the_previous_unit_and_reloads_it(
1159
1258
  recorder.calls.append(list(args))
1160
1259
  command = args[1] if len(args) > 1 else ""
1161
1260
  if command == "print":
1162
- return CommandResult(0, "state = running\n", "")
1261
+ if not state.loaded:
1262
+ return CommandResult(113, "", "Could not find service")
1263
+ state_name = "running" if state.running else "waiting"
1264
+ return CommandResult(0, f"state = {state_name}\n", "")
1163
1265
  if command == "bootstrap":
1266
+ # The new unit is rejected; the restored old unit is accepted.
1267
+ if plist.read_text(encoding="utf-8") == previous:
1268
+ state.loaded = True
1269
+ state.running = True
1270
+ return CommandResult(0)
1164
1271
  return CommandResult(5, "", "Bootstrap failed: 5: Input/output error")
1165
1272
  if command == "bootout":
1166
1273
  state.loaded = False