Repository navigation
feat(worker): govern subprocesses across workers and gateways - #124
Merged
Merged
Conversation
nixuuu
force-pushed
the
feat/process-governor-1
branch
from
November 5, 2026 05:51
2327f15 to
ec3f7f3
Compare
nixuuu
marked this pull request as ready for review
November 5, 2026 05:57
nixuuu
added a commit
that referenced
this pull request
Nov 10, 2026
…#482) Cleanup previews could reuse Git output cached for one second by the process governor, showing a dirty checkout immediately after external changes were removed, or a clean checkout immediately after files were added. `ScanWorktrees` now uses the existing `freshGit` boundary while preserving process admission, background priority and removal safety checks. The automation test warms the scan, changes files outside Canopy, and asserts immediate dirty → clean → dirty → clean results before cleanup. The worktree documentation describes this freshness guarantee. The worktree fixture also waited only for `thread.status === idle`. `threadReady` can set that before the automation turn or its command has settled. It now waits for the worktree's actual busy state before deleting or archiving; preview assertions immediately after delete/settings changes remain direct assertions, without retries. A controlled delayed-ack run reproduced the original refusal with clean Git state, a cancelled turn and a pending `startTurn`. The original CI log reports only `wouldRemove`, so it cannot distinguish that refusal from stale scan state. The desktop/phone CI failure in run 42786085102, attempt 1, rejected a valid transient `syncing` update after both clients' items and turns already matched. The test now waits for completion of the specific reply turn and convergence after recovery, with 100 ms revision probes exercising resubscriptions. Local baseline runs exposed another fixture race: after the parent interruption, its queued question turn could start while `holdTurns` was still enabled and block the final reply forever. Releasing the hold before ending the parent, then observing the question turn complete, removes that race. A controlled run reproduced the stuck interaction turn and queued final message. No production subscription behavior changes. Validation: | Separate sequential file runs | Before | After | | --- | --- | --- | | `worktree-automation.test.ts` | 28 passed / 2 failed | 30 passed / 0 failed | | `thread-multiclient.test.ts` | 29 passed / 1 failed | 30 passed / 0 failed | Each file ran 30 times before and after, one file at a time. All 30 final phone runs exercised revision resubscription. The local baseline phone failure was the held-question timeout, distinct from CI's invalid no-syncing assertion. An intermediate readiness-only revision failed 8/8 worktree runs and exposed the cached Git result; those failures are excluded from the final counts. `bun install`, `bun run typecheck`, `bun run lint`, `bun run format:check`, and `git diff --check` passed. Verification was scoped to the requested integration files and static checks under the supplied execution limits; the full suite, generation check and web build were not run. Scratch logs and fault-injection diagnostics remain outside the repository and are not committed. No schema, proto, UI copy or UI test changes; copy audit is not applicable. Fixes: #124 Related: #473, #478
This was referenced Nov 13, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 18, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 18, 2026
## What changed - Report Git timeouts, output-limit failures and nonzero checkout exits separately. Keep raw command output out of the new checkout errors and map worker and link failures to fixed messages in `spawn_thread`. - Mark the new branch and the temporary Git worktree lock with the same attempt ID. After a failed checkout, remove only a matching worktree and the unchanged, unused branch created by this attempt. Preserve the original failure and report when cleanup is incomplete. - Verify that rollback waits for the process to close and for the attempt to stop its descendants to finish. Keep the 60 s checkout and 90 s gateway budgets. A gateway deadline or disconnect can still leave the outcome unconfirmed, so the agent prompts the caller to check before retrying. The report involved a Windows 11 checkout of about 58,000 tracked files with CRLF conversion and Git LFS. Both reported nightly.70 and the edited report's nightly.74 already include the 60 s checkout limit. The original error alone cannot distinguish elapsed time from excess output. The fixtures reproduce those failure paths with real Git on Linux. The original Windows checkout and its initiating cause remain unverified. A longer checkout budget would need corresponding worker, gateway and client deadline changes based on that evidence. ## Verification - Verified PR head `dc73d853` on `nix-pc` (Linux, Bun 1.4.4, Git 2.56.0). Ran `check:tmp` on the worker worktree tests and five integration files covering worktrees, creation progress, creation failures, automation and the process governor. Also ran the worker's device preview key tests. In all, 51 passed, zero failed, and no temporary test files were left. - The tests exercise a checkout filter that times out before completing, a hook that exceeds output capture, a hook that exits nonzero, a successful retry with the same branch name, a ref modified during checkout, preservation of pre-existing worktrees and refs, both gRPC callers, and an older worker that reports the two limits under one code. - A generated 58,000-file CRLF checkout completed and unlocked in 2.14 s on Linux. The fixture used small files and had no LFS filters. - The prior CI run failed in [Tests (6/8)](https://github.com/itsoltech/canopy/actions/runs/44361247730/job/135003276782) because device preview depended on the shared process error text. The runner now preserves that text and exposes the precise reason to Git. The existing device preview assertions passed locally. - Affected worker, gateway and process-governor typechecks, edited-file lint and formatting, and `git diff --check` passed. Full verification runs in CI. - Copy audit (§8). The ambiguous limit message now identifies time or output, checkout failure names Git settings and filters, and an incomplete rollback tells the user what to check. New messages use static sentence-case text without dynamic paths or names. The creation step and retry were tested through the UI's gRPC API. No browser or Windows runtime verification. Fixes: #74 Fixes: #90 Fixes: #124
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.
Stage 1 of 2. Every subprocess Canopy starts (git, agent CLI probes, utilities) now goes through the shared
@canopy/process-governorpackage. That stops subprocess storms, for example a full worktree scan running hundreds of git processes at once.--versionchecks are now async and run once per CLI, cached for 60 s, instead of blocking the event loop.docs/process-governor.md; Canopy stays on the git CLI for now.tests/integration/process-governor.test.tsruns 100 status reads over 30 real worktrees. It checks that at most 4 processes run at once and only 30 start in total.