fix(discord): default bare numeric IDs to channel kind, classify ambiguous recipient as permanent error#30198
fix(discord): default bare numeric IDs to channel kind, classify ambiguous recipient as permanent error#30198jini92 wants to merge 2 commits intoopenclaw:mainfrom
Conversation
Default bare numeric Discord IDs to channel kind instead of throwing ambiguous recipient errors. Also classify ambiguous recipient as a permanent delivery error to prevent infinite retry queue buildup. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64f52ff9f9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| function parseRecipient(raw: string): DiscordRecipient { | ||
| const target = parseDiscordTarget(raw, { | ||
| defaultKind: "channel", |
There was a problem hiding this comment.
Apply bare-ID default in active recipient parser
Setting defaultKind: "channel" inside parseRecipient does not fix the outbound send flow, because the code paths that actually send messages (parseAndResolveRecipient callers in src/discord/send.outbound.ts) never use parseRecipient; they still construct parseOptions without defaultKind and then call parseDiscordTarget(raw, parseOptions), which continues to throw on bare numeric IDs. In practice, bare IDs still fail delivery, and with the new permanent-error classification they are now dropped immediately instead of retried, so the intended behavior change is still not applied where users send messages.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes the delivery-queue retry-loop caused by bare numeric Discord IDs throwing "Ambiguous Discord recipient" errors. The synchronous Key changes:
Confidence Score: 3/5
Last reviewed commit: 64f52ff |
Additional Comments (1)
The fix adds
Any caller that routes through Prompt To Fix With AIThis is a comment left during a code review.
Path: src/discord/send.shared.ts
Line: 88-90
Comment:
**`parseAndResolveRecipient` still throws for bare numeric IDs**
The fix adds `defaultKind: "channel"` to the synchronous `parseRecipient`, but the async `parseAndResolveRecipient` (used for programmatic/username-resolved sends) builds its `parseOptions` without `defaultKind`. Tracing through `resolveDiscordTarget` in `targets.ts`:
1. For a bare numeric ID like `"1466624220632059934"`, `safeParseDiscordTarget` swallows the throw and returns `undefined`.
2. `isLikelyUsername` returns `false` (the regex `/[\d]+$/` matches pure numeric strings).
3. `shouldLookup` is `false`.
4. The function reaches `return directParse ?? parseDiscordTarget(trimmed, parseOptions)`, where `directParse` is `undefined`, so it calls `parseDiscordTarget` with **no `defaultKind`** — which **throws** the ambiguous error.
Any caller that routes through `parseAndResolveRecipient` will still hit the retry-loop bug. The fix should be applied here as well:
```suggestion
const parseOptions = {
defaultKind: "channel" as const,
ambiguousMessage: `Ambiguous Discord recipient "${trimmed}". Use "user:${trimmed}" for DMs or "channel:${trimmed}" for channel messages.`,
};
```
How can I resolve this? If you propose a fix, please make it concise. |
|
Good catch - applied the same defaultKind=channel fix to parseAndResolveRecipient (async path) as well. Pushed in 8f3a979. |
|
Superseded by #33142 which consolidates the fixes from this PR. Closing this in favor of that PR. |
Summary
1466624220632059934) thrown as "Ambiguous Discord recipient" errors, causing messages to accumulate in the delivery queue with infinite retries.parseRecipientinsend.shared.tsnow defaults bare numeric IDs tochannelkind instead of throwing ambiguous errors. (2)delivery-queue.tsclassifies "ambiguous discord recipient" as a permanent error to stop retry loops if the error ever surfaces through another path.user:ID,channel:ID) is unchanged.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Bare numeric Discord IDs passed to
--targetorto:now resolve to a channel instead of erroring. Users who previously neededchannel:IDprefix for programmatic sends can now use the raw ID.Security Impact (required)
Repro + Verification
Environment
Steps
channel: "1466624220632059934")Expected
Actual (before fix)
Ambiguous Discord recipient "1466624220632059934"error thrownEvidence
Before fix:
After fix: message delivered without error.
Also cleared 7 accumulated messages from delivery queue after applying the fix.
Human Verification (required)
channel:IDprefix (unchanged), explicituser:IDprefix (unchanged)Compatibility / Migration
channel:/user:prefixes still work as before; only bare IDs change behavior (was error, now defaults to channel)Failure Recovery (if this breaks)
defaultKind: "channel"fromsend.shared.tsand the/ambiguous discord recipient/ientry fromdelivery-queue.tsuser:prefixRisks and Mitigations
user:ID.