Hash-verified recorded artifacts. Rejected patches remain visible for inspection, not approval to ship.
Executed test logs
build: PASS · exit 0 · 2 ms
original-tests: PASS · exit 0 · 184 ms
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
schema: PASS · exit 0 · 175 ms
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
tool-calls: PASS · exit 0 · 174 ms
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
streaming-retry: FAIL · exit 1 · 183 ms
======================================================================
FAIL: test_completion_usage_is_preserved (test_streaming_retry.StreamingAndRetry.test_completion_usage_is_preserved)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/portverdict/test_streaming_retry.py", line 7, in test_completion_usage_is_preserved
self.assertEqual(adapter.normalize_event(event), {"choices":[],"usage":{"prompt_tokens":11,"completion_tokens":4,"total_tokens":15}})
AssertionError: {'choices': []} != {'choices': [], 'usage': {'prompt_tokens': 11, 'complet[31 chars] 15}}
- {'choices': []}
? ^
+ {'choices': [],
? ^
+ 'usage': {'completion_tokens': 4, 'prompt_tokens': 11, 'total_tokens': 15}}
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=1)
security: PASS · exit 0 · 175 ms
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
secret-scan: PASS · exit 0 · 0 ms
harness-integrity: PASS · exit 0 · 0 ms
Inspect candidate diff
diff --git a/adapter.py b/adapter.py
--- a/adapter.py
+++ b/adapter.py
@@ -1,34 +1,51 @@
-import json
-
-def normalize_event(event):
- if event.get("type") == "chat.completion.chunk":
- return event
- if event.get("type") == "response.output_text.delta":
- return {"choices": [{"delta": {"content": event.get("delta", "")}}]}
- if event.get("type") == "response.output_item.added":
- call = normalize_tool_call(event.get("item", {}))
- return {"choices": [{"delta": {"tool_calls": [call]}}]} if call else {"choices": []}
- return {"choices": []}
-
-def parse_structured(text):
- raw = text.strip()
- if raw.startswith("```"):
- lines = raw.splitlines()
- if lines[0].strip() not in ("```", "```json") or lines[-1].strip() != "```":
- raise ValueError("invalid JSON fence")
- raw = "\n".join(lines[1:-1]).strip()
- data = json.loads(raw)
- if not isinstance(data, dict) or set(data) != {"answer"} or not isinstance(data["answer"], str) or not data["answer"].strip():
- raise ValueError("expected exactly one non-empty answer")
- return data
-
-def normalize_tool_call(item):
- if item.get("type") != "function_call":
- return None
- arguments = item.get("arguments")
- if not isinstance(arguments, str) or not isinstance(json.loads(arguments), dict):
- raise ValueError("function arguments must be a JSON object string")
- return {"id": item.get("id"), "type": "function", "function": {"name": item.get("name"), "arguments": arguments}}
-
-def retry_delay(status, attempt):
- return min(250 * (2 ** attempt), 2000)
+import json
+
+def normalize_event(event):
+ match event:
+ case {'type': 'chat.completion.chunk'} if isinstance(event, dict):
+ return event
+ case {'type': 'response.output_text.delta', 'delta': delta} if isinstance(event, dict):
+ return {'choices': [{'delta': {'content': delta}}]}
+ case {'type': 'response.output_item.added', 'item': item} if isinstance(event, dict) and isinstance(item, dict):
+ call = normalize_tool_call(item)
+ return {'choices': [{'delta': {'tool_calls': [call]}}]} if call else {'choices': []}
+ case {'type': 'response.completed', 'usage': usage} if isinstance(event, dict) and isinstance(usage, dict):
+ return {
+ 'choices': [],
+ 'usage': {
+ 'prompt_tokens': usage.get('input_tokens', 0),
+ 'completion_tokens': usage.get('output_tokens', 0),
+ 'total_tokens': usage.get('total_tokens', 0)
+ }
+ }
+ case _:
+ return {'choices': []}
+
+def parse_structured(text):
+ raw = text.strip()
+ if raw.startswith("```"):
+ lines = raw.splitlines()
+ if lines[0].strip() not in ("```", "```json") or lines[-1].strip() != "```":
+ raise ValueError("invalid JSON fence")
+ raw = "\n".join(lines[1:-1]).strip()
+ data = json.loads(raw)
+ if not isinstance(data, dict) or set(data) != {"answer"} or not isinstance(data["answer"], str) or not data["answer"].strip():
+ raise ValueError("expected exactly one non-empty answer")
+ return data
+
+def normalize_tool_call(item):
+ if item.get("type") != "function_call":
+ return None
+ arguments = item.get("arguments")
+ if not isinstance(arguments, str) or not isinstance(json.loads(arguments), dict):
+ raise ValueError("function arguments must be a JSON object string")
+ return {"id": item.get("id"), "type": "function", "function": {"name": item.get("name"), "arguments": arguments}}
+
+def retry_delay(status, attempt):
+ match (status, attempt):
+ case (s, a) if isinstance(s, int) and isinstance(a, int) and (s == 429 or 500 <= s < 600):
+ delay = 250 * (2 ** a)
+ return delay if delay <= 2000 else 2000
+ case _:
+ return None
+