A guest socket that a facet is asked about outlives the guest 15 minutes #4
merged guest-call-socket was squashed into main as ac30cfa by jonas, 2026-11-26 15:30 UTC. jonas opened it 2026-11-26 15:23 UTC.
## What A guest socket of `auth.personItx` whose app named `admits` no longer ends with the guest 15-minute sign-in. It ends: - when the named facet says no (asked on the socket traffic at most every 5 s, as before; a no is final): a link that ended; - when an owner blocks the guest: the auth Worker writes `account/person-blocked` (and `person-unblocked`) on the person own context `/users/<id>` too, and the socket reads that log at its open and then at most once a minute of its traffic (`blockWatchOf`). A blocked guest gets no socket, and an open one ends about a minute and a half after the block is in the log, at the latest. Three failed reads in a row end the socket too; - after 4 hours at the latest. Every other person socket ends with the sign-in, as before: a member, a person who proved an address, a guest with no facet named. ## Why A guest sign-in on an app host lasts 15 minutes and is renewed only by a page load. So every guest of a Meet call was cut out four times an hour, with the screen share, while the call still admitted them (26 Nov 2026: a guest signed in at 14:36:52 UTC and dropped out at 14:51:50). Jonas, on the card tasks/fix-meet-guest-disconnects-that-incorrectly-show-access-ended.md of /repos/task-board, 15:07 UTC, to "May I change the platform so that a guest open call socket stays open while the call own check still admits the guest?": "yes!" ## Review /agents/reviewer read it twice. Fixed from its findings: a block ends an open socket; the block check reads what the log says last (no clock compare) and runs at the open; failed reads are bounded; the words about the delay are true now. Left, and said in the code: a block whose fact does not reach the mind (facts are delivered best effort) ends an open socket only by the facet no or the 4 hours; a sure signal needs a way for the mind Worker to ask the auth Worker. ## Checks core/itx 538 tests pass (person-context.test.ts: the end rule, 20 minutes of traffic then a link end, the block watch, a block at the open, failed reads). core/auth-worker 571 pass (a block and its end are on the guest context). Every package type-checks. Not proven on a deployed stack. Session: claude 54816317-8638-4f04-a7ff-dd2e968c9348 on beelink
Conversation
Nobody has said anything yet.
Sign in to comment or to merge.
Files
5 files changed
- M core/auth-worker/src/guest-sign-in.test.ts
- M core/auth-worker/src/members.ts
- M core/itx/src/person-context.test.ts
- M core/itx/src/person-context.ts
- M core/lib/src/sdk/auth.ts
M core/auth-worker/src/guest-sign-in.test.ts
@@ -482,7 +482,13 @@ expect(factsOf(blocked).flatMap((fact) => fact.events.map((event) => event.type))).toEqual([ "events.iterate.com/account/grant-ended", "events.iterate.com/account/person-blocked", + "events.iterate.com/account/person-blocked", ]); + // the block is told on the guest's own context too: an open socket of theirs ends by it + expect(factsOf(blocked).at(-1)).toMatchObject({ + path: `/users/${bob.userId}`, + events: [{ type: "events.iterate.com/account/person-blocked" }], + }); expect(await tokenIdentity(env, token, MEET)).toBeNull(); expect(await tokenIdentity(env, evesToken, MEET)).toMatchObject({ name: "Eve" }); // the cookie earns nothing more, and the form says so with one event on the guest's context @@ -500,7 +506,13 @@ { path: `/users/${bob.userId}`, events: [{ payload: { reason: "blocked" } }] }, ]); - expect(await (await members("unblock", bob.userId)).text()).toContain("is no longer blocked"); + // the block's end is told on the guest's own context too, where the block is + const unblocked = await members("unblock", bob.userId); + expect(await unblocked.text()).toContain("is no longer blocked"); + expect(factsOf(unblocked).at(-1)).toMatchObject({ + path: `/users/${bob.userId}`, + events: [{ type: "events.iterate.com/account/person-unblocked" }], + }); expect(originAndPath(await meet.ask(bob.cookie))).toBe(`${MEET}/.iterate/callback`); });
M core/auth-worker/src/members.ts
@@ -510,6 +510,13 @@ type: "events.iterate.com/account/person-blocked", payload: { email }, }); + // and on the blocked person's own context: a socket of theirs that is open in the mind ends by + // it (core/itx/src/person-context.ts `blockWatchOf`), since no token is asked for again there + if (person) + facts.add(person.id, { + type: "events.iterate.com/account/person-blocked", + payload: { email }, + }); console.info({ event: "auth.person-blocked", by: actor.userId, known: Boolean(person) }); return { facts, @@ -549,6 +556,16 @@ type: "events.iterate.com/account/person-unblocked", payload: { email }, }); + // on the person's own context too, where their block is: what that log says last is whether + // an open socket of theirs ends (core/itx/src/person-context.ts `blockWatchOf`) + const person = await env.DB.prepare("select id from users where email = ?1") + .bind(email) + .first<{ id: string }>(); + if (person) + facts.add(person.id, { + type: "events.iterate.com/account/person-unblocked", + payload: { email }, + }); return { facts, notice: `${email} is no longer blocked.` }; }
M core/itx/src/person-context.test.ts
@@ -6,11 +6,16 @@ import { PERSON_METHOD_MAX_CHARS } from "./context/facet-public-methods.ts"; import { ADMITS_EVERY_MS, + ADMITTED_GUEST_SOCKET_MS, admissionOf, + BLOCK_EVERY_MS, + BLOCK_READ_FAILURES, + blockWatchOf, asAFacetIsTold, asAPersonReads, PersonContextRpcTarget, personItxSession, + socketEndOf, principalOf, readsOf, } from "./person-context.ts"; @@ -859,6 +864,112 @@ 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"); +}); + +// The block, and its end, are on the guest's own context, written by the auth Worker. +const BLOCKED = { type: "events.iterate.com/account/person-blocked" }; +const UNBLOCKED = { type: "events.iterate.com/account/person-unblocked" }; +/** A watch over a log that the test writes, with its clock and the offsets it read from. */ +function blockWatch(log: unknown[]) { + const world = { clock: 1_795_700_000_000, reads: [] as number[], fails: false }; + const watch = blockWatchOf({ + now: () => world.clock, + read: async (afterOffset) => { + world.reads.push(afterOffset); + if (world.fails) throw new Error("no answer"); + return { events: log.slice(afterOffset), scannedThroughOffset: log.length, atHead: true }; + }, + }); + return { world, watch }; +} + +test("an owner's block ends a guest's open socket at the next read, and it is final", async () => { + // at the open: the sign-in, and a block from before that an owner took back + const log: unknown[] = [ + { type: "events.iterate.com/account/guest-signed-in" }, + BLOCKED, + UNBLOCKED, + ]; + const { world, watch } = blockWatch(log); + expect(await watch.blockedNow()).toBe(false); + // frames within the minute read nothing + world.clock += BLOCK_EVERY_MS - 1; + expect(await watch.onFrame()).toBeUndefined(); + expect(world.reads).toEqual([0]); + // an owner blocks the guest: the next read, from where the last one stopped, ends the session + log.push(BLOCKED); + world.clock += 1; + expect(await watch.onFrame()).toBe("your access to this context ended"); + expect(world.reads).toEqual([0, 3]); + // final: an owner who takes the block back does not bring the socket back, and nothing is read + log.push(UNBLOCKED); + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBe("your access to this context ended"); + expect(world.reads).toEqual([0, 3]); +}); + +test("a guest who is blocked at the open gets no socket, whatever the time on the block", async () => { + expect(await blockWatch([BLOCKED]).watch.blockedNow()).toBe(true); + expect(await blockWatch([BLOCKED, UNBLOCKED, BLOCKED]).watch.blockedNow()).toBe(true); + expect(await blockWatch([]).watch.blockedNow()).toBe(false); +}); + +test("reads of the guest's log that fail: one says nothing, three in a row end the session", async () => { + const log: unknown[] = []; + const { world, watch } = blockWatch(log); + world.fails = true; + // the open is not refused for a read that failed (the first of the three) + expect(await watch.blockedNow()).toBe(false); + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBeUndefined(); + // a read that answers starts the count again + world.fails = false; + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBeUndefined(); + world.fails = true; + for (let n = 1; n < BLOCK_READ_FAILURES; n += 1) { + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBeUndefined(); + } + world.clock += BLOCK_EVERY_MS; + expect(await watch.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,15 @@ /** 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; +/** How often such a socket reads whether an owner blocked its guest, at most (`blockWatchOf`). */ +export const BLOCK_EVERY_MS = 60_000; +/** How many reads of the guest's log in a row may fail before the socket ends. */ +export const BLOCK_READ_FAILURES = 3; +const PERSON_BLOCKED = "events.iterate.com/account/person-blocked"; +const PERSON_UNBLOCKED = "events.iterate.com/account/person-unblocked"; 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 +419,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,11 +487,32 @@ true, ), }); + const admittedGuest = person.method === "guest" && !!admission.onFrame; + // the guest's own context, where the auth Worker writes a block of them + const ofThePerson = new IterateContextRpcTarget( + contexts(), + DurableObjectNameCodec.address(`/users/${person.userId}`), + new SessionTeardown(), + (promise) => ctx.waitUntil(promise), + { principal: null }, + ); + const block = blockWatchOf({ + read: (afterOffset) => + ofThePerson.invoke(["itx", "builtins", ["readEvents", afterOffset, 200]]), + }); + // a guest who is blocked gets no such socket, whatever the upgrade's stamp says + if (admittedGuest && (await block.blockedNow())) + return new Response("Your access ended\n", { status: 403 }); + const onFrame = admittedGuest + ? async () => (await admission.onFrame!()) || (await block.onFrame()) + : admission.onFrame; return serveSession(ctx, { caller: { principal: null }, - endsAt, - endReason: "the sign-in for this session ended: sign in again", - onFrame: admission.onFrame, + 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, root: (context, teardown) => { const reads = context.cd(path); // The kernel's own code names the person here, so no signed token is needed, and a redial @@ -505,6 +536,87 @@ ); }, }); +} + +/** 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 the socket itself reads + * whether an owner blocked the guest (`blockWatchOf`): a block ends it about a minute and a + * half later, at the latest. 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; +} + +/** A BLOCK ENDS A GUEST'S OPEN SOCKET. An owner's block ends the guest's tokens at once, and a + * socket that outlives the sign-in asks for no token again. The auth Worker writes a block, and + * its end, on the guest's own context (`/users/<id>`, core/auth-worker/src/members.ts), and + * `read` reads that log from an offset on. Whether the guest is blocked is what the log says + * last: no clock is compared. + * - `blockedNow` reads the log at the open: a guest who is blocked gets no socket, also when the + * upgrade was stamped a moment before the block. + * - `onFrame` reads on the socket's traffic, at most every `BLOCK_EVERY_MS`. A socket has a frame + * every 30 to 40 s or is ended (./end-when-silent.ts), so a block ends the session about a + * minute and a half after it is in the log, at the latest. It is final. + * - A read that fails says nothing; `BLOCK_READ_FAILURES` of them in a row end the session, so + * a guest whose block cannot be read is not kept. The guest's page opens a socket again, and + * the sign-in refuses a blocked guest there. + * What this cannot see: a block whose fact never reached the mind (the auth Worker's facts are + * delivered best effort, iterate/facts). Such a guest's socket ends by the facet's no or the + * socket's own bound (`socketEndOf`), and they come in nowhere again. */ +export function blockWatchOf(args: { + read: (afterOffset: number) => Promise<unknown>; + now?: () => number; +}) { + const now = args.now || Date.now; + const Page = z.object({ + events: z.array(z.object({ type: z.string() }).loose()), + scannedThroughOffset: z.number(), + atHead: z.boolean(), + }); + let after = 0; + let askedAt = 0; + let blocked = false; + let failures = 0; + let ended = false; + const look = async () => { + askedAt = now(); + // at most 10 pages a look: a log longer than that is read on at the next one + for (let pages = 0; pages < 10; pages += 1) { + const page = Page.safeParse(await args.read(after).catch(() => null)); + if (!page.success) return void (failures += 1); + for (const event of page.data.events) { + if (event.type === PERSON_BLOCKED) blocked = true; + else if (event.type === PERSON_UNBLOCKED) blocked = false; + } + after = Math.max(after, page.data.scannedThroughOffset); + if (page.data.atHead) return void (failures = 0); + } + }; + return { + blockedNow: async () => { + await look(); + return blocked; + }, + onFrame: async () => { + if (!ended && now() - askedAt >= BLOCK_EVERY_MS) { + await look(); + ended = blocked || failures >= BLOCK_READ_FAILURES; + } + if (ended) return ACCESS_ENDED; + }, + }; } /** 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, but for a block: a guest whom an owner blocks is out of an open socket about a + * minute and a half later, and comes in nowhere again. */ /** 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