Skip to content
askdareDocumentation

    ADR-0034: Roles and a bot scope in the admin console

    • Status: Accepted on 2026-11-29: the maintainer settled every question as recommended ("Settled with the maintainer", below). 0.8-a1, a2, e1 and q4 amend it where building shows otherwise; their amendments are under "As built in 0.8-a1", "As built in 0.8-e1", "As built in 0.8-a2" and "As built in 0.8-q4".
    • Date: 2026-11-29
    • Extends: ADR-0032, decisions 7 to 9 (the console's routes, its admin token and sealed references, the dashboard's handlers), and ADR-0016, which stays accepted: no accounts, no hosted dashboard, the app's own sign-in for identity.
    • Built by: 0.8-a1 (roles and scope), 0.8-a2 (an owner deletes a conversation), 0.8-e1 (the site's demo). They amend this ADR where building shows otherwise.

    Context

    In 0.7 everyone who signs in to the console, with ADMIN_SECRET or an identity on admin.console.allow, may do everything:

    • read every bot's configuration, its instructions included;
    • run doctor and the playground, which spend tokens (doctor sends each bot's model a short request);
    • read the conversations, their transcripts and the ratings' comments, which are visitors' personal data;
    • in 0.8 (a2), delete a conversation.

    That fits one developer. It doesn't fit a team: a support lead needs the conversations but not the playground's spending; a manager needs costs and ratings but not transcripts; an agency's client should see their own bot and no other. And a public demo of the console (0.8-e1) must not be able to spend or change anything.

    ADR-0016 rules out the usual answer, accounts with a user table and invitations: askdare keeps no users and trusts the app's sign-in. So roles have to fit what exists:

    • Who someone is comes from the app, as the sub of an identity token with the audience askdare:admin (ADR-0032, decision 8), or from knowing ADMIN_SECRET.
    • What they may do is decided by the app's configuration, which today is a list of sub values.
    • Every request carries a 15-minute admin token whose fingerprint ends the session when the configuration changes.
    • The dashboard's handlers live in @boldare/askdare-admin and get the whole AdminStore (AdminDashboardRequest.store), so they can read every bot's records.
    • The store's queries filter by at most one bot (AdminRange.bot).

    The shipped console has these actions (packages/askdare/src/server/admin-console.ts), each POST <basePath>/admin/api/<action> behind the admin token: config, doctor, message (a playground turn), delete (the admin's own playground conversation), conversations, conversation (a review), and dashboard/<action>, where the add-on's actions are days, conversations, ratings and transcript. a2 adds delete-conversation.

    Decision

    1. Four fixed roles, each including the one before

    RoleAddsSpends tokensChanges or erases data
    viewerThe dashboard's daily totals per bot, day and model: cost, turns, failed and unanswered turns, new conversations, ๐Ÿ‘ and ๐Ÿ‘Ž counts, leads, handoffs by state, resolution rate. Nothing about one conversation or one visitor.NoNo
    reviewerThe conversations: lists (with their pseudonyms and counts), reviews, stored transcripts and the ratings with their comments. The bots' configuration, read-only (settled question 1).NoNo
    developerdoctor and the playground, and deleting its own playground conversations (as in 0.7).Yes, within each bot's limits and budgets, as in 0.7 (T37)Only its own playground conversations
    ownerDeleting any conversation (0.8-a2), and any later action that erases or changes stored data.YesYes

    The lines between roles follow what is at stake, not which screen something is on:

    • viewer sees aggregates only. The daily rows hold no conversation or visitor (ADR-0032, decision 2), so a viewer sees no personal data at all. A per-conversation list, even without text, holds a visitor's pseudonym and activity, so it starts at reviewer.
    • viewer and reviewer are read-only. They spend no tokens and write or delete nothing. That is what makes a public demo possible (decision 6). A later action that writes, such as notes on a conversation (Later in the roadmap), either goes to developer or above, or comes with an amendment that says the reviewer is no longer read-only.
    • developer is where spending starts, and it is exactly what everyone could do in 0.7.
    • owner is where erasure starts. Deleting a visitor's data can't be undone, so it is the highest role.

    Roles are fixed in the library. An app can't define its own or pick individual permissions: four named roles are easy to explain, to test and to review in a configuration diff. A finer split later is a new role or an amendment, not a permission language.

    2. Each action's least role

    One permission table in server/admin-console.ts, checked in route after the admin token is verified and before the action reads its body:

    RequestLeast roleBot scope (decision 3)
    GET admin, GET admin/<asset>none: they hold no dataโ€”
    POST admin/api/session (sign in)none: it decides the roleโ€”
    configreviewer (settled question 1)only bots in scope
    doctordeveloperthe shared store checks, then only bots in scope
    message (playground)developerthe bot must be in scope
    delete (own playground conversation)developeralready limited to the admin's own conversations
    conversationsrevieweronly bots in scope
    conversation (review)reviewerthe conversation's bot must be in scope
    delete-conversation (0.8-a2)ownerthe conversation's bot must be in scope
    dashboard/daysvieweronly bots in scope; totals summed over the scope
    dashboard/conversationsrevieweronly bots in scope
    dashboard/ratingsrevieweronly bots in scope
    dashboard/transcriptreviewerthe conversation's bot must be in scope
    any other dashboard/<action>the role the dashboard declares for it, else ownerthe store view is scoped either way
    • What every role needs to draw the page comes with the sign-in answer, not with config: the user's role, the IDs of the configured bots in scope, whether there is an admin store, whether it keeps transcripts, the retention, and whether there is a dashboard. config is then the bots' configuration only, and a viewer never calls it.
    • The dashboard declares its handlers' roles (settled question 7). AdminDashboard gains roles, a map from action to least role. Core reads it and checks it like its own table. An action the map doesn't name needs owner, so a newer add-on with an older core, or a handler added without a role, fails closed.
    • A refused request answers 404 not_found, like an action that doesn't exist, whether the role is too low or the bot is outside the scope (settled question 6). It is the answer an unknown bot or conversation already gets (T31), and it needs no new error code in the protocol. The page never sends these requests, since it hides what the role can't use, so a 404 means a stale page or someone probing.
    • The page only hides. The console and the dashboard hide the views and buttons a role can't use, and the dashboard's mount gets the role and the bots in scope for that (host, an internal contract). Every refusal that matters is the server's.

    3. The bot scope

    A user may be limited to some bots. The scope is a list of bot IDs; without one, the user sees every bot.

    • Without a scope a user sees every bot, including records of bots that are no longer configured.

    • With a scope a user sees only records whose bot is in the list, and only configured bots that are in it. A scoped user never sees totals across the whole app: the dashboard's totals are sums over their scope.

    • The configuration view, doctor and the playground work on the bots in scope only. doctor also runs the shared store checks (the conversation store, the limits store, the admin store's schema and retention). They name the stores and hold no bot's data, and a broken store breaks the scoped user's bots too.

    • A review checks the conversation's bot: from its transcript records, or, without them, from the conversation store's info(). A bot outside the scope answers 404, as an unknown conversation does.

    • The dashboard's handlers get a scoped, read-only store view, not the store (AdminDashboardRequest.store). Core builds it per request from the session:

      • days: with a bot in scope, passed through; with a bot outside it, empty; without a bot, one query per bot in scope, rows put together. Daily rows are already per bot, so nothing is merged.
      • conversations and ratings: with a scope of one bot, that bot is set as bot. With a scope of several, the query must name one of them (the console's bot picker does; settled question 5). A bot outside the scope gives an empty page.
      • transcript: records of a bot outside the scope are returned as none, as for an unknown conversation.
      • Writes, deleteConversation, sweep and diagnose are not on the view. A dashboard handler reads; core alone writes and deletes (ADR-0032, decision 3).

      The scope is enforced in one place, core, and the add-on's handlers don't filter by it themselves. A handler that forgets a filter can't leak another bot's records.

    • Sealed references stay bound to the session (ADR-0032, decision 8). A change of role or scope ends the session (decision 5), so references sealed under a wider scope die with it. Opening a reference still checks the conversation's bot against the scope, as the review does, rather than trusting that the list was filtered.

    • Playground conversations of other admins are listed with their bot (source: 'console'), as in 0.7: a scoped reviewer sees those of their bots only.

    4. How the app assigns roles: admin.console.allow

    In configuration only. allow becomes a map from the identity token's sub to a role, or to a role with bots:

    createChatHandler({
      bots,
      admin: {
        store,
        console: {
          allow: {
            user_1: 'owner',
            user_2: { role: 'reviewer', bots: ['support'] },
            user_3: 'viewer',
            agency_client: { role: 'owner', bots: ['client-bot'] },
          },
          dashboard: adminDashboard({ prices }),
        },
      },
    });
    // From @boldare/askdare/next (names final in a1)
    type ChatHandlerAdminRole = 'viewer' | 'reviewer' | 'developer' | 'owner';
    interface ChatHandlerAdminUser {
      readonly role: ChatHandlerAdminRole;
      /** Without it, every bot. At least one ID. */
      readonly bots?: readonly [string, ...string[]];
    }
    // ChatHandlerAdminConsoleOptions.allow
    readonly allow?: readonly string[] | Readonly<Record<string, ChatHandlerAdminRole | ChatHandlerAdminUser>>;
    • The 0.7 array stays accepted and gives each listed user developer, unscoped (settled question 2). That is exactly what everyone could do in 0.7, so upgrading changes nobody's access and grants no one the new delete. The array is a shorthand, not deprecated.

    • The map is read as own keys only. It is copied into a Map once, so a sub such as __proto__ or constructor can't match anything through the prototype.

    • Checked on the console's first request, like the rest of its setup (ADR-0032, "As built in 0.7"), so next build needs nothing:

      • an unknown role, or bots: [], is a setup error, since either is a mistake and failing closed is better than guessing;
      • a bot ID that no bot has is warned about once. The user sees nothing for it, but records of a removed bot stay reachable by its ID, and one typo doesn't lock every user out.
    • ADMIN_SECRET signs in as an unscoped owner. It is the way in when the app's own sign-in is down or not built yet, and the one that can always erase. An app that doesn't want it leaves it unset; it is not configurable to a lower role.

    • No role claim in the identity token (settled question 3). The app's server signs the token, so a claim would work, but:

      • the allowlist would no longer be the one place that says who may do what. A role would come from whatever code signs tokens, and with IDENTITY_SECRET that is the same code that signs visitors' chat identity tokens;
      • a bug that lets a user influence the claims, or a token minted for one purpose and reused, becomes a privilege escalation, while with the map a token only says who someone is;
      • a role in the token is fixed for its 10 minutes and the session's 15, and only removing the user from allow ends it. With the map, any change ends the session at the next request (decision 5);
      • a configuration diff shows every grant and every change of one in code review.

      The cost: an app whose roles live in its database redeploys, or reads them at startup, to change one. If teams ask, a function form of allow ((sub) => role | undefined, called at sign-in and on each request) is the additive next step. It keeps the decision on askdare's side of the check, unlike a claim.

    5. Enforcement: the admin token carries the role and the scope

    • The admin token (AdminGrant, ADR-0032 decision 8) gains the role and the bots. It stays a JWE, so the browser can't read or change them; the page learns them from the sign-in answer.
    • The fingerprint covers them. It becomes a pseudonym of the subject together with its role and its sorted bots (or of ADMIN_SECRET, whose role is fixed). On every request authorize looks the subject up in the current allow and recomputes the fingerprint. Removing a user, or changing their role or bots, ends their sessions at the next request with 401, and the page signs in again. A changed role takes effect as a new session rather than mid-session, so the page never shows views from the old role.
    • Every action checks the role and scope on the server, from the verified token, through the table of decision 2 and the scoped store view of decision 3. Nothing about access is read from the request body.
    • Sign-in limits, the kill switch, headers and sealed references stay as ADR-0032 decided.

    6. Managing users stays in the app

    askdare has no user list, invitations, role editing or "team" page inside the console. Each would need accounts and storage that ADR-0016 rejected, and a second place where access is granted, beside the app's own sign-in.

    • The app manages users in its own sign-in, and grants console access by editing allow and deploying, as in 0.7.
    • The "super admin" is an unscoped owner. ADMIN_SECRET is one. There is no role above it and no askdare-level administrator. An owner may be scoped to some bots, and then erases only their conversations (settled question 8).
    • askdare keeps no sessions on the server, so there is no list of who is signed in. A session ends when its token expires (15 minutes) or when the configuration changes (decision 5).

    7. The public demo (0.8-e1)

    The demo console on askdare's site is a reviewer on fictional data (settled question 4): one allow entry, { demo: 'reviewer' }, in a handler of its own with its own bots and a seeded memoryAdminStore(), signed in by a site route that signs a short-lived identity token, as docs/admin.md shows for any app. A reviewer can open every view that only reads, the dashboard, the conversations, the reviews and the bots' configuration, and can't run doctor or the playground or delete anything. The demo needs nothing else from the library.

    The rule that keeps the demo safe is e1's, not a role's: the demo handler never reaches the site's real conversation or admin store. A role limits what a user can do with a store; it doesn't make a real store's contents fit to publish.

    8. Later, not decided here

    • A record of who opened which transcript, for teams whose privacy rules ask for one. It is a write on every review, so it needs its own storage decision (the admin store, or a hook such as onAdminAccess that hands the app a metadata-only report).
    • Erasure across all of a signed-in visitor's conversations, for a deletion request from someone who signs in. It needs an AdminStore query by visitor (by pseudonym), so it is a port change with a contract test and an Upstash index.
    • Lists across several bots in one query, if a multi-bot scope's per-bot lists (decision 3) prove awkward: bots in AdminRange, a port change every store implements.
    • A function form of allow (decision 4), if teams ask.

    As built in 0.8-a1

    Amended on 2026-11-30 (task a1), where the code differs from or adds to the decision above:

    • Decision 4, the names: the role type is AdminRole, exported from @boldare/askdare, not ChatHandlerAdminRole from ./next: AdminDashboard.roles needs it, and that type lives in the main entry. ChatHandlerAdminUser is exported from ./next as drafted. AdminDashboardRequest.store is Pick<AdminStore, 'days' | 'conversations' | 'ratings' | 'transcript'>, with no new name; name and diagnose are not on it either.
    • Decision 4, checking allow: an unknown key in a user, such as bot for bots, is a setup error too, since the user would otherwise be unscoped. An empty entry in a 0.7 list is skipped, as 0.7 did in effect, so allow: (process.env.X ?? '').split(',') keeps working with the variable unset.
    • Decision 2, the sign-in answer: role, bots, scoped, store (its name and whether it keeps transcripts, or null), retentionDays and dashboard. For a scoped user bots is the scope as configured, IDs no bot has included (after the configured ones, which come in their configured order, so the page starts on a bot that exists), so the records of a removed bot stay reachable by its ID, as decision 3 says; for an unscoped one, every configured bot. config answers { bots } only, the configured bots in scope.
    • Decision 3, the console's own list: conversations takes an optional bot and reads through the same scoped store view as the dashboard. The page shows a bot picker when there are several bots, with "All" only for an unscoped user; a scope of several starts on its first bot. The dashboard, for a scope of several, asks for a bot in its list views instead of sending a query without one.
    • Decision 3, doctor: the doctor report in server/handler.ts takes a filter of bot IDs (three lines in a hot file); the shared store checks still run for everyone.
    • Decision 3, the playground's own delete: besides its owner, it checks the conversation's bot against the scope, as every other read does.
    • Decision 5, the fingerprint: a pseudonym of the subject together with its role and its sorted bots ([sub, role, bots or null]); authorize also compares the token's role and bots with the current ones. The page learns its role only from the sign-in answer, and a viewer without a dashboard gets a page that says their role has nothing to show.
    • The site: ADMIN_ALLOW takes roles and bots as user:role:bot+bot, comma-separated (the follow-up 0.8-s1 names); a user without a role is a developer on every bot, and a list with no roles is passed as the 0.7 list.

    As built in 0.8-e1

    Amended on 2026-11-30 (task e1). Decision 7 held: the demo needed nothing new from the library. What building it added, all in the site (site/demo-console/, site/CLAUDE.md):

    • ADMIN_SECRET reaches every console an app mounts. The handler reads it from the environment, with no option to leave it out, so the demo's handler would sign the site's owner in as an owner too. The demo's route lets only an identity sign-in through, so its one user really is the reviewer. An app with several handlers should know the secret opens each of them.
    • Its own secrets, not the site's. The demo's handler gets secret and identitySecret derived from CHAT_SECRET with HMAC, and no previousSecrets, so its tokens, sessions and sealed references work nowhere else, and the site's tokens don't work in it.
    • Only the console is served. Its route answers 404 for every other path of the handler, so nobody can chat with the demo's bots and put a real conversation among the made-up records, and its OpenAI key is a dummy, so nothing in it can spend.
    • The console's sign-in limits stay per instance. In a shared store, 20 sign-ins an hour across the app would close a public demo after 20 visitors; its one user's way in is public anyway, and the site's route limits sign-ins per address (5 a minute). Raising or scoping that limit would be a library option, not needed for 0.8.

    As built in 0.8-a2

    Amended on 2026-11-30 (task a2), where the code adds to decisions 2 and 3:

    • delete-conversation takes a sealed reference, needs owner, and calls the same delete as the visitor's own and the sweep (ADR-0032, decision 4): admin records, the conversation, then its files. Like the visitor's delete, it runs under its own 60-second timeout rather than the request's, so an owner who leaves after confirming still gets it done. It needs an admin store, as the review does; without one it answers 404.
    • Its scope check is stricter than the review's. It reads the conversation's bot from every place that names it, all its transcript records and the conversation store's info(), and every one must be in the scope. When neither names a bot (no transcripts, and the conversation store no longer has it), a scoped owner gets 404: the admin store has no lookup of a conversation's bot, and the delete fails closed rather than trust the list. Its remaining records go with the retention, or an unscoped owner deletes them, for whom nothing is checked since every bot is in scope.
    • The page shows Delete in a review for an owner only, behind a modal confirmation that says it can't be undone and names what goes. After it, the review closes and the row leaves the list without reloading it.

    As built in 0.8-q4

    Amended on 2026-11-30 (task q4, ADR-0035 decision 6): the permission table gains cases and run-case, the console's Tests view, both developer with the bot in scope, since a run spends tokens; their runs take the playground's limits for the admin. Drafting a test case from a ๐Ÿ‘Ž answer is a reviewer's and calls no action: the page builds it from the review, which now marks ๐Ÿ‘Ž answers with the visitor's comment, a reviewer's to read already.

    Settled with the maintainer (2026-11-29)

    The questions left open in the draft, all settled as recommended. The alternative each one weighed is kept here.

    1. Which role sees the bots' configuration?
      • Settled: reviewer. It spends nothing and holds no secrets (the view is an allowlist, ADR-0032 decision 7, and instructions hold none, T7). Someone reviewing a bad answer needs the instructions to tell a prompt problem from a knowledge problem. It also lets the demo show the Bots view.
      • The alternative, developer (the x1 brief's proposal), keeps the instructions from support staff and agency clients who may not need them.
    2. What does the 0.7 allow array mean?
      • Settled: developer, which is exactly what everyone could do in 0.7. An upgrade grants nobody the new delete, and the array still needs no change.
      • The alternative, owner, keeps "everyone can do everything", but quietly gives every listed user the power to erase visitors' data in a minor release.
    3. How are roles assigned?
      • Settled: the allow map only, no role claim in the identity token (decision 4 gives the reasons).
      • The alternatives: a role claim, which lets the app's own roles flow in without a deploy; or a function form of allow, which does the same while keeping the check in askdare. The function form can come later as an additive option.
    4. The demo: reviewer or viewer?
      • Settled: reviewer. It is still read-only and spends nothing, and the demo then shows what the console is for: conversations, reviews with transcripts, the ๐Ÿ‘Ž comments and the bots' configuration. e1's brief changed from viewer.
      • The alternative, viewer, shows only the dashboard's totals, and leaves out the seeded conversations and transcripts the e1 brief plans.
    5. A scope of several bots: lists per bot, or across them?
      • Settled: per bot in 0.8. A list names one bot from the scope; the dashboard's totals still sum the whole scope. It needs no port change.
      • The alternative: add bots to AdminRange, so one list spans the scope. Postgres finds that easy; Upstash needs a merge of per-bot sorted sets with a composite cursor, and every store needs a contract test.
    6. What does a refused request answer?
      • Settled: 404 not_found, as for an unknown action, bot or conversation. No protocol change, and nothing tells a prober whether an action or bot exists.
      • The alternative: a new forbidden error code (403). Clearer while debugging, but ErrorCode is part of the public protocol, which gains a code only the console uses.
    7. How does core know a dashboard action's role?
      • Settled: AdminDashboard.roles, declared by the add-on, additive, with owner for an action it doesn't name.
      • The alternatives: core keeps a table of the add-on's action names, which ties core to the add-on's internals; or handler values become { role, handle }, a breaking change to a public type.
    8. May an owner be scoped?
      • Settled: yes. An agency's client can then answer deletion requests for their own bot. The super admin is an unscoped owner (decision 6).
      • The alternative: owner always unscoped, so only the app's own team can erase, and a scoped user's deletion request goes through them.

    Consequences

    • Teams can share the console without sharing everything: costs for a manager, conversations for support, spending for developers, erasure for owners, each optionally to some bots.
    • Upgrading from 0.7 changes no one's access. The array means developer, which is everything 0.7 allowed, and ADMIN_SECRET is an owner.
    • A public read-only console becomes possible (0.8-e1), on fictional data.
    • New public API when a1 lands (ADR-0006, a minor changeset):
      • allow also takes the map, with the role and user types from @boldare/askdare/next;
      • AdminDashboard.roles;
      • AdminDashboardRequest.store narrows to the read methods, a type change to a public type that the add-on, its only implementer, meets as it is. The dashboard's handler actions and its mount contract stay internal.
    • Core grows by the permission table, the scoped store view and the sign-in answer's new fields, all server-side; the console's page grows a little to hide what a role can't use. Its 30 KB budget is checked as before.
    • THREAT_MODEL.md: T35 and T36 gain the roles and the scope, and T36's residual risk changes from "visible to every owner" to "visible to reviewers and above" (in a1).
    • Every role and scope gets tests: each action refused below its role and outside the scope, each list limited to the scope, and a change of role or scope ending the session (a1's Definition of Done).
    • What stays the app's: who its users are, signing them in, and keeping allow current. A user removed from the app's sign-in but left in allow can still sign in for as long as the app keeps signing identity tokens for them, as in 0.7.
    • Multi-bot scopes list one bot at a time in 0.8 (decision 3); totals are not affected.

    Alternatives considered

    • Accounts, invitations and role editing in the console. It would need a user store, an invitation flow and a second sign-in beside the app's, all of which ADR-0016 rejected. The app already has users; askdare reads who someone is from it.
    • Permissions instead of roles ({ transcripts: true, playground: false, โ€ฆ } per user). Flexible, but every combination needs a test, a configuration diff is hard to review, and the console has too few actions for it to pay off. Four roles cover the cases the brief names.
    • Roles in the identity token. Weighed in decision 4: it moves grants out of the one place that lists them and makes a token-signing bug an escalation. A function form of allow gives the same flexibility later without that.
    • Scope enforced by each dashboard handler (the a1 brief's first idea). Every handler, and every future one, would have to remember the filter. A scoped store view in core makes forgetting impossible.
    • Ending sessions only when a user is removed, with the token's role refreshed from the configuration mid-session. A page drawn for one role would keep showing it under another, and references sealed under a wider scope would stay open. Ending the session on any change keeps the page and the server in step.
    • A separate read-only console for demos (a flag such as console.readOnly). A second mode to build and test, when a read-only role already exists and the demo's real safeguard is its fictional store.