Skip to content

refactor(discord): unify custom-id value codecs into one shared module#104334

Merged
steipete merged 1 commit into
mainfrom
claude/chanref-p0-discord-customid
Jul 11, 2026
Merged

refactor(discord): unify custom-id value codecs into one shared module#104334
steipete merged 1 commit into
mainfrom
claude/chanref-p0-discord-customid

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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/ocmodal grammar. The copies had already drifted in shape (plain try/catch vs guarded decode) and the same-name-different-behavior functions (encodeCustomIdValue meant 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.ts now 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 the occomp grammar (escape/unescapeCustomIdFieldValue, kept separate on purpose — it preserves the 100-char custom-id budget and its e=1 wire 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

  • Round-trip + historical-payload tests in extensions/discord/src/custom-id-codec.test.ts (malformed-percent fallback, case-insensitive legacy escapes, separator-safety).
  • Targeted Discord component/picker/approval/command-arg suites + pnpm check:changed on Blacksmith Testbox (run id in comments below).
  • git diff --numstat: net negative prod LOC (four codec copies deleted, one shared module added).

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: M maintainer Maintainer-authored PR labels Jul 11, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Validation (Blacksmith Testbox through Crabbox):

  • Full discord extension suite + this PR: tbx_01kx8603stj54vvdpwr9ms6x5w — 1988/1989 tests pass (166/167 files).
  • The single failure (client.proxy.test.ts:257, undici multipart content-type under proxy fetch) is pre-existing on clean origin/main: reproduced on tbx one-shot from a detached origin/main worktree — 1981/1982 pass with the identical single failure. No overlap with this diff (custom-id codecs only). Tracked separately.
  • Autoreview (codex gpt-5.6-sol, xhigh, branch diff vs origin/main): clean, no accepted/actionable findings — "versioned component-field escaping remains byte-compatible, URI-component consumers preserve their prior malformed-input fallback."
  • Wire compat: zero format change; round-trip + historical-payload tests added in custom-id-codec.test.ts.

@steipete
steipete merged commit 72cf43f into main Jul 11, 2026
112 of 114 checks passed
@steipete
steipete deleted the claude/chanref-p0-discord-customid branch July 11, 2026 09:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant