Persist SaveDataMemory2 save data to disk (fixes Astro Bot progress not saving) #659
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!659
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/659/head"
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?
@defektu on GitHub · 2026-09-17 04:16 UTC · original
defektu:fix/astrobot-savedata-memory-persistence→main· +773 −53 · 4 files · 4 commits · merged 2026-09-19 20:51 UTCSummary
SaveDataSetupSaveDataMemory2/SaveDataGetSaveDataMemory2/SaveDataSetSaveDataMemory2/SaveDataSyncSaveDataMemoryAPI instead of the classicSaveDataMount3/Prepare/Commitflow. That whole family only ever touched an in-processstd::vector, so game progress (coins, level state, rescued bots) was silently discarded on process exit — every boot looked like a new game, even though the game itself was calling these functions correctly.SaveDataSetupSaveDataMemory2now loads an existing_SaveData/<title>/sce_sdmemory_<slot>.binfrom disk into the memory buffer on first setup, andSaveDataSetSaveDataMemory2/SaveDataSyncSaveDataMemorynow flush the buffer back to that file instead of being a no-op.PRINT_NAMElogging for the module and addsLOGFtracing (call params, mount path existence, per-write offsets, and which branch/result each mount call took), since none of this was previously visible and made diagnosing the missing persistence much harder than necessary.Test plan
kyty_emulatortarget (Release, clang-cl + Ninja) with the change._SaveData/PPSA21564/sce_sdmemory_0.binis written with real XML save state (NumCoin,PlayingLevelId, levelIsCleared/IsUnlocked,Bot/<id>/IsRescued).🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-09-17 04:16 UTC · original · edited 2026-09-19 20:51 UTC
📝 Walkthrough
Walkthrough
SaveData now validates user IDs, slots, options, sizes, buffers, and path components. It stores memory state per user and slot, loads persisted metadata, performs atomic replacement, and synchronizes access with mutexes. Directory search, mounting, transfer, and deletion use validated user-aware paths. New tests cover memory behavior, persistence, restart handling, path isolation, deletion, and save-file visibility. CTest registers the dedicated memory test executable.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟠 High · up to
898edInterrupted writes or power loss can corrupt or discard progress, while different users can access the same classic save directory. These issues should be fixed before merge.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-17 04:25 UTC · original · edited 2026-09-17 04:43 UTC
On
src/libs/libSaveData.cppline 532 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Load memory separately for each
slot_id.g_save_data_memory_loadedbecomes true after the first setup and never resets. If a title sets up slot 1 and then slot 2, slot 2 skips its disk load.SaveDataGetSaveDataMemory2then returns slot-1 data, andSaveDataSetSaveDataMemory2can write that data tosce_sdmemory_2.bin.Keep a buffer and loaded state per slot, or flush, clear, and load the buffer when the selected slot changes.
🤖 Prompt for AI Agents
✅ Addressed in commit fac87dc
@coderabbitai[bot] on GitHub · 2026-09-17 04:25 UTC · original · edited 2026-09-17 04:43 UTC
On
src/libs/libSaveData.cppline 562 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11602
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 25205
Return an error when persistence I/O fails.
An absent slot file is a successful empty setup. However, when
IsFileExisting(path)is true, a failedfile.Open()or a short or failedfile.Read()is treated as an empty setup. The code then marks the memory as loaded and returnsOK.Common::File::Read()andWrite()report transferred byte counts through output parameters. The current code does not inspect those counts. Whenfile.Create()fails, both flush callers also returnOK.Propagate an appropriate SaveData I/O error from setup and flush. Mark the memory as loaded only after the complete file has been read.
🤖 Prompt for AI Agents
✅ Addressed in commit fac87dc
@coderabbitai[bot] on GitHub · 2026-09-17 04:25 UTC · original · edited 2026-09-17 04:43 UTC
On
src/libs/libSaveData.cppline 560 (outdated):🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7026
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 17931
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29120
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 31468
Path Traversal
CWE: CWE-22 — Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Constrain
TITLE_IDbefore constructing save-data paths.The loader copies any JSON
titleIdstring intoTITLE_IDwithout format validation.Common::FixFilenameSlash()does not normalize.., and the filesystem helpers pass the resulting path to the host APIs without containment checks. A value such as../outsidecan therefore makeCreateDirectories()andCommon::File::Create()operate outside_SaveData. Reject components or separators outside the expected identifier format, and enforce containment under_SaveData.🤖 Prompt for AI Agents
✅ Addressed in commit fac87dc
@coderabbitai[bot] on GitHub · 2026-09-17 04:25 UTC · original · edited 2026-09-17 04:43 UTC
On
src/libs/libSaveData.cppline 563 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 22310
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 50371
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21186
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9830
Protect SaveData memory state with one mutex.
LIB_FUNCstores the native function address.RelocateRecordpatches resolved function calls directly to that address.PthreadCreateruns each guest pthread on a separate hostpthread. No dispatcher lock protects these calls.The four SaveData APIs access the shared vector, loaded flag, and slot state without a common lock.
SaveDataSetSaveDataMemory2can also flush whileSaveDataSyncSaveDataMemoryor another API changes that state. These calls can race during vector resize, memory access, and file writes. Hold one mutex across all buffer, state, and flush operations.🤖 Prompt for AI Agents
✅ Addressed in commit fac87dc
@coderabbitai[bot] on GitHub · 2026-09-17 04:25 UTC · original · reviewed
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
a5144531-1ea9-473d-abcf-dd72eea3b208📥 Commits
Reviewing files that changed from the base of the PR and between
63fb822f8aand d112b8f2a5007b8c47722a7344d9db627ac74676.📒 Files selected for processing (1)
src/libs/libSaveData.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@defektu on GitHub · 2026-09-17 04:38 UTC · original
Good estimations from @coderabbitai. it somewhat works. Tested some cases and will update pr.
@coderabbitai[bot] on GitHub · 2026-09-17 04:38 UTC · original
@defektuThanks for the update. Please request another review after you update the PR.🐇
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-09-17 04:48 UTC · original · reviewed
🤖 Prompt for all review comments with AI agents
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
5f3a0f2d-9796-47da-98d1-5b33b166292c📥 Commits
Reviewing files that changed from the base of the PR and between d112b8f2a5007b8c47722a7344d9db627ac74676 and fac87dca30f59eae9cbff34ce7bfda43397a7ac2.
📒 Files selected for processing (1)
src/libs/libSaveData.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@Nmzik on GitHub · 2026-09-17 12:02 UTC · original
@defektu please retest. This is a huge ABI change. Your idea is there but we atomically replace the progress/save file
@defektu on GitHub · 2026-09-17 20:23 UTC · original
@Nmzik Tested your force-pushed commit. Broke Astro Bot saves. Will implement a fix and make improvements to
SaveDataMount3according to your changes. Also I remember that Astro Bot had save issues on Ps5, which was corrupting its own save which meant progress loss. Wanna do something for that too.@coderabbitai[bot] on GitHub · 2026-09-17 23:01 UTC · original · edited 2026-09-18 10:51 UTC
On
src/kernel/fileSystem.cppline 521 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16173
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 50372
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 50371
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 30869
Use a unique shadow path for each open descriptor.
KernelOpenis reachable from concurrent guest threads and assignsreal_name + ".tmp"to every whole-file rewrite.Common::File::Createtruncates an existing path (fopen(..., "w+")on Linux andCREATE_ALWAYSon Windows).FileDescriptors::m_mutexprotects descriptor allocation only.Two rewrite opens can therefore truncate the same shadow file and interleave writes. One close can publish data while the other descriptor is still writing. The second close can then rename a missing shadow path and still return
OK. Use a unique shadow path for each descriptor, or explicitly reject or serialize a second rewrite open for the same target.✅ Addressed in commit
898eddb@coderabbitai[bot] on GitHub · 2026-09-17 23:01 UTC · original
On
src/kernel/fileSystem.cppline 603 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Return an error when shadow publication fails.
If
std::filesystem::renamefails,KernelCloseonly logs the error. It then deletes the descriptor and returnsOK. The guest therefore treats the save as committed while the real file still contains the old data.Record the publication status. Complete descriptor cleanup, then return
KERNEL_ERROR_EIOon failure.Proposed correction
@coderabbitai[bot] on GitHub · 2026-09-17 23:01 UTC · original · edited 2026-09-18 10:50 UTC
On
src/libs/libSaveData.cppline 274 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Preserve path-component identity.
The sanitizer deletes invalid characters. Distinct names such as
SAVE/AandSAVEAtherefore select the same directory. An empty or fully invalid name also aliases every other"UNKNOWN"name.This can overwrite or delete an unrelated save. Reject invalid components or encode them with an injective mapping.
✅ Addressed in commit
898eddb@coderabbitai[bot] on GitHub · 2026-09-17 23:01 UTC · original · reviewed
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
860a31cf-0414-407f-a15b-d5162cdd63aa📥 Commits
Reviewing files that changed from the base of the PR and between
cc82984284andc65194d7b7.📒 Files selected for processing (2)
src/kernel/fileSystem.cppsrc/libs/libSaveData.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@nzc20090108 on GitHub · 2026-09-18 03:14 UTC · original
This is a bug report of the emulator version I made with the latest code from your home page.
Initialized: Config
Initialized: Log
Initialized: Timer
Initialized: Pthread
Initialized: Profiler
Initialized: Network
Initialized: Memory
Initialized: FileSystem
Initialized: Controller
Initialized: Audio
Vulkan pipeline cache: initializing _PipelineCache\PPSA21567.bin
Vulkan pipeline cache: initialized empty
Initialized: Graphics
Title ID: PPSA21567
version = 13
Shaders: VS 0 | PS 0 | CS 1 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 0 | PS 0 | CS 2 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 0 | PS 1 | CS 2 | GS 0 | LS 0 | HS 0 | TES 0
Shader: emitted zero-position clip guard
Shaders: VS 1 | PS 1 | CS 2 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 3 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 4 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 5 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 6 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 7 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 8 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 9 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 10 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 11 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 12 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 1 | PS 1 | CS 13 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 2 | PS 1 | CS 13 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 2 | PS 1 | CS 14 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 2 | PS 1 | CS 15 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 2 | PS 2 | CS 15 | GS 0 | LS 0 | HS 0 | TES 0
Shaders: VS 3 | PS 2 | CS 15 | GS 0 | LS 0 | HS 0 | TES 0
--- Build ---
Fork build nzc20090108/KytyPS5
c65194d--- Error ---
shader CFG build failed: unsupported decoded instruction in CFG at pc 0x00002190: 0x00002190: unsupported family=MIMG opcode=0xe6 raw=[0xf1989f07 0x00040505 0x4442413d 0x4543403e 0x00004746] reason=MIMG opcode is not implemented in D:\a\KytyPS5\KytyPS5\src\graphics\shader\recompiler\frontend\cfg\ShaderCFG.cpp:40
D:\PS5\KytyPS5-saveWindows-x64>
Comes whith a shader log
_kyty.txt
@defektu on GitHub · 2026-09-18 05:14 UTC · original
Hi @nzc20090108, you forgot to patch the title. Origin/main needs the patch for this title to work. If you do not want to use patch, you can hop in to #558, which straight away works with Astro Bot.
@nzc20090108 on GitHub · 2026-09-18 06:01 UTC · original
I've patched the title, it's "fix/astrobot- savedata-memory-persistence"
@nzc20090108 on GitHub · 2026-09-18 06:55 UTC · original
This is the error log for the program built with the "astrobot- raytracing" version
Initialized: Config
Initialized: Log
Initialized: Timer
Initialized: Pthread
Initialized: Profiler
Initialized: Network
Initialized: Memory
Initialized: FileSystem
Initialized: Controller
Initialized: Audio
Vulkan pipeline cache: initializing _PipelineCache\PPSA21567.bin
Vulkan pipeline cache: initialized empty
Initialized: Graphics
version = 13
warning: executing wave64 compute shader cs=0x0000000908e86a00
Shaders: VS 0 | PS 0 | CS 1 | GS 0
Shaders: VS 0 | PS 0 | CS 2 | GS 0
Shaders: VS 0 | PS 1 | CS 2 | GS 0
Shaders: VS 1 | PS 1 | CS 2 | GS 0
Shaders: VS 1 | PS 1 | CS 3 | GS 0
Shaders: VS 1 | PS 1 | CS 4 | GS 0
Shaders: VS 1 | PS 1 | CS 5 | GS 0
Shaders: VS 1 | PS 1 | CS 6 | GS 0
Shaders: VS 1 | PS 1 | CS 7 | GS 0
Shaders: VS 1 | PS 1 | CS 8 | GS 0
Shaders: VS 1 | PS 1 | CS 9 | GS 0
Shaders: VS 1 | PS 1 | CS 10 | GS 0
Shaders: VS 1 | PS 1 | CS 11 | GS 0
Shaders: VS 1 | PS 1 | CS 12 | GS 0
Shaders: VS 1 | PS 1 | CS 13 | GS 0
Shaders: VS 1 | PS 1 | CS 14 | GS 0
Shaders: VS 1 | PS 1 | CS 15 | GS 0
Shaders: VS 1 | PS 2 | CS 15 | GS 0
Shaders: VS 2 | PS 2 | CS 15 | GS 0
--- Build ---
Fork build nzc20090108/KytyPS5
f9c1e3f--- Error ---
ShaderRecompiler CS failed hash=0x78af8e269b528b5c: SPIR-V validation failed
in D:\a\KytyPS5\KytyPS5\src\graphics\host_gpu\renderer\pipeline\pipelineCache.cpp:305
D:\PS5\KytyPS5-Windowsastrobot-raytracing-x64>

_kyty.txt
@ -250,0 +293,4 @@return directory / std::to_string(user_id);}}return directory;@coderabbitai[bot] on GitHub · 2026-09-18 10:59 UTC · original
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Include
user_idin classic save paths.save_directory()addsuser_idonly forsce_sdmemory*directories. Classic saves for different users therefore resolve to the same_SaveData/<title>/<dir>path.For example, user 2 can mount or delete a classic save created for user 1. Add the user component for every save type. Update
SaveDataDirNameSearch()to search the matching user directory.@coderabbitai[bot] on GitHub · 2026-09-18 10:59 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
c2ef4b66-cac7-4105-b16b-77f458ebeda8📥 Commits
Reviewing files that changed from the base of the PR and between
c65194d7b7and898eddb31f.📒 Files selected for processing (3)
src/libs/libSaveData.cpptests/KernelFileSystemTests.cpptests/SaveDataMemoryTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Noxy229 on GitHub · 2026-09-18 17:17 UTC · original
Astro Bot PPSA21564 (US) v01.007 on Linux / RX 9070 XT — request for the title patch
Built
astrobot-raytracing(f9c1e3f) locally on Linux (clang, current main + our tree; header-drift fixes for vk 335 headers were purely cosmeticvk::Extent3D{}-style), plus officialKytyPS5-2026-09-18-5b7d334. Results on our hardware:shader CFG build failed: unsupported decoded instruction ... family=MIMG opcode=0xe6 raw=[0xf1989f07 ...] at pc 0x00002190— identical to #657 (which was an RTX 4070), so vendor-independent on this title version. We read this as gfx10.3IMAGE_BVH_INTERSECT_RAYreached during early compute compilation.Shaders: VS 2 | PS 2 | CS 16, wave64 warning included), then dies on the first compute dispatch with a guest write fault[NULL+0x40], host pc inside JIT'd guest code, same family as #677's guest null-deref after intro on RTX 5090.id/versionswapped to01.007.000; validation then passes:Game cheat: waiting for the matching module), but neither pattern probe (first 32-hex-byte exact runs of both mods) occurs anywhere in our US v01.007eboot.bin(251 MB scanned) — so the renderer-switch never engages on this title version, and the BVH path stays live.@defektu mentioned in this thread that "origin/main needs the patch for this title to work". Would you have (or could you post) the ETAHen patch JSON for PPSA21564 v01.007 — specifically the non-tiled deferred renderer selection and GI-probe disable offsets for that build? Happy to retest and report full logs; and if the patch lands, we can attach the exact pattern bytes we verified against our dump.
@Noxy229 on GitHub · 2026-09-18 17:27 UTC · original
Update — solved on our side, patch attached.
We located the renderer-select hook in the US v01.007
eboot.binourselves: the EU pattern's structure is intact in this build, only thejedisplacement differs (0x8edvs0x8f1) and the lea disp moved — which is why the #687 JSON's exact-byte anchor missed.Ported patch for PPSA21564 v01.007 (file off 0x7426b83):
Result with the
astrobot-raytracing(f9c1e3f) build on RX 9070 XT, Linux:Successfully applied cheat, wave64 CS compiles, no fault — the emulator now runs past the previous wall indefinitely (previous: guest null write at first dispatch within seconds). The GI-probe-disable mod from the EU JSON has zero structural hits in the 01.007 binary, so we run with the renderer-select mod only.If useful, take this as the 21564 v01.007 port; happy to test anything you throw at it.