Skip to content

Discord: fix /codex_resume identity resolution in brand-new threads#35

Open
huntharo wants to merge 1 commit intopwrdrvr:mainfrom
huntharo:codex/fix-resume-race-new-discord-thread
Open

Discord: fix /codex_resume identity resolution in brand-new threads#35
huntharo wants to merge 1 commit intopwrdrvr:mainfrom
huntharo:codex/fix-resume-race-new-discord-thread

Conversation

@huntharo
Copy link
Contributor

Summary

Fixes /cas_resume failing on the first attempt in brand-new Discord threads by correcting the identity resolution in toConversationTargetFromCommand().

Why this matters

From #30: in a brand-new Discord thread, sending a first message before the agent has replied causes /cas_resume to show a generic "No active Codex sessions found" reply, with the picker only appearing ~40 seconds later via a retry.

Root cause: the slash interaction placed the slash user identity (e.g. slash:user-id) in ctx.from, with the real channel target in ctx.to. The expression ctx.from ?? ctx.to evaluated to "slash:user-id" (truthy string). normalizeDiscordConversationId() maps any slash: prefix to undefined, so toConversationTargetFromCommand() returned null — and the command could not resolve a conversation target for the picker.

Changes

src/controller.ts, toConversationTargetFromCommand() (line ~274): when ctx.from starts with "slash:", use ctx.to as the channel source instead of ctx.from. Established-channel behavior is unchanged — when ctx.from holds a discord:channel: or channel: identity, it continues to take precedence.

-    const conversationId = normalizeDiscordConversationId(ctx.from ?? ctx.to);
+    const sourceId = ctx.from?.startsWith("slash:") ? ctx.to : (ctx.from ?? ctx.to);
+    const conversationId = normalizeDiscordConversationId(sourceId);

Testing

Added a regression test in src/controller.test.ts with ctx.from = "slash:user-1" and ctx.to = "discord:channel:chan-1" — asserts the thread picker is sent to the correct channel identity ("channel:chan-1"), not a null target.

All 122 tests pass (pnpm typecheck + pnpm test).

Fixes #30

This contribution was developed with AI assistance (Claude Code).

In brand-new Discord threads, the slash interaction can set ctx.from to the
slash user identity (e.g. "slash:user-id") while the real channel target is
in ctx.to. The previous ctx.from ?? ctx.to expression normalized a slash
identity to undefined, causing toConversationTargetFromCommand() to return
null and /cas_resume to fail on the first attempt.

Fix: when ctx.from starts with "slash:", use ctx.to as the channel source
instead. The existing behavior for established channels (ctx.from holds the
channel identity) is unchanged.

Adds a regression test covering the brand-new-thread scenario.

Fixes pwrdrvr#30
Copy link

@mvanhorn mvanhorn left a comment

Choose a reason for hiding this comment

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

Summary

Traced through the fix and the regression test. The slash: prefix check correctly falls through to ctx.to for channel resolution, and the existing if (!conversationId) return null guard covers the case where ctx.to is also missing. Established-channel paths are untouched.

Recommendation

Looks good to merge.


Review assisted by Claude Code

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.

Plugin: fix /codex_resume race in brand-new Discord threads

2 participants