Skip to content

Personal source connections use canonical account ownership - #883

Merged
zlareb1 merged 19 commits into
mainfrom
feat/connected-account-lifecycle
Nov 18, 2026
Merged

zlareb1 merged 19 commits into
mainfrom
feat/connected-account-lifecycle

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Related: #863, #896

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

Personal document-source connections bind sealed provider credentials to the signed-in account owner. Connected sources recheck that owner, the current connection generation and mirrored permissions before provider access, publication and delivery.

Why

A source credential must not become namespace-wide authority to use another person's connected account. Checking only when a source is registered cannot cover later account replacement, namespace-role loss, disconnect, SCIM removal or a restored backup.

This change introduces one canonical account registry and uses its current owner and generation throughout the connection and source lifecycle. Short account and namespace leases protect the actual publication boundary; remote requests and embedding do not hold those leases. A failed permission or generation check refuses delivery and publication.

Scope and risk

  • Browser-bound consent uses the signed-in human subject, one-use pending state, PKCE where the provider supports it and an HttpOnly cookie. Consent start uses normal token-org cell admission; callback verifies the pending binding and current held placement before consuming state or calling a provider. Delegated callers and service identities cannot connect as a person. Credentials and display email are sealed; neither is returned in source metadata.
  • Connected Drive, Notion and Linear sources use checked credentials at fixed provider destinations. Redirects, incomplete permission listings and traversal outside the registered source scope refuse. A typed credential-owner object is internal and cannot be serialized or copied into a normal client configuration.
  • Source creation and management permit the connected owner with namespace writer standing. The frontend operation map follows those minima while existing shared-source controls continue requiring administrator standing. Shared credentials and another person's source still require namespace administration. Administrator checks of someone else's connection can refresh the owner's credential while checking source standing, but never send a native item request or reveal item existence.
  • Read plans retain the original authorized source and independently indexed document permissions. Revalidation can remove stale evidence but cannot add replacement sources. Global token administrator semantics are unchanged.
  • Disconnect and subject deactivation fence the account generation, retire exact owned source ids and erase account credentials while retaining source history. Canonical-owner deletion through SCIM and restore cleanup also purge historical account and source rows. Successful provider token rotation is retained before a later source or presenter refusal; unknown in-flight rotation fails closed. Root-secret rotation reseals the account registry too.
  • A mandatory typed lifecycle port binds account cleanup at the HTTP and CLI composition roots. An unbound process refuses account cleanup rather than skipping it. Browser routes live in the knowledge application layer.
  • Restore reconciliation clears historical connection authority before held documents can publish. Failure leaves publication held. The configured-deployment maintenance entry requires offline workers, fences historical keys, deletes exact owner history and checks for residue before best-effort remote revocation. Ordinary disconnect still refuses to stop a newer live connection.

The registry is an authentication-control relation keyed by (org, subject, kind), spanning namespaces for one canonical sign-in identity. A memory namespace, agent, end-user or session key would bind the credential to the wrong authority. Architecture and erasure classification record this identity-tuple rationale, canonical-owner cleanup and audit provenance.

This is the personal-account backend. Delegated organization crawl, interactive connection UI/CLI and the complete mirror-content restore procedure remain separate work. Existing mirrored-creation and fleet/session-protection gates remain in force; this PR does not declare a host capability, relax session admission or activate connected sources. Personal-namespace support is not claimed where the current mirrored-source contract refuses it.

Compatibility, rollout and rollback

  • New operations: connection.list and connection.disconnect, scoped to the authenticated caller's own accounts.
  • New routes: authenticated POST /v1/connect/{kind}/start and browser-bound GET /v1/connect/{kind}/callback. OAuth routes are always excluded from automatic HTTP tracing, including before routing.
  • knowledge.source.add accepts credential_mode=shared|connected; its credential defaults to empty for the connected form. Shared registration still requires its credential. Source list/inspect entries add credential_mode, access and a restricted owner_subject projection. Connected owners can add, update, check, remove and request synchronization with writer standing; shared-source administration and credential rotation retain their administrator checks.
  • Migration 111 adds connected_accounts and three source columns with defaults that preserve shared registrations. Connected rows leave the legacy provider kind and credential empty, so older workers cannot mistake a connected registration for shared credentials. No existing migration is edited.
  • Configure each provider's connect_*_client_id and connect_*_client_secret registration before use. Notion additionally requires connect_notion_read_content_only=true only after confirming that registration capability. The existing OAuth request/body bounds still apply.
  • New bounded lifecycle settings: knowledge_connected_stop_timeout_s, knowledge_connected_revoke_timeout_s, knowledge_connected_lease_ttl_s, knowledge_connected_lease_wait_s, knowledge_connected_registry_scan_limit, knowledge_connected_registry_page_size, knowledge_connected_sources_max_per_namespace, knowledge_connected_sources_max_per_person and knowledge_source_acl_max_entries. Defaults and ranges are generated in the configuration reference.
  • Apply migrations before the new build. Keep connected/mirrored creation disabled until the existing fleet and session protections are qualified. No provider registration or live credential is supplied by this change.
  • Before rollback or restored serving, stop writers and complete the documented account and mirror cleanup. loom reconcile --apply performs account cleanup before publication for either restored authority store. ClickHouse-only deployments use the dry run and then python dev/restore_connected_accounts.py --apply against their configured stores. Account cleanup alone does not certify mirror document, chunk, head or original erasure. Reverting code leaves additive schema and stored rows; it does not erase them.

Tests

Only bounded, directly related local checks ran. Their separate receipts are retained; they are not one full-suite or final-head execution claim:

  • Account domain: 12 passed; callback and cleanup boundaries: 24 passed; checked provider access: 23 passed; source authority and publication: 24 passed.
  • Read-plan causal checks first exposed two missing positive paths; the corrected paths and existing negative controls then passed 27 checks.
  • Native source operations and Notion worker controls ran separately. Two role-loss fixtures initially used a global administrator token, which cannot express namespace-role loss under the existing additive policy. Corrected fixtures retain the original authorization policy.
  • Refresh-phase checks exposed lost rotated credentials after a source refusal. The corrected phase boundary passed 20 controls; the separately corrected source-deletion contract passed its one focused check. Reservation cancellation produced two causal failures before six affected controls passed. Five typed repair controls also passed.
  • Real Drive and Linear worker paths passed four checks covering permission pagination, registered scope and final publication refusal after account fencing. External HTTP, stores and embedding are controlled test boundaries.
  • Two real ASGI tracing checks failed before the unconditional route exclusion and passed afterward. They establish the pre-route tracing boundary, not every external proxy or error-log policy.
  • Restore reconciliation produced two causal failures before the same two checks passed. Nine further restore/disconnect controls passed, including orphan/history fencing, residue failure, offline enforcement and the unchanged newer-live-connection refusal.

CI exposed formatting, frontend role-map, package-boundary and closed storage/census companion omissions. The repairs add the missing contracts, regenerate SDK/settings/query-corpus snapshots and preserve the existing assertions. The list/inspect assertion permits the intended credential_mode metadata while recursively rejecting secret fields and a seeded opaque credential value. Cell fixtures seed the real snapshot, cleanup fixtures retain the real implementation, and quota checks use the public error projection. The original removed-mirror name reservation is restored; its unchanged controls caught unintended name reuse.

Named CI diagnostics identify a SCIM SQL fake that rejects required account-inventory reads before the test's synchronization event can be signalled. The unit fixture models those exact empty-inventory queries. The standalone ClickHouse race fixture binds the real account cleanup handler, as the HTTP and CLI composition roots do. All original test functions, assertions and timeouts remain unchanged. No production guard is relaxed.

The corrected head passes all six unit shards, coverage and benchmark checks, four integration shards, isolation gates, both supported Postgres authority jobs, native SDK matrices, frontend checks, mixed-version builds and both Quickstart architectures. All 49 check results are terminal: 47 succeed and two publication checks are skipped; all five applicable workflows succeed. The previously cancelled shard now reports 5,838 passes, including both tests that lacked completion records. The standalone integration shard reports 545 passes. The earlier import-evidence stall remains unexplained; its cancellation is not counted as a pass. Verbose node verdicts and nonterminating thread-stack dumps retain every workload, worker count, random-seed calculation, coverage check and original deadline.

Canonical SDK operations, reach, settings, defaults and documentation were regenerated and checked. The schema was generated from an empty private ClickHouse using all migrations; its only changes are the new registry and additive source columns. Scoped Ruff, mypy, whitespace and public-prose checks passed. The related published route-census correction is composed with the new consent-route classifications, preserving its four assertions. Other main changes are imported without feature changes. The cell-placement, redirect, composition-root, role-map and integration checks ran in hosted CI; they were not run locally because the disk-admission floor was unavailable.

Provider registrations and live provider acceptance remain unrun. Broad suites ran in hosted CI. Fresh independent whole-change source review reports no findings or nits. Merge remains subject to the repository branch rules.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: An agent wrote the change and checked account ownership, authorization, publication, cleanup, restore and generated artifacts against the retained causal evidence.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Required full GitHub CI passes on the current head.
  • SDK operations, reach, settings, defaults, documentation and schema artifacts are regenerated using their canonical generators.
  • The migration is additive and follows the latest migration on the reviewed base.
  • No plugin behavior changed. The frontend role map follows the connected-source operation minima; existing shared-source controls retain administrator requirements.
  • Architecture records the registry identity rationale, erasure boundaries, rolling upgrade and rollback requirements.
  • Public text follows the repository's copy rules.
  • Commits are signed off.

Read provider wait and response caps from the settings catalog so operators can tune them. Preserve the existing defaults and caller deadline, generate the configuration outputs, and verify both overrides at the HTTP boundary.

Signed-off-by: zlareb1 <[email protected]>
…nected-account-lifecycle

Signed-off-by: zlareb1 <[email protected]>

# Conflicts:
#	server/settings/catalog.py
Admit browser consent in the owning cell, reject checked redirects, and bind mandatory account cleanup at HTTP and CLI roots. Keep generated contracts and writer role controls aligned.

Signed-off-by: zlareb1 <[email protected]>
Keep the central table taxonomy and source references aligned with the authentication-owner lifecycle without broadening memory erasure scope.

Signed-off-by: zlareb1 <[email protected]>
A shard can reach its job deadline before pytest prints a failure summary.
Record node verdicts as they arrive and dump thread stacks after five minutes
inside a test without terminating it.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
Direct SCIM integration calls bind real cleanup; the unit store models its exact empty inventory reads.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 0a3cde1 into main Nov 18, 2026
49 checks passed
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