Skip to content

feat(discord): route online presence arrivals to agents - #107451

Merged
steipete merged 10 commits into
mainfrom
feat/discord-online-presence-events
Jul 14, 2026
Merged

steipete merged 10 commits into
mainfrom
feat/discord-online-presence-events

Conversation

@steipete

@steipete steipete commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Discord agents cannot currently receive a routed event when a human member becomes newly available online, so they cannot proactively greet that person with relevant memory, wiki, local-time, or timezone context.

Why This Change Was Made

Add an opt-in per-guild presenceEvents configuration that converts observed offline-to-online and first-seen online arrivals into immutable-ID system events. The Discord plugin seeds complete gateway snapshots, handles reconnect and guild lifecycle invalidation, rejects bots, atomically preserves an eight-hour durable cooldown across overlapping listener generations, and wakes the routed agent through the normal heartbeat contract.

User Impact

Operators can choose one Discord channel for context-aware presence greetings. The agent receives only immutable user, guild, and channel IDs, must retrieve safe context itself, and may stay silent when a greeting is inappropriate. Large or incomplete guild snapshots remain conservative until an explicit offline transition is observed.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Jul 14, 2026
@steipete steipete self-assigned this Jul 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e39ca1252b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md Outdated

### Changes

- **Discord presence arrivals:** optionally route observed offline-to-online and first-seen online member events into a configured guild channel so agents can retrieve person and timezone context before sending a bounded greeting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove normal feature entries from CHANGELOG.md

Root AGENTS.md says CHANGELOG.md is release-only and that release generation owns it; this normal Discord feature commit adds an Unreleased entry directly, which can contaminate generated release notes and conflict with the release flow. Please move this release-note context to the PR body or squash message instead of editing the changelog here.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack app: web-ui App: web-ui scripts Repository scripts commands Command implementations agents Agent runtime and tooling plugin: workboard fleet labels Jul 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5782161173

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +244 to +249
const availabilityKind = this.presenceBaseline.isOffline(presenceScope, presenceKey)
? "observed-offline"
: this.guildPresenceState.get(data.guild_id)?.inferUnknownAsNewlyAvailable === true &&
!this.presenceBaseline.isOnline(presenceScope, presenceKey)
? "first-seen-after-snapshot"
: null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Serialize Discord presence snapshots before updates

When live Gateway traffic is queued, this branch can read guildPresenceState before the preceding GUILD_CREATE snapshot has seeded it: extensions/discord/src/internal/gateway.ts:290-296 fires each dispatch without awaiting it, and extensions/discord/src/internal/event-queue.ts:105-118 runs queued listener jobs concurrently. In that startup/reconnect ordering, a first online update for an unseen member gets availabilityKind = null here, is ignored, and is recorded as online, so the configured first-seen presence greeting is permanently missed until that user later goes offline and online again.

Useful? React with 👍 / 👎.

@steipete
steipete requested a review from a team as a code owner July 14, 2026 12:40
@steipete
steipete requested a review from a team as a code owner July 14, 2026 12:42
@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost channel: telegram Channel integration: telegram extensions: acpx channel: qqbot channel: qa-channel Channel integration: qa-channel labels Jul 14, 2026
@steipete
steipete force-pushed the feat/discord-online-presence-events branch from 26b0162 to 8be1334 Compare July 14, 2026 12:43
@openclaw-barnacle openclaw-barnacle Bot removed channel: mattermost Channel integration: mattermost channel: slack Channel integration: slack channel: telegram Channel integration: telegram app: web-ui App: web-ui scripts Repository scripts commands Command implementations agents Agent runtime and tooling labels Jul 14, 2026
@steipete
steipete force-pushed the feat/discord-online-presence-events branch from 8be1334 to f40147e Compare July 14, 2026 12:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f40147e64b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +228 to +231
const config = resolveDiscordGuildEntry({
guildId: data.guild_id,
guildEntries: this.params.guildEntries,
})?.presenceEvents;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve presence config for non-ID guild entries

When a Discord config uses a slug key or the existing "*" guild wildcard instead of the numeric guild ID, this lookup returns null because resolveDiscordGuildEntry only reaches its slug/wildcard branches when a guild object is supplied. Those guild keys are still schema-accepted and supported by sibling Discord paths, so presenceEvents under them is silently ignored: snapshots are not seeded and offline-to-online updates never enqueue a wake.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the feat/discord-online-presence-events branch from f40147e to acedb1d Compare July 14, 2026 13:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acedb1de9b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +310 to +313
registerDiscordListener(
params.client.listeners,
new DiscordPresenceGuildCreateListener(presenceListener),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Register presence snapshot listeners before connecting

When presence events are enabled, these snapshot listeners are added only from registerDiscordMonitorListeners, but the gateway client is already constructed and starts connecting in createDiscordMonitorClient before fetchDiscordBotIdentity completes (extensions/discord/src/monitor/provider.ts:432-448, then :487-560). If Discord delivers the initial READY/GUILD_CREATE during that REST call, no presence Ready/GuildCreate listener exists yet, so the startup snapshot is never seeded and first-seen online arrivals are suppressed until an explicit offline transition. Please either include these listeners in the initial client listener set or delay the gateway connection until after they are registered.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the feat/discord-online-presence-events branch from acedb1d to 7cda613 Compare July 14, 2026 13:43
@steipete
steipete force-pushed the feat/discord-online-presence-events branch from 7cda613 to e6561b7 Compare July 14, 2026 14:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6561b75b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +286 to +288
const reserved = this.cooldownStore.registerIfAbsent(presenceKey, nowMs, {
ttlMs: DISCORD_PRESENCE_GREETING_COOLDOWN_MS,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid cooling down evicted presence events

When more than 20 presence arrivals target the same routed session before the heartbeat drains, enqueueSystemEvent still returns true while the shared system-event queue evicts the oldest entries after MAX_EVENTS in src/infra/system-events.ts. Since this reserves the eight-hour cooldown before enqueueing and never learns that an older queued greeting was shifted out, those evicted users receive no prompt but are suppressed until the cooldown expires. Consider only claiming cooldown for deliverable events or aggregating/back-pressuring this burst path.

Useful? React with 👍 / 👎.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready.

Final proof:

Known proof gap: the real Discord presence transition and personalized greeting require the merged build to be deployed to Molty's gateway. That post-merge live validation is queued immediately after landing.

@steipete
steipete merged commit f59a035 into main Jul 14, 2026
108 checks passed
@steipete
steipete deleted the feat/discord-online-presence-events branch July 14, 2026 14:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@jimmypuckett

Copy link
Copy Markdown
Contributor

Post-merge package-boundary regression on current main (observed while validating unrelated Teams PR #104692):

pnpm run test:extensions:package-boundary:compile

The Discord package compile fails with type errors in the new presence path, including:

  • presence-events.ts: config resolves as {} (enabled, users, and channelId missing)
  • provider.ts / provider.interactions.ts / voice/access.ts: DiscordGuildEntry is not assignable to DiscordGuildEntryResolved because required presenceEvents is missing

None of the reported Discord files are in PR #104692's diff, so I am leaving that Teams branch unchanged.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 15, 2026
)

* feat(discord): add online presence agent events

* fix(discord): harden presence event payloads

* fix(discord): satisfy presence lint contracts

* fix(heartbeat): run notification event wakes

* fix(discord): use wake heartbeat contract

* fix(discord): harden presence snapshot delivery

* chore: remove release-owned changelog entry

* fix(discord): remove unused presence type export

* fix(discord): keep presence config below loc limit

* fix(discord): reserve presence cooldown atomically
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
)

* feat(discord): add online presence agent events

* fix(discord): harden presence event payloads

* fix(discord): satisfy presence lint contracts

* fix(heartbeat): run notification event wakes

* fix(discord): use wake heartbeat contract

* fix(discord): harden presence snapshot delivery

* chore: remove release-owned changelog entry

* fix(discord): remove unused presence type export

* fix(discord): keep presence config below loc limit

* fix(discord): reserve presence cooldown atomically
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants