Classic Mode Routing#
Agenta's frontend runs two coexisting apps: the legacy desktop experience under /w and the simplified mobile-first app under /m. Classic mode is the preference flag that determines which experience a user gets. Routing between /w and /m is driven by three mechanisms working in layers:
- Server-side middleware — reads the
agenta-classic-modecookie on every request. - Client-side hook — mirrors localStorage state to that cookie and performs the first client-side redirect after auth.
/mproxy — handles the reverse trip back to desktop.
The agenta-classic-mode Cookie#
The cookie is the single source of truth for request-time routing. Its values have distinct meanings :
| Cookie value | Meaning |
|---|---|
"1" | Explicit Classic-mode-on (desktop) choice; stay on /w. |
"0" | Simplified mode; redirect to the matching /m route. |
| absent / cleared | Unknown — fall back to device detection heuristic. |
| (not updated) | Profile not yet loaded; leave existing cookie unchanged. |
The distinction between "1" (explicit choice) and absent (device-gate default) matters: a bare Classic-on default must not be written as "1", because the middleware treats "1" as a deliberate preference that overrides the device heuristic .
Preference State & localStorage#
The preference is stored in Jotai atoms backed by localStorage, scoped per user. The key state atoms live in web/packages/agenta-shared/src/state/classicMode.ts :
classicModeEnabledAtom— the final rendered value, inverse ofadvancedNavHiddenAtom.navSimplifiedDefaultAtom— per-user localStorage default, also resolved from account creation date (cutoff: 2026-08-01 UTC: accounts created on or after this date default to simplified mode) .navSimplifiedOverrideAtom— explicit user choice that takes precedence over the default.
Critical: localStorage keys are scoped by activeUserIdAtom (set from user.uid). A mismatch between desktop and /m's user-key lookup was the root cause of cross-device preference confusion, fixed in PR #6642 .
Client-Side Gate (useClassicModeGate.ts)#
useClassicModeGate.ts exports two hooks :
useClassicModeCookieSync— keeps the cookie current whenever userId or preference changes. UsesreadSettledClassicModeCookie(user)which reads user identity directly from localStorage to avoid acting on a pre-hydrationnullatom value.useClassicModeRedirect— for users with Classic mode off on a/wpage: writes the cookie, then callswindow.location.replace(mobileRouteFor(...)). The redirect is one-way (desktop → mobile only);/mexit is handled by the proxy, not a mirror redirect .
These are mounted by ClassicModeGate.tsx, which only enables the redirect after authFlow === "authed" . After PR #6873, ClassicModeGate also passes router.asPath as an effect dependency so the hook re-evaluates on each client-side route change — fixing the case where a post-signin navigation to /w was missed because the hook had already evaluated on the /auth page .
Middleware Route Decision (mobileGate/index.ts)#
web/packages/agenta-shared/src/utils/mobileGate/index.ts contains decideDesktopGate, called from both web/oss/src/middleware.ts and web/ee/src/middleware.ts . Decision priority:
- Device gate (
AGENTA_MOBILE_GATE): if a mobile device is detected, redirect tomapDesktopToMobile(pathname)— works for any route, even those without a/mequivalent (falls back to/m/). - Classic mode gate: if cookie is
"0", callmobileRouteFor(pathname, search)— redirects only when a specific/mroute exists; returnsnullfor desktop-only pages, leaving them in place.
mobileRouteFor maps /w/… paths to /m/… equivalents and returns null for routes /m doesn't support .
The environment flag controlling automatic Classic-mode hops was unified to AGENTA_MOBILE_GATE (removing the separate AGENTA_CLASSIC_MODE_GATE) in PR #6873 .
Known Bugs Fixed#
| Bug | Fix |
|---|---|
/w ↔ /m redirect loop | Removed mobile client mirror redirect; cookie written before location.replace; hydration-safe user-identity read |
| Simplified-mode default treated as explicit choice | Absent/default Classic-on no longer writes "1" cookie |
| Mobile localStorage scoped to wrong user key | /m now reads user.uid as the atom key, matching desktop |
Post-signin redirect skipped on /w | ClassicModeGate re-evaluates on each client-side path change |
Key Files#
| File | Role |
|---|---|
web/packages/agenta-shared/src/state/classicMode.ts | Preference atoms, cohort cutoff, settled-cookie reader |
web/packages/agenta-shared/src/hooks/useClassicModeGate.ts | Cookie sync + client redirect hooks |
web/packages/agenta-shared/src/utils/mobileGate/index.ts | decideDesktopGate, mobileRouteFor, route maps |
web/oss/src/state/onboarding/ClassicModeGate.tsx | Mounts hooks; gates redirect on authFlow and path |
web/oss/src/middleware.ts / web/ee/src/middleware.ts | Calls decideDesktopGate with AGENTA_MOBILE_GATE flag |
web/mobile/src/features/app/ContextSync.tsx | Runs useClassicModeCookieSync on /m; no client redirect |