A guest's socket that a facet is asked about outlives the guest's 15 minutes
Jonas Templestein, 2026-11-26 15:23 UTC · a65b6427c2cad76efde1315fdc02bf6f4872ef15 · parent e194fc9
3 files changed
M core/itx/src/person-context.test.ts
@@ -6,11 +6,13 @@ import { PERSON_METHOD_MAX_CHARS } from "./context/facet-public-methods.ts"; import { ADMITS_EVERY_MS, + ADMITTED_GUEST_SOCKET_MS, admissionOf, asAFacetIsTold, asAPersonReads, PersonContextRpcTarget, personItxSession, + socketEndOf, principalOf, readsOf, } from "./person-context.ts"; @@ -859,6 +861,43 @@ path, }); expect(answer).toMatchObject({ status }); +}); + +// A guest's sign-in on an app's host lasts 15 minutes. Its end cut every guest out of a call, +// while the call's own check still admitted them. +test("a guest's socket whose reach a facet is asked about outlives the guest's sign-in, for 4 hours at most", () => { + const now = 1_795_700_000_000; + const signInEndsAt = now + 15 * 60_000; + expect(socketEndOf({ signInEndsAt, admittedGuest: true, now })).toBe( + now + ADMITTED_GUEST_SOCKET_MS, + ); + expect(ADMITTED_GUEST_SOCKET_MS).toBe(4 * 60 * 60_000); + // a member, a person who proved an address, and a guest with no facet named: the sign-in's end + expect(socketEndOf({ signInEndsAt, admittedGuest: false, now })).toBe(signInEndsAt); +}); + +// What ends such a socket is the facet's no: a link that ended, on the next frame. +test("the facet's no ends an admitted guest's socket on its traffic, whatever the sign-in's end", async () => { + let clock = 0; + let live = true; + const { onFrame, gate } = admissionOf({ + facet: "call", + member: false, + ask: async () => live, + now: () => clock, + }); + // 20 minutes of traffic, past the sign-in's 15: still admitted + for (clock = 0; clock <= 20 * 60_000; clock += ADMITS_EVERY_MS) + expect(await onFrame!()).toBeUndefined(); + // the link ends: the next frame after the wait ends the session, and a write is refused + live = false; + clock += ADMITS_EVERY_MS; + expect(await onFrame!()).toBe("your access to this context ended"); + await expect(gate()).rejects.toThrow("your access to this context ended"); + // a no is final: a link that is live again does not bring the socket back + live = true; + clock += ADMITS_EVERY_MS; + expect(await onFrame!()).toBe("your access to this context ended"); }); // Who asked, as every event of theirs then names them (`source.onBehalfOf.principal`).
M core/itx/src/person-context.ts
@@ -72,6 +72,9 @@ /** How often a person's socket asks the named facet whether the person still reaches the * context, at most (`admissionOf`). */ export const ADMITS_EVERY_MS = 5_000; +/** How long a guest's socket lasts at most, when a facet is asked whether the guest still + * reaches the context (`socketEndOf`). */ +export const ADMITTED_GUEST_SOCKET_MS = 4 * 60 * 60_000; const ACCESS_ENDED = "your access to this context ended"; const FACET_NAME = /^[A-Za-z0-9_.-]+$/; // The only `invoke` texts: the seed of a live state, and a facet's state, for the chat's views. @@ -410,7 +413,8 @@ * named the context; it named no caller and handed over no Request. The person is the one the * boundary stamped on the Request this invocation was given, so nothing user code built or * altered is read. As a member's socket (serve-host.ts `itxSession`): a WebSocket upgrade from - * this origin alone, ended when the person's sign-in ends. */ + * this origin alone, ended when the person's sign-in ends; a guest's whose reach a facet is + * asked about lasts longer (`socketEndOf`). */ export async function personItxSession(args: { ctx: ExecutionContext; request: Request; @@ -477,10 +481,13 @@ true, ), }); + const admittedGuest = person.method === "guest" && !!admission.onFrame; return serveSession(ctx, { caller: { principal: null }, - endsAt, - endReason: "the sign-in for this session ended: sign in again", + endsAt: socketEndOf({ signInEndsAt: endsAt, admittedGuest, now: Date.now() }), + endReason: admittedGuest + ? "this socket was open for 4 hours: open the page again" + : "the sign-in for this session ended: sign in again", onFrame: admission.onFrame, root: (context, teardown) => { const reads = context.cd(path); @@ -505,6 +512,27 @@ ); }, }); +} + +/** WHEN A PERSON'S SOCKET ENDS AT THE LATEST. A sign-in's end ends the socket. One case differs: + * a GUEST whose reach a facet is asked about (`admissionOf`: the app's answer named `admits`). + * A guest's sign-in on an app's host lasts 15 minutes and is renewed only by a page load + * (core/auth-worker/src/guest-sign-in.ts), so its end cut every guest out of a call four times + * an hour, while the call's own check said that the guest was still in. For such a socket the + * facet's answer is what ends it (asked on the socket's traffic at most every `ADMITS_EVERY_MS`, + * and a session with no traffic is probed, which is traffic): a link that ends, ends the socket. + * The sign-in's renewal is not asked while the socket is open. So a guest whom an owner blocks + * comes in nowhere again, as before, but keeps a socket that is open until the facet says no: + * what takes a guest out of an open socket at once is the app's own act (a link's end). The + * bound is 4 hours, as long as a member's relay credentials last in a call. + * A member, a person who proved an address, and a guest's socket with no facet named end with + * the sign-in, as before. */ +export function socketEndOf(args: { + signInEndsAt: number; + admittedGuest: boolean; + now: number; +}): number { + return args.admittedGuest ? args.now + ADMITTED_GUEST_SOCKET_MS : args.signInEndsAt; } /** ADMITS: whether a person who is no member still reaches the context, by the facet the app's
M core/lib/src/sdk/auth.ts
@@ -214,7 +214,11 @@ * person still reaches it. For a person who is no member, the platform asks it before each * write and at most once every 5 seconds of the socket's traffic, and a `false` or a throw * ends the socket: a guest whose link ended is out of the context, not only of a call. A - * member is never asked. */ + * member is never asked. A GUEST'S socket with `admits` does not end with the guest's 15 + * minutes on your host: the facet's answer ends it, and 4 hours at the latest. So a guest stays + * in a call while your facet admits them, and your `admits()` is the whole check for an open + * socket: a guest whom an owner blocks at the sign-in comes in nowhere again, and is out of + * an open socket when your facet says no. */ /** AN MCP SERVER OF THIS APP, SERVED BY THE PLATFORM (./mcp.ts). Call it in `fetch` for the * app's host, before the app's own paths: it answers for `/mcp` and for the document that * tells a client where to sign in, and null for every other path. `target` names the method