GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — fix: harden session diffs, snapshots, and write paths; cut worker-thread stalls under parallel agents by AceRothstein71 · Pull Request #48638 · anomalyco/opencode Conversation
|
| bytes | |
|---|---|
dev |
4 × 300,511 = 1,202,044 |
| this branch | 1 × 300,341 |
| avoided | 901,703 (75.0%) |
A changed diff set still writes one full event, so the pessimal workload is neutral rather than worse.
One deliberate behavior change: a diff event for a turn that is not cached and has no in-flight load no longer triggers a fetch to go find it. The diff appears on the next fetch that includes that turn. No persisted data is lost. I took this route because the alternative required reworking the session client's sync-lifetime model, which is a pre-existing concern on dev and much larger than this fix — happy to follow up on that separately.
bun typecheck clean in schema, core, opencode, app and tui.
Test counts on the branch: schema 15/0, core 1098/0, tui 203/0, app 672 pass with 9 failures that are pre-existing (a clean dev worktree gives 645 pass / 10 fail on the same suite). packages/opencode was 3596/0 on this content; my sandbox later ran out of disk and that suite went non-deterministic on dev too, so I am flagging that rather than claiming a clean run.
For the measurement I wrote a fixture that drives real summarize calls with snapshot tracking and counts durable EventTable rows, so the 75.0% comes from bytes actually written rather than from a mock.
Every new test was written mutation-first: break the behavior, confirm the suite still passes, add the test, confirm it fails, revert, confirm it passes. That protocol caught several tests that could not fail.
Live profiling of multi-agent workloads surfaced more issues in the same pipeline. Additional commits now on this branch:
Session diff pipeline
summarize runs its early-return checks before writing/resetting diffs; the projector skips redundant message_diff upserts; diffFull/revert yield between batchesturnMessages pages newest-first and stops at the target turn (no full-history scans)snapshot.patch() when the completed tree equals the tracked treediff() reads the stored turn diff directly instead of walking message pagestruncated flagWrite path / responsiveness
message.part.delta events (one cross-thread message per flush instead of one per token)SELECT/EXPLAIN runs on a second read-only connection (PRAGMA query_only), writes stay gated, statements inside a transaction route through the transaction connection; WAL growth bounded (wal_autocheckpoint = 4000, journal_size_limit = 32MB, 5-minute wal_checkpoint(PASSIVE) loop); shell tool throttles per-chunk durable metadata writes to 200 ms with a guaranteed trailing flush; file-backed split-driver tests addedValidation for these additions: packages/core typecheck clean + full suite 1101 pass / 0 fail; packages/opencode typecheck clean + 9-file battery 222 pass / 1 skip / 0 fail; prettier clean; the write-path change set was independently reviewed by two models, both SHIP.
Documented limitations (intentionally unchanged): summarize early-returns also skip the diff reset on snapshot: false / empty-turn / non-user paths; the step-finish patch skip can miss worktree writes landing between track() and the patch re-stage (mirror-image race pre-existed); oversized files surface an empty patch with truncated: true for consumers that opt in.
Since the original description, this branch picked up a set of performance and robustness follow-ups:
Session diff pipeline
summarize runs its early-return checks before writing or resetting diffs, and the projector skips redundant message_diff upserts.turnMessages pages newest-first and stops at the target turn instead of scanning the full history; diff() reads the stored turn diff directly.snapshot.patch() when the completed tree is unchanged.message.diff.updated payloads are tombstoned instead of deleted (per-aggregate seqs stay contiguous for replay); per-file patch text is capped at 1 MB with a truncated flag.Write path / responsiveness
message.part.delta events.wal_autocheckpoint = 4000, journal_size_limit = 32MB, and a 5-minute wal_checkpoint(PASSIVE) loop.Validation
packages/core typecheck clean, 1101 pass / 0 fail; packages/opencode typecheck clean, battery 222 pass / 1 skip / 0 fail; prettier clean.sqlite-split tests cover cross-connection read-after-write, in-transaction visibility, and rollback isolation.Documented limitations
summarize early-returns skip the diff reset on snapshot: false, empty-turn, and non-user paths; historic diffs persist until the next summarize.track() and the patch re-stage; the mirror-image race pre-existed.patch with truncated: true; consumers rendering that flag can follow up.Closes #48848 (snapshot transaction serialization, included in this branch).
Also closes #48848.
index.lock deadlock after a crash; per-snapshot git add -A cost on very large workspaces remains git-bound.fix(tui): the TUI worker drops the bridge's duplicate "sync" mirrors before forwarding events over the RPC. Those copies exist for workspace sync consumers and the TUI ignores them on receipt, so they no longer cross the thread boundary, cutting event-forwarding volume further under heavy lane load.fix(snapshot): the snapshot machinery now recovers from a corrupt index in its derived snapshot gitdir. It detects git's index-corruption error, deletes the derived index, retries the command once, and logs snapshot_index_corruption_recovered. Previously a corrupt index silently wedged every subsequent snapshot. A new worker-level regression test proves the one-shot recovery.Closes #42237.
6c1ddb3): closes a silent-corruption gap found in review - a truncated index could make track record the git empty tree as a successful snapshot (revert then treats every file as absent). track now detects the empty-tree result, rebuilds the derived index and recaptures once (a genuinely empty worktree is still accepted), corruption detection covers the index-listing commands and more git error shapes, and recovery retries safely when two lookups race. Added corrupt- and truncated-index recovery tests that assert the recovered tree contains the changed file.fix(snapshot): heal silent empty-tree snapshots and widen index corruption recovery — a truncated index could previously record the git empty tree as a successful snapshot, and a later revert would treat tracked files as absent; track() now detects the empty tree, rebuilds the derived snapshot index and recaptures once (a genuinely empty worktree is still accepted), corruption detection also covers the index-listing commands and more git error shapes, and the recovery retry is safe under concurrent double-recovery. New regression tests cover corrupt and truncated index recovery and assert the recovered tree contains the changed file.Addresses #49565 — the permission-path, turn-diff, event-fanout, and snapshot-churn fixes described there land on this branch as they are reviewed.
Cuts per-event and per-step work on the session worker thread so many concurrent lanes stop queueing behind it:
from === to turn spans short-circuit before diffFull; the last turn diff is memoized per session/message (non-empty results only, bounded) with single-flight summarize; the summarize fork is skipped when a step's snapshot tree is unchangedpatch(hash, { to }) diffs the two trees directly instead of re-staging the shared snapshot indexserver.desync marker when they fall behindLocation.Info payload is memoized and frozen; part deltas merge by part key instead of adjacency; raw deltas no longer dispatch to plugin hooks; the periodic WAL checkpoint interval is jitteredValidation: core typecheck + full suite 1106 pass / 0 fail; opencode typecheck + snapshot/session/event batteries 122 tests / 0 fail (one wall-clock-sensitive snapshot-lock test flaked at 10.4s under live load; reruns pass at 6.3s); prettier clean. Treats the worker-thread saturation described in #49565.
PATCH_CONTEXT_LINES defaulted to 2_147_483_647, which overflows git's hunk-merge arithmetic: every hunk re-emitted the whole file, producing >1 GB of patch text and ~11 s of CPU per filesystem event (#49267). The diff path now clamps the effective context to MAX_PATCH_CONTEXT_LINES (1,000,000) so hunks merge into one full-context hunk per file; a regression test edits a file 400 lines apart and asserts it is emitted exactly once.
Closes #49267.
The filesystem search layer rebuilt its directory index on every ripgrep entry (Array.from per file) and re-joined path prefixes, making initial scans of large trees O(files × directories) (#37869). Directories now accumulate in place in a set and materialize once per query; the search-layer suite covers it.
Closes #37869.
The filesystem search index rebuilt state.directories with Array.from(...) on every ripgrep entry (O(files × directories) for large trees) and re-joined every path prefix per entry. Directories now accumulate in a Set in place with incremental prefixes and are materialized once per query.
Closes #37869.
The per-directory instance cache was unbounded: a long-lived serve process that visits many directories kept every instance (and its bootstrap resources, including MCP child processes) alive until an explicit dispose. The cache now holds at most 16 instances, refreshing recency on access and evicting the oldest completed entry (in-flight boots are never evicted). A regression test loads 17 directories and asserts the first is disposed.
Reverted in 4551204c pending an in-use guard (refcount + awaiter protection); see #47727 for requirements.
Full-branch audits (two independent reviewers) produced ranked P0-P3 findings; this commit addresses the blocking ones:
diffFull now returns undefined on failure or when snapshots are disabled, and summarize never publishes an empty diff over a stored one (prevents silent, unrecoverable diff loss under lock contention)server.desync marker was removed (no wire-protocol change):memory:, disableWAL), preventing dirty readsFileDiff.truncatedReviewed but not fixed in this branch: #46341 (partially addressed by the write-amplification fixes here), #49552, #42306, #46437 (upstream Bun/Effect fix pending), #34574 (bundled AI SDK runtime).
Post-audit hardening based on two independent full-branch reviews:
diffFull now returns undefined on lock failure or disabled snapshots, and summarize never publishes an empty diff over a stored one (closes the silent data-loss path)server.desync marker was removed:memory:, disableWAL) so they cannot observe uncommitted rowsFileDiff.truncatedReviewed but not fixed here (tracked upstream): #46341 (large-history CPU/memory — this branch removes most of the write amplification; retention policy is a follow-up), #49552 (web render cost — the client already batches per frame; deeper render work pending), #42306 (TUI spinner cost lives in the render dependency; animations can be disabled), #46437 (Bun serve dispatch regression; upstream fix in bun), #34574 (listener leak inside the bundled AI SDK runtime; our own listener usage was audited clean).
Live profiling showed the session worker thread pinned at ~99% while the database saw zero events — the remaining cost was the non-durable per-token delta path. Streaming message.part.delta events are now accumulated per part field in the processor and flushed on a 40 ms cadence (or immediately before the part's final text/reasoning update), so one publish covers a whole window instead of one per token. Final part content is unaffected because the completed part is still published by the existing text-end and reasoning-end updates.
Live profiling on a busy instance showed the session worker pinned at ~99% CPU while the durable event tables saw zero writes — the remaining load was the non-durable per-token delta path. Streaming deltas are now accumulated per part field in the processor and flushed on a 40 ms cadence, or immediately before the part's final full update (text-end / reasoning-end), so ordering is preserved and final part content is unchanged while the pipeline sees one publish per window instead of one per token.
Closes #49974
Tracking (stacked-PR plan): #49974 (perf/runtime), #49975 (shell classifier H-L), #49976 (shell classifier M-P), #49977 (instance lifecycle), #49978 (MCP/schema), #49979 (server/SSE + event/db), #49980 (updater tooling).
Original tracker: #49565.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Avoid re-appending a summarized user message's full patch array in each message.updated.1 event. Preserve the first durable diff event and projection value for replay compatibility while compacting later updates.\n\nThe focused SQLite regression fixture reduces the repeated event row from 262515 bytes to 284 bytes (99.89%). Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Record the chosen replay-compatible event compaction, failing-before and passing-after output, SQLite byte measurement, verification, and residual risk. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Compact only patch bodies when SQLite-normalized summary diffs exactly match the projected value. Changed summaries retain their full new patches, and replay restores compact event patches without decoding every projection.\n\nThe real summarize regression covers changed diffs and fresh replay. The repeated fixture event falls from 262515 bytes to 360 bytes (99.86%). Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Keep the requested evidence report as a local untracked deliverable rather than adding it to the upstream branch. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
|
Tracking issues created for this integration branch (stacked-PR plan): #49974 perf/runtime, #49975 shell classifier H-L, #49976 shell classifier M-P, #49977 instance lifecycle, #49978 MCP/schema, #49979 server/SSE + event/db, #49980 updater tooling. Each issue carries its per-subsystem commit list; this PR is intended to be split into the corresponding stacked PRs with the integration branch kept as reference. Original tracker: #49565. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Retry once after stripping caller-bound reasoning.encrypted_content when the provider rejects it, matching overflow recovery. Adapted from PR anomalyco#48918 by 传康Kk <[email protected]>. Fork scope: core runner + @opencode-ai/llm classifier + tests only. The packages/opencode legacy processor path from the PR is intentionally excluded (heavily diverged in this fork and out of Wave Q scope). Type-only adaptation: SessionStaleReasoning.stripOpenaiReplay is typed against the schema ProviderMetadata shape to satisfy this fork's tsgo.
Retry once after stripping caller-bound reasoning.encrypted_content when the provider rejects it, matching overflow recovery. This ports the packages/opencode side of PR anomalyco#48918 (server handler -> SessionPrompt -> SessionProcessor -> llm) that Wave Q intentionally left out. Adapted from PR anomalyco#48918 by 传康Kk <[email protected]> (V1-path port, Wave R). Fork scope: provider/error.ts classifier, session/stale-reasoning.ts sanitizer, session/processor.ts retry-once hook, message-v2.ts serialization, and tests. Adaptation: processor.ts diverged ~+329 lines from the merge-base, so the hook was mirrored onto the fork's retry/backoff + finalizeRetryInflight structure instead of cherry-picking. outputStarted()/recoverStaleReasoning follow upstream.
Resolve bun.lock + packages/sdk/js/package.json drift: take upstream (sdk 1.18.32) and keep the opencode ajv devDependency. Restores clean patch replay for the autopatcher.
Parallel agents in one worktree call track() at every step boundary and each capture is a full stage + write-tree pass behind the per-gitdir lock. Callers now share a queued capture (taken after they asked) and a burst of N costs at most two captures. 20 parallel track() on a 2000-file worktree: 1044/517/403 ms -> 75/57/63 ms.
Every opencode process appends to one log file with no cap (679 MB observed). Rotate to opencode.log.1 at logger startup, best effort so a concurrent rotation or read-only dir never blocks logging.
|
This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2. — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Durable event table bloats from repeated turn diff payloads snapshot.diffFull hangs process and exhausts memory on large generated text files opencode.db grows to ~9 GB due to enormous message.updated.1 event snapshots snapshot: corrupt index causes repeated capture failures and unresponsive service Performance: inefficient O(N^2) ripgrep callback
There was an error while loading. Please reload this page.