GeezerVison is showing github.com — feat(core): add storage.sessions config to delete old sessions by opencode-agent[bot] · Pull Request #57882 · anomalyco/opencode
Conversation
Issue for this PR
Part of #16101
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Adds a storage config group with one field, storage.sessions. It takes a duration and is unset by default, so sessions are kept forever unless you opt in. The group can hold other local-data cleanup later (e.g. storage.snapshots).
{ "storage": { "sessions": "30 days" } }
SessionExpiry (packages/core/src/session/expiry.ts, new) runs an hourly global sweep next to the project archive sweep:
- Config read: same approach as the CLI updater's
update. It reads config.json, opencode.json, and opencode.jsonc from the global config directory, parses JSONC, and uses storage.sessions from the last file that sets it. Project config is never read, so a project can't delete other projects' sessions. As with update, a project-level value is silently ignored, and system/MDM-managed config and {env:...} substitution don't apply.
- Deletion: top-level sessions whose
time_updated is older than the cutoff are removed through Session.remove, so children, events and projections go the same way as a manual delete. Suspended sessions (owned by restart recovery) and sessions with an active execution or running background job are skipped. Non-finite or zero durations are ignored with a warning.
Deleting rows doesn't shrink opencode.db by itself; reclaiming pages is separate (#56365).
How did you verify your code works?
bun test test/session-expiry.test.ts: deletes an expired top-level session and its child, keeps a recent one and a suspended one, reads the value from a temp global config dir (unset → keep), and decodes JSONC edge cases
bun test test/config/normalization.test.ts with a new storage.sessions case
- server
session-create, config, workerd tests with the node in the route graph
tsc -b for core (including tests) and server; regenerated protocol/www OpenAPI and client types
Screenshots / recordings
N/A
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Requested by: @jlongster (James Long via Slack)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mwielgosz-esky reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as described. I ran serve from source with isolated config and data dirs and moved two sessions' time_updated back 40 days. With session_retention: "30 days" only in the project's opencode.json, nothing was deleted. With it in the global opencode.json, startup deleted the two old sessions and kept the recent one. The new tests and the normalization test pass, and type checks pass for core (with tests) and server.
Public API: adds an optional session_retention config key (a duration string) to Config.Info, plus the matching OpenAPI schema and generated client type. Nothing is removed or changed and the default is unset, so this is backwards compatible. The key is only read from global, system and managed config; if it is set in a project config it is accepted but ignored.
One thing worth fixing: the sweep rebuilds a full config service every hour just to read one key (see inline comment).
Related: #55293
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
const SWEEP_INTERVAL = Duration.hours(1)
|
|
|
|
|
|
/** Reads `session_retention` from global, system, and managed config. Project config never applies. */
|
|
|
export const configured = Effect.fn("SessionRetention.configured")(function* () {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configured() builds a new Config.layer on every hourly sweep, even when session_retention is unset. That layer does more than read files: it sets up watchers on the config roots (in my run they started and stopped on /etc and /root at each sweep), resolves well-known config again (an HTTP fetch of remote_config for organisations that use one), and forks reload and refresh fibers that are thrown away right after. Every user would pay this cost hourly just to read one key. Could this read the global, system and managed documents in a lighter way (for example ConfigDiscovery plus parsing just those files), or keep one long-lived global-scoped config instead of rebuilding it each sweep?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
opencode-agent
Bot
changed the title
feat(core): add session_retention config to delete old sessions
feat(core): add storage.sessions config to delete old sessions
Oct 21, 2026
|
@jlongster are you going to do this, because I noticed the parent ticket #16101 is closed?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Automated PR Cleanup
Thank you for contributing to opencode.
Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.
This PR was closed because it matched the following cleanup criteria:
- The PR was created more than 1 month ago
- The PR had fewer than 2 positive reactions
- Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR
PRs created within the last month are not affected by this cleanup.
If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.
Thanks again for taking the time to contribute.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|