Repository navigation
chore(merge-train): #20596 #21026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
chore(merge-train): #20596 #21026
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
b6823c2
feat(slm): roll back to a chosen earlier commit through the updater (…
mrveiss 45c517c
fix(slm): the rollback's audit error has its own name (#20214)
mrveiss fa7a80d
fix(slm): rollback refuses pre-support targets and the service key, a…
mrveiss 46b8733
chore(tests): repin the floors this branch's own files moved (#20214)
mrveiss 1bf9285
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 62e7a04
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] fdfe07c
Merge remote-tracking branch 'origin/main' into issue-20214-rollback
mrveiss 69be72c
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 443c2a0
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 82d8198
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 6a25359
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] f10b854
Merge main into issue-20214-rollback (#20214)
mrveiss c40c7ba
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] e3d8741
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 41cf135
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 0dc0abf
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 693018e
fix(rollback): bounded env read, shared git fixtures, muted-text toke…
mrveiss 8a61482
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 70cace1
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 9af9247
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] e2c3b3f
Merge remote-tracking branch into issue-20214-rollback
mrveiss 2f2d555
Merge main into issue-20214-rollback
mrveiss f7cb4ed
fix(rollback): code rollback tests restore sys.modules after their st…
mrveiss b92c15d
fix(rollback): scope leak-guard owner reuse to the owner's tree and k…
mrveiss e7961de
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 390a32e
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] d882bed
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] 353f31a
Merge #20596 @ d882bedf44 into the merge train
mrveiss c8df616
fix(train): regenerate SLM openapi.json and generated types for the r…
mrveiss cc88121
fix(train): reach floors return to mid-window on the merged tree (#17…
mrveiss 1de8310
fix(train): code rollback composable takes its logger from the kit (#…
mrveiss 626f1db
fix(train): SLM conftest real-loads the code rollback services (#20214)
mrveiss 894ecb3
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] a43d2bc
Merge main into the merge train
mrveiss 720fd85
fix(train): SLM conftest stays under the 600-line cap — real-loaded m…
mrveiss 759509b
fix(train): inline-lazy-singleton floor follows the merged tree's pyt…
mrveiss 1e85124
Merge main into issue-20214-rollback (auto-sync) [skip ci]
github-actions[bot] d2d8346
Merge remote-tracking branch 'origin/main' into train-2026-11-07-t88a
mrveiss 6e462b4
fix(train): real-loaded SLM schemas live under testkit; inline-lazy-s…
mrveiss 1cc261b
fix(slm): code rollback review fixes (#20214)
mrveiss d273b89
fix(slm): rollback statement-timeout test uses a DB-API mock, not a h…
mrveiss b553e06
Merge #20596 @ d273b89965 into the merge train
mrveiss 64d9f51
fix(train): inline-lazy-singleton floor follows the rebuilt train's t…
mrveiss 8cf728b
Merge remote-tracking branch 'origin/main' into train-2026-11-07-t88a
mrveiss 8c14c9d
fix(train): inline-lazy-singleton floor follows the merged tree (#21026)
mrveiss 019b45c
fix(train): T88a red CI — rollback node call through the shared clien…
mrveiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # Copyright 2025-2026 mrveiss | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # AutoBot - AI-Powered Automation Platform | ||
| # Author: mrveiss | ||
| """Roll back to an earlier commit through the builtin updater (#20214). | ||
|
|
||
| GET /code-sync/rollback/candidates the commits that may be chosen | ||
| GET /code-sync/rollback/preview what choosing one would do, and whether a migration is in the way | ||
| POST /code-sync/rollback start it (202, the update-all job; poll /update-all/status) | ||
|
|
||
| Mounted on the code-sync router (``api/__init__.py``), so it carries the include-level auth of | ||
| Update Everything, and takes the same per-request dependency (``get_current_user``). The work is in | ||
| ``services/code_rollback.py``; this module is the HTTP edge only. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Annotated | ||
|
|
||
| from fastapi import APIRouter, Depends, HTTPException, Query, Request, status | ||
| from sqlalchemy.ext.asyncio import AsyncSession | ||
|
|
||
| from api import code_sync as cs | ||
| from autobot_shared import node_proxy | ||
| from autobot_shared.logging_manager import get_logger | ||
| from models.rollback_schemas import ( | ||
| RollbackCandidates, | ||
| RollbackCommit, | ||
| RollbackDatabaseCheck, | ||
| RollbackPreview, | ||
| RollbackRequest, | ||
| ) | ||
| from services import rollback_audit | ||
| from services.auth import get_current_user, verify_internal_api_key | ||
| from services.code_rollback import Preflight, orchestrator, preflight, rollback_enabled | ||
| from services.database import get_db | ||
| from services.rollback_commits import CommitInfo, RollbackRefused, list_candidates | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
| _NOT_ENABLED = "Rollback is not enabled on this SLM (SLM_ROLLBACK_ENABLED is off)." | ||
| #: Machine-readable marker the screen keys on: only this 403 hides the panel; any other 403 is a denial to show. | ||
| FEATURE_DISABLED_CODE = "rollback_feature_disabled" | ||
| _PERSON_ONLY = "A person must do this: the service key cannot roll back." | ||
|
|
||
|
|
||
| def require_rollback_enabled() -> None: | ||
| """Router gate: every rollback route answers 403 while the feature is off (pending a host test, #20214).""" | ||
| if not rollback_enabled(): | ||
| raise HTTPException( | ||
| status_code=status.HTTP_403_FORBIDDEN, detail={"code": FEATURE_DISABLED_CODE, "message": _NOT_ENABLED} | ||
| ) | ||
|
|
||
|
|
||
| router = APIRouter(prefix="/rollback", tags=["code-sync"], dependencies=[Depends(require_rollback_enabled)]) | ||
|
|
||
| _AUDIT_DOWN = "The audit trail is unavailable, so the rollback was not started." | ||
|
|
||
|
|
||
| def _commit_model(info: CommitInfo, deployed: str | None) -> RollbackCommit: | ||
| return RollbackCommit( | ||
| commit=info.commit, short=info.short, date=info.date, subject=info.subject, is_deployed=info.commit == deployed | ||
| ) | ||
|
|
||
|
|
||
| def _actor(user: dict) -> str | None: | ||
| value = user.get("sub") or user.get("username") | ||
| return str(value) if value else None | ||
|
|
||
|
|
||
| def _named_person(request: Request, user: dict) -> str: | ||
| """The person acting. The internal service key passes the router gate; it must not start a rollback.""" | ||
| actor = _actor(user) | ||
| if actor is None or verify_internal_api_key(request.headers.get(node_proxy.INTERNAL_KEY_HEADER)): | ||
| raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=_PERSON_ONLY) | ||
| return actor | ||
|
|
||
|
|
||
| def _bad_request(exc: RollbackRefused) -> HTTPException: | ||
| return HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=exc.reason) | ||
|
|
||
|
|
||
| async def _source(db: AsyncSession): | ||
| tracker = await cs._get_tracker_for_db(db) | ||
| return tracker.repo_path, tracker.remote, tracker.branch | ||
|
|
||
|
|
||
| @router.get("/candidates") | ||
| async def rollback_candidates( | ||
| db: Annotated[AsyncSession, Depends(get_db)], | ||
| _: Annotated[dict, Depends(get_current_user)], | ||
| ) -> RollbackCandidates: | ||
| """The newest commits of the tracked branch, with dates and subjects, for the picker.""" | ||
| repo, remote, branch = await _source(db) | ||
| deployed = await cs._get_slm_deployed_commit() | ||
| try: | ||
| commits = await list_candidates(repo, remote, branch, deployed) | ||
| except RollbackRefused as exc: | ||
| raise _bad_request(exc) from exc | ||
| return RollbackCandidates( | ||
| branch=branch, deployed_commit=deployed, commits=[_commit_model(c, deployed) for c in commits] | ||
| ) | ||
|
|
||
|
|
||
| def _preview(result: Preflight) -> RollbackPreview: | ||
| return RollbackPreview( | ||
| commit=_commit_model(result.target, result.deployed), | ||
| allowed=result.refusal is None, | ||
| refusal=result.refusal, | ||
| checks=[RollbackDatabaseCheck(**vars(c)) for c in result.checks], | ||
| ) | ||
|
|
||
|
|
||
| @router.get("/preview") | ||
| async def rollback_preview( | ||
| commit: Annotated[str, Query(max_length=200)], | ||
| db: Annotated[AsyncSession, Depends(get_db)], | ||
| _: Annotated[dict, Depends(get_current_user)], | ||
| ) -> RollbackPreview: | ||
| """Validate one commit and say whether a database migration is in the way.""" | ||
| repo, remote, branch = await _source(db) | ||
| try: | ||
| return _preview(await preflight(repo, remote, branch, commit)) | ||
| except RollbackRefused as exc: | ||
| raise _bad_request(exc) from exc | ||
|
|
||
|
|
||
| async def _refuse(user: dict, commit: str | None, reason: str, code: int) -> HTTPException: | ||
| """Record a refusal (best effort: it stands either way) and build the response. | ||
|
|
||
| ``commit`` is only ever a validated commit id; client text that failed validation is never stored. | ||
| """ | ||
| try: | ||
| await rollback_audit.record_rollback( | ||
| actor=_actor(user), | ||
| commit=commit, | ||
| outcome=rollback_audit.DENIED, | ||
| phase=rollback_audit.PHASE_REQUESTED, | ||
| reason=reason, | ||
| ) | ||
| except rollback_audit.RollbackAuditUnavailable: | ||
| pass | ||
| return HTTPException(status_code=code, detail=reason) | ||
|
|
||
|
|
||
| async def _start_after_audit(user: dict, result: Preflight) -> cs.UpdateAllJob: | ||
| """Make the request durable, then start through the same gate Update Everything uses.""" | ||
| commit = result.target.commit | ||
| try: | ||
| await rollback_audit.record_rollback( | ||
| actor=_actor(user), commit=commit, outcome=rollback_audit.SUCCESS, phase=rollback_audit.PHASE_REQUESTED | ||
| ) | ||
| except rollback_audit.RollbackAuditUnavailable as exc: | ||
| raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=_AUDIT_DOWN) from exc | ||
| try: | ||
| async with cs._update_all_start_lock: | ||
| return await cs._start_update_all_locked(orchestrate=orchestrator(result.target, _actor(user))) | ||
| except HTTPException as exc: | ||
| raise await _refuse(user, commit, str(exc.detail), exc.status_code) from exc | ||
|
|
||
|
|
||
| @router.post("", status_code=status.HTTP_202_ACCEPTED) | ||
| async def start_rollback( | ||
| body: RollbackRequest, | ||
| request: Request, | ||
| db: Annotated[AsyncSession, Depends(get_db)], | ||
| user: Annotated[dict, Depends(get_current_user)], | ||
| ) -> cs.UpdateAllJob: | ||
| """Deploy the chosen earlier commit. Refused while an update runs or when a migration is in the way.""" | ||
| _named_person(request, user) | ||
| repo, remote, branch = await _source(db) | ||
| try: | ||
| result = await preflight(repo, remote, branch, body.commit) | ||
| except RollbackRefused as exc: | ||
| raise await _refuse(user, None, exc.reason, status.HTTP_400_BAD_REQUEST) from exc | ||
| if result.refusal is not None: | ||
| raise await _refuse(user, result.target.commit, result.refusal, status.HTTP_409_CONFLICT) | ||
| return await _start_after_audit(user, result) | ||
|
mrveiss marked this conversation as resolved.
Resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.