Skip to content

fix(secrets): audit log reads the fields the API sends (#20173) - #21262

Merged
mrveiss merged 20 commits into
mainfrom
issue-20173
Nov 12, 2026
Merged

mrveiss merged 20 commits into
mainfrom
issue-20173

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thinking Path

  • bug(secrets): the secret audit log reads fields the API does not send, so dates and names look wrong #20173: the secret audit log read fields the API does not send. The date and name bugs were already fixed on main (auditTimestampToDate in types/audit.ts, details.name in SecretAuditLog.vue), but the row was still a hand-written interface, because the backend response model typed entries as List[dict] and the generated schema had no row type to read.
  • Fix canonically: give the backend response a real row model, regenerate api.ts with the CI recipe, and make the frontend row type the generated schema.

What Changed

  • autobot-backend/api/schemas_audit.py (new): AuditEntryResponse (every field AuditEntry.to_response_dict sends) and AuditQueryResponse with entries: List[AuditEntryResponse]. Moved out of schemas_system.py (a grandfathered file that may not grow); api/audit.py imports it from there. All four routes using it (/logs, /session, /user, /failures) now serialize typed rows.
  • autobot-frontend/src/types/generated/api.ts: regenerated with the verify-generated-types recipe (dump OpenAPI, then openapi-typescript --additional-properties); +47/-3 lines.
  • autobot-frontend/src/types/audit.ts: AuditEntry = components['schemas']['AuditEntryResponse'] replaces the hand-written interface. Every consumer (secret audit log, audit dashboard table and timeline, plugin capability log) type-checks against it.
  • SecretAuditLog.test.ts: the fixture is typed from the generated row, and a field-presence test ties the fixture's keys to the schema's fields.

Instances of the mismatch in the secret audit UI (the same set as the issue): timestamp seconds read as ms, metadata.secret_name read instead of details.name, username read instead of user_id (all fixed earlier on main, now typed), plus the hand-written row type itself (fixed here).

Not in this PR: the issue's second criterion (one declaration each for AuditLogEntry / AuditQueryResponse and removing the ratchet exceptions) needs the shared kit and the SLM app, held by another open PR; the host criterion needs a finished update. So this is Refs.

Verification

  • vue-tsc --noEmit -p tsconfig.app.json: exit 0.
  • vitest src/components/secrets src/components/audit src/i18n: 11 files, 77 tests passed.
  • eslint on types/audit.ts and the test: clean. Backend audit tests are skipped locally (19 skipped); CI runs them.
  • The pre-commit hooks (file-size guard, mypy, secrets scan) passed.

Refs #20173

Model Used

Claude Sonnet 5.5

🤖 Generated with Claude Code

@mrveiss mrveiss added this to the M3 - Refined GUI complete milestone Nov 9, 2026
@mrveiss mrveiss added bug Something isn't working frontend backend phase:M3.9 Chat, Agents, Analytics and Settings screens labels Nov 9, 2026
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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 12 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 6199adc and c5d54b4.

Files ignored due to path filters: 1

  • autobot-frontend/src/types/generated/api.ts is excluded by !**/generated/**
Files selected for processing: 13

  • autobot-backend/api/audit.py
  • autobot-backend/api/audit_outcome_vocabulary_test.py
  • autobot-backend/api/schemas_audit.py
  • autobot-backend/api/schemas_system.py
  • autobot-frontend/src/components/audit/__tests__/AuditLogTable.pagination.test.ts
  • autobot-frontend/src/components/secrets/__tests__/SecretAuditLog.test.ts
  • autobot-frontend/src/composables/useAuditApi.ts
  • autobot-frontend/src/composables/useSecretsAuditApi.ts
  • autobot-frontend/src/types/audit.ts
  • autobot-slm-frontend/src/composables/useAutobotApi.ts
  • libs/autobot-ui/index.ts
  • libs/autobot-ui/src/types/audit.ts
  • repo_tests/duplicate_names_ratchet_14908_test.py
  • 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 9, 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 9, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at 4af569b

Verdict: CHANGES NEEDED — one backend finding can turn a working audit query into a 500; the rest is sound.

Severity file:line finding fix
HIGH autobot-backend/api/schemas_audit.py (result: AuditResult) with services/audit_logger.py from_event (result=event.get("outcome", "success")) AuditEntry.from_event copies the canonical event outcome, a free str (services/audit/taxonomy.py:50, and :82/:113 document verified/failed/backup-code outcomes). AuditLogger.query calls query_filtered with no category filter. Any non-operation row in the window (e.g. an auth.mfa row with outcome verified) fails the Literal and response_model validation, so /audit/logs, /session/{id}, /user/{id} and /failures return 500 where they returned the row before. Either normalise the outcome to AuditResult in from_event (one mapping, a test with an off-vocabulary outcome), or type the field str in AuditEntryResponse and keep the enum in the frontend narrowing. Add a backend test that builds a response from a non-operation canonical event.
LOW autobot-frontend/src/components/secrets/__tests__/SecretAuditLog.test.ts (comment above ROW_FIELDS) and fixture comment The generated type is {...} & { [key: string]: unknown }, so "an invented field fails vue-tsc" is false; only the Object.keys equality test catches it. Reword the comments: the equality test, not vue-tsc, catches an extra field.
LOW autobot-frontend/src/types/audit.ts (doc of AuditEntry) Says the type lives in api/schemas_system.py; it moved to api/schemas_audit.py. Fix the reference.
INFO autobot-frontend/src/types/audit.ts The nullable fields went from required string | null to optional string | null | undefined. All consumers read them in v-if, || '-' or ?. form, so they still type-check. Local AuditResult stays a second declaration of the generated union (pre-existing). None.

Checks

  1. Match with to_response_dict: it returns dict(self.__dict__), i.e. the 14 dataclass fields. Names, types and optionality match (float timestamp, Metadata details, float | None performance_ms). The only mismatch is the result vocabulary above. The four endpoints that return AuditQueryResponse (/logs, /session, /user, /failures) all build entries from to_response_dict(); there is no other route returning these rows.
  2. Importers: api/audit.py is the only importer and is updated. No second definition remains in the backend. api_endpoint_migrations_test.py:22152 only greps the source for AuditQueryResponse(, which still holds. The SLM frontend's AuditQueryResponse (useAutobotApi.ts:240) is its own interface, unaffected.
  3. Frontend consumers (AuditLogTable, AuditTimeline, AuditLogsView, useAuditApi, useSecretsAuditApi, SecretAuditLog, stories): the field set is unchanged, so no renames. useSecretsAuditApi still uses the generic AuditQueryResponse<AuditApiEntry>.
  4. api.ts: the diff is limited to the new AuditEntryResponse and the AuditQueryResponse.entries type.
  5. Refs #20173 is right: AC1 is already ticked (test with a real-shaped entry). AC2 stays open: AuditLogEntry and AuditQueryResponse still have more than one declaration (frontend types/audit.ts, SLM useAutobotApi.ts:240, useAuditApi generics), and the dedup(types): 28 type names are declared in both GUIs and 2 shadow the kit #19910 guard exceptions are still there; this needs the SLM frontend and the shared kit, held by open PR refactor(frontend): remaining relative time comes from the kit's createRecencyFormatter, formatTimeAgo removed (#19606) #20986. AC3 is a host check after a finished update.
  6. Size: schemas_audit.py is 42 lines; no function added or changed is over 30 lines; no file nears the 600-line ceiling.

@github-actions

github-actions Bot commented Nov 9, 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 commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Code review follow-up at 71319bb

Finding Fix Test
HIGH: AuditEntryResponse.result was the AuditResult Literal while from_event copies the open-string canonical outcome (taxonomy has verified, backup-code); one such row made /logs, /session, /user, /failures return 500 result: str in schemas_audit.py, documented as the taxonomy outcome; the real outcome is carried, nothing normalised. api.ts regenerated with the verify-generated-types recipe: 6 insertions, 5 deletions, only AuditEntryResponse api/audit_outcome_vocabulary_test.py: 10 tests (2 response-model, 8 = 4 endpoints x verified/backup-code, each 200 with the outcome intact). Frontend: AuditLogTable.pagination.test.ts +1 test, unknown result verified renders its own text with the question-circle fallback icon (resultIcon already falls back; no change needed there)
LOW: test comments claimed an invented field fails vue-tsc Reworded in SecretAuditLog.test.ts (2 comments): the Object.keys equality is the guard existing equality test
LOW: types/audit.ts doc named schemas_system.py now schemas_audit.py n/a

Local runs: pytest audit_outcome_vocabulary_test.py + audit_response_test.py 12 passed; vitest src/components/secrets src/components/audit src/i18n 11 files / 78 tests passed; vue-tsc --noEmit -p tsconfig.app.json exit 0; eslint and flake8 on touched files clean. The local venv has older pydantic than declared, so CI is the authority.

@mrveiss

mrveiss commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) follow-up at 71319bb

Verdict: APPROVE.

Finding at 4af569b Resolution
HIGH: result typed as a five-value Literal while the taxonomy outcome is a free string, so an off-vocabulary row would 500 four endpoints AuditEntryResponse.result is str, documented as the taxonomy outcome; no outcome is narrowed or lost. audit_outcome_vocabulary_test.py: verified and backup-code return 200 with the outcome intact on /logs, /session, /user and /failures
Unknown result in the UI Existing resultIcon fallback (question-circle) and raw-value badge; new test in AuditLogTable.pagination.test.ts
LOW: test comments credited vue-tsc Corrected: the Object.keys equality is the guard
LOW: doc comment named schemas_system.py Points to schemas_audit.py

api.ts regenerated (diff limited to AuditEntryResponse). Local: pytest 12 passed; vitest 78 passed; vue-tsc and eslint clean. The local Python venv differs from the declared package set, so CI is the authoritative backend run.

@mrveiss

mrveiss commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE @ e124a68

Read-only review; CI is paused so nothing was run. No blocking defects found.

Severity File:line Finding Required fix
Low PR body "Not in this PR" Stale: says the one-declaration criterion is held by another PR, but the diff moves AuditQueryResponse into the kit (libs/autobot-ui/src/types/audit.ts), empties TYPE_EXCEPTIONS and pins type_names_in_both_apps to 0. The body also omits the kit change and the outcome-vocabulary test. Update the body before merge.
Low libs/autobot-ui/src/types/audit.ts:6 Comment says the backend envelope "carries untyped entry dicts"; this PR types them (List[AuditEntryResponse]). Fix the comment (or fold into a follow-up).
Low libs/autobot-ui/src/types/audit.ts:10 Hand-written envelope duplicates the generated components['schemas']['AuditQueryResponse']. Acceptable because the SLM app has no generated types here. None.
Info autobot-backend/api/api_endpoint_migrations_test.py:22156 Asserts entries=entry_dicts in query_audit_logs source; the source reads entries=[e.to_response_dict() ...]. Not touched by this PR; looks like a stale assertion. Out of scope; check whether it is skipped or failing on main.

Checks:

  • Secrets and authz: no secret values are added to logs, records or responses. check_admin_permission is unchanged on all four routes. Only the response model is typed. details stays Metadata, and AuditEntry.sanitize is unchanged.
  • The result: str choice is correct. The entry's result is an open outcome string, and a Literal would 500 on rows like verified.
  • The test would fail before the fix: List[dict] accepts any row, but the new model and the generated type only exist after it. Pre-fix api.schemas_audit does not import at all. No module-level randomness or time, and the stubs are AsyncMock.
  • Guards: no function over 30 lines. schemas_system.py shrinks. No new route module, so no reach-floor change. No hardcoded IPs, ports or TTLs. No new UI strings. No new repo_tests file reads or ast.parse. No KB reads.
  • Types patch: api.ts was regenerated and the added schema looks consistent with the model. Not regenerated by me, so a CI types patch is possible only if the recipe output differs.
  • CI: no check runs at this head. ci-dispatch-watchdog failed only because CI was never dispatched (paused). Semgrep passed.
  • Threads: none.
  • Labels: milestone M3 and phase:M3.9 are present. Required PR body headings are present.

@mrveiss
mrveiss merged commit 4cdd6bd into main Nov 12, 2026
3 of 4 checks passed
mrveiss added a commit that referenced this pull request Nov 12, 2026
@mrveiss
mrveiss deleted the issue-20173 branch November 12, 2026 16:39
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 frontend phase:M3.9 Chat, Agents, Analytics and Settings screens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant