Skip to content

#762: reconcile rebuilds a request from its bot branch, approved again by people - #802

Open
ephico2real2 wants to merge 3 commits into
mainfrom
feat/762-reconcile-rebuild
Open

ephico2real2 wants to merge 3 commits into
mainfrom
feat/762-reconcile-rebuild

Conversation

@ephico2real2

Copy link
Copy Markdown
Owner

Closes #762
Closes #796
Part of #26

What it does

After a database restore, the reconcile operation rebuilds each bot branch the database lacks, one item of rebuild-requests at a time (cmapi/src/cmapi/core/rebuild.py). docs/01, "Database recovery", asks for this.

  • The branch must have the bot's shape (verify):

    • one parent on main;
    • the bot's name and email as author and committer, with one date;
    • trailers naming this request, this instance and one plan hash;
    • the bot's subject;
    • changes inside one namespace folder;
    • an open PR on the same head whose body states the same plan hash;
    • files that hash to that plan hash when it is computed again.

    Any other branch is reported and not rebuilt. Its item fails, so the run fails and auto-approval stays paused.

  • Skipped: a head already in main (merged), and a folder that moved on since the commit's parent (superseded).

  • Reported: an adoption (its snapshot of the live objects is not in Git), and a host adapter that cannot read commits (the Gitea stand-in, FakeGit).

  • The rebuilt row: it comes back under its own ID in pending_approval, with the files and base that Git holds and no approvals. Git carries no authority (docs/01, "Approval of record"), and the bot does not sign its commits, so the rules decide the request again:

    • at least one approver;
    • no auto-approval;
    • no self-approval.

    The run's starter is the requester, sent by svc-cmapi-workflows. The requester that the commit names cannot approve or reject it.

  • Once approved: push_branch adopts the same branch and open_pr takes up the same PR.

  • git_reconcile deletes the bot branch and closes the PR of a request a restored database lacks #796: git_reconcile closed the PR and deleted the branch of every request a restored database lacked, at its first pass after the restore. It now keeps a branch or PR with no row whose head is not in main, and counts it as unrecorded.

The decisions, the options rejected and the sources are in docs/reviews/2026-12-01-issue-762/README.md. The sources are git-commit(1) and git-interpret-trailers(1), GitHub's commit verification and the repository activity API, Flux's .spec.verify, and Argo CD's signature verification. The options rejected are keeping the approval in pr_open, sealing or signing the bot's commits, and GitHub's pusher record.

Proof (local PostgreSQL 16, no cluster)

cmapi/tests/service/test_reconcile_rebuild_762.py runs on real Git through the Git layer and GitHub's PR paths (StubGitHub):

  • A restore loses a pr_open request. It comes back in pending_approval with the same ID, plan hash and files. It has no approvals, auto is null and selfApproval is false. The named requester and the starter get 409 self-approval. An approver approves it, and it reaches pr_open on the same PR and head, with no second PR.
  • A person re-commits the branch with the bot's trailers. The item fails (not-the-bot), and no row is written.
  • The bot's identity with one file changed. The item fails (hash-mismatch), and no row is written.
  • git_reconcile after the restore keeps the PR and the branch.

cmapi/tests/core/test_approvals.py covers the rebuilt rule and the named-requester refusal.

All six fail before the change. The output from before and after is in the record folder. These files also pass with the change: test_git_layer.py (89 tests, one test adjusted: a no-row orphan whose head main already holds is still deleted), test_operations_26.py (21, the reconcile test updated), test_operations_review_774.py, test_review_288_f2.py, test_review_288_f6.py, test_reject_decision_779_780.py and tests/core/test_approvals.py.

Not tested: an update or a delete rebuilt end to end, and anything on CRC or kind.

Filed

Who wrote what

Opus 5.5 (high), the implementer, wrote every commit and file in this PR. The review has not run yet. The change touches approval and Git provenance (security), so it needs reviewer 1 and reviewer 2.

…n by people

After a database restore the reconcile operation's rebuild-requests step takes
each bot branch the database lacks, one item at a time (core/rebuild.py).

- The head must have the bot's shape: one parent on main, the bot's name and
  email as author and committer with one date, this request's, this
  instance's and one plan hash's trailers, the bot's subject, changes inside
  one namespace folder, the open PR on the same head with the same plan hash
  in its body, and files that hash to the plan hash again. Anything else is
  reported and not rebuilt: the item fails and auto-approval stays paused.
- A head already in main is skipped as merged, a folder that moved on as
  superseded, and an adoption and a host that cannot read commits are
  reported.
- The row comes back under its own ID in pending_approval, with the files and
  base Git holds and no approvals. Git carries no authority (docs/01), so the
  rules decide it again: at least one approver, no auto-approval, and no
  self-approval. The run's starter is the requester (via
  svc-cmapi-workflows). The requester the commit names is refused as
  approver. Once approved, push_branch adopts the same branch and open_pr
  takes up the same PR.

#796: git_reconcile no longer closes the PR or deletes the branch of a request
the database lacks while its head is not in main. It counts them as
unrecorded and keeps them for the reconcile operation.

Decision record and sources: docs/reviews/2026-12-01-issue-762/README.md.
Docs: docs/02, docs/14, docs/16, GLOSSARY, citations relocated.

Written by Opus 5.5 (high), the implementer.
CI's service job: Plan.stored reads plan.rebuilt, and the test's SimpleNamespace
stands in for a Plan field by field, as it already gives adoption=None.

Written by Opus 5.5 (high), the implementer.
Conflicts were citation line numbers in docs/14, docs/16, docs/02 and
citations.lock.json. main's versions are taken, #762's doc edits are applied
again, and the citations are relocated and written with
scripts/doc-citations.py (0 problems).

Written by Opus 5.5 (high), the implementer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant