Skip to content

fix(runner): prevent Gemini CLI exit 42 on workflow add#893

Merged
Gkrumbach07 merged 2 commits intomainfrom
fix/gemini-exit-42-workflow-52260
Mar 13, 2026
Merged

fix(runner): prevent Gemini CLI exit 42 on workflow add#893
Gkrumbach07 merged 2 commits intomainfrom
fix/gemini-exit-42-workflow-52260

Conversation

@Gkrumbach07
Copy link
Copy Markdown
Contributor

@Gkrumbach07 Gkrumbach07 commented Mar 12, 2026

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

  • Unit tests pass (452 passed)
  • Ruff lint/format clean
  • Manual test: add workflow mid-Gemini session, verify no crash

Fixes: RHOAIENG-52260

🤖 Generated with Claude Code

Jira: RHOAIENG-52260

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

The changes add session ID cleanup functionality to the Gemini CLI bridge. A new clear_session_ids() method is introduced to the session manager to invalidate persisted session identifiers, and this method is invoked during the mark_dirty cleanup process before session manager shutdown. Tests verify the cleanup method is called.

Changes

Cohort / File(s) Summary
Session ID Cleanup Method
components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/session.py
Adds clear_session_ids() public method to GeminiSessionManager that clears in-memory session IDs and attempts to delete the persisted session IDs file from disk, with error logging for OS failures.
Cleanup Integration
components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/bridge.py, components/runners/ambient-runner/tests/test_bridge_gemini_cli.py
Invokes clear_session_ids() during mark_dirty() shutdown and adds mock assertion to verify the cleanup method is called.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: preventing an exit code 42 crash when adding a workflow by clearing stale Gemini CLI session IDs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description clearly relates to the changeset, describing the addition of clear_session_ids() method and its call from mark_dirty() to prevent exit code 42 crashes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/gemini-exit-42-workflow-52260
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Ambient Code Bot and others added 2 commits March 12, 2026 16:35
When a workflow is added mid-session, the CWD changes but old session
IDs persist on disk. Gemini CLI fails to resume the old session in the
new CWD and exits with code 42. Now clear session IDs when mark_dirty
is triggered by a workflow change.

- Add clear_session_ids() method to GeminiSessionManager
- Call it from mark_dirty() before shutting down the manager
- Uses EAFP pattern (try/except) to avoid TOCTOU race conditions

Fixes: RHOAIENG-52260

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove executable bit from bridge.py, session.py, and test file
- Files should be 644 (rw-r--r--), not 755 (rwxr-xr-x)

Co-Authored-By: Claude <noreply@anthropic.com>
@ambient-code ambient-code bot force-pushed the fix/gemini-exit-42-workflow-52260 branch from 6d2df33 to 39ebe00 Compare March 12, 2026 16:54
@ambient-code
Copy link
Copy Markdown
Contributor

ambient-code bot commented Mar 12, 2026

PR Fixer Report

✅ Rebase Status

  • Successfully rebased onto main (538ccbd)
  • No merge conflicts

📝 Review Feedback

No inline review comments to address. CodeRabbit hit rate limits before posting a review.

🔍 Code Review

Ran /simplify to review the changes for quality, reuse, and efficiency:

  • Code reuse: ✅ No duplication - clear_session_ids() is Gemini-specific and follows existing patterns
  • Code quality: ✅ Clean implementation with proper abstractions
  • Efficiency: ✅ Minimal file operations, correct EAFP pattern

🛠️ Fixes Applied

  • File permissions: Removed unintentional executable bit from 3 Python modules (755 → 644)

✅ CI Status

All CI checks passed on the original commit:

  • Unit Tests (Ambient Runner): ✅ SUCCESS
  • Build and Push: ✅ SUCCESS
  • E2E Tests: ✅ SUCCESS
  • Local Dev Simulation: ✅ SUCCESS

📤 Commits Pushed

  1. 6db9493 - fix(runner): clear stale Gemini session IDs on workflow change (rebased)
  2. 39ebe00 - fix: remove unintentional executable permissions (new)

The PR is ready for review and merge.

@Gkrumbach07 Gkrumbach07 merged commit 7c84b25 into main Mar 13, 2026
24 of 25 checks passed
@Gkrumbach07 Gkrumbach07 deleted the fix/gemini-exit-42-workflow-52260 branch March 13, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant