Repository navigation
Preserve sr Claude profile config on resume - #7121
azooz2003-bit wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthrough
ChangesPreserve CLAUDE_CONFIG_DIR on Resume
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 24 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (24 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_claude_wrapper_hooks.py`:
- Around line 1413-1449: The setup_env closure in
test_preserved_claude_config_dir_skips_resume_self_heal captures the loop
variable expected by reference, triggering Ruff B023. Bind the current expected
value inside the loop before defining setup_env, and have the closure use that
bound local instead so each iteration uses its own dictionary consistently. Keep
the rest of the test logic the same, including the auth_env assertion against
the selected_root path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 47afc344-853e-4c85-a118-4dad59475311
📒 Files selected for processing (2)
Resources/bin/cmux-claude-wrappertests/test_claude_wrapper_hooks.py
| def test_preserved_claude_config_dir_skips_resume_self_heal(failures: list[str]) -> None: | ||
| session_id = "582054f9-2f87-4e90-ad8d-2f532ed8c61b" | ||
|
|
||
| for socket_state in ("live", "stale"): | ||
| expected: dict[str, str] = {} | ||
|
|
||
| def setup_env(tmp: Path) -> dict[str, str]: | ||
| home = tmp / "home" | ||
| default_root = home / ".claude" | ||
| (default_root / "projects" / "-work").mkdir(parents=True) | ||
| (default_root / "projects" / "-work" / f"{session_id}.jsonl").write_text( | ||
| "{}\n", encoding="utf-8" | ||
| ) | ||
| selected_root = home / ".subrouter" / "codex" / "claude" / "aziz-claude-1" | ||
| (selected_root / "projects").mkdir(parents=True) | ||
| expected["path"] = str(selected_root) | ||
| return { | ||
| "HOME": str(home), | ||
| "CLAUDE_CONFIG_DIR": str(selected_root), | ||
| "CMUX_PRESERVE_CLAUDE_AUTH_SELECTION_ENV": "1", | ||
| "CMUX_PRESERVE_CLAUDE_AUTH_SELECTION_ENV_KEYS": "CLAUDE_CONFIG_DIR", | ||
| } | ||
|
|
||
| code, auth_env, real_argv, stderr = run_wrapper_auth_env( | ||
| argv=["--resume", session_id, "--fork-session"], | ||
| inherited_env={}, | ||
| socket_state=socket_state, | ||
| setup_env=setup_env, | ||
| ) | ||
| expect(code == 0, f"preserved resume config dir {socket_state}: wrapper exited {code}: {stderr}", failures) | ||
| expect( | ||
| auth_env.get("CLAUDE_CONFIG_DIR") == expected["path"], | ||
| f"preserved resume config dir {socket_state}: expected CLAUDE_CONFIG_DIR to remain on the selected profile root " | ||
| f"{expected['path']!r}, got {auth_env.get('CLAUDE_CONFIG_DIR')!r}", | ||
| failures, | ||
| ) | ||
| expect(real_argv[-3:] == ["--resume", session_id, "--fork-session"], f"preserved resume config dir {socket_state}: expected resume+fork argv, got {real_argv}", failures) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Bind expected in the setup_env closure to satisfy Ruff B023.
Static analysis flags the closure at Line 1428 capturing the loop variable expected by reference (B023). It's functionally safe here since setup_env is invoked synchronously within the same loop iteration before expected is reassigned, but binding it explicitly avoids relying on that ordering and silences the lint warning.
🧹 Proposed fix to bind the loop variable
- def setup_env(tmp: Path) -> dict[str, str]:
+ def setup_env(tmp: Path, expected: dict[str, str] = expected) -> dict[str, str]:
home = tmp / "home"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def test_preserved_claude_config_dir_skips_resume_self_heal(failures: list[str]) -> None: | |
| session_id = "582054f9-2f87-4e90-ad8d-2f532ed8c61b" | |
| for socket_state in ("live", "stale"): | |
| expected: dict[str, str] = {} | |
| def setup_env(tmp: Path) -> dict[str, str]: | |
| home = tmp / "home" | |
| default_root = home / ".claude" | |
| (default_root / "projects" / "-work").mkdir(parents=True) | |
| (default_root / "projects" / "-work" / f"{session_id}.jsonl").write_text( | |
| "{}\n", encoding="utf-8" | |
| ) | |
| selected_root = home / ".subrouter" / "codex" / "claude" / "aziz-claude-1" | |
| (selected_root / "projects").mkdir(parents=True) | |
| expected["path"] = str(selected_root) | |
| return { | |
| "HOME": str(home), | |
| "CLAUDE_CONFIG_DIR": str(selected_root), | |
| "CMUX_PRESERVE_CLAUDE_AUTH_SELECTION_ENV": "1", | |
| "CMUX_PRESERVE_CLAUDE_AUTH_SELECTION_ENV_KEYS": "CLAUDE_CONFIG_DIR", | |
| } | |
| code, auth_env, real_argv, stderr = run_wrapper_auth_env( | |
| argv=["--resume", session_id, "--fork-session"], | |
| inherited_env={}, | |
| socket_state=socket_state, | |
| setup_env=setup_env, | |
| ) | |
| expect(code == 0, f"preserved resume config dir {socket_state}: wrapper exited {code}: {stderr}", failures) | |
| expect( | |
| auth_env.get("CLAUDE_CONFIG_DIR") == expected["path"], | |
| f"preserved resume config dir {socket_state}: expected CLAUDE_CONFIG_DIR to remain on the selected profile root " | |
| f"{expected['path']!r}, got {auth_env.get('CLAUDE_CONFIG_DIR')!r}", | |
| failures, | |
| ) | |
| expect(real_argv[-3:] == ["--resume", session_id, "--fork-session"], f"preserved resume config dir {socket_state}: expected resume+fork argv, got {real_argv}", failures) | |
| def test_preserved_claude_config_dir_skips_resume_self_heal(failures: list[str]) -> None: | |
| session_id = "582054f9-2f87-4e90-ad8d-2f532ed8c61b" | |
| for socket_state in ("live", "stale"): | |
| expected: dict[str, str] = {} | |
| def setup_env(tmp: Path, expected: dict[str, str] = expected) -> dict[str, str]: | |
| home = tmp / "home" | |
| default_root = home / ".claude" | |
| (default_root / "projects" / "-work").mkdir(parents=True) | |
| (default_root / "projects" / "-work" / f"{session_id}.jsonl").write_text( | |
| "{}\n", encoding="utf-8" | |
| ) | |
| selected_root = home / ".subrouter" / "codex" / "claude" / "aziz-claude-1" | |
| (selected_root / "projects").mkdir(parents=True) | |
| expected["path"] = str(selected_root) | |
| return { | |
| "HOME": str(home), | |
| "CLAUDE_CONFIG_DIR": str(selected_root), | |
| "CMUX_PRESERVE_CLAUDE_AUTH_SELECTION_ENV": "1", | |
| "CMUX_PRESERVE_CLAUDE_AUTH_SELECTION_ENV_KEYS": "CLAUDE_CONFIG_DIR", | |
| } | |
| code, auth_env, real_argv, stderr = run_wrapper_auth_env( | |
| argv=["--resume", session_id, "--fork-session"], | |
| inherited_env={}, | |
| socket_state=socket_state, | |
| setup_env=setup_env, | |
| ) | |
| expect(code == 0, f"preserved resume config dir {socket_state}: wrapper exited {code}: {stderr}", failures) | |
| expect( | |
| auth_env.get("CLAUDE_CONFIG_DIR") == expected["path"], | |
| f"preserved resume config dir {socket_state}: expected CLAUDE_CONFIG_DIR to remain on the selected profile root " | |
| f"{expected['path']!r}, got {auth_env.get('CLAUDE_CONFIG_DIR')!r}", | |
| failures, | |
| ) | |
| expect(real_argv[-3:] == ["--resume", session_id, "--fork-session"], f"preserved resume config dir {socket_state}: expected resume+fork argv, got {real_argv}", failures) |
🧰 Tools
🪛 Ruff (0.15.20)
[warning] 1428-1428: Function definition does not bind loop variable expected
(B023)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/test_claude_wrapper_hooks.py` around lines 1413 - 1449, The setup_env
closure in test_preserved_claude_config_dir_skips_resume_self_heal captures the
loop variable expected by reference, triggering Ruff B023. Bind the current
expected value inside the loop before defining setup_env, and have the closure
use that bound local instead so each iteration uses its own dictionary
consistently. Keep the rest of the test logic the same, including the auth_env
assertion against the selected_root path.
Source: Linters/SAST tools
Summary
Test
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Preserves the selected Claude profile config on resume by skipping self-heal when
CLAUDE_CONFIG_DIRis explicitly preserved, preventing auth root switches and "No conversation found" errors. Applies this behavior across all wrapper paths (including hooks-disabled and socket passthrough) and adds a resume+fork test to confirm the pinned config dir and argv remain unchanged for live and stale sockets.Written for commit 309a417. Summary will update on new commits.
Summary by CodeRabbit
--resume+--fork-session, ensuring the preserved configuration remains unchanged and the resume arguments are forwarded correctly.