docsOperate

Access codes -- open part of a deployable only to people who hold a code

A hosted site is public. The edge answers any hostname it can resolve to a live deployable and hands the bytes of its bundle to whoever asks. An access code is how a deployable keeps part of itself back: data and actions its own DSL declares, which open only for a visitor who types a code an operator gave them.

A code is random (125 bits), shown to the operator once, stored only as a digest, checked by the cluster on every request, and ends on a clock. Replacing one takes everyone using the old one out. Codes are managed in the Deployables app of MemQL OS, and the mechanism is generic: nothing in the engine knows what a deployable's gates mean.

Audience: operators who hand codes out, authors who declare what a code opens, and front-end authors who build the page that takes one.

Related: Deployables · Site hosting · Packages and deployables · Building a pack · Access model

Design record: docs/superpowers/specs/2026-10-29-deployable-access-codes-design.md.


What a code opens, and what it does not

A code opens gated constructs: the queries and mutations in a deployable's own DSL that carry @accessGate for the gate the code was minted for. That is the whole of its reach.

  • It opens the constructs marked @accessGate for its gate, on its own deployable.
  • It does not open any file in the bundle, any other gate, deployable or route, or any MemQL API. A session is no token, no actor and no stream.

Nothing in a public bundle is protected. The edge serves a bundle's bytes to everyone who can resolve the hostname, with a code or without one, and a code does not change that. Put nothing in the bundle that a visitor without a code should not read -- not a document, not a name, not a price. What is private lives in the graph and reaches the page as the answer to a gated call.

Gating a path of static files (a PDF, a video, a demo) is not in this version. A file that must stay private does not belong in the bundle yet.

A visit, start to finish

  1. An operator adds a code for one gate of a deployable, optionally for one subject (one client, say), and gives the plain value to a person. The cluster keeps its SHA-256 and nothing else.
  2. The visitor's page posts the code to /_memql/access on the deployable's own origin. The edge checks the shape of the request, spends a rate-limit token and forwards it, stamped, to the bff.
  3. The bff finds the code by its digest and, if it is live, opens a session: a row in the graph, and an HttpOnly cookie holding a random token whose digest is in that row.
  4. The page calls the constructs its gate declares through /_memql/access/call. Every request that presents a session reads it and its code from the database again. Nothing in the decision is cached.
  5. The visit ends at the earliest of the code's expiry, 24 hours after the session opened, a regenerate, a removal, or the visitor leaving.

A session is honored by exactly one handler, for exactly one site. It authenticates nobody to MemQL.


Handing a code out

In MemQL OS, open Deployables, select a deployable, and choose the lock after Traffic in the page head: Access codes. The control is absent, not disabled, when you do not hold the part, when the deployable is one the cluster manages itself, and when it was not deployed from a package, since only a package's own deployable can declare a gate.

The part is execute on app:deployables/access, seeded on owner and developer like deploy, publish and preview, and checked against the deployable's own organization (access-model.md).

The panel lists the codes in label order. Each row shows the name the operator gave it, what it unlocks (Unlocks engagement for acme), the last four symbols of the code so two can be told apart, when it expires ("Expires in 8 minutes", with the exact time behind it, and "Expired" once past) and when it was last opened ("Last opened 2 minutes ago", or "Not opened yet"). Last opened is the last unlock with the current secret, not the last request: the code's row is written by an operator's act and by nothing else, so a visitor's activity never touches the credential. A removed code is hidden; its row stays in the graph as the record.

Add takes four things:

  • Name -- the operator's label, 1 to 80 characters. A visitor never sees it.
  • Unlocks -- one of the gates the deployable declares. With none declared the panel says so and explains @accessGate, and Add is absent.
  • Subject, optional -- offered only when the chosen gate's constructs read accessSubject. It says whose part of the app the code opens (acme), up to 120 characters.
  • Expires -- 10 minutes, 1 hour, 1 day, 7 days, 30 days, or a date. It must be more than a minute away and no more than 366 days. Every code expires; there is no "never", because the lifetime is the one honest bound on a bearer credential. A long engagement picks a far date and extends it later.

The code appears once. After Add or Regenerate the panel shows it with a copy control and a notice that this is the only time it is shown. It is held in the page's memory alone, and dropped when the next act starts. While it is on screen, or a write is still out, the dialog's Close and Escape wait and Done is the way out, because what the panel holds is the only copy. Lose it and the answer is Regenerate, never recovery: the cluster does not have it. If the connection drops before the cluster answers, the panel cannot know whether the write landed. It says so, closes the form and shows the list, where a code that did land can be regenerated to get a value to copy.

ActWhat it doesWhat stops working
RegenerateReplaces the secret and keeps the code's id, name, gate and subject, so rows a product stamped with the id stay attached across a rotation. Keeps the expiry unless given a new one; a code that has expired needs one.The previous code, at once. Anyone using it is taken out now.
Change expiryMoves when the code stops opening the site, without changing the code. Takes effect on the next request, in either direction: extending an expired code revives it.A shortened expiry takes out sessions already open.
RemoveEnds the code. The row stays, so it still answers who could get in, and when.Every session opened with it, at its next request. Removal is final: a removed code cannot be regenerated or re-timed, and a new code is added instead.

Regenerate and Remove ask in place, under their own row, and say what stops working. If two operators regenerate one code at the same moment, the second is told so rather than replacing the code the first has just been handed.

What Add refuses

Nothing is minted unless every one of these holds, and a refusal says what to change:

  • the deployable has an owner. A call runs under its owner's authority, so a deployable with no owner, or one the cluster manages itself, cannot have codes;
  • it was deployed from a package, and that package declares the gate you chose. A source deployed before access codes existed has no list of the DSL domains it ships, so it declares none until it is deployed again (below);
  • the name, the subject and the expiry are inside the bounds above.

A regenerate or a new expiry on a deployable that has since lost its owner is refused too, since such a code opens nothing. Only removal stays allowed there.

A code is minted by a person

Add and Regenerate refuse inside a run. The plain code exists in the reply and nowhere else, and a run's journal is durable and readable by the cluster, so a pack that regenerates a client's code and emails it would have written it into the journal. All four acts also need a person behind them, because the person is recorded on the code and in the audit event: a synthetic actor, a connector, an anonymous caller and the operator credential are refused. Tooling that holds the operator key can read the list. It cannot end a code; a person signs in and does that.

The acts are DSL builtins, and the panel is a client of them. Called by a person from anywhere else, they pass the same part and the same organization gate, and the reply holds the code: an MCP client or a script acting for that person receives it, and it reaches whatever that client records.

BuiltinReply
siteAccessCodeCreate(siteId, label, gate, subject?, expiresAt){codeId, code, expiresAt} -- code appears here and nowhere else, ever
siteAccessCodeRegenerate(codeId, expiresAt?)the same shape
siteAccessCodeSetExpiry(codeId, expiresAt){codeId, expiresAt}
siteAccessCodeRemove(codeId){codeId}
siteAccessCodesForSite(siteId)every code of the site, ended ones included, with lastOpenedAt from the newest session of the code's current generation. Never the code or its digest
siteAccessGates(siteId){gate, usesSubject, constructs[]} for each gate the deployable declares

Each act writes a v1:identity:auditEvent with targetType: siteAccessCode and the action site_access_code_created, site_access_code_regenerated, site_access_code_expiry_changed or site_access_code_removed, naming the person. The code is never in it.

Moving a deployable between organizations

A code copies its deployable's organization when it is minted, and the part is checked against that copy. So a deployable's organization cannot change while it has a code that has not been removed -- an expired one included, since a new expiry revives it. The refusal says to remove the codes first. A code whose copy differs from its deployable's (one a move racing a mint can leave) opens nothing. The panel offers only Remove for it, to somebody the organization gate admits; anybody else is told that a cluster operator must remove it.

Where the rows live

Two concepts hold this, v1:platform:siteAccessCode and v1:platform:siteAccessSession. Both are written only by the server, and no client reads them directly: a raw read, parentOf, asOf and a subscription are all refused, because every client path goes through a builtin that passes the part and the organization gate. Neither publishes graph events, so no automation or rule can journal one. Sessions are kept for 30 days, which is as far back as "last opened" can see.


Declaring what a code opens

@accessGate(deployable="client-desk", gate="dashboard") goes on a query or a mutation in the deployable's own DSL.

  • deployable is the name the package's manifest gives the deployable (packages.md).
  • gate is the part of that app a code opens. A code opens one gate.

It opens no endpoint. There is one engine-owned route family on the site's origin; the annotation only says which constructs a gate reaches. A deployable with no codes answers every call the way it answers a stranger.

A worked example

A desk shows each client some briefs. The dashboard gate shows the holder of one code the briefs written for that code. The engagement gate is for a whole client: every code issued with the subject acme reads the same briefs.

memql
/// One brief the desk shows to a client. A gated call runs under the deployable
/// owner's authority, so the rows are the owner's; each also says which code
/// wrote it and which client it is about.
@rowAuthz(owner="ownerUserId")
concept deskBrief {
ownerUserId string
accessCodeId string
client string
title string
body string
}
 
@row
shape deskBrief deskBriefCard {
row.id
title
body
}
 
/// What the dashboard shows the holder of one code. accessCodeId is reserved:
/// the handler stamps it, so the filter can only ever match this code's rows.
@accessGate(deployable="client-desk", gate="dashboard")
@actor
query deskBrief dashboardBriefs {
args {
accessCodeId string!
}
filter row => row.ownerUserId == actor.userId && row.accessCodeId == args.accessCodeId
paginate 20
shape deskBriefCard
}
 
/// One client's engagement, for every code issued for that client. accessSubject
/// is reserved too: it is the subject the operator typed when adding the code
/// (acme), and a code with no subject cannot call this construct at all.
@accessGate(deployable="client-desk", gate="engagement")
@actor
query deskBrief engagementBriefs {
args {
accessSubject string!
}
filter row => row.ownerUserId == actor.userId && row.client == args.accessSubject
paginate 20
shape deskBriefCard
}

The page asks for dashboardBriefs with no arguments at all. It has nothing to send, because the handler supplies the one that matters:

text
POST /_memql/access/call
{"call":"dashboardBriefs","args":{}}
 
200 {"data":[{"id":"8f2k1q","title":"Kickoff","body":"..."}]}

The reserved arguments, and how they isolate data

Five argument names are reserved. When a construct declares one, the handler stamps it, last, from what it knows about the session. A caller that sends one is refused with invalid_args, even to a construct that does not declare it, so a forged argument cannot tell anybody what a construct declares.

NameStamped withUse it to
accessCodeIdthe bare id of the code in use. It survives a regeneratekeep each code's rows apart
accessSubjectthe subject the operator gave the code. Not stamped at all for a code with none -- never an empty stringscope by client
accessGatethe gate the code opens. A construct has exactly one, so this is always that gaterecord on a row which gate wrote it
siteIdthe bare id of the deployable's sitescope by deployable
accessCodeLabelthe operator's name for the code, its label. On a mutation only: the load refuses it on a querytell the operator which code did something

That is the isolation mechanism, and it is the author's to use: rows carry the stamped accessCodeId, or match accessSubject, and the filter says so. A gated construct that reads rows with neither opens them to everyone holding any code for that gate. Writing the annotation without a filter is deciding exactly that.

accessCodeLabel isolates nothing. It lets a product tell the operator, in a message only they read, which code did something, because no workflow can read a code. The visitor is never told: a mutation answers them with its bare id, and the load refuses the name on a query, which answers with what its shape selects. A row you write the name to is yours to keep out of every gated read's shape (added 2026-11-04).

Declare a reserved argument as string!. A construct that needs accessSubject and is called by a code with no subject is refused by the engine for the missing argument, and the visitor sees 502 refused. Every other declared argument is the caller's, and is untrusted input. A product that puts one in a prompt it generates has made that a prompt-injection question; the engine cannot answer it for you.

Writing a gated mutation

The call runs under the owner's authority, and a mutation writes with it. Three things are the author's to get right:

  • Do not let the visitor choose the row's id. An insert at an id that already names a row writes a new version of that row, and every row a gated mutation writes belongs to the same owner, so one code can overwrite another's. Leave the id out: the engine then derives it from the concept and everything the row holds, the stamped accessCodeId included (the example below), so one code's call cannot land on another's row, and a repeat of the same call is the same row rather than a second. Or build the id from the stamped accessCodeId. If a visitor must name the row, as a retry key, make every field the mutation writes @createOnly, so a repeat cannot change a row that exists.
  • A nested name is not checked. The handler refuses a reserved name at the top level of args and looks no deeper. If a construct declares an object argument and spreads it into the row (a bare args.payload), a visitor can send {"payload": {"accessCodeId": "<another code>"}} and the spread writes it. Accept named fields (accept { body }) instead, or name the reserved field explicitly beside the spread, which the engine applies after it.
  • A mutation answers with only the row's bare id ({"data":[{"id":"..."}]}). It has no shape clause, so there is nothing else that may leave.
memql
/// A note a visitor leaves on the desk.
@rowAuthz(owner="ownerUserId")
concept deskNote {
ownerUserId string
accessCodeId string
body string
}
 
/// Leave a note under the code that opened the gate. There is no id argument, so
/// the engine derives the id from what the row holds, accessCodeId included, and a
/// visitor cannot name another code's row.
@accessGate(deployable="client-desk", gate="dashboard")
@actor
mutation deskNote leaveNote {
args {
accessCodeId string!
body string!
}
insert {
accept { body }
stamp {
accessCodeId: args.accessCodeId
ownerUserId: actor.userId
}
}
}

The shape of what not to write -- a visitor-chosen id, and a spread object with no stamp beside it:

memql
/// Two ways to let one code write over another's note.
@accessGate(deployable="client-desk", gate="dashboard")
@actor
mutation deskNote editNote {
args {
noteId string!
payload object!
}
update {
id: args.noteId
args.payload
}
}

What load refuses

These are load faults. They land on the load report, so a strict boot refuses them and package analysis reports dsl_refuses_boot before a deploy. A construct is refused when:

  • the annotation is on anything but a query or a mutation, is written twice, or lacks either key. deployable matches ^[a-z0-9][a-z0-9-]{0,62}$ and gate matches ^[a-z][a-z0-9-]{0,39}$, and neither has a default;
  • it also carries @serverOnly, which bars the very call a visitor makes, or @requiresRank or @requiresCapability: the borrowed authority is a stand-in for the owner, and a rank or a capability would be judged against a role nobody meant;
  • it declares a reserved argument as anything but a string;
  • it declares an argument that differs from a reserved name only in case, such as accessCodeID. The handler matches the reserved names exactly, so that would be an ordinary argument that renders whatever the caller sent, and a filter on it would read as scoped to the code while opening to any id a visitor names;
  • it shares a name with another gated construct, under one deployable, in one DSL domain. The same name in another domain is another product's declaration and not a fault;
  • it is bound to no concept, or written in a nested directory of its domain. A call names the construct as namespace.name, and a nested directory's namespace cannot be written that way.

A package using @accessGate on an engine that predates it is refused at analysis as dsl_refuses_boot, so the wrong order of rollout fails safely rather than crash-looping a node. Ship the engine first.

Which package opens a gate

Gate, deployable and construct names are short and will collide between products, so a gate is tied to the package that ships it:

  • Package analysis refuses a gate naming a deployable the manifest does not declare (dsl_access_gate_foreign_deployable), and one bound to a concept of a DSL domain the package does not ship (dsl_access_gate_foreign_domain), before anything is staged. Both are in the refusal catalogue.
  • At run time the bff opens a construct only when its deployable equals the site's package deployable and its domain is one the site's package ships.

The domains a package ships are dslDomains on the package. A deploy writes them, and nothing else does; no client write can name the field. A deploy records them when it changes what a visitor is served: a run that publishes a serving version, and a run with every app skipped that carries DSL (which is how DSL is deployed ahead of a candidate). A run that publishes only candidates leaves them alone, so a candidate of a tree that dropped a domain cannot close the gates of the build the public is being served (deployables.md). A rollback restores the list of the deployment it returns to.

An empty list opens nothing, and that is also what a source deployed before the field existed reads as. A gate that suddenly answers 404 on such a source is repaired by deploying it again.

This stops one product's code reaching another's operations by accident. It is not a defense against a hostile author: DSL is already cluster-wide authority.


The wire

This is a documented exception to the engine's gRPC-first rule, owner-approved on 2026-10-29. A visitor's browser has no MemQL identity to open a stream with, and only an HTTP response can set an HttpOnly cookie, so the other party dictates the wire. It is one route family on the deployable's own origin, with four method and path pairs. The edge answers them ahead of the bundle and of the generic /_memql/* proxy, whatever the site's apiProxy says.

On the site's originbff route
POST /_memql/access, body {"code":"..."}POST /access/unlock
GET /_memql/accessGET /access/session
POST /_memql/access/leavePOST /access/leave
POST /_memql/access/call, body {"call":"name","args":{...}}POST /access/call

Any other method or path under /_memql/access is not this surface's and reaches the generic proxy as it always did. The four take no query string: the edge forwards the path alone, so a code pasted into a URL never reaches the bff or anything that records what it served. The bff routes are never reachable from outside: the edge is the only way in.

Every reply carries Cache-Control: no-store and X-Content-Type-Options: nosniff. Every POST must declare Content-Type: application/json, leave included, whose body is empty or {}. There is no CORS: the page that calls this is the deployable's own. The bff sees the access cookie and no other credential: the edge drops Authorization and every other cookie on these four routes, a MemQL sign-in cookie included, because nothing here reads them.

text
__Host-memql_access=mql_acs_<43 characters>; Path=/; HttpOnly; Secure; SameSite=Strict

No Domain, and no Max-Age or Expires: the server is the authority on expiry, and an extension must not be cut short by a browser-side clock. Page script cannot read it, and arriving from a link in an email is fine. A clear is the same attributes with Max-Age=0.

The __Host- prefix is what stops another site planting one. Every deployable on *.memql.<domain> is a sibling of every other, whoever owns it, and a page on any of them can set a cookie for the shared parent. A browser refuses a __Host- cookie from a sibling, or with any Path but /, a Domain or no Secure, so none of them can put a cookie of this name in a visitor's browser. Without the prefix a planted cookie with a longer Path would be sent first and read first, which would end the real session, and a planted live session would catch the visitor's gated writes.

Path=/ is the price, and the edge pays it. A browser sends this cookie with every request to the site, so the edge takes it out of everything it forwards anywhere but the four routes: the generic /_memql/* proxy, shopper forms and reads, and the identity endpoints. The rest of the Cookie header goes through as it was. The bundle's own files are served by the edge, which reads nothing from it.

What a code looks like

Twenty-five symbols of Crockford base32 in five groups, K7Q4M-2XPDN-8RT3V-WJ6HC-9FBZA. The bff normalizes whatever was typed before it hashes: letters are upper-cased, O reads as 0, I and L as 1, and every other character outside the alphabet is dropped, including the en dashes and zero-width characters that email clients introduce. A page sends what the person typed, as it was typed.

What the edge answers

These come before anything is forwarded. The checks that cost nothing -- the content type, the Origin, the declared size -- come before the rate limit, so a page that sends a malformed request cannot spend a visitor's budget. Every body is JSON:

StatusBodyWhen
404{"error":"not_found"}the site has no owner (the platform's own sites), or the edge has no API target
415{"error":"json_required"}a POST that does not declare application/json
403{"error":"forbidden_origin"}a POST whose Origin names another host. Origin: null is refused too; a POST with no Origin is allowed
413{"error":"too_large"}a body over 1 KiB (unlock, leave) or 64 KiB (call), by what it declares or by what is read
400{"error":"bad_request"}a body that could not be read
429{"error":"rate_limited"}a budget is spent. Retry-After is in whole seconds

Two replies are not JSON, and a client must not assume they are:

  • a 502 from the proxy, when the edge cannot reach the bff, is text/plain (upstream unavailable). It is the proxy's reply, shared by every route it serves;
  • a deployable that is not live never reaches the surface: offline answers 503 and a draft or archived one 404, both plain text. The exception is somebody holding a preview grant, who is already served a draft or a live deployable's candidate and reaches these routes on it too, where a code still has to be valid.

The edge then strips X-Memql-Access-Site and X-Memql-Access-Owner from everything it forwards, on every path, and sets them itself. The stamp is a pointer, not an assertion: the bff reads the site's row and requires its own owner to equal the stamp, and its account to equal the code's copy.

What the bff answers

A stranger costs nothing. Anybody on the internet can send these four, so the order is deliberate. A request with no cookie, a cookie that could not be a token (mql_acs_ and 43 base64url characters) and a body that could not hold a code (25 symbols once normalized) are answered without a read. Anything else is looked up by its digest first, and a digest that finds nothing is answered with no other read and no write. The site is read only for a request whose digest found a row, and its package and the owner's own view of both only for a gated call.

POST /_memql/access trades a code for a session.

StatusBodyMeaning
200{"gate":"engagement","subject":"acme","expiresAt":"2026-10-30T18:00:00Z","remainingMs":86399000}in, with Set-Cookie
401{"state":"invalid"}unknown, removed, another site's, or superseded by a regenerate. All one reply, so it is no oracle
403{"state":"expired"}the exact code, past its expiry. Only somebody holding the code can learn this
502{"error":"refused"}the bff could not read or write the rows. Try again

A failed attempt writes nothing. subject is "" when the code has none.

expiresAt and remainingMs are one instant, the session's end: the earlier of the code's expiry and 24 hours after it opened, stated two ways. remainingMs is the one to schedule from, so a wrong clock on the visitor's machine does not move the moment.

GET /_memql/access says whether the cookie presented is still good.

StatusBodyMeaning
200as above, no new cookiestill in; the remainder is as of this answer
401{"state":"none"}no cookie. Sets nothing
401{"state":"ended"}a cookie whose session is over for any reason: expired, the 24 hours, regenerated, removed, left, or a token with no row at all. Clears the cookie
502{"error":"refused"}a failed read. Clears nothing: a database blip is not a visitor taken out

none clears nothing because a browser may well hold the cookie. Under SameSite=Strict a link from another site to this path arrives without it, and a clear in that reply would delete the real session of whoever followed the link.

POST /_memql/access/leave ends the session the cookie names, and no other -- two browsers on one code are two sessions. It answers 204 and clears the cookie, and it is idempotent, with no cookie as well. If the end cannot be written it answers 502 {"error":"refused"} and the cookie stays, because clearing it would say the visit is over while the row still honors the token.

POST /_memql/access/call runs a construct.

StatusBodyMeaning
200{"data":[...]}a query's rows, or a mutation's bare id
401{"state":"ended"}the session is over, or there was no cookie at all (a call has one word for both). Clears the cookie
404{"error":"not_found"}see below
400{"error":"invalid_args"}a body that is not one JSON value, a key the construct does not declare, or any reserved name
502{"error":"refused"}the construct refused the call (a wrong argument type, a constraint), or a read failed. Clears nothing

One 404, identical to the byte, for an unknown construct, an undeclared one, one on another gate, one on another deployable, one in a domain the package does not ship, a name two of the package's domains both declare, a site whose owner cannot read it or its package, a stamp the site's row does not agree with, and a request with no stamp. A holder of one gate's code learns nothing about another's. The registry is consulted before the arguments are looked at, so a refused argument is only ever reported for a construct the session's gate reaches.

A call reads the site and its package under the owner's own authority, last, just before the construct runs, because the construct is about to run as that person. A site whose owner was removed from its organization reads as nothing to them, so its calls answer that 404, and the bff logs why. Nothing else lends that authority, so such a site still unlocks and a status check still says who is in; what is gated stays gated.

A query answers with its shape's rows, with every id bare. A query with no shape clause answers with only the ids of the rows it selected, and the bff logs a warning at the site and construct so the author can find out why a page has no fields. A mutation answers with only the row's bare id.

A call decides twice. The session is read before the construct runs and again before its rows leave. A regenerate, a removal, a shortened expiry or the instant of expiry itself can land while the construct runs, and the answer is then 401 {"state":"ended"} with no rows and the cookie cleared. A write the construct made stays made. If the session cannot be read the second time, the rows still do not leave, but nothing has said the visit is over: the answer is 502 {"error":"refused"}, the cookie stays, and a database blip costs one retry and takes nobody out.

Rate limits

Per replica, so the cluster-wide ceiling is the rate times the number of replicas:

OperationBudgetKeyed on
unlock10 a minutethe site and the address
unlock60 a minutethe site
session, leave, call600 a minutethe site and the address

The address is the right-most X-Forwarded-For entry: the hop the ingress itself recorded, which a caller cannot choose. The leftmost entry is the caller's to write, and rotating it would spend the site's sixty unlocks and lock real visitors out. It is a key only when it is an IP address, in its canonical spelling; a name, an ip:port or anything else is not, and the connection's peer is used instead, which behind the ingress is the ingress itself. An IPv6 address keys on its /64, because one connection is routinely handed a whole /64 and may pick any address in it, so everybody behind one /64 shares a bucket. Unlock draws on the address's bucket first, so one machine can take at most ten of the sixty. Retry-After is how long the refusing bucket takes to give one token back: 6 seconds for an address that spent its ten unlocks, 1 otherwise.

These bound load, not guessing. What stops guessing is 125 bits.


What the page does

The server refuses at once and every time, so a page that does nothing is still safe. These three obligations are what make the browser leave when the server has stopped answering, and they are a few dozen lines over fetch. The client is not in the SDK in this version.

The pageThe server beside it
1. Leave on timeSchedule the end from remainingMs the moment a reply arrives, and drop gated state the instant it fires. Never compare expiresAt with the page's own clockRefuses after the exact instant of expiry, with no grace
2. Learn of an actAsk GET /_memql/access every 5 seconds while the page is visible, and at once on visibilitychange, focus and online. A changed remainingMs reschedules the endA regenerate, a removal or a shortened expiry is refused on the next request
3. Treat a 401 as the endAny 401 on a status check or a call means locked: drop gated state and show the code boxended clears the cookie

Keep gated rows in memory. Anything held in localStorage, sessionStorage, IndexedDB or a cache is a place a drop can miss. A 5xx, a 429, a network error or a plain 404 says nothing about the session: keep the state, and ask again at the next tick. Do not read them as locked, and do not read them as in.

typescript
const ACCESS = "/_memql/access";
 
const post = (path, body) =>
fetch(ACCESS + path, {
method: "POST",
credentials: "same-origin",
headers: { "Content-Type": "application/json" }, // leave included: the edge refuses any other type
body: JSON.stringify(body ?? {}),
});
 
export function accessSession({ onOpen, onLocked }) {
let live = false;
let endTimer;
let poller;
 
// Obligation 3, and where obligation 1 ends: stop both clocks, drop everything gated.
function lock() {
live = false;
clearTimeout(endTimer);
clearInterval(poller);
poller = undefined;
onLocked();
}
 
// Obligation 1: end the visit from remainingMs, never from expiresAt against this clock.
function open(session) {
live = true;
clearTimeout(endTimer);
endTimer = setTimeout(lock, session.remainingMs); // a changed remainingMs lands here again
poller ??= setInterval(recheck, 5000);
onOpen(session);
}
 
// Obligation 2: ask whether the session still stands. Offline or a 5xx says nothing either way.
async function check() {
let response;
try {
response = await fetch(ACCESS, { credentials: "same-origin" });
} catch {
return;
}
if (response.status === 401) lock(); // none or ended
else if (response.ok) open(await response.json());
}
const recheck = () => live && document.visibilityState === "visible" && check();
document.addEventListener("visibilitychange", recheck);
window.addEventListener("focus", recheck);
window.addEventListener("online", recheck);
 
return {
restore: check, // on page load: a cookie from an earlier visit may still be good
 
async unlock(code) {
const response = await post("", { code });
if (response.ok) {
open(await response.json());
return "open";
}
if (response.status === 429) return "wait"; // Retry-After says how long
if (response.status === 403) return "expired"; // the exact code, past its expiry
if (response.status === 401) return "invalid";
return "unavailable";
},
 
async call(name, args) {
const response = await post("/call", { call: name, args });
if (response.status === 401) {
lock();
throw new Error("The visit has ended.");
}
if (!response.ok) throw new Error(`The call was refused (${response.status}).`);
return (await response.json()).data;
},
 
async leave() {
const response = await post("/leave");
if (!response.ok) throw new Error("Could not leave; the session still stands. Try again.");
lock();
},
};
}

The limits, stated plainly

  • A code gates what the bff returns, not the bundle. Anything in the bundle is public. Gating a path of static files is not in this version.
  • An idle tab learns of an operator's act within 5 seconds. A regenerate, a removal or a shortened expiry is refused at the server immediately, and an open tab finds out at its next poll, at once when it becomes visible or regains focus or the network, or through a 401 on any call. The server has no way to push to a browser, and a push channel is not worth building for the difference. Expiry itself is exact to the timer. A hidden tab's timer may be throttled by the browser, so it re-checks the moment it becomes visible, and the server has already stopped answering it.
  • Ending a session cannot unsee. It stops the next answer. Rows the page already received stay in the browser until the page drops them, which is why obligations 1 and 3 are the page's.
  • The rate limits are per replica and bound load, not guessing, and they key on the right-most X-Forwarded-For entry. A proxy added in front of the ingress groups every visitor behind it into one bucket: ten unlocks a minute between them, and a share of the site's sixty. So does an ingress that writes ip:port, which is not an address and falls back to the peer, and so does one IPv6 /64.
  • Borrowed authority does not re-check that the site's owner is still active. A construct runs as the owner, as a shopper's form does, and nothing per request asks whether that person is still around. Removing the codes is how an operator ends access.
  • A code is a bearer credential. Whoever holds it can use it until it expires, is replaced, or is removed, and a stolen cookie is good until the code's expiry, a regenerate, a removal, 24 hours or leave. Several people can use one code at once; there is no per-visitor identity and no list of who is in now. Give one code to each person or party you may need to take out alone.
ThreatWhat stands in the way
Guessing a code125 bits. Failures write nothing and are one reply. Rate limits bound load
A leaked row, backup or logOnly digests are stored. A code, a token, a digest and a call's arguments are never logged or put in an audit event
Cross-site request forgerySameSite=Strict, JSON-only POSTs and the Origin check
Another deployable on the same parent domain planting a cookieA browser refuses a __Host- cookie from a sibling, so it cannot hide the real one, end it or catch the visitor's writes with a session of its own
A link from another site to the status checkArrives with no cookie under SameSite=Strict, is answered none, and clears nothing
A stranger running up the databaseNo cookie, a malformed token and a body that holds no code cost no read. A guess costs one lookup by digest, through an index
Script on the deployableCannot read the cookie. Can call declared constructs while the page is open, which is the reach the code already grants. The edge's hash-based CSP applies
Forged reserved argumentsRefused from the caller, stamped last
Forged edge headersStripped on every path, and the bff compares the stamped owner with the site's own
Injection through a callArgument names come from the declaration, values are JSON-encoded, and the construct name comes from the registry
Reaching a @serverOnly constructNever internal origin, and refused at load
Enumerating gates and constructsOne 404 for every miss
Session fixationA fresh token on every unlock; a cookie with no row is ended

When a gate answers 404

SymptomCauseFix
The panel says the app has no gates yet, and Add is absentNo construct declares @accessGate for this deployable's name, or the source has not been deployed since access codes existed, so its dslDomains are emptyDeclare the gate and deploy; or, for an older source, deploy it again
Every call answers 404 on a source that worked beforeThe same: an empty dslDomains opens nothingDeploy the source again
One call answers 404 and others workThe name is not declared, is on another gate, is @disabled, is in a nested directory, or two of the package's domains both declare itCheck the gate, the name and dsl_access_gate_* in the analysis
Unlock and the status check work, every call answers 404, and the bff logs "this site's calls answer 404"The site's owner cannot read it or its package. A site whose owner was removed from its organization reads as zero rows under that owner. The log line carries the reasonRestore the owner's membership, or give the site an owner who can read it
A code unlocks and every call answers 404, and the bff logs nothingWhich node the edge reaches. On an instance where the neutral bff mounts no product bundle, a code minted through bff-<product> unlocks, because the rows are the same everywhere, and every call misses the gate registry of a node that never loaded the gateCheck which node the edge's bff-http selects, and mount the product's DSL there (which node)
All four routes answer 404 for a platform-managed siteIt has no owner to borrowCodes are for your own deployables
Add is absent, and a visitor is only ever told invalid or noneThe deployable was not deployed from a package, so it has no deployable name, no gate can be its own, and it has no codesDeploy it from a package that declares a gate
A 503 or a plain 404 before any JSONThe deployable is offline, or not liveTake it live. An offline spell does not end a session: it works again if its code has not expired

Which node answers

The edge forwards the surface to whatever MEMQL_EDGE_API_TARGET names, normally bff-http, and a gate's registry lives on the node that loaded its DSL. The code and session rows are in the graph and read the same from anywhere, so a node that has not loaded the gate still unlocks and answers every call 404. An instance that runs a separate bff-<product> for its DSL has to have bff-http select a node that mounts it too.

Operating it

  • memql_site_access_requests_total{op,result} counts the four operations by result on bff nodes (app="bff"), with no per-attempt rows behind it. A climb in unlock/invalid is somebody guessing or a code passed along wrongly. refused on unlock, session or leave is the store failing under the surface, and is the one to alert on. refused on call is not an alert: a visitor can move it by sending a construct a wrong argument type, and a code with no subject calling a construct that needs one counts there.
  • "Has anybody opened this?" is answered by the newest session of the code's current generation, with no write to the credential itself.
  • Logs name the deployable and the construct, never an argument. A code, a token and a digest are never logged. The warning about a site whose calls answer 404 carries the deployable, so the Logs button on its page shows it.
  • Failed attempts are not recorded. Operator acts are in the audit log.
  • A stamp that does not check out is logged at WARN, and it takes a credential that found a row to get that far, so a stranger cannot drive that line.

The indexes

Three payload lookup indexes on MemoryNodes keep the lookups cheap (memory_nodes_access_tokenhash_lookup_idx, memory_nodes_access_codeid_lookup_idx, memory_nodes_access_codehash_lookup_idx). Migration 20261030000000_site_access_lookup_indexes builds them like every other lookup index, one chunk per transaction, and that is not free on a large table:

  • Each is a full scan of every chunk's heap, whatever it holds. Being partial decides what goes in, not what is read. Three indexes are three passes.
  • Writes wait, in two places; reads do not. Each build starts with a ShareLock on the table itself, and a write already open holds it back while every later write to any chunk queues behind it, so an open write of a few seconds is a pause of all writes for that long, three times. Each then holds a ShareLock on one chunk at a time, so writes to the newest chunk wait while it is scanned. A write that waits longer than the serving statement limit fails.
  • All three share one migration deadline (MEMORY_NODES_DATABASE_MIGRATION_TIMEOUT_MS, 30 s by default). A build that outlives it carries on server-side and the attempt defers, so the next attempt waits for it and carries on, and the rollout finishes without help (how). Whatever migrations follow wait until it does.

To choose when those pauses happen rather than leaving it to the rollout, build them first, in a session of your own with no client deadline, one statement to a query, and let the migration verify them. Just after a new chunk begins, the newest chunk is nearly empty and the pause is at its shortest:

sql
CREATE INDEX memory_nodes_access_tokenhash_lookup_idx ON "MemoryNodes"
((payload->>'tokenHash'), concept, id, "createdAt" DESC)
WITH (timescaledb.transaction_per_chunk)
WHERE concept = ANY (ARRAY['v1:platform:siteAccessSession'::text]);
CREATE INDEX memory_nodes_access_codeid_lookup_idx ON "MemoryNodes"
((payload->>'codeId'), concept, id, "createdAt" DESC)
WITH (timescaledb.transaction_per_chunk)
WHERE concept = ANY (ARRAY['v1:platform:siteAccessSession'::text]);
CREATE INDEX memory_nodes_access_codehash_lookup_idx ON "MemoryNodes"
((payload->>'codeHash'), concept, id, "createdAt" DESC)
WITH (timescaledb.transaction_per_chunk)
WHERE concept = ANY (ARRAY['v1:platform:siteAccessCode'::text]);

No upgrade barrier. An older engine ignores the indexes, and an engine that reaches the lookups before they exist still answers correctly, slower: neither concept has a row until the first code is minted. After a rollout, the migration is in the ledger, the three root indexes and every chunk's copy are valid, ready and live, and no lock is left in bun_migration_locks.


Reference

  • Edge: component/edge/access.go (routing, caps, budgets, the stamp), routed in component/edge/handler.go ahead of the /_memql/* proxy.
  • bff: component/server/access_handler.go, mounted by app/transport_access_surface.go.
  • The registry and the load rules: component/memql/access_gate.go, component/memql/access_gate_load.go. Codes and tokens: component/memql/site_access_code.go.
  • Operator acts: integrations/siteaccess/; DSL in dsl/platform/ (siteAccessCode, siteAccessSession, the six builtins).
  • MemQL OS: clients/os/src/apps/deployables/access/.
  • Design: docs/superpowers/specs/2026-10-29-deployable-access-codes-design.md.