Repository navigation
Conversation
Closes Tarquinen#557 DCP persists prune state per session at $XDG_DATA_HOME/opencode/storage/plugin/dcp/{sessionId}.json. Nothing ever removed those files, so deleting a session left an orphan on disk forever - and loadAllSessionStats kept counting it, because it aggregates every file it finds in that directory. The host already emits session.deleted with the session id, and createEventHandler previously only looked at message.part.updated, so the delete branch is simply unreachable today. deleteSessionState unlinks the file and swallows the error, since the file may never have been written or may already be gone. If the deleted session is the one the plugin holds state for, the in-memory session id is detached so a later request re-initialises instead of writing the file back. The session.deleted check runs before the timestamp extraction so it cannot change the behaviour of the compression timing branch, which is covered by a test. Tests: tests/session-cleanup.test.ts, six cases. Three fail on the current implementation with `the orphaned state file survived`.
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.
Closes #557
Problem
DCP persists prune state per session at
$XDG_DATA_HOME/opencode/storage/plugin/dcp/{sessionId}.json, and nothing ever removed those files. Deleting a session left the file on disk forever, andloadAllSessionStatskept counting it — it aggregates every*.jsonin that directory, so the all-time totals drifted upward permanently.The host already emits
session.deletedcarrying the session id, butcreateEventHandleronly ever looked atmessage.part.updated:so the delete case was unreachable.
Change
deleteSessionState(sessionId, logger)inlib/state/persistence.tsunlinks the file and swallows the error, since the file may never have been written or may already be gone.createEventHandlerhandlessession.deletedbefore the timestamp extraction, so it cannot perturb the compression-timing branch. If the deleted session is the one the plugin holds state for,state.sessionIdis detached so the next request re-initialises instead of writing the file straight back.Verification
tests/session-cleanup.test.ts, six cases:session.deletedstate.sessionIdpropertiesmissing, empty id) are harmlessmessage.part.updatedtiming branch still records compression startsThree of the six fail on the current implementation with
the orphaned state file survived.Full suite 125 passing,
tsc --noEmitclean,prettier --checkclean.