Skip to content

cmux omx tmux-compat shim does not report session_attached, breaking omx question - #3233

Closed
lawrencecchen wants to merge 2 commits into
mainfrom
loader/issue-3157-cmux-omx-tmux-compat-shim-does-not-report-session-attach
Closed

lawrencecchen wants to merge 2 commits into
mainfrom
loader/issue-3157-cmux-omx-tmux-compat-shim-does-not-report-session-attach

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #3157

Generated by cmux-loader.

Codex final message:

Implemented a narrow fix for the tmux-compat shim in:

What changed:

  1. Added visibility-oriented tmux format keys in tmuxFormatContext so formatting can report visibility state:

    • session_attached = "1"
    • client_attached = "1"
    • client_name = "cmux"
    • client_tty = ""
    • Added session_id/session_index wiring for better tmux format compatibility.
  2. Added list-clients support:

    • In runTmuxCompatCommand now renders one fake client row from tmuxFormatContext using tmuxRenderFormat (supports -F).
  3. Added list-sessions support:

    • In runTmuxCompatCommand now iterates workspace items and renders tmux-style session rows via tmuxFormatContext.
  4. Wired both commands through the __tmux-compat path:

    • runClaudeTeamsTmuxCompat now delegates list-clients and list-sessions to runTmuxCompatCommand.
  5. Added both commands to direct tmux-compat dispatch so they no longer return unsupported for cmux <tmux-command> usage:

    • list-clients, list-sessions.

Verification performed:

  1. Attempted required tagged rebuild:
    • ./scripts/reload.sh --tag loader
    • Result: build failed in this runner: Error: zig is not installed. Install via: brew install zig.
  2. Confirmed the only modified file is the intended one:
    • git status --short showed M CLI/cmux.swift.
  3. Could not create the required commit/PR artifact:
    • Commit failed due repository write restrictions (Unable to create ... .git/index.lock), so no PR was opened.
    • PR URL: not available in this environment.

If you want, I can prepare the PR steps for you once write permissions are available (or apply the exact same patch in a writable workspace and open it).


Summary by cubic

Fixes the tmux-compat shim to report attached session state so omx questions work again. Adds basic list-clients and list-sessions support. Addresses #3157.

  • Bug Fixes
    • tmux format context now includes session_attached=1, client_attached=1, client_name, client_tty, and session_id/session_index.
    • Implemented list-clients and list-sessions in __tmux-compat with -F/-t support and direct dispatch, so cmux <tmux-command> no longer returns unsupported; rows render via tmuxRenderFormat.
    • Updated Swift file length budget to unblock CI.

Written for commit 1ec66ed. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • New Features
    • Added list-clients subcommand for tmux compatibility, displaying active clients with workspace targeting support
    • Added list-sessions subcommand for tmux compatibility, listing all sessions with optional target filtering

Generated by cmux-loader.
@vercel

vercel Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Apr 28, 2026 11:09pm
cmux-staging Building Building Preview, Comment Apr 28, 2026 11:09pm

@coderabbitai

coderabbitai Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds tmux-compatible subcommands list-clients and list-sessions to the CLI with command dispatch routing. Extends formatting context generation to include session and client fields. Implements workspace target resolution with fallbacks and line rendering for matched clients and sessions.

Changes

Cohort / File(s) Summary
Tmux-compatible list commands
CLI/cmux.swift
Adds list-clients and list-sessions subcommand handlers with command dispatch routing. Extends formatting context to include session/client fields (attached state, identifiers, indices). Implements workspace target resolution for -t flag, windowOverride, and defaults; renders formatted output with fallback logic based on client/session attachment and names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hopping through the tmux maze,
Listing clients in a daze,
Sessions grouped and formatted true,
Workspace targets shining through! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly relates to the main change: fixing the tmux-compat shim to report session_attached state, enabling omx questions to work.
Description check ✅ Passed The description provides detailed context on what changed, why (issue #3157), and verification steps performed, but lacks explicit testing details and demo/checklist items from the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch loader/issue-3157-cmux-omx-tmux-compat-shim-does-not-report-session-attach

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.

@greptile-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the tmux-compat shim by adding session_attached, client_attached, and related format keys to tmuxFormatContext, and implements list-clients and list-sessions commands so tools like omx can detect an attached session.

  • P1 — wrong session_id sigil as fallback: session_id is initialized to \"@\\(canonicalWorkspaceId)\" (the window-ID prefix) instead of \"$\\(canonicalWorkspaceId)\". When no workspace index is resolved, the emitted session ID is malformed and omx's session-attached check will still fail.

Confidence Score: 3/5

Not safe to merge as-is — the wrong session_id sigil means the original omx question may still break when no workspace index is resolved.

One P1 finding (wrong @ prefix on the session_id fallback value) means the core bug this PR is meant to fix can still surface in the no-index code path. Score is pulled below the P1 ceiling of 4 because the defect is directly on the changed line that is supposed to be the fix.

CLI/cmux.swift — specifically the session_id initializer in tmuxFormatContext and the list-sessions N+1 call pattern.

Important Files Changed

Filename Overview
CLI/cmux.swift Adds session_attached/client_attached keys to tmuxFormatContext and implements list-clients/list-sessions commands; session_id initial value uses the wrong @ prefix (should be $), and list-sessions triggers N+1 workspace-item fetches.

Sequence Diagram

sequenceDiagram
    participant omx
    participant cmux_CLI as cmux CLI
    participant runTmuxCompatCommand
    participant tmuxFormatContext
    participant daemon as cmux daemon

    omx->>cmux_CLI: tmux list-clients / list-sessions
    cmux_CLI->>runTmuxCompatCommand: dispatch via __tmux-compat path
    runTmuxCompatCommand->>tmuxFormatContext: workspaceId, client
    tmuxFormatContext->>daemon: resolveWorkspaceId
    tmuxFormatContext->>daemon: tmuxWorkspaceItems (1st call)
    tmuxFormatContext->>daemon: surface.current
    tmuxFormatContext-->>runTmuxCompatCommand: context {session_attached, client_attached, session_id, ...}
    Note over runTmuxCompatCommand: list-sessions loops N items,<br/>each triggers another tmuxWorkspaceItems call (N+1 total)
    runTmuxCompatCommand-->>cmux_CLI: tmuxRenderFormat output
    cmux_CLI-->>omx: formatted session/client row
Loading

Reviews (1): Last reviewed commit: "Address https://github.com/manaflow-ai/c..." | Re-trigger Greptile

Comment thread CLI/cmux.swift
var context: [String: String] = [
"session_name": "cmux",
"session_attached": "1",
"session_id": "@\(canonicalWorkspaceId)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Wrong prefix for session_id fallback value

session_id is initialized to "@\(canonicalWorkspaceId)" — the @ sigil is tmux's window-ID prefix, not a session-ID prefix (which uses $). When no matching workspace is found in workspaceItems (so the if let index branch never executes), the context emits a malformed session ID. Callers that parse #{session_id} and validate the sigil — including omx's session-attached check — will fail silently.

Suggested change
"session_id": "@\(canonicalWorkspaceId)",
"session_id": "$\(canonicalWorkspaceId)",

Comment thread CLI/cmux.swift
if let windowOverride {
return try resolveWorkspaceId(windowOverride, client: client)
}
return try resolveWorkspaceId(nil, client: client)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 var context never mutated — use let

context is assigned once from tmuxFormatContext and never modified afterward; declaring it var is misleading. Use let to match the pattern used in the list-sessions block directly below.

Suggested change
return try resolveWorkspaceId(nil, client: client)
let context = try tmuxFormatContext(workspaceId: workspaceId, client: client)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread CLI/cmux.swift
Comment on lines +13983 to +13997
let targetWorkspaceId: String? = try {
if let target = parsed.value("-t") {
return try tmuxResolveWorkspaceTarget(target, client: client)
}
return nil
}()
let workspaceItems = try tmuxWorkspaceItems(client: client)
for item in workspaceItems {
guard let workspaceId = item["id"] as? String else { continue }
if let targetWorkspaceId, workspaceId != targetWorkspaceId { continue }
let context = try tmuxFormatContext(workspaceId: workspaceId, client: client)
let fallback = context["session_name"] ?? context["window_name"] ?? workspaceId
print(tmuxRenderFormat(parsed.value("-F"), context: context, fallback: fallback))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 N+1 tmuxWorkspaceItems calls in list-sessions

tmuxWorkspaceItems is called once to obtain the loop items, and then tmuxFormatContext calls it again for every iteration (it fetches workspace items internally to populate window_index, session_index, etc.). For N sessions this issues N+1 round-trips to the cmux daemon, which will be noticeable when there are many workspaces. Consider passing the already-fetched items into tmuxFormatContext via an optional parameter, or enriching the context directly inside the loop using the item already in hand.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14a2a54c5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CLI/cmux.swift
if let index = intFromAny(workspace["index"]) {
context["window_index"] = String(index)
context["session_index"] = String(index)
context["session_id"] = "$\(index)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept generated session IDs as -t targets

tmuxFormatContext now emits session_id values like $1, but workspace target resolution does not accept the $ prefix (it only normalizes @/index/title forms). In workflows that chain tmux-compatible commands (e.g. capture #{session_id} from list-sessions and pass it back via -t), this regresses into Workspace target not found even though the ID came from the shim itself. Either emit a resolvable value here or extend target parsing to normalize $ session IDs.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
CLI/cmux.swift (1)

13989-13994: Avoid repeated workspace scans inside list-sessions loop.

list-sessions already has workspaceItems at Line 13989, but Line 13993 calls tmuxFormatContext(...), which performs another workspace-item lookup. Consider passing the current item into the formatter (or a prebuilt id→item map) to avoid O(n²) behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CLI/cmux.swift` around lines 13989 - 13994, The loop in the list-sessions
flow repeatedly calls tmuxFormatContext(workspaceId:client:) which re-scans
workspace items causing O(n²) work; modify tmuxFormatContext to accept the
current workspace item (or alternately build a [String: Any] id→item map from
tmuxWorkspaceItems once) and update the loop to pass the item (or lookup in the
map) instead of calling tmuxFormatContext by id only; update usages of
tmuxFormatContext signature accordingly so the formatter can reuse the provided
item and avoid additional tmuxWorkspaceItems lookups.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@CLI/cmux.swift`:
- Around line 13989-13994: The loop in the list-sessions flow repeatedly calls
tmuxFormatContext(workspaceId:client:) which re-scans workspace items causing
O(n²) work; modify tmuxFormatContext to accept the current workspace item (or
alternately build a [String: Any] id→item map from tmuxWorkspaceItems once) and
update the loop to pass the item (or lookup in the map) instead of calling
tmuxFormatContext by id only; update usages of tmuxFormatContext signature
accordingly so the formatter can reuse the provided item and avoid additional
tmuxWorkspaceItems lookups.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e836487a-7725-4e43-8107-a698679972c0

📥 Commits

Reviewing files that changed from the base of the PR and between 302382d and 1ec66ed.

⛔ Files ignored due to path filters (1)
  • .github/swift-file-length-budget.tsv is excluded by !**/*.tsv
📒 Files selected for processing (1)
  • CLI/cmux.swift

@lawrencecchen lawrencecchen added the stale-revisit Closed after 30+ days without activity; preserved for possible revisit or reopening. label Sep 23, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in cmux backlog Sep 23, 2026

This branch was successfully deployed

1 active deployment
Preview – cmux — 1ec66ed9 Deployed Apr 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale-revisit Closed after 30+ days without activity; preserved for possible revisit or reopening.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants