Repository navigation
fix(agents): wait for hook state locks instead of failing with EAGAIN - #285
Merged
Merged
Conversation
Hook entries took the session record and registration locks with LOCK_NB, so concurrent hooks failed at once with errno 35: a second PostToolUse lost its herdr ownership record and simultaneous subagent PreToolUse calls aborted. Wait up to 0.5 s (10 ms retries) and then fail naming the lock and stating that another hook holds it. The limit keeps three sequential acquisitions inside SessionEnd's 3 s timeout. GC keeps skipping records held by a long Stop verification without waiting. Closes #273 Refs furedea/agent-harness#169 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… lock waits Address review findings on the bounded lock wait: - GC takes .gc.lock without blocking and skips the pass when busy, so a concurrent GC can no longer fail Stop or SessionEnd. - Stop (gate) and SessionEnd wait on the record lock without a limit again, restoring serialization of verification runs and session end. - registered_record() no longer takes the record lock, so a long Stop verification cannot fail other hooks of the same session. - herdr ownership records use their own bounded .herdr.lock instead of the record lock. - Registration releases .register.lock before reopening an existing record, so the two bounded waits no longer nest. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…en busy - SessionEnd waits up to 2 s for the record lock and then skips end(), leaving a busy session to mtime-based GC instead of exceeding the 3 s Codex hook timeout. - Resume touches the record and returns when the record lock stays busy, rather than failing SessionStart. - Raise LockTimeoutError for lock wait timeouts so callers can degrade on exactly that failure. - Read LOCK_WAIT_SECONDS at call time so tests patch a single place. - Restore the comment explaining the 0.5 s wait. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
4 tasks
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.
背景
フックの状態ロックを
fcntl.flock(LOCK_NB)で取得していたため,別のフックがロックを保持していると即座にBlockingIOError(EAGAIN,macOS では errno 35)で失敗していました.[Errno 35] Resource temporarily unavailableで失敗し,サブエージェントが何もせず終了する.変更内容(最終的なロックの挙動)
file_lockはblocking=False(即時失敗),timeout=None(無期限に待機),timeout=秒(10 ms 間隔で再試行し,期限超過でロックのパスとanother hook holds itを含むLockTimeoutError)を区別します.通常の待機上限LOCK_WAIT_SECONDSは 0.5 秒で,呼び出し時に読み取ります.registered_record()(全フックの入口)touchは原子的書き込みで足りる.register.lock(登録)reopenはこのロックを解放してから行い,待機が入れ子にならないreopen()のレコードロック)touchのみして返るconfirm).herdr.lockで最大 0.5 秒の待機gate)end()を省略.gc.lockテスト
herdr agent start/workspace createの結果が同時に PostToolUse へ届いても,実際のフックエントリ経由で両方のレコードが保持される.another hook holds itを含む明確なエラーになる.touchのみで返り,SessionEnd は 2 秒でend()を省略する.GC が保持中のレコードや GC ロックを待たずに飛ばす.uv run --frozen pytest tests/agents: 1973 passed.lefthook pre-commit: 全件成功.Closes #273
Refs furedea/agent-harness#169
🤖 Generated with Claude Code