Repository navigation
Description
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/resetclears 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-fleetthen re-runs full provisioning over the selected nodes, including the clean phase above.- The 409 in-flight guard reads an in-memory
_provision_statewith 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
- 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. - Never
state: absenta path that holds persistent data. Either delete only the code subtrees and leavedata/untouched, or refuse whendata/exists and report it. A cleanup task should not be able to remove a database. - 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.
resetshould 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.- 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_*_activefact 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: absenttask is gated on adefault=falselookup.
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
test(provision): follow the safety decision instead of the old inline…
fix(provision): the rescue path must not destroy the data it is run t…
mrveiss commentedon Aug 23, 2026
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
role_*_activefact never deletes a directory; it skips and logs.state: absenttask is gated on a defaulting lookup — both spellings, no exceptions.Still open
.slm_keysintact, 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._provision_stateinapi/setup_wizard.pyis 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_dependenciesresolves 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.github-actions commentedon Aug 23, 2026
PR #14858 (merged to
Dev_new_gui) references this issue with a close keyword.If this issue is fully resolved, close it manually. If work remains, no action is needed.
fix(provision): stop the fleet cleanup removing the protected config …
style(provision): apply black formatting to the cleanup guard (#14856)
mrveiss commentedon Aug 23, 2026
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: absenttasks targeting a component directory, and only the two already fixed were guarded.playbooks/cleanup-nodes.ymlremoved 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.ymlandplaybooks/remove-role.ymlhad 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.
test(provision): pin that every delegated removal path resolves to th…
fix(provision): move become off the task include, and report what the…
fix(provision): route every component removal through one data-guarde…
github-actions commentedon Aug 23, 2026
PR #14890 (merged to
Dev_new_gui) references this issue with a close keyword.If this issue is fully resolved, close it manually. If work remains, no action is needed.
fix(setup-wizard): bound the provision-fleet 409 lock by staleness, n…
fix(config): split ai env registrations out of env_registry.py (#14856)
fix(config): keep baselined ai vars in place, avoid the growth-guard'…
fix(config): register the provision staleness TTL, split env_registry…
mrveiss commentedon Aug 28, 2026
Verification against merged
Dev_new_gui— NOT closingCloses #14856never fires onDev_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).role_*_activefact never deletes; it skips and logsansible/roles/_shared/tasks/clean_wrong_node_dir.yml:32-70: the fact is normalised once withdefault='', deletion is gated on membership of an explicit false-token allowlist, and an undecidable value takes adebugbranch 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)ansible/roles/_shared/tasks/remove_component_dir.yml, which stats<dir>/dataas root and deletes onlywhen: not (_remove_dir_data.stat.exists | default(true))— thedefault(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 >50state: absenttasks so it cannot pass vacuously), branch tests at:817and:831autobot-slm-backend/api/setup_wizard.py:1220-1244returns 409 only whenstatus == "running"andnot _provision_is_stale(...); staleness is judged onlast_progress_at, marked per output line at:1046. Bound is env-backed, not hardcoded:services/provision_progress.py:43PROVISION_STALE_SECONDS = env_int_clamped("AUTOBOT_PROVISION_STALE_SECONDS", 1800, min_v=60), registered inautobot_shared/env_registry.py(#15094). Test:autobot-slm-backend/tests/api/test_setup_wizard_stale_provision_14856.pystate: absenttask is gated on adefault=falselookuptests/test_cleanup_never_destroys_data_14856.py:747test_nothing_on_the_delete_path_defaults_to_false, parametrised per file on the delete pathWhat 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.
mrveiss commentedon Aug 30, 2026
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.ymlon this install matches the merged version:default='', notdefault=false; deletion gated on membership of an explicit false-token allowlist; an undecidable value takes the:57branch 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:
data/data/Backend databases, with sizes and mtimes at time of capture:
project_state_tracking.dbconversation_files.dbtranscriber.dbunified_memory.dbautobot_data.dbproject_state.dbdata/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.dbandautobot_data.dbare written by normal operation, so a mtime change on those two proves nothing on its own — the ones that must not move areunified_memory.db,conversation_files.db,transcriber.db,project_state.db, and theservice-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. Astate: absenton 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".