Atomic Boot Sequence with Rollback: Designing a Fail-Safe OS Startup
LEO's Cognitive OS boot sequence starts services in topological dependency order and performs atomic rollback — stopping all previously started services in reverse order — if any critical service fails to start.
- Reference
- L014
- Project
- LEO
- Status
- Completed
- Evidence
- high
- Source
- 014-boot-sequence-atomic-rollback.md
Context
Many systems fail silently during startup: a service initialization error is caught, logged, and the system continues in a partially initialized state. LEO's architecture made a different choice.
From docs/14_BOOT_SEQUENCE.md:
If any critical subsystem fails to boot, the OS halts.
The boot sequence was implemented as an immutable 12-step sequence:
- Dependency Manager (resolves the boot DAG)
- Kernel
- Clock
- State Manager
- Interconnect
- Interrupt Controller
- Scheduler
- CMMU
- Resource Manager
- Architecture Guardian
- Provider Platform
- Remaining Services (non-critical)
The Question
How do you design an OS boot sequence that is safe in the presence of partial failures, respects dependency ordering, and provides clear failure diagnostics?
Initial Approach
The BootManager (backend/app/cognition/kernel/boot.py) implemented the following algorithm:
order = resolver.get_startup_order() # topological sort
started_services = []
for service_id in order:
lifecycle.transition(service_id, INITIALIZING)
instance.start()
lifecycle.transition(service_id, STARTING)
lifecycle.transition(service_id, RUNNING)
started_services.append(service_id)
# On failure:
lifecycle.transition(service_id, FAILED)
_rollback(started_services)
raise KernelException(f"Boot sequence aborted due to failure in {service_id}")Rollback (_rollback):
- Iterates
started_servicesin reverse (reverse topological order) - Calls
instance.stop()on each - Transitions each through
STOPPING→STOPPED - On rollback failure: transitions to
FAILEDand continues (best-effort)
What Happened
The boot sequence was implemented and executed successfully. The startup log (backend/startup.log) shows the complete boot sequence completing in 1.29 seconds for Phase v1.19.6.
The boot log shows:
PHASE4_STATUS=HEALTHYPROVIDER_LAYER_ACTIVE=TrueGEMINI_PROVIDER_AVAILABLE=True- 39 apps discovered by the App Registry
- 8 projects discovered by the Project Registry
- 73+ MCP tools registered
LEO CORE READY— Platform Version v1.19.6
One startup error was observed in the log:
Startup initialization failed: cannot access local variable 'text' where it is not associated with a valueThis error was at line 42 of the startup log but did not halt the boot — the system continued and reached READY state, suggesting this error was in a non-critical service (not a critical OS component that would trigger atomic rollback).
Evidence
backend/app/cognition/kernel/boot.py—BootManagerwithboot_sequence()and_rollback()backend/app/cognition/kernel/resolver.py—DependencyResolverfor topological sortdocs/14_BOOT_SEQUENCE.md— immutable 12-step boot orderbackend/startup.log— successful boot in 1.29 secondsbackend/startup.logline 42 — non-critical startup error that did not halt bootbackend/app/main.py—BootManagerwith all OS components registered in order
Diagnosis
Established: The boot sequence is implemented with topological ordering and atomic rollback. The startup log confirms a successful boot to READY state. The boot completed in 1.29 seconds.
Likely: The startup error at line 42 (cannot access local variable 'text') was in a non-critical service registered as is_service=True in main.py (the remaining services registered after the OS components). The two-category registration (is_service=False for critical OS components, is_service=True for remaining services) means non-critical services can fail without triggering the atomic rollback of the OS.
Unknown: Whether atomic rollback was ever triggered in testing. The rollback path is implemented but its correctness under actual failure conditions was not confirmed by available evidence.
What Changed
The startup error at line 42 was not documented as fixed in available material.
What I Learned
Separating critical OS components from non-critical services in the boot sequence is important for reliability. Critical components (kernel, scheduler, memory management, interconnect) that must succeed for the system to function should trigger atomic rollback on failure. Non-critical services (specific applications, integrations) should fail gracefully without affecting the OS boot.
The 1.29-second boot time for a system with 39 apps, 8 projects, and 73+ MCP tools is fast and suggests the boot sequence is IO-bound (connecting to PostgreSQL, Redis) rather than compute-bound.
What I Would Do Differently
Hindsight observation: The startup error at line 42 should be surfaced more prominently in the boot log and marked with a specific component identifier. A startup error that is silently swallowed (even if non-critical) should be logged at WARNING level with the component name so it can be tracked.
Broader Principle
OS boot sequences should enforce strict dependency ordering and provide atomic rollback for critical failures. Critical and non-critical components should be distinguished at boot registration time, not at runtime.
Technical References
backend/app/cognition/kernel/boot.pybackend/app/cognition/kernel/resolver.pybackend/app/main.pydocs/14_BOOT_SEQUENCE.mdbackend/startup.log
Failure sequence
On the record- Attempt
- The `BootManager` (`backend/app/cognition/kernel/boot.py`) implemented the following algorithm: ``` order = resolver.get_startup_order() # topological sort started_services = [] for service_id in order: lifecycle.transition(service_id, INITIALIZING) instance.start() lifecycle.transition(service_id, STARTING) lifecycle.transition(service_id, RUNNING) started_services.append(service_id) # On failure: lifecycle.transition(service_id, FAILED) _rollback(started_services) raise KernelException(f"Boot sequence aborted due to failure in {service_id}") ``` **Rollback** (`_rollback`): - Iterates `started_services` in reverse (reverse topological order) - Calls `instance.stop()` on each - Transitions each through `STOPPING` → `STOPPED` - On rollback failure: transitions to `FAILED` and continues (best-effort)
- Failure
- The boot sequence was implemented and executed successfully. The startup log (`backend/startup.log`) shows the complete boot sequence completing in **1.29 seconds** for Phase v1.19.6. The boot log shows: - `PHASE4_STATUS=HEALTHY` - `PROVIDER_LAYER_ACTIVE=True` - `GEMINI_PROVIDER_AVAILABLE=True` - 39 apps discovered by the App Registry - 8 projects discovered by the Project Registry - 73+ MCP tools registered - `LEO CORE READY` — Platform Version v1.19.6 One startup error was observed in the log: ``` Startup initialization failed: cannot access local variable 'text' where it is not associated with a value ``` This error was at line 42 of the startup log but did not halt the boot — the system continued and reached READY state, suggesting this error was in a non-critical service (not a critical OS component that would trigger atomic rollback).
- Diagnosis
- **Established:** The boot sequence is implemented with topological ordering and atomic rollback. The startup log confirms a successful boot to READY state. The boot completed in 1.29 seconds. **Likely:** The startup error at line 42 (`cannot access local variable 'text'`) was in a non-critical service registered as `is_service=True` in `main.py` (the remaining services registered after the OS components). The two-category registration (`is_service=False` for critical OS components, `is_service=True` for remaining services) means non-critical services can fail without triggering the atomic rollback of the OS. **Unknown:** Whether atomic rollback was ever triggered in testing. The rollback path is implemented but its correctness under actual failure conditions was not confirmed by available evidence.
- Lesson
- Separating critical OS components from non-critical services in the boot sequence is important for reliability. Critical components (kernel, scheduler, memory management, interconnect) that must succeed for the system to function should trigger atomic rollback on failure. Non-critical services (specific applications, integrations) should fail gracefully without affecting the OS boot. The 1.29-second boot time for a system with 39 apps, 8 projects, and 73+ MCP tools is fast and suggests the boot sequence is IO-bound (connecting to PostgreSQL, Redis) rather than compute-bound.
- Next iteration
- The startup error at line 42 was not documented as fixed in available material.