Skip to content

CRITICAL(provision): re-running the wizard can delete live databases — an undefined role fact is the delete branch #14856

Closed

Description

@mrveiss

A re-run can delete live databases, and an undefined fact is what triggers it

roles/_shared/tasks/clean_wrong_node_dir.yml deletes a whole component directory when a role-active fact is falsy:

- name: "{{ caller_role }} | Clean: wrong-node {{ dir_name }} dir"
  ansible.builtin.file:
    path: "/opt/autobot/{{ dir_name }}"
    state: absent
  when: not (lookup('vars', role_check_fact, default=false) | bool)

Two properties combine badly.

1. The default is destructive. default=false means an undefined fact is treated as "role inactive", which is the delete branch. The task's own header says so plainly — "which would mean 'role inactive' anyway". So the failure mode of "the fact never got defined" is not "skip", it is "remove the directory".

2. The directory is not just code. On a deployed host:

/opt/autobot/autobot-backend       5.9G   data/unified_memory.db
                                          data/conversation_files.db
                                          data/transcriber.db
                                          data/service-keys
/opt/autobot/autobot-slm-backend   201M   data/.slm_keys

state: absent on the parent removes data/ with it. That is live application state and key material, not rebuildable artifacts.

Callers include roles/ai-stack/tasks/clean.yml, which the ai-stack role runs unconditionally at task 12, before anything else.

Why "undefined" is a realistic state, not a hypothetical

The role_*_active facts come from inventory/group_vars/all.yml, and group_vars is only auto-discovered when ansible is given an inventory directory. services/deployment.py invokes playbooks with a bare host string at two call sites:

ansible_cmd, str(playbook_path), "-i", f"{host},",

There is no sibling group_vars/, so on that path the facts exist only if the playbook loads them explicitly through vars_files. #14289 already documents this exact hazard for chromadb_service_owner and guards deploy.yml's vars_files entry for it. Any playbook reaching clean_wrong_node_dir.yml without that load has undefined facts — and undefined means delete.

This is also the same fact family that has needed four corrections recently: #14513 (detected roles), #14560 (declared-only gating), #14666 (raw union), #14682 (ai_stack conflated with an LLM runtime). Each of those was a case of a role_*_active fact being wrong. When the fact is wrong in the false direction, this task deletes a live directory.

What repeated wizard runs do today

  • POST /setup-wizard/reset clears exactly three Settings keys — setup_wizard_completed, setup_wizard_current_step, setup_wizard_completed_steps. It resets UI progress only and reconciles nothing about the system.
  • POST /setup-wizard/provision-fleet then re-runs full provisioning over the selected nodes, including the clean phase above.
  • The 409 in-flight guard reads an in-memory _provision_state with no staleness bound, so a wedged run blocks every future provision until the process restarts — the same shape as a wedged update-all job locks out every future update with no in-band way to clear it #14703, which was fixed for update-all but not here.

So "run the wizard again" is not a resume and not a no-op; it is a fresh destructive provisioning pass whose safety depends entirely on the role facts being both defined and correct.

How it should behave

  1. Deletion must never be the default branch. Require the fact to be explicitly true-that-it-is-absent, i.e. when: role_check_fact is defined and not (role_check_fact | bool). An undefined fact must skip and warn, never delete. This alone removes the fail-destructive path.
  2. Never state: absent a path that holds persistent data. Either delete only the code subtrees and leave data/ untouched, or refuse when data/ exists and report it. A cleanup task should not be able to remove a database.
  3. Re-running the wizard must be idempotent by default. Provisioning an already-provisioned node should converge, not clean-and-rebuild. Destructive cleanup belongs behind an explicit, separately-confirmed action — not inside the path a user re-enters to change one setting.
  4. reset should say what it does. It resets progress, not the system. If "start over" is meant to reconcile a partially-provisioned fleet, that is a different operation and needs its own name and its own confirmation.
  5. Bound the in-flight guard, as a wedged update-all job locks out every future update with no in-band way to clear it #14703 did for update-all: judge staleness on progress so a wedged provision cannot lock out every later run.

Acceptance criteria

  • An undefined role_*_active fact never deletes a directory; it skips and logs.
  • No cleanup task can remove a directory containing persistent data; verified against the real layout above.
  • A repeated provisioning run over an already-provisioned node changes no data, proven on a host rather than from the diff.
  • The provision 409 guard cannot wedge indefinitely.
  • A guard test that fails if a state: absent task is gated on a default=false lookup.

Related

#14289 (the -i "<host>," / group_vars hazard), #14678 (the facts' triplication), #14513, #14560, #14666, #14682 (four corrections to these same facts), #14703 (the in-memory guard pattern already fixed elsewhere).

Activity

  1. mrveiss commented on Aug 23, 2026

    @mrveiss
    OwnerAuthor

    Partial delivery merged as 754896e03004de9811715423d1d0ce4e51af32c2 (PR #14858). Deliberately left open — four of six acceptance criteria are met.

    Verified against the base tree, not the PR: neither deletion carries a fail-destructive default in any form, and the legacy path migrates before removing.

    Met

    • An undefined role_*_active fact never deletes a directory; it skips and logs.
    • No cleanup task can remove a directory containing persistent data.
    • Legacy directories are migrated to their canonical path rather than deleted.
    • A guard test fails if a state: absent task is gated on a defaulting lookup — both spellings, no exceptions.

    Still open

    • A repeated provisioning run over an already-provisioned node changes no data, proven on a host. This is host behaviour and cannot come from a diff. Partly observable already: a re-run on the test deployment left all four databases and .slm_keys intact, but that run failed at phase 7 before reaching the cleanup path on the affected node, so it is not the evidence this criterion asks for.
    • The provision 409 guard cannot wedge indefinitely. _provision_state in api/setup_wizard.py is still in-memory with no staleness bound — the same shape a wedged update-all job locks out every future update with no in-band way to clear it #14703 fixed for update-all. Kept out of a data-safety change on purpose: it is an availability bug, and mixing the two would have coupled them at merge.

    Related finding

    The phase 7 failure that surfaced during this work is a separate defect, filed as #14859: node_dependencies resolves from the declared-plus-detected union, so a node contaminated by #14513 (tracked in #14667) has nginx, nodejs, postgresql and python314 installed for roles it never declared. One node's stale detection blocks provisioning for the whole fleet.

  2. github-actions commented on Aug 23, 2026

    @github-actions
    Contributor

    PR #14858 (merged to Dev_new_gui) references this issue with a close keyword.

    fix(provision): the rescue path must not destroy the data it is run to save (#14856)

    If this issue is fully resolved, close it manually. If work remains, no action is needed.

  3. mrveiss commented on Aug 23, 2026

    @mrveiss
    OwnerAuthor

    Provisioning-side fix is open as #14890.

    It covers the class rather than the one condition: a sweep of both ansible trees found 61 state: absent tasks targeting a component directory, and only the two already fixed were guarded. playbooks/cleanup-nodes.yml removed 59 of them across seven plays with no condition at all — including the backend and SLM-backend component directories named in this issue — while its own header and closing summary told the operator that data was never removed. roles/slm_agent/tasks/clean.yml and playbooks/remove-role.yml had the same shape.

    All component removals now delegate to a single guarded task that probes for data/ and refuses rather than deleting, defaulting to keep whenever the probe gives no verdict. The wrong-node gate became an allowlist of explicitly-false tokens, which also closed a case the original fix left open: a fact rendering to an empty string was still reaching the delete branch.

    Acceptance criteria 1, 2 and 5 are delivered there. Criteria 3 (repeated provisioning changes no data, proven on a host) and 4 (the 409 guard cannot wedge) are wizard/API behaviour with a different risk profile, and are tracked in #14889 so they are not lost when this issue closes.

  4. github-actions commented on Aug 23, 2026

    @github-actions
    Contributor

    PR #14890 (merged to Dev_new_gui) references this issue with a close keyword.

    fix(provision): route every component removal through one data-guarded task, so an unknown fact cannot delete a database (#14856)

    If this issue is fully resolved, close it manually. If work remains, no action is needed.

  5. mrveiss commented on Aug 28, 2026

    @mrveiss
    OwnerAuthor

    Verification against merged Dev_new_gui — NOT closing

    Closes #14856 never fires on Dev_new_gui, so the merges below left this open mechanically. Four of the five criteria are met on the base; AC3 asks for host proof and nothing has been deployed.

    Merged commits: 754896e03, 744df346a (#14890), eae27e633 (#15090), f1b08542c (#15094).

    AC Evidence kind Verdict
    1. An undefined role_*_active fact never deletes; it skips and logs static + unit Met — ansible/roles/_shared/tasks/clean_wrong_node_dir.yml:32-70: the fact is normalised once with default='', deletion is gated on membership of an explicit false-token allowlist, and an undecidable value takes a debug branch that names the fact and leaves the directory. Tests: autobot-slm-backend/tests/test_cleanup_never_destroys_data_14856.py:863 (test_wrong_node_cleanup_takes_the_right_branch, parametrised in both directions) and :886 (test_wrong_node_undefined_fact_would_hard_error_rather_than_delete)
    2. No cleanup task can remove a directory containing persistent data static + unit Met — every component removal now routes through ansible/roles/_shared/tasks/remove_component_dir.yml, which stats <dir>/data as root and deletes only when: not (_remove_dir_data.stat.exists | default(true)) — the default(true) is the guard, so a probe that did not run refuses. Refusal is reported, not silent. Sweep test at :379 (test_no_component_directory_is_removed_outside_the_primitive, with floors of >100 ansible files and >50 state: absent tasks so it cannot pass vacuously), branch tests at :817 and :831
    3. A repeated provisioning run over an already-provisioned node changes no data, proven on a host host NOT met — the criterion names host proof explicitly and there is none. Nothing has been deployed; the base has not run against a node. Code review of the guards is exactly the evidence this AC was written to exclude.
    4. The provision 409 guard cannot wedge indefinitely static + unit Met — autobot-slm-backend/api/setup_wizard.py:1220-1244 returns 409 only when status == "running" and not _provision_is_stale(...); staleness is judged on last_progress_at, marked per output line at :1046. Bound is env-backed, not hardcoded: services/provision_progress.py:43 PROVISION_STALE_SECONDS = env_int_clamped("AUTOBOT_PROVISION_STALE_SECONDS", 1800, min_v=60), registered in autobot_shared/env_registry.py (#15094). Test: autobot-slm-backend/tests/api/test_setup_wizard_stale_provision_14856.py
    5. A guard test that fails if a state: absent task is gated on a default=false lookup static Met — tests/test_cleanup_never_destroys_data_14856.py:747 test_nothing_on_the_delete_path_defaults_to_false, parametrised per file on the delete path

    What remains

    One provisioning run over an already-provisioned node, with before/after evidence that data/ under each component directory is untouched — file counts and database mtimes, not a diff reading. That single measurement closes this.

    Could not prove

    AC3 in any form. Also not measured: that the 409 staleness bound behaves as intended against a genuinely wedged run on a host — the unit test covers the decision, not the deployment.

  6. mrveiss commented on Aug 30, 2026

    @mrveiss
    OwnerAuthor

    Host evidence on the two things around AC3 that were unverified — and why AC3 itself still is not met

    AC3 asks for a repeated provisioning run over an already-provisioned node, proven on a host. I have not run one and will not: running the provision wizard against a live install is not something I will do unprompted, and a partial or aborted run is exactly the scenario this issue is about. So AC3 stays open.

    Two things around it were unverified, and both are now settled.

    1. The fixed cleanup task is what is actually deployed

    Worth establishing separately, because "the fix is merged" and "the fix is what would run" are different claims, and only the second matters if someone provisions today. The deployed copy of roles/_shared/tasks/clean_wrong_node_dir.yml on this install matches the merged version:

    :38   _wrong_node_fact: "{{ lookup('vars', role_check_fact, default='') | string | trim | lower }}"
    :45   _wrong_node_false_tokens: ['false', 'no', 'off', '0', 'n', 'f']
    :57   when: _wrong_node_fact not in (_wrong_node_false_tokens + _wrong_node_true_tokens)
    :65   when: _wrong_node_fact in _wrong_node_false_tokens
    

    default='', not default=false; deletion gated on membership of an explicit false-token allowlist; an undecidable value takes the :57 branch rather than the delete branch. So the destructive default is gone from the code that would actually execute, not only from the repository.

    2. A "before" baseline, so AC3 becomes a measurement rather than a judgement

    The criterion asks for file counts and database mtimes rather than a diff reading. Captured now, so whoever runs the provisioning pass has something to compare against:

    Component total data/ files in data/
    backend 6.1G 1.7M 27
    slm-backend 204M 8.0K 2

    Backend databases, with sizes and mtimes at time of capture:

    file bytes mtime
    project_state_tracking.db 659456 2026-08-30 12:02
    conversation_files.db 98304 2026-08-29 08:07
    transcriber.db 61440 2026-07-25 09:41
    unified_memory.db 61440 2026-08-28 16:30
    autobot_data.db 45056 2026-08-30 10:18
    project_state.db 32768 2026-06-22 22:44

    data/service-keys/ holds 1 file (name withheld deliberately — it is key material).

    AC3 is then: run the provisioning pass over this already-provisioned node, re-capture the same table, and show the counts and mtimes are unchanged. Note that project_state_tracking.db and autobot_data.db are written by normal operation, so a mtime change on those two proves nothing on its own — the ones that must not move are unified_memory.db, conversation_files.db, transcriber.db, project_state.db, and the service-keys/ count.

    A factual correction to the issue's framing

    The problem statement says "5.9G of data sits under the directory it removes". On this install the component directory is 6.1G but data/ is 1.7M — the bulk is the virtualenv and code, which is rebuildable. That does not reduce the severity, and I want to be precise about why: the irreplaceable content is the databases and the key material, which are small. A state: absent on the parent still removes all of it, and no amount of the 6.1G being rebuildable makes the 1.7M recoverable.

    It does change the recovery story, though, and that is worth knowing before someone plans around the original figure: losing this directory is not "re-sync 6GB", it is "the key material and conversation state are gone, and the rest re-installs".

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions