Read workspace name and disabled state in one query on the invitation page

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, postgresql, python

Research direction

Start with server/orcaster_server/workspaces/seam.py and the two queries in server/orcaster_server/workspaces/service.py; trace how describe_invitation handles disabled, missing, and enabled workspaces. Add a deterministic test for the interleaving and check query counts, alias and uppercase UUID forms, and the invitation mint path in server/orcaster_server/api/admin_ui.py. Done when one read supplies both fields, existing behaviors pass, and the changelog has an Unreleased entry.

Written by the indexing model from the issue text.

Description

bug P3 server

Problem

The invitation page decides whether it may name a workspace and then reads the name, in two separate queries.

describe_invitation calls is_workspace_disabled (server/orcaster_server/workspaces/seam.py:70) and then get_workspace_name (server/orcaster_server/workspaces/seam.py:83). The two queries are server/orcaster_server/workspaces/service.py:147 and server/orcaster_server/workspaces/service.py:128.

The engine does not set an isolation level (server/orcaster_server/db.py:23), so PostgreSQL uses READ COMMITTED and each query sees its own snapshot. If a workspace is disabled and renamed in one commit between the two queries, the page withholds nothing and prints the new name of a workspace that is already disabled.

The window is a few milliseconds and needs two concurrent changes. The exposure is small, but the check and the value it protects should come from the same read. A valid page view also runs two queries where one is enough.

Steps to reproduce

  1. Create a valid invitation for an enabled workspace.
  2. Wrap is_workspace_disabled in a test so that, right after it returns, another session commits one transaction that sets disabled_at and changes name.
  3. Render the invitation page.
  4. The page answers 200 and shows the new name, although the workspace is disabled at that point.

Proposed change

  • Add one service function that parses the id once and reads name and disabled_at in one statement. It returns nothing when the workspace does not exist or the id is not usable.
  • describe_invitation calls it once. A disabled row gives INVITATION_WITHHELD. An enabled row gives the usual description. A missing row keeps today's behavior (warning, None).
  • Keep get_workspace_name for the invitation mint (server/orcaster_server/api/admin_ui.py:1453).
  • Keep a single UUID parsing rule: make is_workspace_disabled a thin wrapper over the new function, or remove it if nothing else needs it. Note that the two helpers accept different id forms today (server/orcaster_server/workspaces/service.py:136); the permissive form of the disabled check must stay.
  • No change of isolation level or locking.

Acceptance criteria

  • describe_invitation runs one workspace query per call (a test counts statements or spies on the service function).
  • A deterministic test reproduces the interleaving and shows that the page never prints the name of a workspace that is disabled at read time.
  • A disabled workspace gives the withheld text, also when the payload id is an alias form of the UUID. An enabled workspace gives Workspace “<name>” as <role>. A missing workspace and unusable payloads behave as before.
  • Uppercase canonical ids still resolve, and the id parsing rule exists in one place.
  • get_workspace_name still serves the invitation mint and its tests pass.
  • Existing deployments keep working without config or schema changes.
  • CHANGELOG entry under Unreleased.
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.