fix: guard flock(LOCK_UN) against OSError in kanban_db and google_oauth - #35204
Open
annguyenNous wants to merge 1 commit into
Open
annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
Two files had unguarded fcntl.flock(LOCK_UN) calls in finally blocks that could raise OSError and propagate as unhandled exceptions. - hermes_cli/kanban_db.py: flock(LOCK_UN) in finally block without try/except — if unlock fails, the exception propagates even though handle.close() still runs in the outer finally. - agent/google_oauth.py: flock(LOCK_UN) inside try/except ImportError (for msvcrt fallback) but OSError was not caught. The msvcrt path already had proper OSError guarding, but the fcntl path did not. Both fixes follow the existing pattern used in tools/skill_usage.py, tools/memory_tool.py, and hermes_cli/auth.py where flock(LOCK_UN) is already wrapped in try/except (OSError, IOError): pass.
Contributor
This was referenced May 31, 2026
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the defensive cleanup. The Kanban issue is still present on current main, but this branch needs a focused salvage rather than a direct cherry-pick.
Problems
agent/google_oauth.pywas deleted by7130d60861a9243301514bff611a9381830d59d8; the OAuth hunk is obsolete. This also aligns with the member note that this portion duplicated earlier work.- The relevant Kanban cleanup has moved: current main still has the unguarded POSIX unlock at
hermes_cli/kanban_db.py:1410, while the submitted hunk targets the older location. - Current tests cover normal lock release (
tests/hermes_cli/test_kanban_db.py:81) and bounded acquisition (tests/hermes_cli/test_kanban_init_lock_bounded.py:75), but not an OSError from POSIX unlock.
Suggested changes
- Reapply only the Kanban guard at
hermes_cli/kanban_db.py:1410, preserving its outer close-finally. - Add an OSError-on-unlock regression test; do not revive the removed OAuth module.
Automated hermes-sweeper review.
|
|
||
| fcntl.flock(fd, fcntl.LOCK_UN) | ||
| except ImportError: | ||
| except (ImportError, OSError): |
Collaborator
There was a problem hiding this comment.
agent/google_oauth.py was deleted on current main by 7130d60861a9243301514bff611a9381830d59d8; omit this hunk when salvaging the still-relevant Kanban fix.
| fcntl.flock(handle.fileno(), fcntl.LOCK_UN) | ||
| try: | ||
| fcntl.flock(handle.fileno(), fcntl.LOCK_UN) | ||
| except OSError: |
Collaborator
There was a problem hiding this comment.
The same cleanup concern remains on current main, but this hunk's context is stale: apply the guard to the current POSIX unlock at hermes_cli/kanban_db.py:1410 and add a regression test that makes that unlock raise OSError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two files had unguarded
fcntl.flock(LOCK_UN)calls infinallyblocks that could raiseOSErrorand propagate as unhandled exceptions.hermes_cli/kanban_db.py:1075:flock(LOCK_UN)infinallyblock withouttry/except— if unlock fails, the exception propagates even thoughhandle.close()still runs in the outerfinally.agent/google_oauth.py:229:flock(LOCK_UN)insidetry/except ImportError(for msvcrt fallback) butOSErrorwas not caught. The msvcrt path already had properOSErrorguarding, but the fcntl path did not.Fix
kanban_db.py: Wrapflock(LOCK_UN)intry/except OSError: passgoogle_oauth.py: Changeexcept ImportErrortoexcept (ImportError, OSError)so both import failures and lock failures are handledBefore vs After
kanban_db.pyflock(UN)bare in finallytry/except OSErrorgoogle_oauth.pyexcept ImportErroronlyexcept (ImportError, OSError)Pattern Consistency
Both fixes follow the existing pattern already used in:
tools/skill_usage.py:91—except (OSError, IOError): passtools/memory_tool.py:234—except (OSError, IOError): passhermes_cli/auth.py:1012—except (OSError, IOError): passcron/scheduler.py:2027—except Exception: passgateway/status.py:416—except OSError: passThe two files in this PR were the remaining unguarded sites across the codebase.