Skip to content

Commit 7c84b25

Browse files
Gkrumbach07Ambient Code Botclaudeambient-code[bot]
authored
fix(runner): prevent Gemini CLI exit 42 on workflow add (#893)
## Summary - Add `clear_session_ids()` to `GeminiSessionManager` to clear stale session IDs from disk - Call it from `mark_dirty()` when workflow changes trigger reinitialisation - Prevents exit code 42 crash from resuming invalid session in new CWD ## Test plan - [x] Unit tests pass (452 passed) - [x] Ruff lint/format clean - [ ] Manual test: add workflow mid-Gemini session, verify no crash Fixes: RHOAIENG-52260 🤖 Generated with [Claude Code](https://claude.com/claude-code) **Jira:** [RHOAIENG-52260](https://issues.redhat.com/browse/RHOAIENG-52260) --------- Co-authored-by: Ambient Code Bot <bot@ambient-code.local> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: ambient-code[bot] <ambient-code[bot]@users.noreply.github.com>
1 parent 12ad547 commit 7c84b25

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/bridge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def mark_dirty(self) -> None:
171171
self._adapter = None
172172
self._mcp_status_cache = None
173173
if self._session_manager:
174+
self._session_manager.clear_session_ids()
174175
manager = self._session_manager
175176
self._session_manager = None
176177
_async_safe_manager_shutdown(manager)

components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/session.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@ def _restore_session_ids(self) -> None:
372372
except (OSError, json.JSONDecodeError):
373373
logger.debug("Could not restore session IDs from %s", path, exc_info=True)
374374

375+
def clear_session_ids(self) -> None:
376+
"""Clear persisted session IDs from disk (e.g., after workflow change)."""
377+
self._session_ids.clear()
378+
path = self._session_ids_path()
379+
if path:
380+
try:
381+
path.unlink()
382+
logger.info("Cleared stale Gemini session IDs from %s", path)
383+
except FileNotFoundError:
384+
pass
385+
except OSError:
386+
logger.debug("Could not remove session IDs at %s", path, exc_info=True)
387+
375388
async def interrupt(self, thread_id: str) -> None:
376389
"""Interrupt the active worker for a thread."""
377390
worker = self._workers.get(thread_id)

components/runners/ambient-runner/tests/test_bridge_gemini_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def test_mark_dirty_shuts_down_session_manager(self):
141141
"""mark_dirty() should trigger shutdown on the old session manager."""
142142
bridge = GeminiCLIBridge()
143143
mock_manager = AsyncMock()
144+
mock_manager.clear_session_ids = MagicMock()
144145
bridge._session_manager = mock_manager
145146

146147
# We need a running event loop for mark_dirty to schedule shutdown
@@ -150,6 +151,7 @@ def test_mark_dirty_shuts_down_session_manager(self):
150151
mock_future.return_value = MagicMock()
151152
bridge.mark_dirty()
152153

154+
mock_manager.clear_session_ids.assert_called_once()
153155
assert bridge._session_manager is None
154156

155157

0 commit comments

Comments
 (0)