fix(sdk_main): inject session URL as secret using conversation.id#142
Conversation
Adds AUTOMATION_SESSION_URL to the sandbox env vars when SANDBOX_ID is
available (Cloud mode). The URL is pre-built as {cloud_api_url}/conversations/{sandbox_id}
so automation scripts can link back to the session without having to
reconstruct it from SANDBOX_ID + OPENHANDS_CLOUD_API_URL individually —
both of which are stripped by sanitized_env() before they reach the
agent's bash subprocess.
Also documents the new env var in the plugin preset sdk_main.py docstring.
Co-authored-by: openhands <openhands@all-hands.dev>
|
🚀 Deploy Preview PR Created/Updated A deploy preview has been created/updated for this PR. Deploy PR: https://github.com/OpenHands/deploy/pull/4429 Once the deploy PR's CI passes, the automation service will be deployed to the feature environment. |
299a7aa to
cab4494
Compare
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable — Clean implementation, but incomplete
The session URL injection logic is well-implemented and correctly scoped to Cloud mode. However, the prompt preset has identical structure and needs the same fix for consistency.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
Adds optional runtime feature (session URL injection) to plugin preset only. No breaking changes, backward compatible. The missing prompt preset update is a consistency issue, not a functional risk.
VERDICT:
❌ Needs rework: Apply the same fix to both presets for consistency
KEY INSIGHT:
Using update_secrets() for runtime URL injection is elegant — secrets auto-export to bash without prompt changes.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/automation/actions/runs/26475714804
| if not IS_LOCAL_MODE and api_url: | ||
| session_url = f"{api_url}/conversations/{conversation.id}" | ||
| conversation.update_secrets({"AUTOMATION_SESSION_URL": session_url}) | ||
| print(f" session URL: {session_url}") |
There was a problem hiding this comment.
🔴 Critical: This same fix must be applied to the prompt preset for consistency.
The file openhands/automation/presets/prompt/sdk_main.py has identical structure:
- Creates a
Conversation(line ~326) - Calls
conversation.update_secrets(secrets)(line ~331) - But is missing the session URL injection
Apply both changes there:
- Add the runtime-injected secrets docstring section (lines 59-61 here)
- Add the session URL injection code block (lines 349-354 here)
Even though the PR review automation currently uses the plugin preset, the prompt preset will have the same bug if any automation using it tries to reference $AUTOMATION_SESSION_URL.
There was a problem hiding this comment.
Fixed in a14efa6 — applied the same session URL injection and docstring changes to openhands/automation/presets/prompt/sdk_main.py.
This reply was posted by an AI agent (OpenHands) on behalf of the user.
After Conversation(...) is created, build the session URL from
conversation.id and inject it via conversation.update_secrets().
The SDK auto-exports secrets as env vars when the agent's bash command
references the key name, so the prompt's ${AUTOMATION_SESSION_URL}
just works — no prompt changes needed.
Applied to both plugin and prompt presets for consistency.
Co-authored-by: openhands <openhands@all-hands.dev>
cab4494 to
a14efa6
Compare
Problem
The PR review automation posts a progress comment and review body with a session URL, but the URL was wrong — it pointed to
https://app.all-hands.dev(the app root) instead of the actual conversation.Root cause: The correct URL is
https://app.all-hands.dev/conversations/{conversation_id}. Theconversation_idis only available afterConversation(...)is instantiated insdk_main.py, but was never being captured and passed to the agent.Fix
After
Conversation(...)is created insdk_main.py, build the session URL fromconversation.idand inject it viaconversation.update_secrets({"AUTOMATION_SESSION_URL": session_url}).The SDK auto-exports secrets as env vars into the agent's bash subprocess when the command text references the key name. So the original prompt's
${AUTOMATION_SESSION_URL}just works — no prompt changes needed.Why
update_secrets()instead of prompt injection?sanitized_env()only stripsSESSION_API_KEY—AUTOMATION_SESSION_URLpasses through fine${AUTOMATION_SESSION_URL:-fallback}naturally picks up the secret valuesdk_main.py, prompt stays focused on agent behaviorChanges
openhands/automation/presets/plugin/sdk_main.py: After conversation creation, buildsession_url = f"{api_url}/conversations/{conversation.id}"and inject viaconversation.update_secrets()openhands/automation/dispatcher.py: No changes (reverted from previous approach that usedsandbox_id)Tested
Triggered via
review-thislabel on OpenHands/software-agent-sdk#3333. The progress comment and review body now contain correcthttps://app.all-hands.dev/conversations/{uuid}links.