Skip to content

fix(twitch): automatic replies fail when the target keeps the internal channel prefix - #167534

Closed
he-yufeng wants to merge 1 commit into
openclaw:mainfrom
he-yufeng:fix/twitch-channel-prefix-normalization
Closed

he-yufeng wants to merge 1 commit into
openclaw:mainfrom
he-yufeng:fix/twitch-channel-prefix-normalization

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

[AI-assisted] Closes #166672

What Problem This Solves

Fixes: Twitch automatic replies never arrive when the reply target carries the internal twitch:channel: prefix, which is every reply routed through the monitor.

User Impact

User impact: mentioning a connected Twitch bot now gets its reply delivered to the same channel, instead of the send failing with "twitch:channel:<name>" is not a valid user or channel name. Prefixed and unprefixed allowlist entries also match the same normalized channel either way.

Why This Change Was Made

The monitor builds reply and durable targets as twitch:channel:<name>, but the channel normalization the outbound adapter runs only stripped a leading #. The prefixed form therefore reached Twitch unchanged and was rejected. The prefix is now stripped at the same normalization owner, so resolveTarget, sendText, and allowlist entries all agree on the bare channel name.

The reporter's second error (PlatformMessageNotDispatchedError / runtime generation superseded) is a separate handoff path and is not claimed here.

Evidence

  • Reproduced from source on current main: normalizeTwitchChannel("twitch:channel:foo") returned the input unchanged while monitor.ts sets reply.to and delivery.durable to exactly that shape; sendText then normalizes again and still passes the prefixed form to the client.
  • Red before green: two new resolveTarget cases fail on the original code (twitch:channel:MyChannel resolves to itself; a prefixed target does not match an unprefixed allowlist entry) and pass with the fix.
  • pnpm test extensions/twitch --maxWorkers=1: 227/227 passed across 17 files, 20.9s wall, including the monitor, plugin, config, and access-control suites that exercise this normalizer.
  • Boundary run through the real adapter (no live Twitch account available): drove twitchOutbound.resolveTarget + sendText with the exact twitch:channel:<name> target shape monitor.ts builds for a mention reply, transport capture standing in at the client-manager send seam that calls client.say. Current head logs client.say(channel="proofchan", text="TWITCH-REPRO-1") and the delivered reply lands back in the originating channel; a prefixed # allowlist entry also matches. The same harness against the pre-fix normalizer logs client.say(channel="twitch:channel:proofchan", ...) (the string Twitch rejects) and fails the allowlist match. Full output in the 2026-10-09 proof comment.
  • oxfmt and scoped oxlint clean on the two touched files.

Gap: no live Twitch delivery was run (needs a real bot account); the proof is at the plugin-owned boundary that produces the transport call, red/green against the original normalizer.

…malization

The monitor builds reply and durable targets as twitch:channel:<name>,
but normalizeTwitchChannel only stripped a leading "#", so the prefixed
form reached Twitch unchanged and every automatic reply failed with
"not a valid user or channel name". Normalize the internal prefix at the
same owner so resolveTarget, sendText, and allowlist entries all agree
on the bare channel name.

Closes openclaw#166672
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: twitch Channel integration: twitch size: XS labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The branch strips the internal twitch:channel: prefix in Twitch channel normalization and adds target-resolution regressions.

Example: A reply uses the target twitch:channel:proofchan

  • Before: The outbound adapter passes twitch:channel:proofchan to the sender, which Twitch rejects.
  • After: The outbound adapter passes the bare channel name proofchan to the sender.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source-supported, but synthetic transport evidence leaves real delivery unverified.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: The agent receives a Twitch mention, but its reply fails because an internal address reaches Twitch as the channel name.
Reason: Restoring the documented reply destination is valuable and requires a small owner-local change. The linked report also describes separate runtime-handoff failures that this branch expressly does not solve.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR repairs a current-main delivery defect with a focused change and no identified patch bugs. The overlapping PR is also unproven, so it does not justify closing this contribution.

Priority: P1
Reviewed head: eb7d0af202c62f067fce563ae2549bf73ff80fb6

Before merge

  • Add real behavior proof - The new trace exercises resolveTarget and sendText with twitch:channel:proofchan and shows the corrected bare target at a substituted client-manager transport seam. It does not run the Gateway mention-to-reply flow with a real Twitch client or observe chat delivery. Add redacted chat screenshots, a recording, or runtime output demonstrating that flow; remove API keys, IP addresses, phone numbers, and private endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Findings

None.

Tests

  • Missing end-to-end proof: A bot mention producing TWITCH-REPRO-1 and an observed reply in the same Twitch chat through the Gateway and real Twitch client is still missing.
Agent review details

How this fits together

The Twitch plugin connects incoming chat messages to an OpenClaw agent and sends replies back to chat. Its target normalizer translates internal conversation addresses into channel names for the Twitch client.

flowchart LR
  A[Twitch chat mention] --> B[Agent reply]
  B --> C[Internal channel address]
  C --> D[Channel normalization]
  D --> E{Target allowed}
  E -->|Yes| F[Twitch outbound sender]
  E -->|No| G[Delivery error]
  F --> H[Twitch chat client]
Loading

Technical review

Best possible solution:

Keep the focused normalization repair, preserve delivery safeguards, and track the linked report’s separate runtime-handoff symptoms independently.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the normalization failure: the monitor creates twitch:channel: targets that current-main outbound normalization forwards unchanged. This review did not execute a live Twitch reproduction.

Is this the best way to solve the issue?

Yes, extending the existing shared channel normalizer is a narrow repair for the invalid-target error and preserves existing valid inputs; it does not establish a fix for the separate runtime-handoff errors.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against da67a08b20eb.

Provenance checked

  • extensions/twitch/src/utils/twitch.ts: normalizeTwitchChannel keeps the original intent (feat: Twitch Plugin #1612: The original helper removes the hash prefix, lowercases, and trims channel names because Twitch’s API expects bare channel names.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • jaydenfyi: Raw commit f5c90f0 adds extensions/twitch/src/utils/twitch.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f5c90f0e5c7a; files: extensions/twitch/src/utils/twitch.ts)

PR surface

Source +5, Tests +24. Total +29 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 1 +5
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 30 1 +29

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166672
Summary: This PR is a candidate repair for the canonical report’s target-normalization defect; the separate runtime symptoms remain outside its scope.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked report documents failed automatic Twitch replies, and current main retains the matching target-format defect.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-09T00:07:25.494Z sha eb7d0af :: needs real behavior proof before merge. :: none

Reviewed October 9, 2026, 1:17 AM ET / 05:17 UTC (Revision 2).

@he-yufeng

Copy link
Copy Markdown
Contributor Author

Boundary proof for the review gate, run at the current head (eb7d0af). No Twitch bot account is available in this environment, so this drives the real plugin outbound path with a transport capture at the client-manager send seam (TwitchClientManager.sendMessage is the owner that calls twurple client.say(channel, chunk), so the captured channel is exactly the PRIVMSG target Twitch validates). The inbound side is the mention shape from the report; the reply target is the exact string monitor.ts:155 builds for it.

Current head:

inbound mention in #proofchan: @proofbot Reply exactly: TWITCH-REPRO-1
monitor.ts reply target (monitor.ts:155): twitch:channel:proofchan
PASS resolveTarget strips the internal prefix: ok=true to=proofchan
PASS resolveTarget matches prefixed target against #allowlist entry: ok=true
[transport] client.say(channel="proofchan", text="TWITCH-REPRO-1")
PASS delivered reply lands in the originating channel
RESULT: mention in #proofchan -> reply delivered back to #proofchan (bare name)

Same harness against the pre-fix normalizer (merge-base version of extensions/twitch/src/utils/twitch.ts):

FAIL resolveTarget strips the internal prefix: ok=true to=twitch:channel:proofchan
FAIL resolveTarget matches prefixed target against #allowlist entry: ok=false
[transport] client.say(channel="twitch:channel:proofchan", text="TWITCH-REPRO-1")
RESULT: 3 check(s) failed

The rejected string from the report ("twitch:channel:<name>" is not a valid user or channel name) is precisely what reaches the transport before the fix. The PR body Evidence section is updated to match.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for digging into this. On current main (fafa5d4) we ran a built Gateway with real Twurple IRC against a local Twitch contract server, with block streaming off so the final reply goes through final delivery. The final-reply target was twitch:channel:proofroom, durable delivery declined it at preflight, and the direct fallback sent PRIVMSG #proofroom correctly. We couldn't reach a real configuration where durable final delivery accepts the prefixed target and then fails. Closing for now. If you can share the config or logs from a run where a Twitch final reply actually failed or went to the wrong channel, reopen and we'll pick it up.

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

Labels

channel: twitch Channel integration: twitch P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Twitch-Plugin-Fehler

2 participants