fix: serialize daemon startup on POSIX - #527
Open
tabtablabs-dev wants to merge 1 commit into
Open
tabtablabs-dev wants to merge 1 commit into
tabtablabs-dev wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/unit/test_admin.py">
<violation number="1" location="tests/unit/test_admin.py:46">
P2: The lock file created by `_daemon_startup_lock` lands in the real system runtime directory instead of `tmp_path`. If the runtime dir is unwritable (sandboxed CI, read-only home), the test fails with a permission error. The lock file also persists after the test and could pollute parallel test runs. Mock `pid_path` (or the whole `_daemon_startup_lock`) so the lock file is scoped to `tmp_path` alongside `log_path`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
|
||
| monkeypatch.setattr(admin, "daemon_alive", daemon_alive) | ||
| monkeypatch.setattr(admin.ipc, "connect", lambda *_args, **_kwargs: (FakeSocket(b'{"result":{}}\n'), None)) | ||
| monkeypatch.setattr(admin.ipc, "log_path", lambda _name: tmp_path / "daemon.log") |
Contributor
There was a problem hiding this comment.
P2: The lock file created by _daemon_startup_lock lands in the real system runtime directory instead of tmp_path. If the runtime dir is unwritable (sandboxed CI, read-only home), the test fails with a permission error. The lock file also persists after the test and could pollute parallel test runs. Mock pid_path (or the whole _daemon_startup_lock) so the lock file is scoped to tmp_path alongside log_path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/unit/test_admin.py, line 46:
<comment>The lock file created by `_daemon_startup_lock` lands in the real system runtime directory instead of `tmp_path`. If the runtime dir is unwritable (sandboxed CI, read-only home), the test fails with a permission error. The lock file also persists after the test and could pollute parallel test runs. Mock `pid_path` (or the whole `_daemon_startup_lock`) so the lock file is scoped to `tmp_path` alongside `log_path`.</comment>
<file context>
@@ -20,6 +23,35 @@ def close(self):
+
+ monkeypatch.setattr(admin, "daemon_alive", daemon_alive)
+ monkeypatch.setattr(admin.ipc, "connect", lambda *_args, **_kwargs: (FakeSocket(b'{"result":{}}\n'), None))
+ monkeypatch.setattr(admin.ipc, "log_path", lambda _name: tmp_path / "daemon.log")
+ monkeypatch.setattr("subprocess.Popen", FakeProcess)
+
</file context>
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.
Summary
ensure_daemon()by daemon name with a POSIXflockReproduction
On macOS, concurrent harness calls left 211
python -m browser_harness.daemonprocesses adopted by PID 1.ensure_daemon()checked daemon state before spawning without a cross-process startup lock, so several callers could observe the same missing endpoint and spawn together.The regression test fails on current
mainwith multiple spawns and passes with this change.Verification
uv run --with pytest pytest -qWindows behavior is unchanged.
Summary by cubic
Serialize daemon startup on POSIX to prevent duplicate spawns when multiple callers invoke
ensure_daemon(). Adds a per-daemon file lock and a regression test; Windows behavior is unchanged._daemon_startup_lockusing POSIXflockon a per-daemon.lockfile.ensure_daemonwith the lock and split out_ensure_daemon_unlocked.Written for commit 092f3d6. Summary will update on new commits.