fix(workspace): Prevent session file collisions via source-prefixed keys - #792
Merged
Conversation
Two sessions sharing a value but differing in source — e.g. `$JP_SESSION=1234` alongside `$TMUX_PANE=1234`, or an `Env` value that matched a session-leader PID — resolved to the same `1234.json` file, causing one session to silently overwrite the other's active conversation. The filename now encodes both the session value and its source: - `getsid-<pid>.json` - `hwnd-<handle>.json` - `env-<KEY>-<hash(value)>.json` The opaque `Env` value is SHA-256 hashed (first 16 hex chars) so distinct variables holding the same value are kept apart and unsafe characters are excluded from the filename. The session id is now stored inside the mapping itself, making each file self-describing. Stale detection decodes the id via typed `SessionId::as_pid` / `SessionId::as_hwnd` methods — inverses of the encoding in `Session::getsid` / `Session::hwnd` — instead of parsing the filename string. This closes the silent failure where a debug-formatted HWND (`0x...`) was stored but later parsed as decimal, yielding `Unknown` liveness and disabling stale detection. `Session::getsid` and `Session::hwnd` now accept the raw typed value (`i32` / `isize`) and own the encoding, keeping encode and decode in sync by construction. `jp_cli` passes the raw platform handle directly. Existing bare-value files are handled without data loss: reads fall back to the legacy key when the source-prefixed key is absent, and stale-file cleanup migrates surviving legacy files to their new name in one pass. Signed-off-by: Jean Mertz <git@jeanmertz.com>
JeanMertz
force-pushed
the
rfd-020-filename-collision
branch
from
June 25, 2026 05:21
51fab52 to
cc53208
Compare
…fixed keys Signed-off-by: Jean Mertz <git@jeanmertz.com>
…fixed keys Signed-off-by: Jean Mertz <git@jeanmertz.com>
…fixed keys Signed-off-by: Jean Mertz <git@jeanmertz.com>
…fixed keys Signed-off-by: Jean Mertz <git@jeanmertz.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two sessions sharing a value but differing in source — e.g.
$JP_SESSION=1234alongside$TMUX_PANE=1234, or anEnvvalue that matched a session-leader PID — resolved to the same1234.jsonfile, causing one session to silently overwrite the other's active conversation.The filename now encodes both the session value and its source:
getsid-<pid>.jsonhwnd-<handle>.jsonenv-<KEY>-<hash(value)>.jsonThe opaque
Envvalue is SHA-256 hashed (first 16 hex chars) so distinct variables holding the same value are kept apart and unsafe characters are excluded from the filename.The session id is now stored inside the mapping itself, making each file self-describing. Stale detection decodes the id via typed
SessionId::as_pid/SessionId::as_hwndmethods — inverses of the encoding inSession::getsid/Session::hwnd— instead of parsing the filename string. This closes the silent failure where a debug-formatted HWND (0x...) was stored but later parsed as decimal, yieldingUnknownliveness and disabling stale detection.Session::getsidandSession::hwndnow accept the raw typed value (i32/isize) and own the encoding, keeping encode and decode in sync by construction.jp_clipasses the raw platform handle directly.Existing bare-value files are handled without data loss: reads fall back to the legacy key when the source-prefixed key is absent, and stale-file cleanup migrates surviving legacy files to their new name in one pass.