Skip to content

feat: non-blocking log buffer with batch inserts - #6492

Closed
0xbbjoker wants to merge 3 commits into
v2-developfrom
feat/log-buffer-batching
Closed

0xbbjoker wants to merge 3 commits into
v2-developfrom
feat/log-buffer-batching

Conversation

@0xbbjoker

Copy link
Copy Markdown
Contributor

Summary

  • LogBuffer class in runtime.ts — sync push(), async flush(), payload truncation (strips state to summary, caps at 256KB)
  • Replace 3 blocking adapter.log() callsites with logBuffer.push() — action, evaluator, and model logs are now fire-and-forget
  • Add optional logBatch() to IDatabaseAdapter with plugin-sql implementation (groups by entityId for RLS, single multi-row INSERT per group)
  • Add idx_logs_type_created and idx_logs_room_created DB indexes
  • runtime.stop() drains buffer before shutdown; flushLogs() exposed on IAgentRuntime
Metric Before After
Action log blocking 50-200ms/action 0ms (async)
DB round-trips per request 3-8 txns (9-32 queries) 1-2 batch txns (3-6 queries)
Payload per log entry 1-10MB 50-256KB
Log table query perf Full scan Indexed

Test plan

  • bun run build passes on @elizaos/core and @elizaos/plugin-sql
  • 51/51 runtime tests pass (bun test packages/core/src/__tests__/runtime.test.ts)
  • Manual: send message via stream endpoint, verify logs appear in DB with stripped state
  • Manual: verify idx_logs_type_created, idx_logs_room_created indexes created after migration
  • Note: expression index idx_logs_run_id on (body->>'runId') needs custom SQL migration (Drizzle doesn't support expression indexes in schema DSL)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/log-buffer-batching

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Add LogBuffer class to runtime.ts: sync push(), async flush(),
  auto-flush on threshold (10 entries) or timer (5s)
- Replace 3 blocking adapter.log() callsites with logBuffer.push()
  (action, evaluator, model logs are now fire-and-forget)
- Public runtime.log() preserves backward compat (push + immediate flush)
- Add flushLogs() to IAgentRuntime interface
- Add optional logBatch() to IDatabaseAdapter with plugin-sql implementation
  (groups by entityId for RLS, single multi-row INSERT per group)
- Add createBatch() to LogStore
- Add idx_logs_type_created and idx_logs_room_created indexes
- runtime.stop() drains buffer before shutdown
- Update tests to flush buffer before asserting on adapter.log calls

Full payloads preserved — no truncation. Perf win comes from
non-blocking writes and batch inserts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@0xbbjoker
0xbbjoker force-pushed the feat/log-buffer-batching branch from c4833ed to 405e744 Compare February 11, 2026 18:16
- Extract shared LogWriteParams type across core + SQL plugin
- Fix flush race condition with drain loop for entries pushed during in-flight flush
- Use Promise.allSettled for partial-failure visibility in batch fallback
- Add failedEntries pattern to avoid duplicate retries on partial batch failure
- Add warning logs instead of silent error swallowing
- Expand test coverage: boundary conditions, error handling, destroy behavior,
  timer behavior, AgentRuntime integration, SQL createBatch (21 new tests)
- Remove verbose comments, inline single-caller flushLoop(), trim noise
Move LogBuffer class out of runtime.ts into its own utility file
to reduce runtime.ts bloat.
@odilitime
odilitime changed the base branch from develop to v2-develop March 4, 2026 20:28
@odilitime odilitime added the 1.x V2 label Mar 4, 2026
@lalalune

Copy link
Copy Markdown
Member

We did not carry this in the current merge train. The direction may be useful, but it needs a fresh rebase and focused validation proving batching and drain semantics are correct under real runtime load before we can take it. Please resubmit as a narrower PR with end-to-end tests and clear behavior guarantees.

@lalalune

Copy link
Copy Markdown
Member

Closing — draft PR with only 2/5 tasks completed and no recent activity. Feel free to reopen when this is ready for review.

@lalalune lalalune closed this Apr 12, 2026
@lalalune
lalalune deleted the feat/log-buffer-batching branch May 5, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants