claw-code/.guardrails/docs/agentmcp/Sentinel Rollback Procedure...

1 line
3.2 KiB
Plaintext

Project Sentinel: Rollback & Disaster RecoveryVersion: 3.0.0-EnterpriseModule: 14-Workflow-RollbackMaps to: docs/workflows/ROLLBACK_PROCEDURES.mdScope: Automated detection of bad states, "Time Machine" functionality, and database state reversion.1. The "Undo" PhilosophyIn a high-velocity Agent environment, mistakes happen fast. Sentinel provides an "Instant Undo" capability that is safer and more precise than manual git commands. Sentinel rolls back not just the Files, but the State (DB) and the Context.2. The Micro-Rollback (Task Level)Used when an Agent goes down a rabbit hole and breaks the build during a single task.2.1 TriggerManual: Agent calls revert_changes().Automatic: run_tests fails 5 times consecutively (The "Thrashing" Rule).2.2 The Restore SequenceFile System: Sentinel executes git restore . and git clean -fd to wipe uncommitted changes.State DB: Sentinel reverts the tasks table status from review back to in_progress.Context: Sentinel injects a "Fresh Start" prompt:SYSTEM: Changes reverted. You are back at the start state of Task T-101. Please re-read the requirements and try a different approach.3. The Macro-Rollback (Release Level)Used when a bad deployment hits production or a bad merge hits main.3.1 The "Red Button" ToolCommand: emergency_rollback(target="production").Sentinel Protocol:Identify Last Known Good (LKG): Sentinel queries the audit_log for the last deployment event with status: success and health_check: passed.Git Revert: Sentinel creates a new PR that is the inverse of the offending merge.Fast-Track: This PR bypasses the standard "Review Queue" (Human Confirmation still required via HITL).Deploy: Once merged, Sentinel triggers the deploy pipeline for the LKG commit.4. Database & State RecoveryWhat happens if the Agent corrupts the Sentinel DB itself?4.1 The WAL GuardianSentinel uses SQLite in Write-Ahead Log (WAL) mode.Protection: Even if the Agent crashes the binary mid-write, the WAL ensures atomic durability.Recovery: On boot, Sentinel checks for a state.db-wal file. If present, it replays the log to restore consistency.4.2 SnapshottingFrequency: Every time a Sprint Status changes (e.g., Active -> Review).Location: .sentinel/snapshots/state-[timestamp].bak.Restoration:If state.db is corrupt/deleted:Sentinel boots in Recovery Mode.It lists available snapshots.User selects a snapshot via CLI.Sentinel restores the DB and aligns the Git HEAD to the snapshot's timestamp.5. The "Clean Slate" ProtocolSometimes, the Agent's context and workspace are so messed up (hallucinated files, broken deps) that a reset is the only option.5.1 The reset_workspace ToolScope: Destructive.Actions:git reset --hard origin/main (Align to remote).go clean -modcache / npm cache clean (Flush dependency caches).rm -rf build/ dist/ tmp/ (Flush artifacts).Preserves: .sentinel/state.db (So we don't lose task tracking).Use Case: Agent reports "Weird linker errors" or "Phantom files."6. Audit Trail of ReversalsEvery rollback is a learning opportunity.Log Entry: When a rollback occurs, Sentinel logs event_type: ROLLBACK.Metadata: Includes the Diff of the code that was thrown away.Analysis: At Sprint Retro, Sentinel presents a "Waste Report": "You generated 500 lines of code that were reverted. Main cause: Test failures."