fix(cli): pin HERMES_KANBAN_BOARD at chat boot to stop subprocess board drift (salvages #20094)#20186
Merged
Conversation
…rd drift Without an explicit pin, in-process kanban tools and shelled-out `hermes kanban …` subprocesses resolve the active board on different paths: the env var when set, otherwise the global `<root>/kanban/current` file. When a concurrent session toggles the current-board pointer mid-turn, the same chat ends up routing tool calls to board A while its shell calls hit board B, surfacing as phantom "no such task" errors. Pin the resolved board into env once at `cmd_chat` boot when HERMES_KANBAN_BOARD isn't already set. Mirrors what the dispatcher does for spawned workers (kanban_db.py:2622-2623). Idempotent and a no-op when the env is already pinned by the caller. Closes #20074
The helper under test writes to os.environ directly, bypassing monkeypatch tracking. Without an explicit snapshot/restore fixture, the mutation leaks into subsequent tests and breaks TestSharedBoardPaths (kanban path resolution reads HERMES_KANBAN_BOARD and routes through boards/<leaked-slug>/ instead of the test's own HERMES_HOME). Add an autouse fixture that snapshots the env var before the test and restores (or pops) it after, regardless of what the helper did.
19 tasks
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.
Chat sessions now pin
HERMES_KANBAN_BOARDinto the process env at boot, so in-processkanban_*tools and shelled-outhermes kanban …subprocesses always resolve to the same board even if a concurrent session runshermes kanban boards switchmid-turn.Salvaged from #20094 (@0xDevNinja).
Root cause:
kanban_db.connect()resolves the active board via a two-source chain —HERMES_KANBAN_BOARDenv var, then the global<root>/kanban/currentfile. Agent tool calls run in the chat process where env may be set; shell-outs spawn fresh subprocesses with no env inherited, so they fall through to thecurrentfile. Thecurrentfile is global mutable state — another session'sboards switchflips it — so mid-turn the same chat routes tool calls to board A while its shell calls hit board B. Symptom:kanban_createreturns a task id, immediately followed byhermes kanban show <id>reporting "no such task."Mirrors the pin the dispatcher already does for spawned workers (
kanban_db.py:2622-2623), so every code path resolves the same DB consistently.Changes
hermes_cli/main.py: new_pin_kanban_board_env()helper, called fromcmd_chatafter the existing env-flag block, before forking to TUI vs CLI. Idempotent — no-op ifHERMES_KANBAN_BOARDis already set; swallowsget_current_board()failures so chat boot never crashes because the kanban dir is unreadable.tests/hermes_cli/test_pin_kanban_board_env.py: three tests covering pin-when-unset, no-op-when-set, and swallow-on-failure. Autouse fixture snapshots and restoresHERMES_KANBAN_BOARDaround each test (the helper writes toos.environdirectly, bypassing monkeypatch tracking — without the fixture the mutation leaked intoTestSharedBoardPathsin the same suite).Validation
boards switchmid-turnkanban_createandhermes kanban show <id>hit different boards → "no such task"HERMES_KANBAN_BOARDalready setIncludes a small follow-up commit fixing env-var leakage in the test file — the original test used
monkeypatch.delenvbut the helper writesos.environ[...]directly, so the mutation survived teardown and broke 9 unrelated tests in the same suite. Added an autouse snapshot/restore fixture.Closes #20074
Co-authored-by: 0xDevNinja manmit0x@gmail.com