Fix terminal worktree cleanup and token reporting#58
Merged
Conversation
Persist terminal stop intent before canceling live runs, clean retry worktrees when tracked issues close, avoid counting generic usage maps as absolute token totals, and reduce shared clone git config writes during worktree creation.
There was a problem hiding this comment.
Pull request overview
This PR tightens Symphony’s v1 orchestrator behavior around terminal workspace cleanup, absolute-only token usage accounting, and safer/more reliable Git worktree preparation under concurrent dispatch.
Changes:
- Persist terminal stop intent before canceling live runs; extend terminal cleanup to tracked retrying issues (including releasing retry/claim state and recording cleanup metadata).
- Token accounting now ignores generic per-event
usagemaps except for explicit absolute token-usage update events, and resets “last reported” totals when a retry starts a fresh attempt. - Git worktree creation now uses upstream-free branches (
--no-track) and serializes shared-clone Git mutations to reduce.git/configcontention.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Symphony.Integration.Tests/WorkspaceManagerTests.cs | Adds coverage ensuring worktree branches don’t configure upstream tracking; updates git helper to assert nonzero exit codes. |
| tests/Symphony.Integration.Tests/OrchestrationTickServiceTests.cs | Adds integration tests for persisting terminal stop state pre-cancel, retry workspace cleanup on terminal transition, and token “last reported” reset on retry attempt restart. |
| tests/Symphony.Integration.Tests/CodexAgentRunnerTests.cs | Adds tests verifying generic usage is ignored on ordinary events but accepted for absolute token usage update events. |
| src/Symphony.Infrastructure.Workspaces/GitWorktreeWorkspaceManager.cs | Adds per-shared-clone locking; switches new worktree branch creation to --no-track; avoids redundant remote set-url calls; improves process output flushing. |
| src/Symphony.Infrastructure.Agent.Codex/CodexAgentRunner.cs | Restricts usage parsing to absolute token usage update contexts; continues accepting known absolute total token payload shapes. |
| src/Symphony.Host/Services/OrchestrationTickService.cs | Passes instanceId into tracked-issue state refresh to support terminal retry cleanup/claim release. |
| src/Symphony.Host/Services/OrchestrationTickService.Reconciliation.cs | Persists stop intent before attempting to stop live execution, enabling runners to observe terminal stop semantics reliably. |
| src/Symphony.Host/Services/OrchestrationTickService.Persistence.cs | Adds tracked terminal cleanup for retrying issues during cache refresh; releases retry queue/claim state; records cleanup metadata. |
| src/Symphony.Host/Services/OrchestrationTickService.Dispatch.cs | Resets SessionId and last-reported token totals when re-dispatching a retrying run as a fresh attempt. |
| docs/UserGuide.md | Documents absolute-only token accounting and terminal cleanup behavior for retrying issues; notes upstream-free worktree branches and serialized Git mutations. |
| README.md | Updates high-level runtime behavior summary for retrying terminal cleanup and absolute-only token totals. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Spec References
SPEC.mdSection 8.5: terminal tracker state stops running workers and cleans the workspace.SPEC.mdSection 8.6: startup and terminal workspace cleanup semantics.SPEC.mdSection 13.5: token accounting must prefer absolute totals, ignore delta/generic payloads, and track deltas from last reported totals.SPEC.mdSection 15.1/15.2: workspace containment and subprocess safety remain mandatory.SPEC.mdSection 17.2, 17.4, 17.5, and 17.6: conformance coverage for workspace cleanup, reconciliation, protocol usage extraction, and token/rate-limit observability.Summary
This change tightens terminal cleanup, token accounting, and Git worktree preparation reliability for Symphony's v1 orchestrator.
Terminal Worktree Cleanup
RunStopReasons.Terminaland theCleanupWorkspaceOnStopflag.Closed.Token Reporting
usagemaps as cumulative token totals.thread/tokenUsage/updated,total_token_usage,totalTokenUsage,token_usage, andtokenUsage.usagemap when the event itself is an absolute token usage update.LastReported*Tokenswhen a retry run starts a fresh agent attempt so new absolute session totals are counted correctly without losing the aggregate run totals.Git Worktree Config Lock Fix
git worktree add --no-track -b ...so Git does not attempt to write upstream branch configuration..git/configand worktree metadata contention when multiple issues dispatch concurrently.git remote set-url origin ...calls when the shared clone already points at the configured remote.Documentation
README.mdto describe retrying terminal workspace cleanup and absolute-only token totals.docs/UserGuide.mdto document terminal retry cleanup, token accounting behavior, and upstream-free worktree branch creation.Tests
dotnet test tests/Symphony.Integration.Tests/Symphony.Integration.Tests.csproj --filter "WorkspaceManagerTests|OrchestrationTickServiceTests|CodexAgentRunnerTests"dotnet testFull suite result: 13 core tests passed, 119 integration tests passed, 1 real GitHub integration test skipped because it is gated by opt-in credentials.
Notes
.claude/directory was intentionally not staged.