stats command: SyntaxError: Failed to parse JSON
Description
hello
i guess its a json file that is corrupted somewhere ? Already deleted all json files that failed to parse in my ~/.local/share/opencode:
storage/message/ses_54083ec12ffeOtMmb4yMoQbN5R/msg_abf9864e1001eB66VAVeot7G8k.json storage/part/msg_abf9877a6001iIxq2Vz1WX6WSQ/prt_abf988344001VPHnbczWh0cyDu.json storage/part/msg_abf9877a6001iIxq2Vz1WX6WSQ/prt_abf987e9b001pqZxSRyN6kaOWk.json storage/part/msg_abf9877a6001iIxq2Vz1WX6WSQ/prt_abf987e91001DA63PmoYbDSdm6.json storage/part/msg_abf9864e1001eB66VAVeot7G8k/prt_abf987785001pqOsi6OYgADUOy.json storage/part/msg_abf9864e1001eB66VAVeot7G8k/prt_abf986cd2002mznKM3uYZ1gDy4.json storage/part/msg_abf9864e1001eB66VAVeot7G8k/prt_abf986cd2001Vqqm8Qj92DImxl.json storage/part/msg_abf97a095001VEGhQcBivnTi26/prt_abf9864d9001nw8Iphf4zMzrSF.json storage/part/msg_abf97a095001VEGhQcBivnTi26/prt_abf9864b4001UNgGRZFWcDEKEb.json
but still hapenning.
im sure rm the whole dir would fix it, but i would like to keep my session.
i would have hoped for the log to show which file or what did it fail to parse so i can remove only that.
thanks
OpenCode version
1.0.150
Steps to reproduce
opencode stats
Screenshot and/or share link
❯ opencode --print-logs --log-level DEBUG stats
INFO 2025-12-12T09:39:13 +180ms service=default version=1.0.150 args=["--print-logs","--log-level","DEBUG","stats"] opencode
INFO 2025-12-12T09:39:13 +0ms service=default directory=/home/mirsella/dev/bevy creating instance
INFO 2025-12-12T09:39:13 +1ms service=project directory=/home/mirsella/dev/bevy fromDirectory
INFO 2025-12-12T09:39:13 +6ms service=default directory=/home/mirsella/dev/bevy bootstrapping
INFO 2025-12-12T09:39:13 +2ms service=config path=/home/mirsella/.config/opencode/config.json loading
INFO 2025-12-12T09:39:13 +1ms service=config path=/home/mirsella/.config/opencode/opencode.json loading
INFO 2025-12-12T09:39:13 +0ms service=config path=/home/mirsella/.config/opencode/opencode.jsonc loading
INFO 2025-12-12T09:39:13 +8ms service=bun cmd=["/usr/bin/opencode","add","@opencode-ai/[email protected]","--exact"] cwd=/home/mirsella/.config/opencode running
INFO 2025-12-12T09:39:13 +3ms service=bun code=0 stdout=bun add v1.3.3 (274e01c7)
installed @opencode-ai/[email protected]
[1.00ms] done
stderr=Saved lockfile
done
INFO 2025-12-12T09:39:13 +0ms service=plugin path=opencode-gemini-auth@latest loading plugin
INFO 2025-12-12T09:39:13 +17ms service=plugin path=@tarquinen/opencode-dcp@latest loading plugin
INFO 2025-12-12T09:39:13 +48ms service=plugin path=@tarquinen/opencode-smart-title loading plugin
INFO 2025-12-12T09:39:13 +2ms service=bun pkg=@tarquinen/opencode-smart-title version=latest installing package using Bun's default registry resolution
INFO 2025-12-12T09:39:13 +0ms service=bun pkg=@tarquinen/opencode-smart-title version=latest attempt=1 total=3 bun install attempt
INFO 2025-12-12T09:39:13 +0ms service=bun cmd=["/usr/bin/opencode","add","--force","--exact","--cwd","/home/mirsella/.cache/opencode","@tarquinen/opencode-smart-title@latest"] cwd=/home/mirsella/.cache/opencode running
INFO 2025-12-12T09:39:13 +256ms service=bun code=0 stdout=bun add v1.3.3 (274e01c7)
+ @ai-sdk/[email protected]
+ @tarquinen/[email protected]
+ [email protected]
+ [email protected]
+ [email protected]
installed @tarquinen/[email protected]
120 packages installed [253.00ms]
stderr=Resolving dependencies
Resolved, downloaded and extracted [1]
Saved lockfile
done
INFO 2025-12-12T09:39:13 +2ms service=plugin path=file:///home/mirsella/.config/opencode/plugin/notify-send.ts loading plugin
INFO 2025-12-12T09:39:13 +1ms service=plugin [email protected] loading plugin
INFO 2025-12-12T09:39:13 +0ms service=plugin [email protected] loading plugin
INFO 2025-12-12T09:39:13 +1ms service=bus type=* subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=session.updated subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=message.updated subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=message.part.updated subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=session.updated subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=message.updated subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=message.part.updated subscribing
INFO 2025-12-12T09:39:13 +0ms service=bus type=session.diff subscribing
INFO 2025-12-12T09:39:13 +1ms service=format init
INFO 2025-12-12T09:39:13 +0ms service=bus type=file.edited subscribing
INFO 2025-12-12T09:39:13 +0ms service=lsp LSP server rust is disabled
INFO 2025-12-12T09:39:13 +0ms service=lsp serverIds=deno, typescript, vue, eslint, biome, gopls, ruby-lsp, pyright, elixir-ls, zls, csharp, sourcekit-lsp, clangd, svelte, astro, jdtls, yaml-ls, lua-ls, php intelephense, dart, ocaml-lsp, bash, terraform, rust-lspmux enabled LSP servers
INFO 2025-12-12T09:39:13 +0ms service=file.watcher init
INFO 2025-12-12T09:39:13 +1ms service=bus type=command.executed subscribing
INFO 2025-12-12T09:39:13 +1ms service=file.watcher platform=linux backend=inotify watcher backend
INFO 2025-12-12T09:39:13 +6ms service=vcs branch=release-0.16.1 initialized
INFO 2025-12-12T09:39:13 +0ms service=bus type=file.watcher.updated subscribing
ERROR 2025-12-12T09:39:13 +209ms service=acp-command promise={} reason=Bad file descriptor Unhandled rejection
ERROR 2025-12-12T09:39:13 +0ms service=default e=Bad file descriptor rejection
INFO 2025-12-12T09:39:14 +938ms service=default directory=/home/mirsella/dev/bevy disposing instance
INFO 2025-12-12T09:39:14 +0ms service=state key=/home/mirsella/dev/bevy waiting for state disposal to complete
INFO 2025-12-12T09:39:14 +1ms service=bus type=file.watcher.updated unsubscribing
ERROR 2025-12-12T09:39:14 +0ms service=state error=Bad file descriptor key=/home/mirsella/dev/bevy Error while disposing state:
INFO 2025-12-12T09:39:14 +0ms service=state key=/home/mirsella/dev/bevy state disposal completed
ERROR 2025-12-12T09:39:14 +6ms service=default name=SyntaxError message=Failed to parse JSON fatal
Error: Unexpected error, check log file at for more details
SyntaxError: Failed to parse JSON
Operating System
archlinux
Terminal
wezterm
This issue might be a duplicate of existing issues. Please check:
- #2135: Session becomes unusable after UnknownError: Failed to parse - Similar JSON parsing error that affects session functionality
- #4277: Getting a json parse error on the prompt history and/or token error - Similar JSON parsing error after sudden shutdown affecting sessions
- #2188: JSON parsing failed: Text - Related JSON parsing errors
Feel free to ignore if none of these address your specific case.
can't reproduce:
$ opencode --version
1.0.150
$ opencode stats
Large dataset detected (1178 sessions). This may take a while...
┌────────────────────────────────────────────────────────┐
│ OVERVIEW │
├────────────────────────────────────────────────────────┤
│Sessions 1,178 │
│Messages 41,100 │
│Days 143 │
└────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────┐
│ COST & TOKENS │
├────────────────────────────────────────────────────────┤
│Total Cost $0.01 │
│Avg Cost/Day $0.00 │
│Avg Tokens/Session 219.4K │
│Median Tokens/Session 25.2K │
│Input 245.0M │
│Output 11.5M │
│Cache Read 1964.1M │
│Cache Write 88.8M │
└────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────┐
│ TOOL USAGE │
├────────────────────────────────────────────────────────┤
│ bash ████████████████████ 13929 (32.9%) │
... snipp ...
Seems to be caused by a specific session of yours, too bad there isn't enough logging.
This would require using lsof/strace to find the offending session file.
i've drafted a small tool to find issues in sessions, maybe this will find the offending file, you could give it a try:
https://github.com/rwese/opencode_session_analyzer
yes I'm sure that's a corruption on my files. thanks a lot for the tool will report back ASAP
❯ uv run https://raw.githubusercontent.com/rwese/opencode_session_analyzer/main/oc_session_analyzer.py --verbose
Fetching session list...
Found 24 sessions
Processing session 1/24: ses_4fcb98481ffeL5jQmulnG8Fn1C
Exporting session ses_4fcb98481ffeL5jQmulnG8Fn1C...
Processing session 2/24: ses_4fcad9d3fffeV1lju0cSk3ypPF
Exporting session ses_4fcad9d3fffeV1lju0cSk3ypPF...
Processing session 3/24: ses_4fcaec0fdffeNwvH179JrS1VlQ
Exporting session ses_4fcaec0fdffeNwvH179JrS1VlQ...
Processing session 4/24: ses_4fcaf4430ffe7kTeP01Eu6b9Gn
Exporting session ses_4fcaf4430ffe7kTeP01Eu6b9Gn...
Processing session 5/24: ses_4fcafea97ffe3pNqp2ojVjG0Yc
Exporting session ses_4fcafea97ffe3pNqp2ojVjG0Yc...
Processing session 6/24: ses_4fcb26fc6ffeUzp3y0b78UiL0o
Exporting session ses_4fcb26fc6ffeUzp3y0b78UiL0o...
Processing session 7/24: ses_4fcb2d2f9ffejJKZnX3V5vKb7n
Exporting session ses_4fcb2d2f9ffejJKZnX3V5vKb7n...
Processing session 8/24: ses_4fcb35ff3ffeINVJL0H215Clf6
Exporting session ses_4fcb35ff3ffeINVJL0H215Clf6...
Processing session 9/24: ses_4fcb4adb4ffeeWVT5BRPiweHFJ
Exporting session ses_4fcb4adb4ffeeWVT5BRPiweHFJ...
Processing session 10/24: ses_4fcb5e987ffeBC29GrHWwmUmTx
Exporting session ses_4fcb5e987ffeBC29GrHWwmUmTx...
Processing session 11/24: ses_4fcb7a650ffeZyLqLeD2iltjDB
Exporting session ses_4fcb7a650ffeZyLqLeD2iltjDB...
Processing session 12/24: ses_4fde8848affeA6Fw9C65fYjUjb
Exporting session ses_4fde8848affeA6Fw9C65fYjUjb...
Processing session 13/24: ses_501089db8ffeeCcsmN0pf7pK3a
Exporting session ses_501089db8ffeeCcsmN0pf7pK3a...
Processing session 14/24: ses_5080dcde8ffeywLTVm6dWnkuz2
Exporting session ses_5080dcde8ffeywLTVm6dWnkuz2...
Processing session 15/24: ses_53a0b8189ffekuNCCxu8QIWKgJ
Exporting session ses_53a0b8189ffekuNCCxu8QIWKgJ...
Processing session 16/24: ses_540108244ffeAFncBEF3k5F1H9
Exporting session ses_540108244ffeAFncBEF3k5F1H9...
Processing session 17/24: ses_54010e5fdffeWvmw6uaZ6WG6v3
Exporting session ses_54010e5fdffeWvmw6uaZ6WG6v3...
Processing session 18/24: ses_5492121d3ffedAwoxWHnSMeHS5
Exporting session ses_5492121d3ffedAwoxWHnSMeHS5...
Processing session 19/24: ses_60bc850c0ffe2VOpQC9BmqbaYi
Exporting session ses_60bc850c0ffe2VOpQC9BmqbaYi...
Processing session 20/24: ses_61dfc1e40ffeo3Lyi3Q4j0D91j
Exporting session ses_61dfc1e40ffeo3Lyi3Q4j0D91j...
Processing session 21/24: ses_63f564c67ffe9zT2evr6PSWfmv
Exporting session ses_63f564c67ffe9zT2evr6PSWfmv...
Processing session 22/24: ses_63f6c9ea6ffeVlKaSC6qKBBEzs
Exporting session ses_63f6c9ea6ffeVlKaSC6qKBBEzs...
Processing session 23/24: ses_63f9b04daffeyjoBslFffHO1OR
Exporting session ses_63f9b04daffeyjoBslFffHO1OR...
Processing session 24/24: ses_6400f9c2bffewFB3lJxTHF1Dx3
Exporting session ses_6400f9c2bffewFB3lJxTHF1Dx3...
Completed: 0 matches found out of 24 sessions processed
opencode session list also works fine. but i remember having some buggy session and like two disappearing from the session menu in opencode tui, but was listed in opencode session list, and was able to continue using a session using --resume.
ill try to use strace but i think its not showing whats happening in other threads/process, ill have to investigate further
big pickle failed but gemini 3 succeeded at finding the problem https://opncd.ai/share/c5MiaR5V multiples files where corrupted:
/home/mirsella/.local/share/opencode/storage/message/ses_54083ec12ffeOtMmb4yMoQbN5R/msg_abf976f90001L7vyrvJaVTAIT0.json
/home/mirsella/.local/share/opencode/storage/part/msg_abf97a095001VEGhQcBivnTi26/prt_abf97a9b0002VJ0soQplLdnHLc.json
/home/mirsella/.local/share/opencode/storage/todo/ses_54083ec12ffeOtMmb4yMoQbN5R.json
/home/mirsella/.local/share/opencode/storage/session_diff/ses_54083ec12ffeOtMmb4yMoQbN5R.json
it added a few try catch which allowed the command to finish without crashing
wanna pr the try catch?
will do