← Back to Pull requests

fix(openai): record Responses computer calls as client tools #837

Closed
unknown closed this pull request without merging on Oct 11, 2026 16:33 UTC
View on GitHub
unknown unknown commented on Oct 02, 2026 18:28 UTC
Author

Description

Responses telemetry omitted computer calls and screenshot results. It now records both with matching call IDs and a tool_calls finish reason. Fixes #831.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • This change requires a documentation update
  • How has this been tested?

  • Test A: sync/async Responses replay
  • Testing Done

    Both paths replayed with OpenAI 3.16.2 without credentials or network access. The recordings use screenshot fixtures, not a live browser.

    Before, with dc32152 production code and this PR's recordings and tests, both span snapshots showed:

    {"call_ids_match":false,"finish_reasons":["stop"],"first_parts":[],"first_tool":null,"screenshot_matches_fixture":false,"screenshot_type":null,"second_parts":["text"],"second_roles":["user"]}
    

    After, both snapshots showed:

    {"call_ids_match":true,"finish_reasons":["tool_calls"],"first_parts":["tool_call"],"first_tool":"computer","screenshot_matches_fixture":true,"screenshot_type":"computer_screenshot","second_parts":["text","tool_call","tool_call_response"],"second_roles":["user","assistant","tool"]}
    

    The observer reads finished spans from the existing SDK replay tests:

    uvx --with tox-uv tox -e py314-test-instrumentation-genai-openai-latest --notest
    env -u OPENAI_API_KEY .tox/py314-test-instrumentation-genai-openai-latest/bin/python /tmp/observe_computer_loop.py
    

    <details>
    <summary>Reproducer source: observe_computer_loop.py</summary>

    import json
    import socket
    import sys
    
    import pytest
    
    
    @pytest.hookimpl(hookwrapper=True)
    def pytest_fixture_setup(fixturedef, request):
        outcome = yield
        if fixturedef.argname == "vcr":
            outcome.get_result().record_mode = "none"
            print("evidence_record_mode=none; command_line_record_override=None")
    
    
    @pytest.fixture(autouse=True)
    def prohibit_network(monkeypatch):
        attempts = []
    
        def denied(*args, **kwargs):
            attempts.append(True)
            raise AssertionError("The offline replay attempted a network connection.")
    
        monkeypatch.setattr(socket.socket, "connect", denied)
        monkeypatch.setattr(socket.socket, "connect_ex", denied)
        monkeypatch.setattr(socket, "create_connection", denied)
        yield
        print(f"network_connection_attempts={len(attempts)}")
        assert not attempts
    
    
    @pytest.hookimpl(hookwrapper=True)
    def pytest_runtest_makereport(item, call):
        outcome = yield
        report = outcome.get_result()
        if report.when != "call" or "computer_tool_loop" not in item.name:
            return
        exporter = item.funcargs.get("span_exporter")
        spans = exporter.get_finished_spans() if exporter is not None else []
        result = {"node": item.name, "outcome": report.outcome}
        if report.skipped:
            result["reason"] = str(report.longrepr)
        if len(spans) == 2:
            first, second = spans
            output = json.loads(first.attributes.get("gen_ai.output.messages", "[]"))
            inputs = json.loads(second.attributes.get("gen_ai.input.messages", "[]"))
            output_parts = [part for message in output for part in message["parts"]]
            input_parts = [part for message in inputs for part in message["parts"]]
            calls = [part for part in output_parts if part["type"] == "tool_call"]
            responses = [
                part for part in input_parts if part["type"] == "tool_call_response"
            ]
            replayed_calls = [part for part in input_parts if part["type"] == "tool_call"]
            screenshot = responses[0]["response"] if responses else {}
            result.update(
                finish_reasons=first.attributes.get("gen_ai.response.finish_reasons"),
                first_parts=[part["type"] for part in output_parts],
                second_roles=[message["role"] for message in inputs],
                second_parts=[part["type"] for part in input_parts],
                call_ids_match=bool(
                    calls
                    and responses
                    and replayed_calls
                    and calls[0]["id"] == responses[0]["id"] == replayed_calls[0]["id"]
                ),
                first_tool=calls[0]["name"] if calls else None,
                screenshot_type=screenshot.get("type"),
                screenshot_matches_fixture=(
                    screenshot.get("image_url") == item.module.COMPUTER_SCREENSHOT_DATA_URL
                ),
            )
        print("OBSERVED " + json.dumps(result, sort_keys=True))
    
    
    if __name__ == "__main__":
        raise SystemExit(
            pytest.main(
                [
                    "instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_responses.py",
                    "instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_async_responses.py",
                    "-k", "computer_tool_loop",
                    "-s", "--tb=short",
                ],
                plugins=[sys.modules[__name__]],
            )
        )
    

    </details>

    Checklist

    See CONTRIBUTING.md.

  • Followed the style guidelines of this project

  • Changelog updated if the change requires an entry

  • Unit tests added

  • Documentation updated (not applicable; no API or configuration changes)
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: 1fanwang Review duration: 12844m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #837"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%