refactor(discord): unify custom-id value codecs into one shared module#104334
Merged
Conversation
Contributor
Author
|
Validation (Blacksmith Testbox through Crabbox):
|
Contributor
Author
|
Merged via squash.
|
chenyangjun-xy
pushed a commit
to chenyangjun-xy/openclaw
that referenced
this pull request
Jul 11, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #104318
What Problem This Solves
Discord's interactive component custom-id values were encoded and decoded by four independently maintained codec copies (exec approvals, model picker, native command-arg menus, agent components) plus a fifth, deliberately different minimal-escape scheme for the versioned
occomp/ocmodalgrammar. The copies had already drifted in shape (plain try/catch vs guarded decode) and the same-name-different-behavior functions (encodeCustomIdValuemeant different escaping depending on the file) made cross-use a latent wire-corruption hazard for button/select callback values.Why This Change Was Made
One shared
custom-id-codec.tsnow owns both schemes under distinct names: the URI-component pair (encode/decodeCustomIdComponent, decode falls back to the raw value because Discord redelivers old component ids indefinitely) and the versioned minimal field escape for theoccompgrammar (escape/unescapeCustomIdFieldValue, kept separate on purpose — it preserves the 100-char custom-id budget and itse=1wire format must keep decoding byte-exactly). All six call sites migrated; zero wire-format change: every historical custom id decodes identically before and after.User Impact
No behavior change. Removes a class of future bugs where a button's callback value (e.g.
env|prod) round-trips differently depending on which Discord surface rendered it.Evidence
extensions/discord/src/custom-id-codec.test.ts(malformed-percent fallback, case-insensitive legacy escapes, separator-safety).pnpm check:changedon Blacksmith Testbox (run id in comments below).git diff --numstat: net negative prod LOC (four codec copies deleted, one shared module added).