Repository navigation
Description
Context
Principal { user_id, workspace_id } (crates/thrust-contracts/src/lib.rs:81-86) is what the SessionStore port returns (crates/thrust-ports/src/lib.rs:187-191). authenticate maps a bearer token to it (crates/thrust-core/src/lib.rs:177-183), and authorize checks membership against who.workspace_id (line 165). On the Cloudflare set, sessions live in KV: KvSessionStore (crates/thrust-adapters-cloudflare/src/lib.rs:65-94) on the SESSIONS binding (crates/thrust-worker/wrangler.toml:27-29, wrangler.stage2.toml:33-35), wired at crates/thrust-worker/src/lib.rs:92. The native server keeps sessions in process memory in both modes (docs/src/architecture/infra.md:91-92). A session exists only if /internal/seed created it (crates/thrust-api/src/lib.rs:150-156). The slice's routes carry no workspace segment (crates/thrust-api/src/lib.rs:278-291), and the spike schema has no workspaces or workspace-membership table (crates/thrust-adapters-postgres/migrations/0001_init.sql).
Problem
- A session bound to one workspace cannot serve the stock React app. Plane resolves the workspace from
kwargs["slug"]on every request (apps/api/plane/app/permissions/base.py:28,47,55atoracle/v1-pin-20261018). ItsSessionmodel holdssession_key,user_idanddevice_info, with no workspace (apps/api/plane/db/models/session.py:17). A user can belong to several workspaces and switches between them by URL. - KV is eventually consistent, and the adapter forces a TTL of at least 60 s (
crates/thrust-adapters-cloudflare/src/lib.rs:81-82), so revocation and sign-out-everywhere depend on KV propagation. The accepted design keeps sessions in the database with no cache at P0: ADR-0052 (lines 37, 41), D-003 (DEVIATIONS.md:11). ADR-0082 round 26 already says the spike's KV store "is not the accepted design" (ADR-0082:93). - A native
postgresserver loses every session on restart (docs/src/architecture/infra.md:94). - Every use-case takes
&Principal, so changing the shape is cheap now and expensive after the second feature.
Proposal
Implements ADR-0052, ADR-0082 and ADR-0051 (round-29 notes) and D-003.
Principal { user_id }only.authorizetakes the workspace slug from the route as well as the project, resolves slug to workspace and checks membership in one query, and returns theScopefrom feat(core): makeScopethe argument of every repository andTxmethod #35. This needs aworkspaces (id, slug)table and workspace membership in the slice schema, and a workspace segment in the slice routes. Agree the path with chore(api): move the slice's routes out of the/api/v1prefix; reserve it for wire-compatible routes #47.- Sessions become rows behind the
Databaseport in asessionstable with directory scope (ADR-0041'sscope: tenant|directory, line 42). Store a hash of the token (ADR-0141:26: sessions are "revocable and stored hashed") withuser_id,created_at,expires_at(30 days, ADR-0052),revoked_at, andlast_seen_at, which is updated lazily. The lookup runs before authorization, so it carries no tenant key. - Delete
KvSessionStore, theSESSIONSbinding in bothwrangler*.tomlfiles, and thesessionsfield ofPorts(crates/thrust-core/src/lib.rs:20). Keep the memorySessionStoreonly if the tests still want it, and dropCacheErrorif nothing else uses it. SeedSession(crates/thrust-contracts/src/lib.rs:201-203) seeds rows through the same repository, and the contract fixture (crates/thrust-contract-tests/src/lib.rs:67-68) drops the per-session workspace.- Update
docs/src/flows/app.md:31,42,docs/src/architecture/app.md:82anddocs/src/architecture/infra.md:91-99.
Acceptance criteria
-
Principalhas noworkspace_id, andgrep -rn "KvSessionStore\|SESSIONS" crates/returns nothing. - Contract test
a_session_is_not_bound_to_a_workspace: one token works in both workspaces a user belongs to. Control: the same token gets 404 on a project in a workspace the user does not belong to. - Contract test: after the session row is revoked, the next request is 401 on every target. The revocation goes through a test route under
THRUST_TEST_ROUTESuntil sign-out from spike(auth): the two-day Rust auth slice (argon2id, sessions, CSRF, API keys, one OIDC login) #38 exists. Control: an unrevoked token on the same request gets 200. - No plaintext token column in the migration (ADR-0052 Tests, line 53).
-
cross_tenant_access_is_rejected_and_has_no_effect(crates/thrust-contract-tests/tests/contract.rs:136) andauthenticate_resolves_a_live_session_and_nothing_else(crates/thrust-core/tests/authorize.rs:52) stay green, with the 404/403 split written down for both URL forms, andscripts/mutants.shreports every mutant KILLED. -
scripts/contract-all.shpasses on all four targets, andgateis green.
References
- Review: .agents/plans/contrail/reviews/2026-10-19-fable-architecture-review.md (FR-03)
crates/thrust-contracts/src/lib.rs:81-86,201-203;crates/thrust-ports/src/lib.rs:187-191;crates/thrust-core/src/lib.rs:165,177-183;crates/thrust-adapters-cloudflare/src/lib.rs:65-94;crates/thrust-worker/src/lib.rs:92;crates/thrust-worker/wrangler.toml:27-29- ADR-0052 (
.agents/plans/contrail/adrs/auth/0052-sessions-and-api-keys.md:37,41,53), ADR-0082 (adrs/storage/0082-cache-and-session-port-kv.md:93), ADR-0051, ADR-0041:42, ADR-0141:26; D-003 (.agents/plans/contrail/DEVIATIONS.md:11); spike 0003 step 2 - Plane oracle (
oracle/v1-pin-20261018=ba85d4d3d3):apps/api/plane/app/permissions/base.py:28,47,55,apps/api/plane/db/models/session.py:17 docs/src/flows/app.md:31,42;docs/src/architecture/infra.md:91-99
Blocked by: #35
Finding: FR-03
Activity
Scopethe argument of every repository andTxmethod #35