Skip to content

fix(telegram): resolve openshell path for child processes - #266

Closed
mihai-chiorean wants to merge 1 commit into
NVIDIA:mainfrom
mihai-chiorean:fix/telegram-path
Closed

fix(telegram): resolve openshell path for child processes#266
mihai-chiorean wants to merge 1 commit into
NVIDIA:mainfrom
mihai-chiorean:fix/telegram-path

Conversation

@mihai-chiorean

@mihai-chiorean mihai-chiorean commented Mar 18, 2026

Copy link
Copy Markdown

Summary

  • Telegram bridge fails with openshell: not found because ~/.local/bin isn't in PATH for child processes spawned via nohup
  • start-services.sh now adds ~/.local/bin to PATH if missing, resolves openshell to its absolute path via command -v, and exports it as OPENSHELL_BIN
  • Bridge reads OPENSHELL_BIN env var (falls back to bare openshell)

Fixes #199

Summary by CodeRabbit

  • Chores
    • Improved startup reliability for the Telegram bridge by deterministically locating the required helper binary and ensuring user-local bin is included in PATH so child processes can find executables.
    • Exposes the resolved helper binary path to downstream processes for more consistent startup behavior.
    • Made the bridge’s retrieval of SSH configuration more robust by invoking the helper directly rather than through a shell command.

@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Prepends ~/.local/bin to PATH during service startup, resolves and exports OPENSHELL_BIN, and updates the Telegram bridge to call OpenShell via execFileSync(OPENSHELL_BIN, [...]) to obtain SSH config instead of relying on shell PATH lookups.

Changes

Cohort / File(s) Summary
Startup PATH Hardening
scripts/start-services.sh
Prepends ~/.local/bin to PATH when present and not already included; resolves openshell with command -v and exports OPENSHELL_BIN before launching services.
Telegram bridge exec change
scripts/telegram-bridge.js
Replaces shell execSync("openshell ...") with execFileSync(OPENSHELL_BIN, ["sandbox","ssh-config", SANDBOX], ...); imports adjusted for execFileSync and removes shell-dependent invocation.

Sequence Diagram(s)

sequenceDiagram
    participant StartScript as Start Script
    participant Bridge as Telegram Bridge
    participant OpenShell as OpenShell Binary
    participant SSH as ssh (client)

    StartScript->>StartScript: if ~/.local/bin exists && not in PATH -> prepend to PATH
    StartScript->>StartScript: resolve openshell via `command -v` -> set OPENSHELL_BIN
    StartScript->>Bridge: spawn with OPENSHELL_BIN exported
    Bridge->>OpenShell: execFileSync(OPENSHELL_BIN, ["sandbox","ssh-config", SANDBOX])
    OpenShell-->>Bridge: stdout -> SSH config
    Bridge->>SSH: spawn ssh using provided config
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through PATH where binaries hide,
I prepend a trail so none are denied.
OPENSHELL_BIN lights the way, neat and swift,
No lost commands — a dependable gift! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: resolving the openshell path for child processes to fix the Telegram bridge failure.
Linked Issues check ✅ Passed The PR fully addresses issue #199 by resolving the openshell path via command -v, exporting it as OPENSHELL_BIN, and updating the Telegram bridge to use the resolved path.
Out of Scope Changes check ✅ Passed All changes are scoped to resolving the openshell path resolution issue; no unrelated modifications are present.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/telegram-bridge.js`:
- Line 89: Replace the execSync call that builds a shell-interpolated command
using OPENSHELL and SANDBOX with execFileSync to avoid shell interpolation: call
execFileSync(OPENSHELL, ["sandbox", "ssh-config", SANDBOX], { encoding: "utf-8"
}) (ensure execFileSync is imported from child_process) so arguments are passed
as an array and no shell parsing occurs; update the sshConfig assignment
accordingly and preserve the encoding option.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 560bf688-22fb-49f0-aa3f-b6cadf92898a

📥 Commits

Reviewing files that changed from the base of the PR and between 0d1d2d8 and 44ada0d.

📒 Files selected for processing (2)
  • scripts/start-services.sh
  • scripts/telegram-bridge.js

Comment thread scripts/telegram-bridge.js Outdated
@wscurran wscurran added the integration: telegram Telegram integration or channel behavior label Mar 18, 2026

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/start-services.sh`:
- Around line 148-152: The script currently sets OPENSHELL_BIN but continues to
start the Telegram bridge even when openshell is missing; update the block that
defines OPENSHELL_BIN to check for TELEGRAM_BOT_TOKEN and, if TELEGRAM_BOT_TOKEN
is non-empty while OPENSHELL_BIN is empty, immediately fail (echo a clear error
and exit 1) or alternatively log a warning and skip starting the bridge; refer
to the OPENSHELL_BIN variable and the TELEGRAM_BOT_TOKEN env var in your change
so the script refuses to proceed with launching the Telegram bridge when
openshell cannot be resolved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4da854c2-b53a-4d28-aa2d-54dace311075

📥 Commits

Reviewing files that changed from the base of the PR and between 9effed1 and 31fc6ea.

📒 Files selected for processing (2)
  • scripts/start-services.sh
  • scripts/telegram-bridge.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/telegram-bridge.js

Comment thread scripts/start-services.sh
Comment on lines +148 to +152
# Resolve openshell absolute path so child processes find it regardless of PATH
OPENSHELL_BIN="$(command -v openshell 2>/dev/null || true)"
if [ -n "$OPENSHELL_BIN" ]; then
export OPENSHELL_BIN
fi

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.

⚠️ Potential issue | 🟡 Minor

Fail fast when openshell is missing before launching Telegram bridge.

Right now the bridge still starts even when OPENSHELL_BIN cannot be resolved, which can lead to a “started but broken” service state. Consider failing early (or skipping bridge start with a warning) when TELEGRAM_BOT_TOKEN is set and openshell is absent.

Suggested fix
-    OPENSHELL_BIN="$(command -v openshell 2>/dev/null || true)"
-    if [ -n "$OPENSHELL_BIN" ]; then
-      export OPENSHELL_BIN
-    fi
+    OPENSHELL_BIN="$(command -v openshell 2>/dev/null || true)"
+    [ -n "$OPENSHELL_BIN" ] || fail "openshell not found. Install OpenShell or add it to PATH."
+    export OPENSHELL_BIN
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/start-services.sh` around lines 148 - 152, The script currently sets
OPENSHELL_BIN but continues to start the Telegram bridge even when openshell is
missing; update the block that defines OPENSHELL_BIN to check for
TELEGRAM_BOT_TOKEN and, if TELEGRAM_BOT_TOKEN is non-empty while OPENSHELL_BIN
is empty, immediately fail (echo a clear error and exit 1) or alternatively log
a warning and skip starting the bridge; refer to the OPENSHELL_BIN variable and
the TELEGRAM_BOT_TOKEN env var in your change so the script refuses to proceed
with launching the Telegram bridge when openshell cannot be resolved.

@mihai-chiorean

Copy link
Copy Markdown
Author

Closing — upstream merged the equivalent fix in 3cb192c (PR #222), including execFileSync and resolveOpenshell() improvements.

mafueee pushed a commit to mafueee/NemoClaw that referenced this pull request Mar 28, 2026
* docs(examples): add sandbox policy quickstart walkthrough

Add an interactive getting-started example that demonstrates OpenShell's
network policy system end-to-end: default-deny, L7 read-only access,
and audit logging — all with a single YAML policy file.

- examples/sandbox-policy-quickstart/policy.yaml: policy with default
  static fields (filesystem, landlock, process) so it works out of the
  box with `openshell policy set`
- examples/sandbox-policy-quickstart/demo.sh: automated demo script
  using printf (portable) and openshell ssh-proxy for sandbox exec
- examples/sandbox-policy-quickstart/README.md: step-by-step manual
  walkthrough
- README.md: add "See network policy in action" section linking to the
  quickstart

Signed-off-by: Alexander Watson <zredlined@gmail.com>
Made-with: Cursor
Signed-off-by: Alexander Watson <zredlined@gmail.com>
Made-with: Cursor

* docs: soften default-deny wording to minimal outbound access

Sandbox defaults vary by type and community configs, so
"all outbound traffic is blocked" is too absolute.

Made-with: Cursor

* docs: use curl -sS so L4 deny errors are visible

curl -s suppresses stderr, hiding the 403 from the CONNECT
proxy. Adding -S ensures the error message is always shown.

Made-with: Cursor

---------

Signed-off-by: Alexander Watson <zredlined@gmail.com>
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression integration: telegram Telegram integration or channel behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram bridge fails with "openshell: not found" because ~/.local/bin isn't on PATH for child processes

2 participants