fix(sessions): escape LIKE wildcards in the cwd-prefix clause - #78927
Closed
Drexuxux wants to merge 1 commit into
Closed
fix(sessions): escape LIKE wildcards in the cwd-prefix clause#78927Drexuxux wants to merge 1 commit into
Drexuxux wants to merge 1 commit into
Conversation
_cwd_prefix_clause builds "cwd is this directory or under it" for session
listing, workspace resume and prune/archive. The two LIKE arms bound the
raw prefix, so `_` and `%` acted as wildcards on a value that is a path:
cwd_prefix="/home/me/my_project"
main -> ['sibling', 'target'] # /home/me/myXproject/src matched too
fix -> ['target']
`_` matches any single character, so a same-length sibling directory with
children falls inside the pattern. prune_sessions() deletes the rows it
matches (and their on-disk transcripts), so an unrelated project's history
goes with it.
Escape the needle and pair both arms with ESCAPE, the convention the rest
of this file already uses; the literal separator backslash in the Windows
pattern is escaped for the same reason. The `=` arm is an exact compare and
keeps the raw prefix, so directory-and-children matching is unchanged.
Follow-up to the *_like filters in NousResearch#78681, kept separate because this helper
is shared by four call sites beyond prune.
Collaborator
|
Merged via #79722 — your commit cherry-picked onto current main with authorship preserved (rebase merge), together with #78681. Follow-up we added: the inline escape in |
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
Follow-up on the salvage of NousResearch#78681 + NousResearch#78927: the second fix inlined the exact body of the _escape_like helper the first fix introduced ten lines above. Call the helper instead so there is one copy of the escaping rule.
33hodl
pushed a commit
to 33hodl/hermes-agent
that referenced
this pull request
Aug 12, 2026
Follow-up on the salvage of NousResearch#78681 + NousResearch#78927: the second fix inlined the exact body of the _escape_like helper the first fix introduced ten lines above. Call the helper instead so there is one copy of the escaping rule.
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.
What
_cwd_prefix_clausebuilds the "cwd is this directory or somewhere under it" predicate used by session listing, workspace resume, and prune/archive. BothLIKEarms bound the raw prefix:_and%are LIKE wildcards, and both are ordinary characters in a path._matches any single character, so a same-length sibling directory with children falls inside the pattern. RealSessionDB, real SQLite:prune_sessions()deletes the rows this clause matches, along with their on-disk transcripts, so pruning one project's sessions takes an unrelated project's history with it.list_prune_candidates(which backs--dry-runand the confirmation preview) runs through the same builder, so the preview shows the same over-broad set rather than warning about it.The bare-
%case is the same class from the other direction — a prefix of/home/me/%matches every session under that root.The fix
Escape the needle and pair both
LIKEarms withESCAPE '\'— the convention the rest ofhermes_state.pyalready follows for user-derived text. The literal separator backslash in the Windows pattern is escaped for the same reason. The=arm is an exact compare and keeps the raw prefix.Directory-and-children matching is unchanged for prefixes without wildcards: the clause still matches the directory itself and everything below it.
This is the follow-up I flagged in #78681, which escaped the
title_like/model_like/branch_likefilters and deliberately left this helper alone because it is shared by four call sites beyond prune. The two changes touchhermes_state.pyin unrelated regions and do not conflict.Tests
Added to
TestPruneSessionFiltersintests/test_hermes_state.py:_selects only the real directory, andprune_sessionsdeletes exactly one session — the same-length sibling survives%prefix selects nothingResults:
That is the whole file; the 178 pre-existing tests are unchanged and there are no pre-existing failures in it.
Red without the source change:
The two control cases pass on both sides, which is what they are for.