Skip to content

[chore] store layer uses context.Background everywhere, no HTTP context propagation #14

@nkanf-dev

Description

@nkanf-dev

Problem

All SQLite operations in internal/store/sqlite.go use context.Background():

func (s *SQLiteStore) AppendEvent(event types.EventEnvelope) error {
    _, err := s.db.ExecContext(context.Background(), ...)

This pattern repeats across all 22+ StateStore methods and 4 EventStore methods. HTTP request contexts (with cancellation, deadlines, trace IDs) are not propagated from handlers through the engine to the store layer.

Impact

  • No cancellation: if an HTTP client disconnects, the SQLite query still runs to completion
  • No deadlines: slow queries can block indefinitely (mitigated by SQLite's busy_timeout pragma, but not by request-level timeouts)
  • No tracing: cannot correlate a slow DB operation back to the originating HTTP request

Expected

Pass context.Context from HTTP handlers through Engine methods to store operations. This requires:

  1. Adding context.Context as the first parameter to all EventStore and StateStore interface methods
  2. Threading context through Engine's public methods (Decide, Report, ResolveApproval, etc.)
  3. Updating all callers in httpapi/router.go

Key code

  • internal/store/sqlite.go — all methods use context.Background()
  • internal/core/engine.go — Engine methods don't accept context
  • internal/httpapi/router.go — HTTP handlers have r.Context() but don't pass it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions