Skip to content

fix(reply): prefer provider over surface for run channel fallback#31880

Merged
steipete merged 1 commit intoopenclaw:mainfrom
liuxiaopai-ai:codex/feishu-message-provider-fallback-31859
Mar 2, 2026
Merged

fix(reply): prefer provider over surface for run channel fallback#31880
steipete merged 1 commit intoopenclaw:mainfrom
liuxiaopai-ai:codex/feishu-message-provider-fallback-31859

Conversation

@liuxiaopai-ai
Copy link

Summary

  • Problem: in queued run setup, messageProvider fallback used Surface before Provider when OriginatingChannel was missing.
  • Why it matters: mixed relay metadata can carry Surface=webchat while the active channel is still Feishu, causing embedded runs to be mislabeled and downstream channel behavior to drift.
  • What changed: switched fallback precedence to Provider -> Surface in get-reply-run, and added a regression test for Provider=feishu + Surface=webchat + missing origin metadata.
  • What did NOT change (scope boundary): no routing policy changes, no dispatch logic changes, no channel adapter behavior changes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Feishu turns with missing OriginatingChannel no longer fall back to webchat when context has Provider=feishu and Surface=webchat.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 + pnpm
  • Model/provider: N/A
  • Integration/channel (if any): Feishu + auto-reply queued run path
  • Relevant config (redacted): N/A

Steps

  1. Build queued run context with missing OriginatingChannel.
  2. Set ctx.Provider="feishu" and ctx.Surface="webchat".
  3. Inspect followupRun.run.messageProvider.

Expected

  • messageProvider resolves to feishu.

Actual

  • Before fix: resolved to webchat.
  • After fix: resolves to feishu.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios:
    • pnpm test src/auto-reply/reply/get-reply-run.media-only.test.ts src/auto-reply/reply/agent-runner-utils.test.ts
    • Added regression test: prefers Provider over Surface when origin channel is missing.
  • Edge cases checked:
    • Existing origin-precedence scenario still passes (uses inbound origin channel for run messageProvider).
  • What you did not verify:
    • Live Feishu end-to-end on a real bot account.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
    • Revert this PR commit.
  • Files/config to restore:
    • src/auto-reply/reply/get-reply-run.ts
    • src/auto-reply/reply/get-reply-run.media-only.test.ts
  • Known bad symptoms reviewers should watch for:
    • messageProvider unexpectedly reverting to webchat in Feishu relayed contexts.

Risks and Mitigations

  • Risk: contexts relying on legacy Surface-first fallback might observe different inferred provider when origin metadata is missing.
    • Mitigation: origin channel still has highest precedence; change only affects ambiguous fallback and is covered by regression tests.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR fixes a bug in queued run setup where messageProvider fallback incorrectly preferred Surface over Provider when OriginatingChannel was missing. This caused Feishu messages with mixed relay metadata (Surface=webchat while Provider=feishu) to be mislabeled as webchat.

Key changes:

  • Switched fallback precedence in get-reply-run.ts from ctx.Surface ?? ctx.Provider to ctx.Provider ?? ctx.Surface
  • Added clear inline comment explaining the rationale: Surface can carry relayed metadata while Provider reflects the active channel that should own tool routing
  • Added regression test verifying Provider=feishu + Surface=webchat + missing OriginatingChannel resolves to feishu
  • Existing test still passes, confirming OriginatingChannel maintains highest precedence

Impact:
The fix is minimal and focused. The change only affects the fallback order when OriginatingChannel is undefined - the highest priority path remains unchanged. Test coverage validates both the new behavior and preserves existing functionality.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is surgical and well-contained: a simple two-field swap in fallback precedence with clear rationale. The fix is covered by a new regression test and preserves existing test behavior. The PR description is thorough, explicitly scopes what was NOT changed, and includes verification steps. No security concerns, no breaking changes, and the logic is straightforward.
  • No files require special attention

Last reviewed commit: 9d61044

@steipete steipete force-pushed the codex/feishu-message-provider-fallback-31859 branch from 9d61044 to d60e17c Compare March 2, 2026 18:36
@steipete steipete force-pushed the codex/feishu-message-provider-fallback-31859 branch from d60e17c to c7ff32c Compare March 2, 2026 18:36
@steipete steipete merged commit 740bb77 into openclaw:main Mar 2, 2026
9 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm test src/auto-reply/reply/get-reply-run.media-only.test.ts -t "prefers Provider over Surface when origin channel is missing"
  • Land commit: c7ff32c
  • Merge commit: 740bb77

Thanks @liuxiaopai-ai!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu channel: Message replies are routed to webchat instead of feishu

2 participants