fix: replace per-instance disk log with in-memory ring buffer - #41
Merged
Conversation
Eliminate ~100,000× disk write amplification caused by the old enforceMaxLogSize loop (read 10MB + truncate + write 10MB per 1024-byte PTY chunk). Under TUI redraw workloads, this could generate 280MB+ of accumulated disk writes in the data directory. Changes: - Add RingBuffer (internal/instance/logbuf.go): bounded, thread-safe, in-memory ring buffer. Backing slice pre-allocated eagerly. Hot-path optimized with WriteString (no []byte(chunk) copy) and atomic pointer access (no stateMu per chunk). - Add adaptive sizing (internal/instance/sizing.go): per-instance cap clamp(available/16, 16MB, 256MB), default 32MB. Global budget capped at 25% system RAM. User override via config.GlobalConfig.LogBufferBytes. - Refactor Manager (internal/instance/manager.go): pumpLogs writes to ring buffer instead of disk. Tail/ReadSince read from buffer. Removed enforceMaxLogSize, logPathByID, and all LogPath references. - Remove LogPath from ManagedInstance (internal/store/state.go). Old state.json files with log_path load cleanly (JSON silently ignores). - Add PurgeOrphanLogFiles() called at daemon startup to clean up dead .log artifacts left by pre-buffer code. - HTTP/MCP: budget-exceeded returns 503 with structured log_buffer_budget_exceeded body. UI shows dedicated modal. - Test coverage: RingBuffer (15 tests), sizing/budget (9 tests), manager budget integration, backward-compat state loading. - Docs: PRD, ARCHITECTURE §4.1, API (error shape + cursor semantics), CHANGELOG Unreleased section, and detailed implementation plan. BREAKING: state.json schema — log_path field removed. Old files continue to load; external tooling should drop log_path dependency.
- Stats API now includes daemon_cpu_percent/daemon_memory_bytes in global totals - Per-instance stats expose memory_buffer_bytes (used) and memory_buffer_cap_bytes (cap) - Collector refactored: system calls moved outside lock, 3-phase pipeline - UI adds mw daemon row and buffer used/cap annotation per instance - Add .omo/ to .gitignore for OpenCode internal session data
Halves the per-second process.NewProcess() syscall storm when the resource monitor modal is open, reducing daemon CPU overhead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates massive disk write amplification caused by per-instance files, and enhances resource monitoring with daemon stats and ring buffer visibility.
Changes
In-memory ring buffer (678490f) — replaces per-instance disk log files with process-in-memory bounded ring buffers (16–256 MB per instance, adaptive to system RAM). Eliminates ~280 MB+ disk writes caused by the old append + truncate cycle under heavy TUI workloads.
Daemon resource monitoring (f1ed5ab) — stats API now includes daemon CPU/memory in global totals. Per-instance stats expose ring buffer used/cap. UI shows dedicated mw daemon row and per-instance buffer annotations.
UI translation fix (2befdd1) — translate subprocess disclaimer to English.
Reduce polling interval (99349d7) — resource monitor polling from 1s to 2s to halve per-second
process.NewProcess()syscall overhead.Risk
log_pathfield removed fromstate.json. Old files load safely (unknown fields ignored by JSON decoder). External tools readingstate.jsonshould drop thelog_pathfield.