You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// preserve-branch-name asked us to keep the exact branch name, but
478
+
// recreate-ref is not enabled, so we cannot silently destroy the
479
+
// existing remote ref. Surface an error so the caller falls back to the
480
+
// configured fallback (e.g. opening an issue).
481
+
thrownewError(
482
+
`Remote branch "${branchName}" already exists and preserve-branch-name is enabled. `+`Set recreate-ref: true to force-delete and recreate the remote ref, or disable `+`preserve-branch-name to allow renaming the branch.`
483
+
);
484
+
}
485
+
// Reuse the existing branch by deleting the remote ref so the subsequent
486
+
// push recreates it from the local HEAD (force-push semantics). This is the
487
+
// intended behavior when recreate-ref is enabled for long-lived
488
+
// reusable branches whose previous PR was merged.
489
+
if(!githubClient||!owner||!repo){
490
+
thrownewError(
491
+
`Remote branch "${branchName}" already exists and recreate-ref is enabled, `+
492
+
`but no GitHub client was provided to delete the existing remote ref. This is an `+
493
+
`internal error: the caller must pass githubClient, owner, and repo to reuse the branch.`
preserve-branch-name: true # omit random salt suffix from branch name (default: false)
51
+
recreate-ref: true # force-delete and recreate the remote branch when it already exists (requires preserve-branch-name; default: false)
51
52
excluded-files: # files to omit from the patch entirely
52
53
- "**/*.lock"
53
54
- "dist/**"
@@ -84,7 +85,7 @@ The `excluded-files` field accepts a list of glob patterns. Each matching file i
84
85
85
86
The `preserve-branch-name` field, when set to `true`, omits the random hex salt suffix that is normally appended to the agent-specified branch name. This is useful when the target repository enforces branch naming conventions such as Jira keys in uppercase (e.g., `bugfix/BR-329-red` instead of `bugfix/br-329-red-cde2a954`). Invalid characters are always replaced for security, and casing is always preserved regardless of this setting. Defaults to `false`.
86
87
87
-
When `preserve-branch-name: true` and the agent-supplied branch name already exists on the remote, the workflow fails with an explicit error rather than silently appending a random suffix. To resolve, delete the existing remote branch, choose a different branch name, or disable `preserve-branch-name` to allow collision-avoidance via a random suffix.
88
+
When `preserve-branch-name: true` and the agent-supplied branch name already exists on the remote, the default behavior is to fall back (e.g. open an issue when `fallback-as-issue: true`) rather than rename the branch or overwrite the remote ref. To enable reuse of the existing remote branch, set `recreate-ref: true`: the handler will force-delete the stale remote ref and recreate it from the agent's local HEAD (force-push semantics). This is the intended behavior for long-lived reusable branches whose previous PR was merged. `recreate-ref` requires `preserve-branch-name: true` to take effect; the handler does not silently rename the branch in this case.
88
89
89
90
The `draft` field is a **configuration policy**, not a default. Whatever value is set in the workflow frontmatter is always used — the agent cannot override it at runtime.
preserve-branch-name: false # Keep agent branch name verbatim (no random salt suffix)
1583
+
recreate-ref: false # When preserve-branch-name and remote branch exists, force-delete and recreate the remote ref
1582
1584
```
1583
1585
1584
1586
**Asset Upload Extensions**:
@@ -2179,6 +2181,14 @@ safe-outputs:
2179
2181
3. **Draft Status**: Creates as draft by default for safety.
2180
2182
4. **Auto-Commit**: When `commit-changes: true`, commits workspace changes before PR creation.
2181
2183
5. **Reviewer Assignment**: Auto-requests reviewers if configured.
2184
+
6. **Branch Name Normalization**: The agent-supplied branch name is sanitized (invalid characters replaced; casing preserved). When `preserve-branch-name: false` (default), a random hex salt suffix is appended to ensure uniqueness across runs. When `preserve-branch-name: true`, the salt suffix is omitted so the branch name appears verbatim (useful for repository naming conventions, e.g. `bugfix/BR-329-red`).
2185
+
7. **Remote Branch Collision Handling**: When the resolved branch name already exists on the remote, behavior depends on the configuration:
2186
+
2187
+
| `preserve-branch-name` | `recreate-ref` | Behavior on collision |
2188
+
|---|---|---|
2189
+
| `false` (default) | n/a | Append random hex suffix to local branch name and continue |
2190
+
| `true` | `false` (default) | Surface `push_failed`; caller falls back (e.g. opens an issue when `fallback-as-issue: true`) |
2191
+
| `true` | `true` | Force-delete the existing remote ref via `DELETE /repos/{owner}/{repo}/git/refs/heads/{branch}` and let the subsequent push recreate it from the agent's local HEAD (force-push semantics). Concurrent-deletion 422 responses with "Reference does not exist" are treated as success. |
2182
2192
2183
2193
**Configuration Parameters**:
2184
2194
@@ -2191,6 +2201,8 @@ safe-outputs:
2191
2201
- `labels`: Auto-apply labels
2192
2202
- `title-prefix`: Prepend to titles
2193
2203
- `footer`: Footer override
2204
+
- `preserve-branch-name`: When `true`, use the agent-supplied branch name verbatim without appending a random salt suffix (default: `false`)
2205
+
- `recreate-ref`: When `true` (and `preserve-branch-name: true`), allows the handler to force-delete an existing remote branch ref and recreate it from the agent's local HEAD on collision. When `false` (default), an existing remote branch under `preserve-branch-name: true` causes a fallback rather than overwriting the remote ref. Has no effect when `preserve-branch-name: false`. (default: `false`)
Copy file name to clipboardExpand all lines: pkg/parser/schemas/main_workflow_schema.json
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5950,6 +5950,11 @@
5950
5950
"description": "When true, the random salt suffix is not appended to the agent-specified branch name. Invalid characters are still replaced for security, and casing is always preserved regardless of this setting. Useful when the target repository enforces branch naming conventions (e.g. Jira keys in uppercase such as 'bugfix/BR-329-red'). Defaults to false.",
5951
5951
"default": false
5952
5952
},
5953
+
"recreate-ref": {
5954
+
"type": "boolean",
5955
+
"description": "When true (and preserve-branch-name is true), allows the handler to force-delete an existing remote branch ref and recreate it from the agent's local HEAD. When false (default), if the agent-specified branch already exists on the remote with preserve-branch-name enabled, the handler falls back (e.g. opens an issue) rather than overwriting the remote ref. Useful for long-lived reusable branches whose previous PR was merged.",
0 commit comments