Found while diagnosing a failed iPad stream to chunky-turnip-23 (node-b961f1c8, hydrabody v2.0.70-rc.9, mobile-kit).
apps.json is rewritten every 30 seconds with byte-identical content (len 4419 at 01:28:03, 01:28:33, 01:29:03). In a ~7 minute Sunshine log window there were 48 POSTs and 72 GETs to /api/apps. The re-POSTed apps repeat forever: gallo-romeins-museum 24x, gallo-romeins-v3 18x, hello-xr 8x.
There are two writers to one file.
sanitizeSunshineApps (pkg/provider/sunshine.go:64) reads, edits and writes <ProviderInstallDir>/config/apps.json DIRECTLY on disk, deduplicating by name and dropping blank-named entries. But Sunshine is a running process holding its own in-memory app list, and it serialises that list back to apps.json on every write through its HTTP API. So:
The observable results, all present on chunky:
hello-xr is registered TWICE in apps.json with different cmds (hellohydra_xr.exe and hello_xr.exe) even though sanitize dedupes by name, because sanitize's edit is discardedgallo-romeins-museum is POSTed 24 times yet is ABSENT from apps.jsonSyncApps correctly skips unchanged apps, so the churn is not its change detection; the disk state it compares against is simply never the state Sunshine believes inEvery POST makes Sunshine rewrite and reload its app list. A launch request arriving during that churn is at risk, which is a plausible contributor to failed stream launches.
It also destroys diagnostics. Sunshine runs at min_log_level = 1 (Debug) and logs the full apps.json body on every GET, so this traffic fills sunshine.log at roughly 26 KB/min. chunky's 132 KB log covered only ~5 minutes, which meant the evidence of the actual failed stream attempt had already rolled out of the log before it could be read.
sanitize must go through Sunshine's HTTP API (delete/update by index) rather than editing apps.json behind the running process, or it must only touch the file while Sunshine is stopped. Two writers to one file cannot be made correct by ordering.
Separately, consider not logging the full app list body on every poll, and reducing the poll rate when nothing has changed.
Fixed in hydrabody v2.0.70-rc.14 and rc.15, verified live on cloud-l4-euw1 (node-558827b8).
The two-writer diagnosis in the report was right but incomplete. Fixing it exposed the real generator, which took a second commit.
1. Sanitize fought the file (rc.14)
sanitizeSunshineAppsedited apps.json directly while hydrabody also drove Sunshine's HTTP API. Sunshine holds the list in memory and serialises it back on every API write, so each disk edit was discarded. Sanitize now works through the API:ListApps, thenDeleteAppfrom the highest index DOWN, because Sunshine addresses applications by position and ascending deletes would remove the wrong entries.2. GET /api/apps returns no index, so every update appended (rc.15)
This is the actual duplicate generator. Confirmed against Sunshine 2026.914.233613, whose response is a bare list with no index field:
So every
sunshine.Appdecodes withIndex == 0, andSyncAppsposted that zero back as the index of the app it meant to update. Sunshine does not update the intended entry, it appends. A fresh duplicate on every 30 second tick.SyncAppsnow addresses applications by their POSITION in theListAppsresult and never trustsApp.Indexfrom a read.Note for anyone using go-sunshine directly:
App.Indexis only meaningful on a write. Treat it as write-only.3. The wrong duplicate was being kept (rc.15)
apps.json held
rupelmonde-castle-viewertwice: once complete with launch args and prep-cmd, once bare with neither.appsToDropkept the LAST entry, so it deterministically deleted the complete one and preserved the bare one. The old file-editing code carried the same rule but never took effect; once deletes started working it reliably kept the wrong entry.That was the cause of the per-tick warning
app "rupelmonde-castle-viewer" has no prep-cmd after sync - VDD orientation will not be set before stream starts. Both the VDD orientation and hydrabody's session tracking ride the prep-cmd, so this broke a stream that otherwise pairs and launches fine. Among duplicates the keeper is now the entry carrying prep-cmd hooks, and only otherwise the later one.Verification
Before: apps.json rewritten every 30s, 48 POSTs to /api/apps in seven minutes, rupelmonde warned every tick.
After, on rc.15: apps.json mtime frozen at 00:28:33 across 100+ seconds and 3+ ticks, the only sanitize activity being the single startup pass. Final state, all three entries unique and hooked:
One behaviour deliberately dropped: stripping empty per-app
envobjects, which the API's App struct cannot express. That artifact clears itself whenever Sunshine next serialises the list, and unlike a blank name it was never recorded as breaking anything. The top-levelenvrepair is still a file write but now runs at most once per process rather than on a schedule.Not yet rolled out: rc.15 is on the staging channel only. Production bodies still run v2.0.69 with this bug and need the promotion to stable.