Skip to content

Allow for this chat: a granted bot's offers go with no Send; offers expire and report back - #2497

Merged
TheAnimatrix merged 3 commits into
masterfrom
issue-2490-chat-grant
Nov 30, 2026
Merged

TheAnimatrix merged 3 commits into
masterfrom
issue-2490-chat-grant

Conversation

@TheAnimatrix

@TheAnimatrix TheAnimatrix commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Stage 1 (#2496) lets a bot on another computer offer a message for a bot on the computer you write from, and you press Send on each one. Three gaps were left: offers never expired, the offering bot's chat never learned what happened, and Make private on another computer's bot left that bot taking offers there. Pressing Send on every message is also slow when you trust the conversation you're in.

Change

This is the backend for Allow for this chat. The window UI comes in the next PR.

  • The grant. While a PC window shows a Mac bot's chat, a person there can allow up to 8 of the PC's bots (bots.remote.grantOpen). While the grant is open, what the Mac bot offers one of them is kept on the PC with no Send, if it came from a turn that window's message started. It goes through the same commit as Send: same checks, caps and one-receipt dedupe; a quiet notice; no turn started; no reply. An offer to a bot outside the grant still waits for Send. Messages only.

  • Where it lives. The grant lives only in the PC's memory (ChatGrants). It is bound to the window's connection and to that window showing the chat. Other windows can read its state (bots.remote.grantState), but they can't end it or take it over (grant_elsewhere).

  • Run tokens. Each message from the granting window gets a fresh token from the PC's router (run, bots.chat.send version 4). A window can never supply one. The Mac stamps the token on that turn's offers, and only the device each offer is for sees it. The PC sends an offer on its own only when:

    • the token is held by the open grant;
    • to names exactly one of the grant's bots.

    A forged token, a replayed one, or one from an ended grant is held by no grant, so that offer expires. If a message without a token (another window, another device) joins the turn, it takes the token off. A resend of the same message carries the token it was first sent with, so the Mac takes it as the same message.

  • When it ends:

    • End access, or the window leaving the chat or closing;
    • 10 minutes with no message from that window, or 1 hour after it opened;
    • the chat stream ending, starting again or replaying from its copy;
    • Make private of a granted bot, or any change from here to who reaches the offering bot;
    • blocking the Mac, or the Mac no longer listing the bot.

    Every one of these wins over a send in progress, because the last check and the commit run with nothing awaited between them. Offers left unsent under the grant expire. Reconnecting or another window needs a new Allow.

  • What the Mac hears. The Mac's offer card now has a state.

    • It starts queued for a PC that reports (offers: 2) and unsupported for an older PC (offers: 1). An older PC keeps stage 1's Send, with nothing wider.
    • The PC reports delivered (with the bot's name), busy (the hourly cap, under a grant) or expired, through bots.offers.outcome. The Mac takes a report only from the device the offer is for, and delivered is final.
    • A lost report is sent again when the offer next comes into the PC's copy, and on a timer up to 4 more times.
    • A card still queued after a day shows unknown.
  • Expiry. An offer expires a day after it was made, or when the grant it was made under ends. Send then answers offer_expired.

  • Make private of a Mac bot from the PC now also closes that bot's offers on the Mac (bots.devices.set with offers: false, version 2). An older Mac is sent the access change alone.

  • Hourly cap. It now counts receipts instead of chat rows, so clearing a chat no longer makes room for more.

  • Person-only methods trust a connection's self-declared gui label, which any local client with the owner token can claim #2052 (Send trusts the declared window type) is unchanged. A grant adds nothing a window couldn't already do with Send, and it is bound to that window's connection and its open chat. Binding "a window" to a real window is still Person-only methods trust a connection's self-declared gui label, which any local client with the owner token can claim #2052's job.

  • Docs. docs/bots.md → "Offered messages" now has "Allow for this chat", the end rules, expiry, outcomes and remote Make private.

How to review

  1. src/shared/bots/personal/offers.ts: tokens, states, times, grant refusals.
  2. src/mms/bridge/routed/chatGrants.ts: the grant itself, its tokens and timers.
  3. BotRouter.ts, the "Offered messages" part: commitOffer, observed (auto-delivery), tellOutcome, the end rules and grantOpen. This is where the risk is.
  4. The Mac side: BotEngine.offerBotMessage and recordOfferOutcome, BotChatService (the token on the turn, narrowOwnerRun on join), and RemoteBots.ts (bots.offers.outcome, remote Make private).

Verification

  • Safe because the PC sends nothing on its own unless the offer carries a token the PC's own router issued to the granting window, and that grant is still open at the commit. The proof is tests/netEngine/checks/offeredMessagesOneWay.test.ts, which runs two real daemons paired one way. It shows:
    • Auto-delivery happens once, and the Mac hears it.
    • A second window sees the grant, can't end it, and its messages carry no token.
    • A forged token expires the offer.
    • A lost report is told again.
    • An older Mac is refused with grant_unsupported.
    • The grant ends on Make private, a block, removal, the PC's networking restarting and the Mac going away. What it left unsent expires, and the next message carries no token.
    • The Mac never calls the PC.
  • tests/bots/offeredMessagesGrant.test.ts covers:
    • open refusals;
    • auto-delivery and the report;
    • another window, a joined turn, a resend and a forged token;
    • every end rule, plus a revoke and a block while a Send waits;
    • expiry by time;
    • lost reports, by the stream and by the timer;
    • reports from another device;
    • remote Make private and older peers.
  • tests/net/bridge/routed/chatGrants.test.ts covers tokens, idle and hard expiry, and ending once.
  • node scripts/verify.mjs <38 affected test files> --max-failures 40 ran on b7ca302: 787 of 788 tests pass. The one failure, tests/gitAccessTable.test.ts, timed out under load and passes alone (6 of 6). tests/gitDaemonMethods.test.ts (Git hooks and pushes, slow on this PC) passes alone on this branch, 39 of 39, as on master.
  • Both typechecks pass on b7ca302 (--typecheck all).
  • After the review, new checks cover:
    • a grant opened later trying to take over a turn an ended grant started;
    • End access pressed while an Allow waits;
    • a grant past its time with its timer late;
    • an older PC reading its card in stage 1's shape;
    • expired being final;
    • Send reporting expiry.
  • Not checked: the installed app on two real computers, and a real model under a grant.

Notes

The UI (picker, active state, End access and per-message states) comes next, then the bot guidance wording. Until then, the bot_offer result still tells the bot that its offer waits for Send, which is wrong for one sent under a grant; the guidance PR changes it.

The plan was read against master before coding. Its points that touched this code are fixed here: a silent reconnect ends the grant, a second window's message can't ride a granted turn, a resend keeps its first token, lost reports are retried on a timer, and the hourly cap survives a cleared chat.

The review pass found six points, all fixed in b7ca302:

  • A joined turn keeps its own token, so a later grant can't take it over.
  • An older PC gets its card without the new fields, which its parser refused, so its Send kept failing.
  • A grant past its time ends when read, even if its timer is late.
  • End access wins over an Allow still waiting.
  • Expired is final on the Mac, so a late busy can't overwrite it.
  • Send reports expiry when it finds it.

A third device on stage 1 that reads a stage-2 offer card (one for another device) drops the card, because its parser refuses the new fields. It had no Send on it anyway, and the row's words still show.

Refs #2490

…Send; offers expire and their computer hears what became of them

A PC window showing another computer's bot chat can allow it for up to 8 bots here. While the grant is open, offers to those bots from turns that window's messages started are kept with no Send, through the same commit as Send. The grant lives on the PC alone, bound to the window and to a run token its router issues per message; it ends on End access, leaving or closing, idle and hard expiry, the stream ending or replaying, Make private, a block or removal. Offers expire after a day or when their grant ends; the offering computer hears delivered, busy or expired; Make private of another computer's bot closes its offers there.
… offers in its own shape; grants end at their time when read; End access wins over a pending Allow; expired is final and Send reports it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant