Skip to content

feat(admin): cleanup proposals in the admin page, and role manifests read from code_source (#20567) - #20576

Closed
mrveiss wants to merge 36 commits into
mainfrom
issue-20567-cleanup-proposals
Closed

mrveiss wants to merge 36 commits into
mainfrom
issue-20567-cleanup-proposals

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

Owner rule: people work in the UI, not API calls. Two decided cleanups had no way to be proposed from the UI: the .env.*~ copies of the secrets file, and the subscription_tier column (#19997). The approval registry fits: an action registered there runs on the server only after a human approves it.

Building this found a live problem. The SLM's manifest_loader reads role manifests from the autobot-infrastructure copy beside the install, which is not updated, and no role sets SLM_INFRA_BASE_DIR. Pre-flight checks use those manifests. So hosts read old manifests, and that "stale" directory is not unused.

What Changed

  • manifest_loader reads code_source's copy when it exists, else the base's own directory, so a checkout and an agent-only node keep working, and warns when there is none. This changes behaviour on every host: manifests become current on the next update.
  • New admin page, Cleanup proposals, showing each cleanup's status and a Propose button that goes to the review queue. Nothing is removed by proposing.
  • A registered, server_only action for .env.*~: keep the newest by mtime, remove the rest, as the maintainer chose. Refused when the install root is a checkout.
  • On a deployed host AUTOBOT_BASE_DIR is <install>/autobot-backend itself (read from the local install's env), so the action handles that as well as an install root.
  • Paths come from the server at execution, re-planned then, never from the request. A symlink or a path outside the root refuses. File contents are never opened.
  • A durable audit entry is committed before anything is removed; no entry means no removal. A second entry records how it ended.

Removing the stale directory is NOT here. Several modules may still read it, so #20578 establishes each reader, repoints it, and then adds the proposal.

Verification

See the test results in the commits: backend action and route tests using tmp_path only, loader tests on real directories, the view's spec, and the contract, i18n and fragmentation ratchets.

Limits:

  • adminRoutes.test.ts could not run locally: reka-ui does not resolve. CI is its first run.
  • That approval is never automatic rests on server_only plus the existing gate; the gate itself was not tested here.
  • Handles this node's files only.
  • A repeat Propose returns 409 on the .env.*~ route, tested with a mocked service only: the JSONB query was never run against a database. The existing column route can still create a duplicate proposal.
  • Not run on a host.

Refs #20567, #19997, #20517

Model Used

Claude Opus 5.5

Summary by CodeRabbit

  • New Features

    • Added an admin page to review cleanup proposals for old environment-file copies and an unused organisation-tier field.
    • Proposals require approval; the newest environment-file copy is retained. Cleanup is not performed when a proposal is submitted.
    • Infrastructure manifests can now be loaded from a code-source or installation copy, with an explicit setting taking precedence.
  • Safety

    • Cleanup checks reject unsafe file locations and record an audit trail before removing files.
  • Bug Fixes

    • Manifest loading now warns when no manifest directory is available.

@mrveiss mrveiss added the phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work label Nov 1, 2026
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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 46 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 dd95607 and 4440175.

Files selected for processing: 11

  • autobot-backend/api/admin_cleanup_proposals.py
  • autobot-backend/api/admin_cleanup_proposals_20567_test.py
  • autobot-backend/api/admin_cleanup_proposals_auth_20567_test.py
  • autobot-backend/api/internal_slm_credential_proposals_index_20046_test.py
  • autobot-backend/services/install_cleanup_actions.py
  • autobot-backend/services/install_cleanup_actions_20567_test.py
  • autobot-frontend/src/i18n/locales/en.json
  • autobot-frontend/src/router/__tests__/adminRoutes.test.ts
  • autobot-frontend/src/router/adminRoutes.ts
  • autobot-frontend/src/views/AdminCleanupProposalsView.vue
  • autobot-slm-backend/tests/services/manifest_loader_reads_code_source_20567_test.py
Walkthrough

The pull request adds an approval-based admin flow for cleaning older environment backup copies, including backend planning and execution, proposal APIs, and a frontend page. It also changes how the SLM backend selects its infrastructure manifest directory.

Changes: Environment-copy cleanup proposals

Layer / File(s) Summary
Plan and execute environment-copy cleanup
autobot-backend/services/install_cleanup_actions.py, autobot-backend/services/audit/taxonomy.py, autobot-backend/services/install_cleanup_actions_20567_test.py
The cleanup action plans older copies while keeping the newest, checks paths and approval conditions, records audit events, and removes approved targets. Tests cover cleanup outcomes, safeguards, and audit behaviour.
Admin status and proposal API
autobot-backend/api/schemas_cleanup_proposals.py, autobot-backend/api/admin_cleanup_proposals.py, autobot-backend/initialization/router_registry/core_routers.py, autobot-backend/api/admin_cleanup_proposals_20567_test.py, autobot-backend/api/admin_cleanup_proposals_auth_20567_test.py
The admin API reports cleanup status and creates pending proposals without file paths. The router is registered, and tests cover proposal responses and authentication.
Pending proposal uniqueness
autobot-backend/models/approval.py, autobot-backend/migrations/versions/20261106_112_approvals_pending_env_copies_cleanup_unique.py, autobot-backend/api/admin_cleanup_proposals_index_20567_test.py
The approval model and migration add a PostgreSQL partial unique index for pending environment-copy cleanup approvals. Tests cover conflicts and migration behaviour.
Admin cleanup proposal view
autobot-frontend/src/router/adminRoutes.ts, autobot-frontend/src/i18n/locales/en.json, autobot-frontend/src/views/AdminCleanupProposalsView.vue, autobot-frontend/src/views/__tests__/AdminCleanupProposalsView.spec.ts
The admin page displays status for two cleanup types, submits proposals, and links to approvals. The route, English translations, and tests support the view.

Infrastructure manifest resolution

Layer / File(s) Summary
Resolve infrastructure manifest directory
autobot-slm-backend/services/manifest_loader.py, autobot-slm-backend/tests/services/manifest_loader_reads_code_source_20567_test.py
The loader checks an explicit override first, then the code-source and installation directories. It warns when neither directory exists. Tests cover these selection cases and unavailable manifests.
Merge Risk: Moderate · previous review dd956

Resolve the cleanup safeguards and manifest-selection gap before merging. Cleanup can affect the wrong node or redirected directory, and an incomplete manifest tree can bypass role conflict checks. Concurrent requests and failed completion audits also need handling.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.93% 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 identifies both the admin cleanup proposals and the role-manifest loading change.
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: Docstring Coverage

Explanation

Docstring coverage is 25.93% 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 27 functions across 15 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

@github-actions

github-actions Bot commented Nov 1, 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.

@mrveiss

mrveiss commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20576 (head 5c1ee56): changes needed.

Read only; nothing was run, and CI is mostly cancelled so gives no signal. The approval and removal design is sound: server-only, verified human decider, durable intent first, paths re-planned at execution, symlinks refused, and a smuggled context path is ignored. The manifest change isn't:

  • High, services/manifest_loader.py:50-53: base_dir / "code_source" / "autobot-infrastructure" has no fallback. A checkout has no code_source sibling and an agent-only node has none, so load_all returns {}, and a missing manifest makes preflight allowed=True: port-conflict checks silently stop, which this PR set out to prevent. Try config.path.code_source_path and then the base's own directory, log when neither exists, and use the SSOT rather than the literal.
  • High: the body says only manifest_loader reads the directory. utils/error_catalog.py _candidate_paths, event_manager.py:43,61 and config/service_config.py:366 use autobot-infrastructure/shared/config, through PATH.CONFIG_DIR or the install root. It's unverified which resolve to this directory on a deployed host. Establish that, then re-point them or have plan_infrastructure_dir refuse.
  • Medium, install_cleanup_actions.py plan_infrastructure_dir: the gate only checks the new directory exists, not that this host runs the new loader, and the approval text doesn't say so. Refuse unless the loader resolves to code_source, or at least tell the approver.
  • Medium, manifest_loader_reads_code_source_20567_test.py: it matches source text and proves no behaviour. Build a loader; cover the missing-base case.
    Low: repeat Propose creates duplicate approvals; a failed rmtree is partial.

@mrveiss

mrveiss commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20576 (head e62508b): approve.

Read only; nothing was run. The stale-directory removal is out and owned by #20578. The loader tries the override, then code_source_path, then base_dir, and warns when none exists, with real-directory tests replacing the source-text test. A repeat Propose returns 409 on the env route; the column route can still duplicate, as stated. adminRoutes.test.ts runs first in CI.

@github-actions

github-actions Bot commented Nov 2, 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.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Auto-sync: merging main into issue-20567-cleanup-proposals conflicts

The sync aborted the merge and pushed nothing. Conflicts are information, so it never resolves one itself. Below, for each conflicted file, are the commits that touched it on each side since the merge base 7b3358f315. Merge main in yourself and push; the label clears on the first run that finds this branch 0 behind.

autobot-backend/api/admin_cleanup_proposals.py

side commit subject issue refs
main 9cec6261a1 fix(slm): satisfy admin-gate, unconnected-code guards after merging main (#20046) #20046
main 0a13682e6e fix(slm): round-2 review of the SSH-password deletion proposal - sudo probe, cleanup guards, atomic proposals, edge deny (#20046) #20046
main e62508b8f0 fix(admin): the stale-directory cleanup moves to #20578; manifests fall back to the install copy; no duplicate proposals (#20567) #20578, #20567
main 216915b0e4 feat(admin): cleanup proposals for .env copies, the stale directory and the tier column (#20567) #20567
this branch dd95607e2c fix(cleanup): admin gate tested through the real auth stack, pending proposal unique in the database, intent audit is attempted (#20567) #20567
this branch e62508b8f0 fix(admin): the stale-directory cleanup moves to #20578; manifests fall back to the install copy; no duplicate proposals (#20567) #20578, #20567
this branch 216915b0e4 feat(admin): cleanup proposals for .env copies, the stale directory and the tier column (#20567) #20567

autobot-backend/models/approval.py

side commit subject issue refs
main 0a13682e6e fix(slm): round-2 review of the SSH-password deletion proposal - sudo probe, cleanup guards, atomic proposals, edge deny (#20046) #20046
main ab55d41295 Merge main into issue-20046-ssh-password-proposal none
main 34dcb9bfa4 Merge remote-tracking branch 'origin/main' into issue-20046-ssh-password-proposal none
this branch dd95607e2c fix(cleanup): admin gate tested through the real auth stack, pending proposal unique in the database, intent audit is attempted (#20567) #20567
this branch 5b6a45954a Merge main into issue-20567-cleanup-proposals (#20567) #20567
this branch f9b32dd40b fix(merge): resolve the core_routers.py clash with #20445 into one implementation (#20567) #20445, #20567

autobot-backend/services/install_cleanup_actions.py

side commit subject issue refs
main 0a13682e6e fix(slm): round-2 review of the SSH-password deletion proposal - sudo probe, cleanup guards, atomic proposals, edge deny (#20046) #20046
main f9b32dd40b fix(merge): resolve the core_routers.py clash with #20445 into one implementation (#20567) #20445, #20567
main d201fc287a fix(admin): the .env cleanup finds the backend when the base dir already is it (#20567) #20567
main e62508b8f0 fix(admin): the stale-directory cleanup moves to #20578; manifests fall back to the install copy; no duplicate proposals (#20567) #20578, #20567
main 15201851ad fix(admin): cleanup removals are audited first, and role manifests come from code_source (#20567) #20567
main 216915b0e4 feat(admin): cleanup proposals for .env copies, the stale directory and the tier column (#20567) #20567
this branch dd95607e2c fix(cleanup): admin gate tested through the real auth stack, pending proposal unique in the database, intent audit is attempted (#20567) #20567
this branch f9b32dd40b fix(merge): resolve the core_routers.py clash with #20445 into one implementation (#20567) #20445, #20567
this branch d201fc287a fix(admin): the .env cleanup finds the backend when the base dir already is it (#20567) #20567
this branch e62508b8f0 fix(admin): the stale-directory cleanup moves to #20578; manifests fall back to the install copy; no duplicate proposals (#20567) #20578, #20567
this branch 15201851ad fix(admin): cleanup removals are audited first, and role manifests come from code_source (#20567) #20567
this branch 216915b0e4 feat(admin): cleanup proposals for .env copies, the stale directory and the tier column (#20567) #20567

autobot-frontend/src/types/generated/api.ts

side commit subject issue refs
main b538829e64 fix(train): T86 — #20587 types, observable 113, admin menu entry, async session mock, SLM loggers, test-loader router, deterministic ids (#20046) #20587, #20046
main 7b9596f713 Merge main into the merge train none
main 54daa85828 fix(company-os): make the unfiled-recovery notice company-wide and drop the ignored created_by_user_id (#20687) #20687
main ab55d41295 Merge main into issue-20046-ssh-password-proposal none
main 9cde5310e5 Merge main into issue-18978-hierarchy none
main b9edada413 Merge main into issue-20046-ssh-password-proposal (#20046) #20046
main f55b33c71e Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main e0b409e80c Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main de2fc37310 Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main 7ea4e2fa5c Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main e9059136bf Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main 4553e11991 Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main cba1c46171 Merge main into issue-20046-ssh-password-proposal (auto-sync) [skip ci] none
main 4baaaf1783 Merge main into issue-18978-hierarchy (auto-sync) [skip ci] none
main f9b32dd40b fix(merge): resolve the core_routers.py clash with #20445 into one implementation (#20567) #20445, #20567
main 10 more commit(s) not listed
this branch 5b6a45954a Merge main into issue-20567-cleanup-proposals (#20567) #20567
this branch d61b77fa9a Merge main into issue-20567-cleanup-proposals (auto-sync) [skip ci] none
this branch 0aa5520331 Merge main into issue-20567-cleanup-proposals (auto-sync) [skip ci] none
this branch 5d6fd8066e Merge main into issue-20567-cleanup-proposals (auto-sync) [skip ci] none
this branch 132964496f Merge main into issue-20567-cleanup-proposals (auto-sync) [skip ci] none
this branch f9b32dd40b fix(merge): resolve the core_routers.py clash with #20445 into one implementation (#20567) #20445, #20567
this branch e62508b8f0 fix(admin): the stale-directory cleanup moves to #20578; manifests fall back to the install copy; no duplicate proposals (#20567) #20578, #20567
this branch 216915b0e4 feat(admin): cleanup proposals for .env copies, the stale directory and the tier column (#20567) #20567

@mrveiss

mrveiss commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Code review on PR #20576 (head ff6800b): approve.

Read only; I didn't run the tests. Since the last approved head: floor-only conflicts taking main's side, and _backend_dir handling AUTOBOT_BASE_DIR being the backend directory itself as well as the install root, tested both ways, which fixes the .env.*~ action looking one level too deep.

@mrveiss

mrveiss commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Delta review: cef54df after approved cd10121. Verdict: APPROVE

Severity File:line Finding Fix
none autobot-backend/services/install_cleanup_actions.py:216 Pure extract of the completion audit + note into _finish_removal; order is unchanged (audit, record, then raise if the audit was not written), so the four-eyes / audit-first behaviour is preserved. execute_env_copies_cleanup is now about 19 lines, _finish_removal about 20; file is 273 lines -

@mrveiss

mrveiss commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Landed on main in merge train T101b (#21263), merge commit 4b5a129 (frozen head c325bf7 is an ancestor of main). Closing as landed; the owning session closes the linked issue with AC evidence and disposes of the branch.

@mrveiss mrveiss closed this Nov 9, 2026
@mrveiss
mrveiss deleted the issue-20567-cleanup-proposals branch November 9, 2026 13:53
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant