Repository navigation
fix(discord): agent presentation controls stop expiring - #201965
Conversation
Buttons and selects that a message action authors are now stateless: a button carries its core-marked value in its custom id and a select carries it in its option values, so a tap needs no registry entry and survives restarts and the callback TTL. A tap runs the normal sender checks, offers the value to a plugin first, consumes the message's controls, and reaches the conversation's agent as callback_data. The unused legacy agent:/agentsel: system-event handlers are replaced by this path. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR carries agent-authored Discord callback values in controls so supported buttons and selects survive registry expiry and Gateway restarts. Example: Tap an agent-authored Discord button with callback value pick:a after 31 minutes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 3 items remain Keep open: this maintainer-authored PR addresses a real expiry bug, but plugin dispatch can bypass control consumption, and new production assertions fail the safety ratchet. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Discord plugin renders portable presentations into Discord components, admits incoming interactions through existing access checks, offers callbacks to plugins, and dispatches unclaimed values into conversation turns. flowchart LR
A[Message tool presentation] --> B[Discord component renderer]
B --> C[Value carried in control]
C --> D[Discord user interaction]
D --> E[Existing access checks]
E --> F[Plugin dispatcher]
F --> G[Conversation agent]
Technical reviewBest possible solution: Keep stateless encoding and existing admission owners, make control consumption work across plugin response states, and replace unchecked component casts with concrete Discord types. Do we have a high-confidence way to reproduce the issue? Current-main rendering requires registry entries whose default lifetime is 30 minutes, and the resolver rejects expired entries before callback dispatch; no target code was executed. Is this the best way to solve the issue? Carrying short agent-owned values in Discord controls removes the lifetime dependency using existing owners, but the plugin branches must preserve the promised single-use behavior. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6502a5769c0e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -11, Tests -187, Docs +2. Total -196 across 10 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 19, 2026, 1:04 PM ET / 18:04 UTC. |
… tapped A tap removed every action row, so URL buttons and other controls vanished, and `reusable: true` agent buttons worked only once. The tap now removes only the agent's controls, and a reusable button keeps the message as it is. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
A tap on a controls-only message could not remove its controls (Discord rejects empty messages), so every later tap reached the agent again. Disabling keeps the message intact and makes every non-reusable agent control single-use. Co-authored-by: obviyus <[email protected]>
…one group - Disable a single-use agent control before plugin dispatch, so a plugin-handled tap is consumed too; a handler that edits the source message replaces that update. - If any agent value does not fit a stateless id, render all of the presentation's agent controls through the registry, one consumption group. - Give plugin select handlers the selected option labels, as registry selects did. Co-authored-by: obviyus <[email protected]>
…parser The message tool path re-reads the generated spec with readDiscordComponentSpec, which dropped internalCustomId, so agent buttons became registry buttons without a value. Keep agent:/agentsel: ids; approval and question ids stay builder-only. Co-authored-by: obviyus <[email protected]>
|
Maintainer override for head 449bd60. Two checks are red, and this PR caused neither:
Every other check is green, and the local review of this exact head is clean (0 findings). The maintainer approved landing this PR as long as the red checks are shown to be unrelated. |
|
Landed as a757a08. When the agent sends Discord presentation buttons and selects, and every value fits Discord's 100-character id, each control's id now carries its own value, so taps reach the conversation's agent as |
) ## Problem On Discord, a button or select that the agent sends through the `message` tool (`presentation` with `action: { type: "callback" }` or a legacy `value`) stops working 30 minutes after it is sent, and after any Gateway restart that loses the in-memory registry: the tap answers "This component has expired." The agent never sees it. Follow-up to openclaw#201764, which made these taps reach the agent on every channel while the Discord callback is still registered. ## Root cause Discord presentation controls get a random `occomp:cid=<id>` custom id, and the meaning of the tap lives only in the component registry (`extensions/discord/src/components.builders.ts:55-84`, select at `:194-244`), which expires after `agentComponents.ttlMs` (default 30 minutes) and is lost when persistence is unavailable. The resolver then replies "This component has expired." (`extensions/discord/src/monitor/agent-components.ts`, `handleDiscordComponentEvent`). Core already marks agent-authored values (openclaw#201764), so the value alone is enough to route the tap; it was just not carried by the component. ## Solution Agent-authored controls are stateless: - **Send** (`shared-interactive.ts`, `components.builders.ts`): a core-marked callback button gets the custom id `agent:<index>:<marked value>`; a select whose options are all core-marked gets `agentsel:<index>` and keeps the marked values as option values. No registry entry is written. The index keeps ids unique per message (duplicate values, several selects). The send-action parser (`components.parse.ts`, `readDiscordComponentSpec`), which re-reads the generated spec on the `message` tool path, keeps `agent:`/`agentsel:` ids; other internal ids (approvals, questions) stay builder-only. - **Tap** (`monitor/agent-components.system-controls.ts`): the existing `agent`/`agentsel` component handlers, which no code path produced anymore, now handle these ids: 1. the normal sender checks for components (`resolveAuthorizedComponentInteraction`: DM policy, pairing, guild/channel allowlists, policy freshness); 2. single use unless the button sets `reusable: true` (carried in the id as `agent:<index>r:`): the tap response disables the agent's buttons and selects (Discord renders them greyed out and rejects further taps) and keeps the text, media, URL buttons and other controls unchanged; the message can never become empty. This happens before any handler runs, so a plugin-handled tap is single use too; a handler that edits the source message replaces that update; 3. plugin first on the value (the core dispatcher strips the mark); select handlers get the selected option labels in `values`, as registry selects did; 4. the value reaches the conversation's session as `callback_data: <value>` through the same dispatch as registry-backed components. - Native `components` and forms keep the registry and `agentComponents.ttlMs`. ## What was deleted - The legacy `agent:`/`agentsel:` system-event handler body (`[Discord component: … clicked by …]`), `parseAgentComponentData`, `ensureAgentComponentInteractionAllowed`, and their tests. Nothing produced these ids. - Registry writes for agent-authored presentation controls. ## Accepted edges - If any agent button value in a presentation does not fit Discord's 100-character custom id (values over about 90 characters), all of that presentation's agent controls use the registry path, one consumption group as before, and expire as before. Not dropped, not silent. - Buttons sent before this change keep their registry entries and expire as before. - A tap goes to the conversation's session (the normal inbound route of the channel and sender), not to the session that sent the message. This matches Telegram, Mattermost and Feishu after openclaw#201764, and it is what the agent-controls design specifies ("stateless taps re-run normal inbound auth and resolve the conversation session"). Before, Discord routed to the sender's session through the registry entry, which is the state that expires. Controls sent into a channel from another session (for example, a cron run) now reach that channel's session. ## Local review - `[P2]` reusable buttons, `[P2]` URL buttons kept, `[P2]` empty container, `[P2]` controls-only message stayed tappable: fixed, with tests (consumed controls are now disabled instead of removed). - `[P2]` plugin-handled tap skipped consumption, `[P2]` mixed short and long values, `[P2]` stateless select lost `values` for plugin handlers: fixed, with tests (red on `71786b2`, green on head). - `[P1]` send parser dropped the generated agent ids on the `message` tool path (the earlier tests bypassed the parser): fixed. The tests now render through `readDiscordComponentSpec`; without the parser fix 8 of 11 fail. - `[P1]` sender session route: conversation-session routing approved by the maintainer, see accepted edges. ## Tests (red on base `2887e01d8fa9`, green on head) `extensions/discord/src/monitor/monitor.agent-components.test.ts` renders a core-marked presentation through the real builders, clears the in-memory and persistent registry (restart or TTL expiry), and routes the tap to the registered control the way the Discord client resolves custom ids. | Test | Base | Head | |---|---|---| | typed callback button after the registry is gone → `callback_data: pick:a`, controls removed, plugin offered `::pick:a` | ✗ "This component has expired." | ✓ | | legacy value button after the registry is gone → `callback_data: /pick a` | ✗ "This component has expired." | ✓ | | select choice after the registry is gone → `callback_data: size:m` | ✗ | ✓ | | tapper outside the allowlist → "You are not authorized to use this button.", no dispatch | ✗ | ✓ | | duplicate values and two selects in one message → distinct custom ids | ✓ (guard) | ✓ | Gates: Discord extension suite, `pnpm tsgo:extensions`, `pnpm check:test-types`, oxlint and oxfmt on changed files. - `monitor.agent-components.test.ts`: tapping an agent button disables it and keeps a URL button in the same row; a `reusable` agent button leaves the message unchanged and still delivers `callback_data: refresh`; a controls-only message has its control disabled, so a second tap cannot fire ; a plugin-claimed tap disables the control and the handler runs once; a select handler gets `values: ["Medium"]`; a presentation with one value too long for an id renders every agent control through the registry, in either order (added after local review). ## E2E Not run live. Discord component clicks need a real user client: bots cannot click components, and the Discord E2E skill treats component clicks as manual (`.agents/skills/discord-e2e/features.md`). No computer-control node was available for a manual click. A maintainer can verify by sending a presentation button with the `message` tool, restarting the Gateway (or waiting 30 minutes), and tapping it. ## Size - Production: +115 / −126 (net **−11**). - Tests/docs: −185 net (legacy handler tests removed). Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
On Discord, a button or select that the agent sends through the
messagetool (presentationwithaction: { type: "callback" }or a legacyvalue) stops working 30 minutes after it is sent, and after any Gateway restart that loses the in-memory registry: the tap answers "This component has expired." The agent never sees it. Follow-up to #201764, which made these taps reach the agent on every channel while the Discord callback is still registered.Root cause
Discord presentation controls get a random
occomp:cid=<id>custom id, and the meaning of the tap lives only in the component registry (extensions/discord/src/components.builders.ts:55-84, select at:194-244), which expires afteragentComponents.ttlMs(default 30 minutes) and is lost when persistence is unavailable. The resolver then replies "This component has expired." (extensions/discord/src/monitor/agent-components.ts,handleDiscordComponentEvent). Core already marks agent-authored values (#201764), so the value alone is enough to route the tap; it was just not carried by the component.Solution
Agent-authored controls are stateless:
shared-interactive.ts,components.builders.ts): a core-marked callback button gets the custom idagent:<index>:<marked value>; a select whose options are all core-marked getsagentsel:<index>and keeps the marked values as option values. No registry entry is written. The index keeps ids unique per message (duplicate values, several selects). The send-action parser (components.parse.ts,readDiscordComponentSpec), which re-reads the generated spec on themessagetool path, keepsagent:/agentsel:ids; other internal ids (approvals, questions) stay builder-only.monitor/agent-components.system-controls.ts): the existingagent/agentselcomponent handlers, which no code path produced anymore, now handle these ids:resolveAuthorizedComponentInteraction: DM policy, pairing, guild/channel allowlists, policy freshness);reusable: true(carried in the id asagent:<index>r:): the tap response disables the agent's buttons and selects (Discord renders them greyed out and rejects further taps) and keeps the text, media, URL buttons and other controls unchanged; the message can never become empty. This happens before any handler runs, so a plugin-handled tap is single use too; a handler that edits the source message replaces that update;values, as registry selects did;callback_data: <value>through the same dispatch as registry-backed components.componentsand forms keep the registry andagentComponents.ttlMs.What was deleted
agent:/agentsel:system-event handler body ([Discord component: … clicked by …]),parseAgentComponentData,ensureAgentComponentInteractionAllowed, and their tests. Nothing produced these ids.Accepted edges
Local review
[P2]reusable buttons,[P2]URL buttons kept,[P2]empty container,[P2]controls-only message stayed tappable: fixed, with tests (consumed controls are now disabled instead of removed).[P2]plugin-handled tap skipped consumption,[P2]mixed short and long values,[P2]stateless select lostvaluesfor plugin handlers: fixed, with tests (red on71786b2, green on head).[P1]send parser dropped the generated agent ids on themessagetool path (the earlier tests bypassed the parser): fixed. The tests now render throughreadDiscordComponentSpec; without the parser fix 8 of 11 fail.[P1]sender session route: conversation-session routing approved by the maintainer, see accepted edges.Tests (red on base
cd2ae19272a3, green on head)extensions/discord/src/monitor/monitor.agent-components.test.tsrenders a core-marked presentation through the real builders, clears the in-memory and persistent registry (restart or TTL expiry), and routes the tap to the registered control the way the Discord client resolves custom ids.callback_data: pick:a, controls removed, plugin offered::pick:acallback_data: /pick acallback_data: size:mGates: Discord extension suite,
pnpm tsgo:extensions,pnpm check:test-types, oxlint and oxfmt on changed files.monitor.agent-components.test.ts: tapping an agent button disables it and keeps a URL button in the same row; areusableagent button leaves the message unchanged and still deliverscallback_data: refresh; a controls-only message has its control disabled, so a second tap cannot fire ; a plugin-claimed tap disables the control and the handler runs once; a select handler getsvalues: ["Medium"]; a presentation with one value too long for an id renders every agent control through the registry, in either order (added after local review).E2E
Not run live. Discord component clicks need a real user client: bots cannot click components, and the Discord E2E skill treats component clicks as manual (
.agents/skills/discord-e2e/features.md). No computer-control node was available for a manual click. A maintainer can verify by sending a presentation button with themessagetool, restarting the Gateway (or waiting 30 minutes), and tapping it.Size