With V1 conversations, do we use a db to store con...
# proj-sdk
q
With V1 conversations, do we use a db to store conversation metadata, user secrets, etc for local installations of OpenHands?
w
I believe it's sqllite, so it's a "database" that's just a single file, no process
q
gotcha, i think i found the relevant files seems like we have separate migrations for oss and saas as well, and the data models can get out of sync
w
nod yeah @straight-sundown-84319 knows more
s
Yes - we now have separate migrations
I figure it means at least we use the same mechanism for both rather than migrations for one and checking on the fly for the other
q
Gotcha I'm introducing org id to the conversation metadata storage data model The data model is now used in local installations too, and we don't have local migrations for org_id (nor should we imho) i'm guessing for shared data models we'll have to start doing something like this?
Copy code
if is_saas():                                                                                                                                                                                                                
     org_id = Column(SQL_UUID(as_uuid=True), ForeignKey('org.id'), nullable=True)                                                                                                                                                               
     org = relationship('Org', back_populates='conversation_metadata')
😭 1
c
Does conversation_metadata really need org_id?
q
I think we may have to in order to know which org the conversation belongs to thonk I believe it will be needed to implement conversation sharing features (e.g share trajectories only with members of the org)
c
Well, idk, I'm thinking like: the conversation belongs to a user, the user has an org, there is enough information to figure out who has permissions thinky spin It could be handled in code, that is, a small API could say
has_same_org(user)
or maybe ``````
s
Hey - sorry for the delay weighing in here - In the conversation table we currently have a nullable column user_id. We mirror this column in OSS, but the value for user_id is null. The way I see it, we have 2 options: Create a new column org id in both, but it will be null in OSS. • We add a column definition to StoredConversationMetadata here with the org id • We add migrations to both OSS and SAAS for this value • We add a limit on the org id here (if None, then we are in OSS and there is no limit) Start separating the schemas for the conversation table in OSS and SAAS. • We turn StoredConversationMetadata into 2 separate models - one for OSS, one for SAAS. The saas version has a user_id and org_id - the OSS one does not. • We create a migration in openhands/app_server/app_lifespan/alembic/versions to remove the
user_id
from the OSS table • We create a migration in enterprise/migrations/versions to add the
org_id
to the enterprise table • We rename the SQLAppConversationInfoService to
OSSAppConversationInfoService
and have its secure_select method simply
return select(StoredConversationMetadata)
. We do similarly with the save_app_conversation_info method and any other reference to user_id • We create a SAASAppConversationInfoService which impelements filtering by
user_id
/
org_id
. (Probably a subclass of OSSAppConversationInfoService) • We create replacements for SQLAppConversationInfoServiceInjector - the SAAS one obviously injects the user_context. • We check the app_mode here, and initialize the appropriate injector
c
How bad is the third option? • there's a user table, an org table, indexes, foreign key • ConversationMetadata has
user_id
, but does not get
org_id
• => adds a JOIN in various queries that need the "sharing" functionality
s
Probably better than option 2
We still need a different implementation for SAAS vs OSS though
But it does allow for a conversation to be part of multiple orgs
Why may be desirable?
c
The "sharing" functionality would be saas only, so that's just code that would exist in all cases, I guess. What differences are concerning, in case three?
I have no good idea why a conversation could be part of multiple orgs, Tim. Probably that's not needed? Re: case one, it leaks in OH something that clearly doesn't belong there - I have multiple concerns with that 😭
s
I don't see any major concerns with case 3. It will take a little longer to implement than case 1 but will probably leave us happier in the long term
c
I had Claude make me some "how would it look like on OH repo" in the gist above ( https://openhands-ai.slack.com/archives/C09FJAZSP9N/p1761342430318279?thread_ts=1761331470.863679&cid=C09FJAZSP9N )
For the record, I do think case 3 is good, but I'm not sure the maintenance implications are ... great
s
I think type are probably better than case 1 - it is better to treat separate cases as being separate than to pretend they are the same
nod 1
That eventually bites back
q
Ah also one user can belong to multiple orgs So we could drop the foreign key to org id and have it for org member instead (which is equivalent for user_id) so we know which org it belongs the caveat being we can only add/disable members from orgs but never remove them (similar to slack, so that org member ids aka user id never change)
c
Re: case 2. I think you're right, Tim. I take back what I said on maintenance, rather it seems to require more effort on the initial refactoring. With the injector to isolate what is specific to each type of deployment, early in the execution path, case 2 could work really nicely in app code. I'm looking at details, and I like it! That direction is the same direction where my proposals on V0 were going. I do think that with the right abstractions at the right place, the maintenance will get easier than to work permanently around special cases, which is what I fear from stuff creeping in. I would be happy if we settle on that! In any case, I really appreciate that it's on the table, even. (I don't know why, I thought the user_id on conversation_metadata seemed there to stay. 😅) The initial refactoring... thinky spin For migrations or lower level ORM/SQL, idk, how much is the agent able to help with those these days?
@nutritious-balloon-65098 Read this thread carefully and the linked gist to see the 3 options proposed here. Then make an issue where you list them all, with ALL the details here and in the gist. It is important to get all details, including the links in Tim's post, include those too in the issue just like they are here.
n
I'm on it! can track my progress here.
Summary of work • Parsed the provided thread and extracted all explicit details about the three options: ◦ Option 1: Considered quicker but “leaks” concerns into core OH; architecturally/maintenance concerning; not preferred vs. 3. ◦ Option 2: Less preferred; Option 3 is “probably better than option 2.” ◦ Option 3 (preferred): ▪︎ Data model: user table, org table, indexes, FKs; ConversationMetadata has user_id but no org_id. ▪︎ Implication: adds a JOIN for queries needing “sharing.” ▪︎ SaaS vs OSS: “sharing” is SaaS-only; still need different implementation paths; propose injector to isolate deployment-specific logic early; heavier initial refactor, better long-term. ▪︎ Membership: users can belong to multiple orgs. Suggest drop FK to org_id in ConversationMetadata and use org_member mapping; Slack-like lifecycle (add/disable, never remove to keep member IDs stable). Multi-org conversations likely not needed, but was noted as possible. • Compiled these into a ready-to-post GitHub issue draft: ◦ Proposed title: “V1 Conversations: storage strategy for conversation metadata and secrets (OSS vs SaaS) — compare Options 1–3” ◦ Body includes: context, detailed bullets for each option, SaaS/OSS split, injector abstraction, JOIN implications, membership modeling, open questions, and next steps. ◦ Included the exact Slack link provided for the gist reference: ▪︎ https://openhands-ai.slack.com/archives/C09FJAZSP9N/p1761342430318279?thread_ts=1761331470.863679&cid=C09FJAZSP9N ◦ Left placeholders to insert the actual gist URL/content and Tim’s links verbatim, per your requirement to include ALL details. Why the issue isn’t created yet • The gist content and Tim’s additional links weren’t available to me. Since your requirement is to include ALL details verbatim (including links), I held off creating the issue to avoid posting an incomplete version. What I need from you • Share the actual gist URL or paste its full content, and provide all links Tim referenced so I can include them verbatim. • Confirm whether you want me to: a. Create the GitHub issue immediately with placeholders for the gist/links, b. Wait until you provide the gist and links, then create the fully detailed issue, or c. Hand you the final text to paste yourself. Task status • Draft prepared and ready to post once the gist and links are supplied. • Blocked only on receiving the gist content and Tim’s links. <sub>View full conversation</sub>
Final summary • Created a comprehensive GitHub issue that lists and contextualizes all three options, includes the full Option 3 gist verbatim, and adds all links exactly as provided. • Incorporated Tim’s links in context: ◦ Option 1 “limit on org_id here”: https://github.com/OpenHands/OpenHands/blob/47776ae2adcf8fb9f5592a0ba79ea0def08ccaac/openhands/app_server/app_conversation/sql_app_conversation_info_service.py#L323 ◦ Option 2 references: ▪︎ secure_select: https://github.com/OpenHands/OpenHands/blob/47776ae2adcf8fb9f5592a0ba79ea0def08ccaac/openhands/app_server/app_conversation/sql_app_conversation_info_service.py#L318 ▪︎ save_app_conversation_info: https://github.com/OpenHands/OpenHands/blob/47776ae2adcf8fb9f5592a0ba79ea0def08ccaac/openhands/app_server/app_conversation/sql_app_conversation_info_service.py#L272 • Added the relevant CamelCase class names from the code for the “types approach” (Option 2) context: AppConversationInfoService, SQLAppConversationInfoService, AppConversationInfoServiceInjector, SQLAppConversationInfoServiceInjector, StoredConversationMetadata, UserContext, AuthUserContext, UserContextInjector, AuthUserContextInjector. • Included the Slack thread link verbatim that references the gist. Issue link • https://github.com/OpenHands/OpenHands/issues/11531 Checklist • Read thread and gist, extracted all details: done • Included gist content (Option 3) verbatim: done • Added Tim’s links in the correct context: done • Found and listed the CamelCase class names for Option 2 context: done • Posted the issue in the OpenHands/OpenHands repo: done Notes • No repository code changes were made; thus no git diff or push was necessary. • If you want me to update the issue (e.g., add more class names or adjust formatting), tell me what to change and I’ll update it. <sub>View full conversation</sub>