You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(deploy): the updater re-renders the AI Stack env files (#20724) - #20730
#20724: the builtin updater applies the ai-stack role only through tasks_from: code_only. code_only.yml rendered the two systemd units but never ai-stack.env.j2, so a setting added to that template (for example the failsafe provider vars from #20654 for #19733) reached a node only on a full install. The backend already has this path (env_only.yml). The fix moves the env render into one task file that both the install and the update path include, so the two can't drift.
What Changed
New roles/ai-stack/tasks/env_files.yml holds the /etc/autobot dir task, the shared Redis credential read and adopt, and both ai-stack.env.j2 renders (the /etc/autobot env file and the install-dir .env). Every write task uses become: true, because the updater's play has no play-level become.
code_only.yml includes env_files.yml first, so the env file exists before the AI Stack unit that reads it as a mandatory EnvironmentFile.
main.yml drops its copies of those tasks. A fresh install still renders them, through its existing include of code_only.yml, before it starts the service.
test_redis_password_provisioned_16627.py now points its ai-stack consumer entry at env_files.yml.
Refs #20724. Its host criterion needs an update through the builtin updater and a check of the env file on an AI Stack node.
Verification
New tests/test_ai_stack_env_rerendered_on_update_20724.py: 4 pass. It covers three things. The updater reaches both renders. The env file is rendered before the unit. There is only one copy of the render, and the install path still renders before the service starts. A control checks that the finder sees a render. On the old code, the 3 behaviour tests fail and the control passes.
ansible-playbook --syntax-check passes on the role and on update-all-nodes.yml.
Not run on a host.
Model Used
Claude Opus 5.5
Summary by CodeRabbit
Bug Fixes
AI Stack environment settings are refreshed during updates and prepared before service units are configured, helping services start with current settings.
Existing Redis credentials are preserved when no replacement password is available. A configuration with an existing Redis password is not overwritten by an empty credential.
Tests
Added checks for environment configuration during updates and fresh installs, including availability before service startup and protection against overwriting existing credentials.
Notice: 29 open PRs — past the runaway threshold (25)
This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.
This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.
If the queue is draining normally, ignore this. Otherwise:
Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
Look for a loop opening near-identical PRs
Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.
The AI Stack role now provisions environment files through a shared task file. The code-only updater includes that task file before rendering service units. Tests check the update path, render destinations, task order, and Redis credential handling.
env_files.yml creates /etc/autobot, conditionally adopts the Redis credential, checks existing environment files when the credential is empty, and renders ai-stack.env.j2 to both destinations. The corresponding provisioning tasks were removed from main.yml.
Updater integration and validation autobot-slm-backend/ansible/roles/ai-stack/tasks/code_only.yml, autobot-slm-backend/ansible/roles/ai-stack/tasks/main.yml, autobot-slm-backend/tests/test_ai_stack_env_rerendered_on_update_20724.py, autobot-slm-backend/tests/test_redis_password_provisioned_16627.py
code_only.yml includes env_files.yml before the service-unit tasks. The service-files include gains the config tag. Tests check render destinations and order, duplicate renders, refusal conditions, and the credential consumer path.
Merge Risk: Moderate · previous review cd274
Environment rendering now reaches the updater correctly, but a failed credential-file read can allow an existing Redis password to be removed. Handle that error before merging.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names a fix to the deploy path: the updater now re-renders the AI Stack env files. The raw summary confirms this. code_only.yml now includes env_files.yml before the unit templates, and the …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names a fix to the deploy path: the updater now re-renders the AI Stack env files. The raw summary confirms this. code_only.yml now includes env_files.yml before the unit templates, and the new tests check that the updater reaches both env renders. The title is concise, specific and follows the conventional-commit style. It does not mention the Redis credential adoption or the removal of duplicate tasks from main.yml, but those are supporting details.
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 2 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Code review, head 821b7ee: APPROVE (one medium note, one low).
Severity
File:line
Issue
Fix
Medium
ai-stack role tasks/env_files.yml (Redis credential read + template tasks)
An update now overwrites the env file. If the SLM secrets file cannot be read during the run (the read is best-effort, run_once on the SLM) and no vault Redis password is set, the template drops the REDIS_PASSWORD/REDIS_USERNAME block and the AI stack loses Redis auth on the next restart. The shared reader's header says "callers keep what they already have", but a template render does not. The backend env render follows the same design, so this is consistent, not new.
Follow-up: fail the render, or skip it, when the read is empty and the target already contains a REDIS_PASSWORD= line.
When restart=false, the executor passes a single !restart tag. I could not confirm how ansible treats that value, and the include_role tags (ai-stack, deploy) do not carry config. This applies to every task in code_only, not just the new one. The restart ai-stack handler also fires at play end whenever the env changed, so a no-restart sync can still restart the service.
Note only. Confirm on a host.
Requested checks:
Every route gets the render. The maintenance UI, the REST code-sync and the scheduler all run update-all-nodes.yml, either with no tags or with !restart. They reach include_role ai-stack tasks_from: code_only on aiml hosts, and code_only.yml now includes env_files.yml first. Both templates render there. main.yml reaches the same file through code_only, so there is one copy.
Operator values and secrets.ai-stack.env.j2 has no inline secrets, only inventory variables and the Redis credential. The credential is adopted only when no password is already set. Hand-edits to the file are overwritten, but the same already happened on every install. There is no data-loss path other than the medium note above.
Does the test fail without the fix? Yes. Without env_files.yml, _tasks("env_files.yml") fails on a missing file. Without config on either include tag, test_a_config_only_run_still_reaches_the_renders fails. The one-copy test fails if a render returns to main.yml or code_only.yml, and there is a finder control. The tests are structural: they parse YAML and never run ansible. They do not pin the empty-Redis-read case, and they do not check that the update-all-nodes include_role carries config.
Not checked: no live ansible run, no --check run, no CI result.
Assert that the env_files.yml include has no when condition.
test_the_updater_reaches_both_env_renders checks only that the include exists. Ansible applies a when on an include_tasks to the include task itself. A false condition skips all of env_files.yml, so neither render runs. The test still passes in that state. Add an assertion that the include is unconditional, so the test detects this regression.
Suggested fix
- assert _index(code_only, "env_files.yml") >= 0+ include = code_only[_index(code_only, "env_files.yml")]+ assert "when" not in include, "the include must run on every update"
The test checks only the include-level tags. Tags on an include_tasks apply to the include itself, not to the tasks inside the included file. If a render task loses config, a --tags config run skips it, and this test still passes. Add an assertion on each render task.
🧪 Suggested test change
def test_a_config_only_run_still_reaches_the_renders() -> None:
- """An include's tags gate the tasks under it: `--tags config` must pass both includes to reach env_files."""+ """Tags on an include apply only to the include. Each render task needs its own `config` tag."""
main = _tasks("main.yml")
code_only = _tasks("code_only.yml")
assert "config" in main[_index(main, "code_only.yml")]["tags"]
assert "config" in code_only[_index(code_only, "env_files.yml")]["tags"]
+ renders = [+ t+ for t in _tasks("env_files.yml")+ if (t.get("ansible.builtin.template") or {}).get("src") == "ai-stack.env.j2"+ ]+ assert len(renders) == 2+ assert all("config" in t["tags"] for t in renders)
Reviewed 821b7ee843..cd274e041c (roles/ai-stack/tasks/env_files.yml and its test). The refusal's when is correct for every case:
Case
ai_redis_password
Check task
Result
No password, existing password in either file
empty
rc 0 for a file
refuse (fail before both templates)
Fresh install
empty
files missing, grep -qs rc 2 (or no match, rc 1)
render
Password present
non-empty
skipped
render (first condition false, short-circuits)
Check skipped, with or without a password
any
items have no rc
selectattr('rc','defined') drops them, so it cannot refuse
The fail task sits before both templates, so nothing is written on refusal. The test covers all four cases with the actual when clauses.
Severity
File:line
Issue
Fix
LOW
env_files.yml (check task)
In --check mode the command task is skipped, so the refusal does not preview. It fails open (renders), never wrongly refuses.
Optional: check_mode: false on the grep (read-only).
LOW
env_files.yml (fail task)
An operator who deliberately wants no Redis password on an existing node is refused until the file is edited by hand. The message does not say how to clear it deliberately.
Optional: mention that in the message.
Not checked: I did not run the role against a real node.
Delta review of 95ea827 against the boarded head cd274e0 (one commit, 2 files).
The probe is fail-closed: [ -e "$1" ] || exit 1 makes absent 1 by construction, grep gives 0 on a match and 1 on no match, and the refuse task now rejects only rc 1, so an unreadable file (rc 2) refuses.
The path goes in as $1, never interpolated into the script, so it can't inject.
failed_when: false keeps rc 2 from failing the probe itself; the refuse task decides.
The new test runs the task's own argv on absent, has, without and unreadable files; the unreadable case is skipped correctly when run as root.
No findings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thinking Path
#20724: the builtin updater applies the
ai-stackrole only throughtasks_from: code_only.code_only.ymlrendered the two systemd units but neverai-stack.env.j2, so a setting added to that template (for example the failsafe provider vars from #20654 for #19733) reached a node only on a full install. The backend already has this path (env_only.yml). The fix moves the env render into one task file that both the install and the update path include, so the two can't drift.What Changed
roles/ai-stack/tasks/env_files.ymlholds the/etc/autobotdir task, the shared Redis credential read and adopt, and bothai-stack.env.j2renders (the/etc/autobotenv file and the install-dir.env). Every write task usesbecome: true, because the updater's play has no play-level become.code_only.ymlincludesenv_files.ymlfirst, so the env file exists before the AI Stack unit that reads it as a mandatoryEnvironmentFile.main.ymldrops its copies of those tasks. A fresh install still renders them, through its existing include ofcode_only.yml, before it starts the service.test_redis_password_provisioned_16627.pynow points its ai-stack consumer entry atenv_files.yml.Refs #20724. Its host criterion needs an update through the builtin updater and a check of the env file on an AI Stack node.
Verification
tests/test_ai_stack_env_rerendered_on_update_20724.py: 4 pass. It covers three things. The updater reaches both renders. The env file is rendered before the unit. There is only one copy of the render, and the install path still renders before the service starts. A control checks that the finder sees a render. On the old code, the 3 behaviour tests fail and the control passes.test_redis_password_provisioned_16627.py: 22 pass.test_update_all_applies_roles_12959.py: 30 pass. security(chromadb): no CHROMA_SERVER_AUTHN configured — any internal-network container can reach chroma unauthenticated #12513 guard: 24 pass.repo_tests15560: 26 pass.ansible-playbook --syntax-checkpasses on the role and onupdate-all-nodes.yml.Model Used
Claude Opus 5.5
Summary by CodeRabbit