Implement unique filename generation to prevent overwriting existing session files
This commit is contained in:
@@ -14,6 +14,8 @@ Custom OpenClaw session-memory hook.
|
||||
- Saves the **full** user/assistant session context into `workspace/memory/`
|
||||
- Uses `agents.defaults.userTimezone` for date/time formatting
|
||||
- Uses a slugged filename, with slug generation based on a small excerpt
|
||||
- Avoids overwriting existing files: if a filename already exists the hook
|
||||
appends `-1`, `-2`, ... to produce a unique filename.
|
||||
|
||||
## Disable the bundled hook
|
||||
|
||||
@@ -42,3 +44,8 @@ Or set it false in config:
|
||||
## Notes
|
||||
|
||||
This repo is intentionally lightweight, it exists so the custom hook can live in the managed hooks directory and stay separate from the bundled one.
|
||||
|
||||
If you prefer atomic creation to fully eliminate a race window (two processes
|
||||
creating the same new filename simultaneously), replace the simple existence
|
||||
check with an atomic open/write using `fs.open(..., 'wx')` or write to a
|
||||
temporary file and `fs.rename()` it into place.
|
||||
|
||||
Reference in New Issue
Block a user