worktree-controller 1.32.2__tar.gz → 1.32.4__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 (79) hide show
  1. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/PKG-INFO +11 -1
  2. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/README.md +10 -0
  3. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/architecture.md +7 -0
  4. worktree_controller-1.32.4/docs/integration-boundaries.md +68 -0
  5. worktree_controller-1.32.4/docs/roadmap.md +46 -0
  6. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/scope.md +16 -10
  7. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/pyproject.toml +1 -1
  8. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/pyproject.toml.orig +1 -1
  9. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/__init__.py +1 -1
  10. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/cli.py +1 -0
  11. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/convergence.py +3 -3
  12. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/delivered_closeout.py +120 -1
  13. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/lifecycle.py +21 -78
  14. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/preserved_cleanup.py +5 -0
  15. worktree_controller-1.32.4/src/worktree_controller/release_intents.py +57 -0
  16. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/semantics.py +28 -0
  17. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/tool_cli_contract.json +9 -1
  18. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/tool_cli_contract.json +9 -1
  19. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/LICENSE +0 -0
  20. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/client-integration.md +0 -0
  21. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/daily-workflow.md +0 -0
  22. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/first-change.md +0 -0
  23. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/getting-started.md +0 -0
  24. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/operations.md +0 -0
  25. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/publishing.md +0 -0
  26. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/docs/reference.md +0 -0
  27. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/examples/change_task.py +0 -0
  28. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/examples/client_continuation.py +0 -0
  29. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/examples/quickstart.py +0 -0
  30. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/activation_layout.py +0 -0
  31. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/branch_retirement.py +0 -0
  32. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/canonical_refresh.py +0 -0
  33. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/canonical_transition.py +0 -0
  34. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/cleanup_attempts.py +0 -0
  35. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/cleanup_evidence.py +0 -0
  36. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/cleanup_recovery.py +0 -0
  37. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/controller.py +0 -0
  38. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/disposable.py +0 -0
  39. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/environment.py +0 -0
  40. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/frozen_recovery.py +0 -0
  41. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/git_backend.py +0 -0
  42. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/governance.py +0 -0
  43. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/hardlinks.py +0 -0
  44. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/integration_cleanup.py +0 -0
  45. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/integration_conflict.py +0 -0
  46. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/integration_retry.py +0 -0
  47. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/keyed_document_scope.py +0 -0
  48. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/lifecycle_history.py +0 -0
  49. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/lifecycle_observation.py +0 -0
  50. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/metadata_codec.py +0 -0
  51. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/metadata_relocation.py +0 -0
  52. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/models.py +0 -0
  53. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/mount_diagnostics.py +0 -0
  54. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/multiple_cleanup_recovery.py +0 -0
  55. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/namespace_migration.py +0 -0
  56. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/native_session_recovery.py +0 -0
  57. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/owner_actions.py +0 -0
  58. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/policy.py +0 -0
  59. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/preservation.py +0 -0
  60. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/publication_execution.py +0 -0
  61. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/reconciler.py +0 -0
  62. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/record_updates.py +0 -0
  63. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/recovery_guidance.py +0 -0
  64. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/registration_backfill.py +0 -0
  65. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/registration_prune.py +0 -0
  66. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/rendering.py +0 -0
  67. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/resource_admission.py +0 -0
  68. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/retirement_adapters.py +0 -0
  69. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/retirement_execution.py +0 -0
  70. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/session.py +0 -0
  71. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/session_admission.py +0 -0
  72. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/source_cleanup.py +0 -0
  73. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/source_preservation.py +0 -0
  74. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/source_recovery.py +0 -0
  75. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/store.py +0 -0
  76. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/task_workflow.py +0 -0
  77. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/transaction_scope.py +0 -0
  78. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/writer_lease.py +0 -0
  79. {worktree_controller-1.32.2 → worktree_controller-1.32.4}/src/worktree_controller/writer_session.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: worktree-controller
3
- Version: 1.32.2
3
+ Version: 1.32.4
4
4
  Summary: Govern Git worktree budgets, authority, ownership, and lifecycle
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -114,3 +114,13 @@ a successful process exit alone does not prove that all worktrees are settled.
114
114
  - [Report a security issue](https://github.com/xuanheng-tech/worktree-controller/blob/main/SECURITY.md)
115
115
 
116
116
  Licensed under the [Apache License 2.0](https://github.com/xuanheng-tech/worktree-controller/blob/main/LICENSE).
117
+
118
+ With `terminal_preserved_cleanup_version` 1, published integrations and completed
119
+ no-change feature/audit tasks may use the existing preservation and `resource-clean --typed`
120
+ flow. Require one exact remote-verified, lease-cleared publication or one verified original
121
+ no-change completion. Every removed tree needs immutable preservation coverage.
122
+ Plans pin the current verified proof baseline; cleanup and release recheck it without
123
+ rewriting history, reopening lifecycle or relaxing owner/HEAD/CAS, runtime, lease, retained-ref
124
+ and transaction guards. A newly observed legacy digest is not historical hash evidence.
125
+ New-format no-change completions may clean afterward only when their frozen prior cleanup
126
+ set is empty; existing pre-completion proofs retain their original CAS.
@@ -97,3 +97,13 @@ a successful process exit alone does not prove that all worktrees are settled.
97
97
  - [Report a security issue](https://github.com/xuanheng-tech/worktree-controller/blob/main/SECURITY.md)
98
98
 
99
99
  Licensed under the [Apache License 2.0](https://github.com/xuanheng-tech/worktree-controller/blob/main/LICENSE).
100
+
101
+ With `terminal_preserved_cleanup_version` 1, published integrations and completed
102
+ no-change feature/audit tasks may use the existing preservation and `resource-clean --typed`
103
+ flow. Require one exact remote-verified, lease-cleared publication or one verified original
104
+ no-change completion. Every removed tree needs immutable preservation coverage.
105
+ Plans pin the current verified proof baseline; cleanup and release recheck it without
106
+ rewriting history, reopening lifecycle or relaxing owner/HEAD/CAS, runtime, lease, retained-ref
107
+ and transaction guards. A newly observed legacy digest is not historical hash evidence.
108
+ New-format no-change completions may clean afterward only when their frozen prior cleanup
109
+ set is empty; existing pre-completion proofs retain their original CAS.
@@ -12,6 +12,7 @@ development and recovery paths; exact public interfaces live in the [contract](.
12
12
  | Git observations and mutations | `git_backend.py` | Git owns registrations, refs, paths, HEAD and cleanliness |
13
13
  | State and durable evidence | `models.py`, `store.py`, `metadata_codec.py`, `record_updates.py` | Validate stored identities; serialize mutations under the repository lock; record updates bump their version, and both update helpers append history |
14
14
  | Shared identity and semantic checks | `semantics.py` | Consume the caller's snapshot, including effective intent state and terminal reconciliation; do not acquire authority or write metadata |
15
+ | Release-intent queries | `release_intents.py` | Select from the caller's snapshot and calculate renewal backoff using its supplied time; no metadata writes or fresh observation |
15
16
  | Budget admission | `resource_admission.py` | Preserve durable request identity and host reservations across retries |
16
17
  | Writer entitlement | `writer_lease.py`, `writer_session.py`, `governance.py` | Bind the real process identity and exact operation/target |
17
18
  | Lifecycle orchestration | `lifecycle.py` and focused recovery modules | Compose existing guards and append durable transition evidence |
@@ -76,3 +77,9 @@ Further lifecycle extraction should follow one cohesive transition at a time, ke
76
77
  scope and immutable evidence together. Avoid moving mutation helpers that depend on lifecycle's
77
78
  clock, transaction state or caller-specific guards merely to reduce a line count. Public CLI,
78
79
  capability and storage changes require their own version and compatibility review.
80
+
81
+ Release-intent selection and renewal backoff share a pure query module. Lifecycle keeps the
82
+ mutation helpers, clock, lock scope, cancellation and history append unchanged. Convergence
83
+ uses the same query directly; lifecycle retains its existing internal aliases. A changed HEAD
84
+ or record version still renews immediately, and repeated unchanged expiries retain the existing
85
+ one-day backoff cap. This extraction changes no CLI, capability or storage contract.
@@ -0,0 +1,68 @@
1
+ # Consumer and protocol boundaries
2
+
3
+ Inventory verified on 2026-10-23 against WC 1.32.3 (CLI 61, storage 5) and GF 1.9.7.
4
+ This is a source inventory, not an observation of every installed host or external user.
5
+ The public [CLI contract](../tool_cli_contract.json) remains authoritative.
6
+ [Scope](scope.md) records the conservative decision to keep existing commands supported.
7
+
8
+ ## Existing delivery protocols
9
+
10
+ | Flow | Producer authority | Consumer responsibility | Required evidence and refusal |
11
+ | --- | --- | --- | --- |
12
+ | Integration publication | WC `integration-publication-session/v1`; repository lock spans verify, authorize, push observation and completion | GF publishes the exact authorized candidate with a non-force push and independently observes the remote | Repository/allocation, lease/run, candidate, expected main, record version and validation identity must match. Missing capability, drift or incomplete completion blocks. After uncertain transport, inspect remote facts and re-enter the same identity. |
13
+ | Branch retirement | WC `branch-retirement-execution/v1` and `retirement-execution-result/v1` | GF performs only the plan-authorized exact-OID ref operation | The public plan, verify, authorize and complete results bind the operation and ancestry proof. Missing refs alone do not establish a completed retirement; retain recovery identity. |
14
+ | Sensitive source review | GF owns its review-file schema | Treat the four WC linkage fields as opaque identities | No derivation of private authority digests or parsing WC metadata to construct authority. |
15
+ | Review evidence | SR owns `snapshot-runner read`, evidence-read schema 1 and stored-era validation | GF's explicit initial-publish mode consumes public fields | Unknown schema, partial output, gaps or identity mismatch blocks; GF does not parse SR storage or hard-code its security epoch. |
16
+ | Deployment health | The published toolchain catalog, currently owned by GF | `tool-skill-sync doctor` verifies installed capabilities and the frozen runtime contract | Explicit CLI/storage allowlists and required capability versions all apply. Source availability or equal CLI numbers alone do not prove compatibility. |
17
+
18
+ These protocols already exist. The next step is preserving and testing them, not designing a
19
+ replacement message bus or accepting unknown versions. Protocol/capability versioning does not
20
+ relax the deployment catalog's explicit CLI/storage compatibility checks.
21
+
22
+ GF is independently usable for its core Git operations. WC/SR adapters run only when their
23
+ corresponding operation is requested. GF's
24
+ [adapter inventory and regression matrix](https://github.com/xuanheng-tech/git-finalizer/blob/828c35a3bc3d60c5ef25f1fb5221a086e749c0b5/docs/integration-boundaries.md)
25
+ is the consumer-owned authority. WC owns lifecycle; a GF execution receipt still needs the
26
+ formal `lease-complete` flow before lifecycle completion.
27
+
28
+ Two bounded legacy couplings remain: GF checks WC namespace directory **existence** to report
29
+ a migration blocker, and recognizes exact public contract descriptions in its scanner. Neither
30
+ is general private-state parsing. Replace the existence probe only after a producer-owned
31
+ public unmanaged/legacy/migrated verdict exists and all negative controls pass. Keep the narrow
32
+ scanner recognition until an agreed producer/consumer contract change replaces it; never widen
33
+ the scanner or silently fall back to private files.
34
+
35
+ ## Host consumers
36
+
37
+ A fresh inspection of AW's current controller client confirms the following source call paths:
38
+
39
+ | Surface | Evidence classification | Ownership decision |
40
+ | --- | --- | --- |
41
+ | `host-execution`, `execution-admit/cancel`, `admission-queue` | Direct calls | WC governs admission and resource claims; AW keeps business scheduling and host policy. |
42
+ | `session-admit` | Direct `_invoke` call after capability negotiation | Supported. The earlier audit's absence claim is obsolete. |
43
+ | `session-bind` | Argument tuple passed through `_run`, rather than a literal `_invoke` call | Supported. An `_invoke`-only search misses this consumer. |
44
+ | `binding-add/remove/transfer` | Transfer is direct; add/remove are dynamically composed by a bounded helper | Supported; explicit client/session identity and existing lease checks remain required. |
45
+ | `lifecycle-events`, `lifecycle-event-ack` | Direct calls | WC owns event identity; AW acknowledges after its own durable update. |
46
+ | `reconcile-session` | No direct external AW CLI call found in this inspection; WC's shipped session-end adapter calls the lifecycle function | Supported. No proof of exclusive use or safe deprecation. |
47
+
48
+ Also observed: plan/acquire/resume/status/capabilities, writer lease acquire/release and write
49
+ guard; integration queue/refresh/validate, publication lease acquire/complete, reconciliation,
50
+ release-intent and lifecycle-history. Static literals are evidence of a call path, not runtime
51
+ frequency or a complete list of dynamically constructed commands.
52
+
53
+ No AW identity default, resource limit, QP policy or business approval changes in this inventory.
54
+ Any future host-policy relocation needs consumer-owned changes, staged compatibility, migration
55
+ and rollback. Recovery commands remain supported until all consumers have an evidence-backed
56
+ migration and a published deprecation window.
57
+
58
+ ## Regression and change gates
59
+
60
+ - WC: public CLI/API contract tests plus the affected lifecycle/recovery suites, and the complete
61
+ integration gate for shared changes. A pure helper extraction preserves clocks, locks, request
62
+ identity, immutable history, refusal codes, retry timing and aliases.
63
+ - GF: its existing boundary tests, public-protocol negative controls and required real WC/SR
64
+ release gate. A consumer stub is not a substitute for real producer acceptance.
65
+ - Host: installed capability checks and the consumer's existing acceptance command before
66
+ activation. Source inspection is not installed-runtime or live-business acceptance.
67
+ - Preserve old receipts and explicit version allowlists. Do not count an expected nonzero refusal
68
+ as functional success, and do not infer business completion from a clean checkout.
@@ -0,0 +1,46 @@
1
+ # Maintenance roadmap
2
+
3
+ Execution baseline: 2026-10-23. This is the WC portion of the approved four-tool maintenance
4
+ direction. Each stage needs its own tested deliverable; later ideas are not current behavior.
5
+
6
+ ## Current baseline
7
+
8
+ WC 1.32.4 retains CLI contract 61 and storage layout 5. The scope and architecture documents
9
+ are already on main. Two previous extractions reduced private cross-module imports from 93 to
10
+ 82; this batch moves pure release-intent selection/backoff queries into one module, reducing
11
+ the baseline to 80. It retains lifecycle mutation helpers, clocks and internal aliases.
12
+
13
+ GF 1.9.7 already consumes SR's public read API and WC's versioned publication/retirement
14
+ protocols. CL 1.3.10 and SR 2.5.12 already use main on both hosting platforms. These completed
15
+ items are not prerequisites still waiting to happen.
16
+
17
+ [Consumer boundaries](integration-boundaries.md) correct the earlier AW session-call inventory.
18
+ Remaining evidence gaps are external consumer usage, installed-host behavior beyond the existing
19
+ acceptance gates, and historical temporary-file impact. No historical evidence is cleaned up.
20
+
21
+ ## Sequence and acceptance
22
+
23
+ | Stage | Deliverable | Exit evidence | Stop or rollback boundary |
24
+ | --- | --- | --- | --- |
25
+ | Now: boundaries | Current protocol and consumer inventory, including legacy adapters | Named owner per interface, source references, explicit unknowns; no changes to supported commands | Conflicting evidence keeps the interface supported |
26
+ | Now: WC structure | One cohesive pure release-intent query extraction | Full integration gate; existing renewal/cancellation/recovery behavior; CLI 61/storage 5 unchanged | Revert the isolated extraction if behavior differs |
27
+ | Pilot: shared quality checks | Local release-tools candidate and CL integration packet with a full commit pin | Workflow lint, CL local quality check, then all supported Python versions on real hosted CI after publication | Restore the pinned original CL workflow; PyPI/Gitea flows remain owned by consumers |
28
+ | Next 2–6 weeks | Further WC extraction only where a shared responsibility is clear; measure maintenance burden and failures | One behavior-preserving batch at a time, consumer gates, shrinking private-import baseline | Keep injected clocks, transaction and crash hooks with their owner until an explicit migration is tested |
29
+ | Following 6–12 weeks | Evaluate moving manifests, compatibility catalog and shared Skills from GF to a dedicated toolchain owner | Full ownership inventory, staged installer/migration, exactly one active writer, historical pin and rollback tests | No second simultaneous Skill authority; no ownership switch on file-copy evidence |
30
+ | Following 3–6 months | Evaluate a staged GF Python core migration | Characterization of exit/status/ref effects, isolated old/new comparisons, interruption recovery and real consumer gates | No dual production writes; preserve scanner refusals and existing installation until replacement passes |
31
+
32
+ The time ranges express ordering, not release deadlines. Batch internal maintenance with a
33
+ planned software release instead of increasing the CLI contract for every refactor. A public
34
+ behavior change still requires explicit contract/capability review and compatibility updates.
35
+
36
+ ## Shared workflow pilot boundary
37
+
38
+ Start with CL and retain its Python matrix and `just check`; only after hosted equivalence is
39
+ proved adopt SR with its additional package check. Pin all workflow dependencies to reviewed
40
+ commits. Keep upload jobs and their Trusted Publisher/environment in each repository's top-level
41
+ release workflow. First publication of a new public repository requires its own authorization.
42
+
43
+ Do not introduce a shared runtime Python dependency into CL/SR, merge the tools, relax SR's
44
+ Python floor, move host-specific defaults without migration, or replace existing WC/GF protocols.
45
+ GitHub-first release consolidation and a future toolchain repository remain design decisions,
46
+ not permission to disable existing Gitea delivery or platform controls.
@@ -4,16 +4,18 @@ This document records which parts of the public CLI are generic worktree governa
4
4
  exist mainly for one consumer. It is an inventory plus proposed boundaries; nothing here changes
5
5
  behavior, and every "proposed" line needs an owner decision before code moves.
6
6
 
7
- Snapshot: CLI contract 61, 81 commands, 65 `*_version` capability keys. The public contract
8
- counts were rechecked on 2026-10-23; consumer mappings below are the cloud audit
9
- reported in the maintainer handoff, not a runtime trace or proof of exclusive use.
7
+ Snapshot: WC 1.32.3, CLI contract 61, 81 commands, 66 `*_version` capability keys. The public contract
8
+ counts were rechecked on 2026-10-23. Host call paths were rechecked against current
9
+ consumer source; this remains static evidence, not a runtime trace or proof of exclusive use.
10
+ See [consumer boundaries](integration-boundaries.md) for the updated protocol inventory.
10
11
 
11
12
  ## How the inventory was made
12
13
 
13
14
  - **Agent Workspace (AW):** every `_invoke(...)` call in AW's controller client
14
- (`backend/src/agent_workspace/infrastructure/worktree_controller.py`) plus its session-retirement
15
- and external-execution modules. This was an exact static match in that audit, not a guarantee
16
- that dynamic or other consumers do not exist.
15
+ (`backend/src/agent_workspace/infrastructure/worktree_controller.py`), plus argument tuples
16
+ passed through `_run`, bounded dynamic binding helpers, session-retirement and external-execution
17
+ modules. The earlier `_invoke`-only inventory missed `session-bind`. This is not proof that
18
+ dynamic or other consumers do not exist.
17
19
  - **Git Finalizer (GF):** word match over `git-finalize*` and `tooling/*.py`. Common words
18
20
  (`review`, `task`, `release`, `resume`, `status`, `doctor`) can be false positives; the
19
21
  retirement and publication entries are confirmed by GF's adapter code.
@@ -34,7 +36,8 @@ Checkout budget, ownership and safe release for any person or agent sharing a re
34
36
 
35
37
  `branch-retirement-plan`, `-verify`, `-authorize`, `-complete`, `-record`, `-status`,
36
38
  `-executions`, and `publication-execution-session`. These are the public protocols GF consumes
37
- through capabilities; they should evolve by capability version, not by CLI contract number.
39
+ through versioned capabilities and protocols. This does not relax explicit CLI/storage version
40
+ allowlists in the deployment catalog or permit unknown versions. See [boundaries](integration-boundaries.md).
38
41
 
39
42
  ## 3. Host-runtime integration (used by AW today)
40
43
 
@@ -45,7 +48,8 @@ through capabilities; they should evolve by capability version, not by CLI contr
45
48
  | `admission-queue` | yes | Periodic queue reconciliation |
46
49
  | `binding-add`, `binding-remove`, `binding-transfer` | yes | Runtime bindings owned by a host |
47
50
  | `lifecycle-events`, `lifecycle-event-ack` | yes | Event feed with consumer acknowledgement |
48
- | `session-admit`, `session-bind`, `reconcile-session` | not found in AW's client | Need an owner answer: other host, legacy, or removable |
51
+ | `session-admit`, `session-bind` | yes, confirmed in current source | Capability-negotiated direct/tuple call paths; retain support |
52
+ | `reconcile-session` | no direct external AW CLI call found | WC session-end calls its lifecycle function; other external consumers remain unverified |
49
53
 
50
54
  **Proposed:** keep these in WC only if they are documented as a generic *host runtime protocol*
51
55
  (any host, explicit `--client-id`, no AW-specific defaults or wording). Otherwise move the
@@ -61,7 +65,8 @@ and binding records.
61
65
  `reconcile-writers`, `acquire-across`, `acquire-when-free`, `canonical-refresh`,
62
66
  `canonical-transition`, `namespace-migration-plan`, `-verify`, `-receipts`, `namespace-migrate`.
63
67
 
64
- Most of these have no consumer in AW or GF and appear only in reference docs, or not at all.
68
+ A static AW/GF inventory cannot establish usage by operators, other hosts or indirect adapters.
69
+ These commands remain supported; lack of a literal call is not deprecation evidence.
65
70
 
66
71
  **Proposed:** classify each as *supported*, *operator-only* or *deprecated* in the CLI contract,
67
72
  publish a deprecation window for the last group, and stop adding a new top-level command per
@@ -70,7 +75,8 @@ recovery case — prefer one `recover` entry with typed subcases.
70
75
  ## Open questions for the owner
71
76
 
72
77
  1. Is `host-execution` meant for hosts other than AW? If not, should its policy move to AW?
73
- 2. Who uses `session-admit`, `session-bind` and `reconcile-session`?
78
+ 2. Which additional consumers use the session interfaces? AW use of `session-admit` and
79
+ `session-bind` is confirmed; direct external `reconcile-session` usage remains unverified.
74
80
  3. Which section-4 commands may be deprecated, and on what timeline?
75
81
 
76
82
  ## Current compatibility decision
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "worktree-controller"
7
- version = "1.32.2"
7
+ version = "1.32.4"
8
8
  description = "Govern Git worktree budgets, authority, ownership, and lifecycle"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12,<3.13"
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "worktree-controller"
7
- version = "1.32.2"
7
+ version = "1.32.4"
8
8
  description = "Govern Git worktree budgets, authority, ownership, and lifecycle"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12,<3.13"
@@ -1,3 +1,3 @@
1
1
  """Worktree lifecycle controller."""
2
2
 
3
- __version__ = "1.32.2"
3
+ __version__ = "1.32.4"
@@ -1047,6 +1047,7 @@ def _main(argv: list[str] | None) -> int:
1047
1047
  "preservation_supersession_version": 1,
1048
1048
  "retained_typed_cleanup_version": 1,
1049
1049
  "aborted_integration_preserved_cleanup_version": 1,
1050
+ "terminal_preserved_cleanup_version": 1,
1050
1051
  "preservation_leaf_version": 1,
1051
1052
  "integration_publication_execution_version": 1,
1052
1053
  "integration_retry_version": 1,
@@ -316,11 +316,11 @@ def _require_intent_renewal_due(
316
316
  stays blocked. The same rule as stale-intent renewal applies: a changed record or
317
317
  HEAD, or a first expiry, proceeds at once.
318
318
  """
319
- from .lifecycle import _release_intents_for_allocation, _renewal_due
319
+ from .release_intents import release_intent_renewal_due, release_intents_for_allocation
320
320
 
321
321
  canonical = inventory(repository_path)
322
322
  snapshot = MetadataStore(canonical.common_dir).load()
323
- intents = _release_intents_for_allocation(snapshot, record.allocation_id)
323
+ intents = release_intents_for_allocation(snapshot, record.allocation_id)
324
324
  if any(intent.status in {"PENDING", "BLOCKED_RETRYABLE"} for intent in intents):
325
325
  return # create_release_intent reuses the live intent
326
326
  stale = [intent for intent in intents if intent.status == "STALE"]
@@ -329,7 +329,7 @@ def _require_intent_renewal_due(
329
329
  # The backoff runs from the most recent time an intent of this allocation went stale.
330
330
  latest = max(stale, key=lambda intent: (intent.updated_at, intent.created_at, intent.intent_id))
331
331
  ttl = load_policy(canonical.canonical_path).release_intent_ttl_seconds
332
- if not _renewal_due(snapshot, latest, record, item.head, datetime.now(UTC), ttl):
332
+ if not release_intent_renewal_due(snapshot, latest, record, item.head, datetime.now(UTC), ttl):
333
333
  raise ControllerError(
334
334
  "RENEWAL_BACKOFF",
335
335
  f"unchanged handoff release intent is backing off after {latest.blocker or 'expiry'}",
@@ -136,8 +136,119 @@ def _legacy_no_change(store: MetadataStore, item: WorktreeGitState, record: Meta
136
136
  return original
137
137
 
138
138
 
139
+ def _has_pre_completion_cleanup(store: MetadataStore, record: MetadataRecord) -> bool:
140
+ from .cleanup_evidence import read
141
+
142
+ for path in sorted(store.completion_receipts_dir.glob("*.json")):
143
+ value, _ = read(path)
144
+ plan = value.get("plan", {})
145
+ if plan.get("allocation_id") == record.allocation_id and plan.get("terminal_evidence") is None:
146
+ return True
147
+ return False
148
+
149
+
150
+ def terminal_cleanup_evidence(store: MetadataStore, snapshot: MetadataSnapshot,
151
+ item: WorktreeGitState, record: MetadataRecord) -> dict[str, Any]:
152
+ """Pin existing terminal proof without reopening a frozen allocation.
153
+
154
+ Legacy no-change receipts acquire a verified baseline now, never a claim of
155
+ historical digest observation. New completions can clean at their terminal
156
+ CAS only when they froze an empty prior cleanup set.
157
+ """
158
+ from .cleanup_evidence import read
159
+ from .semantics import publication_receipt_lease_released
160
+
161
+ def invalid():
162
+ return ControllerError("TERMINAL_CLEANUP_EVIDENCE_INVALID",
163
+ "exact lease-cleared publication or no-change completion required")
164
+
165
+ try:
166
+ if record.lifecycle == "PUBLISHED" and record.role == "integration":
167
+ matches = [receipt for receipt in snapshot.publication_receipts.values()
168
+ if receipt.allocation_id == record.allocation_id]
169
+ if len(matches) != 1:
170
+ raise invalid()
171
+ receipt = matches[0]
172
+ if (receipt.repository_id != snapshot.repository_id
173
+ or receipt.status not in {"REMOTE_VERIFIED", "RELEASED"}
174
+ or not receipt.remote_verified_at
175
+ or not publication_receipt_lease_released(snapshot, receipt)
176
+ or receipt.candidate_oid != item.head
177
+ or receipt.finalizer_record_id != record.finalizer_record_id
178
+ or not receipt.validation_evidence_id):
179
+ raise invalid()
180
+ intents = [intent for intent in snapshot.integration_intents.values()
181
+ if intent.allocation_id == record.allocation_id]
182
+ if receipt.intent_id is not None or intents:
183
+ if len(intents) != 1:
184
+ raise invalid()
185
+ intent = intents[0]
186
+ if (receipt.intent_id != intent.intent_id
187
+ or intent.allocation_id != record.allocation_id
188
+ or intent.publication_identity != receipt.receipt_id
189
+ or intent.candidate_oid != item.head
190
+ or intent.validation_evidence_id != receipt.validation_evidence_id):
191
+ raise invalid()
192
+ from .store import publication_receipt_to_dict
193
+
194
+ receipt_path = store.publication_receipts_dir / f"{receipt.receipt_id}.json"
195
+ receipt_value, receipt_digest = read(receipt_path)
196
+ if receipt_value != publication_receipt_to_dict(receipt):
197
+ raise invalid()
198
+ # The producer receipt is immutable; later closeout has separate evidence.
199
+ return {"contract": "terminal-preserved-cleanup/v1", "kind": "publication",
200
+ "receipt_id": receipt.receipt_id,
201
+ "receipt_ref": {"path": str(receipt_path), "sha256": receipt_digest},
202
+ "repository_id": receipt.repository_id,
203
+ "allocation_id": receipt.allocation_id, "intent_id": receipt.intent_id,
204
+ "candidate_oid": receipt.candidate_oid,
205
+ "finalizer_record_id": receipt.finalizer_record_id,
206
+ "validation_evidence_id": receipt.validation_evidence_id,
207
+ "remote_verified_at": receipt.remote_verified_at}
208
+ if (record.lifecycle != "NO_CHANGE_COMPLETED" or record.role not in {"feature", "audit"}
209
+ or not record.history):
210
+ raise invalid()
211
+ completion_ref = record.history[-1].get("no_change_completion_ref")
212
+ if completion_ref:
213
+ receipt = _completion_document(store, completion_ref)
214
+ original = record_from_dict(receipt["before_record"])
215
+ event = record.history[-1]
216
+ if (receipt.get("contract") != NO_CHANGE_CONTRACT
217
+ or receipt.get("kind") != "no_change_completion"
218
+ or receipt.get("preservation_cleanup_receipts") != []
219
+ or _no_change_transition(original, event) != record
220
+ or {key: value for key, value in event.items() if key != "no_change_completion_ref"}
221
+ != receipt["completion_event"]):
222
+ raise invalid()
223
+ _no_change_identity(receipt, original, item, snapshot.repository_id)
224
+ if not (_no_change_time(original.last_reviewed_at)
225
+ <= _no_change_time(receipt["completed_at"]) <= _no_change_time(event["at"])):
226
+ raise invalid()
227
+ if _has_pre_completion_cleanup(store, record):
228
+ raise invalid()
229
+ return {"contract": "terminal-preserved-cleanup/v1", "kind": "no_change",
230
+ "completion_ref": completion_ref}
231
+ matches = []
232
+ for path in sorted(store.completion_receipts_dir.glob("*.json")):
233
+ value, digest = read(path)
234
+ if (value.get("kind") == "no_change_completion"
235
+ and value.get("allocation_id") == record.allocation_id):
236
+ matches.append({"receipt_id": path.stem, "path": str(path), "sha256": digest})
237
+ if len(matches) != 1:
238
+ raise invalid()
239
+ ref = matches[0]
240
+ _legacy_no_change(store, item, record, snapshot.repository_id, ref)
241
+ return {"contract": "terminal-preserved-cleanup/v1", "kind": "legacy_no_change",
242
+ "completion_ref": ref}
243
+ except (OSError, KeyError, TypeError, ValueError, IndexError, ControllerError) as exc:
244
+ raise invalid() from exc
245
+
246
+
139
247
  def verify_no_change_cleanup(store: MetadataStore, item: WorktreeGitState,
140
- record: MetadataRecord, repository_id: str | None) -> list[dict[str, str]]:
248
+ record: MetadataRecord, repository_id: str | None, *,
249
+ cleanup_recovery: dict[str, Any] | None = None,
250
+ cleanup_transaction_id: str | None = None,
251
+ allow_pending_typed_no_action: bool = False) -> list[dict[str, str]]:
141
252
  """Bridge only frozen normal transitions; cleanup keeps its original exact CAS."""
142
253
  from .preserved_cleanup import cleanup_receipts
143
254
 
@@ -157,6 +268,14 @@ def verify_no_change_cleanup(store: MetadataStore, item: WorktreeGitState,
157
268
  <= _no_change_time(receipt["completed_at"]) <= _no_change_time(event["at"])):
158
269
  raise _no_change_fail("completion timestamp differs from its transition")
159
270
  refs = receipt["preservation_cleanup_receipts"]
271
+ if refs == [] and not _has_pre_completion_cleanup(store, record):
272
+ terminal_cleanup_evidence(store, store._load_unlocked(), item, record)
273
+ return cleanup_receipts(
274
+ store, item, record, repository_id, cleanup_recovery=cleanup_recovery,
275
+ cleanup_transaction_id=cleanup_transaction_id,
276
+ allow_pending_typed_no_action=allow_pending_typed_no_action,
277
+ include_no_action_refs=True,
278
+ )
160
279
  elif receipt.get("kind") == "no_change_cleanup_recovery":
161
280
  plan = receipt["plan"]
162
281
  legacy = record_from_dict(plan["record"])
@@ -79,6 +79,9 @@ from .preserved_cleanup import CONTRACT as PRESERVED_CLEANUP_CONTRACT
79
79
  from .preserved_cleanup import coverage, delete_preserved_state
80
80
  from .record_updates import updated_intent as _updated_intent
81
81
  from .record_updates import updated_record as _updated_record
82
+ from .release_intents import RENEWAL_BACKOFF_CAP_SECONDS as RENEWAL_BACKOFF_CAP_SECONDS
83
+ from .release_intents import release_intent_renewal_due as _renewal_due
84
+ from .release_intents import release_intents_for_allocation as _release_intents_for_allocation
82
85
  from .semantics import assert_record_version as _cas
83
86
  from .semantics import (
84
87
  attribution_base,
@@ -95,6 +98,7 @@ from .semantics import (
95
98
  from .semantics import effective_intent_state as _effective_intent_state
96
99
  from .semantics import integration_reconciliation as _integration_reconciliation
97
100
  from .semantics import managed_record as _managed_record
101
+ from .semantics import publication_receipt_lease_released as _publication_receipt_lease_released
98
102
  from .semantics import record_for as _record_for
99
103
  from .store import (
100
104
  INTEGRATION_INTENT_CONTRACT_VERSION,
@@ -348,54 +352,6 @@ def _updated_release_intent(intent: ReleaseIntent, event: str, **changes: Any) -
348
352
  return release_intent_from_dict(payload)
349
353
 
350
354
 
351
- RENEWAL_BACKOFF_CAP_SECONDS = 24 * 3600
352
-
353
-
354
- def _renewal_due(
355
- snapshot: MetadataSnapshot,
356
- previous: ReleaseIntent,
357
- record: MetadataRecord,
358
- head: str,
359
- now: datetime,
360
- ttl_seconds: int,
361
- ) -> bool:
362
- """Whether a stale release intent should be renewed on this pass.
363
-
364
- The first expiry, or a changed record or HEAD, is renewed at once. Each further
365
- stale intent of an unchanged identity failed the same way, so the next renewal
366
- waits the TTL doubled per repeat, capped at a day. Renewal stays eventual (a stuck
367
- checkout is still retried) while one blocked allocation no longer adds an intent
368
- on every reconciliation pass.
369
- """
370
- if (previous.expected_record_version, previous.expected_head) != (record.record_version, head):
371
- return True
372
- streak = sum(
373
- 1
374
- for intent in _release_intents_for_allocation(snapshot, record.allocation_id)
375
- if intent.status == "STALE"
376
- and (intent.expected_record_version, intent.expected_head) == (record.record_version, head)
377
- )
378
- if streak <= 1:
379
- return True
380
- delay = min(ttl_seconds * 2 ** (streak - 2), RENEWAL_BACKOFF_CAP_SECONDS)
381
- return (now - datetime.fromisoformat(previous.updated_at)).total_seconds() >= delay
382
-
383
-
384
- def _release_intents_for_allocation(
385
- snapshot: MetadataSnapshot, allocation_id: str
386
- ) -> tuple[ReleaseIntent, ...]:
387
- return tuple(
388
- sorted(
389
- (
390
- intent
391
- for intent in snapshot.release_intents.values()
392
- if intent.allocation_id == allocation_id
393
- ),
394
- key=lambda intent: (intent.created_at, intent.intent_id),
395
- )
396
- )
397
-
398
-
399
355
  def _cancel_release_intents(
400
356
  store: MetadataStore,
401
357
  snapshot: MetadataSnapshot,
@@ -4760,6 +4716,7 @@ def _typed_cleanup_plan_locked(
4760
4716
  blockers: list[dict[str, str]] = []
4761
4717
  aborted_integration = record.role == "integration" and record.lifecycle == "INTEGRATION_ABORTED"
4762
4718
  integration_abort_evidence = None
4719
+ terminal_evidence = None
4763
4720
  preserved_evidence = None
4764
4721
  preserved_evidences: list[dict[str, Any]] = []
4765
4722
  multiple = bool(additional_preservation_receipts or additional_preservation_receipt_sha256)
@@ -4907,6 +4864,12 @@ def _typed_cleanup_plan_locked(
4907
4864
  from .integration_cleanup import abort_evidence
4908
4865
 
4909
4866
  integration_abort_evidence = abort_evidence(store, snapshot, item, record)
4867
+ elif ((record.lifecycle == "PUBLISHED" and record.role == "integration")
4868
+ or (record.lifecycle == "NO_CHANGE_COMPLETED" and not archived_no_commit
4869
+ and record.history)):
4870
+ from .delivered_closeout import terminal_cleanup_evidence
4871
+
4872
+ terminal_evidence = terminal_cleanup_evidence(store, snapshot, item, record)
4910
4873
  elif (record.lifecycle != "HANDOFF_READY" and not archived_no_commit and not retained_cleanup) or record.role not in {
4911
4874
  "feature",
4912
4875
  "audit",
@@ -4963,13 +4926,13 @@ def _typed_cleanup_plan_locked(
4963
4926
  runtime_evidence["scan_error"] = {"code": exc.code, "message": str(exc)}
4964
4927
  blockers.append({"code": exc.code, "message": str(exc)})
4965
4928
  for resource in resources:
4966
- if aborted_integration and resource["cleanup_action"] == "remove-tree":
4929
+ if (aborted_integration or terminal_evidence is not None) and resource["cleanup_action"] == "remove-tree":
4967
4930
  # This additional lifecycle has no project-name/path allowlist. Even
4968
4931
  # otherwise recognized build output requires an exact preserved copy.
4969
4932
  resource.update(
4970
4933
  classification="blocked", cleanup_action="none",
4971
- blocker="INTEGRATION_PRESERVATION_REQUIRED",
4972
- reason="aborted integration cleanup requires exact preservation for every tree",
4934
+ blocker="INTEGRATION_PRESERVATION_REQUIRED" if aborted_integration else "TERMINAL_PRESERVATION_REQUIRED",
4935
+ reason="terminal integration/no-change cleanup requires exact preservation for every tree",
4973
4936
  )
4974
4937
  if resource["blocker"]:
4975
4938
  blockers.append(
@@ -5039,6 +5002,8 @@ def _typed_cleanup_plan_locked(
5039
5002
  identity["preservation_evidence"] = preserved_evidence
5040
5003
  if multiple:
5041
5004
  identity["preservation_evidences"] = preserved_evidences
5005
+ if terminal_evidence is not None:
5006
+ identity["terminal_evidence"] = terminal_evidence
5042
5007
  if integration_abort_evidence is not None:
5043
5008
  identity["integration_abort_evidence"] = integration_abort_evidence
5044
5009
  if recovery is not None:
@@ -6215,32 +6180,6 @@ def _reconciliation_for_publication_receipt(
6215
6180
  return matches[0] if matches else None
6216
6181
 
6217
6182
 
6218
- def _lease_release_reconciliation_for_publication_receipt(
6219
- snapshot: MetadataSnapshot, receipt_id: str
6220
- ) -> ReconciliationReceipt | None:
6221
- matches = [
6222
- receipt
6223
- for receipt in snapshot.reconciliation_receipts.values()
6224
- if receipt.source_receipt_id == receipt_id
6225
- and receipt.result == "LEASE_RELEASE_ACKNOWLEDGED"
6226
- ]
6227
- if len(matches) > 1:
6228
- raise ControllerError(
6229
- "RECONCILIATION_DRIFT", "publication receipt has multiple lease reconciliations"
6230
- )
6231
- return matches[0] if matches else None
6232
-
6233
-
6234
- def _publication_receipt_lease_released(
6235
- snapshot: MetadataSnapshot, receipt: PublicationReceipt
6236
- ) -> bool:
6237
- return bool(
6238
- receipt.lease_released_at is not None
6239
- or _lease_release_reconciliation_for_publication_receipt(snapshot, receipt.receipt_id)
6240
- is not None
6241
- )
6242
-
6243
-
6244
6183
  def _publication_receipt_effectively_released(
6245
6184
  snapshot: MetadataSnapshot, receipt: PublicationReceipt
6246
6185
  ) -> bool:
@@ -7518,7 +7457,11 @@ def _validate_release_core(
7518
7457
  elif record.lifecycle == "NO_CHANGE_COMPLETED" and record.history[-1].get("no_change_completion_ref"):
7519
7458
  from .delivered_closeout import verify_no_change_cleanup
7520
7459
 
7521
- cleanup_refs = verify_no_change_cleanup(store, item, record, snapshot.repository_id)
7460
+ cleanup_refs = verify_no_change_cleanup(
7461
+ store, item, record, snapshot.repository_id, cleanup_recovery=cleanup_recovery,
7462
+ cleanup_transaction_id=cleanup_transaction_id,
7463
+ allow_pending_typed_no_action=allow_pending_typed_no_action,
7464
+ )
7522
7465
  else:
7523
7466
  cleanup_refs = cleanup_receipts(
7524
7467
  store, item, record, snapshot.repository_id,
@@ -640,6 +640,11 @@ def cleanup_receipts(
640
640
  plan = receipt.get("plan", {})
641
641
  if plan.get("allocation_id") != record.allocation_id:
642
642
  continue
643
+ if plan.get("terminal_evidence") is not None:
644
+ from .delivered_closeout import terminal_cleanup_evidence
645
+
646
+ if terminal_cleanup_evidence(store, store._load_unlocked(), item, record) != plan["terminal_evidence"]:
647
+ raise _blocked("terminal completion evidence changed after cleanup")
643
648
  if plan.get("integration_abort_evidence") is not None:
644
649
  from .integration_cleanup import abort_evidence
645
650
 
@@ -0,0 +1,57 @@
1
+ """Pure queries over the caller's release-intent snapshot.
2
+
3
+ Callers retain ownership of clocks, locks and all release-intent mutations.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from datetime import datetime
9
+
10
+ from .models import MetadataRecord, MetadataSnapshot, ReleaseIntent
11
+
12
+ RENEWAL_BACKOFF_CAP_SECONDS = 24 * 3600
13
+
14
+
15
+ def release_intent_renewal_due(
16
+ snapshot: MetadataSnapshot,
17
+ previous: ReleaseIntent,
18
+ record: MetadataRecord,
19
+ head: str,
20
+ now: datetime,
21
+ ttl_seconds: int,
22
+ ) -> bool:
23
+ """Whether a stale release intent should be renewed on this pass.
24
+
25
+ The first expiry, or a changed record or HEAD, is renewed at once. Each further
26
+ stale intent of an unchanged identity failed the same way, so the next renewal
27
+ waits the TTL doubled per repeat, capped at a day. Renewal stays eventual (a stuck
28
+ checkout is still retried) while one blocked allocation no longer adds an intent
29
+ on every reconciliation pass.
30
+ """
31
+ if (previous.expected_record_version, previous.expected_head) != (record.record_version, head):
32
+ return True
33
+ streak = sum(
34
+ 1
35
+ for intent in release_intents_for_allocation(snapshot, record.allocation_id)
36
+ if intent.status == "STALE"
37
+ and (intent.expected_record_version, intent.expected_head) == (record.record_version, head)
38
+ )
39
+ if streak <= 1:
40
+ return True
41
+ delay = min(ttl_seconds * 2 ** (streak - 2), RENEWAL_BACKOFF_CAP_SECONDS)
42
+ return (now - datetime.fromisoformat(previous.updated_at)).total_seconds() >= delay
43
+
44
+
45
+ def release_intents_for_allocation(
46
+ snapshot: MetadataSnapshot, allocation_id: str
47
+ ) -> tuple[ReleaseIntent, ...]:
48
+ return tuple(
49
+ sorted(
50
+ (
51
+ intent
52
+ for intent in snapshot.release_intents.values()
53
+ if intent.allocation_id == allocation_id
54
+ ),
55
+ key=lambda intent: (intent.created_at, intent.intent_id),
56
+ )
57
+ )
@@ -20,6 +20,8 @@ from .models import (
20
20
  IntegrationReconciliationReceipt,
21
21
  MetadataRecord,
22
22
  MetadataSnapshot,
23
+ PublicationReceipt,
24
+ ReconciliationReceipt,
23
25
  RepositoryInventory,
24
26
  WorktreeGitState,
25
27
  WorktreePolicy,
@@ -29,6 +31,32 @@ from .policy import load_policy
29
31
  EVIDENCE_LIFECYCLES = frozenset({"HANDOFF_READY", "PRESERVED", "INTEGRATING", "PUBLISHED"})
30
32
 
31
33
 
34
+ def _lease_release_reconciliation_for_publication_receipt(
35
+ snapshot: MetadataSnapshot, receipt_id: str
36
+ ) -> ReconciliationReceipt | None:
37
+ matches = [
38
+ receipt
39
+ for receipt in snapshot.reconciliation_receipts.values()
40
+ if receipt.source_receipt_id == receipt_id
41
+ and receipt.result == "LEASE_RELEASE_ACKNOWLEDGED"
42
+ ]
43
+ if len(matches) > 1:
44
+ raise ControllerError(
45
+ "RECONCILIATION_DRIFT", "publication receipt has multiple lease reconciliations"
46
+ )
47
+ return matches[0] if matches else None
48
+
49
+
50
+ def publication_receipt_lease_released(
51
+ snapshot: MetadataSnapshot, receipt: PublicationReceipt
52
+ ) -> bool:
53
+ return bool(
54
+ receipt.lease_released_at is not None
55
+ or _lease_release_reconciliation_for_publication_receipt(snapshot, receipt.receipt_id)
56
+ is not None
57
+ )
58
+
59
+
32
60
  def record_for(item: WorktreeGitState, snapshot: MetadataSnapshot) -> MetadataRecord | None:
33
61
  allocation_id = snapshot.bindings.get(item.key)
34
62
  if allocation_id is None:
@@ -1071,7 +1071,7 @@
1071
1071
  "session_launcher_entrypoint": "worktree-session",
1072
1072
  "session_entrypoint": "worktree-session-end",
1073
1073
  "tool_name": "worktree-controller",
1074
- "tool_version": "1.32.2",
1074
+ "tool_version": "1.32.4",
1075
1075
  "delivered_closeout_version": 1,
1076
1076
  "retained_archive_version": 1,
1077
1077
  "retention_convergence_version": 2,
@@ -1512,6 +1512,14 @@
1512
1512
  "single_input_compatibility": "existing single receipt contract, plan and receipt shape remain unchanged",
1513
1513
  "storage_layout_version": 4
1514
1514
  },
1515
+ "terminal_preserved_cleanup_version": 1,
1516
+ "terminal_preserved_cleanup_contract": {
1517
+ "contract": "terminal-preserved-cleanup/v1",
1518
+ "eligible": "PUBLISHED integration with one matching remote-verified publication and cleared publication lease; NO_CHANGE_COMPLETED feature/audit with one verified original completion transition and receipt",
1519
+ "coverage": "every removed tree requires an exact immutable preservation generation; existing owner, HEAD, CAS, retained-ref, binding, runtime, writer and transaction guards remain mandatory",
1520
+ "evidence": "plan pins raw producer publication bytes or exact completion reference; legacy completion establishes a newly verified raw baseline; cleanup and release reverify it without rewriting historical evidence or reopening lifecycle",
1521
+ "new_no_change": "new-format completions with an empty frozen prior cleanup set may clean at the exact terminal CAS; nonempty prior proof sets retain their original pre-completion CAS"
1522
+ },
1515
1523
  "retained_typed_cleanup_version": 1,
1516
1524
  "aborted_integration_preserved_cleanup_version": 1,
1517
1525
  "aborted_integration_preserved_cleanup_contract": {
@@ -1071,7 +1071,7 @@
1071
1071
  "session_launcher_entrypoint": "worktree-session",
1072
1072
  "session_entrypoint": "worktree-session-end",
1073
1073
  "tool_name": "worktree-controller",
1074
- "tool_version": "1.32.2",
1074
+ "tool_version": "1.32.4",
1075
1075
  "delivered_closeout_version": 1,
1076
1076
  "retained_archive_version": 1,
1077
1077
  "retention_convergence_version": 2,
@@ -1512,6 +1512,14 @@
1512
1512
  "single_input_compatibility": "existing single receipt contract, plan and receipt shape remain unchanged",
1513
1513
  "storage_layout_version": 4
1514
1514
  },
1515
+ "terminal_preserved_cleanup_version": 1,
1516
+ "terminal_preserved_cleanup_contract": {
1517
+ "contract": "terminal-preserved-cleanup/v1",
1518
+ "eligible": "PUBLISHED integration with one matching remote-verified publication and cleared publication lease; NO_CHANGE_COMPLETED feature/audit with one verified original completion transition and receipt",
1519
+ "coverage": "every removed tree requires an exact immutable preservation generation; existing owner, HEAD, CAS, retained-ref, binding, runtime, writer and transaction guards remain mandatory",
1520
+ "evidence": "plan pins raw producer publication bytes or exact completion reference; legacy completion establishes a newly verified raw baseline; cleanup and release reverify it without rewriting historical evidence or reopening lifecycle",
1521
+ "new_no_change": "new-format completions with an empty frozen prior cleanup set may clean at the exact terminal CAS; nonempty prior proof sets retain their original pre-completion CAS"
1522
+ },
1515
1523
  "retained_typed_cleanup_version": 1,
1516
1524
  "aborted_integration_preserved_cleanup_version": 1,
1517
1525
  "aborted_integration_preserved_cleanup_contract": {