Repository navigation
fix(claude): serialize herdr starts so one session gets one workspace - #1278
Merged
Merged
Conversation
Two runs starting the same herdr session at once could both find no workspace and make one each: two Claudes in one directory under one label, after which `herdr workspace focus` got two ids and every attach failed until a workspace was closed by hand. A run that restarted the server could also close the workspace another run had just made. herdr's start now runs from the server check to the pane under a flock on the box (where flock exists), released before attaching and not inherited by the server. A label already on two workspaces attaches to the first instead of failing. Claude-Session: https://claude.ai/code/session_01Ba6Vc66D5hH1xSTvJcCbVz
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1278 +/- ##
==========================================
+ Coverage 50.67% 50.68% +0.01%
==========================================
Files 83 83
Lines 9840 9843 +3
==========================================
+ Hits 4986 4989 +3
Misses 4854 4854 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 the third
cmd/mux.gobug from the review that went with #1275 (#1 and #2 were fixed in #1276).The bug
Two
onctl clauderuns starting the same herdr session at once both found no workspace, and each made one. That left:wsheld two ids, soherdr workspace focus "$ws"failed on every attach.running()still reported true, so retrying never got past it, and the only fix was closing a workspace by hand.A related race (review finding #4): one run's server restart could close the workspace another run had just made.
Fix
pane run, now runs underflockon/run/boxctl/herdr.lock, which serializes concurrent starts on a box. The lock fd is closed beforeexec herdr, so attaching doesn't hold it. The background server doesn't inherit it (9>&-).flockis missing, the script runs without the lock, as before. It is part of util-linux on Debian and Ubuntu, and busybox has it.Tests
TestHerdrStartConcurrent: two starts race against a slowed-down fake herdr, and exactly one workspace is made.flock.golang:1.26container: it passed 3 out of 3 runs, and with the lock removed it fails with "2 workspaces made for one session". CI runs on Ubuntu, so it runs there.TestHerdrStartDuplicateLabel: with a label already on two workspaces, the run focusesw1and makes no new workspace.workspace focusnow rejects unknown ids, as real herdr does. Without that, the test passed even with the fix removed.go test ./cmd/passes andgolangci-lintreports 0 issues.Not tested against a real herdr on a box.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ba6Vc66D5hH1xSTvJcCbVz