Skip to content

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

Merged
rylinjames merged 7 commits into
FastCrest:mainfrom
mvanhorn:fix/48-record-writer-background-worker
Jun 17, 2026
Merged

feat(runtime): move record writing to a background worker thread#218
rylinjames merged 7 commits into
FastCrest:mainfrom
mvanhorn:fix/48-record-writer-background-worker

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

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
…background-worker

# Conflicts:
#	src/tether/runtime/record.py
rylinjames
rylinjames previously approved these changes Jun 17, 2026

@rylinjames rylinjames left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Resolved current-main conflict in RecordWriter by preserving deployment evidence/action trace fields and queueing the final record. Focused recorder/server tests passed locally: 46 passed.

rylinjames
rylinjames previously approved these changes Jun 17, 2026

@rylinjames rylinjames left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved after fixing async recorder ordering and shadow-worker drain. Local regression batch passed: shadow rollout integration, policy diff shadow result, shadow rollout gate, and background writer tests.

@rylinjames rylinjames left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed after the shadow rollout test stabilization and main merge. The async recorder ordering and drain fixes are scoped, and the focused shadow/MCP tests pass locally.

@rylinjames rylinjames merged commit 6d5ac31 into FastCrest:main Jun 17, 2026
7 checks passed
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

2 participants