Make worktree cleanup audit merged-PR aware for issue worktrees #858
Closed
opened 2026-07-23 20:01:40 -05:00 by jcwalker3
·
0 comments
No Branch/Tag Specified
master
fix/issue-850-native-mcp-bootstrap
fix/issue-860-dirty-orphan-worktree-recovery
fix/issue-858-audit-merged-pr-aware
feat/issue-639-webui-system-health-dashboard
docs/issue-656-mcp-restart-governance
fix/issue-842-conflict-fix-lease-lifecycle
feat/issue-628-autonomous-handoffs-orchestration
fix/issue-790-slice-a-heartbeat-policy
feat/issue-637-timeline-model
feat/issue-646-policy-guardrail-visibility
feat/issue-638-webui-app-shell-phase1
fix/issue-851-cleanup-worktree-before-remote-delete
fix/issue-843-cross-role-allocation-handoff
fix/issue-844-exclude-epic-containers
feat/issue-634-readonly-system-health-api
fix/issue-840-cross-role-queue-allocation
feat/issue-822-atomic-install-authority-kernel
feat/issue-633-console-authz-audit-model
feat/issue-636-inventory-api
fix/issue-815-preflight-worktree-forwarding
feat/issue-812-publish-unpublished-commit
feat/issue-635-project-registry-api
feat/issue-798-worker-registry-schema
feat/issue-610-live-remote-parity
docs/issue-632-web-console-architecture
fix/issue-760-exact-owner-renewal
fix/issue-787-kill-segment-separators
chore/issue-681-preserve-review-session-wip
v1.1.0
Labels
Clear labels
allocator
anti-stomp
architecture
bug
chore
codex
concurrency
contamination
control-plane
dashboard
database
design
documentation
enhancement
gitea
glitchtip
important
incident
incident-bridge
integration
jenkins
labels
leases
mcp
mcp-health
mcp-menu
multi-project
mutating
nice-to-have
observability
portability
preflight
protected-branch
queue
read-only
reconnect
recovery
refactor
release
reliability
resumable-review
reviewer
roadmap
safety
security
self-hosted
sentry
stale-runtime
status:blocked
status:in-progress
status:pr-open
status:ready
terminal-lock
testing
tracker
type:bug
type:feature
type:feature
type:guardrail
visibility
workflow
workflow-hardening
workflow-hardening
Controller-owned work allocator
Prevent concurrent LLM session stomping
Architecture / structural design
OpenAI Codex client / workflow session surface
Concurrent session safety
Workflow or session contamination incident
MCP control-plane coordination and allocation authority
MCP operational dashboard/queue view
Internal coordination storage (SQLite/Postgres)
Design / investigation, no implementation
Docs / runbooks
New feature or improvement
Gitea MCP workflow
GlitchTip integration
Operational or process incident requiring durable audit trail
Sentry-to-Gitea incident bridging
Integration testing
Jenkins integration
Label taxonomy management
Lease adopt/release/expire lifecycle
MCP server / tooling
MCP namespace and runtime health
MCP menu surface
Work spanning multiple monitoring projects or Gitea repos
Mutating action; requires gating
Observability, metrics, traces, error reporting
Cross-platform / portability
Shared preflight gates before mutation
Protected branch / stable-branch policy concern
Work queue visibility and allocation
Read-only, no mutation
MCP client reconnect/reload recovery path
Recovery paths for stale/foreign leases
Code refactor / restructure
Release / versioning
Reliability / failure handling
Persist and resume prepared review verdicts across sessions
Reviewer workflow tooling
Roadmap / umbrella issue
Safety rails and fail-closed mutation guards
Security / trust boundary
Self-hosted infrastructure integration
Sentry error monitoring integration
Stale backend daemon / runtime-vs-master parity failures
Issue is blocked
Issue is being worked on
Issue has an open pull request
Issue is ready for work
Terminal review lock (#332) path
Tests / test coverage
Issue tracker hygiene / meta
Bug or defect
Feature or enhancement
Feature or enhancement
Safety gate or guardrail
Workflow state visibility for LLMs/operators
Cross-tool workflow
LLM workflow coordination hardening
LLM workflow coordination hardening
Milestone
No items
No Milestone
Projects
Clear projects
No projects
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Scaled-Tech-Consulting/Gitea-Tools#858
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
gitea_audit_worktree_cleanuphas no merged-PR linkage. Forworkflow_type=issue_workworktrees it therefore reportspr_number=nulland classifies every one of themactive_issue_workwithremovable=false, permanently — even when the owning PR is merged, the head is already contained in master, and nothing protects the worktree.The PR-aware assessor
gitea_reconcile_merged_cleanupslooks at the same on-disk state and disagrees.Observed disagreement (master
9301739910df)For registered worktree
branches/issue-637-timeline-model(branchfeat/issue-637-timeline-model, headb9ba43a5bf292690eec0b24b19a1f489930986e7, owning PR #849 merged as9301739910df7b51ca3abcdbf46cce25cfb026e5, issue #637 closed, no lease, clean):gitea_reconcile_merged_cleanupslinks the worktree to merged PR #849 and reportssafe_to_remove_worktree=true,safe_to_delete_remote=true,block_reasons=[].gitea_audit_worktree_cleanupreportspr_number=null,classification=active_issue_work,removable=false, withdirty=false,has_open_pr=false,has_active_lease=false,has_active_issue_lock=false,is_protected=false.Repository-wide in the same audit run: 42 worktrees of
workflow_type=issue_work,removable=trueon 0 of them,pr_numberpopulated on 0 of them.Root cause
Two independent gaps in
worktree_cleanup_audit.pyand its MCP wiring:No PR linkage at all.
audit_branches_directorybuilds metadata withbuild_worktree_metadata(path=..., branch=..., head_sha=...)and never suppliespr_number, sopr_numberis structurally alwaysnull.gitea_audit_worktree_cleanupfetches onlypulls?state=open; merged PRs are never read, so no owning-PR evidence exists.clean_stale_removableis unreachable forissue_work. Inclassify_worktree,issue_work/conflict_fixreachclean_stale_removableonly whenttl_expiredis true.audit_branches_directoryderives that frommetadata["last_used_at"], whichbuild_worktree_metadatanever populates, andis_ttl_expiredfail-safes toFalseon an unknown timestamp. Sottl_expiredis alwaysFalseand the finalreturn CLASS_ACTIVE_ISSUE_WORKis the only reachable outcome for a cleanissue_workworktree.A merged
issue_workworktree is therefore reported as active work forever, and the audit can never agree with the PR-scoped reconciler.Adjacent safety gap this exposes
audit_branches_directoryacceptsleased_branches, butgitea_audit_worktree_cleanupnever passes it, sohas_active_leaseisfalsefor every worktree in a live run (0 of 90 observed). This is currently inert only becauseissue_workcan never become removable. Making removability reachable without first wiring real lease evidence would convert an inert gap into an active hole, so lease and issue-lock protection must be supplied from authoritative state as part of this change.Required behavior
issue_workworktree can be linked deterministically to its owning PR when authoritative repository state permits, andpr_numberis populated from that linkage.active_issue_workis not weakened globally; it is replaced only when authoritative merged-PR evidence satisfies the complete policy.gitea_reconcile_merged_cleanupsstay semantically aligned while keeping their distinct responsibilities.Acceptance criteria
issue_workworktree is linked to its owning PR and can become removable.pr_numberis populated from authoritative linkage rather than left null.issue_workare unchanged.Explicit non-authorization
This task authorizes no real worktree or branch cleanup. Implementation and tests must not remove any real worktree or delete any real remote branch. In particular the
branches/issue-637-timeline-modelworktree and thefeat/issue-637-timeline-modelremote branch are retained as the reproduction fixture and must be left untouched; PR #849 and issue #637 must not be modified.Scope boundary against issue #855
Issue #855 is a reconciler-executor issue: it asks for a PR-scoped target for
gitea_reconcile_merged_cleanups(whose execute path is batch-only) and for expired reviewer leases to stop protecting an already-merged branch. It does not mentiongitea_audit_worktree_cleanup, PR linkage in the audit, or the permanentactive_issue_workclassification, and none of its acceptance criteria cover them.This issue is assessor-side only and additive to #855: it makes the audit's classification merged-PR aware. It does not add a PR-scoped executor, does not change lease reclaim policy, and does not alter the batch reconciliation path. #855 is cross-referenced as context only; the two scopes stay separate.
Non-goals
gitea_audit_worktree_cleanup.References
worktree_cleanup_audit.py(classify_worktree,audit_branches_directory,build_worktree_metadata),gitea_audit_worktree_cleanupingitea_mcp_server.py.merged_cleanup_reconcile.py(build_pr_cleanup_entry,assess_local_worktree_cleanup,is_head_ancestor_of_ref).9301739910df.