Allow exact-owner renewal of expired author issue locks #760
Open
opened 2026-07-19 11:51:08 -05:00 by jcwalker3
·
0 comments
No Branch/Tag Specified
master
feat/issue-626-self-propagating-handoffs
fix/issue-772-unpublished-claim-recovery
archive/role-poisoning-dfb5ebd
archive/capability-role-invariants-bc9366c
docs/mcp-stable-control-runtime-policy
fix/issue-695-native-quarantine-v2
chore/issue-681-preserve-review-session-wip
fix/issue-673-remediate-regressions-part2
feat/issue-610-live-remote-parity
feat/issue-503-reviewer-active-worktree
feat/issue-470-preflight-contract
feat/issue-440-lock-recovery
feat/issue-440-branch-recovery
feat/issue-458-queue-fail-closed-copy
feat/issue-400-early-duplicate-work-gate
feat/issue-308-reconcile-inventory-pagination
feat/issue-308-reconcile-pagination-proof
docs/issue-261-agent-temp-artifact-cleanup
feat/issue-262-map-commit-files
fix/infra-stop-conflict-marker-false-positive
feat/issue-139-role-aware-task-routing
feat/issue-188-continuation-selection-wall
feat/issue-189-continuation-mode-proofs
feat/issue-232-refresh-wiki-proof-heads
feat/issue-210-block-workspace-edits
feat/issue-204-exact-issue-lock
docs/issue-80-label-taxonomy
docs/issue-79-safety-boundary-updates
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#760
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.
Summary
An expired file-store author issue lock cannot be renewed by its exact owner when the recorded PID remains alive and the worktree still exists.
Because the PID represents a persistent MCP daemon rather than the individual author task, daemon liveness is not proof that task ownership remains active. The expired-lock path treats same-owner continuation as a foreign takeover and returns before exact ownership is considered.
Verified against master
bde5c5fb20fbf6aec9cd6b802341c43078921d13.Observed production state
Issue #757 was a historical instance of the expired-plus-live-daemon condition. It is not reproduced live at the time of filing, and this issue does not claim that it is.
Durable lock record for #757, read from
~/.cache/gitea-tools/issue-locks/prgs-Scaled-Tech-Consulting-Gitea-Tools-757.json:Corroborating repository state, all verified:
adc61255b2d7eb65d1670e09e561dbd84b652317;last_heartbeat_atequalscreated_at, so the lease was never renewed across a multi-hour authoring task;Why this instance no longer demonstrates the defect
Recorded PID
3543has since exited.kill -0 3543reports no such process, and the live MCP daemon cohorts carry unrelated PIDs.With a dead PID the reclaim gate now permits recovery:
deadbecomes true, the fail-closed return is skipped,assess_expired_lock_reclaimreturnsreclaim_allowed=true, andassess_same_issue_lease_conflictreturnsNone. Issue #757 is therefore recoverable today through the existing dead-PID path and is filed here as evidence of the condition, not as a live reproduction.What remains proven
The expired-plus-live-PID same-owner renewal gap is proven by production code inspection and by the absence of any test covering it. Nothing in the source grants renewal to an exact owner whose lease expired while its recording daemon stayed alive, and no regression asserts that behavior in either direction. Because the recorded PID is the long-lived MCP daemon, a live PID at expiry is the ordinary case for any author task that outlives the four-hour TTL — the condition will recur.
Root cause
Gate ordering
assess_same_issue_lease_conflict(issue_lock_store.py:436) computes same-owner evidence before it consults it:issue_lock_store.py:461-464—same_owneris computed from the locked branch and the realpath-normalized worktree.issue_lock_store.py:465— the expired-lease branch is entered.issue_lock_store.py:466-470— onreclaim_allowed, returnsNone.issue_lock_store.py:471-475— otherwise returns the "Recovery review is required before takeover (fail closed)" error.issue_lock_store.py:476— thesame_ownerallowance. Unreachable whenever the lease is expired, because both preceding paths return.assess_expired_lock_reclaim(issue_lock_store.py:379) permits reclaim only on dead PID or missing worktree (issue_lock_store.py:404-420, gate at:410). An exact owner whose daemon is alive and whose worktree is present satisfies neither, so it takes the fail-closed return and never reaches line 476.Why the lease expires under an active task
session_pidandpidare bound fromos.getpid()atissue_lock_store.py:170-171and:174, recording the persistent MCP daemon rather than the individual author task. The session pointer path also embeds that PID (issue_lock_store.py:73).Expiry is computed once at creation —
gitea_mcp_server.py:2016-2027, withWORK_LEASE_TTL_HOURS = 4atgitea_mcp_server.py:1913— from the single call site atgitea_mcp_server.py:3398. No renewal writer exists for this store.gitea_post_heartbeat(gitea_mcp_server.py:15481) does not reference the file store,work_lease, orexpires_at.gitea_heartbeat_reviewer_pr_lease(gitea_mcp_server.py:12297) renews a reviewer PR comment lease, a different substrate. Once wall-clock passesexpires_at,assess_lock_freshness(issue_lock_store.py:340-355) reports the lock non-live no matter how active the owning task is.Two distinct substrates
File-store author locks are JSON on disk (
issue_lock_store.py:34,:59,:117,:129). Control-plane workflow leases are SQLite (control_plane_db.py:23,:44,:254;lease_lifecycle.py:31).gitea_adopt_workflow_lease(gitea_mcp_server.py:18313),gitea_release_workflow_lease(:18368), andgitea_reclaim_expired_workflow_lease(:18488) all delegate tolease_lifecycle, which never importsissue_lock_store. Those tools cannot clear, refresh, or overwrite a file-store issue lock.The only writer is blocked
gitea_lock_issueis the sole native writer of the file store:gitea_mcp_server.py:3428calls_save_issue_lock(:1982,:1993), which callsbind_session_lock, which performs the writes atissue_lock_store.py:197-198. It is refused by the expired conflict at two points — the pre-check atgitea_mcp_server.py:3215-3223and again under the exclusive file lock atissue_lock_store.py:189-196— before reaching the write.Downstream,
verify_lock_for_mutation(issue_lock_store.py:565, call sitegitea_mcp_server.py:3628) requires a live lock atissue_lock_store.py:577-579, so no author mutation can proceed.Related but separately owned
assess_lock_freshness(issue_lock_store.py:340-355) has two independent non-live triggers: expired-by-time and dead-PID. Line 465 gates the reclaim assessor on expiry alone, so the two triggers have symmetric but opposite gaps. The dead-PID-under-unexpired-lease side is documented atissue_lock_recovery.py:12-14and is owned by #753; it is not re-owned here.Verify current line numbers during implementation rather than treating reported locations as immutable.
Safety impact
Acceptance criteria
AC1. Distinguish exact-owner renewal from foreign takeover.
AC2. Evaluate a strengthened same-owner renewal disposition before the expired foreign-takeover return.
AC3. Renewal requires exact match of: remote; owner; repository; issue number; operation type; branch; realpath-normalized worktree; claimant username; claimant profile.
AC4. The registered worktree must exist and be clean.
AC5. Local branch head must equal the remote branch head.
AC6. When an owning PR exists, local head, remote branch head, and live PR head must all match.
AC7. No competing live lock, competing branch claim, or other owning PR may exist.
AC8. Any missing or contradictory evidence fails closed.
AC9. Successful renewal atomically records: prior PID; replacement PID; prior expiry; renewal timestamp; new expiry; claimant and evidence provenance.
AC10. The renewed lock must immediately satisfy the existing downstream
verify_lock_for_mutationpath.AC11. Foreign expired-lock takeover continues to require the existing dead-PID or missing-worktree recovery conditions.
AC12. A live foreign lease remains non-recoverable.
AC13. Renewal is available through a native sanctioned tool path; no JSON edit, daemon restart, fabricated worktree, or direct API/CLI mutation is required.
AC14. Do not expose a caller-controlled boolean that declares ownership or renewal eligibility.
AC15. Tests cover: expired plus alive PID plus present clean worktree plus exact owner, renewal allowed; different branch refused; different worktree refused; different claimant or profile refused; dirty worktree refused; local and remote head mismatch refused; PR-head mismatch refused; competing lock, branch, or PR refused; live foreign lease refused; existing dead-PID reclaim unchanged; renewed lock satisfies downstream mutation ownership.
AC16. Add an explicit regression proving an MCP daemon PID remaining alive is not sufficient evidence of an active author task after lease expiry.
AC17. Do not special-case #757, PR #759, or any repository issue number.
Validation expectations
gitea_lock_issue, not only against the assessor functions.Linkage and ownership boundary
assess_expired_lock_reclaim. The component being corrected.Canonical issue state