Repository navigation
feat(discord): route online presence arrivals to agents - #107451
Conversation
There was a problem hiding this comment.
💡 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".
|
|
||
| ### 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. |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| 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; |
There was a problem hiding this comment.
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 👍 / 👎.
26b0162 to
8be1334
Compare
8be1334 to
f40147e
Compare
There was a problem hiding this comment.
💡 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".
| const config = resolveDiscordGuildEntry({ | ||
| guildId: data.guild_id, | ||
| guildEntries: this.params.guildEntries, | ||
| })?.presenceEvents; |
There was a problem hiding this comment.
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 👍 / 👎.
f40147e to
acedb1d
Compare
There was a problem hiding this comment.
💡 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".
| registerDiscordListener( | ||
| params.client.listeners, | ||
| new DiscordPresenceGuildCreateListener(presenceListener), | ||
| ); |
There was a problem hiding this comment.
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 👍 / 👎.
acedb1d to
7cda613
Compare
7cda613 to
e6561b7
Compare
There was a problem hiding this comment.
💡 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".
| const reserved = this.cooldownStore.registerIfAbsent(presenceKey, nowMs, { | ||
| ttlMs: DISCORD_PRESENCE_GREETING_COOLDOWN_MS, | ||
| }); |
There was a problem hiding this comment.
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 👍 / 👎.
|
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. |
|
Merged via squash.
|
|
Post-merge package-boundary regression on current The Discord package compile fails with type errors in the new presence path, including:
None of the reported Discord files are in PR #104692's diff, so I am leaving that Teams branch unchanged. |
) * 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
) * 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
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
presenceEventsconfiguration 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
pnpm check:changedon Testbox: all generated, format, TypeScript, core/extension lint, import-cycle, state, and policy guards passed.