fix(admin): refresh audit events after model-group save/delete - #1026
Conversation
The admin console's Audit tab reads from `state.recent_audit_events`, which is only populated by /admin/state -- there is no scoped audit endpoint. saveModelGroup() and the model-group delete handler only called refreshModelGroups() (which re-fetches /api/v1/model_groups), so a save/delete that produced a new server-side audit event left the shared Audit tab stale until an unrelated full page reload. Adds a lightweight refreshAuditEvents() helper -- re-fetches /admin/state and applies only the recent_audit_events slice -- rather than reusing the heavier load() (which also re-triggers simulate() and every readiness/commercial endpoint), and wires it into both the save and delete handlers. Also gives the shared model-group feedback text a success/error color, matching the console's existing --green/--red status-color convention used elsewhere. New tests/test_admin_contract.py::test_model_group_mutations_refresh_audit_events locks in the fix by extracting each handler's source and asserting the call sites and the scoped (not full-load) shape of the new helper. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 12 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
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. Comment |
|
Routine staleness triage: this PR's base was behind current Verification before push:
Note for the reviewer/maintainer: this PR and #1011 ( No source changes beyond the merge commit itself; fresh exact-head CI evidence is still required before merge per this repo's governance. Generated by Claude Code |
Restore the last current-main-compatible admin console tree after the refresh-isolation follow-up accidentally deleted the rendering, loading, navigation, session, evaluation, and listener functions required at startup. Preserve the original scoped audit-refresh fix while reverting only the broken follow-up implementation and its obsolete/syntactically invalid test additions. Keep the remaining refresh-failure-isolation finding open for a behavioral RED-first repair.
|
Repair-first reconciliation applied after fresh review found a RED startup regression on the prior head.
RCA: the refresh-isolation follow-up had accidentally deleted ~500 lines of the embedded admin console, including render/load/navigation/session/evaluation functions and event registrations. The current review correctly identified that The repair commit deliberately restores the last current-main-compatible tree ( This does not claim the PR is merge-ready. The earlier valid review finding remains: once the model-group mutation is confirmed, |
| async function refreshModelGroupViews() { | ||
| let modelGroupsRefreshed = true; | ||
| try { | ||
| await refreshModelGroups(); | ||
| } catch (error) { | ||
| modelGroupsRefreshed = false; | ||
| console.warn("Could not refresh model groups after mutation", error); | ||
| } | ||
| const auditRefreshed = await refreshAuditEvents(); | ||
| if (!modelGroupsRefreshed) { | ||
| showModelGroupRefreshWarning(t("model_groups_refresh_warning")); | ||
| } | ||
| if (!auditRefreshed) { | ||
| showModelGroupRefreshWarning(t("audit_refresh_warning")); | ||
| } |
| const response = await fetch(endpoint, {method: "DELETE"}); | ||
| const payload = await response.json(); | ||
| if (!response.ok) throw new Error(payload.error?.message || "Could not delete model group"); |
There was a problem hiding this comment.
Summary (backlog item 25)
The admin console's Audit tab reads
state.recent_audit_events, which is only exposed on/admin/state(no scoped audit endpoint exists).saveModelGroup()and the model-group delete handler only calledrefreshModelGroups()(/api/v1/model_groups), so a save/delete that produced a new server-side audit event left the shared Audit tab stale until an unrelated full page reload.Note on provenance: the backlog item cited PR #1010 as a precedent for this fix pattern ("model-timeouts panel"). That PR is actually closed, not merged (rejected via no-heuristics RCA — its per-model timeout bounds were an unreviewed heuristic), and there is no timeout-related code in
admin.pyat all. The actual bug and fix here were independently re-derived from the current codebase; the closest real precedent isstartSession()'s existingawait load()-after-success pattern, which this fix deliberately does not copy wholesale (too heavy — it also re-triggerssimulate()and every readiness/commercial endpoint for what should be a lightweight group edit).Changes
refreshAuditEvents()helper: re-fetches/admin/stateand applies only therecent_audit_eventsslice, then callsrenderAudit(). Scoped, not a fullload().saveModelGroup()(afterrefreshModelGroups()) and the model-group delete click handler's.then()chain.#modelGroupFeedback) now gets--green/--redon success/error, matching the console's existing status-color convention (also flagged as a low-priority related issue in the backlog item).CHANGELOG.d/admin-model-group-audit-refresh.mdfragment, matching this repo's existing convention.Test plan
pytest tests/test_admin_contract.py tests/test_admin_spend_view.py— 6 passedtest_model_group_mutations_refresh_audit_eventsextracts each handler's source text and asserts both the call-site wiring and that the new helper stays scoped to/admin/state(notsimulate()/refreshReadiness())uv run --locked --extra api --extra db --extra queue --group dev python -m pytest -q— 3313 passed, 2 skipped, 0 failures🤖 Generated with Claude Code