Repository navigation
fix(app-server): PLTF-3702 let OSS mode start sandboxes again - #680
aivong-openhands merged 4 commits into
Conversation
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>
Mutation review of the tests in this PR
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 ( Controls: undo the fix (these must fail)
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 Survivors (no test caught these)
M3: nothing checks that
|
…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>
Coverage reportClick to see where and how coverage changed
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>
|
I added both survivor tests in c4c50f8.
How I checked it:
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
left a comment
There was a problem hiding this comment.
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_idandsecure_selectare 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 oneLOCAL_USER_IDconstant, so they can't drift apart. - SaaS isn't affected. SaaS uses
server.auth.saas_user_auth.SaasUserAuth, notDefaultUserAuth.SaasSQLAppConversationInfoServiceoverrides the three read paths that call the changed_to_info(get, batch get, search) and sets the real owner fromConversationMetadataSaas. - Nothing else relied on the old
Noneuser id. The issue asked for this check. I went through everyget_user_id()caller and everyuser_id is None/if not user_idcheck:FileSettingsStoreandFileSecretsStoreignore the user id, sosettings.jsonandsecrets.jsonstay where they are._maybe_rotate_stale_managed_keyonly acts on aSaasSettingsStore.- 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_manageris set. - The memory callback skips a non-UUID user id.
- The webhook
/secretspath andvalidate_session_key_ownershipnow 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_userdrifting fromget_user_id, and owner reads on batch get and search) are closed inc4c50f8. Thetest_user_app_settingsfixture 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 runwith Docker sandboxes can start a conversation (manual before/after evidence in the description: a conversation reachesREADYand 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_refusedis unchanged and passes).
To fix in the PR description
- The
## Typesection from.github/pull_request_template.mdis 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. - 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]
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/codereviewtrigger), 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.
Impact assessmentWarning OSS Verdict: This PR fixes local OSS: sandboxes and webhooks work again. OHE and every SaaS environment run
Validation: diff and call sites read statically at Customer installs:
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
This analysis was produced by an AI agent (OpenHands) on behalf of @aivong-openhands. |
…sandboxes-since-466
Replicated (Embedded Cluster) validation — enterprise install unaffectedSetup: fresh Embedded Cluster install of a release running
On an enterprise install, sandboxes and conversations stay owned by the real user, and the webhook owner check passes. |
|
🚀 Released in 1.70.0. |
HUMAN:
AGENT:
Why
Since #466, the OSS app server (
make run) answers every sandbox request with 401User 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'sDefaultUserAuthhas never had one.This PR gives OSS mode's single user a fixed id,
root.DefaultUserAuth.get_for_useralready asserted that value.require_user_idandsecure_selectare 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 nowroot, so every event the sandbox posted was rejected with 401. The OSS store now reportsrootas the owner. The SaaS store already replaces this value with the real owner and is unaffected.Summary
DefaultUserAuth.get_user_id()returnsLOCAL_USER_ID('root') instead ofNone.SQLAppConversationInfoServicereportsLOCAL_USER_IDas the owner of every conversation.DefaultUserAuth.get_for_useraccepts 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 reportrootas its owner.Issue Number
Fixes #625 (PLTF-3702).
How to Test
I checked this with Docker sandboxes (
RUNTIMEunset):main, both sandbox calls returned 401. With this branch, both return 200, and a conversation started throughPOST /api/v1/app-conversationsreachedREADY./api/v1/webhooks/conversationsand/api/v1/webhooks/eventscalls returned 200, and the conversation's events loaded throughGET /api/v1/conversation/{id}/events/search. With only the conversation-store change reverted, all 12 webhook calls returned 401.tests/unit/app_server,tests/unit/test_sharing,tests/unit/mcp,tests/unit/test_auth_routes.pyand 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_refusedstill covers the multi-user 401.Video/Screenshots
N/A, backend only.
Type
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 onmain.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: