mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-10 04:02:38 -05:00
[Bug]: Empty metadata.json files causing 'Unexpected end of JSON input' errors in @actual-app/api #2564
Closed
opened 2026-02-28 20:19:08 -06:00 by GiteaMirror
·
10 comments
No Branch/Tag Specified
master
claude/fix-simplefin-batch-sync-O8LcD
matiss/modal-and-server-refactor
claude/fix-simplefin-ssrf-T31gX
claude/release-notes-validation-X7rvR
ai/custom-theme-dual-prefs
matiss/fix-6804
add-claude-github-actions-1772738270730
react-query-rules
react-query-useSchedules
matiss/separate-lint-format
dependabot/npm_and_yarn/ajv-6.14.0
cursor/sync-performance-notification-9899
react-query-prefs
matiss/chunked-sync-and-progress-ux
v26.2.1
copilot/sub-pr-6880
fix-react-query-clear-on-close-budget
copilot/sub-pr-6140
feat/auto-note
feat/scoped-bank-sync
cursor/desktop-transactions-react-table-1d0c
fix-exhaustive-deps-App
copilot/fix-find-replace-bug
release/v26.2.0-pre
matiss/browser-tests
mobile-fix-drag-and-drop-across-groups
budget-table-v2
PayeeAutocomplete2
pglite
bugfix/plugins/fix-plugins-sw
feat/plugins/plugins-core-package
prerelease
matiss/unicode-minus-fix
cursor/fix-actual-github-issue-6206-gemini-3-pro-preview-9c37
TransactionFormPage
cursor/implement-mortgage-and-loan-account-type-78ca
tests-update-fill-with-pressSequentially
mobile/link-modal
deps/25.11
cursor/fix-update-vrt-apply-ci-job-dispatch-b324
sync-server-plugins
cursor/propose-patch-for-github-issue-5680-2a18
fix/compiler-preserve-inner-dollar-escapes
cursor/analyze-actual-budget-issue-and-propose-fix-5b70
coderabbitai/docstrings/0c070e5
cursor/add-wip-prefix-and-comment-to-prs-d78d
jfdoming/08-21-auto-focus-on-navigate-in-all-browsers
show-totals-on-mobile-budget-banners
allow-child-transactions-make-transfer
mobile-calculator-keyboard
payee-geolocation
enhance/restore_scroll_position
dm-fix-second-click-on-mobile-new-transaction-2
scrollToLocationBudget
alert-autofix-38
tsconfig-composite
mobile-fix-uncategorized-transactions-on-tracking-budgets
server-budget-handlers
fix-sql-injection-in-cleanup-template
non-chrome-draggable-workaround
mobile-budget-page-swipe-navigation
ts-db-all
stable
dark-theme-with-brand-colors
fix-mobile-delete-group
ts-db-select
UnderKoen/reconcile-context-menu
master-before-server-merge
v25.2.1
ts-runQuery
rename-redux-hooks
UnderKoen/3557-persist-state-in-history
remove-redux-CLOSE_BUDGET
fix-exhaustive-deps-errors-FinancesApp
redux-toolkit-createSlice-backup
accounts-function-component
ts-useSplitsExpanded
loot-core-server-package
useTransactios-in-TransactionEdit
react-aria-input
move-redux-to-desktop-client
QueryState-type
fix-themes-applied-late
mobile-vrts
revert-3295-spendingCardFix
react-aria-button-4
split-payee-on-mobile
twk3/pin-apis-crdt
notes-tag-autocomplete
ts-LoadBackup
dnd-kit
package-upgrades
v26.3.0
v26.2.1
v26.2.0
v26.1.0
v25.12.0
v25.11.0
v25.10.0
v25.9.0
v25.8.0
v25.7.1
v25.7.0
v25.6.1
v25.6.0
v25.5.0
v25.4.0
v25.3.1
v25.3.0
v25.2.1
v25.2.0
v25.1.0
v24.12.0
v24.11.0
v24.10.1
v24.10.0
v24.9.0
v24.8.0
v24.7.0
v24.6.0
v24.5.0
v24.4.0
v24.3.0
v24.2.0
v24.1.0
v23.12.0
v23.11.0
v23.10.0
v23.9.0
v23.8.1
v23.8.0
v23.7.2
v23.7.1
v23.7.0
v23.6.0
v23.5.0
v23.4.2
v23.4.1
v23.4.0
v23.3.2
v23.3.0
v23.2.9
v23.2.5
v23.1.12
v22.12.9
Labels
Clear labels
AI generated
API
bank sync
budgeting
bug
can’t replicate
dependencies
docker
documentation
electron
experimental feature
feature
feedback
goal templates
good first issue
help wanted
importers
maintenance
needs info
needs testing
needs triage
needs votes
openid
payees
pull-request
regression
reports
responsive
rules
schedules
server
✨ merged
split transactions
tech debt
theme
transaction import
transaction reconciliation
transactions
translations
upstream
user interface
✅ approved
wontfix
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/actual#2564
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @1cu on GitHub (Oct 25, 2025).
Verified issue does not already exist?
What happened?
The
@actual-app/apipackage creates emptymetadata.jsonfiles (0 bytes) during thedownloadBudget()process, leading to "Unexpected end of JSON input" errors whengetBudgets()tries to parse them.Expected behavior:
metadata.jsonshould contain valid JSON with budget metadata, andgetBudgets()should parse the file successfully.Actual behavior:
metadata.jsonis created as 0-byte empty file, causinggetBudgets()to fail with JSON parse error and application crashes.How can we reproduce the issue?
@actual-app/apipackage in a TypeScript projectdownloadBudget()with a valid sync IDmetadata.jsonfile - it will be 0 bytesgetBudgets()- throws "Unexpected end of JSON input" errorCode example:
Root cause: Race condition in file system operations where multiple processes attempt to write to
metadata.jsonsimultaneously, causing the file to be overwritten with empty content.Where are you hosting Actual?
Locally via Yarn
What browsers are you seeing the problem on?
Desktop App (Electron)
Operating System
Mac OSX
@1cu commented on GitHub (Oct 25, 2025):
Proposed Fix
Implement atomic write for
metadata.jsonfiles inpackages/loot-core/src/platform/server/fs/index.electron.ts:Testing
@MatissJanis commented on GitHub (Oct 26, 2025):
👋 I would be happy to look in to the issue if I could interact with a human, but I'd wager that this issue was written by an LLM.
It takes time for us to review issues by hand. So I would appreciate to interact here with humans that take their time to write out the problem they are experiencing along with a reproduction. Not an AI agent that half-hallucinates a reproduction and "potential" fix.
In the meantime, here is the LLM response from me:
Thanks for filing this issue! However, after reviewing the code, I'm unable to reproduce this behavior and the description doesn't match how the system actually works. Let me explain:
Current Error Handling
The
getBudgets()function already has error handling for corrupted/empty metadata.json files:https://github.com/actualbudget/actual/blob/master/packages/loot-core/src/server/budgetfiles/app.ts#L102-L137
When it encounters a JSON parse error, it logs the error and filters out that budget entry rather than throwing an exception. This means empty or corrupted metadata.json files shouldn't cause the application to crash.
No Race Condition
The
downloadBudget()flow is completely sequential with properawaitstatements throughout. Since Node.js is single-threaded and all file operations are awaited, there's no race condition where multiple processes write to the same file simultaneously.Possible Actual Causes
If you are genuinely seeing empty metadata.json files, it could be:
dataDirlocationdataDirsimultaneously (which would be a usage error, not a bug)@github-actions[bot] commented on GitHub (Nov 3, 2025):
This issue has been automatically closed because there have been no comments for 7 days after the "needs info" label was added. If you still need help, please feel free to reopen the issue with the requested information.
@e2jk commented on GitHub (Nov 4, 2025):
EDIT: see my comment https://github.com/actualbudget/actual/issues/6001#issuecomment-3487956882 below, adding a 2 second delay before the POST where this issue got triggered gets around the issue (credits: I got that idea from another issue, linked below)
Short version; when running my Node script using the API inside the Docker container where Actual budget runs, I quite often get
PostError: network-failurethat result (or are caused by?) an empty metadata.json file.@MatissJanis I'm not the OP, but I'm a human ;) (it seems I have no permission to reopen the issue, just comment on it)
First some background info, before coming to this issue I'm encountering as well:
I have Actual Budget running via Docker.
I've created a Node script using the Actual API to manipulate and import the CSV exports I get from the different banks. Basically 2 steps:
It's in that second step that I'm encountering this issue.
This is an extract of my codepath:
This is the output I get (I looked in the /tmp/acutal-data folder that is created by the script, the metadata.json file is empty, which is causing this
Error parsing metadata: SyntaxError: Unexpected end of JSON inputandLoading fresh spreadsheetin the output logging - if I "sh" into the container, and manually delete that empty file, it gets created again, but still as an empty file)I've tried all kinds of stuff (including edit the actual
bundle.api.jsfile to add debutconsole.logstatements, to no avail.Any idea what might go wrong here?
In the previous week, I've had this issue "go away" at some point (I don't know if restarting the container, or other actions I took helped this), but as I write this I'm not having any success at making it work again...
@e2jk commented on GitHub (Nov 4, 2025):
In case it might be useful (as https://github.com/actualbudget/actual/issues/1695#issuecomment-1784104166 mentions "a self-signed cert inside my local network"), I do run the actual-server docker container behind a Traefik reverse proxy that uses a self-signed certificate (I don't want the server to be accessible from outside my network, so no ACME protocol with Let's Encrypt for instance). But setting
NODE_TLS_REJECT_UNAUTHORIZED=0has no visible effect (I also tried "nuking" the temp folder that the API script uses to download a copy of the budget, so that it tries to download it fresh, to no avail)docker exec -it actual-server sh -c "rm -rf /tmp/actual-data && NODE_TLS_REJECT_UNAUTHORIZED=0 node /opt/scripts/actual-csv-importer.js --upload-only --budget-id f1d1a1c5-6ef9-4de1-aac5-24e39f754e13 --api-verbose"still returnsPostError: network-failure.@e2jk commented on GitHub (Nov 4, 2025):
I added a debug statement in the budle file, just before the line that fails, looks like the URL that causes the network-failure is
http://localhost:5006/sync/sync- is that double/syncexpected?@e2jk commented on GitHub (Nov 4, 2025):
From the extra debug information comes out
TypeError: fetch failedand[cause]: SocketError: other side closed.here is more information from my added debug statements in
async function postBinary:This is what comes out of it:
@e2jk commented on GitHub (Nov 4, 2025):
Well well well, per https://github.com/actualbudget/actual/issues/1695#issuecomment-2409046329 I added a 2 second delay before the POST request is done, and lo-and-behold, the request goes through and the rest of the script executes fine...
Note that the OP of that comment states in https://github.com/actualbudget/actual/issues/1695#issuecomment-3393739002
Looking at my log, I see I run
Node.js v22.21.1If useful for others, this is the code I added just before the
tryblock inpostBinary:@MatissJanis commented on GitHub (Nov 4, 2025):
@e2jk thanks for the investigation.
There are two things at play here: the malformed
metadata.jsonfile and networking.For the metadata file: even if it is completely broken - it will not block the execution of any subsequent script. We do log the error message, but that's as far as it goes. It's not a fatal error. See code snippet here. I do find it interesting, however, that it is empty. And I wonder if your set-up plays a role here (maybe multiple interfering writes? Or lacking in permissions to write file contents? Just guessing at this stage). To further debug this I would need a way to reproduce the issue.
As for the networking error: also very interesting, but most likely again due to your set-up. I would need a reproduction to investigate this further.
@cvoege commented on GitHub (Feb 24, 2026):
I can replicate this issue. I do not know what causes it, but sometimes (most of the time)
downloadBudgetwrites content to metadata.json, and then almost immediately deletes it. Here is what I can provide. The log of running the first time, with an empty dataDirAnd the code:
I'm running on an M-series macbook directly (i.e. not via docker).
That results in the metadata.json being set for just a moment to the correct data, then writing empty. The subsequent run works, and uses the local cache, but then sometimes resets the metadata.json to empty. I would appreciate it if this issue was re-opened, as this does break my ability to use locally cached data.