GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@opencode-agent

@opencode-agent opencode-agent Bot commented Oct 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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
All reactions
  • 👍 1 reaction
@github-actions github-actions Bot added the contributor label Oct 21, 2026
@opencode-agent opencode-agent Bot assigned jlongster Oct 21, 2026
opencode-agent[bot]
opencode-agent Bot commented Oct 21, 2026
View reviewed changes

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

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.

All reactions
Comment thread packages/core/src/session/retention.ts Outdated
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* () {

@opencode-agent opencode-agent Bot Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

All reactions
@opencode-agent 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
@opencode-agent opencode-agent Bot mentioned this pull request Oct 21, 2026
refactor(core): read storage.sessions from global config files like update #57912
Closed
3 of 6 tasks
@jlongster
feat(core): add storage.sessions config to delete old sessions
eff2fd6
@opencode-agent
opencode-agent Bot force-pushed the session-retention branch from 0ee0d22 to eff2fd6 Compare October 21, 2026 20:48
@Dante-dan Dante-dan mentioned this pull request Oct 23, 2026
Database always increasing its size #58124
Open
@MercuryOoO MercuryOoO mentioned this pull request Oct 23, 2026
storage: base64 image tool outputs dominate opencode.db (538 MB of 587 MB) #58436
Open
@esafak

esafak commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@jlongster are you going to do this, because I noticed the parent ticket #16101 is closed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@opencodejr opencodejr Bot mentioned this pull request Nov 5, 2026
Critical: Session Data Management Issues - Unbounded Growth & No Cleanup #62214
Closed
@github-actions

github-actions Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Nov 21, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@jlongster jlongster

Labels

automated-pr-cleanup contributor

Projects

None yet

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.

2 participants

@esafak @jlongster
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.