Skip to content

feat(api): accept organization ids where a workspace id is expected (M4b step 1) - #7789

Merged
mmabrouk merged 6 commits into
release/v0.125.0from
feat/m4b-workspace-accept
Oct 25, 2026
Merged

mmabrouk merged 6 commits into
release/v0.125.0from
feat/m4b-workspace-accept

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Ships in v0.125.0. #7780 is merged into release/v0.125.0; this PR now targets that branch. Its migration oss000000052 follows oss000000051.

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 reads workspaces by id.

This PR is step 1 ("accept"). The database stops cascading project deletes from workspaces and 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

  • Revision oss000000052 (after 051 of feat(api): new mounts use the organization storage layout (M4b mount step) #7780): drops every foreign key from projects.workspace_id to workspaces (found by definition, not by name) and makes the column nullable. lock_timeout = '2s'. The model drops the unused ProjectDB.workspace relationship.
  • One rule for the answer: a project answers its own workspace_id, else its organization id (legacy_workspace_id). Lists, project responses, tokens and the admin DTO use it.
  • Readers (db_manager.py, memberships DAO) map a workspace id or an organization id inside the same statement:
    • fetch_default_project returns the workspace's own default project, else the organization default (the default-type workspace first).
    • get_project_by_workspace keeps today's order inside a workspace, so every legacy answer stays the same.
    • The project list and the resolver rows return the organization id and name for a project without a workspace.
    • GET /workspaces/ and the OSS GET /organizations/ add one organization-id item for an organization where the user has no workspace row.
  • Writers:
    • create_project accepts the organization id. It uses the default-type workspace, or no workspace when the organization has none.
    • set_default_project on a project without a workspace clears every default of the organization.
    • Admin workspace and organization deletes delete the projects the cascade used to delete. Each is still one statement (a data-modifying CTE).
  • Bearer auth (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 of resolve). It no longer reads workspace_members.
    • No parameters: the oldest workspace membership as today, else the oldest organization. The resolver checks the selected project every time.
    • The state cache keys of the two branches without project_id carry "v": "m4b1", so a success cached by v0.124.0 pods is not reused.
  • Routes:
    • DELETE /projects/{id} and the /access workspace scope accept the organization id.
    • Invitation accept checks that {ws} is {org} or a workspace of {org} before any write.
    • Accepting for a project without a workspace skips the admin email and logs [invitations] admin notice skipped: no workspace.
  • Docs: "Upgrading to 0.125.0" (mount layout, upgrade from 0.124.0, workspace deletes, organization ids) and one api/AGENTS.md bullet for read_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=.

# Case Before After
W1 Bearer ?project_id=P&workspace_id=<another workspace of P's organization> 401 member of P: 200
W2 Bearer ?project_id=P&workspace_id=<P's organization id> 401 member of P: 200
W3 Bearer ?workspace_id=W, resolver member of W's default project, no workspace row in W 401 200
W4 Bearer without parameters, user with no workspace row at all 401 resolver member of the oldest organization's default project: 200
W5 DELETE /projects/{id} with the organization id as context (step-2 data) 404 permission check as before
W6 /access with scope_type=workspace and the organization id denied the caller's own scope
W7 Invite, resend, role and remove routes with the organization id in the path 404/500 checked on the organization's default project
W8 GET /workspaces/, OSS GET /organizations/ for a member without a workspace row no item one organization-id item (a list entry, no access)
N1 Bearer ?workspace_id=W, workspace row in W, not a resolver member of W's default project 200 401
N2 Invitation accept through a {ws} that is not {org} or one of its workspaces accepted 400 "Invitation does not exist."
N3 Bearer without parameters when the selected project is not one the resolver allows (also a workspace with projects but no default) 200 or 401 401 unless the resolver allows it

Known gaps kept for step 2

  • CONTRACT section 1 (the organization is the tenant boundary). A legacy project of organization O1 can sit in a workspace of organization O2. For it, the workspace-only and no-parameter branches still sign the token with O2, as today (no lockout in step 1). Before step 2, every such project is repaired (projects.organization_id wins), and step 2 refuses the shape.
  • get_project_by_workspace (member routes) and fetch_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 covers check_organization_write.

Tests / notes

Run on two local dev stacks (OSS and EE) with the seeded test data, on the release/v0.124.0 tip. Both stacks ran 047 -> 050 -> 051 -> 052 from a 047 copy.

  • Migration gate: 1 warning (drop_constraint), 0 critical, pass. One Alembic head.
  • Lock test on a scratch copy: uncontended 5.7 ms. With a 10 s reader lock held, the revision stops with lock_not_available after 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.
  • Old code (v0.124.0) on the 052 schema: OSS accounts acceptance 111 passed; EE accounts and workspaces 126 passed.
  • Responses unchanged: a snapshot of 247 (OSS) and 245 (EE) requests is byte-identical before and after. It covers project lists, current project, organization and workspace lists and details, roles and permissions, as ApiKey and Bearer with every query variant. The organization-id variants answer the same as the workspace-id variants (77 of 77 per edition).
  • Data written by step 2, on this pod (both editions): log in, list and create projects, open organization details, invite and accept, and list workspaces. Mixed data in a legacy organization works, including the default flag and the step-2 consolidation applied by SQL. Tokens signed with the organization id as workspace_id work. Old cached Bearer states: the workspace-only one is ignored, the project one is still served.
  • EE meters: a normal token increments its existing TRACES_RETRIEVED row. A step-2 token meters under the organization id, as design D7 accepts.
  • Unit and integration: unit OSS 8799, EE 9747 passed (after the no-parameter fix). Integration OSS 536, EE 556. Acceptance OSS 871 (one setup timeout passed on rerun), EE 914.
  • Live QA, /w and /m, OSS and EE: pages load with the organization id and with the workspace id in the URL, members invite and remove work, a /m chat turn works, and the SDK works.

Statement and Redis counts

Pinned in integration/memberships/test_workspace_accept_postgres.py: one whole verify_bearer_token call, real readers, resolver and Redis, with random cache leakage turned off. Each cell is SQL statements per request, today -> after.

Bearer query Fully cold Cold Partly warm Warm
project_id + workspace_id 5 -> 4 3 -> 2 2 -> 1 0 -> 0
project_id 4 -> 4 2 -> 2 1 -> 1 0 -> 0
workspace_id only 5 -> 4 3 -> 2 3 -> 2 0 -> 0
no parameters 5 -> 5 3 -> 3 3 -> 3 0 -> 0
  • Redis commands per state are 16/10/7/2 (project branches) and 12/6/6/2 (the other branches). These are the same cache calls as today: only the key of the branches without project_id gains a field, and read_membership has no cache. A warm request is 2 GETs in every branch.
  • API key: cold 2 SQL and 4 Redis commands, warm 0 SQL and 1 GET, as today.
  • Organization details of an organization without workspace rows take the same 3 statements as today.
  • No new HTTP or cross-service call.

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:

Route (team-editor) ApiKey old ApiKey new Bearer old Bearer new
GET /api/projects/ 12.2 / 19.2 16.0 / 22.5 25.0 / 40.0 20.2 / 26.9
GET /api/projects/current 12.4 / 17.7 13.0 / 18.3 29.1 / 47.3 21.3 / 27.3
POST /api/workflows/query 12.5 / 21.2 12.9 / 17.4 24.6 / 49.5 19.7 / 26.4

The ApiKey path did not change (the only change there is pure Python, legacy_workspace_id), so its GET /projects/ difference is noise. The stress-organization runs show the same picture.

Mixed versions

  • v0.124.0 pods on the 052 schema: they always write a workspace and read rows that all still have one. The only difference: an admin workspace delete served by an old pod during the rollout keeps its projects.
  • Rollback: fine while no step-2 code has written projects without a workspace.

Not tested locally (staging gates)

  • On a staging stage: log in and list projects for a multi-workspace EE organization, through both id forms.
  • Invite and accept from /w.
  • Real production-shaped data for the access-change cases. The counts for W3/W4/W8/N1/N3 run on production read-only and stay in private notes.

Merge note

052 follows 051 (#7780), and 051 follows 050. If M3 (048, 049) merges first, #7780 re-points 051 -> 049, and this PR keeps 052 -> 051. Check one Alembic head after each merge.

Follow-ups

  • The spec text edits for this step (OpenSpec 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.
  • Steps 2 and 3 (switch, contract).

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 13d9298 and 937c46f.

Files selected for processing: 4
  • 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
  • api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Workspace-scoped routes and requests now accept organization IDs. Members without workspace memberships see their organization in workspace listings.
    • Authentication and project selection support projects without an associated workspace, with membership checks on the selected default project.
    • Invitations and project access support organization-owned projects and valid workspaces within the same organization.
  • Bug Fixes
    • Project creation, listing, and deletion handle organizations without workspaces and projects linked to workspaces in other organizations.
    • Deleting a workspace directly in the database no longer deletes its projects; the admin API continues to delete projects.
  • Documentation
    • Added version 0.125.0 upgrade guidance covering deployment considerations, mount paths, workspace deletion, and API compatibility.

Project workspace references can now be null. Organization IDs are supported as workspace scope across project lookup, membership, authentication, invitation, and organization APIs. The change also updates deletion handling, metering scopes, tests, and upgrade notes.

Changes: Workspace-removal compatibility

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: Normal

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
Loading
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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 13.77% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 247 functions across 27 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely summarizes the primary change: accepting organization IDs where workspace IDs are expected.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description directly explains the organization-ID compatibility changes, migration, authentication updates, route behavior, tests, rollout constraints, and documentation changes summa…
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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 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.

Flow OSS EE
/w/<organization id>/p/<project>/apps: apps, project switcher, playground, Settings > Members (invite, remove) pass pass
The same with the legacy workspace id in the URL pass pass
/m: chat list and one turn pass pass
SDK ag.init() and GET /projects/current with the team key pass pass

A fresh login straight on /w shows "None of your organizations accept the authentication method you used" on EE. This is not related to this PR. The classic app keeps only organizations whose flags allow the session's method, and the seed organizations have no such flags. /m logs in normally.

@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: @coderabbitai review

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

📘 Docs preview

Status ✅ Ready
Preview https://pr-7789-agenta-docs-preview.mahmoud-637.workers.dev/docs/
Inspect Actions run
Commit b2997fcd5bfaa3d4b9fbb9cc499c25871122a131

Pages changed in this pull request

This comment updates in place on every push.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

@mmabrouk I will review the PR changes and consider the supplied OSS and EE QA evidence.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Item Value
Status stopped
Commit b2997fcd5bfaa3d4b9fbb9cc499c25871122a131
Manual expiry (UTC) Not granted
CI deadline (UTC) Not granted
Workflow https://github.com/Agenta-AI/agenta/actions/runs/40244726866

PR closed or converted to draft. Environment absence verified; retained storage requires separate provider accounting.

Post /preview as a new comment to request a one-hour preview. Repeating it while active does not extend the hour.
Preview data is disposable. Expiry is enforced by the next successful cleanup sweep, not an exact timer.
Environment deletion stops its compute. Provider-retained storage and permanent services may still be billed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 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_checks assertion or make it effective.

The fixture no longer patches workspace_member_exists, so nothing appends to world.workspace_checks. The assertion world.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. The read_calls assertion already covers the new behavior.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c7eb111 and 7004f3f.

Files selected for processing: 26
  • api/AGENTS.md
  • api/oss/databases/postgres/migrations/core_oss/versions/oss000000052_drop_projects_workspace_cascade.py
  • api/oss/src/apis/fastapi/access/router.py
  • api/oss/src/core/accounts/service.py
  • api/oss/src/core/memberships/service.py
  • api/oss/src/core/memberships/workspaces.py
  • api/oss/src/core/workflows/service.py
  • api/oss/src/dbs/postgres/access/dao.py
  • api/oss/src/dbs/postgres/memberships/dao.py
  • api/oss/src/middlewares/auth.py
  • api/oss/src/models/db_models.py
  • api/oss/src/routers/organization_router.py
  • api/oss/src/routers/projects_router.py
  • api/oss/src/routers/workspace_router.py
  • api/oss/src/services/db_manager.py
  • api/oss/src/services/organization_service.py
  • api/oss/tests/pytest/acceptance/accounts/test_workspace_ids_accept.py
  • api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.py
  • api/oss/tests/pytest/unit/middlewares/test_auth_bearer_membership.py
  • api/oss/tests/pytest/unit/middlewares/test_auth_run_principal.py
  • api/oss/tests/pytest/unit/middlewares/test_auth_workspace_accept.py
  • api/oss/tests/pytest/unit/routers/test_membership_endpoints.py
  • api/oss/tests/pytest/unit/routers/test_projects_router_membership.py
  • api/oss/tests/pytest/unit/routers/test_workspace_ids_accept_routes.py
  • api/oss/tests/pytest/utils/redis_calls.py
  • docs/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.

@mmabrouk
mmabrouk force-pushed the feat/m4b-workspace-accept branch from 7004f3f to c495f52 Compare October 25, 2026 00:38
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: Fixed the nitpick in c495f52c06. The test now asserts that db_manager.workspace_member_exists no longer exists, and the dead stub is removed. @coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

@mmabrouk Thanks for fixing the nitpick in c495f52c06. I will review the new changes.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 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_exists is 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
Commits

Reviewing files that changed from the base of the PR and between 7004f3f and c495f52.

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.

@mmabrouk
mmabrouk force-pushed the feat/m4b-workspace-accept branch from c495f52 to 0d9c759 Compare October 25, 2026 00:44
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: The comment now states the invariant the test protects (membership comes from the resolver only), in 0d9c759d30. @coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

@mmabrouk Thanks for updating the comment in 0d9c759d30 to explain the membership resolver invariant. I will review the new changes.


🧠 Learnings used
Learnt from: CR
Repo: Agenta-AI/agenta PR: 0
File: api/AGENTS.md:0-0
Timestamp: 2026-10-19T11:44:57.685Z
Learning: Applies to api/** : Applicability reference:
AGENTS.md: # Contributor Guide
## Repo map
- `api/` — FastAPI backend (OSS + EE + entrypoints). See `api/AGENTS.md`.

AGENTS.md: # Contributor Guide
## Where conventions live
- API architecture (layering, domains, endpoints, exceptions, DTOs): `api/AGENTS.md`.

AGENTS.md: # Contributor Guide
## Before committing
- API or SDK changes: run `ruff format` then `ruff check --fix` within the SDK or API
  folder (from the repo root: `ruff format` then `ruff check`). Fix all errors before
  committing. Details: `api/AGENTS.md`.

AGENTS.md: # Contributor Guide
## Environment config
- For API configuration, add new environment variables to `api/oss/src/utils/env.py` and
  consume them via the shared `env` object. Do not call `os.getenv(...)` directly for
  application config. Full detail: `api/AGENTS.md`.

Source excerpt:
# API conventions (OSS + EE)

## Code comments

Keep AI-generated in-code comments minimal. Comment only the non-obvious *why* (a subtle invariant, a workaround, a pool/concurrency hazard), never the *what* the code already states. Prefer one terse line over a multi-line block; do not narrate steps, restate the code, or leave TODO-style prose. If a comment is needed to explain *what* a block does, rename or extract instead.
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 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 neighboring read_calls and 401 assertions already fail if it uses the obsolete workspace_member_exists path. Keeping the hasattr assertion couples the test to an unused db_manager attribute and can cause a false failure.

Suggested fix
-    assert not hasattr(auth.db_manager, "workspace_member_exists")

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c495f52 and 0d9c759.

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.

@mmabrouk
mmabrouk force-pushed the feat/m4b-workspace-accept branch from 0d9c759 to 9bb45aa Compare October 25, 2026 00:58
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: CI found two integration tests that assumed seeded data. On a fresh database, test_get_project_by_workspace_keeps_the_legacy_answer had no workspace to check, and test_user_workspace_items_of_legacy_users_equal_today compared the order of rows created at the same instant. The first test now seeds its own shapes, including a workspace without a default. The second compares the same items and checks their created_at order. Fixed in 9bb45aa17b. The product code is unchanged.

@mmabrouk
mmabrouk force-pushed the feat/m4b-workspace-accept branch from 9bb45aa to 13d9298 Compare October 25, 2026 01:10
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: Removed the hasattr assertion and its comment in 13d9298533. The read_membership call check and the 401 assertion cover the path. @coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

@mmabrouk Thanks for the update in 13d9298533. I will review the removal of the hasattr assertion and check the remaining read_membership call check and 401 assertion.


🧠 Learnings used
Learnt from: CR
Repo: Agenta-AI/agenta PR: 0
File: api/AGENTS.md:0-0
Timestamp: 2026-10-19T11:44:57.685Z
Learning: Applies to api/** : Applicability reference:
AGENTS.md: # Contributor Guide
## Repo map
- `api/` — FastAPI backend (OSS + EE + entrypoints). See `api/AGENTS.md`.

AGENTS.md: # Contributor Guide
## Where conventions live
- API architecture (layering, domains, endpoints, exceptions, DTOs): `api/AGENTS.md`.

AGENTS.md: # Contributor Guide
## Before committing
- API or SDK changes: run `ruff format` then `ruff check --fix` within the SDK or API
  folder (from the repo root: `ruff format` then `ruff check`). Fix all errors before
  committing. Details: `api/AGENTS.md`.

AGENTS.md: # Contributor Guide
## Environment config
- For API configuration, add new environment variables to `api/oss/src/utils/env.py` and
  consume them via the shared `env` object. Do not call `os.getenv(...)` directly for
  application config. Full detail: `api/AGENTS.md`.

Source excerpt:
# API conventions (OSS + EE)

## Code comments

Keep AI-generated in-code comments minimal. Comment only the non-obvious *why* (a subtle invariant, a workaround, a pool/concurrency hazard), never the *what* the code already states. Prefer one terse line over a multi-line block; do not narrate steps, restate the code, or leave TODO-style prose. If a comment is needed to explain *what* a block does, rename or extract instead.
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0d9c759 and 13d9298.

Files selected for processing: 2
  • api/oss/tests/pytest/integration/memberships/test_workspace_accept_postgres.py
  • 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; 4 remain after this review.

@mmabrouk
mmabrouk force-pushed the feat/m4b-workspace-accept branch from 13d9298 to 41a60a0 Compare October 25, 2026 01:20
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: Added one EE fix in 937c46fddc, "fix(api): read meter rows that have no workspace (EE)".

Why. Step 2 writes and re-keys TRACES_RETRIEVED rows with no workspace. The usage report of a step-1 pod built a MeterScope from each row, refused those rows ("project_id requires workspace_id"), logged and skipped them, and never synced them. During a step-2 rollout or a rollback, that can stall the Stripe report run.

Change. MeterScope now requires the organization for a project ("project_id requires organization_id"), not a workspace. A workspace still requires the organization. compute_meter_id already omits missing parts, so such a row gets exactly the id step 2 gives it. Every existing id is unchanged.

Tests. The new ee/tests/pytest/unit/test_meter_scope_switch_rows.py failed before the change and passes after it. It covers four cases:

  • the scope without a workspace is valid;
  • the id equals a frozen copy of the step-2 canonical string;
  • an existing id with a workspace is unchanged;
  • the DAO conversion of such a row keeps its stored id.

One assertion in test_compute_meter_id.py was turned the other way. EE unit layer: 9754 passed. The accept suite (integration, acceptance, middleware and router units) passed on OSS and EE: 181 passed each.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: Rebased with the stack onto release/v0.125.0 (444ee6b, with M3 #7791). New head: b2997fc. The base stays feat/m4b-mount-step (85f02c2). Merge this after #7780.

  • oss000000052 still revises oss000000051, so the chain has one head: 047 -> 050 -> 048 -> 049 -> 051 -> 052. core_ee is unchanged.
  • The rebase was clean, with no conflicted commits and no content change in this lane.
  • Chain run on stack B from restored 047 copies, OSS and EE: rc 0. 051 -> 052 took about 20 to 50 ms.
  • The accept suite, the count tests, and the memberships, migrations, sharing and sessions integration tests pass in both editions.

@mmabrouk
mmabrouk changed the base branch from feat/m4b-mount-step to release/v0.125.0 October 25, 2026 23:50
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: Base changed to release/v0.125.0 after #7780 merged (71991e5). No rebase was needed: GitHub reports the PR as mergeable, with its own 6 commits and 29 files. Head b2997fc. Migration chain on the release branch: 049 -> 051 (from #7780) -> 052 (this PR).

@mmabrouk
mmabrouk merged commit a2cc36a into release/v0.125.0 Oct 25, 2026
77 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant