Skip to content

feat(auth,web): auto-seed founderInboxOwner from authenticated session founder - #232

Merged
nullStack65 merged 2 commits into
release/native-0.1.10from
feat/auto-seed-founder-inbox
Nov 26, 2026
Merged

nullStack65 merged 2 commits into
release/native-0.1.10from
feat/auto-seed-founder-inbox

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Summary

Follow-up to #231 so fresh mobile browsers authenticated via Cloudflare Access (or any founder-bound session) immediately get the right My Bots / Others / Closura sidebar split on first load without opening Settings.

Changes

  1. packages/contracts/src/auth.ts: adds optional founder: Schema.optionalKey(Founder) to AuthSessionState.
  2. apps/server/src/auth/SessionStore.ts, EnvironmentAuth.ts, CloudflareAccessAuth.ts, http.ts:
    • Propagates row.value.founder onto VerifiedSession → AuthenticatedSession → AuthSessionState on GET /api/auth/session (both existing sessions and freshly auto-minted Cloudflare Access sessions).
  3. apps/web/src/state/founderSessionSeed.tsx + apps/web/src/routes/__root.tsx:
    • Adds <AutoSeedFounderInboxOwner />: when clientSettings.founderInboxOwner === undefined and an authenticated environment session carries founder, calls updateClientSettings({ founderInboxOwner: sessionFounder }) once.
    • Never overwrites an already-configured founderInboxOwner.

Verification

  • pnpm exec vp fmt on all edited files: pass
  • pnpm exec effect-tsgo tsrs -p apps/server/tsconfig.json --noEmit: 0 errors
  • pnpm exec effect-tsgo tsrs -p apps/web/tsconfig.json --noEmit: 0 errors in touched files
  • pnpm --dir apps/server exec vp test run src/auth/CloudflareAccessAuth.test.ts: 5/5 passed

Deploy: fleet

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nullStack65

Copy link
Copy Markdown
Owner Author

Independent full review (Claude family; author was Gemini) of #232 at 53d3071654. Typecheck (effect-tsgo, contracts and server clean; web errors only in untouched test files Sidebar.logic.test.ts and botOrgTree.test.ts), vp lint on all 7 touched files (clean, Node 26.13.1), and 5 auth test files (70/70 pass) were run in a detached worktree.

Server propagation is correct: founder reaches /api/auth/session for existing sessions (row founder via SessionStore.verify, both token paths, through AuthenticatedSession into getSessionState) and for freshly auto-minted Cloudflare Access sessions (http.ts), and is omitted when unauthenticated or when the row has no founder. WorkOS sessions get it through the stored row, since WorkOS does not auto-mint on this route. The web seed runs only when founderInboxOwner is unset, cannot loop (the effect no-ops once the value is set), and does not conflict with the My Bots / Others / Closura grouping from #231, which reads the same setting. One important finding (hydration race) and two nits below.

{
  "reviewed_base": "b1827643e0301a6da4178d2dcd14afca1990927f",
  "reviewed_head": "53d307165483ab8e0bf997e858c4ae810dc2a2ca",
  "reviewer": "Claude Sonnet 5.5, Claude Code",
  "author_session": "t3-thread:6a6b870263499e5c3c4ceec5efb20d31b46884a74e0c45beedb1a4cddb9ac991",
  "reviewer_session": "claude-sonnet-5-5-review-pr232-20261126-a",
  "fresh_context": true,
  "review_kind": "full",
  "round_id": "claude-sonnet-5-5-review-pr232-20261126-a",
  "intent": [
    "GET /api/auth/session returns founder for existing sessions and freshly auto-minted Cloudflare Access sessions, omitted when unauthenticated or non-founder",
    "AutoSeedFounderInboxOwner seeds founderInboxOwner only when unset and never overwrites an explicit choice",
    "No render loop; vp lint clean; compatible with the My Bots / Others / Closura grouping (#231)"
  ],
  "prior_findings": [],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "summary": "The seed effect does not wait for client settings hydration, so it can overwrite a persisted explicit founderInboxOwner.",
      "outcome": "open",
      "file": "apps/web/src/state/founderSessionSeed.tsx",
      "line": 33,
      "check": "Read useSettings.ts: before hydration getClientSettingsSnapshot() is DEFAULT_CLIENT_SETTINGS, so founderInboxOwner reads undefined. If the session state resolves before hydrateClientSettings() finishes, updateClientSettings -> persistClientSettingsPatch defers the patch, and after hydration applies {...persisted, ...patch} unconditionally, replacing the saved choice. Sibling code (knownEnvironments.tsx:107, ChatView.tsx:657) gates on useClientSettingsHydrated(). Fix: return early unless useClientSettingsHydrated() is true and add it to the effect deps."
    },
    {
      "id": "F2",
      "severity": "nit",
      "summary": "No tests cover the new server propagation or the seeding behavior.",
      "outcome": "open",
      "file": "apps/server/src/auth/CloudflareAccessAuth.ts",
      "line": 201,
      "check": "The PR touches no test files. AGENTS.md asks backend behavior changes to ship with focused tests; CloudflareAccessAuth.test.ts could assert minted.founder, and EnvironmentAuth/http tests could assert founder in getSessionState."
    },
    {
      "id": "F3",
      "severity": "nit",
      "summary": "The seed takes the first authenticated environment's founder in list order, not the primary environment's.",
      "outcome": "open",
      "file": "apps/web/src/state/founderSessionSeed.tsx",
      "line": 24,
      "check": "The loop over environmentSessionStatesAtom breaks on the first session with a founder. A linked remote environment paired under a different founder could seed this device. Prefer the primary environment's session, or document that any connected environment is acceptable."
    }
  ]
}

…, prefer primary env, assert founder in auth test
@nullStack65

Copy link
Copy Markdown
Owner Author

Focused re-check (Claude family; author was Gemini) of #232 at e6c38ca844, covering 53d3071654..e6c38ca844. It follows up findings F1–F3 from the earlier full review (#issuecomment-7188060445). I ran the checks below in a detached worktree on Node 26.13.1.

  • vp lint on founderSessionSeed.tsx and CloudflareAccessAuth.test.ts is clean, exit 0.
  • vp test run src/auth/CloudflareAccessAuth.test.ts in apps/server passes, 5/5.
  • effect-tsgo tsrs --noEmit on apps/server reports 0 errors. The only output is suggestions, such as schemaClassMissingBrand, none in changed lines.

F1 is confirmed fixed. AutoSeedFounderInboxOwner now reads useClientSettingsHydrated() and returns early unless hydrated is true. hydrated is in the effect deps, so the seed re-runs once hydration reaches "ready". A persisted founderInboxOwner can no longer be overwritten by a pre-hydration undefined.

F2 (tests) is fixed. CloudflareAccessAuth.test.ts asserts founder === "kameron" on the initial CF Access auto-mint response and on the cookie-authenticated GET /api/auth/session response.

F3 (prefer the primary environment) is not effectively fixed. The new check identities[i]?.environmentId === PRIMARY_LOCAL_ENVIRONMENT_ID can never match. PRIMARY_LOCAL_ENVIRONMENT_ID is the literal "primary", used only as the registration cache key in platform.ts and for desktop bootstrap ids. identitiesAtom yields the catalog's environmentId, which for the primary environment is descriptor.environmentId (platform.ts:464). That is the server's persisted UUIDv4 (ServerEnvironment.ts). In practice the loop still falls through to sessionFounder ??= …, which is the same first-authenticated-in-list-order behavior that F3 flagged.

Options for F3: (a) drop the dead branch and document that any authenticated environment may seed, or (b) identify the primary environment through a real signal, such as the primary connection target or catalog entry kind, instead of comparing to "primary". This is a nit and does not touch F1's correctness.

{
  "reviewed_base": "b1827643e0301a6da4178d2dcd14afca1990927f",
  "reviewed_head": "e6c38ca8449dd09a2b76ec8b6504a50536f9e1b9",
  "reviewer": "Claude Sonnet 5.5, Claude Code",
  "author_session": "t3-thread:6a6b870263499e5c3c4ceec5efb20d31b46884a74e0c45beedb1a4cddb9ac991",
  "reviewer_session": "claude-sonnet-5-5-recheck-pr232-20261126-b7f3",
  "fresh_context": true,
  "review_kind": "focused_recheck",
  "round_id": "claude-sonnet-5-5-review-pr232-20261126-a",
  "intent": [
    "Auto-seed founderInboxOwner after settings hydration preferring primary environment + CF Access founder test coverage"
  ],
  "prior_findings": ["F1", "F2", "F3"],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "summary": "The seed effect now waits for client settings hydration, so a persisted explicit founderInboxOwner is not overwritten.",
      "outcome": "confirmed",
      "rechecked_head": "e6c38ca8449dd09a2b76ec8b6504a50536f9e1b9",
      "file": "apps/web/src/state/founderSessionSeed.tsx",
      "line": 41,
      "check": "useClientSettingsHydrated() (status === 'ready') is read at line 21; the effect returns early on !hydrated and lists hydrated in deps, so it re-runs after hydration."
    },
    {
      "id": "F2",
      "severity": "nit",
      "summary": "CloudflareAccessAuth.test.ts now asserts founder === 'kameron' on both the initial CF Access auto-mint and the cookie-authenticated GET /api/auth/session.",
      "outcome": "fixed",
      "rechecked_head": "e6c38ca8449dd09a2b76ec8b6504a50536f9e1b9",
      "file": "apps/server/src/auth/CloudflareAccessAuth.test.ts",
      "line": 288,
      "check": "Assertions at lines 288 and 317; vp test run src/auth/CloudflareAccessAuth.test.ts passes 5/5."
    },
    {
      "id": "F3",
      "severity": "nit",
      "summary": "The primary-environment preference never takes effect: identities' environmentId is the server's UUID descriptor id, never the literal 'primary', so selection still falls back to first authenticated environment in list order.",
      "outcome": "open",
      "rechecked_head": "e6c38ca8449dd09a2b76ec8b6504a50536f9e1b9",
      "file": "apps/web/src/state/founderSessionSeed.tsx",
      "line": 33,
      "check": "PRIMARY_LOCAL_ENVIRONMENT_ID === 'primary' (contracts/ipc.ts:383) is the registration cache key and desktop bootstrap id; identitiesAtom (client-runtime presentation.ts:251) maps catalog keys, and the primary entry's environmentId is descriptor.environmentId (platform.ts:464), a UUIDv4 from ServerEnvironment. The comparison cannot match; either remove the dead branch and document any-authenticated-env semantics, or detect the primary environment via a real signal."
    }
  ]
}

@nullStack65
nullStack65 merged commit caf9ebe into release/native-0.1.10 Nov 26, 2026
7 of 10 checks passed
@nullStack65
nullStack65 deleted the feat/auto-seed-founder-inbox branch November 26, 2026 11:15
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