fix(reconcile): retire workflow session rows whose owners are no longer live #971

Open
jcwalker3 wants to merge 1 commits from fix/issue-969-native-mcp-bootstrap into master
Owner

Summary

Implements a sanctioned lifecycle for control-plane workflow session rows whose recorded owners are no longer live (#969).

Post-restart reconciliation was remaining permanently degraded because hundreds of active session rows still named dead owner PIDs even when fleet-wide live leases were zero. A bare PID existence check is insufficient (OS PID reuse), so this change classifies sessions with stronger evidence and terminalizes only confirmed-stale rows.

Behavior

  • New session_lifecycle module classifies sessions as live / disconnected / stale / protected / terminal
  • Protects live owners, live workflow leases, and live client-managed sessions
  • Detects PID reuse via process start time vs session started_at
  • Terminalizes confirmed-stale rows to retired (CAS, never deletes history)
  • Writes durable session_retired audit events
  • Idempotent under concurrent reconciliation
  • Wired into gitea_reconcile_after_restart(apply_session_cleanup=…) and dedicated gitea_retire_stale_workflow_sessions

Tests

Focused coverage for dead owners, PID reuse, live owners, live leases, client-managed sessions, mixed fleets, concurrent retirement, repeated cleanup, and reconcile dimension resolution.

Closes #969

## Summary Implements a sanctioned lifecycle for control-plane workflow session rows whose recorded owners are no longer live (#969). Post-restart reconciliation was remaining permanently degraded because hundreds of `active` session rows still named dead owner PIDs even when fleet-wide live leases were zero. A bare PID existence check is insufficient (OS PID reuse), so this change classifies sessions with stronger evidence and terminalizes only confirmed-stale rows. ### Behavior - New `session_lifecycle` module classifies sessions as live / disconnected / stale / protected / terminal - Protects live owners, live workflow leases, and live client-managed sessions - Detects PID reuse via process start time vs session `started_at` - Terminalizes confirmed-stale rows to `retired` (CAS, never deletes history) - Writes durable `session_retired` audit events - Idempotent under concurrent reconciliation - Wired into `gitea_reconcile_after_restart(apply_session_cleanup=…)` and dedicated `gitea_retire_stale_workflow_sessions` ### Tests Focused coverage for dead owners, PID reuse, live owners, live leases, client-managed sessions, mixed fleets, concurrent retirement, repeated cleanup, and reconcile dimension resolution. Closes #969
jcwalker3 added 1 commit 2026-07-29 04:28:39 -05:00
Implement a sanctioned session lifecycle for post-restart reconciliation so
active session rows with dead or reused owner PIDs can be terminalized
without deleting history. Protect live owners, live leases, and live
client-managed sessions; record durable session_retired audit events; keep
cleanup idempotent under concurrent reconciles.

Closes #969

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Author
Owner

Canonical Issue State

STATE:
needs-review

WHO_IS_NEXT:
reviewer

NEXT_ACTION:
Review PR #971 at pinned head e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c; approve or request changes.

NEXT_PROMPT:

Review PR #971 in Scaled-Tech-Consulting/Gitea-Tools as prgs-reviewer (gitea-reviewer). Pin expected_head_sha=e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c. Scope is issue #969 session lifecycle retirement only. Do not merge without explicit operator authorization.

WHAT_HAPPENED:
Author implemented #969 session lifecycle retirement, published branch fix/issue-969-native-mcp-bootstrap at e8bae606cb, and opened PR #971.

WHY:
Post-restart reconciliation remained degraded with active session rows whose owners are no longer live; this PR implements safe terminalization without PID-reuse false ownership.

RELATED_PRS:

BRANCH:
fix/issue-969-native-mcp-bootstrap

HEAD_SHA:
e8bae606cb

VALIDATION:
unittest: test_issue_969_session_lifecycle + test_issue_662 + test_control_plane_db + test_lease_lifecycle + test_restart_coordinator + test_mcp_restart_governance (105 passed)

BLOCKERS:
none

LAST_UPDATED_BY:
jcwalker3 / prgs-author / 2026-07-29

Canonical Handoff

REPOSITORY: Scaled-Tech-Consulting/Gitea-Tools
ISSUE: #969
PR: #971
WORKFLOW_STATE: needs-review
HEAD_SHA: e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c
BASE_BRANCH: master
BASE_OR_MERGE_SHA: 956fa15fe3dab82c8669d5b257406e1e4c14929c
ACTING_ROLE: author
ACTING_IDENTITY: jcwalker3/prgs-author
COMPLETED_ACTIONS: implemented session lifecycle; committed e8bae606; published branch; opened PR #971 closing #969
VALIDATION_EVIDENCE: unittest suite: test_issue_969_session_lifecycle, test_issue_662_post_restart_reconcile, test_control_plane_db, test_lease_lifecycle, test_restart_coordinator, test_mcp_restart_governance — 105 passed
MUTATION_LEDGER: created session_lifecycle.py; updated control_plane_db.py, post_restart_reconcile.py, gitea_mcp_server.py, task_capability_map.py, docs/post-restart-reconcile.md, tests; no approve/merge mutations
BLOCKERS: none
NEXT_ACTOR: reviewer
NEXT_ACTION: Review PR #971 at pinned head e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c; approve or request changes
PROHIBITED_ACTIONS: author must not self-review, approve, or merge; do not touch allocation #970
NEXT_PROMPT: Review PR #971 in Scaled-Tech-Consulting/Gitea-Tools as prgs-reviewer (gitea-reviewer). Pin expected_head_sha=e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c. Scope is issue #969 session lifecycle retirement only. Do not merge without explicit operator authorization.
WORKFLOW_FAILURE_ISSUES: none
LAST_UPDATED: 2026-07-29T09:29Z
## Canonical Issue State STATE: needs-review WHO_IS_NEXT: reviewer NEXT_ACTION: Review PR #971 at pinned head e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c; approve or request changes. NEXT_PROMPT: ```text Review PR #971 in Scaled-Tech-Consulting/Gitea-Tools as prgs-reviewer (gitea-reviewer). Pin expected_head_sha=e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c. Scope is issue #969 session lifecycle retirement only. Do not merge without explicit operator authorization. ``` WHAT_HAPPENED: Author implemented #969 session lifecycle retirement, published branch fix/issue-969-native-mcp-bootstrap at e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c, and opened PR #971. WHY: Post-restart reconciliation remained degraded with active session rows whose owners are no longer live; this PR implements safe terminalization without PID-reuse false ownership. RELATED_PRS: - #971 BRANCH: fix/issue-969-native-mcp-bootstrap HEAD_SHA: e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c VALIDATION: unittest: test_issue_969_session_lifecycle + test_issue_662 + test_control_plane_db + test_lease_lifecycle + test_restart_coordinator + test_mcp_restart_governance (105 passed) BLOCKERS: none LAST_UPDATED_BY: jcwalker3 / prgs-author / 2026-07-29 <!-- sph:v1 --> ## Canonical Handoff ```text REPOSITORY: Scaled-Tech-Consulting/Gitea-Tools ISSUE: #969 PR: #971 WORKFLOW_STATE: needs-review HEAD_SHA: e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c BASE_BRANCH: master BASE_OR_MERGE_SHA: 956fa15fe3dab82c8669d5b257406e1e4c14929c ACTING_ROLE: author ACTING_IDENTITY: jcwalker3/prgs-author COMPLETED_ACTIONS: implemented session lifecycle; committed e8bae606; published branch; opened PR #971 closing #969 VALIDATION_EVIDENCE: unittest suite: test_issue_969_session_lifecycle, test_issue_662_post_restart_reconcile, test_control_plane_db, test_lease_lifecycle, test_restart_coordinator, test_mcp_restart_governance — 105 passed MUTATION_LEDGER: created session_lifecycle.py; updated control_plane_db.py, post_restart_reconcile.py, gitea_mcp_server.py, task_capability_map.py, docs/post-restart-reconcile.md, tests; no approve/merge mutations BLOCKERS: none NEXT_ACTOR: reviewer NEXT_ACTION: Review PR #971 at pinned head e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c; approve or request changes PROHIBITED_ACTIONS: author must not self-review, approve, or merge; do not touch allocation #970 NEXT_PROMPT: Review PR #971 in Scaled-Tech-Consulting/Gitea-Tools as prgs-reviewer (gitea-reviewer). Pin expected_head_sha=e8bae606cb1a82d4cb6f3e544c8ffe28e9617f0c. Scope is issue #969 session lifecycle retirement only. Do not merge without explicit operator authorization. WORKFLOW_FAILURE_ISSUES: none LAST_UPDATED: 2026-07-29T09:29Z ```
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/issue-969-native-mcp-bootstrap:fix/issue-969-native-mcp-bootstrap
git checkout fix/issue-969-native-mcp-bootstrap
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Scaled-Tech-Consulting/Gitea-Tools#971