Galaxy Shell / docs
Docs / Arquitetura e desenvolvimento

Independent conversation recovery

openspec/specs/automatic-recovery/spec.md · Editar no GitHub ↗

Esta página ainda não tem tradução em português. O conteúdo abaixo está em inglês.

Nesta página

Independent conversation recovery

Purpose

Recovers the conversation environment after a host, core or compositor failure through independent supervisors that do not depend on a model or provider, preserving profile and history.

Requirements

Requirement: Current backend and historical River policy

The current backend SHALL be Smithay, and the Historical River policy section MUST NOT guide the current operation. Full text: section Introduction.

Scenario: Reading the doc

  • WHEN an operator looks for current recovery behavior
  • THEN the Smithay policy applies and the River section is only historical evidence

Requirement: Single fallback attempt

After a non-zero failure the Smithay policy SHALL allow only one attempt with a configured fallback release that is a different sibling release; without a fallback or after it fails the session SHALL end and return to GDM, with no unlimited restart cycle. Full text: section Smithay session policy.

Scenario: Fallback fails

  • WHEN the fallback release also fails
  • THEN the session ends and returns to GDM

Requirement: No fallback on intentional exit

An intentional logout with exit zero, a handled termination signal and a busy profile lock SHALL NOT trigger the fallback, and locks MUST NOT be removed to force recovery. Full text: section Smithay session policy.

Scenario: Logout

  • WHEN the user logs out with exit zero
  • THEN the fallback is not triggered

Requirement: Profile outside releases

The profile, conversations, credentials and custom UI SHALL stay outside the releases, and rollback MUST NOT replace them. Full text: section Smithay session policy.

Scenario: Rollback

  • WHEN a rollback to the fallback release happens
  • THEN profile, conversations, credentials and custom UI are not replaced

Requirement: Planned recovery preconditions

Before a planned recovery the operator SHALL hold coordination.lock, reread the log, confirm no answer or change is in progress and persist the plan and the rollback; recovery MUST work without an available provider or conversation. Full text: section Before any planned recovery.

Scenario: Provider down

  • WHEN the provider is unavailable
  • THEN recovery still works

Requirement: Continuous unavailability deadline

The Smithay deadline SHALL measure 90 seconds of continuous shell unavailability, and each healthy observation SHALL reset the recovery count. Full text: section Fix for the activation failure of 2026-10-27.

Scenario: Healthy observation

  • WHEN a healthy observation occurs
  • THEN the recovery count resets

Requirement: Signals only to the generation's own runtime

Cleanup SHALL signal only executables of the runtime of that Electron generation; external applications and cores of other generations MUST stay intact. Full text: section Fix for the activation failure of 2026-10-27.

Scenario: Other generation

  • WHEN another generation of the same core runs
  • THEN it is not ended

Requirement: Policy update leaves processes alone

The policy update command SHALL send no signals to the compositor, host or core, hold coordination.lock, and run with the chat idle because concurrent profile changes abort the switch. Full text: section Policy update without restarting the compositor.

Scenario: Concurrent change

  • WHEN the profile changes during the switch
  • THEN the switch aborts

Requirement: Candidate policy limits and rollback

A candidate policy MUST NOT order the end of healthy processes or shorten the guardian's minimum tolerance; an exception, a one-second timeout or an invalid decision SHALL restore the earlier policy, and a 40-second lease SHALL undo the switch if the coordinator disappears before the commit. Full text: section Policy update without restarting the compositor.

Scenario: Candidate hangs

  • WHEN the candidate times out
  • THEN the earlier policy is restored

Requirement: Structural changes need a new login

The mechanism SHALL update only supervision policies; changes to the guardians, their protocol or the runtime executables MUST still require a new prepared login, and old supervisors SHALL refuse the operation before publishing any request. Full text: section Policy update without restarting the compositor.

Scenario: Old supervisor

  • WHEN an old supervisor receives the update
  • THEN it refuses before publishing any request

Status

Doc status: current contract. The Smithay session policy and the shell supervisor are current; the River policy section is history. Checked 2026-11-10.

Introduction

Implementation update: River was removed from the product. At login, the session can now load the active checkout in the home directory, with build preparation and independent Smithay recovery. See the current loading and recovery contract. The descriptions below preserve earlier decisions and evidence. Old releases can stay as known-good recovery, without bringing a River backend back into the product.

The current backend is Smithay. The shell supervisor recovers the host/core inside the existing session. The dispatcher keeps a separate Smithay fallback for a preparation or session failure. The River section below is historical evidence and must not guide the current operation. For a planned update that does not end applications, follow the current procedure.

Historical River policy

The agent-native-session launcher keeps a Python supervisor as the GDM session process. It starts River as a child and stays alive when the compositor crashes. The River init starts another Python supervisor, which is responsible for the Electron host, the core and the WM. None of these supervisors queries a model or depends on ChatGPT/OpenCode to decide to restart.

A core crash can make Electron exit with code zero. For this reason, the shell supervisor also restarts the host after a normal exit. It does not depend on Restart=on-failure. While River stays alive, recovery ends only the identified runtime processes. It does not kill the whole group or its external applications. Maintenance commands started in independent groups are not ended by the watchdog. A hung core is identified by consecutive failures on /health. A disconnected WM also causes a shell restart. The endpoint answers only on loopback and contains four health flags, with no history, credentials or profile content.

After the initial tolerance of 60 seconds, three failed probes trigger recovery. The query runs every two seconds and has a timeout of two seconds. Provider unavailability is reported as ready=false, but it does not cause endless restarts if the core and the WM keep answering. The AI does not automatically redo interrupted messages or commands, because a repetition could duplicate effects.

If River ends by failure or signal, the session supervisor ends the old supervisor/host, changes the generation identifier and starts River and the shell again with the same profile. An intentional River exit with code zero ends the session and allows a return to login. Wayland applications lose their connection when the compositor crashes. The mechanism recovers the conversation environment, not documents that are not yet saved or the state of arbitrary applications.

The attempts have a growing wait of up to ten seconds. Three failures within three minutes try an earlier release known to be good, inside the same installation. The rejected release stays in quarantine in the profile and is not chosen again at the next login until another release is installed or the policy is explicitly corrected. The first installation does not invent an earlier version: a validated release must exist. A release that stays healthy for ten seconds is recorded, and the earlier one stays as fallback. Compatibility with releases that predate /health uses the existing local API only in memory, without recording a token or history.

Private state and metadata live in the profile: supervisor-session.json, supervisor-shell.json, their policies supervisor-*-policy.json and supervisor.log, with rotation at about 1 MiB. system_context exposes the two summaries with an indication of recent update. Separate locks per mode prevent two instances on the same profile. The supervisor does not delete locks, databases, checkpoints or conversations to force a start. PID and start time are checked before ending processes.

The existing GDM installation calls ~/.local/bin/agent-native-session. The next login goes through the new supervisor automatically. A session that started by running River directly cannot get another parent process through a shell update. In that session, the core protection can be activated immediately, but the compositor protection needs a new entry through the login screen. This chat does not need to stay open after that.

Tests: npm test in web-shell/ and npm run test:supervisor. The supervisor tests exercise a compositor crash, a core freeze with SIGSTOP, preservation of a sentinel application, data continuity, instance exclusion, intentional exit and rollback after three defective starts. An isolated River run also lets the team validate the real process chain without taking down the desktop in use.

Smithay session policy

The agent-native-smithay-session launcher starts scripts/smithay-session.py, which waits for the Wayland and control sockets before it starts the shell supervisor. The shell supervisor recovers the host/core without restarting a healthy compositor. The effective chain depends on the launcher and the release used at login. Updating files or links does not replace the parent supervisor that is already running.

The Smithay policy differs from the progressive retry of River. After a failure with a non-zero result, it allows only one attempt with a configured fallback release. The previous attempt ends its own children and releases locks before that. The fallback must be a different sibling release. The installer writes fallback-root.txt when it receives a Smithay base that is compatible with this condition. Without a fallback, or after the fallback fails, the session ends and returns to GDM. There is no unlimited restart cycle.

An intentional logout with exit zero, a handled termination signal and a busy profile lock do not trigger the fallback. Do not remove locks to force recovery. Private metadata lives in supervisor-smithay-recovery.json, with the phase and the requested, active and fallback roots. The profile, conversations, credentials and custom UI stay outside the releases and rollback does not replace them. A compositor crash disconnects the Wayland applications and can lose unsaved content.

Python tests with synthetic processes validated this policy, including a defective fallback, profile preservation and exclusion by lock. The team did not cause a compositor crash on the shared desktop to prove it. See the Smithay evidence. The earlier reports of a direct return to GDM describe the version before the fallback attempt.

Before any planned recovery

Discover the real session, backend, release, profile, sockets and supervisor, as AGENTS.md describes. Hold coordination.lock, reread the log and confirm that no answer or change is in progress. Persist the plan and the rollback before the switch. Preserve the compositor and the applications when updating the host/core is enough. Recovery must work without an available provider or conversation. A publication to main does not prove activation at login.

Fix for the activation failure of 2026-10-27

The Smithay deadline now measures 90 seconds of continuous shell unavailability. The earlier code checked health only at the end of 90-second cycles. A restart close to the next check could end the compositor within a few seconds. Each healthy observation now resets the recovery count.

The supervisor marks each Electron generation with a private identifier that the core inherits. Cleanup recognizes its own processes that were reparented after an early host exit, including before the first inspection. Only executables of the runtime of that generation receive signals. External applications and cores of other generations stay intact. The core ownership test tells a zombie PID from a live process, and it preserves the earlier lock as evidence before the new start.

Regressions use synthetic processes. Recovery after a long healthy session keeps the compositor PID. An immediate host exit collects its orphan core and allows the fallback. A core freeze recovers the shell and preserves the history and a sentinel application. Another generation of the same core is not ended. A real zombie PID does not block profile ownership. These tests do not end the shared graphical session.

Python supervisors that are already loaded keep the old code in memory. Updating the sources and the dispatcher prepares the fixes for the next login, without changing the existing compositor. Do not replace the parent process of the session to try to apply this fix live. If the trusted UI is already active, confirm its assets, the DOM, the profile and the continuity, without repeating an unnecessary host switch.

Activation evidence

On 2026-10-26, release release-fmMX2Jjl passed the 77 Node tests and five Python tests. In a synthetic profile, a real River run with a headless backend, Electron and a synthetic OpenCode transport recovered from both SIGKILL of the core and SIGKILL of the compositor, with an identical comparison of session IDs and messages. The QA run ended after the test and did not query an AI provider.

On the GDM desktop in use, the user unit agent-native-shell-recovery.service activated the shell supervisor. A real SIGKILL of the core recovered automatically, and the history comparison was identical. River PID 2451 and ChatGPT PID 3377 stayed the same. The team checked the interface at the new loopback address, and it kept the history, the model and the send control enabled. The current session still has River as a direct child of GDM. The compositor protection takes effect at the next entry through the Agentic Shell session, through the launcher that is already installed. There was no destructive test of the compositor of the desktop in use.

Policy update without restarting the compositor

The prepared next login starts two stable guardians: the session dispatcher and the shell supervisor. They keep their PIDs, children, descriptors, locks and recovery clocks. The health decisions live in versioned Python workers, separate from the processes that own those resources. The configurator copies the guardians, the worker, the protocol and the initial policy to the same private dispatch directory. Changing the checkout does not change that running bootstrap.

After entering through that bootstrap, authenticated maintenance can run:

python3 scripts/update-supervisors.py --policy scripts/supervisor_policy.py

The command uses the profile configured in project.json, holds coordination.lock and sends no signals to the compositor, host or core. It checks the owners by PID and process start, preserves hashes of the conversation/interface files and verifies the core and the protected children during the whole operation. Run it with the chat idle: concurrent profile changes abort the switch. Generated HTML and the renderer have no access to it.

The candidate gets a snapshot by SHA-256 and goes through the decision contract of the two roles. Both prepare before activation. During the three-second probation, the earlier policy stays alive for rollback. An exception, a one-second timeout or an invalid decision restores the earlier one. The candidate cannot order the end of healthy processes or shorten the minimum tolerance of the guardian. The commit persists the earlier version for later recovery. If the coordinator disappears before the commit, a 40-second lease undoes the switch even if request.json was removed or corrupted. A later policy failure also restores the earlier one. Without a working worker, the guardian keeps the built-in basic decisions.

Workers run maintenance code with the privileges of the user. The process separation contains failures and hangs. It is not a security sandbox. This mechanism updates the supervision policies, not arbitrary code of the guardians, their protocol or the runtime executables. Those structural changes still require a new prepared login. Old supervisors refuse the operation before they publish any request: there is no safe retroactive installation of this protocol in the earlier session.

The tests use two guardians and real synthetic children to prove the switch, rollback by exception and by hang, expiry without a coordinator, late failure, busy lock and incompatible bootstrap. They compare PID/start of the guardians, compositor, host, core and sentinel application, the inode of the sockets, the exclusivity of the locks and the bytes of the conversations/interface. They do not cause a crash or a new login on the shared desktop.