Skip to content

fix(sessions): keep cwd filters within case-distinct workspaces - #115979

Open
Bryson11111w wants to merge 1 commit into
NousResearch:mainfrom
Bryson11111w:fix/session-cwd-case-boundary
Open

Bryson11111w wants to merge 1 commit into
NousResearch:mainfrom
Bryson11111w:fix/session-cwd-case-boundary

Conversation

@Bryson11111w

Copy link
Copy Markdown

What does this PR do?

Keep directory-scoped session operations inside the selected workspace. With ended sessions in /work/Agent/src and /work/agent/src, filtering by /work/Agent currently selects both: SQLite LIKE folds ASCII case even when its wildcard characters are escaped. prune_sessions() consequently deletes both sessions, and workspace resume, listing and bulk archive use the same predicate.

Use literal instr(...)=1 prefix comparisons with a trailing path separator, matching the case sensitivity of the existing exact-directory comparison. This preserves literal %, _ and backslashes and excludes similarly named sibling directories. Reuse the predicate for legacy Kanban worker retagging, which otherwise misclassifies unrelated CLI sessions and misses backslash-delimited descendants.

Related Issue

Found while reviewing the session persistence code on main at 8df0a03793784205833f9e0db12395aa33ada433; no new issue has been filed. Related prior fix: #78927 escaped SQL wildcards, but LIKE still folds ASCII case. This change addresses that remaining path-boundary failure.

Type of Change

  • Bug fix

Changes Made

  • hermes_state_sessions.py: use literal, separator-bounded comparisons in the shared cwd predicate.
  • hermes_state.py: reuse that predicate when retagging legacy Kanban workers.
  • tests/hermes_state/test_cwd_prefix_isolation.py: two behavioral tests, parameterized over slash- and backslash-delimited stored paths. Exercise real SessionDB imports and SQLite databases under isolated HERMES_HOME values.

How to Test

scripts/run_tests.sh \
  tests/hermes_state/test_cwd_prefix_isolation.py \
  tests/hermes_state/test_session_workspace_binding.py \
  tests/hermes_cli/test_kanban_worker_session_source.py \
  tests/hermes_state/test_session_archiving.py \
  -j 1 --file-retries 0 --tb=short

scripts/run_tests.sh tests/hermes_state/test_hermes_state.py \
  -j 1 --file-retries 0 -k cwd_prefix --tb=short

Results on Linux / Python 3.12.13:

  • Before the production change, all four new parameterized cases fail on the base commit: directory filtering admits the case-distinct sibling; worker retagging either admits it or misses the backslash descendant.
  • After the change, the first command passes 17 tests and the second passes four existing cwd-filter regressions: 21 passed, zero failed, with retries disabled.
  • git diff --check passes.

Rebased onto main at 633dda6d7fdcac7e8340471c9f5ed08cdccbd70c and reran both focused commands: 21 passed, zero failed. The affected production paths were unchanged between the original reproduction and this base.

The new tests cover listing/count agreement, workspace lookup, prune preview/count agreement, archive/delete isolation, literal wildcard characters, separator boundaries and one-time worker retagging. Stored Windows-style paths are exercised as data on Linux; native Windows and macOS have not been run. No live provider or full-suite claim.

Checklist

  • Read the contributing guide and applicable area instructions.
  • Searched existing issues/PRs for cwd_prefix and reviewed the earlier wildcard fix.
  • Changes are limited to the cwd-boundary bug and its sibling retag path.
  • Added behavioral regression tests demonstrated to fail on base.
  • Ran focused checks with scripts/run_tests.sh.
  • Full test suite passed (not run).
  • Tested on Linux with isolated real SQLite databases.
  • No configuration keys, tool schemas or documented import paths changed.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Sep 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants