Skip to content

Updated Token Count - #60

Merged
nickbeau merged 1 commit into
mainfrom
feature/worktree-cleanup-token-reporting
Aug 24, 2026
Merged

nickbeau merged 1 commit into
mainfrom
feature/worktree-cleanup-token-reporting

Conversation

@nickbeau

Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to the reliability and safety of Git workspace preparation in Symphony by adding cross-process locking for shared Git clones and switching to private, non-pruning fetches for base branch snapshots. It also adds comprehensive tests for the new locking mechanism and refactors related code for clarity and correctness.

Concurrency and Safety Improvements:

  • Added a cross-process mutation lock using a <shared_clone_path>.lock file to serialize Git mutations across processes, preventing race conditions and .git/config lock contention during concurrent workspace preparations. (src/Symphony.Infrastructure.Workspaces/GitWorktreeWorkspaceManager.cs, docs/UserGuide.md) [1] [2]
  • Introduced the AcquireSharedCloneMutationLockAsync method to handle creation and acquisition of the lock file with metadata for debugging. (src/Symphony.Infrastructure.Workspaces/GitWorktreeWorkspaceManager.cs) [1] [2]

Git Fetch and Worktree Handling:

  • Changed base branch fetches to use a private refs/symphony/origin/<base_branch> snapshot instead of updating/pruning all remote refs, reducing side effects and improving reproducibility. (src/Symphony.Infrastructure.Workspaces/GitWorktreeWorkspaceManager.cs, docs/UserGuide.md) [1] [2] [3]
  • Updated worktree creation to use the new snapshot ref instead of origin/<base_branch>. (src/Symphony.Infrastructure.Workspaces/GitWorktreeWorkspaceManager.cs)

Testing:

  • Added an integration test to ensure that PrepareIssueWorkspaceAsync waits correctly for the shared clone mutation lock, verifying the new locking mechanism works as intended. (tests/Symphony.Integration.Tests/WorkspaceManagerTests.cs)

These changes collectively improve the robustness of workspace management, especially in environments with high concurrency.

Copilot AI lite review requested due to automatic review settings August 24, 2026 02:04
@nickbeau
nickbeau merged commit 244694b into main Aug 24, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Git workspace preparation reliability under concurrency by adding a cross-process mutation lock around shared-clone Git operations and by switching base-branch updates to a private snapshot ref (refs/symphony/origin/<base_branch>) rather than broad/pruning origin fetches.

Changes:

  • Added a cross-process shared-clone mutation lock using a <shared_clone_path>.lock file and lock metadata for debugging.
  • Updated base-branch fetching and worktree creation to use a private snapshot ref (refs/symphony/origin/<base_branch>).
  • Added an integration test intended to verify that workspace preparation waits for the mutation lock.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Symphony.Infrastructure.Workspaces/GitWorktreeWorkspaceManager.cs Adds cross-process file locking around shared-clone mutations and fetches base branch into a private snapshot ref for safer worktree creation.
tests/Symphony.Integration.Tests/WorkspaceManagerTests.cs Adds an integration test for the shared-clone mutation lock behavior.
docs/UserGuide.md Documents the new cross-process lock and private snapshot ref fetch behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +296 to +306
var stream = new FileStream(
lockPath,
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.None,
bufferSize: 1,
FileOptions.None);

WriteLockMetadata(stream, sharedClonePath);
return stream;
}
Comment on lines +122 to +123
var firstCompleted = await Task.WhenAny(prepareTask, Task.Delay(TimeSpan.FromMilliseconds(500), cts.Token));
Assert.NotSame(prepareTask, firstCompleted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants