Repository navigation
Fix abandoned session cleanup terminal-state gap - #336
Conversation
There was a problem hiding this comment.
Hi @openxfactory[bot]! 👋
Your private repo does not have access to Sourcery.
Please upgrade to continue using Sourcery ✨
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ce9a06875
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| references=(_repo_reference(root, folder / ".openspec.yaml"),), | ||
| recorded_at=_path_recorded_at(root, folder)) |
There was a problem hiding this comment.
Correlate the origin evidence, not any folder edit
When an active proposal's staged origin predates abandonment but any unrelated file in its change folder is committed afterward, _path_recorded_at(root, folder) reports that later folder-wide commit as the origin evidence's recording time. machine_release_correlation_error then accepts the historical proposal as post-abandonment evidence and cleanup can delete a branch whose newer exploration was never preserved. Record the commit time of the actual origin evidence rather than the newest commit touching the entire change directory.
AGENTS.md reference: AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid, and it was fail-OPEN — reproduced, then fixed in #362 (commit a21d40f).
The reproduction: archive exact-origin custody before the session, abandon it, then commit an unrelated tasks.md inside that archived change folder. _path_recorded_at(root, folder) reported that unrelated commit as the origin evidence's recording time, machine_release_correlation_error accepted the historical proposal, and cleanup answered 200 and DELETED the branch — the newer exploration it was the only record of was preserved by nothing.
Fix: recorded_at is now the recording time of the origin evidence the candidate actually cites (<folder>/.openspec.yaml), derived from the same path as the reference so the two cannot drift. An origin declaration with no commit of its own therefore has no durable recording time, which the correlation already treats as a refusal — the tightening runs in the fail-closed direction. Regression: test_a_later_edit_elsewhere_in_the_change_folder_does_not_freshen_the_origin, which also pins that a later commit to the declaration ITSELF still releases cleanup.
| if machine_retention is not None and abandonment is not None and head: | ||
| correlation_error = branch_session.machine_release_correlation_error( | ||
| machine_retention, abandonment, head) | ||
| if correlation_error: | ||
| machine_retention = None |
There was a problem hiding this comment.
Evaluate every matching retention candidate
When a reused tile has multiple matching lifecycle records, retention_release_for returns one deterministic candidate before abandonment correlation is checked here. If that first candidate predates abandonment, it is discarded and cleanup refuses without considering a later active, archived, or demotion record that independently satisfies the retention requirement; the operator must unnecessarily use an explicit release despite valid machine evidence. Correlate all matching candidates and select a qualifying one before concluding that machine retention is unavailable.
AGENTS.md reference: AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid — reproduced and fixed in #362 (commit a21d40f). Measured impact is operator friction rather than a safety hole: the wrong answer here was a refusal, not a deletion.
Reproduction: two archived changes carrying the same staged origin, the first-sorted one older than the abandonment and a successor archived after it. Cleanup refused with "the retention evidence was recorded ... before the session was abandoned" and the operator's only way through was an explicit human release they should not have needed.
Fix: retention_release_candidates returns EVERY matching record in acceptance order (active custody, archived custody, pick fallback, receipt-proved demotion, corroborated legacy demotion) and execute_cleanup_abandoned_branch takes the first that CORRELATES — a candidate that fails disqualifies only itself. The reported error stays the FIRST candidate's, so a refusal still names the nearest-miss evidence. No candidate clears a lower evidence bar than before, and when every candidate predates the abandonment the refusal is unchanged: test_no_matching_record_after_abandonment_still_refuses_cleanup pins that half alongside test_a_second_matching_record_recorded_after_abandonment_releases_cleanup.
There was a problem hiding this comment.
Pull request overview
This PR closes the abandoned-session cleanup “terminal-state gap” by making cleanup decisions evidence-based and transactional: cleanup now requires explicit retention-release evidence (active, archived, executed-demotion, or explicit human release), binds that evidence to the exact abandoned head and chronology, and deletes refs atomically using Git’s expected-old-value mechanism with safe restoration on record-finalization failure. It also hardens related governance surfaces (demotion receipts, contract/validator coverage, NotebookLM projection title injectivity, and doc-health family enumeration drift prevention).
Changes:
- Add atomic expected-SHA local ref deletion (and guarded restore) plus additional “checked out anywhere” safety checks for session branch deletion.
- Introduce durable demotion execution receipts (schema + examples + validator rules) and write receipts after successful demotion execution.
- Fix NotebookLM projection title collisions by deriving injective stems, and add a new doc-health family (“family-enumeration”) with fixtures/tests to prevent deterministic-family prose drift.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/ideation-dashboard/test_session_git.py | Adds regression for atomic expected-value delete preserving concurrently moved refs. |
| tests/ideation-dashboard/test_gate_console.py | Adds demotion receipt validation tests and cleanup record collision/semantics tests. |
| tests/doc-health/test_lifecycle_scan_set.py | Updates reader/non-reader classification expectations for the new doc-health family. |
| tests/doc-health/fixtures/family-enumeration-unknown-name/alphaFactory/openspec/specs/doc-health/spec.md | New fixture: unknown family name in deterministic-family prose. |
| tests/doc-health/fixtures/family-enumeration-thin-delta/alphaFactory/openspec/specs/doc-health/spec.md | New fixture: canon expectation for thin-delta prevention scenario. |
| tests/doc-health/fixtures/family-enumeration-thin-delta/alphaFactory/openspec/changes/add-something/specs/doc-health/spec.md | New fixture: thin delta that improperly truncates requirement text. |
| tests/doc-health/fixtures/family-enumeration-stale-numeral/alphaFactory/openspec/specs/doc-health/spec.md | New fixture: stale numerals in deterministic-family prose. |
| tests/doc-health/fixtures/family-enumeration-pending/alphaFactory/openspec/specs/doc-health/spec.md | New fixture: pending-promotion behavior for canon vs active delta. |
| tests/doc-health/fixtures/family-enumeration-pending/alphaFactory/openspec/changes/add-something/specs/doc-health/spec.md | New fixture: delta that updates enumeration/numerals. |
| tests/doc-health/fixtures/family-enumeration-no-spec/betaFactory/openspec/specs/solo/spec.md | New fixture: repository without doc-health capability. |
| tests/doc-health/fixtures/family-enumeration-missing-name/alphaFactory/openspec/specs/doc-health/spec.md | New fixture: missing “family-enumeration” name in prose list. |
| tests/doc-health/fixtures/family-enumeration-clean/alphaFactory/openspec/specs/doc-health/spec.md | New fixture: clean/consistent deterministic-family prose. |
| specs/011-council-feature-clearance/tasks.md | Updates task gating notes to reflect successor dependency vs “ruling exists”. |
| specs/011-council-feature-clearance/spec.md | Records correction about schema capabilities vs security/ruling basis. |
| specs/011-council-feature-clearance/implementation-notes.md | Records the R4 ruling outcome and successor dependency. |
| scripts/validate-ideation-dashboard-contracts.py | Adds demotion receipt + cleanup record semantic checks (scope identity, safe paths). |
| scripts/sync-notebooklm-books.py | Makes notebook title derivation injective (shortest distinguishing suffix) and improves parity to detect collapses. |
| scripts/ideation_dashboard/session_git.py | Adds path commit-time reader; implements atomic expected-SHA ref deletion and restore; adds “checked out anywhere” delete guard. |
| scripts/ideation_dashboard/generator.py | Promotes change/origin helpers to public names with compatibility aliases. |
| scripts/ideation_dashboard/cli.py | Writes demotion execution receipts on --execute; hardens cleanup CLI validation and reporting. |
| scripts/ideation_dashboard/boundary.py | Adds exclusive-create and atomic-replace output helpers to support prepared/completed transactions. |
| scripts/hermes_runtime_validation/release.py | Includes ideation-dashboard contract validator in Hermes runtime auxiliary members. |
| scripts/doc_health/release_inventory.py | Clarifies release-inventory rationale around untagged bundles as a general rule. |
| scripts/doc_health/families.py | Registers new family-enumeration family. |
| scripts/doc_health/duplicate_packet.py | Updates module docstring with ruled measurement basis decision. |
| scripts/doc_health/init.py | Fixes/report-order projection drift by ensuring FAMILY_IDS includes all registered families and adds family-enumeration. |
| README.md | Adds index entries for new changes (projection title uniqueness; family enumeration check) and updates archived-change notes. |
| openspec/changes/fix-abandoned-session-cleanup-terminal-states/tasks.md | New change packet tasks for cleanup evidence, transactions, tests, and guidance. |
| openspec/changes/fix-abandoned-session-cleanup-terminal-states/specs/ideation-dashboard/spec.md | New ideation-dashboard spec delta defining cleanup evidence/transaction semantics. |
| openspec/changes/fix-abandoned-session-cleanup-terminal-states/proposal.md | New proposal describing evidence-based abandoned-branch cleanup and atomic deletion. |
| openspec/changes/fix-abandoned-session-cleanup-terminal-states/design.md | New design describing evidence model, demotion proof, and transactional cleanup. |
| openspec/changes/fix-abandoned-session-cleanup-terminal-states/.openspec.yaml | New change metadata declaring ad-hoc origin for the cleanup-terminal-states change. |
| openspec/changes/create-medxpractice-overlay-boundary/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| openspec/changes/create-medxchart-overlay-boundary/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| openspec/changes/archive/2026-08-25-add-duplicate-packet-check/tasks.md | Records closure of previously open questions by ruling. |
| openspec/changes/archive/2026-08-14-add-worker-credential-by-reference/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-07-add-register-edit-lane/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-06-add-lens-gate-verbs/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-06-add-consent-instrument/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-05-adopt-neutral-tooling-home/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-05-add-neutrality-drift-lane/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-04-adopt-neutral-utility-pack/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-08-02-add-workbench-integrated-editor-chat/.openspec.yaml | Adds derived origin metadata and approval provenance. |
| openspec/changes/archive/2026-08-01-add-propose-verb/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-30-publish-semantic-kernel/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-30-add-ontology-term-lifecycle-enforcement/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-30-add-ontology-stewardship-hardening/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-30-add-omnigent-semantic-wiring/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-30-add-domain-ontology-layer/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-30-add-deployment-handoff-boundary/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-24-add-hermes-domain-content-manifest/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-24-add-client-layer-tuning-contracts/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-23-add-hermes-domain-overlay-contract/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-23-add-governed-derived-model/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-17-add-client-infrastructure-liaison/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-16-adopt-avatar-client-lab-candidates/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/archive/2026-07-14-add-github-app-identity-tiers/.openspec.yaml | Adds derived origin metadata for archived packet. |
| openspec/changes/add-worker-enrollment-broker/.openspec.yaml | Adds staged origin metadata and approval provenance. |
| openspec/changes/add-substantive-review-lane/tasks.md | Records corrections about matcher/schema capabilities and upstream discharge notes. |
| openspec/changes/add-shared-identity-seeds/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| openspec/changes/add-projection-title-uniqueness/specs/lifecycle-notebook-projection/spec.md | New spec delta formalizing injective title derivation and document-level parity. |
| openspec/changes/add-projection-title-uniqueness/.openspec.yaml | New change metadata for projection title injectivity. |
| openspec/changes/add-omnigent-domain-terminology/.openspec.yaml | Adds ad_hoc origin metadata and admission approval provenance. |
| openspec/changes/add-nightly-dashboard-refresh/.openspec.yaml | Adds ad_hoc origin metadata and admission approval provenance. |
| openspec/changes/add-model-provider-broker/.openspec.yaml | Adds ad_hoc origin metadata and admission approval provenance. |
| openspec/changes/add-hermes-customer-subject-runtime-contract/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| openspec/changes/add-family-enumeration-check/proposal.md | New proposal adding doc-health family-enumeration check. |
| openspec/changes/add-family-enumeration-check/design.md | New design for the family-enumeration check. |
| openspec/changes/add-family-enumeration-check/.openspec.yaml | New change metadata for family-enumeration check. |
| openspec/changes/add-doxchat-model-intake/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| openspec/changes/add-dispatch-credential-contract/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| openspec/changes/add-composed-view-authoring/.openspec.yaml | Adds ad_hoc origin metadata and approval provenance. |
| examples/ideation-dashboard/README.md | Registers new examples/negatives for cleanup records and demotion receipts. |
| examples/ideation-dashboard/negative/gate-action-cleanup-scope-mismatch.yaml | New negative example: cleanup scope mismatch. |
| examples/ideation-dashboard/negative/gate-action-cleanup-machine-empty-evidence.yaml | New negative example: machine evidence missing required references. |
| examples/ideation-dashboard/negative/gate-action-cleanup-explicit-release-without-reason.yaml | New negative example: explicit release missing required reason. |
| examples/ideation-dashboard/negative/demotion-execution-receipt-unsafe-path.yaml | New negative example: demotion receipt path traversal/unsafe path. |
| examples/ideation-dashboard/negative/demotion-execution-receipt-destination-mismatch.yaml | New negative example: demotion receipt destination mismatch. |
| examples/ideation-dashboard/gate-action-record-cleanup-abandoned-branch.example.yaml | New positive example: cleanup-abandoned-branch record. |
| examples/ideation-dashboard/gate-action-record-abandon-session.example.yaml | Updates abandon-session example commentary to reflect new cleanup semantics. |
| examples/ideation-dashboard/demotion-execution-receipt.example.yaml | New positive example: demotion execution receipt. |
| docs/lifecycle-notebook-projection.md | Updates lifecycle notebook projection rule documentation to require injective titles and document-level parity. |
| docs/ideation-dashboard-session-runbook.md | Updates operator guidance for cleanup evidence lanes and transactional semantics. |
| docs/contract-versioning-policy.md | Updates policy section to record discharge of previously untagged bundles and tagging rule. |
| docs/archive-record-discrepancies.md | Adds record entry about projection title collapse and its remediation. |
| contracts/schemas/gate-action-record.schema.yaml | Adds cleanup-abandoned-branch action and cleanup evidence structure (prepared/completed). |
| contracts/schemas/demotion-execution-receipt.schema.yaml | Adds new schema for executed demotion receipts. |
| contracts/README.md | Documents new schemas and extended validator responsibilities for contract-v1.43. |
| contracts/manifest.yaml | Advances bundle version and registers new/updated schema digests. |
| contracts/hermes-runtime/contract-index.yaml | Registers demotion-execution-receipt as a release-schema. |
| contracts/CHANGELOG.md | Adds contract-v1.43 (and v1.42 editorial cut) entries describing the new schema surfaces and release identity changes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| current = self.branch_sha(branch) | ||
| if current != expect_sha: | ||
| raise SessionGitRefused( | ||
| f"refusing to delete {branch!r}: it was at {expect_sha} when " | ||
| f"cleanup was authorized and is at {current} now. Git's " | ||
| "atomic expected-value ref transaction preserved the changed " | ||
| "ref; observe it and decide again") |
There was a problem hiding this comment.
Valid — fixed in #362 (commit a21d40f), at both sites.
Measured first: git update-ref -d <ref> <old> cannot lock a ref that is already gone (error: cannot lock ref ..., rc=1), so a concurrently removed branch reaches this failure path rather than the success path. branch_sha() then returned None and the refusal described an absence as an object id. The pre-flight compare in delete_branch had the same defect and is the likelier place to observe it, so it is fixed too.
Both refusals now say the ref NO LONGER EXISTS and that this process deleted nothing, and restore_branch_if_absent distinguishes "still absent" from a value. Behaviour is deliberately unchanged: the transaction still refuses and the prepared cleanup record still unwinds, so no durable artifact claims a deletion this process did not perform. Regressions: test_a_concurrently_removed_ref_is_reported_as_absent_not_as_none, test_a_ref_removed_before_the_delete_is_reported_as_absent_too, test_a_restore_onto_a_ref_that_is_still_absent_says_so.
|
All three bot findings on this PR are VALID and are fixed in #362 ( Codex P1, Codex P2, Copilot, No declines — nothing was left unfixed. Tests (real numbers, #362 deliberately touches neither the OpenSpec packet nor the canonical spec, so it does not conflict with #361's archive-and-promote of this change. |
Summary
Validation