Skip to content

fix(deploy): the updater re-renders the AI Stack env files (#20724) - #20730

Merged
mrveiss merged 7 commits into
mainfrom
issue-20724-ai-stack-env
Nov 3, 2026
Merged

mrveiss merged 7 commits into
mainfrom
issue-20724-ai-stack-env

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

#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.
  • 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_tests 15560: 26 pass.
  • 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.

@mrveiss mrveiss added bug Something isn't working priority: high backend phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. 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
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between cd274e0 and 95ea827.

Files selected for processing: 5
  • autobot-slm-backend/ansible/roles/ai-stack/tasks/code_only.yml
  • autobot-slm-backend/ansible/roles/ai-stack/tasks/env_files.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
Walkthrough

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.

Changes: AI Stack environment provisioning

Layer / File(s) Summary
Environment file provisioning
autobot-slm-backend/ansible/roles/ai-stack/tasks/env_files.yml, autobot-slm-backend/ansible/roles/ai-stack/tasks/main.yml
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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6403609 and cd274e0.

Files selected for processing: 4
  • autobot-slm-backend/ansible/roles/ai-stack/tasks/env_files.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

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@mrveiss mrveiss left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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.
Low update tag-filter path, code_sync.py --tags !restart 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.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Comments

Nitpick Assert that the envfiles.yml include has no when condition.

49-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

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"

Open the source location

Nitpick Assert the config tag on each env render task.

85-87: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the config tag on each env render task.

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)

Open the source location

@mrveiss

mrveiss commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20730 (head cd274e0): APPROVE

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.

@mrveiss

mrveiss commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20730 (95ea827): APPROVE

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.

@mrveiss
mrveiss merged commit 80f0d0e into main Nov 3, 2026
77 of 83 checks passed
@mrveiss
mrveiss deleted the issue-20724-ai-stack-env branch November 3, 2026 23:32
mrveiss added a commit that referenced this pull request Nov 3, 2026
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant