Phase 13, part 5: each team's jobs, locks, files and sign-ins

Background jobs run for each active team on its own Server and under its
own locks, a few teams at a time and from a different team each round, so
the work is shared between copies of the app and no team holds up another.
Each team's files are under its own prefix, and an OAuth sign-in comes
back only to the team that started it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:26:33 -07:00
co-authored by Claude Opus 5.5
parent 47cc8b2b10
commit af6598271c
16 changed files with 275 additions and 40 deletions
+19 -1
View File
@@ -55,7 +55,7 @@ tools over MCP, approvals, limits and visibility, and the JSON API. Schema
39.
**Phase 13 (multi-tenant) is under way** on branch `phase13`, with a
Postgres schema per team (decided 2026-11-26); parts 1–4 are built.
Postgres schema per team (decided 2026-11-26); parts 1–5 are built.
**Phase 12 (signing in with the Core, OIDC) is set aside for now**
(2026-11-26): before it starts, the user will share the Federated Core's
@@ -2865,6 +2865,24 @@ stand.
briefs' pull requests) send the admin to Settings → Domain; an agent's
SEO change is refused too. Background jobs are part 5.
**Part 5 built 2026-11-26** on `phase13`.
- Connections and secrets were already each team's (part 1: the
`secrets` table is in the team's schema). An OAuth sign-in records the
team it started in, and its callback is refused in any other.
- Background jobs: `jobDo` hands each turn its team's Server. On the
multi-tenant edition it runs the turn for every active team (suspended
and deleting ones wait), each under the team's own lock
(`team:<id>:job:<name>`), so copies of the app share the teams; four
teams at a time in one copy, starting from a different team each round,
so a team with 10,000 pages doesn't hold up another's morning check. The
SEO job skips a team that hasn't proved its domain. Every other lock
(sending email, an audit, an import, a discovery) is the team's too, and
the start-up recoveries run for each team.
- Files: each team's are under `teams/<id>/` in the platform's store
(`storage.Under`, which checks keys before adding the prefix).
- Left for Phase 14, which sets them by plan: limits on outgoing fetches
and storage.
1. **Teams everywhere.**
- Every table that holds a company's data gets `team_id`, and its
unique keys include it. The settings table's key becomes