Skip to content

fix: recover Linux state locks after PID reuse as worker TID - #175109

Draft
belbix wants to merge 1 commit into
openclaw:mainfrom
belbix:fix/linux-state-lock-worker-tid
Draft

belbix wants to merge 1 commit into
openclaw:mainfrom
belbix:fix/linux-state-lock-worker-tid

Conversation

@belbix

@belbix belbix commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Related: #175100

What Problem This Solves

Fixes an issue where users restarting Gateway cannot recover a stale state-owner lock when Linux recycles the former owner's PID as an unrelated service's worker TID. The observed incident required quarantining obsolete locks before startup could proceed.

Why This Change Was Made

Locks written with process.pid identify a process leader. Linux kill(pid, 0) also accepts nonleader thread IDs, so the existing existence check can incorrectly preserve a stale owner. Extend the canonical Linux procfs decision with Tgid != pid, retaining current terminal-leader/live-sibling handling and zero-thread snapshot revalidation. Non-Linux native identity policies, schemas and configuration are unchanged.

User Impact

Allows stale state locks whose numeric owner ID now belongs to a worker thread to be reclaimed without a manual lock quarantine. Live process leaders remain protected. No runtime patch has been deployed.

Evidence

  • Fresh upstream base: b7bb85a.
  • Real Linux worker, current-base predicate before/after (actual isExitedLinuxProcess body evaluated with real fs/process): baseline leaderRejected=false, workerRejected=false; fixed leaderRejected=false, workerRejected=true. This is predicate-level proof, NOT full packaged Gateway end-to-end proof. The full PID-reuse startup flow is not reproduced: deliberately cycling the running service/host's PID allocation would disturb the recovered instance; no isolated packaged-runtime reproduction has yet been completed.
  • Added regression protects the live leader while rejecting its worker TID through both public liveness helpers; no new production seam. It targets the baseline false-positive condition demonstrated above.
  • Earlier diagnostic checkout: full helper reproduction and 29/29 focused tests passed; added regression failed on its original source. These results are NOT claimed for this newer base.
  • Current-base focused suites attempted: collection blocked by missing @openclaw/proc-safe/errors in reused dependencies; 0 tests executed. Full build, typecheck and formatting tooling not completed. CI/maintainer validation required; draft intentionally.
  • git diff --check passes. Production +7/-1 (net +6): one canonical identity invariant and rationale; tests +14/-0. This absorbs the check in the existing procfs owner decision instead of adding another lock policy. Added lines express the otherwise missing process-leader ownership boundary.

Environment and limits

Affected host checked directly: OpenClaw 2026.9.8 (fc23bc8), Ubuntu 24.04.4 LTS x86_64, Linux 4.14.174, Node v24.16.0; global Node package layout and systemd user service (full details in #175100). Exact original failed-process build and original termination cause were not captured independently. This proposal fixes the confirmed worker-TID collision, not all leader-PID reuse across boots.

Prepared with AI assistance from incident diagnostics. Reporter: @belbix. No install, restart, merge, or deployment requested by this PR.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Reject Linux worker thread IDs as process owners when procfs identifies a different thread-group leader.

Example: A stale lock records PID 1103, now a worker TID whose procfs Tgid is 956, without usable start-time evidence.

  • Before: The liveness predicate accepts 1103 and prevents stale-owner recovery.
  • After: The predicate rejects 1103 as a process leader, allowing the existing stale-lock recovery policy to proceed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has no identified correctness defect, but required proof through the shipped behavior is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A stale process-owner lock can remain protected when its former PID now identifies an unrelated Linux worker thread.
Reason: Recognizing a proven nonleader restores the documented process-owner contract without adding configuration, another ownership layer, or a new API.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it narrowly repairs a current-main process-owner classification gap and is paired with the author's unresolved bug report.

Priority: P1
Reviewed head: 41c6a00ca231d73abfe158cd28e54decd121df8c

Before merge

  • Add real behavior proof - The supplied before/after values exercise an evaluated predicate body against a real Linux worker, while the added test mocks procfs and signals; neither exercises shipped Gateway state-owner acquisition, and the body explicitly records no packaged startup reproduction or successful current-base test collection. Provide redacted terminal output or logs from isolated post-fix Gateway startup recovering the worker-TID collision and refusing a live leader, accounting for start-time comparison and preserving settings and data through an upgrade from latest stable; redact IPs, keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Missing isolated Linux Gateway startup evidence showing this change recovers a worker-TID-owned stale lock beyond existing start-time recovery while refusing a live leader, including latest-stable upgrade preservation; current-head regression execution is also not demonstrated.
Agent review details

How this fits together

The shared process-liveness helpers translate signal and operating-system identity observations into owner-liveness decisions consumed by state locks, process supervision, updates, and plugins.

flowchart TD
  A[Gateway startup] --> B[State owner acquisition]
  B --> C[Namespace and start identity checks]
  C --> D[Shared PID liveness]
  D --> E[Linux procfs status]
  C --> F[Checked stale lock recovery]
  D --> F
Loading

Technical review

Best possible solution:

Keep the process-leader check in the shared Linux predicate while preserving existing start-identity recovery and conservative live-owner protection.

Do we have a high-confidence way to reproduce the issue?

Source establishes the worker-TID classification error, consistent with the reported real-thread reproduction; existing start-time recovery means the complete current-main startup failure is not independently established.

Is this the best way to solve the issue?

The shared Linux predicate is the appropriate repair boundary, and the patch preserves the established terminal-thread and uncertain-observation policies.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 66ffabc522ac.

Provenance checked

  • Linux terminal-task and reaping policy keeps the original intent (b57aca4: Revalidate zero-thread snapshots and recognize terminal tasks without releasing live sibling threads or exec handoffs.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The patch adds the Tgid invariant inside the existing Linux predicate and a leader-versus-worker regression; zero-thread revalidation and terminal-leader handling remain intact. (src/shared/pid-alive.ts:87, 41c6a00ca231)
  • Current-main classification gap: Current main checks Linux State and Threads but not Tgid, so a live nonleader worker is accepted as a process owner. (src/shared/pid-alive.ts:85, 66ffabc522ac)
  • Existing start-time recovery limits the incident claim: The stale-lock owner already recovers mismatched start identities before consulting liveness; matching or unavailable identity is the relevant remaining path. (src/infra/stale-lock-file.ts:72, 66ffabc522ac)
  • State-owner integration: State ownership passes the recorded PID and startTime to the shared stale-lock decision; acquisition retains checked remove-if-unchanged recovery. (src/infra/gateway-state-owner-record.ts:21, 66ffabc522ac)
  • Intentional conservative liveness policy: The preceding repair explicitly preserved live sibling threads, exec handoffs, permission uncertainty, and fresh existence checks for zero-thread snapshots. (src/shared/pid-alive.ts:85, b57aca41466b)
  • Reporter evidence and explicit limits: belbix reports a recovered Linux incident and real-worker predicate reproduction, while explicitly distinguishing these from packaged Gateway startup proof.

Likely related people:

  • Peter Steinberger: Raw commit b57aca4 adds src/shared/pid-alive.ts:107 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b57aca41466b; files: src/shared/pid-alive.ts)
  • Vincent Koc: Raw commit 5a2200b adds src/shared/pid-alive.ts:4 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5a2200b28003; files: src/shared/pid-alive.ts)
  • jeffr: Raw commit 6eaf2ba adds src/shared/pid-alive.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: low; commits: 6eaf2baa57dd; files: src/shared/pid-alive.ts)

PR surface

Source +6, Tests +14. Total +20 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 1 +6
Tests 1 14 0 +14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 21 1 +20

Root-cause cluster

Relationship: same_root_cause
Canonical: #175100
Summary: The paired issue tracks this state-lock repair; the earlier Telegram incident involved the same numeric-identity hazard in a separate ownership implementation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked incident describes a supervised Gateway remaining unavailable until manual stale-lock recovery.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the isolated Linux startup and live-owner protection evidence described in the proof assessment.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 17, 2026, 12:58 AM ET / 04:58 UTC.

steipete added a commit to xiaopan-xydt/openclaw that referenced this pull request Oct 17, 2026
Use the shared namespace policy to qualify local Windows PID/start identity
instead of letting disputed boot observations revoke a live state owner.
Preserve non-Windows previous-boot recovery and remove the duplicate
state-owner exception. Reject Linux worker TIDs as process.pid owners while
retaining conservative permission, thread-group, and reaping behavior.

Add deterministic process-identity regressions and recovery guidance. PR CI
owns tests and typechecks; local proof is changed-file lint and formatting.
Related: openclaw#174895. Fixes openclaw#175100. Folds in openclaw#175109 without closing it.

Co-authored-by: xiaopan-xydt <[email protected]>
Co-authored-by: belbix <[email protected]>
steipete added a commit that referenced this pull request Oct 18, 2026
…5118)

* fix(gateway): prevent spurious restart when Windows boot identity disagrees

When same-host Windows boot identity probes disagree, fall back to PID and
start-time evidence instead of treating the owner as immediately dead. This
preserves a live Gateway lock while retaining recovery for dead or reused PIDs.

* fix(gateway): preserve live owners and recover recycled Linux thread IDs

Use the shared namespace policy to qualify local Windows PID/start identity
instead of letting disputed boot observations revoke a live state owner.
Preserve non-Windows previous-boot recovery and remove the duplicate
state-owner exception. Reject Linux worker TIDs as process.pid owners while
retaining conservative permission, thread-group, and reaping behavior.

Add deterministic process-identity regressions and recovery guidance. PR CI
owns tests and typechecks; local proof is changed-file lint and formatting.
Related: #174895. Fixes #175100. Folds in #175109 without closing it.

Co-authored-by: xiaopan-xydt <[email protected]>
Co-authored-by: belbix <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: belbix <[email protected]>
Co-authored-by: xiaopan-xydt <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Your Linux worker-TID fix was folded into #175118, which landed as 1446ecc. Thank you, @belbix — your co-author credit is preserved in the merged commit alongside @xiaopan-xydt. This draft remains open.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…nclaw#175118)

* fix(gateway): prevent spurious restart when Windows boot identity disagrees

When same-host Windows boot identity probes disagree, fall back to PID and
start-time evidence instead of treating the owner as immediately dead. This
preserves a live Gateway lock while retaining recovery for dead or reused PIDs.

* fix(gateway): preserve live owners and recover recycled Linux thread IDs

Use the shared namespace policy to qualify local Windows PID/start identity
instead of letting disputed boot observations revoke a live state owner.
Preserve non-Windows previous-boot recovery and remove the duplicate
state-owner exception. Reject Linux worker TIDs as process.pid owners while
retaining conservative permission, thread-group, and reaping behavior.

Add deterministic process-identity regressions and recovery guidance. PR CI
owns tests and typechecks; local proof is changed-file lint and formatting.
Related: openclaw#174895. Fixes openclaw#175100. Folds in openclaw#175109 without closing it.

Co-authored-by: xiaopan-xydt <[email protected]>
Co-authored-by: belbix <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: belbix <[email protected]>
Co-authored-by: xiaopan-xydt <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 26, 2026
…5118)

* fix(gateway): prevent spurious restart when Windows boot identity disagrees

When same-host Windows boot identity probes disagree, fall back to PID and
start-time evidence instead of treating the owner as immediately dead. This
preserves a live Gateway lock while retaining recovery for dead or reused PIDs.

* fix(gateway): preserve live owners and recover recycled Linux thread IDs

Use the shared namespace policy to qualify local Windows PID/start identity
instead of letting disputed boot observations revoke a live state owner.
Preserve non-Windows previous-boot recovery and remove the duplicate
state-owner exception. Reject Linux worker TIDs as process.pid owners while
retaining conservative permission, thread-group, and reaping behavior.

Add deterministic process-identity regressions and recovery guidance. PR CI
owns tests and typechecks; local proof is changed-file lint and formatting.
Related: #174895. Fixes #175100. Folds in #175109 without closing it.

Co-authored-by: xiaopan-xydt <[email protected]>
Co-authored-by: belbix <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: belbix <[email protected]>
Co-authored-by: xiaopan-xydt <[email protected]>
(cherry picked from commit 1446ecc)

Adapted for 2026.9.x: ported only the Linux Tgid check in
src/shared/pid-alive.ts and its regression. The Windows boot-identity
gateway-lock change, namespace tests, and gateway-lock docs are not
included. 9.x names the procfs helper isZombieProcess and only treats a Z
leader with one thread as exited, so the Tgid rejection runs before that
existing check.
RomneyDa added a commit that referenced this pull request Nov 8, 2026
…5118)

* fix(gateway): prevent spurious restart when Windows boot identity disagrees

When same-host Windows boot identity probes disagree, fall back to PID and
start-time evidence instead of treating the owner as immediately dead. This
preserves a live Gateway lock while retaining recovery for dead or reused PIDs.

* fix(gateway): preserve live owners and recover recycled Linux thread IDs

Use the shared namespace policy to qualify local Windows PID/start identity
instead of letting disputed boot observations revoke a live state owner.
Preserve non-Windows previous-boot recovery and remove the duplicate
state-owner exception. Reject Linux worker TIDs as process.pid owners while
retaining conservative permission, thread-group, and reaping behavior.

Add deterministic process-identity regressions and recovery guidance. PR CI
owns tests and typechecks; local proof is changed-file lint and formatting.
Related: #174895. Fixes #175100. Folds in #175109 without closing it.

Co-authored-by: xiaopan-xydt <[email protected]>
Co-authored-by: belbix <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: belbix <[email protected]>
Co-authored-by: xiaopan-xydt <[email protected]>

(cherry picked from commit 1446ecc)

Release adaptation: Apply Linux Tgid validation and same-host Windows namespace handling through the existing release identity owner; preserve PID/start-time and conservative probe behavior.

Co-authored-by: RomneyDa <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants