Skip to content

Commit 0667de8

Browse files
committed
fix(ci): bedrock recordings hash stability improvements
- Skip embedding model validation for bedrock setup (empty string forces override) - Exclude stream_options from hash computation for consistent recordings The bedrock provider adds stream_options for telemetry but this was causing hash mismatches since recordings were made before this was added. Now infrastructure/telemetry fields are excluded from the hash computation.
1 parent b4a341c commit 0667de8

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/llama_stack/testing/api_recorder.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,29 @@ def _replace(match: re.Match[str]) -> str:
7777
return _FLOAT_IN_STRING_PATTERN.sub(_replace, value)
7878

7979

80-
def _normalize_body_for_hash(value: Any) -> Any:
81-
"""Recursively normalize a JSON-like value to improve hash stability."""
80+
# Keys to exclude from hash computation - these are infrastructure/telemetry fields
81+
# that don't affect the logical request identity
82+
_HASH_EXCLUDED_KEYS = {"stream_options"}
83+
84+
85+
def _normalize_body_for_hash(value: Any, is_top_level: bool = True) -> Any:
86+
"""Recursively normalize a JSON-like value to improve hash stability.
87+
88+
Args:
89+
value: The value to normalize
90+
is_top_level: Whether this is the top-level body dict (for key exclusion)
91+
"""
8292

8393
if isinstance(value, dict):
84-
return {key: _normalize_body_for_hash(item) for key, item in value.items()}
94+
return {
95+
key: _normalize_body_for_hash(item, is_top_level=False)
96+
for key, item in value.items()
97+
if not (is_top_level and key in _HASH_EXCLUDED_KEYS)
98+
}
8599
if isinstance(value, list):
86-
return [_normalize_body_for_hash(item) for item in value]
100+
return [_normalize_body_for_hash(item, is_top_level=False) for item in value]
87101
if isinstance(value, tuple):
88-
return tuple(_normalize_body_for_hash(item) for item in value)
102+
return tuple(_normalize_body_for_hash(item, is_top_level=False) for item in value)
89103
if isinstance(value, float):
90104
return round(value, 5)
91105
if isinstance(value, str):
@@ -162,14 +176,6 @@ def normalize_inference_request(method: str, url: str, headers: dict[str, Any],
162176
normalized_json = json.dumps(normalized, sort_keys=True)
163177
request_hash = hashlib.sha256(normalized_json.encode()).hexdigest()
164178

165-
if is_debug_mode():
166-
logger.info("[RECORDING DEBUG] Hash computation:")
167-
logger.info(f" Test ID: {test_id}")
168-
logger.info(f" Method: {method.upper()}")
169-
logger.info(f" Endpoint: {parsed.path}")
170-
logger.info(f" Model: {body.get('model', 'N/A')}")
171-
logger.info(f" Computed hash: {request_hash}")
172-
173179
return request_hash
174180

175181

tests/integration/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ def pytest_configure(config):
134134
if k not in os.environ:
135135
os.environ[k] = str(v)
136136
# Apply defaults if not provided explicitly
137+
# Empty string ("") is a special case that means "force override to disable"
138+
# This allows setups like bedrock to skip embedding validation
137139
for dest, value in setup_obj.defaults.items():
138-
current = getattr(config.option, dest, None)
139-
if current is None:
140+
if value == "":
141+
# Empty string forces override - used to disable features
142+
setattr(config.option, dest, value)
143+
elif getattr(config.option, dest, None) is None:
140144
setattr(config.option, dest, value)
141145

142146
# Apply global fallback for embedding_dimension if still not set

tests/integration/suites.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Setup(BaseModel):
107107
description="AWS Bedrock provider with OpenAI GPT-OSS model (us-west-2)",
108108
defaults={
109109
"text_model": "bedrock/openai.gpt-oss-20b-1:0",
110+
"embedding_model": "", # Bedrock doesn't support embeddings
110111
},
111112
),
112113
"gpt": Setup(

0 commit comments

Comments
 (0)