fix: revive the reasoning verdict as an enum, not a bare string
asdict keeps the enum and json.dumps writes it as a string because StrEnum is a str subclass, but nothing turns it back on the way in, so a cache hit returned a plain str where the annotation promised an enum. Verified end to end rather than assumed from the subclass relation. A value outside the domain now raises inside the existing guard and the call falls back to source, which is the right direction for a poisoned or stale cache entry. Entries written before this column existed still replay: the guard checks for the key first, and a test pins that, since turning it into an unconditional conversion would quietly turn every pre-upgrade entry into a permanent miss.
This commit is contained in:
@@ -17,7 +17,7 @@ from typing import TYPE_CHECKING, Any
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from polygateway.types import ChatRequest, LLMResponse
|
||||
from polygateway.types import ChatRequest, LLMResponse, ThinkingObservation
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
@@ -132,6 +132,12 @@ class CacheMW:
|
||||
data = json.loads(raw)
|
||||
fields = {k: v for k, v in data.items() if k in _RESPONSE_FIELDS}
|
||||
structured_data = self._rebuild_structured(fields.get("content", ""), request)
|
||||
# JSON 里存的是 StrEnum 的字符串值,不转就复活成裸 str,与字段注解分叉
|
||||
# (下游 `is ThinkingObservation.OBSERVED` 会在命中路径上静默为 False);
|
||||
# 键缺失即升级前写入的旧条目,交给 dataclass 默认值。域外值抛
|
||||
# ValueError,由下方 except 吞成"按未命中回源"——降级方向正确。
|
||||
if "thinking_observation" in fields:
|
||||
fields["thinking_observation"] = ThinkingObservation(fields["thinking_observation"])
|
||||
fields.update(
|
||||
cache_hit=True,
|
||||
latency_ms=0,
|
||||
|
||||
Reference in New Issue
Block a user