Skip to content

feat: Add persistent event logging (audit_events) - #22

Merged
dsactivi-2 merged 1 commit into
mainfrom
feat/persistent-events
Dec 31, 2025
Merged

feat: Add persistent event logging (audit_events)#22
dsactivi-2 merged 1 commit into
mainfrom
feat/persistent-events

Conversation

@dsactivi-2

Copy link
Copy Markdown
Owner

Summary

  • Adds persistent event logging to SQLite database
  • Events survive server restarts (Single Source of Truth)
  • Global recordEvent() helper for easy usage

Changes

  • src/db/audit-events.ts: Event table schema + AuditService
  • src/lib/events.ts: Global helper with convenience wrappers
  • src/index.ts: Initialize event recorder at startup
  • src/api/tasks.ts: Log task lifecycle events
  • src/api/auth.ts: Log login/logout events
  • src/chat/manager.ts: Log chat events

Event Types

  • task_created, task_started, task_finished, task_failed
  • chat_sent
  • user_login, user_logout
  • agent_heartbeat
  • deploy, error

Test plan

  • TypeScript compiles without errors
  • Server starts successfully
  • Events are persisted to audit_events table
  • Events survive restart

🤖 Generated with Claude Code

- src/db/audit-events.ts: Event table + AuditService
- src/lib/events.ts: Global recordEvent() helper
- Task lifecycle: created, started, finished, failed
- Chat events: message sent
- Auth events: login, logout
- Events persisted to SQLite, survive restarts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dsactivi-2
dsactivi-2 merged commit 0f4357d into main Dec 31, 2025
9 of 10 checks passed
@github-actions

Copy link
Copy Markdown

@sentry review

@dsactivi-2
dsactivi-2 deleted the feat/persistent-events branch December 31, 2025 22:18
Comment thread src/index.ts
log.info("Database initialized");

// Initialize event recorder for persistent event logging
initEventRecorder(db.audit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The db object lacks the audit property, but the code attempts to access it in initEventRecorder and for logging, which will cause a crash on startup and during operations.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The initDatabase function does not create and attach the audit service to the returned database object. Consequently, db.audit is undefined. The application attempts to access this property at startup in src/index.ts:71 by calling initEventRecorder(db.audit), which will cause a crash. Further crashes will occur during user authentication or task management operations, as functions in src/api/tasks.ts and src/api/auth.ts attempt to call db.audit.log(). The new audit feature is not correctly integrated.

💡 Suggested Fix

In src/db/database.ts, update the initDatabase function. Call initAuditEventsTable(db) to create the table. Then, call createAuditService(db) and assign its return value to an audit property on the object returned by initDatabase. Also, add the audit property to the Database interface.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/index.ts#L71

Potential issue: The `initDatabase` function does not create and attach the `audit`
service to the returned database object. Consequently, `db.audit` is `undefined`. The
application attempts to access this property at startup in `src/index.ts:71` by calling
`initEventRecorder(db.audit)`, which will cause a crash. Further crashes will occur
during user authentication or task management operations, as functions in
`src/api/tasks.ts` and `src/api/auth.ts` attempt to call `db.audit.log()`. The new audit
feature is not correctly integrated.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 507385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants