Skip to content

Harden tmux session handling and enforce Claude model behavior#6

Merged
axeldelafosse merged 2 commits intomainfrom
chore/tmux-session-handling-and-claude-models
Feb 22, 2026
Merged

Harden tmux session handling and enforce Claude model behavior#6
axeldelafosse merged 2 commits intomainfrom
chore/tmux-session-handling-and-claude-models

Conversation

@axeldelafosse
Copy link
Copy Markdown
Owner

Summary

This change improves loop robustness in tmux execution paths and clarifies model selection behavior for Claude runs. It also makes app server startup waits less brittle in slower environments and updates tests to lock in behavior.

What changed

  • Increased app-server wait timeout from 30s to 10m to reduce false timeouts in long-running startup scenarios (src/loop/codex-app-server.ts).
  • Simplified interactive detection to rely on stdin TTY only, preventing accidental tmux attach logic when running inside non-interactive TMUX contexts (src/loop/main.ts).
  • Ensured Claude command builder always uses DEFAULT_CLAUDE_MODEL for consistency, regardless of provided model overrides (src/loop/runner.ts, tests/loop/runner.test.ts).
  • Refactored tmux session setup/attach flow for safer session resolution, explicit no-session checks, and better handling when sessions die early (src/loop/tmux.ts).
  • Added/updated tests for tmux command construction, session indexing conflicts, no-session-before-attach cases, and launch argv edge cases for executable/script combinations (tests/loop/tmux.test.ts).

Why this matters

  • Avoids intermittent timeouts and attach-time failures when tmux sessions are unavailable by the time attach is attempted.
  • Improves determinism when launching loop under different packaging modes (bun executable, Node-compiled binary, or installed binary).

Validation

  • Added assertions for new tmux session error paths and command-construction invariants in unit tests.

Notes

  • No behavior change to non-interactive non-tmux flows except updated default model and timeout semantics.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @axeldelafosse, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the stability and predictability of the application's execution environment. It addresses intermittent issues related to tmux session management and application server startup, while also standardizing model selection for Claude. These changes aim to provide a more reliable and consistent user experience across different deployment scenarios.

Highlights

  • App Server Timeout: Increased the application server wait timeout from 30 seconds to 10 minutes to prevent false timeouts during slow startup sequences.
  • Interactive Detection: Simplified the logic for detecting interactive sessions to solely rely on stdin TTY status, avoiding unintended tmux attachment in non-interactive tmux environments.
  • Claude Model Enforcement: Ensured the Claude command builder consistently uses the DEFAULT_CLAUDE_MODEL, disregarding any model overrides to maintain predictability.
  • Tmux Session Handling: Refactored the tmux session setup and attachment process for enhanced robustness, including explicit checks for non-existent sessions and improved handling of sessions that terminate prematurely.
  • Test Coverage: Expanded and updated unit tests to cover new tmux command construction, potential session indexing conflicts, scenarios where sessions are not found before attachment, and various launch argv edge cases for executable and script combinations.
Changelog
  • src/loop/codex-app-server.ts
    • Increased WAIT_TIMEOUT_MS from 30 seconds to 10 minutes.
  • src/loop/main.ts
    • Removed Boolean(process.env.TMUX) from interactive session detection.
  • src/loop/runner.ts
    • Removed DEFAULT_CODEX_MODEL import.
    • Modified buildCommand to be exported.
    • Removed logic that conditionally selected Claude model, now always uses DEFAULT_CLAUDE_MODEL.
  • src/loop/tmux.ts
    • Added utility functions isScriptPath, isBunExecutable, sessionExists, keepSessionAttached, isSessionGone, and buildSessionCommand.
    • Introduced NO_SESSION_RE regex for detecting no-session errors.
    • Refactored buildLaunchArgv to handle different executable and script paths more robustly.
    • Restructured runInTmux to use new helper functions for session finding, existence checks, and attachment, improving error handling and robustness.
  • tests/loop/runner.test.ts
    • Imported DEFAULT_CLAUDE_MODEL.
    • Updated buildCommand import to reflect its new export status.
    • Added a new test case to verify that buildCommand for Claude always uses DEFAULT_CLAUDE_MODEL.
  • tests/loop/tmux.test.ts
    • Updated existing runInTmux tests to assert against the new tmux command structure and session handling, including has-session and set-window-option calls.
    • Added a new test case to verify error handling when a tmux session exits before attachment.
    • Added new test cases for buildLaunchArgv to cover scenarios with executables, installed binaries, and Bun executing installed binaries.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several valuable improvements. The hardening of tmux session handling is well-executed, with thoughtful refactoring and new checks to prevent race conditions and handle session lifecycle events more gracefully. The added tests for tmux.ts, especially for the complex buildLaunchArgv logic and session exit scenarios, are excellent and significantly improve confidence in the changes. Enforcing the default Claude model also brings consistency.

I have one suggestion in tests/loop/tmux.test.ts to make a test assertion more specific to better lock in the behavior and prevent future regressions. Overall, this is a solid set of changes that improves the robustness of the tool.

Comment thread tests/loop/tmux.test.ts Outdated
@axeldelafosse axeldelafosse merged commit 7e01dce into main Feb 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant