Skip to content

refactor(#7361): add force-re-root commit to forge.Client - #7368

Merged
ggallen merged 2 commits into
mainfrom
agent/7361-force-reroot-commit
Sep 16, 2026
Merged

ggallen merged 2 commits into
mainfrom
agent/7361-force-reroot-commit

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

Adds ForceCommitFileToBranch to forge.Client so later GitLab poller-state work can persist HMAC-signed JSON on a Developer-writable unprotected branch. Each write re-roots the branch on the repository's root commit with force:true, so history stays at base + 1 commit and never grows.

Related Issue

Phase 1 of #7343 (branch-backed poller state). Blocks phases 2 and 3 (#7362, #7366).

Changes

  • forge.Client.ForceCommitFileToBranch(ctx, owner, repo, branch, path, message, content)
  • GitLab: extend commitFilesImpl with force + start_sha; resolve the root commit SHA internally; suffix [skip ci]
  • GitHub: return forge.ErrNotSupported (explicit, no silent success)
  • FakeClient: per-branch files, create-on-first-write, last-write-wins, prune to one reachable commit
  • Document and test that GitLab GetFileContentAtRef 404 unwraps to forge.ErrNotFound so a missing state file is distinguishable

Testing

  • GitLab httptest: first write creates the branch with force:true and start_sha; repeated writes keep the same start SHA; missing file → ErrNotFound; missing/unreachable base → error; [skip ci] suffix
  • Fake: create-on-first-write, last-write-wins, history pruned to one commit after N writes, per-branch isolation, concurrent writes, error injection
  • GitHub stub: ErrNotSupported
  • go test ./internal/forge/ ./internal/forge/github/ ./internal/forge/gitlab/ and go vet pass; new functions ≥ 80% coverage

Checklist

  • PR title follows Conventional Commits
  • Commits are not DCO-signed (autonomous agent exemption)
  • I wrote this contribution myself and can explain all changes in it

Closes #7361

Post-script verification

  • Branch is not main/master (agent/7361-force-reroot-commit)
  • Secret scan passed (gitleaks — 90a86f0b1ad9cb8aa27effbd623f4227dba4e21e..HEAD)
  • PR body secret scan passed (gitleaks — no-git)

Add ForceCommitFileToBranch so GitLab poller state can live on a
Developer-writable unprotected branch (phase 1 of #7343). Each write
re-roots the target branch on the repository root commit with
force:true, leaving history at base + 1 commit.

GitLab extends commitFilesImpl with force and start_sha, resolves
the root SHA internally, and suffixes [skip ci]. GitHub returns
ErrNotSupported. FakeClient models per-branch last-write-wins
files and prune-to-one-commit. GetFileContentAtRef 404 already
unwraps to ErrNotFound via APIError; tests lock that contract.

Note: pre-commit could not fetch remote hook repos (HTTP 403).
Local equivalents were run: gofmt, go vet, whitespace/EOF checks,
gitleaks, and lint-broken-symlinks.

Closes #7361
@fullsend-ai-coder
fullsend-ai-coder Bot requested a review from a team September 16, 2026 12:34
@fullsend-ai-coder fullsend-ai-coder Bot added the ready-for-review Triggers review agent dispatch label Sep 16, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 12:37 PM UTC · Completed 12:54 PM UTC

Commit: 91ebc05 · View workflow run →

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

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Sep 16, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Tier 1 signals are unchanged from the prior review (same file count/blast-radius bucket, no protected/security/dependency changes, bot author) and remain low apart from the large diff size; Tier 2 remains elevated due to heavy historical fix/revert churn and multi-author contention in the shared forge package (same file set as before, since the new commit only touched already-included gitlab/repo.go and gitlab_test.go to fix a review-identified bug); Tier 3 remains tightly scoped and well-matched to the linked issue with no risk labels. Anchored to the prior moderate (2) rating.

Previous run

Risk Assessment: moderate (2/5)

Details

Tier 1 is low outside of the large diff size, Tier 3 shows a tightly-scoped, well-matched change against the linked issue's checklist with no risk labels, while Tier 2 is elevated due to heavy historical fix/revert churn and multi-author contention in the shared forge package; together these average to a moderate composite score.

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Looks good to me

Previous run

Review

Findings

High

  • [logic-error] internal/forge/gitlab/repo.go:833 — resolveRootCommitSHA resolves the force-commit base by calling GET /projects/:id/repository/commits?ref_name=<default-branch>&order_by=committed_date&sort=asc&per_page=1. GitLab's List Repository Commits API documents ref_name, since, until, path, author, all, with_stats, first_parent, order (default|topo), and trailers — not order_by/sort (those params belong to other GitLab endpoints, e.g. pipelines/jobs/issues, which this same client uses correctly elsewhere, but this is a different endpoint with a different parameter set). Unrecognized query params are silently ignored, so this call almost certainly returns the endpoint's documented default ordering (reverse-chronological from the ref tip), meaning per_page=1 returns the current default-branch HEAD, not the repository's DAG root commit. Because ForceCommitFileToBranch re-resolves this SHA on every call, start_sha would track a moving main tip: each force-write's parent becomes whatever main currently is, the state branch's reachable history would include all of main (not exactly 1 commit), and the tree seeded for the commit would be main's full tree plus the one new file — not the minimal single-file tree the design requires. This breaks the interface's documented contract ("re-rooted on a fixed base... branch at base + 1... history is pruned") and the parent design's core acceptance criterion (verified live on GitLab: "only one commit touching state.json was reachable... branch always base + 1"). The GitLab httptest suite (TestForceCommitFileToBranch and related tests) only asserts that the client sends these query params and then returns a canned fake SHA — it cannot catch a live-API parameter mismatch, so this would ship believing it's tested.
    Remediation: Do not rely on order_by/sort against the commits-list endpoint. Resolve the actual DAG root by walking first-parent ancestry (GET /projects/:id/repository/commits/:sha, following parent_ids[0] until empty) or by paginating GET /projects/:id/repository/commits?ref_name=<default-branch>&first_parent=true to the last page and taking its last entry. Cache the resolved root SHA if repeating this on every write is too costly. Update the GitLab httptest coverage to assert the actual resolution protocol rather than accepting any commit-list response.

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-coder

fullsend-ai-coder Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 12:56 PM UTC · Completed 1:05 PM UTC

Commit: 91ebc05 · View workflow run →

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

The commits-list endpoint does not support order_by/sort (those belong
to other GitLab endpoints); unrecognized params are silently ignored,
so resolveRootCommitSHA's per_page=1 request returned main's current
HEAD instead of the DAG root. That let start_sha drift with every push
to main, breaking ForceCommitFileToBranch's base+1 history guarantee.

Resolve the root by paginating first-parent history (first_parent=true)
to its last page and taking that page's last entry, mirroring the
pagination pattern already used by getTreeMap/ListRepositoryFiles.
Update GitLab httptest coverage to assert the real query params and add
a multi-page test proving the root is taken from the last page, not the
branch tip.

Addresses review feedback on PR #7368
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 1 (bot-triggered)

Fixed the single high-severity finding: resolveRootCommitSHA now resolves the actual repository DAG root via first-parent pagination instead of relying on order_by/sort params the GitLab commits-list endpoint doesn't support (which previously returned main's moving HEAD instead of a fixed root). Updated and added GitLab httptest coverage to assert the real resolution protocol, including a multi-page test that would fail under the old bug or a naive first-page-first-entry fix.

Fixed (1):

  1. resolveRootCommitSHA uses order_by/sort, which the GitLab commits-list endpoint ignores, so it returns main's HEAD instead of the DAG root. (internal/forge/gitlab/repo.go): Rewrote resolveRootCommitSHA to resolve the true DAG root by paginating first-parent history (first_parent=true, per_page=100, offset pagination via page/X-Next-Page) to its last page and taking that page's last entry, instead of relying on the unsupported order_by/sort params. Reused the existing maxTreePages pagination bound and updated its doc comment to reflect the new usage. Updated internal/forge/gitlab/gitlab_test.go: fixed TestForceCommitFileToBranch to assert the real query params (first_parent, per_page=100, page=1) and that order_by/sort are absent, and added TestForceCommitFileToBranch_WalksToLastPage, a two-page httptest scenario that proves the resolved start_sha comes from the last entry of the last page (the true root) rather than the first entry of the first page (the branch tip).

Tests: passed

Decision points
  • Chose first-parent pagination-to-last-page over walking parent_ids one commit at a time via GET .../commits/:sha (alternatives: Walk first-parent ancestry one commit at a time via GET /projects/:id/repository/commits/:sha, following parent_ids[0] until empty, Paginate GET /projects/:id/repository/commits?ref_name=&first_parent=true to the last page and take its last entry; rationale: The per-commit walk needs one round trip per commit in the repository's first-parent history, which is far more expensive for large/old repos. Pagination reuses the exact list+X-Next-Page pattern already used elsewhere in this file (getTreeMap, ListDirectoryContents, ListRepositoryFiles), stays consistent with repo conventions, and both options were explicitly offered as acceptable remediations by the reviewer.)

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

🤖 Review · ❌ Terminated · Started 1:07 PM UTC · Ended 1:25 PM UTC

Commit: 051542c · View workflow run →

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.37398% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/forge/gitlab/repo.go 96.82% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@fullsend-ai-review
fullsend-ai-review Bot dismissed their stale review September 16, 2026 13:25

Superseded by updated review

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Sep 16, 2026
@fullsend-ai-review

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 1:07 PM UTC · Completed 1:25 PM UTC

Commit: 051542c · View workflow run →

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

@ggallen
ggallen enabled auto-merge September 16, 2026 13:28
@ggallen
ggallen added this pull request to the merge queue Sep 16, 2026
Merged via the queue into main with commit 780aee7 Sep 16, 2026
55 of 56 checks passed
@ggallen
ggallen deleted the agent/7361-force-reroot-commit branch September 16, 2026 13:58
@fullsend-ai-retro

fullsend-ai-retro Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

🤖 Finished Retro · ✅ Success · Started 2:00 PM UTC · Completed 2:06 PM UTC

Commit: 051542c · View workflow run →

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

@fullsend-ai-retro

Copy link
Copy Markdown

PR #7368 (phase 1/4 of #7343, branch-backed poller state) shows a healthy, fast pipeline: triage → /fs-code (grok-4.6, commit 91ebc05) → review (High-severity finding) → auto-dispatched fix agent → re-review (approve) → human approval → merge, issue-to-merge in ~2h6m. The review agent's High finding was technically correct: resolveRootCommitSHA in internal/forge/gitlab/repo.go passed order_by/sort query params to GitLab's List Repository Commits endpoint, which doesn't support them (GitLab silently ignores unrecognized params), so the call would have returned main's HEAD instead of the DAG root — silently breaking the branch-pruning contract the whole #7343 design depends on. The fix agent resolved it in one automated iteration (~9 minutes after the finding posted) by switching to first_parent pagination and added a new regression test (TestForceCommitFileToBranch_WalksToLastPage) specifically designed to catch both the original bug and a naive one-page fix — good test design. No human debugging was needed; the human's only touchpoints were the initial /fs-code dispatch and a final no-comment approval, which reflects a reviewer judging the automated review-fix loop as sufficient, not a lack of engagement. Risk-tier scoring (moderate 2/5, high review effort) was already appropriately calibrated for this diff — no miscalibration found. This incident is a fresh confirming data point for an already-tracked systemic gap: the code agent introduced an incorrect assumption about external GitLab API behavior, masked by mocked/httptest coverage that only asserted request shape rather than resolution correctness. That exact failure class (hallucinated/wrong API params or paths, hidden by mocks, in this same forge-client area) is already covered by open issues fullsend-ai/agents#314 (review should verify API assumptions against docs — filed from a near-identical prior GitLab forge.Client incident on PR #4101), #1126 (cross-check external API paths against training knowledge), and #1275 (code agent should proactively use web tools to verify uncertain API contracts, from PR #7141). This run shows the review-side catch (#314's premise) working well, while the root-cause code-agent-side gap (#1275) persisted again. No new proposal is filed for this; it's noted here as supporting evidence rather than a duplicate issue. Overall this was an example of the pipeline working as designed, and no new improvement proposals were identified.

This branch was previously deployed

1 inactive deployment
dev — 051542cb Deployed Sep 16, 2026 by fullsend-ai-coder[bot] via behaviour #12964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gitlab poller state (1/4): add force-re-root single-file commit to forge.Client

1 participant