Skip to content

feat(slm): roll back to a chosen earlier commit through the updater (#20214) - #20596

Closed
mrveiss wants to merge 2 commits into
mainfrom
issue-20214-rollback
Closed

mrveiss wants to merge 2 commits into
mainfrom
issue-20214-rollback

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

Updates go through the builtin updater only, but "deploy a specific commit" had no builtin path: the runbook told operators to check out an old commit and rsync it. The maintainer chose to add rollback: pick an earlier commit on the maintenance page, deploy through the updater path, and warn or refuse when a database migration is in the way.

What Changed

  • Off by default: SLM_ROLLBACK_ENABLED is false until a host test passes. Routes return 403 and the panel hides.
  • Supported targets only: a target must contain the code that reads the resume plan. Older commits aren't offered and are refused, because they would leave the SLM old and the fleet on main while reporting success.
  • A named person only: the internal key gets 403, and a denied row never stores the client's text.
  • Page: a panel on Code Sync lists up to 50 earlier versions by date and subject, never asking anyone for an id. Review shows what will happen, or the refusal with database and migration names.
  • Validation: the commit must be a full id, pass is_safe_ref, exist, and be an ancestor of origin/<branch>. Anything else gets 400 before anything runs. It is validated again after the fetch.
  • Migrations: refused when a database has applied something the target doesn't ship, for both databases, and when state can't be read. The page and runbook say what isn't checked: SQLite stores, Redis, ChromaDB, file formats and tables made at startup. No downgrade ever runs, as that would lose data (Umbrella: SLM Data hygiene page — detect and safely clean up orphaned data across services #17038). Target migrations are read with git show and ast, never executed.
  • Run: the same job, lock, gate, resume plan and progress view as Update Everything. The code_source pull is skipped, since the playbook checks out the ref itself. The ref survives the restart in the resume plan, which expires.
  • Audit: code.rollback, written before the run; if it can't be stored, the rollback is refused with 503.
  • Three things that would have gone wrong, fixed: Play 0's notify would have marked every node up to date at an old commit, so it is skipped for a rollback. _update_code_source resets to origin/main before each run, so the ref is passed on every run. A rollback leaves a detached HEAD that would fail the next update's pull, so _git_pull_local checks out the branch first.
  • Afterwards: nodes read OUTDATED against the latest. Update Everything, unchanged, returns to it.
  • docs/runbooks/CODE_UPDATE.md describes this.

Verification

Backend 190 pass, using real git in tmp_path for ancestry, migrations and the supported-target check. Ratchets 237 pass. CodeRollbackPanel.test.ts 6 pass with @autobot/ui mocked; it failed once in an earlier run and then passed three reruns, cause not found, so it may be flaky.

Reading the code, a supported target's _git_pull_local, _update_code_source and sync_deletions all cope with a detached HEAD, and the playbook's branch read can't fail the play. That is reading only.

Not safe to enable until run on a host

Nothing has run against a real playbook or host. The test before enabling: roll back to a supported earlier commit, then run Update Everything, and confirm the host updates forward. When that happens is the maintainer's call. Reasoned, not observed:

  • The git module with a commit as version, then with version: main from a detached HEAD on the next update.
  • sync_deletion_planner in the reverse direction: it should remove files added after the target.
  • OUTDATED being recomputed on heartbeat.

Known limits:

  • If the SLM can't read the backend's .env and Postgres, every rollback is refused as unknown. Whether that holds in a separate-machine layout isn't known.
  • Tables main.py makes through create_all rather than the runner or alembic aren't tracked, so a migration in the way there is missed.
  • After the run, a job reporting completed fails if any node's commit differs from the target. That only runs in the process that ran the job, so a run spanning the SLM's restart isn't re-checked.
  • Until the job ends, another update-all-nodes.yml run is pinned to the old commit by the resume plan, up to its 2-hour limit. Binding it to a job needs a change in code_sync.py. The runbook says not to start another sync during a rollback.
  • If the database is unreadable as a restarted process resumes the fleet stage, remaining nodes get main, not the target, with a warning.
  • When the SLM's own restart cuts the run, the final audit entry isn't written; the job status and update report are the record.
  • A rollback to the commit this SLM already runs is refused, even if nodes differ.
  • The CodeSyncView.vue change has no test that runs here, since its spec needs reka-ui, and vue-tsc was only checked for touched files.

Refs #20214

Model Used

Claude Opus 5.5

@mrveiss mrveiss added the phase:M1.1 install.sh completes, fails loudly and is safe label Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9acab51 and 1815d40.

Files ignored due to path filters: 2

  • autobot-slm-frontend/src/types/generated/api.ts is excluded by !**/generated/**
  • scripts/python_file_size_known_large.py is excluded by !scripts/python_file_size_known_large.py
Files selected for processing: 40

  • autobot-backend/services/audit/taxonomy.py
  • autobot-slm-backend/_slm_stub_lifetime.py
  • autobot-slm-backend/ansible/playbooks/update-all-nodes.yml
  • autobot-slm-backend/api/__init__.py
  • autobot-slm-backend/api/_resume_plan.py
  • autobot-slm-backend/api/code_rollback.py
  • autobot-slm-backend/api/code_rollback_test.py
  • autobot-slm-backend/api/code_sync.py
  • autobot-slm-backend/conftest.py
  • autobot-slm-backend/models/rollback_schemas.py
  • autobot-slm-backend/services/code_rollback.py
  • autobot-slm-backend/services/code_rollback_nodes_test.py
  • autobot-slm-backend/services/code_rollback_test.py
  • autobot-slm-backend/services/playbook_executor.py
  • autobot-slm-backend/services/rollback_audit.py
  • autobot-slm-backend/services/rollback_commits.py
  • autobot-slm-backend/services/rollback_commits_test.py
  • autobot-slm-backend/services/rollback_migrations.py
  • autobot-slm-backend/services/rollback_migrations_test.py
  • autobot-slm-backend/services/rollback_target.py
  • autobot-slm-backend/services/rollback_target_test.py
  • autobot-slm-backend/services/sync_orchestrator.py
  • autobot-slm-backend/services/sync_orchestrator_checkout_test.py
  • autobot-slm-backend/tests/api/test_resume_rollback_ref_20214.py
  • autobot-slm-backend/tests/api/test_resume_waits_for_detached_self_update_16644.py
  • autobot-slm-frontend/src/components/CodeRollbackPanel.test.ts
  • autobot-slm-frontend/src/components/CodeRollbackPanel.vue
  • autobot-slm-frontend/src/composables/useCodeRollback.ts
  • autobot-slm-frontend/src/locales/en.json
  • autobot-slm-frontend/src/views/CodeSyncView.vue
  • autobot_shared/env_registry_slm.py
  • autobot_shared/env_registry_slm_rollback.py
  • docs/developer/AUDIT_SYSTEMS.md
  • docs/developer/CLAUDE_WORKFLOW.md
  • docs/developer/ENV_VARS.md
  • docs/runbooks/CODE_UPDATE.md
  • repo_tests/audit_writer_single_source_17225_test.py
  • repo_tests/sys_modules_leak_guard.py
  • repo_tests/sys_modules_leak_guard_session_test.py
  • repo_tests/sys_modules_leak_guard_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@mrveiss

mrveiss commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20596 (head 45c517c): changes needed.

Read only; nothing was run. Ref validation is solid (a 40-hex sha, ancestor of origin/<branch>, re-validated after fetch), the migration check is right for the two databases it reads and refuses when unknown, and the audit precedes the run.

  • High, services/rollback_target.py _read_plan_ref, api/_resume_plan.py:77, api/code_sync.py fleet stage: after the SLM restarts onto the target, only the plan carries the ref, and code older than this PR can't read it. Rolling back to any commit predating this feature leaves the SLM on the old commit, deploys main to the fleet, and reports completed. Refuse targets without plan-reading code, or verify each node's commit equals the target before reporting success.
  • Medium, host test only: after a rollback code_source sits on a detached HEAD, and the pull fix exists only in new code, so the old updater's stage 2 may fail on every attempt, leaving the host unable to update forward. This is the most important host test: roll back to a pre-feature commit, then run Update Everything.
  • Medium, api/code_rollback.py:48-50, :119-131: _SM_OR_AGENT lets the internal key through, and _actor then records None. Refuse the key on this destructive action, as fix(kb): backup restore and delete send the filename the list returns (#19721) #20510 does. A denied row also stores the raw client string as its resource.
  • Medium, services/rollback_migrations.py: sqlite stores, Redis, ChromaDB, file formats and create_all tables aren't checked. The runbook says "both databases"; it must name what's unchecked.
    Low: a fresh plan pins any concurrent update-all-nodes.yml run to the old commit. Also for host testing: the deletion planner in reverse, heartbeat OUTDATED, and separate-machine layouts refusing as unknown. This shouldn't be relied on, or offered in the UI as ready, before that host test.

@mrveiss

mrveiss commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20596 (head 46b8733): approve, off by default.

Read only; nothing was run. Behind SLM_ROLLBACK_ENABLED, routes return 403 and the panel is hidden, so landing this changes nothing until it's enabled. Targets without the plan-reading code are refused, the internal key gets 403, and the page and runbook name what's unchecked. Enabling needs the owner's host test: roll back to a supported target, then run Update Everything, and confirm a run spanning the SLM restart ends with the fleet on the target, since the node-commit check covers only the process that ran it.

This was referenced Nov 2, 2026
@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Review findings from the train review fixed and pushed: 1cc261b (+ test follow-up d273b89, branch head d273b89).

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at d273b89

Verdict: APPROVE. Every expected fix is present in the code at this head; the 5 threads still open on train PR #21026 are resolved, the other 11 were already resolved.

Item Finding Status
check_migrations after fetch _revalidate_after_fetch re-runs check_migrations and fails the stage on any non-CLEAR verdict fixed
Strict ancestor require_before_deployed refuses equal, newer, unrelated and unknown; list_candidates starts the log at the deployed commit; preflight and post-fetch both re-check fixed
Resume ref _read_plan_ref is gone (asserted absent); resume_ref(plan) is read once, raises on a missing ref, and the fleet stage runs in resumed_scope; the test drives the real persister and real hook fixed
Confirm and picker confirm posts chosen.commit (the previewed commit) and requires allowed; picker disabled while checking fixed
Minors NULL code_version counted off-target; env-backed statement timeout (registered, documented); start_new_session plus kill_process_group; emitted job adopted without a re-fetch; 403 keyed on rollback_feature_disabled; failed reset on preview; weakref fallback with latest-owner tracking fixed
Generated SLM types The 403 detail is an HTTPException detail with no declared response model, so it is not in the OpenAPI schema; no regeneration needed no action
MagicMock psycopg2 connection Sync DB-API connection, not an AsyncSession; the one-fake-session guard does not scan inline mocks and there is no canonical psycopg2 fake acceptable
@autobot/ui createLogger exported from the package index ok
Hygiene no fixed sleeps, no line-number comments, no function over 30 lines in the touched rollback modules; touched ratcheted files did not grow ok
Nit (non-blocking) rollback_migrations.read_applied_backend imports the private _resolve_pg_db_url / _load_env_file from api.code_sync (service importing from an API module); a shared resolver used by both the forward migration and the preflight would remove the layering inversion and the chance of the two drifting follow-up
Nit (non-blocking) The preflight reads only this SLM's backend env; the database identity it checked is not shown to the operator. Showing host, port and database name (no credentials) in the check message would make a mismatch visible follow-up

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Landed on main via merge train #21026 (merge commit a0b419b). Every commit of head d273b89 is in main: git log --no-merges origin/main..d273b89965 is empty.

@mrveiss mrveiss closed this Nov 7, 2026
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 7, 2026
@mrveiss mrveiss reopened this Nov 18, 2026
@mrveiss

mrveiss commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Branch audit (zero-change deletion). This PR shows 0 changed files against main (head da7dd077c4): every change it carried is already in main. Closing and deleting the branch through this PR; it can be restored with the Restore branch button below.

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

Labels

phase:M1.1 install.sh completes, fails loudly and is safe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant