feat(audit): Outbox 기반 감사 이벤트 전달과 Workflow 실행 연계 구현 - #490
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d157b146ed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| audit_organization_id = _to_uuid(metadata.get("organization_id")) | ||
| if audit_organization_id is None: | ||
| audit.workflow_run_id = None | ||
| audit.workflow_node_run_id = None | ||
| return |
There was a problem hiding this comment.
조직 메타데이터가 없는 실행 감사도 run 연결을 보존하세요
일반 수동/API workflow 완료 경로에서는 _schedule_audit_organization_id()가 scheduler 실행이 아니면 None을 반환해 _record_workflow_execute_audit()가 workflow_run_id만 metadata에 넣고 organization_id는 넣지 않습니다. 이 새 검증은 그런 기존 workflow.execute payload를 모두 여기서 workflow_run_id=None으로 지워 버리므로, 가장 흔한 사용자 실행 감사가 typed run FK 없이 저장되어 감사 목록/상세에서 실행 기록과 연결되지 않습니다. workflow_run_id가 있으면 Run→Workflow에서 조직을 확인해 보존하거나 producer가 사용자 실행에도 organization_id를 넘기도록 맞춰야 합니다.
Useful? React with 👍 / 👎.
| AuditEventOutbox.lease_expires_at <= now, | ||
| ) | ||
| .with_for_update(skip_locked=True) | ||
| .all() |
There was a problem hiding this comment.
Log worker 장애나 재시작 중 leased 상태로 만료된 audit outbox row가 많이 쌓이면, 다음 beat 실행이 여기서 모든 stale row를 한 번에 조회·잠금·갱신합니다. process_due_events(limit=...)의 한도는 신규 lease에만 적용되어 대량 backlog에서는 singleton beat task가 오래 점유되고 정상 pending 배송까지 밀릴 수 있으므로, stale lease 복구도 동일하게 제한하거나 별도 batch size로 끊어 처리해야 합니다.
Useful? React with 👍 / 👎.
| run = db.get(WorkflowRun, audit.workflow_run_id) | ||
| if run is None: | ||
| audit.workflow_run_id = None | ||
| audit.workflow_node_run_id = None | ||
| return |
There was a problem hiding this comment.
아직 저장 중인 WorkflowRun correlation을 재시도하세요
Workflow Engine은 run id를 먼저 만들고 log.create_run을 비동기로 보낸 뒤 노드 실행 audit도 같은 workflow_run_id로 남길 수 있는데, log queue 지연/재시도 중 Outbox worker가 먼저 이 row를 처리하면 db.get(WorkflowRun, ...)가 아직 None입니다. 현재는 이를 영구 orphan처럼 처리해 correlation을 지우고 AuditLog를 성공 commit하므로, 이후 log.create_run이 정상 저장되어도 RAG/LLM 노드 audit은 실행 기록에 연결되지 않습니다; missing run은 짧게 retry하거나 생산자가 run 저장 이후에만 outbox를 확정해야 합니다.
Useful? React with 👍 / 👎.
변경 사항
audit_event_outbox에 저장하도록 변경했습니다.workflow_run_id,workflow_node_run_id연계 필드를 추가했습니다.관련 이슈
Closes #
변경 유형
테스트
테스트 결과:
upgrade head성공a9b0c1d2e3f4로 일치함스크린샷 (UI 변경 시)
해당 없음 — UI 변경이 없습니다.