Skip to content

Workspaces phase 2d: logs and operations keep to the workspace (#277) - #319

Merged
antiv merged 1 commit into
mainfrom
workspaces-phase-2d
Nov 2, 2026
Merged

antiv merged 1 commit into
mainfrom
workspaces-phase-2d

Conversation

@antiv

@antiv antiv commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Phase 2d of #277 (documents/design/2.0-plan.md). Logs and operations now read and write only the request's workspace. With one workspace the behaviour doesn't change, apart from what is listed below.

What is scoped

  • Logs and figures.
    • The Usage page and Overview, /stats and /usage/logs.
    • The guardrail and audit logs, with the audit export.
    • Rated answers in the satisfaction panel.
  • Sessions. A session belongs to the workspace of its app_name, the root agent. Detail and delete answer 404 for another workspace's session.
  • Traces, the replay picker and replays. A trace belongs to a workspace when every agent its spans name is one of that workspace's agents. A trace that names no agent belongs to the default workspace.
  • Rate limits.
    • Configs are looked up by scope, scope id and workspace, so a user has one limit in each workspace, counted against their usage there.
    • The request check takes the configs of the agent's workspace.
    • Agent and project scopes may name only the workspace's agents and projects.
    • upsert_config sets only an allowlist of fields.
  • Alert rules.
    • CRUD and test keep to the rule's workspace.
    • Every measurement reads only that workspace, so global means the workspace's agents.
    • update_rule sets only an allowlist of fields.
  • Triggers, widget keys and Slack integrations.
    • Lists show the workspace's rows only.
    • A route naming another workspace's row answers 404.
    • Create and edit take only agents and projects of the workspace.
  • Feedback. Ratings are given and read for the workspace's agents only.
  • Personal access tokens. Create writes ctx.workspace_id. List and revoke cover the current workspace's tokens only.
  • V047: UNIQUE (team_id) on channel_integrations.
    • An inbound Slack event names only its team. With two rows for one team, the first row answered every event, whichever workspace it belonged to.
    • Creating or editing an integration onto a taken team answers 409 and doesn't say whose the team is.
  • Audit entries. Entries about widget keys, template imports and syncs, and memory block restores now carry their project. PAT entries carry their workspace.

A log row with no workspace counts as the default workspace's (workspaces.rows_of and in_projects_of). That covers an agent with no config, an installation-wide audit entry, and a row the backfill hasn't reached yet. So a 1.x installation still sees all of its rows: locally, the audit log lists 371 of 371 entries, 246 of which have no workspace.

NOT_YET_SCOPED is empty, so it is removed from test_cross_workspace.py. BODIES_NAMING_B gains eight writes. The new TestLogsAndOperations checks that:

  • each workspace sees its own rows on every list and page;
  • sessions and traces stay in their workspace;
  • a user budget counts the user in one workspace and doesn't apply in another;
  • alert rules measure their own workspace;
  • a Slack team connects to one integration only;
  • a token acts in the workspace it was created in.

Behaviour changes with one workspace

  • V047 fails if two integrations share a Slack team id, an inactive one included. The server logs the failure, starts without the index and retries on the next start. Before upgrading, run the query from the migration file on production:
    SELECT team_id, COUNT(*) FROM channel_integrations
    WHERE team_id IS NOT NULL GROUP BY team_id HAVING COUNT(*) > 1;
  • Creating an integration with a taken team id answers 409. Before, the second row was stored and never answered.
  • Unknown ids in these routes answer 404 where they used to answer 500:
    • PUT /widget-keys/{id} and DELETE /widget-keys/{id};
    • POST /triggers with a project that doesn't exist;
    • POST /alert-rules/{id}/test.
  • DELETE /sessions answers 404 for a session it can't find. Before, it tried the delete anyway, and still answered 404.

Verification

  • Tests. The full suite passes (1799 tests). test_client_contract.py is unchanged.
  • Mutation check. I removed each of the 35 new checks one at a time; the cross-workspace test fails for every one.
  • Local server.
    • V047 applies.
    • Every page and API route of 2d answers 200.
    • Totals are unchanged.
    • X-MATE-Workspace: 2 answers 404.

Docs

  • python scripts/gen_docs.py was rerun: the API reference and the database reference (V047).
  • Guides updated:
    • user: rate limits, alerts, Slack, personal access tokens, sessions and traces, trace replay, usage and audit, guardrails, widget, triggers;
    • dev: auth and access, alerts, database and migrations, trigger engine.
  • Guides drift lists that still hold:
    • docs/user/agents.md, templates.md, memory-blocks.md, users-and-roles.md and docs/dev/template-format.md match only on dashboard_server.py name patterns. Their behaviour is unchanged; only the audit entries for template import and sync and memory block restore gain a project.
    • docs/user/evals.md: the thumbs-down list is unchanged. Only the Work Room's per-session ratings are filtered.

Next is 2e: enforcing the platform-only list, ctx.is_admin taking in workspace owners and admins, A2A, and the switcher.

The usage figures and pages, the usage, guardrail and audit logs, sessions, traces
and replays, rate limits, alert rules, triggers, widget keys, feedback, personal
access tokens and Slack integrations read and write the request's workspace only. A
route naming another workspace's row answers 404, and a budget, rule, trigger, key or
integration may name only the workspace's agents and projects.

- workspaces.rows_of and in_projects_of filter on a row's workspace or project. A log
  row with no workspace (an agent with no config, an installation-wide audit entry, a
  row the backfill hasn't reached) counts as the default workspace's, so a 1.x
  installation sees all its rows.
- A session belongs to the workspace of its app_name; a trace to the workspace of
  every agent its spans name.
- rate_limit_config is looked up by scope, scope id and workspace, so a user has a
  limit in each workspace, counted on their usage there. Alert rules measure their
  own workspace; global means its agents. update_rule and upsert_config set only an
  allowlist of fields.
- V047: UNIQUE (team_id) on channel_integrations, since a Slack event names only its
  team; a taken team answers 409. The migration fails on duplicates and says how to
  find them.
- Audit entries about widget keys, template imports and syncs and memory block
  restores carry their project, and PAT entries their workspace.

NOT_YET_SCOPED is empty and removed from the cross-workspace test.
@antiv
antiv merged commit 130913f into main Nov 2, 2026
2 checks passed
@antiv
antiv deleted the workspaces-phase-2d branch November 2, 2026 12:14
@antiv antiv mentioned this pull request Nov 3, 2026
22 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant