status.py: /proc/<pid>/stat parsing breaks when comm contains spaces/parens (contradicts drain_control.py's own correct parser)

Open Beginner friendly
#86,471 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start in gateway/status.py around line 309 and compare its /proc//stat handling with the parser in gateway/drain_control.py around lines 147-149. Verify that the extracted start time remains field 22 when comm contains spaces and right parentheses, then check the interaction with delivery_ledger.py around line 174. Done means live-owner checks no longer misread processes or permit duplicate claims.

Written by the indexing model from the issue text.

Description

comp/gateway P2 sweeper:risk-message-delivery type/bug

Summary

gateway/status.py (~line 309) reads the process start time with:

int(stat_path.read_text(encoding="utf-8").split()[21])

Whitespace-splitting /proc/<pid>/stat is unsafe: field 2 (comm, parenthesized) may contain spaces and right parens, shifting every subsequent field index. The same repository already documents and handles this correctly in gateway/drain_control.py (~lines 147-149): "comm can contain spaces and parens, so split on the LAST ')'" and indexes the tail — this call site is a leftover.

Impact

Beyond a wrong value or IndexError fallback, if the shifted index lands on a volatile field (e.g. processor number, which changes with CPU migration), two reads of the same live process can yield different values. delivery_ledger._owner_alive() (gateway/delivery_ledger.py ~line 174) would then misjudge a live owner as dead, letting a second gateway process claim its pending/attempting rows — duplicate delivery, which violates that module's "never a silent duplicate" contract.

Suggested fix

Align with drain_control.py:

text = stat_path.read_text(encoding="utf-8")
tail = text.rsplit(")", 1)[1].split()
return int(tail[19])  # field 22 == tail index 19 (tail starts at field 3)

Found auditing v0.20.1 (v2026.8.13).

Dominant language
Python
Stars
247k
Forks
52k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NousResearch/hermes-agent

All issues in NousResearch/hermes-agent

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.