propose_code_change: take the diff from the swarm's worktree capture, refuse incomplete runs - #5308
Merged
Merged
Conversation
… refuse incomplete runs Preview runs were coming back with narration instead of a diff while the edit had landed in the swarm's worktree (stakwork/stakgraph#1692 has the root cause: a gateway tool-version rewrite made the AI SDK's tool loop exit silently, and the swarm reported success). The swarm now reads the diff from the ephemeral worktree itself and returns it as `diff`, with `diff_error` when it looked and found a reason there is none, and `incomplete` when the run never reached a proper termination. - Prefer the swarm's `diff` over anything in the model's text. It is ground truth and includes new files; the model's pasted diff was a transcription that `git diff HEAD` would have left new files out of. - Refuse `incomplete` runs outright: the text is narration and the worktree may hold a half-applied change, so no proposal card. - Believe `diff_error` (no_changes, change_too_large, secrets_detected) over a diff the model pasted, with a specific message for each. - Keep the regex-on-text extraction as the fallback for swarms that predate the capture, and make that fallback stage first (`git add -A && git diff --cached`) so it too includes new files. - Surface the swarm's error text when the run fails instead of a generic "timed out or returned an error". Tests cover each source and refusal, the error passthrough, and the prompt change. Backward compatible with older swarms.
The swarm reports the ephemeral worktree diff as one `preview` field with the create_pr result's ok / failure / error shape, instead of three top-level fields.
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.
Problem
propose_code_changepreview runs were coming back with the model's narration as the answer and no diff, while the edit had actually landed in the swarm's worktree. Root cause and swarm-side fix are in stakwork/stakgraph#1692: a gateway tool-version rewrite made the AI SDK's tool loop exit silently on the edit step, and the swarm reported success.The swarm now reads the diff from the ephemeral worktree itself and reports it on the terminal result as
preview, the counterpart ofpron create_pr runs, with the same shape:{ ok: true, diff, filesChanged }or{ ok: false, failure, error }. It also setsincomplete: { reason }when the run never reached a proper termination. This PR consumes both.Changes (
src/lib/ai/codeChangeTools.ts)preview.diffover anything in the model's text. It is ground truth and includes new files; the model's pasted diff was a transcription, andgit diff HEADwould have left new files out of it.incompleteruns with a clear message. The text is narration and the worktree may hold a half-applied change, so no proposal card.preview(no_changes,change_too_large,secrets_detected, otherwise generic) over a diff the model pasted.git add -A && git diff --cachedso that path includes new files too.Testing
codeChangeTools.test.ts: 15 passed (7 new cases: worktree diff preferred, text fallback, incomplete refused, no_changes believed over pasted diff, secrets mapping, error passthrough, prompt stages before diffing)eslintandprettier --checkclean on touched filesNotes