Skip to content

Permission service logs full ruleset on every tool call, causing 50GB+ log bloat #17218

Closed

Description

@XucroYuri

Permission service logs full ruleset on every tool call, causing 50GB+ log bloat

Bug Summary

The service=permission logger writes the entire permission ruleset (all rules, including every external_directory allow/ask entry) into every single log line at INFO level. With a moderate number of installed skills (~648), each permission log line balloons to ~148KB (148,601 characters). During an active session with Oh-My-OpenCode subagents, this produces ~29MB/min of logs per process, causing the log directory to grow to 50GB+ within hours.

Environment

Component Version/Value
OpenCode 1.1.53
OS macOS (darwin-arm64)
Plugin [email protected]
Installed Skills 648 (via ~/.agents/skills/ + ~/.claude/skills/)
MCP Servers 18 configured (shadcn, context7, grep, github, playwright, filesystem, memory, sequential-thinking, fetch, git, postgres, sqlite, redis, mongodb, cloudflare, supabase, neon, zai-mcp-server)

Reproduction

Prerequisites

  • Install 100+ skills (via ~/.agents/skills/ or ~/.claude/skills/)
  • Configure multiple MCP servers
  • Optionally install oh-my-opencode plugin (amplifies the issue via subagent processes)

Steps

  1. Start OpenCode: opencode
  2. Send any message that triggers tool calls (e.g., "list files in current directory")
  3. Observe ~/.local/share/opencode/log/ directory growth

Expected

Log directory grows at a reasonable rate (~1-10MB per session).

Actual

Log directory grows at ~29MB/min per active process. With oh-my-opencode spawning multiple subagent processes, total growth reaches hundreds of MB per minute.

Root Cause Analysis

Primary: Permission ruleset serialized into every log line

Every tool invocation triggers permission evaluation, which logs two lines to the session log:

Line 1 — Permission check (contains full ruleset):

INFO  2026-03-12T17:43:54 +1ms service=permission permission=bash pattern=echo "hello" ruleset=[{"permission":"*","pattern":"*","action":"allow"},{"permission":"doom_loop","pattern":"*","action":"ask"},{"permission":"external_directory","pattern":"*","action":"ask"},{"permission":"external_directory","pattern":"/Users/xuyu/.local/share/opencode/tool-output/*","action":"allow"},{"permission":"external_directory","pattern":"/Users/xuyu/.claude/skills/postgresql-code-review/*","action":"allow"},{"permission":"external_directory","pattern":"/Users/xuyu/.claude/skills/python-packaging/*","action":"allow"}, ... <1,278 rules total> ...]

Line 2 — Evaluation result (also contains full ruleset):

INFO  2026-03-12T17:43:54 +1ms service=permission permission=bash pattern=echo "hello" action={"permission":"*","pattern":"*","action":"allow"} evaluated

Each skill contributes ~2 external_directory rules. With 648 skills:

  • 1,278 rules serialized per permission check
  • Each rule ~116 characters
  • Total ruleset string: ~148KB per log line

Quantified Impact

Metric Value
Rules per permission check 1,278
Characters per permission log line 148,601
Log lines per tool call 2 (check + evaluate)
Bytes per tool call ~296KB
Tool calls per minute (active session) ~100+
Log growth per minute (single process) ~29MB
Log growth per minute (11 processes) ~320MB
Log growth per hour (worst case) ~19GB

Evidence from real session

# Log file: only 200K lines but 24GB
$ wc -l 2026-03-12T165514.log
200047       # → avg 120KB per line!

# Active log: 7066 lines, 52% are permission checks
Total lines:      7,066
Permission lines: 3,709 (52.5%)
Bus publishing:     640
Message.part:       557

# Permission checks by tool type:
3200 permission=skill      # skills loaded on every message
 428 permission=bash       # shell commands
 119 permission=task       # subagent delegation

# Single permission line size:
$ grep -m1 'service=permission' log | wc -c
148601

Secondary: Orphaned subagent processes

Oh-My-OpenCode spawns subagent processes (Sisyphus, Hephaestus, explore, librarian, etc.) that sometimes become orphaned (ppid=1) and continue running for 16+ hours, each maintaining their own log session:

# 10 orphaned processes found, all ppid=1
 8697     1  Thu Mar/12 09:36:41 2026   opencode  # 16 hours old!
 8849     1  Thu Mar/12 09:36:49 2026   opencode
 8991     1  Thu Mar/12 09:36:53 2026   opencode
 9131     1  Thu Mar/12 09:36:59 2026   opencode
 9135     1  Thu Mar/12 09:37:02 2026   opencode
10925     1  Thu Mar/12 09:43:07 2026   opencode
34325     1  Thu Mar/12 22:27:23 2026   opencode
80965     1  Thu Mar/12 23:00:09 2026   opencode
85117     1  Fri Mar/13 00:08:42 2026   opencode
86339     1  Fri Mar/13 00:55:13 2026   opencode

Tertiary: MCP "Method not found" error spam

Multiple MCP servers repeatedly log -32601: Method not found errors for prompts/list, adding noise:

ERROR service=mcp clientName=filesystem error=MCP error -32601: Method not found failed to get prompts
ERROR service=mcp clientName=sequential-thinking error=MCP error -32601: Method not found failed to get prompts
ERROR service=mcp clientName=mongodb error=MCP error -32601: Method not found failed to get prompts
ERROR service=mcp clientName=playwright error=MCP error -32601: Method not found failed to get prompts
ERROR service=mcp clientName=shadcn error=MCP error -32601: Method not found failed to get prompts

Tertiary: No log rotation or size limits

OpenCode has no built-in log rotation, maximum file size, or auto-cleanup mechanism. A single session log file can grow unboundedly.

Proposed Fixes

P0 — Critical (permission ruleset logging)

  1. Do NOT serialize the full ruleset into log lines. The ruleset=[...] field in permission logs is the single biggest contributor. Options:

    • Remove ruleset from INFO-level logs entirely (move to DEBUG/TRACE)
    • Log only the matched rule, not the entire ruleset
    • Log a ruleset hash/fingerprint instead of the full array
  2. Add a logLevel configuration option that users can set in opencode.json:

    { "logLevel": "warn" }

P1 — High (log management)

  1. Implement log rotation: Max file size (e.g., 100MB per file) with automatic rotation and retention limit (e.g., keep last 5 files or 500MB total).

  2. Auto-cleanup old logs: Delete log files older than N days (configurable, default 7 days).

P2 — Medium (subagent lifecycle)

  1. Ensure subagent processes terminate when parent session ends. Currently orphaned processes (ppid=1) accumulate and continue writing logs indefinitely. (This may be an oh-my-opencode plugin issue rather than core OpenCode.)

P3 — Low (MCP error noise)

  1. Suppress or rate-limit repeated MCP errors: The -32601: Method not found for prompts/list is expected for MCP servers that don't implement the prompts capability. Log once per server at WARN, not repeatedly at ERROR.

Workarounds

Until fixed, users can mitigate with:

# 1. Kill orphaned opencode processes
ps aux | grep opencode | grep -v grep | awk '{print $2}' | xargs kill

# 2. Delete large log files
find ~/.local/share/opencode/log -type f -size +500M -delete

# 3. Set up auto-cleanup cron (daily at 4:00 AM)
(crontab -l 2>/dev/null; echo "0 4 * * * find ~/.local/share/opencode/log -type f -mtime +3 -delete") | crontab -
(crontab -l 2>/dev/null; echo "30 4 * * * find ~/.local/share/opencode/log -type f -size +500M -delete") | crontab -

# 4. Reduce installed skills to decrease ruleset size
# Each skill removed saves ~232 bytes per log line (2 rules × 116 chars)

Impact

  • Disk exhaustion: 50GB+ log accumulation in hours on a 228GB disk
  • Performance degradation: 11 orphaned processes consuming CPU/memory
  • Silent failure: No warnings when logs consume excessive disk space
  • Scales with skill count: More skills installed → exponentially worse logging overhead

Related

  • Potentially related to log cleanup reverse-deletion bugs (where old logs are kept and new logs deleted)
  • Oh-My-OpenCode subagent process lifecycle management
  • MCP server capability negotiation (prompts/list on non-supporting servers)

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Mar 12, 2026
  2. github-actions commented on Mar 12, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or related to existing issues. Please check:

    Please review the above to determine if this should be consolidated with any of them, or if the specific root cause (permission ruleset serialized into every log line) is sufficiently distinct to warrant its own tracking.

  3. htafolla commented on Apr 13, 2026

    @htafolla

    Confirmed with smaller skill count (0xRay/StringRay plugin)

    Seeing the same pattern with a much smaller setup — proving this isn't limited to high skill counts.

    Environment

    • OpenCode: 1.1.27
    • Plugin: strray-ai (0xRay agent orchestration framework)
    • Installed Skills: 0 (only 7 MCP subagent entries in opencode.json)
    • MCP Servers: 7 (all strray agents configured as mode: subagent)

    Measurements (26-minute session)

    Metric Value
    Session log 41 MB, 41,477 lines
    Permission evaluate lines 36,441 (87.8%)
    Unique tool evaluations 155
    Avg permission log line 1,125 bytes
    Total permission log bytes 41.1 MB
    Log growth rate ~1.6 MB/min
    RSS growth (sustained) 57 MB/min after initial burst

    Memory Impact

    The permission ruleset is held in V8 memory as string history:

    Uptime RSS Delta
    T+1min 2,120 MB Initial load
    T+3min 3,793 MB +1,673 MB burst (language servers, indexing)
    T+8min 3,523 MB Plateau (GC reclaimed)
    T+21min 4,258 MB +736 MB sustained growth
    T+26min 3,822 MB ~57 MB/min sustained

    Key finding: sockets and handles are stable (not leaking). The memory growth correlates directly with log buffer accumulation — 87.8% of which is the permission ruleset being re-serialized on every evaluate call.

    Minimal Reproduction

    Even with zero custom skills and only 7 MCP servers, the 14-rule default ruleset gets logged on every permission check. The bloat scales linearly with session activity — not skill count.

    Suggested Fix

    The evaluate log line should log only the pattern and action, not the full ruleset:

    // Before (current):
    INFO service=permission permission=bash pattern="ls" ruleset=[...] evaluate
    // After (proposed):
    INFO service=permission permission=bash pattern="ls" action=allow evaluate
    

    This alone would cut log volume by ~90% and eliminate the sustained memory growth from permission log buffering.

  4. boyingliu01 commented on Apr 14, 2026

    @boyingliu01

    I just experienced the exact same issue - a single log file grew to 33GB within 23 hours of an OpenCode session running overnight.

    My Case

    Component Details
    OpenCode 1.4.3
    OS WSL2 Ubuntu on Windows (D drive)
    Log file
    Duration ~23 hours (00:54:50 to 23:35:47)
    Size 33GB (1,205,817 lines, ~27KB avg per line)
    Skills installed ~150+
    D drive impact 98% full (294G/301G) - caused WSL instability

    Root Cause Confirmed

    The log tail shows exactly the pattern described in this issue:

    INFO 2026-04-13T15:35:13 +0ms service=permission permission=skill pattern=evomap-publish ruleset=[{...hundreds of rules...}] evaluate

    Every permission check dumps the entire ruleset JSON array (~27KB in my case).

    Impact

    • WSL VHDX grew to 92GB
    • Tabby terminal disconnected due to disk exhaustion
    • Had to manually delete the 33GB log file
    • Required VHDX compaction to reclaim space

    Workaround Applied

    Added cron job for log cleanup:

    (crontab -l 2>/dev/null; echo "0 4 * * * find ~/.local/share/opencode/log -type f -mtime +3 -delete") | crontab -
    (crontab -l 2>/dev/null; echo "30 4 * * * find ~/.local/share/opencode/log -type f -size +500M -delete") | crontab -

    This is a critical issue that can silently exhaust disk space and crash user systems. The proposed P0 fix (remove ruleset from INFO logs or log only matched rule) would completely solve this.

  5. boyingliu01 commented on Apr 14, 2026

    @boyingliu01

    Workaround Verified: --log-level WARN Effectively Solves Log Bloat

    After experiencing the same issue (50GB+ log accumulation within hours with ~100 skills installed), I verified that using --log-level WARN completely eliminates the permission ruleset log bloat.

    Verification Results

    Metric Before (INFO) After (WARN)
    Permission log entries 900+ per session 0
    Log file size 16-365 MB per session 47 KB per session
    Total log directory 648 MB 212 KB

    Workaround Implementation

    Created a wrapper script that always starts OpenCode with --log-level WARN:

    # ~/.local/bin/opencode-wrapper
    #!/bin/bash
    exec /home/USER/.opencode/bin/opencode --log-level WARN "$@"

    Then added alias in shell config:

    alias opencode="~/.local/bin/opencode-wrapper"

    Key Observation

    The --log-level CLI flag does work for the main process. The permission service logs (service=permission) at INFO level are suppressed when using WARN level.

    This suggests:

    1. The P0 fix (move ruleset to DEBUG/TRACE level) would be simpler than expected - just change the log level for permission service entries
    2. Users can mitigate immediately with this workaround without waiting for upstream fix

    Suggested P0 Fix

    Since the permission ruleset is logged at INFO level, changing the permission service logging to DEBUG or TRACE would solve this completely:

    // Before (current behavior)
    log.info({ permission, pattern, ruleset: fullRuleset }, "evaluate")
    
    // After (proposed fix)
    log.debug({ permission, pattern, matchedRule }, "evaluate")  // Only matched rule, at DEBUG level

    This would:

    • Eliminate 148KB per permission log line → ~100 bytes
    • Reduce INFO-level noise significantly
    • Allow users who need debugging to use --log-level DEBUG to see full ruleset

    Environment: OpenCode 1.4.3, Linux, oh-my-openagent plugin, ~100 skills

  6. boyingliu01 commented on Apr 15, 2026

    @boyingliu01

    Windows Environment Reproduction

    Confirmed the same issue on Windows 11 (WSL2 hybrid environment).

    Environment

    • OS: Windows 11 Pro + WSL2 (Ubuntu)
    • OpenCode: 1.1.XX (latest via scoop)
    • Installed Skills: ~200+ skills

    Findings

    Log location: C:\Users\think.local\share\opencode\log

    Log file sizes:

    • 2026-04-14T012210.log - ~1GB
    • Multiple files 100MB-500MB
    • Total: ~2GB+ in log directory

    Permission log analysis:

    • 12,696 permission log lines in a single day
    • Each line contains full ruleset JSON (~30KB per line vs ~148KB on macOS)
    • Log level hardcoded to INFO for permission service

    Root Cause Confirmed

    1. Primary: service=permission logs contain full ruleset at INFO level
    2. Secondary: CLI --log-level flag doesn't affect file logging (issue bug: --log-level CLI flag not passed to Worker, file logs always INFO #13158)
    3. Tertiary: No log rotation or cleanup

    Temporary Workaround

    Created wrapper script (oc.bat) to pass --log-level WARN:
    @echo off C:\Users\think\scoop\apps\bun\current\bin\opencode.exe --log-level WARN %*

    Note: Only suppresses console - file logs still INFO due to #13158.

    Suggested Fix

    1. P0: Remove ruleset from permission INFO logs (move to DEBUG)
    2. P0: Make file log level respect --log-level CLI flag (bug: --log-level CLI flag not passed to Worker, file logs always INFO #13158)
    3. P1: Implement log rotation with size limits

    Affects all platforms with many skills.

  7. nabeelio commented on May 2, 2026

    @nabeelio

    I closed my issue since it was a duplicate, but just adding some more datapoints: #25433

  8. nabeelio commented on May 2, 2026

    @nabeelio

    It seems a top level "logLevel": "WARN" in the opencode.jsonc dialed the log level down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions