hosted_rooms: add cross-process lock to prevent state.db corruption on concurrent gateway startup - #102176
Open
Sahilvishnaliya wants to merge 1 commit into
Open
hosted_rooms: add cross-process lock to prevent state.db corruption on concurrent gateway startup#102176Sahilvishnaliya wants to merge 1 commit into
Sahilvishnaliya wants to merge 1 commit into
Conversation
Contributor
Contributor
Author
|
🔴 CI failing — needs a fix before merge. Failing check:
Other jobs (tests, other lints) are passing. Please check the |
Contributor
Author
|
CI
Fix the top of the file to: from __future__ import annotations
import contextlib
import hashlib
import json
import re
import sqlite3
import time
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Iterator, Mapping, NoReturn
# Cross-process file locking: fcntl on Unix, msvcrt on Windows.
fcntl = None
msvcrt = None
try:
import fcntl
except ImportError:
try:
import msvcrt
except ImportError:
passAnd delete Do not nest |
…n concurrent gateway startup Fixes NousResearch#102120 The hosted_room_worker starts on every profile gateway restart and calls prune_disbanded_rooms() on the shared state.db. When multiple profiles restart simultaneously (e.g. during 'hermes update' fleet restart), all gateways hit the same SQLite database concurrently, causing corruption ('file is not a database'). This fix adds a cross-process advisory lock (fcntl on Unix, msvcrt on Windows) that serializes access to the shared database during pruning. The lock file is created alongside the database with a .hosted_rooms.lock suffix. Also adds a graceful fallback when neither locking mechanism is available (no-op lock that at least doesn't crash).
Sahilvishnaliya
force-pushed
the
fix/102120-hosted-room-worker-lock
branch
from
September 17, 2026 12:34
11d6a58 to
9b88865
Compare
This branch has not been deployed
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.
Fixes #102120
The hosted_room_worker starts on every profile gateway restart and calls
prune_disbanded_rooms() on the shared state.db. When multiple profiles
restart simultaneously (e.g. during 'hermes update' fleet restart), all
gateways hit the same SQLite database concurrently, causing corruption
('file is not a database').
This fix adds a cross-process advisory lock (fcntl on Unix, msvcrt on
Windows) that serializes access to the shared database during pruning.
The lock file is created alongside the database with a .hosted_rooms.lock
suffix.
Also adds a graceful fallback when neither locking mechanism is available
(no-op lock that at least doesn't crash).
Testing: All 44 hosted_rooms tests pass.