Repository navigation
fix(opencode-plugin): only commit sessions with new messages at cleanup - #5497
oliver-mee wants to merge 2 commits into
Conversation
|
there's a config in server side, where you can configure auto-commit on server, that applies to all agents. I think thats the easier way, and no extra code in plugin side. |
|
To make my previous comment precise, current {
"memory": {
"session_auto_commit": {
"enabled": true,
"check_interval_seconds": 60.0,
"scan_rate_limit_files_per_second": 2.0
}
},
"server": {
"user_config_defaults": {
"auto_commit_policy": {
"pending_token_threshold": 0,
"message_count_threshold": 0,
"idle_timeout_seconds": 600,
"keep_recent_count": 0,
"min_commit_interval_seconds": 0
}
}
}
}
Two caveats:
So for deployments where we control server config, I still prefer this centralized path over adding another OpenCode-only timer/config. The plugin-side fallback is only needed if OpenCode must support servers where this is not enabled or cannot be configured. |
ed0519f to
f210b8b
Compare
|
Thanks @ZaynJarvis, that's the cleaner route. We've turned on One note for anyone on the 0.4.22 release: there the switch is still I've cut this PR down to the cleanup fix. Cleanup now commits only sessions with new messages since their last commit, and the commit log line shows |
There was a problem hiding this comment.
Follow-up: 2026-10-14, current head de41f08162d4a69b9e6e69a6d931a0b971f7ad82
Rechecked against main ad4d99de1d95145d42b81904be2546c4302c5ac7: the cleanup guard follows pending capture inside upstream's serialized flush chain, preserves keep_recent_count: 0 and the commit watermark, and the delayed-response regression releases the response before awaiting the queued flush.
Windows / Node 24 passes 26/26 in the two affected manager/v2 test files, including both watermark regressions, both changed modules pass syntax checks, and the official version gate passes with 0.5.14 -> 0.5.15; the actual merge-tree is conflict-free and its OpenCode/shared/gate inputs match the tested author head byte-for-byte.
Temporary-fixture ENOENT log-write warnings appear during teardown; this controlled-localhost execution covers the two test files, with no complete 56-test suite, Linux, full merged server, real host/backend/auth/model, performance or legacy-state upgrade validation.
I found no additional blocker in those scoped cleanup/watermark cases, while the code and regressions remain @oliver-mee's work; my repository permission is READ, so I cannot approve workflows and these local results do not establish official CI execution or approval.
Preserved earlier review
Verbatim previous body; its stated heads, execution scope and original GitHub review metadata are historical.
Follow-up: 2026-10-04, current head 5a4289fe94c581dcd31f1df1526aca8f7ba4aea1
AI-assisted follow-up with local execution and an additional AI-assisted source review. The author's capture/committed sequence watermark addresses both findings below. I reran the original same-millisecond and capture-during-commit-response scenarios: each now makes the second commit and leaves no pending fixture messages. All seven diagnostic probes passed, including normal cleanup, empty cleanup, retryable failure/retry, keep-window and existing reentrant behavior controls. The two original scenarios also pass on current main 9d9bc85e1f6a15afa7f23b0d7bf114a7c61cad14.
The complete current-head OpenCode suite passes on Ubuntu WSL with Node 24.21.0: 55 passed, 0 failed, 0 skipped, including both new manager regressions. On Windows, it is 50 passed / 5 failed; current main is 45 passed / the same 5 failed. Those five failures are the previously reported POSIX-path fixture assertions. I did not modify the author's tests to obtain a green result.
Current main is not an ancestor of this head. The actual merge-tree is conflict-free, but differs from the head tree. Both examples/opencode-plugin and examples/memory-plugin-shared are identical between the tested head and that merge result, so the OpenCode code/tests reviewed here also match the merged view. The OpenCode release version is 0.5.5 versus current main's 0.5.4; its 22 generated shared runtime files match current main's canonical sources byte-for-byte.
I found no remaining blocker for the two reported watermark scenarios within this review scope. The three current-head official workflows are still action_required with zero jobs; these local results are not executed official CI or maintainer approval. The probes use a controlled local HTTP fixture and clock. I did not test a deployed OpenViking service, real OpenCode host workflows, or an upgrade from legacy persisted state without sequence fields. The code change and added regressions are the author's work.
Historical review: previous head f210b8b8e8738f08e4e7db9da841b8cbda34d6ea
The findings and counts below describe the old head and are superseded for the two watermark cases by the follow-up above. GitHub's original review commit metadata remains attached to that old head.
AI-assisted first-pass review of f210b8b8, with automated local validation on Windows / Node 24.21.0. No independent human code review is claimed.
One correctness blocker in the new hasUncommittedActivity() guard: wall-clock comparison does not reliably identify messages covered by a completed commit.
I reproduced both cases through the actual createMemorySessionManager() and startV2Plugin() cleanup entrypoint, using a local HTTP fixture:
- A new message in the same millisecond as the preceding commit. After the first commit, a second message is captured and POSTed while both
lastActivityAtandlastCommitTimeare1000. Cleanup sees equality, skips the second commit, and leaves the second message pending. - A message captured while an earlier commit response is delayed. The fixture snapshots the first message for the commit, then delays its response. The second message is captured and POSTed at
2100; the first response arrives at3000, causingcommitOvSession()to advancelastCommitTimepast the second message's activity. Cleanup at4000skips, leaving that second message pending even though it was not covered by the earlier commit.
On this head, each scenario issues one commit and leaves the second message pending. With the same production-client probes against current-main df32bf6e runtime, both scenarios issue the second commit and leave no pending messages. This is a client-entrypoint A/B reproduction with a fake backend, not a live OpenViking deployment.
Please use a capture/commit watermark tied to the messages actually covered by that commit, so an older request's completion cannot mark newer captured messages clean. Add these two regression cases alongside the existing quiet-cleanup test; normal new-message cleanup, empty sessions and retryable commit failure/retry controls passed in this probe.
The existing suite passed 48 of 53 tests on Windows; its five failures are unchanged POSIX path assertions that also fail on main. I submitted the independent test-only correction in #5562, where the current-main suite passes 50/50. Those fixture failures are separate from the two new cleanup regressions above. The scoped manager suite passed 13/13 and the v2 cleanup tests passed 2/2. This head currently has no check runs, and its Actions await approval, so these local results do not imply green CI.
5a4289f to
de41f08
Compare
|
Rebased onto Updated the blocked-commit test to release the response before awaiting the queued flush, so it no longer depends on a request timeout. All 56 plugin tests pass, syntax checks pass, and the plugin-version gate passes with 0.5.14 to 0.5.15. The old failed check was a version-bump failure on an earlier head. Could a maintainer approve the workflows for the new head, |
|
Please rebase onto main: #5936 (60629f9) and #5935 (a0c3574) changed |
de41f08 to
d5015c1
Compare
|
Refreshed on current main Refresh assisted by GPT-6.1 Sol. |
da33345 to
72447d1
Compare
|
Rebased onto current @ZaynJarvis on the server side point: agreed that |
72447d1 to
a6a026a
Compare
Description
On OpenCode v2, plugin cleanup commits every session in the state file, including ones with nothing new since their last commit. A server that ran many short conversations sends a stack of empty commits each time cleanup runs (an hour of inactivity, a service stop, or a hot reload).
This PR makes cleanup commit only sessions that have new messages since their last commit, and adds the server's
statusandarchivedto the commit log line so an empty commit is visible inopenviking-memory.log.An earlier revision also added a plugin-side idle timer (
commitIdleSeconds) to commit sessions once they go quiet. Following review, that part is dropped: the server'smemory.session_auto_commitscheduler with a defaultauto_commit_policyalready covers it for every harness, with no plugin code.Human Involvement
Related Issue
Refs #5494
Type of Change
Changes Made
lib/memory-session.mjs:flushSessionandflushAlltakeonlyIfUncommitted, which skips the commit when a session has no messages, or no successful captures beyond its commit watermark. It defaults tofalse, so v1 cleanup and every other caller behave as before. The commit log line now includesstatusandarchived.lib/v2-plugin.mjs: v2 cleanup callsflushAll({ commit: true, onlyIfUncommitted: true }).docs/en,docs/zhand the plugin README.package.json: version 0.5.28 to 0.5.29 for the plugin-versions check.Testing
Current refresh on macOS (arm64) with Node 26.13.1, based on
af8ae4a4cb74(heada6a026accbf0):npm --prefix examples/opencode-plugin test: 66 passed, 0 failed, 0 cancelled, 0 skipped, with an isolated test home.npm --prefix examples/opencode-plugin run check: passed.bash .github/scripts/check-plugin-version-bumps.sh origin/main: passed with 0.5.28 -> 0.5.29.node examples/memory-plugin-shared/sync.mjs: completed and left the checkout clean..github/scripts/ci_plan.py --base origin/main:plugins_changed=true,deps_changed=false, and the other optional component selectors false.git diff --check: passed.action_requiredawaiting maintainer approval; no executed upstream CI result is claimed.Checklist
Additional Notes
The branch is rebased on
af8ae4a4cb74db4414ac4860fa9ce9bace7275b3; current head isa6a026accbf008c40e15020141ac850a680d0222. Upstream had moved the OpenCode package to 0.5.28, so this PR now carries 0.5.29. Conflicts inpackage.jsonandtests/v2-plugin.test.mjswere resolved while retaining current upstream changes and restoring the cleanup regression. The implementation preserves upstream stale-session pruning, missing-session mapping removal, subagent exclusion, flush serialization, and full-backlog commit behavior.The cleanup watermark is captured when the commit request is sent. The blocked-response test queues its second flush before releasing the first response, so captures that arrive during a slow commit remain uncommitted without relying on a timeout. The server-side idle scheduler remains the preferred deployment-controlled idle mechanism; this PR retains only the cleanup watermark fix.
Model used: Claude Opus 5.5 (Claude Code) for the original code and tests. Later refreshes used GPT-6.1 Sol and Kimi under human direction.
🤖 Generated with Claude Opus 5.5; refreshed with GPT-6.1 Sol and Kimi
🧑💻 Ideated, directed and reviewed by a human, @oliver-mee