Skip to content
← All reviews
open-webui/open-webui #27186 · ekinnee · 4mo ago

feat: forward chat_id as user field in OpenAI-compatible chat completions

Needs attention2 findings · openOpen the pull request on GitHub ↗
Panel verdict

The panel surfaced issues that deserve attention before merge.

2
raised by reviewers
2
kept by the panel

Findings

HighCorrectnessconfidence 0.95

Crash when metadata is not a dict

The helper _inject_chat_id_as_user calls metadata.get('chat_id') without checking that metadata is a dict. If a client sends a non-dict value for metadata (e.g. an empty list [], a string, a number), metadata.get(...) raises AttributeError, resulting in a 500 error. The condition only uses truthiness (if metadata), which passes for non-empty lists and other truthy non-dict objects. This introduces a new crash path compared to the previous code that just popped and ignored metadata.

Suggested fix ·

if ENABLE_FORWARD_CHAT_ID and isinstance(metadata, dict) and metadata.get('chat_id') and 'user' not in payload:

LowArchitectureconfidence 0.95

Module-level flag read prevents runtime toggling

_inject_chat_id_as_user reads ENABLE_FORWARD_CHAT_ID from the module's import-time snapshot rather than from env.py on every call. This means _inject_chat_id_as_user will never observe a runtime change to the environment variable — it behaves as a static constant. While this matches the default-deferred resolution pattern used elsewhere in this codebase (e.g., ENABLE_FORWARD_USER_INFO_HEADERS), it breaks unit-test isolation: the test suite monkeypatches the router module instead of the source-of-truth env module, creating a divergence between test behavior and production. The pattern is fragile; future maintainers may re-import and lose the monkeypatch. Consider reading the env variable lazily inside the helper or during request processing so that runtime changes are reflected and tests can set the environment directly without patching module state.

3 reviewers · deepseek/deepseek-v4-pro · reviewed in 1m 37s · 4 files, +183 −0

Ship the PR.
Skip the noise.

Free on 2 repositories · No credit card · Advisory only—never blocks a merge