Skip to content

feat: add CODE_AUTO_MERGE env var to post-code script - #491

Open
maruiz93 wants to merge 7 commits into
fullsend-ai:mainfrom
maruiz93:auto-merge-env-var
Open

feat: add CODE_AUTO_MERGE env var to post-code script#491
maruiz93 wants to merge 7 commits into
fullsend-ai:mainfrom
maruiz93:auto-merge-env-var

Conversation

@maruiz93

@maruiz93 maruiz93 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD environment variables to the code agent post-code script
  • When CODE_AUTO_MERGE=true, enables GitHub auto-merge on newly created and existing PRs
  • Merge method is resolved via CODE_AUTO_MERGE_METHOD (squash/rebase/merge), or auto-detected from the repo's allowed merge methods when unset (prefers squash)
  • Safety guards:
    • Only arms auto-merge when PR is in BLOCKED state (requires branch protection with required reviews or status checks) — prevents immediate merge on unprotected repos
    • Detects merge queues and omits the method flag so gh can negotiate with the queue
    • Skips re-arming on existing PRs where auto-merge is already enabled
    • Warns on unknown CODE_AUTO_MERGE_METHOD values instead of silent coercion
  • Best-effort: failure to enable auto-merge emits a warning, not a blocking error
  • Env vars are read directly from the runner environment (not declared in runner_env) to avoid harness validation failures on deployments that don't define these optional vars

The fullsend CLI will populate this from config.Defaults.AutoMerge in a follow-up change. Until then, orgs can set the env vars manually in their GHA workflow files.

Test plan

  • 5 decide_auto_merge test cases (true, empty, false, TRUE, 1)
  • 5 resolve_merge_method_flag test cases (squash, merge, rebase, default, unknown with warning)
  • Bundled-script grep check for CODE_AUTO_MERGE
  • Full test suite passes (make test — 93 post-code tests + all others)
  • Manual verification: set CODE_AUTO_MERGE=true on a repo with branch protection and confirm gh pr merge --auto is called
  • Manual verification: confirm auto-merge is skipped with a warning on a repo without branch protection

🤖 Generated with Claude Code

@maruiz93
maruiz93 requested a review from a team as a code owner July 28, 2026 10:24
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 28, 2026

Copy link
Copy Markdown

🤖 Review · ⚠️ Cancelled · Started 10:26 AM UTC · Ended 10:41 AM UTC
Commit: 4c88885 · View workflow run →

@maruiz93
maruiz93 force-pushed the auto-merge-env-var branch from 4c88885 to 2e267a9 Compare July 28, 2026 10:40
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 28, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:42 AM UTC · Completed 10:58 AM UTC
Commit: 2e267a9 · View workflow run →

@qodo-code-review

Copy link
Copy Markdown

Qodo is busy working

Check back in a few minutes. Qodo's code review agents are on it.

Grey Divider

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add CODE_AUTO_MERGE env var to enable GitHub auto-merge in post-code

✨ Enhancement 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Plumb CODE_AUTO_MERGE through the code harness runner environment.
• When true, enable GitHub auto-merge for newly created and existing PRs.
• Add shell tests to lock in auto-merge decision behavior and bundling.
Diagram

graph TD
A["GHA workflow env"] --> B["harness/code.yaml"] --> C["post-code scripts"] --> D{"CODE_AUTO_MERGE=true?"} --> E["gh pr merge --auto"] --> F["GitHub PR"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Treat common truthy values as enabled
  • ➕ More ergonomic for users (e.g., TRUE/1/yes)
  • ➕ Reduces misconfiguration risk across varied workflow styles
  • ➖ Slightly more ambiguous behavior; needs documented precedence
  • ➖ Adds parsing logic that must be maintained/tested
2. Use GitHub API directly instead of gh CLI
  • ➕ Avoids dependency on gh CLI behavior/version differences
  • ➕ More explicit control over payloads and error reporting
  • ➖ More complex implementation (auth, endpoints, preview headers)
  • ➖ Potentially harder to debug locally compared to gh commands
3. Gate auto-merge behind explicit “new PR only” vs “existing PR too” flags
  • ➕ Prevents surprise behavior when re-running on an existing PR
  • ➕ Offers finer-grained control for different workflows
  • ➖ Adds configuration surface area
  • ➖ May be unnecessary for most users; current behavior is simpler

Recommendation: The current approach (single env var, best-effort gh pr merge --auto, no merge-method flag) is a good default because it respects repo branch protection and configured merge strategy. Consider optionally expanding truthy parsing if user misconfigs are expected; otherwise keeping the exact "true" match is predictable and easy to document.

Files changed (4) +113 / -0

Enhancement (2) +48 / -0
post-code.shOptionally enable auto-merge for new and existing PRs +24/-0

Optionally enable auto-merge for new and existing PRs

• Documents CODE_AUTO_MERGE and conditionally runs gh pr merge --auto when the env var is exactly "true". Applies the behavior both after PR creation and when updating an already-existing PR, emitting warnings on failure instead of failing the pipeline.

scripts/post-code.sh

post-code.src.shMirror auto-merge support in source post-code script +24/-0

Mirror auto-merge support in source post-code script

• Keeps the source version of the post-code script in sync by documenting CODE_AUTO_MERGE and adding the same best-effort gh pr merge --auto calls for existing and newly created PRs.

scripts/post-code.src.sh

Tests (1) +64 / -0
post-code-test.shAdd CODE_AUTO_MERGE bundling check and decision tests +64/-0

Add CODE_AUTO_MERGE bundling check and decision tests

• Adds a grep-based assertion that the bundled post-code script contains CODE_AUTO_MERGE handling. Introduces decide_auto_merge helper and five test cases to ensure only the exact value "true" enables auto-merge.

scripts/post-code-test.sh

Other (1) +1 / -0
code.yamlPass CODE_AUTO_MERGE through forge.github runner_env +1/-0

Pass CODE_AUTO_MERGE through forge.github runner_env

• Adds CODE_AUTO_MERGE to the GitHub forge runner environment so it is available to the runner-side post-code script. This keeps the variable out of the sandbox while enabling post-script behavior.

harness/code.yaml

@fullsend-ai-review

fullsend-ai-review Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review

Findings

High

  • [protected-path] scripts/post-code-test.sh, scripts/post-code.sh, scripts/post-code.src.sh — Three changed files are under the protected scripts/ path. The PR has no linked issue providing justification for modifying infrastructure files. Human approval is always required for protected-path changes.
    Remediation: Link a tracking issue that documents the authorization for these changes, or obtain explicit human approval.

Medium

  • [logic-error] scripts/post-code.src.sh — When a merge queue is detected on the target branch, the code omits the method flag but still proceeds to call gh pr merge --auto. According to the project's merge-queue skill documentation (skills/merge-queue/SKILL.md), gh pr merge --auto does not work with merge queues — the call will always fail for merge-queue-enabled branches, emitting a misleading "Failed to enable auto-merge" warning instead of a clear diagnostic.
    Remediation: When mq_id is non-empty, return 0 early after logging a message directing users to the merge-queue skill's await-and-enqueue.sh, instead of proceeding to the gh pr merge --auto call.

Low

  • [permission-expansion] scripts/post-code.src.sh — New CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD env vars expand the post-code script's capability to enable auto-merge on agent PRs. Opt-in (disabled by default), strict = "true" comparison (fail-closed), BLOCKED-state guard, and GitHub auto-merge respects branch protection rules. All variables interpolated into GHA workflow commands are sanitized.

  • [fail-open] scripts/post-code.src.sh — Auto-merge failure is caught as a GHA warning and the script continues normally. This is intentional best-effort design.

  • [incomplete-feature] docs/code.md — PR body states the fullsend CLI will populate CODE_AUTO_MERGE from config.Defaults.AutoMerge in a follow-up change (phase 1 of a multi-part feature). The environment variables are documented and implemented, but there is no user-facing mechanism to set them without manual environment variable injection.

  • [test-model-inaccuracy] scripts/post-code-test.sh — The resolve_merge_method_flag test helper maps the empty string to --merge via a merge|"" case arm, but in the production code the auto-detect logic always sets method to a non-empty value before the case statement is reached. The merge-method-default test case (empty input → --merge) tests a code path that is unreachable in production.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run

Review

Findings

High

  • [protected-path] scripts/post-code-test.sh, scripts/post-code.sh, scripts/post-code.src.sh — Three changed files are under the protected scripts/ path. The PR has no linked issue providing justification for modifying infrastructure files. Human approval is always required for protected-path changes.
    Remediation: Link a tracking issue that documents the authorization for these changes, or obtain explicit human approval.

Medium

  • [logic-error] scripts/post-code.src.sh — When a merge queue is detected on the target branch, the code omits the method flag but still proceeds to call gh pr merge --auto. According to the project's merge-queue skill documentation, gh pr merge --auto does not work with merge queues. The call will always fail for merge-queue-enabled branches, emitting a misleading warning rather than proactively skipping.
    Remediation: When mq_id is non-empty, return 0 early instead of proceeding to the gh pr merge --auto call. Log a message directing users to the merge-queue skill's await-and-enqueue.sh.

Low

  • [missing-authorization] scripts/post-code.src.sh — Non-trivial feature addition (~270 lines) without a linked issue.

  • [permission-expansion] scripts/post-code.src.sh — New CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD env vars expand the post-code script's capability to enable auto-merge on agent PRs. Opt-in (disabled by default), strict = "true" comparison (fail-closed), BLOCKED-state guard, and GitHub auto-merge respects branch protection rules.

  • [fail-open] scripts/post-code.src.sh — Auto-merge failure is caught as a GHA warning and the script continues normally. This is intentional best-effort design.

  • [test-inadequate] scripts/post-code-test.sh — The resolve_merge_method_flag test helper tests only the case-statement mapping, not the auto-detect priority order (squash > merge > rebase). The more complex and error-prone logic path has no test coverage.

  • [incomplete-feature] docs/code.md — PR body states the fullsend CLI will populate CODE_AUTO_MERGE from config.Defaults.AutoMerge in a follow-up change (phase 1 of a multi-part feature).


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (2)

Review

Findings

High

  • [protected-path] harness/code.yaml, scripts/post-code-test.sh, scripts/post-code.sh, scripts/post-code.src.sh — All changed files except docs/code.md are under protected paths (harness/, scripts/). The PR has no linked issue providing justification for modifying governance and infrastructure files. Human approval is always required for protected-path changes.
    Remediation: Link a tracking issue that documents the authorization for these changes, or obtain explicit human approval.

Low

  • [permission-expansion] harness/code.yaml:65 — New CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD env vars expand the post-code script's capability to enable auto-merge on agent PRs. Opt-in (disabled by default), strict = "true" comparison (fail-closed), and GitHub auto-merge respects branch protection rules.

  • [fail-open] scripts/post-code.src.sh:528 — Auto-merge failure is caught as a GHA warning and the script continues normally. This is intentional best-effort design. Same pattern applies to the new-PR path (section 9).

  • [architectural-conflict] scripts/post-code.src.sh:528 — gh pr merge --auto is incompatible with GitHub merge queues. The docs note the incompatibility, and the failure is handled gracefully (GHA warning, non-blocking). Consider adding a cross-reference to the merge-queue skill's await-and-enqueue.sh for merge-queue-enabled repos.

  • [incomplete-feature] — PR body states the fullsend CLI will populate CODE_AUTO_MERGE from config.Defaults.AutoMerge in a follow-up change (phase 1 of a multi-part feature).

  • [stale-post-script-description] docs/code.md:52 — The post-script description enumerates steps but does not mention the new optional auto-merge step. The Variables table documents the new vars, but the prose description is now incomplete.

  • [missing-configuration-guidance] docs/code.md:45 — The Variables table documents CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD but omits configuration instructions. The existing CODE_ALLOWED_TARGET_BRANCHES row includes provenance guidance ("Set via runner_env in harness/code.yaml").


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (3)

Review

Findings

High

  • [protected-path] harness/code.yaml, scripts/post-code-test.sh, scripts/post-code.sh, scripts/post-code.src.sh — All changed files except docs/code.md are under protected paths (harness/, scripts/). The PR has no linked issue providing justification for modifying governance and infrastructure files. Human approval is always required for protected-path changes.
    Remediation: Link a tracking issue that documents the authorization for these changes, or obtain explicit human approval.

Medium

  • [architectural-conflict] scripts/post-code.src.sh — The CODE_AUTO_MERGE feature uses gh pr merge --auto, which is incompatible with GitHub merge queues. The merge-queue skill (skills/merge-queue/SKILL.md) explicitly states this API does not work with merge queues. While the docs note the incompatibility and failures are handled gracefully (GHA warning, non-blocking), repos with merge queues enabled will see the feature silently fail to achieve its goal. No guidance is provided on using the merge-queue skill's await-and-enqueue.sh as an alternative.
    Remediation: Either detect merge queue configuration and skip auto-merge with a clear warning directing users to the merge-queue skill, or document the limitation more prominently with a pointer to the alternative approach.

  • [missing-authorization] — PR introduces ~200 lines of new functionality across protected paths without a linked issue. The PR body describes this as "phase 1 of a multi-part feature" but provides no issue reference establishing authorization or documenting the phased design. Non-trivial features benefit from a tracking issue to establish scope, success criteria, and phase boundaries.
    Remediation: Create a tracking issue documenting the CODE_AUTO_MERGE feature's purpose, phased rollout plan, and success criteria. Link it to this PR.

Low

  • [missing-configuration-guidance] docs/code.md — The Variables table documents CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD but omits configuration instructions. Other agent docs (e.g., docs/review.md) include guidance like "Set this in the CI workflow env: block."

  • [permission-expansion] harness/code.yaml:65 — New CODE_AUTO_MERGE and CODE_AUTO_MERGE_METHOD env vars expand the post-code script's capability to enable auto-merge on agent PRs. Opt-in (disabled by default), strict = "true" comparison (fail-closed), and GitHub auto-merge respects branch protection rules.

  • [fail-open] scripts/post-code.src.sh:528 — Auto-merge failure is caught as a GHA warning and the script continues normally. This is intentional best-effort design.

  • [incomplete-feature] — PR body states the fullsend CLI will populate CODE_AUTO_MERGE from config.Defaults.AutoMerge in a follow-up change (phase 1 of a multi-part feature).


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (4)

Review

Findings

High

  • [protected-path] harness/code.yaml, scripts/post-code-test.sh, scripts/post-code.sh, scripts/post-code.src.sh — All changed files except docs/code.md are under protected paths (harness/, scripts/). The PR has no linked issue providing justification for modifying governance and infrastructure files. Human approval is always required for protected-path changes.
    Remediation: Link a tracking issue that documents the authorization for these changes, or obtain explicit human approval.

Medium

  • [api-contract] scripts/post-code.src.sh:479gh pr merge --auto is invoked without a merge method flag (--merge, --squash, or --rebase). The underlying GraphQL enablePullRequestAutoMerge mutation defaults to MERGE (merge commit). For repos that have disabled merge commits (allowing only squash or rebase), this will fail with GraphQL: Merge method merge commits are not allowed on this repository. The failure is caught by the warning handler so the pipeline won't crash, but the auto-merge feature will silently fail for such repos. Same issue in generated scripts/post-code.sh.
    Remediation: Accept a CODE_AUTO_MERGE_METHOD env var (defaulting to e.g. --squash) and pass it to the command, or query the repo's allowed merge methods via gh api.

  • [documentation-accuracy] docs/code.md:42 — The CODE_AUTO_MERGE variable description states "Uses the repo's configured merge strategy." This is inaccurate — gh pr merge --auto without an explicit merge method flag defaults to merge commit, not the repo's configured strategy. The same misleading claim appears in the header comments of post-code.src.sh and post-code.sh.
    Remediation: Either fix the implementation to detect the repo's allowed merge methods, or update the documentation and header comments to remove the misleading claim.

Low

  • [architectural-coherence] docs/code.md:44 — The CODE_AUTO_MERGE documentation does not mention its incompatibility with GitHub merge queues. When merge queues are enabled, gh pr merge --auto will fail (caught as a warning, non-blocking).

  • [test-inadequate] scripts/post-code-test.sh:1064 — The decide_auto_merge test helper verifies the boolean gating logic but does not exercise the actual gh pr merge --auto command or the missing merge method flag.

  • [permission-expansion] harness/code.yaml:66 — New CODE_AUTO_MERGE env var expands the post-code script's capability to enable auto-merge on agent PRs. Opt-in (disabled by default), strict = "true" comparison (fail-closed), and GitHub auto-merge respects branch protection rules.

  • [fail-open] scripts/post-code.src.sh:476 — Auto-merge failure is caught as a GHA warning and script continues normally. This is the intentional best-effort design.

  • [incomplete-feature] — PR body states the fullsend CLI will populate CODE_AUTO_MERGE from config.Defaults.AutoMerge in a follow-up change (phase 1 of a multi-part feature).


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (5)

Review

Findings

High

  • [protected-path] harness/code.yaml, scripts/post-code-test.sh, scripts/post-code.sh, scripts/post-code.src.sh — All changed files are under protected paths (harness/, scripts/). The PR has no linked issue providing justification for modifying governance and infrastructure files. Human approval is always required for protected-path changes.
    Remediation: Link a tracking issue that documents the authorization for these changes, or obtain explicit human approval.

  • [missing-doc] docs/code.md:40 — The Variables section states "None" but the PR introduces a new CODE_AUTO_MERGE environment variable that controls whether PRs are automatically merged. The documentation actively contradicts the new feature.
    Remediation: Replace "None." with a table documenting CODE_AUTO_MERGE: description, default (disabled), and valid values ("true" to enable).

Medium

  • [api-contract] scripts/post-code.src.sh:479gh pr merge --auto is invoked without a merge method flag (--merge, --squash, or --rebase). In non-interactive CI environments, gh requires an explicit merge method when multiple methods are enabled on the repo. The PR description claims "Uses the repo's configured merge strategy" but gh pr merge --auto does not auto-select from repo settings. The failure is caught by the warning handler, so the pipeline won't crash, but the auto-merge feature will silently fail for repos with multiple or restricted merge methods. Same issue in generated scripts/post-code.sh:1109.
    Remediation: Accept a CODE_AUTO_MERGE_METHOD env var (defaulting to e.g. --squash) and pass it to the command, or query the repo's allowed merge methods via gh api.

  • [architectural-coherence] scripts/post-code.src.sh — The merge-queue skill documents that gh pr merge --auto does not work with merge queues. When merge queues are enabled on the target branch, this command will fail (caught by the warning handler, so non-blocking).
    Remediation: Add a note in the code comment or documentation that CODE_AUTO_MERGE is incompatible with merge queues and will be a no-op in that configuration.

  • [incomplete-doc] docs/code.md:50 — The post-script description lists "protected path checks, secret scanning, pre-commit checks, pushes the branch, creates the PR, and best-effort assigns the PR" but does not mention the optional auto-merge functionality.
    Remediation: Update to include auto-merge as an optional step.

Low

  • [test-inadequate] scripts/post-code-test.sh:1064 — The decide_auto_merge test helper verifies the boolean gating logic but does not exercise the actual gh pr merge --auto command or the missing merge method flag.

  • [permission-expansion] harness/code.yaml:66 — New CODE_AUTO_MERGE env var expands the post-code script's capability to enable auto-merge on agent PRs. Opt-in (disabled by default), strict = "true" comparison, and GitHub auto-merge respects branch protection rules (required reviews, status checks).

  • [fail-open] scripts/post-code.src.sh:476 — Auto-merge failure is caught as a GHA warning and script continues normally. This is the intentional best-effort design.

  • [incomplete-feature] — PR body states the fullsend CLI will populate CODE_AUTO_MERGE from config.Defaults.AutoMerge in a follow-up change (phase 1 of a multi-part feature).


Labels: PR modifies code agent harness and post-code scripts, adding a new feature


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review fullsend-ai-review Bot added code-agent enhancement New feature or request labels Jul 28, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 28, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 11:01 AM UTC · Completed 11:18 AM UTC
Commit: 0dbf6ce · View workflow run →

fullsend-ai-review[bot]

This comment was marked as outdated.

Comment thread docs/code.md
1. **Pre-script** validates inputs on the runner before sandbox creation. It also checks for open PRs linked to the issue.
2. **Sandbox** — the agent reads the issue, explores the codebase, writes code, runs tests and linters, and commits locally. It has no network access (enforced by OpenShell).
3. **Post-script** runs on the runner: it performs protected path checks, secret scanning, pre-commit checks, pushes the branch, creates the PR, and best-effort assigns the PR to a human owner (latest `/fs-code` invoker, else issue assignee, else issue author).
3. **Post-script** runs on the runner: it performs protected path checks, secret scanning, pre-commit checks, pushes the branch, creates the PR, optionally enables auto-merge, and best-effort assigns the PR to a human owner (latest `/fs-code` invoker, else issue assignee, else issue author).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is required, otherwise this will grow into a big list of things that it does, probably not even comprehensive right now. If you want to add something, add "and other operations" at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in f3ba9b9 — removed the auto-merge mention from the post-script description.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like this snuck back in in a subsequent commit.

Comment thread scripts/post-code.sh Outdated
Comment thread scripts/post-code.sh Outdated
Comment thread scripts/post-code.src.sh Outdated
@maruiz93
maruiz93 force-pushed the auto-merge-env-var branch from 0dbf6ce to bb597d4 Compare July 29, 2026 09:50
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 29, 2026

Copy link
Copy Markdown

🤖 Review · ⚠️ Cancelled · Started 9:51 AM UTC · Ended 10:05 AM UTC
Commit: bb597d4 · View workflow run →

@fullsend-ai-review

fullsend-ai-review Bot commented Jul 29, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:07 AM UTC · Completed 10:25 AM UTC
Commit: f3ba9b9 · View workflow run →

fullsend-ai-review[bot]

This comment was marked as outdated.

@maruiz93
maruiz93 force-pushed the auto-merge-env-var branch from f3ba9b9 to 4f60e98 Compare July 29, 2026 10:47
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 29, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:48 AM UTC · Completed 11:04 AM UTC
Commit: 4f60e98 · View workflow run →

fullsend-ai-review[bot]

This comment was marked as outdated.

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review-only pass focused on the CODE_AUTO_MERGE safety semantics (branch-protection dependency, merge-method defaults, and the merge-queue claim). Four findings are attached as inline comments. One additional finding has no single line to anchor to and is included below.


[MEDIUM] PR description Summary contradicts the shipped implementation

The PR description's Summary section still reads: "enables GitHub auto-merge ... using the repo's configured merge strategy (no merge method flag — respects branch protection settings)." This is no longer accurate: both auto-merge call sites (post-code.src.sh:535-539 and 715-719) always pass an explicit --squash/--rebase/--merge flag via CODE_AUTO_MERGE_METHOD, added in a later commit specifically because the "no flag" approach didn't work. The Summary was never updated to match, so a reviewer relying on the description alone would be misled about how merge-strategy selection works, including the safety property ("respects branch protection settings") disputed in the inline comments on this review.

Suggested fix: Update the PR Summary to describe the CODE_AUTO_MERGE_METHOD-based behavior, its default ("merge"), and the merge-queue caveat, so the description matches the diff being merged.

Comment thread scripts/post-code.src.sh Outdated
Comment thread scripts/post-code.src.sh Outdated
Comment thread docs/code.md Outdated
Comment thread scripts/post-code.src.sh Outdated

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Follow-up review pass on the auto-merge feature — three new findings attached as inline comments (env-validation break, silent method fallback, unsanitized log output), plus one below that has no diff line to anchor to. Separately, the existing comment at post-code.src.sh:713 has been escalated to CRITICAL with verification details from the gh CLI source.


[MEDIUM] Docs regression: "How the agent works" lost the auto-merge mention

Commit 2d86dbf added "...pushes the branch, creates the PR, optionally enables auto-merge, and best-effort assigns the PR..." to the post-script bullet in docs/code.md (line 53). Commit 4f60e98 reverted that phrase — apparently an accidental hunk resolution while updating the doc for CODE_AUTO_MERGE_METHOD — so the current head's prose no longer mentions auto-merge at all, while the Variables table two paragraphs above documents both variables and the script unconditionally performs the step when enabled.

Suggested fix: Restore "...creates the PR, optionally enables auto-merge, and best-effort assigns the PR..." in the post-script bullet of docs/code.md. (Posted in the review body because line 53 is not part of this PR's diff.)

Comment thread harness/code.yaml Outdated
Comment thread scripts/post-code.src.sh Outdated
Comment thread scripts/post-code.src.sh Outdated
@maruiz93

Copy link
Copy Markdown
Contributor Author

Addressed in 2f93e79 — updated the PR description to reflect the current implementation: auto-detection of merge methods, merge-state guard, merge queue support, and safety guards.

@maruiz93

Copy link
Copy Markdown
Contributor Author

Addressed in 2f93e79 — restored "optionally enables auto-merge" in the post-script description at docs/code.md line 54.

@maruiz93

Copy link
Copy Markdown
Contributor Author

All findings from this review addressed in 2f93e79:

  • permission-expansion: acknowledged (opt-in, fail-closed)
  • fail-open: acknowledged (intentional best-effort)
  • architectural-conflict: fixed — merge queue detection added, method flag omitted for queue branches
  • stale-post-script-description: fixed — restored auto-merge mention in docs
  • missing-configuration-guidance: addressed — docs updated with runner env and prerequisite guidance

@fullsend-ai-review

fullsend-ai-review Bot commented Jul 31, 2026

Copy link
Copy Markdown

🤖 Review · ⚠️ Cancelled · Started 10:18 AM UTC · Ended 10:35 AM UTC
Commit: 2f93e79 · View workflow run →

Signed-off-by: Marta Anon <manon@redhat.com>
maruiz93 and others added 5 commits July 31, 2026 12:32
When CODE_AUTO_MERGE=true, enable GitHub auto-merge on newly created PRs
using the repo's configured merge strategy. Best-effort — failure to
enable auto-merge is a warning, not a blocking error.

The env var is passed through forge.github.runner_env in the code agent
harness. The fullsend CLI will populate it from config.Defaults.AutoMerge
in a follow-up change.

Signed-off-by: Marta Anon <manon@redhat.com>
Signed-off-by: Marta Anon <manon@redhat.com>
Signed-off-by: Marta Anon <manon@fullsend.sh>
Signed-off-by: Marta Anon <manon@redhat.com>
gh pr merge --auto defaults to merge commit, which silently fails for
repos that only allow squash or rebase. Accept CODE_AUTO_MERGE_METHOD
(squash|rebase|merge, default: merge) and pass the corresponding flag.

Also fixes inaccurate docs claiming "uses the repo's configured merge
strategy" and adds merge queue incompatibility note.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Marta Anon <manon@redhat.com>
- Add merge-state guard: only arm auto-merge when PR is BLOCKED
  (requires branch protection). Prevents immediate merge on
  unprotected repos where gh silently downgrades --auto to a
  direct merge.
- Auto-detect merge method from repo's allowed methods (prefer
  squash) when CODE_AUTO_MERGE_METHOD is unset.
- Detect merge queues and omit method flag so gh can negotiate
  with the queue.
- Skip re-arming on existing PRs where auto-merge is already set.
- Warn on unknown CODE_AUTO_MERGE_METHOD values instead of silent
  coercion.
- Capture and sanitize gh pr merge output via
  print_sanitized_gha_log.
- Remove CODE_AUTO_MERGE/CODE_AUTO_MERGE_METHOD from
  forge.github.runner_env to avoid harness env validation failures
  on deployments that don't define these optional vars.
- Restore auto-merge mention in docs post-script description.
- Extract enable_auto_merge helper to deduplicate existing-PR and
  new-PR paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Marta Anon <manon@redhat.com>
@maruiz93
maruiz93 force-pushed the auto-merge-env-var branch from 2f93e79 to 9e9a752 Compare July 31, 2026 10:35
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 31, 2026

Copy link
Copy Markdown

🤖 Review · ⚠️ Cancelled · Started 10:37 AM UTC · Ended 10:42 AM UTC
Commit: 9e9a752 · View workflow run →

@fullsend-ai-review

fullsend-ai-review Bot commented Jul 31, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:43 AM UTC · Completed 10:57 AM UTC
Commit: 94ddb9b · View workflow run →

fullsend-ai-review[bot]

This comment was marked as outdated.

The bundled script contains PR_NUMBER from the failure-report library.
Adding a local pr_number in enable_auto_merge triggered shellcheck
SC2153 ("Possible misspelling"). Follow the existing convention of
using target_pr for function parameters.

Signed-off-by: Marta Anon <manon@fullsend.sh>
Signed-off-by: Marta Anon <manon@redhat.com>
@maruiz93
maruiz93 force-pushed the auto-merge-env-var branch from 94ddb9b to ae8c86b Compare July 31, 2026 11:15
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 31, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 11:17 AM UTC · Completed 11:33 AM UTC
Commit: ae8c86b · View workflow run →

@fullsend-ai-review fullsend-ai-review Bot 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.

See the review comment for full details.

Comment thread scripts/post-code.src.sh
fi

local merge_state
merge_state="$(echo "${pr_json}" | jq -r '.mergeStateStatus // "UNKNOWN"')"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[HIGH] enable_auto_merge's UNKNOWN-state guard races GitHub's async mergeability computation with no retry, likely no-opping the primary use case

The BLOCKED-only guard added to fix the earlier CRITICAL bypass bug (commit 2f93e79) queries gh pr view --json mergeStateStatus exactly once, immediately after gh pr create (new-PR path) or immediately after a push (existing-PR path), with zero delay/retry/backoff. GitHub computes mergeStateStatus/mergeable asynchronously in the background after a PR is created or its head ref changes, and commonly returns UNKNOWN for a window immediately afterward. The UNKNOWN branch here treats this identically to a hard skip: it logs a warning and returns 0 permanently for that invocation — there is no re-check. This means the single highest-value scenario this PR advertises (arming auto-merge on a freshly created PR against a branch-protected repo) is likely to silently no-op on the only invocation that occurs. This is a new, previously-unraised consequence of the BLOCKED-guard fix itself (distinct from the original CRITICAL bug, which was about incorrectly merging on CLEAN/HAS_HOOKS/UNSTABLE states and has been fixed). It also remains unverified: the PR's test plan still shows both manual end-to-end verification checkboxes unchecked ("confirm gh pr merge --auto is called" and "confirm auto-merge is skipped ... without branch protection"), and the unit tests in scripts/post-code-test.sh only exercise hand-reimplemented copies of the decision logic, never the real gh-pr-view-driven state machine, so this UNKNOWN race path has zero test coverage.

Suggestion: add a short bounded retry/poll (e.g. 2-3 attempts with a brief sleep) around the mergeStateStatus check before treating UNKNOWN as a skip, and complete the two unchecked manual-verification checkboxes against a real branch-protected repo before merging this feature as final.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-agent enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants