Skip to content

fix(discord): preserve channel session keys via channel_id fallbacks#17622

Merged
thewilloftheshadow merged 3 commits intomainfrom
fix/discord-session-key-continuity
Feb 16, 2026
Merged

fix(discord): preserve channel session keys via channel_id fallbacks#17622
thewilloftheshadow merged 3 commits intomainfrom
fix/discord-session-key-continuity

Conversation

@shakkernerd
Copy link
Member

@shakkernerd shakkernerd commented Feb 16, 2026

Summary

This is a focused first-pass fix for Discord session continuity issues reported in #16333 and #16979.

  • Added canonical Discord channel ID resolution that falls back in order:
    • message.channelId
    • message.channel_id
    • message.rawData.channel_id
    • event payload channel_id
  • Threaded that canonical messageChannelId through Discord preflight and processing so routing/session/history/reply paths no longer depend on a single runtime field shape.
  • Updated Discord threading + auto-thread paths to use the same canonical channel ID for thread/session context and API calls.
  • Updated route ID normalization to safely coerce runtime number/bigint IDs into stable string IDs for session keys.
  • Updated diagnostic state correlation so session state keyed by sessionKey is reused when later looked up by sessionId, and PI embedded runner now emits session state transitions with sessionKey where available.
  • Added targeted regression tests for channel-id fallback resolution, process-path channel-id fallback behavior, route numeric-id coercion, and diagnostic state reuse.

Verification

  • bunx vitest run --config vitest.unit.config.ts src/discord/monitor/message-utils.test.ts src/discord/monitor/message-handler.process.test.ts src/logging/diagnostic.test.ts src/routing/resolve-route.test.ts
  • bunx vitest run --config vitest.unit.config.ts src/discord/monitor/message-handler.inbound-contract.test.ts src/discord/monitor/monitor.test.ts
  • pnpm tsgo
  • pnpm check

Related

Greptile Summary

This PR fixes Discord session continuity by implementing canonical channel ID resolution with multiple fallbacks (message.channelIdmessage.channel_idmessage.rawData.channel_id → event payload channel_id). The changes thread this messageChannelId through preflight, processing, threading, and auto-thread creation paths to ensure consistent session keys regardless of runtime field shape variations.

Key improvements:

  • Added resolveDiscordMessageChannelId() helper with numeric type coercion support
  • Updated normalizeId() in route resolution to handle number/bigint types for stable session keys
  • Enhanced diagnostic session state correlation to reuse state keyed by sessionKey when looked up by sessionId
  • Updated Pi embedded runner to emit session state transitions with sessionKey where available
  • Added comprehensive regression tests covering fallback resolution, numeric ID coercion, and state reuse

The implementation is solid with proper type handling and fallback chains. Test coverage is strong across the critical paths.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured with clear intent to fix session continuity issues. The implementation adds proper fallback chains without breaking existing logic, includes comprehensive test coverage for the new behavior, and maintains backward compatibility. The type handling for numeric IDs is correct, and the threading of messageChannelId through all paths is systematic and complete.
  • No files require special attention

Last reviewed commit: b8b2805

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +17 to +22
it("falls back to message.rawData.channel_id", () => {
const channelId = resolveDiscordMessageChannelId({
message: asMessage({ rawData: { channel_id: "456" } }),
});
expect(channelId).toBe("456");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

missing test case for message.channel_id fallback (the second fallback in the chain)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/message-utils.test.ts
Line: 17:22

Comment:
missing test case for `message.channel_id` fallback (the second fallback in the chain)

How can I resolve this? If you propose a fix, please make it concise.

@github-actions
Copy link

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@thewilloftheshadow thewilloftheshadow self-assigned this Feb 16, 2026
@thewilloftheshadow thewilloftheshadow added the channel: discord Channel integration: discord label Feb 16, 2026
@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Feb 16, 2026
@github-actions
Copy link

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

1 similar comment
@github-actions
Copy link

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@thewilloftheshadow thewilloftheshadow force-pushed the fix/discord-session-key-continuity branch from 5056113 to 8d3fd4b Compare February 16, 2026 02:24
@thewilloftheshadow thewilloftheshadow merged commit 09566b1 into main Feb 16, 2026
10 checks passed
@thewilloftheshadow thewilloftheshadow deleted the fix/discord-session-key-continuity branch February 16, 2026 02:30
@github-actions
Copy link

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

treygoff24 pushed a commit to treygoff24/openclaw that referenced this pull request Feb 16, 2026
…penclaw#17622)

* fix(discord): preserve channel session keys via channel_id fallbacks

* docs(changelog): add discord session continuity note

* Tests: cover discord channel_id fallback

---------

Co-authored-by: Shadow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments