Skip to content

Running opencode locally and in docker while sharing config corrupts the database #14194

Closed as not planned

Description

@d4rky-pl

Description

If you run opencode locally and in docker and share ~/.local/share/opencode/, ~/.local/state/opencode/ and ~/.config/opencode/ with the container it will lead to sqlite corruption if you try to run two sessions at the same time:

  ┃  588 |           session_id: sessionID,
589 |           time_created,
590 |           data, GitHub Copilot
591 |         })▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
592 |         .onConflictDoUpdate({ target: MessageTable.id, set: { data } })                                                                                                                                    ctrl+t variants  tab agents  ctrl+p commands
593 |         .run()
               ^
SQLiteError: database disk image is malformed
      errno: 11,
 byteOffset: -1,
       code: "SQLITE_CORRUPT"

      at #run (bun:sqlite:185:20)
      at <anonymous> (src/session/index.ts:593:10)
      at run (node:async_hooks:62:22)
      at use (src/storage/db.ts:111:28)
      at <anonymous> (src/session/index.ts:584:14)
      at process (src/session/processor.ts:411:25)

Plugins

No response

OpenCode version

No response

Steps to reproduce

  1. Run opencode session locally
  2. Run another opencode session in Docker container with
  -v "$HOME/.local/state/opencode:/home/node/.local/state/opencode" \
  -v "$HOME/.local/share/opencode:/home/node/.local/share/opencode" \
  -v "$HOME/.config/opencode:/home/node/.config/opencode" \
  1. Start agent session (e.g. ask it to review the codebase)

Screenshot and/or share link

It crashes immediately when the next session starts
https://opncd.ai/share/fbRFgNq0

Operating System

macOS 15.7.4

Terminal

iTerm

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 18, 2026
  2. added a commit that references this issue on Feb 20, 2026
    c547a06
  3. dejwi commented on Feb 21, 2026

    @dejwi

    same

  4. Miskamyasa commented on Feb 25, 2026

    @Miskamyasa

    Same issue

  5. Dulani commented on Feb 27, 2026

    @Dulani

    This looks very similar to #14970 (NFS/WAL corruption), just via a different trigger. In our case the corruption didn’t come from local + Docker, but from two different servers sharing the same NFS home directory. The underlying pattern is the same: multiple opencode processes on different “hosts” are writing to the same global SQLite DB (~/.local/share/opencode/opencode.db), and WAL/SHM is not safe across NFS clients.

    Why it was a problem for us:

    • We opened opencode on server A, then later on server B (same user, same NFS home).
    • Both processes wrote to the same DB; corruption followed.

    Workaround that fixed it:

    • Make XDG_DATA_HOME host-specific in .bashrc, e.g.
      export XDG_DATA_HOME="/home/RAND.ORG/dwoods/.local/share/opencode-vincent"
    • That isolates the DB per server and avoids cross-host WAL/SHM issues.

    Durable fix ideas:

    • Detect NFS (statfs 0x6969) and either warn or force a local DB dir.
    • Add a configurable DB location override (env var) so users can opt into local storage.
    • Optional: disable WAL on NFS or add integrity checks + auto-recovery.

    If this aligns with maintainers’ direction, I’m happy to help craft a PR that adds NFS detection + local fallback + explicit override.

  6. Miskamyasa commented on Feb 27, 2026

    @Miskamyasa

    How to disable sqlite? And continue using files. Don't see any benefits actually.
    I'm using devcontainers and several worktrees and mount the same XDG folder. Separate db instance will make sessions not sharable between them

  7. Miskamyasa commented on Mar 3, 2026

    @Miskamyasa

    Does it mean that we cannot share the database at all? All sessions will be saved for a particular container only.

  8. Dulani commented on Mar 3, 2026

    @Dulani

    Does it mean that we cannot share the database at all? All sessions will be saved for a particular container only.

    Unless you implement something to migrate session info from one DB to another (or somehow mount the db to the container... likely one mount at a time), then I do think that's what it means.

  9. igorwang commented on Mar 5, 2026

    @igorwang

    Same issue

  10. tdgroot commented on Mar 7, 2026

    @tdgroot

    Just found out the hard way as well 😅

  11. Miskamyasa commented on Mar 9, 2026

    @Miskamyasa

    What options do we have? Still on 1.1.63 because of this and can not use GPT 5.4 models

  12. Miskamyasa commented on Mar 11, 2026

    @Miskamyasa

    Guys, three weeks have passed. Maybe we can add a variable, perhaps OPENCODE_AVOID_SQLITE or something, to prevent SQLite usage?

  13. d4rky-pl commented on Mar 16, 2026

    @d4rky-pl
    Author

    @thdxr any chance this issue could get some love? It's really frustrating to break sqlite over and over again accidentally 🥲

  14. Miskamyasa commented on Mar 17, 2026

    @Miskamyasa

    @thdxr any chance this issue could get some love? It's really frustrating to break sqlite over and over again accidentally 🥲

    At the beginning, I mounted the .local/share folder from the container to a volume and bound the auth.json file from the host. It worked as a workaround. But then, when I wanted to continue the session, I realized that I needed to find the exact container to do so. Then I saw a bug with the light theme and white letters.

    Rolled back to 1.1.63

  15. d4rky-pl commented on Mar 18, 2026

    @d4rky-pl
    Author

    opencode-db-unfuck (uncorrupts your sqlite):

    #!/bin/bash
    bash -c "cd ~/.local/share/opencode && sqlite3 opencode.db '.recover' | sqlite3 opencode.db-recovered && mv opencode.db-recovered opencode.db"

    It's not a real solution but at least if the corruption happens to you you don't need to lose everything and can go back to your previous session and ask the model to continue. It also doesn't work on every type of corruption so if you're very unlucky, well...

  16. erlinerd commented on Mar 20, 2026

    @erlinerd

    Same issue

  17. jeffdev11 commented on Mar 30, 2026

    @jeffdev11

    same issue

  18. added a commit that references this issue on Apr 21, 2026
  19. assigned and unassigned on Apr 26, 2026
  20. randommm commented on Apr 30, 2026

    @randommm

    it seems to have solved the problem for me to mount the directories according to the current working dir:

      -v "$(pwd):/work$(pwd):Z" \
      -w "/work$(pwd)" \
    

    e.g. from https://github.com/randommm/opencode:

    podman run -it --rm \
      -v "$(pwd):/work$(pwd):Z" \
      -w "/work$(pwd)" \
      -v "$HOME/.local/share/opencode:/root/.local/share/opencode:Z" \
      -v "$HOME/.local/state/opencode:/root/.local/state/opencode:Z" \
      -v "$HOME/.config/opencode:/root/.config/opencode:Z" \
      -v "$HOME/.cache/opencode:/root/.cache/opencode:Z" \
      --network host \
      --volume /tmp/.X11-unix:/tmp/.X11-unix:ro \
      --volume $HOME/.Xauthority:/root/.Xauthority:ro \
      --env DISPLAY=$DISPLAY \
      ghcr.io/randommm/opencode
    
  21. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  22. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions