Goal: ensure multi-tenant isolation by enforcing workspace_id filtering everywhere it applies.
Workflow:
Identify affected scope
- Ask which feature/agent/API route is in scope if unclear.
- Prefer targeted fixes over repo-wide refactors.
Find candidate queries
- Search for
.from(usage in the relevant area. - Look for missing
.eq("workspace_id", workspaceId)(or equivalent RLS-safe filter).
- Search for
Verify workspace context
- API routes: read
workspaceIdfromreq.nextUrl.searchParams, validate viavalidateUserAndWorkspace. - Agents: use
task.workspace_id(required); do not derive workspace from auth user id. - Server helpers: ensure functions accept
workspaceIdexplicitly rather than importing globals.
- API routes: read
Fix and harden
- Add the required filter.
- Add or update targeted tests for the modified behavior.
Validate
- Run
npm run typecheck. - Run the most targeted tests that cover the change (Vitest/Playwright depending on area).
- Run