Skip to content

feat(hooks): cross-platform terminal identity for agent binding [OMN-7295] - #1072

Closed
jonahgabriel wants to merge 0 commit into
mainfrom
jonah/omn-7295-terminal-identity
Closed

jonahgabriel wants to merge 0 commit into
mainfrom
jonah/omn-7295-terminal-identity

Conversation

@jonahgabriel

@jonahgabriel jonahgabriel commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds terminal_identity.py — PPID-based heuristic that assigns a stable terminal ID per shell session
  • Stored in .onex_state/terminal/tid_{ppid}, survives /clear, distinct per terminal tab
  • Includes unit tests (4 passing)

Context

Part of Phase 2 Agent Identity (OMN-7291). Terminal identity is the bootstrap mechanism for binding agents to terminal sessions via /login.

Test plan

  • uv run pytest tests/unit/hooks/lib/test_terminal_identity.py -v — 4 tests pass
  • CI green

Summary by CodeRabbit

  • New Features

    • Added terminal identity tracking to maintain stable session identifiers across terminal tabs and shell sessions.
  • Tests

    • Added comprehensive unit tests for terminal identity creation, persistence, and validation.

@coderabbitai

coderabbitai Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new Python module introducing terminal identity management is added. The module provides functions to generate, persist, and validate unique terminal identifiers per shell session using parent process IDs and UUID-based naming. Comprehensive unit tests validate creation, persistence, and format enforcement of these terminal IDs.

Changes

Cohort / File(s) Summary
Terminal Identity Module
plugins/onex/hooks/lib/terminal_identity.py
New module providing stable terminal identifiers with functions: _get_shell_key() deriving session keys from parent process ID, get_or_create_terminal_id() managing persistent ID files in ~/.onex_state/terminal/, and is_terminal_id_valid() validating ID format (must start with "terminal-" prefix).
Terminal Identity Tests
tests/unit/hooks/lib/test_terminal_identity.py
Unit test suite validating ID creation, file persistence across calls, isolation across directories, and prefix validation using temporary fixtures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A terminal takes form, with identity so neat,
State files stored, from shell to seat,
UUID crafted with hostname's grace,
Persistent IDs in their place! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding terminal identity functionality with PPID-based heuristics for agent binding, which aligns with the core feature added in terminal_identity.py and its supporting tests.

✏️ 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 jonah/omn-7295-terminal-identity
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch jonah/omn-7295-terminal-identity

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

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
plugins/onex/hooks/lib/terminal_identity.py (1)

32-40: Docstring mentions Windows-specific behavior not implemented.

The docstring states "session leader PID on Windows" but the implementation unconditionally uses os.getppid() for all platforms. Either update the docstring to reflect the actual implementation or add the Windows-specific logic if intended.

📝 Suggested docstring fix
 def _get_shell_key() -> str:
     """Get a stable key for the current shell process.
 
-    Uses PPID (parent process ID) on Unix, or a combination of
-    session leader PID on Windows. Falls back to PID if PPID
-    is not available.
+    Uses PPID (parent process ID) which is available on all platforms
+    including Windows, macOS, and Linux. Behavior may vary by platform
+    and terminal emulator.
     """
     ppid = os.getppid()
     return str(ppid)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/onex/hooks/lib/terminal_identity.py` around lines 32 - 40, The
docstring for _get_shell_key mentions Windows-specific "session leader PID"
behavior that isn't implemented; update the function so docstring matches
reality: either implement the Windows-specific logic or simplify the docstring
to state that the function currently returns the parent process ID
(os.getppid()) on all platforms and falls back to PID if needed. Locate
_get_shell_key and modify its docstring accordingly (or implement
platform-specific behavior using Windows APIs if you prefer), ensuring the
docstring and implementation are consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/hooks/lib/test_terminal_identity.py`:
- Around line 10-14: Remove the redundant sys.path manipulation block that
inserts the hooks/lib path at test import time: delete the sys.path.insert(...)
call along with the preceding comment and the Path(...) expression (the block
that uses Path(__file__).resolve().parents[4] / "plugins" / "onex" / "hooks" /
"lib"). Rely on the existing tests/conftest.py setup that already configures
sys.path instead of duplicating it in test_terminal_identity.py.

---

Nitpick comments:
In `@plugins/onex/hooks/lib/terminal_identity.py`:
- Around line 32-40: The docstring for _get_shell_key mentions Windows-specific
"session leader PID" behavior that isn't implemented; update the function so
docstring matches reality: either implement the Windows-specific logic or
simplify the docstring to state that the function currently returns the parent
process ID (os.getppid()) on all platforms and falls back to PID if needed.
Locate _get_shell_key and modify its docstring accordingly (or implement
platform-specific behavior using Windows APIs if you prefer), ensuring the
docstring and implementation are consistent.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3a713e1e-a217-4d08-9bf2-92695b27224a

📥 Commits

Reviewing files that changed from the base of the PR and between 5ae1721 and 8500867.

📒 Files selected for processing (2)
  • plugins/onex/hooks/lib/terminal_identity.py
  • tests/unit/hooks/lib/test_terminal_identity.py

Comment on lines +10 to +14
# Add hooks/lib to path so we can import the module directly
sys.path.insert(
0,
str(Path(__file__).resolve().parents[4] / "plugins" / "onex" / "hooks" / "lib"),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if other test files in this repo use the same sys.path pattern
rg -n "sys\.path\.insert" --type=py -g '*test*.py' | head -20

Repository: OmniNode-ai/omniclaude

Length of output: 1656


🏁 Script executed:

head -60 tests/conftest.py

Repository: OmniNode-ai/omniclaude

Length of output: 2366


🏁 Script executed:

cat pyproject.toml | head -100

Repository: OmniNode-ai/omniclaude

Length of output: 3217


🏁 Script executed:

cat -n tests/unit/hooks/lib/test_terminal_identity.py

Repository: OmniNode-ai/omniclaude

Length of output: 1830


Remove the redundant sys.path manipulation—conftest.py already configures this path.

The tests/conftest.py already adds plugins/onex/hooks/lib to sys.path (line 41), so lines 10–14 in this file are redundant. Remove them and rely on the central conftest configuration:

Suggested fix
# Add hooks/lib to path so we can import the module directly
-sys.path.insert(
-    0,
-    str(Path(__file__).resolve().parents[4] / "plugins" / "onex" / "hooks" / "lib"),
-)
-
 from terminal_identity import (  # noqa: E402
     get_or_create_terminal_id,
     is_terminal_id_valid,
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/hooks/lib/test_terminal_identity.py` around lines 10 - 14, Remove
the redundant sys.path manipulation block that inserts the hooks/lib path at
test import time: delete the sys.path.insert(...) call along with the preceding
comment and the Path(...) expression (the block that uses
Path(__file__).resolve().parents[4] / "plugins" / "onex" / "hooks" / "lib").
Rely on the existing tests/conftest.py setup that already configures sys.path
instead of duplicating it in test_terminal_identity.py.

@jonahgabriel
jonahgabriel force-pushed the jonah/omn-7295-terminal-identity branch from 8500867 to 035707d Compare April 2, 2026 17:08
@jonahgabriel
jonahgabriel deleted the jonah/omn-7295-terminal-identity branch April 4, 2026 02:01

This branch was previously deployed

1 inactive deployment
production — 035707dd Deployed Apr 2, 2026 by github-merge-queue[bot] via Deploy to Production #3518
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