Skip to content

feat(runtime): move record writing to a background worker thread#218

Open
mvanhorn wants to merge 1 commit into
FastCrest:mainfrom
mvanhorn:fix/48-record-writer-background-worker
Open

feat(runtime): move record writing to a background worker thread#218
mvanhorn wants to merge 1 commit into
FastCrest:mainfrom
mvanhorn:fix/48-record-writer-background-worker

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Jun 7, 2026

Summary

Moves record writing off the request path (#48). Public writes now enqueue to a bounded in-process queue drained by a daemon worker thread, so a slow or blocked disk no longer stalls the caller. The worker flushes per record, so a writer crash loses at most one record.

Changes

  • runtime/record.py: bounded queue.Queue (RECORD_QUEUE_MAXSIZE), a background worker thread, and a sentinel-based clean shutdown; image redaction preserved.
  • runtime/server.py: wired to the queue-backed writer.

Testing

PYTHONPATH=src python3 -m pytest tests/test_record.py — 36 passed (enqueue/flush, shutdown drains the queue, redaction modes, bounded-queue behavior).

Closes #48

AI was used for assistance.

Public writes enqueue to a bounded in-process queue drained by a daemon
worker thread, so disk latency no longer stalls callers. The worker flushes
per record, so a crash loses at most one record.

Closes FastCrest#48

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mvanhorn mvanhorn requested a review from rylinjames as a code owner June 7, 2026 16:14
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.

[Performance] Move RecordWriter to Background Worker to Prevent Loop Freezing

1 participant