fix(opencode-plugin): decouple flush/threshold-commit from session.idle and make state save process-safe - #3691
Open
TE-N-ElvenWang wants to merge 17 commits into
Conversation
…le and make state save process-safe
Author
|
虽然是AI写的patch啊,但是问题是opencode里用openviking的话会导致上传信息不准确的问题。尤其是多个opencode进程一起开着的时候。 |
…t duplicate sends
…lush overlap guard
…drop gate auto-reset
… intervalMs clamp
… avoid PID-reuse leak
…ng, temp sweep; harden intervalMs fallback
…ng, temp sweep; harden intervalMs fallback
…n; strengthen drain/dead-pid tests
…n; strengthen drain/dead-pid tests
Author
|
all patches are refined by open-code-review tools with claude opus 4.8. |
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.
Problem
The opencode plugin's message flush and threshold-commit path
(
flushPendingMessages→maybeCommitByThreshold) is wired exclusively to thesession.idleevent. OpenCode emitssession.idleonly when an assistant turnfully completes (no queued work). During long multi-step agent turns
(back-to-back tool calls),
session.idleis never emitted, so:captured: falsebut are never POSTed.pending_tokenson the server never grows.commitTokenThresholdis never reached, so threshold-basedcommits never fire.
dispose(shutdown) viaflushAll.Additionally,
saveStateuses a single fixed temp file (${statePath}.tmp).When two opencode processes run concurrently, both race on the same
.tmp,causing
ENOENTrename failures and cross-process state clobbering.Fix
Fix A: Process-safe temp file
Use a per-PID temp file:
${statePath}.${process.pid}.tmp— eliminatescross-process
ENOENTrename races.Fix B: Periodic flush timer
Add a
setInterval-based periodic flush independent ofsession.idle:periodicFlushIntervalMs, floor 10s)flushSession(..., { reason: 'periodic' })init(), cleared influshAll(),.unref()'dThis decouples the send + threshold-check path from
session.idle, so messagesflush and threshold commits fire even during long multi-step agent turns.
Verification
Tested in production:
Periodic flush timer startedappears at startup;pending_tokensaccumulates during long turns; threshold commit fires at≥20000 without
dispose; zeroENOENTraces under dual-process concurrency.