Skip to content

merge failure recovery docs and error catalogue#9566

Open
ajtmccarty wants to merge 6 commits into
ifc-2437-merge-failure-recoveryfrom
ifc-2437-merge-failure-recovery-docs-and-catalogue
Open

merge failure recovery docs and error catalogue#9566
ajtmccarty wants to merge 6 commits into
ifc-2437-merge-failure-recoveryfrom
ifc-2437-merge-failure-recovery-docs-and-catalogue

Conversation

@ajtmccarty

@ajtmccarty ajtmccarty commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Why

The write-block increment rejects mid-merge writes with a hardcoded message string, and the only way for a client to tell "retry, this is transient" from "give up, this branch is read-only" was to string-match the error message. The E2E retry helper already did exactly this (error.message === MERGE_IN_PROGRESS_MESSAGE), which silently breaks the moment the wording changes. The new write-blocking behavior was also undocumented for both users and contributors.

Goal: give the merge write-block rejections stable, structured GraphQL error codes so clients (and the E2E suite) can branch on a code instead of a message, and document the during-merge write-blocking in the user docs and the dev knowledge base.

Non-goals: no change to the write-block behavior itself, the messages users see, or which operations are blocked (all from the prior increment); the MERGE_FAILED state and infrahub recover recovery flow are out of scope; REST endpoints keep their existing 422 wrapping.

Closes IFC-2562

What changed

Behavioral changes (API surface):

  • Three branch-status rejections now carry a structured catalogue code in the GraphQL error extensions ({code, http_status, data}), in addition to the unchanged human message:
    • BRANCH_ALREADY_MERGED (HTTP 400) — write to a MERGED branch. Payload: {branch_name}.
    • BRANCH_NEEDS_REBASE (HTTP 400) — write to a NEED_REBASE branch. Payload: {branch_name}.
    • MERGE_IN_PROGRESS (HTTP 423 Locked) — write blocked by an in-progress merge, on either the branch being merged or the default branch. Payload: {branch_name, merging_branch}.
  • MERGE_IN_PROGRESS is the transient/retryable signal; clients should match on the code and retry rather than treating the failure as permanent.
  • The Playwright E2E mutation helper now retries on parseCatalogueError(error.extensions).code === ERROR_CODES.MERGE_IN_PROGRESS instead of comparing the message string.

Implementation notes:

  • New MergeInProgressError(BranchStatusError) (HTTP 423) carrying a merging_branch attribute. Both gates in BranchStatusChecker.check_merging_status (source-branch and default-branch) and the cache-unreachable DB fallback raise it; the messages are unchanged. The default-branch DB-fallback case uses min(merging_branch_names) for a deterministic merging_branch.
  • Both source-branch and default-branch blocks map to the single MERGE_IN_PROGRESS code (decision: one code for "blocked by an active merge"). A client retrying a write to the source branch self-corrects — once the merge lands the code flips to BRANCH_ALREADY_MERGED and the retry helper fails fast.
  • HTTP 423 was chosen for the catalogue entry as the most precise "temporarily locked, retry later" status. It surfaces only in the GraphQL extensions.http_status.
  • Drive-by fix in tasks/backend.py: export-error-catalogue built its output path from the shell-escaped repo path, so in a worktree whose path contains a . it wrote to a literal infrahub\.worktrees/... directory instead of the real one. Switched to the unescaped REPO_BASE since the path is used for a filesystem write, not a shell command.

How to review

Focus areas:

  • backend/infrahub/branch/status_checker.py — the four raise-site swaps to MergeInProgressError and the merging_branch values passed on each path.
  • backend/infrahub/errors/{catalogue,payloads}.py, exceptions.py, graphql/error_formatter.py — the catalogue entries, payload models, and the _build_payload match arms.
  • frontend/app/tests/e2e/utils/graphql.ts — the actual consumer change (string match → code match).

Checklist

  • Tests added/updated
  • Changelog entry added (uv run towncrier create ...)
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)
  • I have reviewed AI generated content

Summary by cubic

Introduce a structured MERGE_IN_PROGRESS error and enforce merge-time write blocking on the source and default branches. Updates align with IFC-2437 by making merge state visible to clients so they can safely retry and by clarifying behavior in docs.

  • New Features

    • Added MergeInProgressError (HTTP 423) with payload { branch_name, merging_branch }; raised by the status checker when merge protection is active (cache-first with DB fallback).
    • Expanded the error catalogue and GraphQL formatter with BRANCH_ALREADY_MERGED, BRANCH_NEEDS_REBASE, and MERGE_IN_PROGRESS.
    • Updated docs: merge flow now documents temporary write blocks and shows a MERGE_IN_PROGRESS example; error catalogue lists the new codes; internal knowledge base covers MERGING state and the write blocker.
    • Regenerated frontend error types and tests; e2e now matches on the MERGE_IN_PROGRESS code instead of the message.
    • Exported the updated error-catalogue.json; adjusted the export task to write to the repo base path.
  • Migration

    • Update client error handling to check extensions.code === "MERGE_IN_PROGRESS" and retry after a short delay.
    • Prefer error codes over parsing messages in any existing logic.

Written for commit 9ff5cb3. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added type/documentation Improvements or additions to documentation group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) labels Jun 13, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 19 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Introduces a new MergeInProgressError with structured error code, updates error catalogue, docs, and frontend error handling. All changes are additive and well-tested, with no refactoring of existing logic or risk to core business functionality.

Re-trigger cubic

@codspeed-hq

codspeed-hq Bot commented Jun 13, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 32.11%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 10 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_base_schema_duplicate_CoreProposedChange 2.2 ms 1.5 ms +49.84%
test_schemabranch_duplicate 7.7 ms 6.6 ms +16.48%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ifc-2437-merge-failure-recovery-docs-and-catalogue (66b6354) with stable (1653400)1

Open in CodSpeed

Footnotes

  1. No successful run was found on ifc-2437-merge-failure-recovery (bfc7962) during the generation of this report, so stable (1ae00c7) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Base automatically changed from ifc-2437-merge-failure-recovery-branch-protection to ifc-2437-merge-failure-recovery June 15, 2026 17:52
@ajtmccarty ajtmccarty force-pushed the ifc-2437-merge-failure-recovery-docs-and-catalogue branch from 9ff5cb3 to 66b6354 Compare June 15, 2026 19:23
@github-actions github-actions Bot added the type/spec A specification for an upcoming change to the project label Jun 15, 2026
@ajtmccarty ajtmccarty marked this pull request as ready for review June 15, 2026 20:39
@ajtmccarty ajtmccarty requested review from a team as code owners June 15, 2026 20:39

@ajtmccarty ajtmccarty left a comment

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.

@opsmill/frontend could you please review the small frontend changes in this PR when you have time?

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.

support new error codes

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.

match on new error code for "merge in-progress" for retrying during E2E tests

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

Labels

group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) type/documentation Improvements or additions to documentation type/spec A specification for an upcoming change to the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant