Repository navigation
fix(update): preserve operator work during retained Git rollback - #160170
Conversation
Forward-port rollback-ownership and runtime-restoration corrections from 008d0c4. Preserve operator edits and changed branch refs, and record completed runtime restoration before rechecking authority. Validation remains incomplete under host load; do not publish.
Keep retained Git rollback ownership and runtime restore replay fixes within existing file limits. Move rollback commands to the Git step owner and transaction regressions to sibling test support; preserve the original regression coverage. Completes the implementation extraction from 7d8c28f; validation and review are recorded in the PR.
Replace retained reset --keep with a non-forcing detached checkout, conditional branch-ref update, and reattachment. The old reset discarded staged content in unchanged files when the working copy contained a different edit. A real-Git regression reproduced the index losing the staged bytes before this fix.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 28, 2026, 2:24 PM ET / 18:24 UTC (Revision 12). ClawSweeper reviewWhat this changesThe branch changes Git-checkout rollback to preserve operator edits and branch custody, prevents replay of completed runtime restoration, adds real-Git regressions, and documents recovery. Merge readiness⛔ Blocked before merge - 4 items remain Current main still has the destructive Git rollback path, so this PR remains useful. The prior code findings are addressed, but the reflog-less recovery tradeoff needs an update-owner decision and the required published-updater upgrade result is still absent. Priority: P1 Review scores
Verification
How this fits togetherThe installed updater builds and activates a Git checkout, then retains the previous checkout and runtime until verification finishes. If verification fails, rollback restores source and runtime before the Gateway can safely restart. flowchart LR
A[Installed updater] --> B[Git checkout activation]
C[Operator edits and worktrees] --> D[Retained rollback]
B --> D
D --> E[Branch and reflog checks]
E --> F[Source and runtime restoration]
F --> G[Gateway restart or manual recovery]
Decision needed
Why: The reflog check protects branch-ref integrity but changes upgrade behavior for existing checkouts and can leave a stopped Gateway awaiting operator action. Before merge
Agent review detailsSecurityNone. PR surfaceSource +197, Tests +434, Docs +4. Total +635 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one rollback owner that preserves operator source work, retains the previous runtime when restoration is unsafe, and gives operators a clear recovery path for checkouts that cannot be restored automatically. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main still has the destructive rollback sequence, and the PR reports pre-fix failures in real-Git cases. This read-only review did not execute the path. Is this the best way to solve the issue? Yes in principle: the patch repairs the existing rollback owner and tests Git's actual branch behavior. The reflog-less policy and first-hop upgrade evidence remain merge decisions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5117d94bdf94. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (11 earlier review cycles; latest 8 shown)
|
…hanges Linked worktrees in a paused rebase or bisect detach HEAD, so worktree porcelain misses their branch reservation. Probe with a no-op branch reset, which Git refuses for every worktree owner state.
|
Status: two ClawSweeper/autoreview P1 rounds on branch custody were fixed (porcelain check, then Git's native no-op |
Chat transcript tool-card disclosure toggles call the current render lifecycle's update hook (rebound on every projection without repainting cached rows) instead of the closure captured when the row was first rendered. Latent hardening; no visual change. The session-roster-request-rate real-gateway e2e failure seen on this PR also fails on unrelated PRs today (e.g. #160170) and is not caused by this change. Forward-port of release/2026.9.7 0c06877 and a124ea0.
Keep HEAD attached during retained source restoration and verify the reflog transition before restoring the runtime. Restore claimed dev refs with create-only compensation after CAS deletion. Preserve operator edits and report explicit recovery steps.
Leave the created dev ref intact during retained rollback and report a quoted manual cleanup hint while restoring the original checkout and runtime. Remove post-delete custody scans and compensation, which cannot exclude in-flight claims or safely repair after authority revocation. Preserve the existing rewrite and non-retained cleanup paths.
|
CI note for run 36427635465 (head a2267cf): the only failure was |
|
CI note for run 36445218914 (head 2296b06): the only failure was |
Require an existing, readable branch reflog before retained rollback rewrites source. If the ref changes after checkout, retain both runtimes and report the expected, current, and reflog-previous commits without a forced-ref command. Only offer conditional restoration of an overwritten earlier write while the branch still points to the rollback commit. Extend the real-Git transaction table with the post-checkout writer and pre-mutation reflog refusal, and document the installed-updater behavior. Both regressions fail against the previous implementation; the existing pre-checkout writer recovery remains covered. Validation: 101 candidate/runtime tests pass (176.9s wall); core and infra-test typechecks, targeted oxlint, oxfmt, and git diff --check pass. The three focused real-Git cases take 6.4s test time on one worker. Isolated P2 review is clean.
|
CI note for run 36463778760 (head 6524c79): the only failure was |
|
Maintainer decision on the reflog-less refusal (relayed for Peter, 2026-09-28): accepted as a fail-closed edge. It only occurs when branch reflogs are disabled ( Why the previous Gateway is not restarted in that path: restoring only the backed-up runtime while the checkout stays at the activated commit is not a coherent previous generation. The runtime backup holds generated directories, but plugin discovery still reads the tracked candidate plugin manifests from the checkout (src/plugins/discovery.ts), which drive config validation, and runtime artifact selection can fall back to candidate source when a previous compiled entry is missing (src/plugins/plugin-runtime-artifact-selection.ts). That could start a mixed old/new generation despite a correct previous build-info SHA. Doing this safely needs the transaction to retain all previous runtime inputs or verify the remaining tracked inputs, which is a larger follow-up for the update owner. The refusal message names the branch, the SHAs, and what to inspect. |
|
Merged via squash.
|
|
Post-merge published-driver proof: Package Acceptance run 36482095098 on main 165fd29 (contains this PR and #160164/#160170) passed both Docker lanes: |
Chat transcript tool-card disclosure toggles call the current render lifecycle's update hook (rebound on every projection without repainting cached rows) instead of the closure captured when the row was first rendered. Latent hardening; no visual change. The session-roster-request-rate real-gateway e2e failure seen on this PR also fails on unrelated PRs today (e.g. openclaw#160170) and is not caused by this change. Forward-port of release/2026.9.7 0c06877 and a124ea0.
…nclaw#160170) * fix(update): preserve retained rollback ownership (WIP) Forward-port rollback-ownership and runtime-restoration corrections from 008d0c4. Preserve operator edits and changed branch refs, and record completed runtime restoration before rechecking authority. Validation remains incomplete under host load; do not publish. * refactor(update): separate rollback steps and transaction fixtures Keep retained Git rollback ownership and runtime restore replay fixes within existing file limits. Move rollback commands to the Git step owner and transaction regressions to sibling test support; preserve the original regression coverage. Completes the implementation extraction from 7d8c28f; validation and review are recorded in the PR. * fix(update): preserve staged content during retained rollback Replace retained reset --keep with a non-forcing detached checkout, conditional branch-ref update, and reattachment. The old reset discarded staged content in unchanged files when the working copy contained a different edit. A real-Git regression reproduced the index losing the staged bytes before this fix. * fix(update): preserve branches claimed by linked worktrees * fix(update): use Git's own branch custody check before rollback ref changes Linked worktrees in a paused rebase or bisect detach HEAD, so worktree porcelain misses their branch reservation. Probe with a no-op branch reset, which Git refuses for every worktree owner state. * fix(update): keep branch custody through retained rollback ref writes Keep HEAD attached during retained source restoration and verify the reflog transition before restoring the runtime. Restore claimed dev refs with create-only compensation after CAS deletion. Preserve operator edits and report explicit recovery steps. * fix(update): keep the created dev branch on retained rollback Leave the created dev ref intact during retained rollback and report a quoted manual cleanup hint while restoring the original checkout and runtime. Remove post-delete custody scans and compensation, which cannot exclude in-flight claims or safely repair after authority revocation. Preserve the existing rewrite and non-retained cleanup paths. * fix(update): keep newer branch writes out of rollback recovery guidance Require an existing, readable branch reflog before retained rollback rewrites source. If the ref changes after checkout, retain both runtimes and report the expected, current, and reflog-previous commits without a forced-ref command. Only offer conditional restoration of an overwritten earlier write while the branch still points to the rollback commit. Extend the real-Git transaction table with the post-checkout writer and pre-mutation reflog refusal, and document the installed-updater behavior. Both regressions fail against the previous implementation; the existing pre-checkout writer recovery remains covered. Validation: 101 candidate/runtime tests pass (176.9s wall); core and infra-test typechecks, targeted oxlint, oxfmt, and git diff --check pass. The three focused real-Git cases take 6.4s test time on one worker. Isolated P2 review is clean.
What Problem This Solves
After a Git-checkout update completes and its transaction is retained, a later rollback checked source cleanliness once and then ran
reset --hard,clean -fd,checkout --force, anotherreset --hardandbranch -D. Operator edits made while the rollback awaited (tracked, untracked or staged) were destroyed, an operator-recreated or moved dev branch was deleted, and the checkout could land on the wrong lineage. Separately,prepareGitRuntimePromotion().restore()re-checked authority after the rename but before recording completion, so a restore that finished and then lost authority could be replayed and delete the restored runtime (latent today because the only caller is memoized).Both corrections were made on the abandoned
release/2026.9.7branch during review of 008d0c4 and never reached main; this forward-ports them before that branch is deleted.Summary
git checkout --no-overwrite-ignore -B <branch> <beforeSha>: while this worktree holds the branch, Git refuses any other worktree's checkout,worktree add,branch -f, rebase or bisect of it, so the earlier probe-to-update-refwindow is gone. Porcelain checkout also refuses to overwrite ignored or untracked files (a review showedread-tree -m -udoes overwrite ignored files).checkout -Bhas no old-SHA check, so the step verifies the branch reflog transition (<branch>@{1}must be the activated SHA, the branch must bebeforeSha) and otherwise fails closed with the concurrently written SHA and recovery commands; the previous runtime is retained.recoverable-maintenanceadvisory naming its creation SHA and a quotedgit branch -dhint. Autoreview showed no Git primitive can exclude a linked worktree that is mid-checkout of that branch, and a post-delete repair can be stranded by authority loss, so deleting it could still orphan another worktree. The non-retained path keeps its priorbranch -D.reset --keepstill discarded it), and never deletes the created dev branch in the retained path.update-runner-git-steps.tsand the retained-transaction cases intoupdate-runner-git-transactions.test-support.tsto stay within line caps (no cap changes).Evidence
Linked-worktree regressions (checkout and paused-bisect claims, for both delete and rewrite): 4 cases pass; retained-rollback selection 17 passed (single run ~70 s wall under host load; individual real-Git cases 3-6 s).
Baseline on unchanged main: 11 of the new retained-rollback cases failed (plus the runtime replay case); two controls passed.
After the fix: 77 update-runner-git tests passed, including all 13 retained-rollback cases and the runtime replay case. 12 existing cases that failed intermittently during a loaded local run also pass on pinned origin/main in isolation (host load, not this change).
Line-cap gates pass;
pnpm check:changedotherwise did not finish locally under host load, so the remaining lanes are covered by this PR's CI.Autoreview (branch mode): first round found the staged-content case (fixed, with regression); final round scoped-clean.
Final-effect proof (real Git, redacted)
Git 2.54.0; synthetic update fixtures through the real retained transaction (
devismainin these fixtures).Validation (head ecf3cc5)
node scripts/run-vitest.mjs run src/infra/update-runner-git-candidate.test.ts src/infra/update-runner-git-runtime.test.ts --maxWorkers=2: 100 passed, 240.9 s wall locally (real Git fixtures dominate).pnpm tsgo:core, core infra test typecheck, targeted oxlint, oxfmt,git diff --check: pass.Review round 4 (f65bc60)
git branch -frestore is only suggested when the branch still points at the rollback commit and the reflog shows a raw writer moved it before the rewrite; when someone wrote aftercheckout -B, the message reports the expected and observed SHAs and asks the operator to inspectgit reflog <branch>and keep the newest intended commit.git reflog exists+<branch>@{0}); without one, rollback refuses before touching the source (previous runtime retained) instead of refusing after the rewrite.git update-refimmediately aftercheckout -B-> rollback step fails closed, branch and HEAD stay at the operator's commitc7d2457, reflog showsmain@{1}= the rollback reset, stderr contains nobranch -fsuggestion, active runtime and previous-runtime backup retained. Reflog disabled (core.logAllRefUpdates=false, branch reflog removed) -> refused before mutation: branch/HEAD still at the activated commit, source unchanged. Both regressions failed before the fix; the raw-writer-before control keeps its safe restore guidance.Known edge (accepted)
Retained rollback refuses (before touching the checkout, previous-runtime backup kept, Gateway left stopped with guidance) only when branch reflogs are disabled and the branch reflog was deleted. Restarting the previous runtime alone is not safe here because plugin discovery and artifact fallback still read tracked candidate inputs from the checkout; see the PR comment for details. Follow-up for the update owner: retain all previous runtime inputs (or verify tracked inputs) so a checkout refusal can still bring the previous Gateway back.
Release note: Git-checkout updates no longer discard operator edits or rewrite/delete branches another worktree owns during rollback; a dev branch created by a failed update is kept with a cleanup hint.