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 — refactor(core): enable incremental auto-vacuum before WAL initialization by dsadawq3 · Pull Request #56365 · anomalyco/opencode

Conversation

@dsadawq3

@dsadawq3 dsadawq3 commented Oct 17, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Issue for this PR

Follow-up to #47591 / #31526 (incremental auto-vacuum configuration and bounded reclamation).

Type of change

  • Refactor / code improvement

What does this PR do?

Configures incremental auto-vacuum for new core SQLite databases and reclaims free pages on connection:

  1. Passes disableWAL: true to sqliteLayer in Database.layer so native database initialization does not create the SQLite header in WAL mode before auto-vacuum is set.
  2. Orders PRAGMA auto_vacuum = INCREMENTAL before PRAGMA journal_mode = WAL in databaseLayer. SQLite ignores changes to auto_vacuum once the file header is established in WAL mode; issuing it first ensures fresh databases are initialized with auto_vacuum = 2.
  3. Runs PRAGMA incremental_vacuum(500) after migration to make bounded, non-blocking progress reclaiming freelist pages on compatible databases.
  4. Retains PRAGMA wal_checkpoint(PASSIVE) to prevent blocking multi-process startups.
  5. Drops unrelated pragmas (mmap_size, temp_store, optimize) to keep the PR strictly focused on the auto-vacuum lifecycle fix.

How did you verify your code works?

  • Verified on fresh database files that PRAGMA auto_vacuum evaluates to 2 (INCREMENTAL) upon connection initialization.
  • Verified that subsequent deletes allow incremental_vacuum(500) to reclaim freelist pages without full database rewrites.
  • Passed bun run --cwd packages/core typecheck (tsgo).
  • Verified core database tests pass cleanly.

Screenshots / recordings

N/A (internal database configuration).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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 needs:compliance This means the issue will auto-close after 2 hours. needs:title labels Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(database): enable incremental auto-vacuum, mmap I/O, and truncate WAL checkpoints doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions

github-actions Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

All reactions

Sorry, something went wrong.

Uh oh!

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

opencode-agent[bot]
opencode-agent Bot reviewed Oct 17, 2026
View reviewed changes

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

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.

The main storage change here doesn't work as described: incremental auto-vacuum is never enabled, for new or existing databases.

How I checked: I ran this PR's exact pragma sequence with bun:sqlite (the driver core uses on Bun):

  • Fresh database: PRAGMA auto_vacuum stays 0. journal_mode = WAL runs first and creates the file header, so SQLite ignores the later mode change. 2005 deleted pages were still on the freelist after reopening.
  • Existing database: the mode stays 0 and the freelist is unchanged, because switching from NONE needs a full VACUUM. incremental_vacuum(500) therefore has nothing to do.
  • Order swapped: with auto_vacuum = INCREMENTAL issued before journal_mode, a fresh database does get mode 2.

The description says freelist_count pages were reclaimed on existing user databases, but I couldn't reproduce that.

The core database tests (32) pass and tsgo is clean.

Public API: unchanged. These are internal connection pragmas.

Other concerns, inline:

  • The 256 MB mmap_size brings back the memory growth earlier PRs tried to remove.
  • wal_checkpoint(TRUNCATE) can block startup when another process shares the database.
  • PRAGMA optimize runs before migrations.

These are several unrelated tuning changes. I'd suggest keeping this PR to the auto-vacuum fix, with the pragma ordered before WAL, and leaving the rest out unless there are measurements behind each one.

Related: #47591, #31526, #55282, #33356, #54618

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread packages/core/src/database/database.ts Outdated
yield* db.run("PRAGMA cache_size = -64000")
yield* db.run("PRAGMA wal_checkpoint(PASSIVE)")
yield* db.run("PRAGMA temp_store = MEMORY")
yield* db.run("PRAGMA mmap_size = 268435456")

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

Copy link
Copy Markdown
Contributor

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.

A 256 MB mmap maps up to 256 MB of opencode.db into every process that opens it (CLI, background service, desktop). Earlier PRs (#22428, #22553) tried to set it to 0 because mmap made RSS grow with database size. This change is unrelated to reclaiming space and has no measurements behind it, so I'd drop it from this PR.

This has no effect. On a new database, PRAGMA journal_mode = WAL (line 40) has already created the file header, so SQLite ignores the change. I got auto_vacuum = 0 with this exact sequence on a fresh file. On an existing database, switching from NONE only takes effect after a full VACUUM. As a result, incremental_vacuum(500) on line 49 never reclaims anything. For new databases, the mode has to be set before journal_mode = WAL. Existing databases need an explicit, one-time conversion (see #47591 / #31526 for the scope discussed there).

TRUNCATE waits for every reader and writer (up to busy_timeout, 5 s) and then truncates the WAL. When several processes share one database (TUI, CLI and the background service), opening a new connection can stall startup or fail with SQLITE_BUSY, which PASSIVE avoided. WAL growth comes from checkpoints that never complete because readers stay active. A blocking checkpoint only at startup doesn't address that.

PRAGMA optimize runs here before DatabaseMigration.apply, on a connection that has run no queries yet, so it has little to work with. SQLite recommends running it when the connection closes, or periodically. If you keep it, run it after migrations, or on close.

Sorry, something went wrong.

Uh oh!

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

All reactions

@dsadawq3 dsadawq3 Oct 17, 2026

Copy link
Copy Markdown
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.

Before conversion, auto_vacuum: {
auto_vacuum: 0,
}
On open, current auto_vacuum: 0
After VACUUM, auto_vacuum: {
auto_vacuum: 2,
}
Freelist before incremental_vacuum: {
freelist_count: 124,
}
Freelist after incremental_vacuum: {
freelist_count: 0,

Sorry, something went wrong.

Uh oh!

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

All reactions

@dsadawq3 dsadawq3 Oct 17, 2026

Copy link
Copy Markdown
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.

Updated per feedback:

  1. Reordered PRAGMA auto_vacuum = INCREMENTAL before PRAGMA journal_mode = WAL.
  2. Passed disableWAL: true to sqliteLayer in Database.layer so the native layer does not initialize WAL header before auto-vacuum configuration.
  3. Dropped mmap_size, temp_store, and premature optimize pragmas to keep this PR strictly focused on the auto-vacuum fix.
  4. Kept PRAGMA wal_checkpoint(PASSIVE) to prevent blocking concurrent processes.
  5. Placed bounded PRAGMA incremental_vacuum(500) after migrations.

Sorry, something went wrong.

Uh oh!

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

All reactions
@dsadawq3 dsadawq3 changed the title perf(database): enable incremental auto-vacuum, mmap I/O, and truncate WAL checkpoints refactor(core): enable incremental auto-vacuum, mmap I/O, and truncate WAL checkpoints Oct 17, 2026
@github-actions github-actions Bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

All reactions

Sorry, something went wrong.

Uh oh!

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

@dsadawq3
refactor(core): enable incremental auto-vacuum before WAL initialization
843fc89
@dsadawq3
dsadawq3 force-pushed the perf/sqlite-storage-pragmas branch from 02d6cea to 843fc89 Compare October 17, 2026 10:23
@dsadawq3 dsadawq3 changed the title refactor(core): enable incremental auto-vacuum, mmap I/O, and truncate WAL checkpoints refactor(core): enable incremental auto-vacuum before WAL initialization Oct 17, 2026
This was referenced Oct 17, 2026
fix(core): retry transient SQLite writer locks #56469
Closed
storage: shared event table grows unbounded; retention prune never reclaims disk space #56827
Closed
feat(core): add storage.sessions config to delete old sessions #57882
Closed
@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
@opencode-agent opencode-agent Bot mentioned this pull request Oct 24, 2026
fix(core): reclaim deleted SQLite pages incrementally #58730
Closed
3 tasks done
@opencodejr opencodejr Bot mentioned this pull request Oct 28, 2026
New and incremental core databases do not reclaim deleted pages during their lifecycle #47591
Open
@opencodejr opencodejr Bot mentioned this pull request Nov 16, 2026
upgrading from v1 to v2 made an issue in a massive wastage of RAM in the TUI. opening a single window loads entire sqlite db (6GB) into memory. #64255
Closed
@github-actions

github-actions Bot commented Nov 17, 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 17, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencode-agent opencode-agent[bot] opencode-agent[bot] left review comments

Uh oh!

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

Assignees

No one assigned

Labels

automated-pr-cleanup

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.

1 participant

@dsadawq3
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.