Skip to content

Validate ORCA_TERMINAL_HANDLE and remint stale orchestration terminals via pane key - #7514

Merged
AmethystLiang merged 3 commits into
mainfrom
debug-orchestration-no-active-terminal
Jul 6, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
debug-orchestration-no-active-terminal

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

This PR improves terminal handle resolution for orchestration commands by validating ORCA_TERMINAL_HANDLE and falling back to reminting pane-specific terminals using ORCA_PANE_KEY if the environment handle is stale.

  • Validates if the ORCA_TERMINAL_HANDLE is live before using it as the coordinator or task creator terminal.
  • If stale, attempts to remint a live pane terminal handle using ORCA_PANE_KEY to preserve user identity and avoid blind fallback.
  • Gracefully degrades task creation metadata recording when the runtime is unavailable.
  • Improves error reporting with clear, actionable no_active_sender_terminal messages.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

AI Review Report

The review checked validation logic for environment handle staleness and active terminal fallback mechanisms. It verified that critical dispatch/run failures properly block, while non-critical metadata queries (like task creator metadata) gracefully fail-safe. Cross-platform compatibility for macOS, Linux, and Windows was reviewed; the resolution relies entirely on standard shell environment variables and platform-agnostic client RPC commands.

Security Audit

Security analysis confirmed that validation functions and terminal handles are handled entirely as typed structured values inside client RPCs without raw string interpolation or shell expansion, avoiding execution or command injection risks.

Notes

No platform-specific risks or follow-up work.

Long-lived shells can retain a stale ORCA_TERMINAL_HANDLE environment
variable after the runtime remints a pane handle. This can cause commands
to bake obsolete terminal handles into coordinator preambles or tasks.

- Check if the environment-provided handle is live via terminal.show before
  using it in dispatch, task-create, or run operations.
- Fall back to resolving the active terminal/implicit sender if the environment
  handle is stale.
- Map raw "no_active_terminal" errors to a helpful user-facing error message
  suggesting the use of the "--from" flag.
Resolve stale environment-provided terminal handles using the caller's
pane key (ORCA_PANE_KEY) via terminal.resolvePane instead of falling
back to the active focused terminal. This prevents commands from being
dispatched from or credited to the wrong terminal pane if focus has
changed.

Additionally, handle graph or pane resolution failures gracefully during
task creation since creator handles are best-effort lineage metadata.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: de239c94-8e7f-427f-b846-17177a51b2b3

📥 Commits

Reviewing files that changed from the base of the PR and between 04e5b83 and 13c3e35.

📒 Files selected for processing (1)
  • src/cli/handlers/orchestration.test.ts

📝 Walkthrough

Walkthrough

Changes

This PR updates orchestration CLI terminal-handle resolution. Coordinator commands now validate ORCA_TERMINAL_HANDLE, fall back to a live pane-derived handle when needed, and surface no_active_sender_terminal when no active sender can be determined. Task creation uses a best-effort caller handle resolver. Dispatch, dispatch-show, run, and task-create are wired to the new resolution paths, and tests add ORCA_PANE_KEY isolation plus coverage for remint success, remint failure, and sender-resolution errors.

Sequence Diagram(s)

sequenceDiagram
  participant Command
  participant resolveOrchestrationTerminalHandle
  participant terminal
  participant RuntimeClientError
  Command->>resolveOrchestrationTerminalHandle: request from handle (validateEnvHandle)
  resolveOrchestrationTerminalHandle->>terminal: show(ORCA_TERMINAL_HANDLE)
  terminal-->>resolveOrchestrationTerminalHandle: stale/gone error
  resolveOrchestrationTerminalHandle->>terminal: resolvePane(orchestration pane)
  alt live pane found
    terminal-->>resolveOrchestrationTerminalHandle: live coordinator handle
  else no active sender
    resolveOrchestrationTerminalHandle->>RuntimeClientError: throw no_active_sender_terminal
  end
Loading

Related issues: None provided.

Related PRs: None provided.

Suggested labels: cli, orchestration, testing

Suggested reviewers: None provided.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: validating ORCA_TERMINAL_HANDLE and reminting stale orchestration terminals via pane key.
Description check ✅ Passed The description follows the required template and covers summary, screenshots, testing, AI review, security, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
src/cli/handlers/orchestration.test.ts (1)

276-431: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting shared helpers for the repeated stale-handle-remint mock chains.

Multiple tests (e.g., Lines 276-313, 368-400, 402-430, 576-602) repeat the same three-call mock chain (terminal_handle_stale → resolvePane success → downstream RPC) with only the endpoint/result varying, and similarly for the failure paths (Lines 315-335, 337-366, 511-537, 539-561). Extracting small helpers like stubStaleHandleRemint(liveHandle) / stubStaleHandleRemintFailure(errorCode) would reduce duplication and make future changes to the remint contract cheaper to update across the suite.

Also applies to: 433-602


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2c0d29db-8a24-43e0-9e0c-77acc16201aa

📥 Commits

Reviewing files that changed from the base of the PR and between 61ecaaf and 04e5b83.

📒 Files selected for processing (2)
  • src/cli/handlers/orchestration.test.ts
  • src/cli/handlers/orchestration.ts

Consolidate repetitive mocking boilerplate for stale terminal handle
reminting and failure flows using new helper functions.
@AmethystLiang

Copy link
Copy Markdown
Contributor Author

looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…s via pane key (stablyai#7514)

* Validate ORCA_TERMINAL_HANDLE and fall back to active terminal if stale

Long-lived shells can retain a stale ORCA_TERMINAL_HANDLE environment
variable after the runtime remints a pane handle. This can cause commands
to bake obsolete terminal handles into coordinator preambles or tasks.

- Check if the environment-provided handle is live via terminal.show before
  using it in dispatch, task-create, or run operations.
- Fall back to resolving the active terminal/implicit sender if the environment
  handle is stale.
- Map raw "no_active_terminal" errors to a helpful user-facing error message
  suggesting the use of the "--from" flag.

* Remint stale orchestration terminals via pane key instead of focus

Resolve stale environment-provided terminal handles using the caller's
pane key (ORCA_PANE_KEY) via terminal.resolvePane instead of falling
back to the active focused terminal. This prevents commands from being
dispatched from or credited to the wrong terminal pane if focus has
changed.

Additionally, handle graph or pane resolution failures gracefully during
task creation since creator handles are best-effort lineage metadata.

* refactor orchestration tests to use helper stubs for stale handles

Consolidate repetitive mocking boilerplate for stale terminal handle
reminting and failure flows using new helper functions.
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