HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
The login cookies follow the session, and the probe reads every hr_auth it is sent (#127)
github-actions[bot]0d2fca46dc44
diff --git a/ui/src/app/(app)/layout.tsx b/ui/src/app/(app)/layout.tsxindex b7e310dd..ca4d1204 100644--- a/ui/src/app/(app)/layout.tsx+++ b/ui/src/app/(app)/layout.tsx@@ -7,7 +7,7 @@ import '../revamp.css';import { SkelPage } from '@/components/Skel';import { useEffect, useState } from 'react';import { usePathname, useRouter } from 'next/navigation';-import { isAuthed, hasActiveOrg, getSession, refreshToken } from '@/lib/auth';+import { isAuthed, hasActiveOrg, getSession, refreshToken, reconcileLoginState } from '@/lib/auth';import { WorkspaceProvider } from '@/lib/workspace';import { Shell } from '@/components/revamp/Shell';import { billing } from './billing/lib';@@ -40,6 +40,8 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {// Slide the session TTL on every app load: an active user's token never hard-expires.// A 401 here (token already dead) redirects to /login via handleAuthExpired.void refreshToken();+ // The marketing header's login state follows the session rather than the sign-in moment.+ reconcileLoginState();setReady(true);}, [router]);diff --git a/ui/src/app/api/session/route.ts b/ui/src/app/api/session/route.tsindex 1ea48be5..93a08395 100644--- a/ui/src/app/api/session/route.ts+++ b/ui/src/app/api/session/route.ts@@ -85,27 +85,46 @@ export async function OPTIONS(req: NextRequest) {});}+/** Every hr_auth value the request carries, in the order the browser sent them.+ *+ * During the migration a browser can hold two cookies of this name: the earlier script-set one on+ * the registrable domain and this route's host-only one. Both are sent, `cookies.get` returns one+ * of them, and which one is not ours to choose — a stale domain copy would shadow a good host-only+ * cookie and read as signed out. So try each; the first that verifies is the answer. */+function authTokens(req: NextRequest): string[] {+ const out: string[] = [];+ for (const part of (req.headers.get('cookie') || '').split(';')) {+ const eq = part.indexOf('=');+ if (eq === -1 || part.slice(0, eq).trim() !== COOKIE) continue;+ try {+ const v = decodeURIComponent(part.slice(eq + 1).trim());+ if (v && !out.includes(v)) out.push(v);+ } catch { /* a malformed value is not a session */ }+ }+ return out.slice(0, 2); // two is the migration's worst case; bound the engine calls+}+export async function GET(req: NextRequest) {const origin = req.headers.get('origin');const headers = { ...corsHeaders(origin), 'content-type': 'application/json' };// Self-hosted has no sign-in and no engine to ask, so the answer is always "not signed in" —// the same fail-closed answer this route already gives when the engine can't be reached.- const token = SELF_HOSTED || !ENGINE ? '' : (req.cookies.get(COOKIE)?.value || '');- if (!token) {- return new Response(JSON.stringify({ authed: false }), { status: 200, headers });- }+ const tokens = SELF_HOSTED || !ENGINE ? [] : authTokens(req);+ const signedOut = new Response(JSON.stringify({ authed: false }), { status: 200, headers });+ if (!tokens.length) return signedOut;try {- const who = await verified(token);- if (!who) {- // expired / revoked / invalid → treat as logged out- return new Response(JSON.stringify({ authed: false }), { status: 200, headers });+ for (const token of tokens) {+ const who = await verified(token); // expired / revoked / invalid → try the next+ if (who) {+ return new Response(+ JSON.stringify({ authed: true, name: who.name, dashboardUrl: DASHBOARD_URL }),+ { status: 200, headers },+ );+ }}- return new Response(- JSON.stringify({ authed: true, name: who.name, dashboardUrl: DASHBOARD_URL }),- { status: 200, headers },- );+ return signedOut;} catch {// engine unreachable → fail closed to logged-out (header just shows Sign up, never a token)- return new Response(JSON.stringify({ authed: false }), { status: 200, headers });+ return signedOut;}}diff --git a/ui/src/lib/auth.ts b/ui/src/lib/auth.tsindex ebb5da51..1ef6b2fa 100644--- a/ui/src/lib/auth.ts+++ b/ui/src/lib/auth.ts@@ -88,12 +88,40 @@ function clearLoginHint(): void {document.cookie = `${LEGACY_AUTH_COOKIE}=; Path=/; Max-Age=0${_cookieDomain()}; SameSite=Lax`;}/** The console's own route sets or clears the HttpOnly session cookie the marketing probe reads.- * Best effort: the console never depends on it (its calls carry the bearer from storage). */+ * Best effort: the console never depends on it (its calls carry the bearer from storage).+ * Deduped per tab so the several session writes of one page load (sign-in, org switch, the TTL+ * refresh) cost one request, and only a request that actually succeeded counts as synced. */+let _syncedToken: string | null = null;function syncServerCookie(token: string | null): void {if (typeof window === 'undefined') return;+ if (token !== null && token === _syncedToken) return;void fetch('/api/session', token? { method: 'POST', headers: { authorization: `Bearer ${token}` }, cache: 'no-store' }- : { method: 'DELETE', cache: 'no-store' }).catch(() => { /* the header shows Sign up until the next sign-in */ });+ : { method: 'DELETE', cache: 'no-store' })+ .then((r) => { _syncedToken = r.ok ? token : null; })+ .catch(() => { _syncedToken = null; /* the header shows Sign up until the next write */ });+}++/** Make the login cookies match the session this tab actually holds.+ *+ * The hint and the server cookie are a PROJECTION of the session, not a record of the moment it+ * changed: written only at the sign-in edge they never reach the people already signed in when+ * this ships, and the server cookie's seven days expire under a localStorage session that does+ * not, so a signed-in member would see "Sign up" on the marketing header. Called on app load, so+ * every visit reconciles. Idempotent, and cheap after the first call in a tab.+ *+ * Self-hosted this is inert without a guard of its own: there is no login, the local session+ * carries no token, and an instance that never wrote these cookies has none to clear. */+export function reconcileLoginState(): void {+ if (typeof window === 'undefined') return;+ const token = getSession()?.token;+ if (token) { setLoginHint(); syncServerCookie(token); return; }+ // Signed out: the hint and the server cookie are written together and cleared together, so the+ // JS-visible one answers for both — no request on an anonymous page load that has neither.+ if (document.cookie.includes(`${HINT_COOKIE}=`) || document.cookie.includes(`${LEGACY_AUTH_COOKIE}=`)) {+ clearLoginHint();+ syncServerCookie(null);+ }}function setSession(s: Session): void {