GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Worker-thread saturation under concurrent sessions: permission matching, turn-diff recomputation, event fanout, snapshot churn · Issue #49565 · anomalyco/opencode

Worker-thread saturation under concurrent sessions: permission matching, turn-diff recomputation, event fanout, snapshot churn #49565

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Worker-thread saturation under concurrent sessions: permission matching, turn-diff recomputation, event fanout, snapshot churn#49565
Copy link
Assignees
kitlangton

Description

@AceRothstein71
AceRothstein71
opened on Sep 17, 2026
Issue body actions

Summary

With 8+ concurrent sessions (subagent lanes running bash-heavy work), a single instance visibly slows down: the Worker thread that processes session events saturates at ~90-99% of a core in userspace JS (no syscall blocking, no lock waits), and every lane queues behind it. Measured on a 16-core/62GB Linux box while 8 lanes ran: DB event rate ~2.4/s, WAL bounded by autocheckpoint, read/write lane split active, CPU/RAM headroom, network fine. The cost is per-event/per-step JS work on that one thread.

Contributors and fix directions

1. Permission matching path

  • packages/core/src/util/wildcard.ts compiles a fresh RegExp per comparison, called per rule per pattern for every tool call.
  • packages/opencode/src/permission/index.ts emits an INFO log line per pattern evaluation.
  • Direction: cache compiled regexes (keyed pattern + platform flag), demote or throttle the per-pattern log line, hoist rulesets.flat() out of the hot path.

2. Turn diff recomputation

  • packages/opencode/src/session/summary.ts runs on every step-finish and always diffs the first step-start tree against the last step-finish tree; the no-change dedup sits after the expensive diffFull, so step k re-diffs steps 1..k — quadratic jsdiff work per turn, multiplied by lane count.
  • Direction: memoize the last computed (from, to) pair per session/message, skip identical pairs, single-flight/coalesce per session, and short-circuit from === to before the git work.

3. Event fanout / SSE

  • packages/opencode/src/server/routes/instance/httpapi/handlers/event.ts enqueues events for every connection into an unbounded queue and filters afterwards; RSS grows with lane count.
  • packages/opencode/src/event-v2-bridge.ts constructs a fresh Location.Info schema instance plus AbsolutePaths per published event even though they are constant per directory/workspace.
  • collapseEventBatch only merges adjacent deltas, which rarely happens while sessions interleave.
  • Direction: filter before enqueue, bound queues, memoize the location payload, merge deltas by part key.

4. Snapshot churn

  • Per-step track() runs continuously under many lanes (~19/min observed) and all lanes share one derived snapshot gitdir, so their git transactions serialize; patch() re-runs the full add-scan immediately after the preceding track().
  • Direction: reuse the staged index for patch(), thread an unchanged flag into summarize, memoize exclude/sync scans. Do not debounce track() itself — the snapshot race tests depend on the current behavior.

5. Smaller items

  • Doom-loop detection rebuilds a JSON needle per tool-result event.
  • Unbounded in-memory maps (approved-permission list, TUI stores) grow with session count.
  • Session-layer delta coalescing is worth doing only after the above items are measured; worker-thread sharding is out of scope.

Notes

  • Suggested way to attribute the remaining cost precisely: run a controlled 8-session repro with bun run src/index.ts --cpu-prof-md --cpu-prof-dir=/tmp/prof (the profiler cannot attach to a running process), plus an event-loop lag probe while the lanes run.

Activity

  1. github-actions
    assigned
    kitlangton
    on Sep 17, 2026
  2. github-actions commented on Sep 17, 2026

    @github-actions
    github-actionsBot
    on Sep 17, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • No issue template was used. Please use one of: Bug Report, Feature Request, or Question.
    • The issue reads as AI-generated content (comprehensive multi-section analysis with precise file paths, measurements, and fix directions across 5 distinct subsystems). AI-generated walls of text are not acceptable per our guidelines.
    • Bug reports should include reproducible steps and system information so maintainers can verify the problem independently.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue may overlap with existing issues. Please check:

    • Unbounded growth of the event table: opencode.db reaches 13GB+, mostly message.updated.1 snapshots (no retention/compaction) #33356: Unbounded growth of the event table / snapshot churn — covers similar ground to your points 3 (event fanout) and 4 (snapshot churn)

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. github-actions
    added
    needs:complianceThis means the issue will auto-close after 2 hours.
    on Sep 17, 2026
  4. AceRothstein71 commented on Sep 17, 2026

    @AceRothstein71
    AceRothstein71
    on Sep 17, 2026
    Author
    More actions

    Update: fixes for most of the contributors listed here have landed on PR #48638 (branch tip d84bbc6):

    • Permission path: compiled wildcard regex cache, per-pattern log demoted, ruleset flattening and dedupe.
    • Turn diff: from === to short-circuit, per-session/message non-empty-only memo of the last turn diff, single-flight summarize, unchanged-step skip, and patch(hash, { to }) tree-to-tree diffs.
    • Event fanout: SSE filter-before-enqueue with a bounded dropping queue and a server.desync marker, memoized Location.Info payload, part-key delta merging, and delta skipping for plugin hooks.

    Remaining known follow-ups: session-layer delta coalescing (measure-first) and bounding the TUI store maps.

  5. github-actions commented on Sep 17, 2026

    @github-actions
    github-actionsBot
    on Sep 17, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

  6. github-actions
    removed
    needs:complianceThis means the issue will auto-close after 2 hours.
    on Sep 17, 2026
  7. github-actions
    closed this as not plannedon Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kitlangton
    kitlangton

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.