Skip to content

fix(app-server): PLTF-3702 let OSS mode start sandboxes again - #680

Merged
aivong-openhands merged 4 commits into
mainfrom
aivong/pltf-3702-oss-mode-cant-start-docker-sandboxes-since-466
Oct 7, 2026
Merged

aivong-openhands merged 4 commits into
mainfrom
aivong/pltf-3702-oss-mode-cant-start-docker-sandboxes-since-466

Conversation

@aivong-openhands

@aivong-openhands aivong-openhands commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:


Why

Since #466, the OSS app server (make run) answers every sandbox request with 401 User authentication required, so a local setup can't start a conversation. #466 made the sandbox table refuse callers without a user id, and OSS mode's DefaultUserAuth has never had one.

This PR gives OSS mode's single user a fixed id, root. DefaultUserAuth.get_for_user already asserted that value. require_user_id and secure_select are unchanged, so a multi-user caller with no user id still gets 401.

The user id also has to match in one more place. The OSS conversation store has no owner column and reported every conversation's owner as None. The webhook that the agent server calls compares that owner with the sandbox's owner, which is now root, so every event the sandbox posted was rejected with 401. The OSS store now reports root as the owner. The SaaS store already replaces this value with the real owner and is unaffected.

Summary

  • DefaultUserAuth.get_user_id() returns LOCAL_USER_ID ('root') instead of None.
  • SQLAppConversationInfoService reports LOCAL_USER_ID as the owner of every conversation.
  • Regression tests: OSS auth starts and lists a Docker sandbox, and DefaultUserAuth.get_for_user accepts that sandbox's owner id (the path secret lookup and webhook callbacks use). A saved OSS conversation passes the webhook owner check for the local user's sandbox, and get, batch get and search all report root as its owner.

Issue Number

Fixes #625 (PLTF-3702).

How to Test

make local-db
env -u SESSION_API_KEY make run   # or: uv run uvicorn openhands.server.listen:app --host 0.0.0.0 --port 3000
curl -X POST http://127.0.0.1:3000/api/v1/sandboxes          # 200, created_by_user_id "root"
curl http://127.0.0.1:3000/api/v1/sandboxes/search            # 200, lists it

I checked this with Docker sandboxes (RUNTIME unset):

  • Before / after: on main, both sandbox calls returned 401. With this branch, both return 200, and a conversation started through POST /api/v1/app-conversations reached READY.
  • Webhooks: with this branch, the agent server's /api/v1/webhooks/conversations and /api/v1/webhooks/events calls returned 200, and the conversation's events loaded through GET /api/v1/conversation/{id}/events/search. With only the conversation-store change reverted, all 12 webhook calls returned 401.
  • Unit tests: tests/unit/app_server, tests/unit/test_sharing, tests/unit/mcp, tests/unit/test_auth_routes.py and the SaaS conversation-store tests pass (2377 tests). Each new test fails when the fix it covers is reverted. TestScoping::test_a_caller_without_a_user_id_is_refused still covers the multi-user 401.

Video/Screenshots

N/A, backend only.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Breaking for existing OSS local data: conversation events are now stored under <persistence dir>/root/v1_conversations/ instead of <persistence dir>/v1_conversations/. Events from OSS conversations created before this change won't load unless you move that directory. Sandboxes created before #466 have no owner and stay hidden, as they already are on main.


This PR was drafted by an AI agent on behalf of the user.

@aivong-openhands can click here to continue refining the PR


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-e51b9b2

DefaultUserAuth.get_user_id() returned None, so since #466 every sandbox
request in OSS mode (make run) failed with 401 'User authentication required'.
It now returns LOCAL_USER_ID ('root', the id get_for_user already expected).

The OSS SQLAppConversationInfoService stores no conversation owner and
reported None, which no longer matches the sandbox owner in the webhook
owner check. It now reports LOCAL_USER_ID. The SaaS subclass still
overrides it with the owner from ConversationMetadataSaas.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions github-actions Bot added the type: fix A bug fix label Oct 6, 2026
@aivong-openhands

aivong-openhands commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Mutation review of the tests in this PR

Updated for 3e85d30. The first version of this review ran only the 2377-test subset quoted in the PR description, at 9acfd68. CI was red on that commit: two tests in tests/unit/server/routes/test_user_app_settings.py failed. Their fixture overrode get_user_id, but the service never reads it; it reads the user from its injected user_context. The tests only passed because DefaultUserAuth used to return no user id. 3e85d30 makes the fixture set no user on the dependency the service actually uses. I then reran every mutant against the full suite. The results are unchanged.

Method: I broke the PR's code by hand in 5 targeted ways ("mutants") and ran the suite after each one. A mutant that leaves the suite green means no test checks that behaviour. Before any mutation, the full unit suite (tests/unit, the same command CI runs) passed at 3e85d30 with 7025 tests. CI's Python Tests job is also green on this commit.

Controls: undo the fix (these must fail)

Mutant Result
C1: DefaultUserAuth.get_user_id() returns None again ❌ caught
C2: OSS _to_info reports created_by_user_id=None again ❌ caught
M1: SaaS _to_info_with_user_id stops overriding the owner, so SaaS conversations report 'root' ❌ caught (by the existing SaaS store tests)

The two new tests catch both controls on their own (2 tests, about 2s). Both tests go through real code. The Docker test uses a real AuthUserContext(DefaultUserAuth()) with secure_select, and the webhook test saves a row through the real SQLAppConversationInfoService and then runs valid_conversation on it. Neither test fakes the owner. M1 matters because this PR changes what the base _to_info returns: before, a SaaS row missing the override reported None; now it would report 'root'. The existing SaaS tests catch that.

Survivors (no test caught these)

Mutant Result
M3: get_for_user drifts from get_user_id: LOCAL_USER_ID becomes 'local', but get_for_user keeps asserting 'root' ✅ 7025 passed
M2: only get_app_conversation_info reports the local owner; batch_get and search report None ✅ 7025 passed

M3: nothing checks that get_for_user accepts the id get_user_id returns

This PR gives OSS sandboxes a real owner ('root'). That puts DefaultUserAuth.get_for_user on a live code path. Two places rebuild the owner's auth from that id:

  • sandbox_router._get_user_context, used by /sandboxes/{id}/settings/secrets[/{name}]. This is how LookupSecret inside the sandbox reads secrets.
  • webhook_router._resolve_user_context, used by the webhook /secrets provider-token endpoint.

Before this PR, the owner was None. The first path returned 401 and the second fell back to DefaultUserAuth(), so get_for_user was never called. Now both call get_for_user('root'). If get_user_id and the assertion in get_for_user ever disagree, OSS secret lookups fail with an AssertionError (a 500). The PR prevents that today by using one constant on both sides, but no test would catch the two drifting apart. You can fix this with one more assertion at the end of test_oss_default_auth_starts_and_lists_its_sandbox:

        assert page.items[0].created_by_user_id == LOCAL_USER_ID
        # Secret lookup and webhook callbacks rebuild the owner's auth from this id.
        assert isinstance(
            await DefaultUserAuth.get_for_user(started.created_by_user_id),
            DefaultUserAuth,
        )

Verified at 3e85d30: the test passes on this branch as is, and fails when M3 is applied.

M2: only the single-get path is tested

The webhook test reads the owner through get_app_conversation_info, so that path is covered. search_app_conversation_info and batch_get_app_conversation_info also build their results with _to_info, but no test checks their owner. Today all three share one line, so they can't drift apart. A later refactor that sets the owner only on the get path, which is what M2 does, would leave /api/v1/app-conversations/search and the batch endpoints returning created_by_user_id: null, while the single get returns "root". No authorization check in OSS reads the owner from those two paths, so the impact is limited to inconsistent API responses. That's why I've ranked this second. A small test in test_sql_app_conversation_info_service.py covers all three reads:

from openhands.app_server.user.user_models import LOCAL_USER_ID

    @pytest.mark.asyncio
    async def test_every_read_reports_the_local_user_as_owner(
        self,
        service: SQLAppConversationInfoService,
        sample_conversation_info: AppConversationInfo,
    ):
        """No owner column, so get, batch get and search all report OSS mode's single user."""
        await service.save_app_conversation_info(sample_conversation_info)

        got = await service.get_app_conversation_info(sample_conversation_info.id)
        [batched] = await service.batch_get_app_conversation_info(
            [sample_conversation_info.id]
        )
        page = await service.search_app_conversation_info()

        owners = [got.created_by_user_id, batched.created_by_user_id] + [
            item.created_by_user_id for item in page.items
        ]
        assert owners == [LOCAL_USER_ID] * 3

Verified at 3e85d30: the test passes on this branch as is, and fails when M2 is applied. With both additions in place, test_docker_sandbox_service.py and test_sql_app_conversation_info_service.py pass (144 tests).

Not a test gap

  • Using one LOCAL_USER_ID constant for get_user_id, get_for_user and the OSS store is the structural fix. M3 is only possible if someone undoes it. The extra assertion just keeps it that way.

This comment was generated by an AI assistant on behalf of the user.

…no user

The unauthenticated fixture overrode get_user_id, which the service never
reads; it reads the user from its injected user_context. The tests only
passed because DefaultUserAuth returned no user id. Override the service
dependency with a user_context that has no user instead.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  sql_app_conversation_info_service.py
  openhands/app_server/user
  user_models.py
  openhands/app_server/user_auth
  default_user_auth.py
Project Total  

This report was generated by python-coverage-comment-action

…wner read path

Addresses mutation review: assert DefaultUserAuth.get_for_user accepts the
id the sandbox is created with, and that get, batch get and search all
report LOCAL_USER_ID as the conversation owner.

Co-authored-by: openhands <openhands@all-hands.dev>
@aivong-openhands

Copy link
Copy Markdown
Contributor Author

I added both survivor tests in c4c50f8.

  • M3: test_oss_default_auth_starts_and_lists_its_sandbox now also checks that DefaultUserAuth.get_for_user(started.created_by_user_id) returns a DefaultUserAuth.
  • M2: a new test, test_every_read_reports_the_local_user_as_owner in test_sql_app_conversation_info_service.py, checks that get, batch get and search all report LOCAL_USER_ID as the owner.

How I checked it:

  • On this branch, both tests pass. The two files pass in full (144 tests), and the Python pre-commit hooks (ruff, ruff format, mypy) pass.
  • M3 (LOCAL_USER_ID = 'local', with get_for_user still asserting 'root'): the Docker test fails with an AssertionError at default_user_auth.py:92.
  • M2 (search and batch get return created_by_user_id=None): the new test fails with ['root', None, None] == ['root', 'root', 'root'].

I also updated the test bullet in the PR description.

This comment was generated by an AI agent (OpenHands) on behalf of the user.

@aivong-openhands aivong-openhands left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code review at c4c50f8

Taste rating: 🟢 Good. It's a small fix in the right place, it leaves the #466 security checks alone, and the tests exercise the actual code instead of mocks.

Material findings

None.

What I checked

  • The fix is in the right place. require_user_id and secure_select are unchanged. OSS mode's single user now has a real id, root, so the per-user checks #466 added apply to it like any other user. get_user_id(), get_for_user() and the OSS conversation store all use one LOCAL_USER_ID constant, so they can't drift apart.
  • SaaS isn't affected. SaaS uses server.auth.saas_user_auth.SaasUserAuth, not DefaultUserAuth. SaasSQLAppConversationInfoService overrides the three read paths that call the changed _to_info (get, batch get, search) and sets the real owner from ConversationMetadataSaas.
  • Nothing else relied on the old None user id. The issue asked for this check. I went through every get_user_id() caller and every user_id is None / if not user_id check:
    • FileSettingsStore and FileSecretsStore ignore the user id, so settings.json and secrets.json stay where they are.
    • _maybe_rotate_stale_managed_key only acts on a SaasSettingsStore.
    • The daily quota code returns early unless the app is in SaaS mode.
    • Analytics only runs when an analytics service is configured.
    • Provider token refresh only runs when external_token_manager is set.
    • The memory callback skips a non-UUID user id.
    • The webhook /secrets path and validate_session_key_ownership now work in OSS instead of returning 401.
  • The webhook owner check is fixed end to end. The events path is now <prefix>/root/v1_conversations/... both when events are written (webhook, using the sandbox owner) and when they're read (EventServiceBase.get_conversation_path, using the user context).
  • The tests catch the bugs. The new tests would fail if either fix were undone. The two gaps from the earlier mutation review (get_for_user drifting from get_user_id, and owner reads on batch get and search) are closed in c4c50f8. The test_user_app_settings fixture now overrides the dependency the service actually reads.
  • CI is green on c4c50f8. That includes Python Tests (3.12), the lint jobs and the Docker image build.

Acceptance criteria (#625)

  • make run with Docker sandboxes can start a conversation (manual before/after evidence in the description: a conversation reaches READY and the webhooks return 200).
  • A test covers starting and listing a sandbox with OSS default auth (test_oss_default_auth_starts_and_lists_its_sandbox).
  • A multi-user caller with no user id still gets 401 (TestScoping::test_a_caller_without_a_user_id_is_refused is unchanged and passes).

To fix in the PR description

  1. The ## Type section from .github/pull_request_template.md is missing. Since existing OSS conversation events move to <persistence dir>/root/v1_conversations/, also consider ticking "Breaking change" and putting the move-the-directory note under ## Notes.
  2. The "A human has tested these changes" box is unchecked. A human should confirm before the PR leaves draft.

Minor: OSS start tasks and sandboxes created with no owner become invisible. Sandboxes already are on main, and start tasks are short-lived, so this doesn't block anything.


[RISK ASSESSMENT]

[Overall PR] ⚠️ Risk Assessment: 🟡 MEDIUM

The change touches identity and ownership logic (DefaultUserAuth, the conversation owner, the webhook owner check), which is security-sensitive by category. In practice it only affects pure OSS mode: SaaS and self-hosted Enterprise use SaasUserAuth and the SaaS store, which sets the real owner. The #466 rule that refuses callers without a user id is unchanged. Reviewers should focus on the one-time move of OSS event storage.

Verdict: ✅ Worth merging once the PR leaves draft (template gap fixed and the human-tested box checked). This is posted as a COMMENT because the author can't approve their own PR.

Key insight: the earlier bug came from "no user id" meaning two things: "the single OSS user" and "not logged in". Giving the OSS user a real id leaves "no user id" with only one meaning, so the #466 checks keep working without an OSS exception.

Improve this review? If feedback seems incorrect or irrelevant, update the repository's .agents/skills/custom-codereview-guide.md (with the /codereview trigger), then re-request review. The reviewer reads the guide from the PR head.

Resolve with AI? Install the iterate skill and run /iterate.

Was this review helpful? React with 👍 or 👎.

This review was generated by an AI agent (OpenHands) on behalf of the user.

@aivong-openhands

aivong-openhands commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Impact assessment

Warning

OSS make run with existing local conversation history: event history moves from <persistence>/v1_conversations/ to <persistence>/root/v1_conversations/ (event/event_service_base.py:145-158). Old history won't load until the folder is moved by hand (documented in the PR). A read fallback to the old path would remove the manual step.

Verdict: This PR fixes local OSS: sandboxes and webhooks work again. OHE and every SaaS environment run SaaSServerConfig (SaasUserAuth + SaasSQLAppConversationInfoService) and never reach the changed code. No opt-out is needed.

Result Deployment Auth / conversation-info impl Behavior (before → after)
🟡 changed OSS make run, existing local history DefaultUserAuth / SQLAppConversationInfoService event folder v1_conversations/ → root/v1_conversations/
🟢 fixed OSS make run DefaultUserAuth / SQLAppConversationInfoService sandbox API + webhooks 401 → 200; owner None → root
🟢 unchanged OHE (Replicated, chart defaults) SaasUserAuth / SaasSQLAppConversationInfoService no change; real owner still set
🟢 unchanged SaaS prod / staging / dev / feature, dev_config/local_saas same as OHE no change

Validation: diff and call sites read statically at c4c50f8 against main cc77012. OHE settings come from chart defaults (OPENHANDS_CONFIG_CLS=server.config.SaaSServerConfig) and the image's OH_APP_CONVERSATION_INFO_KIND (SaaS injector). SaaS settings come from the umbrella chart (same values). PR CI is green. Nothing was verified live.

Customer installs:

  • On OHE, SaaSServerConfig selects SaasUserAuth (server/config.py:66), so requests never use DefaultUserAuth.
  • The SaaS conversation service overrides search, get and batch get and always sets the real owner (saas_app_conversation_info_injector.py:472-487), so the new root default never surfaces.
  • The only shared path is the /secrets webhook fallback for tokens with no user_id (webhook_router.py:625). It now looks up root instead of None; that user doesn't exist in SaaS mode, so it fails the same way as before.

Rollout: Draft. On merge, local OSS works again; users with existing local conversation history need the one-time folder move. OHE and SaaS pick up the image with no behavior change.

Changed symbols and call sites
  • LOCAL_USER_ID = 'root' (new, user/user_models.py): used by DefaultUserAuth and SQLAppConversationInfoService._to_info.
  • DefaultUserAuth.get_user_id() None → 'root': only when the OSS default auth class is configured (server_config/server_config.py:24). OSS readers: sandbox/sandbox_store.py:132, sandbox/session_auth.py (user scoping, now passes); event/filesystem_event_service.py:121 (event folder prefix); sql_app_conversation_start_task_service.py:370 (start tasks filtered by root; pre-PR tasks hidden, and an in-flight one re-saved across the upgrade would trip the assert at :255); live_status_app_conversation_service.py:410, app_conversation_router.py:538/1225/2195 (quota still skipped, app_mode != saas); git/git_router.py, user/auth_user_context.py:141 (external_auth_id='root'); recaptcha/sql_recaptcha_service.py:46; settings/marketplace_composition.py:293 (file stores ignore user_id, so settings.json/secrets.json don't move).
  • DefaultUserAuth() direct use: event_callback/webhook_router.py:625.
  • SQLAppConversationInfoService._to_info owner None → 'root': base search/get/batch get (:304, :431, :455), all overridden by the SaaS subclass. Webhook owner check at webhook_router.py:323/436.

This analysis was produced by an AI agent (OpenHands) on behalf of @aivong-openhands.

@aivong-openhands

Copy link
Copy Markdown
Contributor Author

Replicated (Embedded Cluster) validation — enterprise install unaffected

Setup: fresh Embedded Cluster install of a release running enterprise-server:sha-e51b9b2 (this PR's head), with external Postgres and GitLab login.

Check Result
Install All pods Running/Completed.
End to end Login, new conversation, sandbox started, agent replied.
Sandbox → app webhooks GET /api/v1/webhooks/secrets 200, POST /api/v1/webhooks/conversations 200, POST /api/v1/webhooks/events 200 (×2). No User authentication required or 401 responses in the app
log.
Sandbox owner v1_remote_sandbox.created_by_user_id is the logged-in user's id.
Conversation owner conversation_metadata_saas.user_id is the same user. conversation_metadata.user_id is empty, and the SaaS table supplies the owner.
root ownership 0 sandboxes and 0 conversations owned by root.

On an enterprise install, sandboxes and conversations stay owned by the real user, and the webhook owner check passes.

@aivong-openhands
aivong-openhands marked this pull request as ready for review October 7, 2026 15:21
@aivong-openhands
aivong-openhands merged commit 6ca6c90 into main Oct 7, 2026
20 checks passed
@aivong-openhands
aivong-openhands deleted the aivong/pltf-3702-oss-mode-cant-start-docker-sandboxes-since-466 branch October 7, 2026 17:40
@openhands-release-bot openhands-release-bot Bot added the released: 1.70.0 Shipped in 1.70.0 label Oct 8, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.70.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.70.0 Shipped in 1.70.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSS mode can't start Docker sandboxes since #466: DefaultUserAuth has no user id, so POST /api/v1/sandboxes returns 401

3 participants