Skip to content

Fix agent push fails on GitLab MRs (non-fast-forward from reconstructed branch) #1228

Closed

Description

@ggallen

What happens

The fix agent completes successfully on GitLab MRs — changes are correct, tests pass, validation passes — but the post-fix.sh push fails with non-fast-forward, then the --force-with-lease fallback fails with stale info. The job exits 1.

! [rejected] feature/jwant/FRFLY-640-fullsend-part-2 -> ... (non-fast-forward)
::warning::Plain push failed (non-fast-forward) — retrying with --force-with-lease
! [rejected] feature/jwant/FRFLY-640-fullsend-part-2 -> ... (stale info)

What should happen

The fix commit(s) should be pushed to the MR source branch.

How to reproduce

  1. Have a GitLab MR with a human-triggered /fs-fix instruction
  2. The fix agent job runs on a fullsend runner
  3. Agent enters the sandbox, which blocks git protocol access (network policy)
  4. Agent cannot git fetch the MR source branch, so it reconstructs the branch by:
    • Starting from main (the runner's checkout ref)
    • Fetching file content from the GitLab API for the source branch
    • Creating a local branch and committing
  5. Agent makes its fix commit on top of this reconstructed history
  6. Post-fix.sh extracts the repo and tries to push
  7. Push fails because the local branch history diverges from the remote branch (reconstructed vs actual commits)
  8. --force-with-lease also fails because the local ref was never fetched from the remote, so the lease has no baseline

Observed on: gitlab.cee.redhat.com/ixd-firefly/ixd-firefly-harness-engineering-cli/-/jobs/60626544, MR !107, runner fullsend-gitlab-runner-04.

Context

This only affects GitLab. On GitHub, the sandbox can fetch the PR branch, so the commit history matches and plain push succeeds.

The runner itself (outside the sandbox) has full git access — the get_sources step clones successfully, and the post-fix.sh push reaches GitLab (it gets a rejection, not a network error). The problem is that post-fix.sh doesn't fetch the remote branch before pushing.

Where to fix

The push logic is in scripts/post-fix.sh in fullsend-ai/agents (generated from post-fix.src.sh). The push section is in the shared code path (not forge-specific), around line 1631 in the generated file:

# ---------------------------------------------------------------------------
# 4. Push branch (only if we have commits)
# ---------------------------------------------------------------------------
if [ "${NO_PUSH}" = "false" ]; then
  forge_set_push_remote "${PUSH_TOKEN}"

  # Plain push first. Falls back to --force-with-lease when the push
  # is rejected (non-fast-forward), which happens after a rebase — the
  # agent rewrote history so the remote branch diverged. force-with-lease
  # is safe: it still rejects if someone else pushed in the meantime.
  echo "Pushing branch ${BRANCH}..."
  PUSH_OUTPUT="$(git push -u origin -- "${BRANCH}" 2>&1)" && PUSH_RC=0 || PUSH_RC=$?

Insert a fetch + rebase after forge_set_push_remote and before the push, so the agent's commit(s) are replayed on top of the actual remote branch tip:

forge_set_push_remote "${PUSH_TOKEN}"

# Ensure local branch is up-to-date with the remote. On GitLab, the
# sandbox cannot git-fetch the source branch, so the agent reconstructs
# it from API content — the resulting commit history diverges from the
# remote. Fetching and rebasing here makes the push a fast-forward.
# On GitHub this is a no-op (history already matches).
git fetch origin "${BRANCH}" 2>/dev/null || true
git rebase "origin/${BRANCH}" 2>/dev/null || true

echo "Pushing branch ${BRANCH}..."

This is safe for both forges — on GitHub the rebase is a no-op since history already matches. The || true guards handle the case where the remote branch doesn't exist yet (fresh branch).

Activity

  1. fullsend-ai-triage commented on Sep 9, 2026

    @fullsend-ai-triage

    🤖 Triage · ⚠️ Cancelled · Started 6:38 PM UTC · Ended 6:39 PM UTC

    Commit: e6924b8 · View workflow run →

  2. fullsend-ai-triage commented on Sep 9, 2026

    @fullsend-ai-triage

    🤖 Finished Triage · ✅ Success · Started 6:41 PM UTC · Completed 6:45 PM UTC

    Commit: e6924b8 · View workflow run →

    Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $0.33

  3. added
    bug
    ready-to-code
    on Sep 9, 2026
  4. fullsend-ai-triage commented on Sep 9, 2026

    @fullsend-ai-triage

    Re-triage confirms the original analysis: a real, reproducible defect in scripts/post-fix.sh's push logic, not a duplicate, and not blocked by other work. One correction to the earlier triage note -- scripts/post-fix.sh and its source post-fix.src.sh were verified to exist in this repository at the path described, so the fix belongs here as originally proposed.

    Searched this repo and fullsend-ai/fullsend for anything already addressing this: issue #139 in this repo is related (also about post-fix.sh's push-rejection handling) but covers a distinct failure mode -- misclassifying GitHub App permission errors as non-fast-forward -- and is not a duplicate. Open PR #1163 adds a different, agent-side rebase mechanism for when a PR head moves mid-run; it does not touch the push section this issue targets, so it does not resolve this bug. fullsend-ai/fullsend#5419 and #5525 remain related-but-distinct post-script robustness gaps worth keeping in mind for whoever implements this, since all three touch push/rebase correctness in the same code area.

    Proposed test case:

    Given: a remote branch with commit A, and a local reconstructed branch
    starting from a different base with divergent commit A' plus the agent's
    fix commit F on top.
    When: the push logic runs.
    Then:
      1. Plain push is rejected (as today).
      2. New fetch+rebase step replays F onto the real remote tip A,
         producing a linear A -> F' history.
      3. The subsequent push succeeds as a fast-forward.
    
    Also cover:
      - No existing remote branch (fresh branch): fetch/rebase no-ops cleanly,
        push still succeeds.
      - GitHub-style flow (local already matches remote): rebase is a true
        no-op, F is unchanged.
      - A genuine rebase conflict (remote branch has new commits that
        textually conflict with F): the script should fail loudly with an
        actionable message rather than silently mis-merging.
    

    Next steps:

    • /fs-code — agent creates a PR to implement this issue
    • /fs-code <your instruction> — agent implements with your specific guidance
    Previous run

    This report is unusually thorough — exact error output, a precise mechanistic explanation, a real job/MR reference, and a concrete proposed patch. Searched both fullsend-ai/fullsend and fullsend-ai/agents for open issues or PRs referencing post-fix.sh, non-fast-forward pushes, or this issue number; found no duplicates and no in-flight PR addressing it. Two related open issues (#5419 on commit-range scoping after rebase, and fullsend-ai/fullsend#5525 on verifying PR head/CI triggered after push) cover distinct post-script robustness gaps and are not duplicates of this one.

    One thing worth flagging for whoever picks this up: the file needing the change (scripts/post-fix.sh, generated from post-fix.src.sh) doesn't live in this repository — it lives in fullsend-ai/agents, as the report's own 'Where to fix' section notes. Make sure the fix lands there rather than being attempted against this repo's tree.

    Proposed test case:

    Given: a remote branch with commit A, and a local reconstructed branch
    starting from a different base with divergent commit A' plus the agent's
    fix commit F on top.
    When: the push logic runs.
    Then:
      1. Plain push is rejected (as today).
      2. New fetch+rebase step replays F onto the real remote tip A,
         producing a linear A -> F' history.
      3. The subsequent push succeeds as a fast-forward.
    
    Also cover:
      - No existing remote branch (fresh branch): fetch/rebase no-ops cleanly,
        push still succeeds.
      - GitHub-style flow (local already matches remote): rebase is a true
        no-op, F is unchanged.
    

    Labels: Matches this repo's established convention for fix-agent post-script defects: type/bug plus agent/fix and component/ci, with priority/high reflecting that it breaks the fix agent's GitLab push path entirely.


    Next steps:

    • /fs-code — agent creates a PR to implement this issue
    • /fs-code <your instruction> — agent implements with your specific guidance
  5. ggallen commented on Sep 9, 2026

    @ggallen
    MemberAuthor

    /fs-triage

  6. fullsend-ai-triage commented on Sep 9, 2026

    @fullsend-ai-triage

    🤖 Triage · ⚠️ Cancelled · Ended 6:48 PM UTC

    Commit: 7ab0556 · View workflow run →

  7. fullsend-ai-triage commented on Sep 9, 2026

    @fullsend-ai-triage

    🤖 Finished Triage · ✅ Success · Started 6:50 PM UTC · Completed 6:55 PM UTC

    Commit: 7ab0556 · View workflow run →

    Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $0.34

  8. added
    ready-to-code
    and removed
    ready-to-code
    on Sep 9, 2026
  9. 4 remaining items

  10. added 2 commits that reference this issue on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-to-code

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions