Repository navigation
feat(api): accept organization ids where a workspace id is expected (M4b step 1) - #7789
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Nullable project workspace scope api/oss/databases/postgres/migrations/core_oss/versions/oss000000052_drop_projects_workspace_cascade.py, api/oss/src/models/db_models.py, api/oss/src/core/memberships/*, api/oss/src/dbs/postgres/memberships/dao.py, api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.py |
The migration removes the cascading workspace foreign key and makes projects.workspace_id nullable. Membership queries and project creation support projects without a workspace and resolve organization IDs to an available workspace when possible. |
Project resolution and lifecycle api/oss/src/services/db_manager.py, api/oss/src/dbs/postgres/access/dao.py, api/oss/src/core/accounts/service.py, api/oss/src/core/workflows/service.py, api/oss/src/routers/organization_router.py, api/oss/src/routers/workspace_router.py, api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.py |
Database helpers resolve projects and workspace items from workspace or organization IDs. Organization details can represent an organization as a workspace when it has no workspace rows. Deletion helpers explicitly delete projects before parent rows. |
Authentication and default-project scope api/oss/src/middlewares/auth.py, api/oss/src/core/memberships/service.py, api/oss/tests/pytest/unit/middlewares/*, api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.py, api/oss/tests/pytest/utils/redis_calls.py |
Bearer and API-key authentication derive workspace scope from project and organization IDs. Bearer requests without a project resolve a default project and check project membership. Tests cover scope resolution, membership policies, cache behavior, and database and Redis calls. |
Invitation and route scope api/oss/src/services/organization_service.py, api/oss/src/apis/fastapi/access/router.py, api/oss/src/routers/*, api/oss/tests/pytest/acceptance/accounts/test_workspace_ids_accept.py, api/oss/tests/pytest/unit/routers/*, docs/docs/self-host/upgrade-and-migrate/01-upgrading.mdx |
Routes and invitation acceptance support organization IDs as workspace scope where applicable. Invitation acceptance validates supplied scope against the invited project’s organization and handles projects without workspaces. Upgrade notes describe mount paths, deletion behavior, and API compatibility. |
Workspace-less meter scopes api/ee/src/core/meters/types.py, api/ee/tests/pytest/unit/test_compute_meter_id.py, api/ee/tests/pytest/unit/test_meter_scope_switch_rows.py |
Meter scopes allow projects without a workspace when an organization is present. Tests cover meter ID stability and conversion of workspace-less rows. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Sequence Diagram(s)
sequenceDiagram
participant Request
participant AuthMiddleware
participant DBManager
participant MembershipsService
participant MembershipDAO
Request->>AuthMiddleware: Send request without project_id
AuthMiddleware->>DBManager: Resolve default project
DBManager-->>AuthMiddleware: Return project and scope
AuthMiddleware->>MembershipsService: read_membership(user_id, project_id)
MembershipsService->>MembershipDAO: Read membership under edition policy
MembershipDAO-->>MembershipsService: Return membership result
AuthMiddleware-->>Request: Set authentication state or reject
Merge Risk: 
Minimal · up to 937c4
-
The reported test cleanup issue is fixed. No actionable merge-blocking issue remains in the reviewed changes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The pull request description directly explains the organization-ID compatibility changes, migration, authentication updates, route behavior, tests, rollout constraints, and documentation changes summarized in the changeset.
-
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
|
🤖 The AI agent says: QA evidence for this PR. GitHub's API cannot attach files to a comment, so the MP4 recordings stay on the dev box with the QA notes. Ask and I will share any of them.
A fresh login straight on |
|
🤖 The AI agent says: @coderabbitai review |
📘 Docs preview
Pages changed in this pull request This comment updates in place on every push. |
|
✅ Action performed
|
Railway Preview Environment
PR closed or converted to draft. Environment absence verified; retained storage requires separate provider accounting. Post |
There was a problem hiding this comment.
🧹 Nitpick comments: 1
api/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py: 1
142-142:Trivial · Maintainability & Code Quality · Low value Remove the no-op
workspace_checksassertion or make it effective.The fixture no longer patches
workspace_member_exists, so nothing appends toworld.workspace_checks. The assertionworld.workspace_checks == []therefore always passes. To keep a real guard, patch a stub that raises when it is called. Otherwise, remove the list and the assertion. Theread_callsassertion already covers the new behavior.

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Agenta-AI/agenta
- Branch: feat/m4b-workspace-accept
- File: .coderabbit.yaml
- Commit: 7004f3f
- Layers: Repository YAML (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3f2fa812-b7e2-449f-be0e-a5982ab86bdc
Files selected for processing: 26-
api/AGENTS.mdapi/oss/databases/postgres/migrations/core_oss/versions/oss000000052_drop_projects_workspace_cascade.pyapi/oss/src/apis/fastapi/access/router.pyapi/oss/src/core/accounts/service.pyapi/oss/src/core/memberships/service.pyapi/oss/src/core/memberships/workspaces.pyapi/oss/src/core/workflows/service.pyapi/oss/src/dbs/postgres/access/dao.pyapi/oss/src/dbs/postgres/memberships/dao.pyapi/oss/src/middlewares/auth.pyapi/oss/src/models/db_models.pyapi/oss/src/routers/organization_router.pyapi/oss/src/routers/projects_router.pyapi/oss/src/routers/workspace_router.pyapi/oss/src/services/db_manager.pyapi/oss/src/services/organization_service.pyapi/oss/tests/pytest/acceptance/accounts/test_workspace_ids_accept.pyapi/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.pyapi/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.pyapi/oss/tests/pytest/unit/middlewares/test_auth_run_principal.pyapi/oss/tests/pytest/unit/middlewares/test_auth_workspace_accept.pyapi/oss/tests/pytest/unit/routers/test_membership_endpoints.pyapi/oss/tests/pytest/unit/routers/test_projects_router_membership.pyapi/oss/tests/pytest/unit/routers/test_workspace_ids_accept_routes.pyapi/oss/tests/pytest/utils/redis_calls.pydocs/docs/self-host/upgrade-and-migrate/01-upgrading.mdx
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
-
7004f3f to
c495f52
Compare
|
🤖 The AI agent says: Fixed the nitpick in |
|
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! ✅ Action performed
|
There was a problem hiding this comment.
🧹 Nitpick comments: 1
api/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py: 1
135-135:Trivial · Maintainability & Code Quality · Low value Remove the redundant comment.
The following assertion already shows that
workspace_member_existsis absent. Remove this comment, or replace it with a short explanation of the invariant that the test protects.As per coding guidelines: comments must explain the non-obvious why and must not restate what the code already states.
Proposed cleanup
- # No workspace-row check is left to call. assert not hasattr(auth.db_manager, "workspace_member_exists")Source: Coding guidelines

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Agenta-AI/agenta
- Branch: feat/m4b-workspace-accept
- File: .coderabbit.yaml
- Commit: c495f52
- Layers: Repository YAML (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3cb8cdd6-2c36-4026-8498-190a785d547c
Files selected for processing: 1-
api/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
-
c495f52 to
0d9c759
Compare
|
🤖 The AI agent says: The comment now states the invariant the test protects (membership comes from the resolver only), in |
|
🧠 Learnings used
✅ Action performed
|
There was a problem hiding this comment.
🧹 Nitpick comments: 1
api/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py: 1
136-136:Trivial · Maintainability & Code Quality · Quick win Remove the implementation-detail assertion.
The bearer path delegates to
read_membership. The neighboringread_callsand401assertions already fail if it uses the obsoleteworkspace_member_existspath. Keeping thehasattrassertion couples the test to an unuseddb_managerattribute and can cause a false failure.Suggested fix
- assert not hasattr(auth.db_manager, "workspace_member_exists")

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Agenta-AI/agenta
- Branch: feat/m4b-workspace-accept
- File: .coderabbit.yaml
- Commit: 0d9c759
- Layers: Repository YAML (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
76f73ea8-b144-465f-90e0-1d85f4ebbf1d
Files selected for processing: 1-
api/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
-
0d9c759 to
9bb45aa
Compare
|
🤖 The AI agent says: CI found two integration tests that assumed seeded data. On a fresh database, |
9bb45aa to
13d9298
Compare
|
🤖 The AI agent says: Removed the |
|
🧠 Learnings used
✅ Action performed
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Agenta-AI/agenta
- Branch: feat/m4b-workspace-accept
- File: .coderabbit.yaml
- Commit: 13d9298
- Layers: Repository YAML (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f673a403-aa81-4bbc-ad31-b7f349dc666b
Files selected for processing: 2-
api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.pyapi/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
-
13d9298 to
41a60a0
Compare
|
🤖 The AI agent says: Added one EE fix in Why. Step 2 writes and re-keys Change. Tests. The new
One assertion in @coderabbitai review |
✅ Action performed
|
c7eb111 to
85f02c2
Compare
937c46f to
b2997fc
Compare
|
🤖 The AI agent says: Rebased with the stack onto
|
Context
Workspace removal step 2 will stop writing workspaces: new projects get no
workspace_id, new members get no workspace row, and clients start sending the organization id where they send a workspace id today. Pods of the release before step 2 must already serve that data and accept those ids, or the step-2 rollout breaks logins, project lists and invitations. Today a project cannot even exist without a workspace (foreign key, NOT NULL), and every workspace-taking route readsworkspacesby id.This PR is step 1 ("accept"). The database stops cascading project deletes from
workspacesand allows a project without a workspace. Every place that takes a workspace id also takes the organization id and any workspace id of the same organization. Answers for existing data stay the same.Changes
oss000000052(after051of feat(api): new mounts use the organization storage layout (M4b mount step) #7780): drops every foreign key fromprojects.workspace_idtoworkspaces(found by definition, not by name) and makes the column nullable.lock_timeout = '2s'. The model drops the unusedProjectDB.workspacerelationship.workspace_id, else its organization id (legacy_workspace_id). Lists, project responses, tokens and the admin DTO use it.db_manager.py, memberships DAO) map a workspace id or an organization id inside the same statement:fetch_default_projectreturns the workspace's own default project, else the organization default (thedefault-type workspace first).get_project_by_workspacekeeps today's order inside a workspace, so every legacy answer stays the same.GET /workspaces/and the OSSGET /organizations/add one organization-id item for an organization where the user has no workspace row.create_projectaccepts the organization id. It uses thedefault-type workspace, or no workspace when the organization has none.set_default_projecton a project without a workspace clears every default of the organization.middlewares/auth.py):?project_id=&workspace_id=: the project's own workspace id or its organization id needs no read. Any other workspace must belong to the project's organization, else a cached 401 (as today).?workspace_id=alone: the default project of that workspace or organization, checked by the membership resolver (MembershipsService.read_membership, the uncached form ofresolve). It no longer readsworkspace_members.project_idcarry"v": "m4b1", so a success cached by v0.124.0 pods is not reused.DELETE /projects/{id}and the/accessworkspace scope accept the organization id.{ws}is{org}or a workspace of{org}before any write.[invitations] admin notice skipped: no workspace.api/AGENTS.mdbullet forread_membership.No API model, OpenAPI, web, SDK, env, Helm or Railway change.
Access changes
Every case that goes from refused to allowed is allowed only where M1's resolver already allows the same user the same project through
?project_id=.?project_id=P&workspace_id=<another workspace of P's organization>?project_id=P&workspace_id=<P's organization id>?workspace_id=W, resolver member of W's default project, no workspace row in WDELETE /projects/{id}with the organization id as context (step-2 data)/accesswithscope_type=workspaceand the organization idGET /workspaces/, OSSGET /organizations/for a member without a workspace row?workspace_id=W, workspace row in W, not a resolver member of W's default project{ws}that is not{org}or one of its workspacesKnown gaps kept for step 2
projects.organization_idwins), and step 2 refuses the shape.get_project_by_workspace(member routes) andfetch_default_project(Bearer) answer different projects for a workspace that has projects but no default project. Both stay in the same organization. Step 2 makes them agree, and uses one default-project rule that also coverscheck_organization_write.Tests / notes
Run on two local dev stacks (OSS and EE) with the seeded test data, on the
release/v0.124.0tip. Both stacks ran047 -> 050 -> 051 -> 052from a 047 copy.drop_constraint), 0 critical, pass. One Alembic head.lock_not_availableafter 2.0 s and readers wait at most 1.5 s. With the lock released after 1 s, it finishes in 0.8 s and readers wait at most 0.3 s.workspace_idwork. Old cached Bearer states: the workspace-only one is ignored, the project one is still served.TRACES_RETRIEVEDrow. A step-2 token meters under the organization id, as design D7 accepts./wand/m, OSS and EE: pages load with the organization id and with the workspace id in the URL, members invite and remove work, a/mchat turn works, and the SDK works.Statement and Redis counts
Pinned in
integration/memberships/test_workspace_accept_postgres.py: one wholeverify_bearer_tokencall, real readers, resolver and Redis, with random cache leakage turned off. Each cell is SQL statements per request, today -> after.project_id+workspace_idproject_idworkspace_idonlyproject_idgains a field, andread_membershiphas no cache. A warm request is 2 GETs in every branch.Latency
Interleaved run on EE, alternating old code and new code on the same 052 database, 3 rounds, N=200 each. Medians, p50 / p99 in ms:
GET /api/projects/GET /api/projects/currentPOST /api/workflows/queryThe ApiKey path did not change (the only change there is pure Python,
legacy_workspace_id), so itsGET /projects/difference is noise. The stress-organization runs show the same picture.Mixed versions
Not tested locally (staging gates)
/w.Merge note
052follows051(#7780), and051follows050. If M3 (048,049) merges first, #7780 re-points051 -> 049, and this PR keeps052 -> 051. Check one Alembic head after each merge.Follow-ups
remove-workspaces-org-storage, the M1 resolver requirement, and a new M4b technical design) are prepared separately and land with the conductor's spec update.