Skip to content

BigQuery forecast, analyze_contribution and detect_anomalies block the event loop #7253

Description

@yumizu-da

🔴 Required Information

Describe the Bug:
Follow-up to #7160, split out as requested there. forecast, analyze_contribution and detect_anomalies in the BigQuery toolset have the same problem that #7160 reported for execute_sql: they are plain defs that call the blocking _execute_sql helper directly (src/google/adk/integrations/bigquery/query_tool.py, L934, L1143 and L1375). ADK awaits a sync tool inline on the running loop, so nothing else in the process runs until the queries come back.

analyze_contribution and detect_anomalies call _execute_sql twice in a row (CREATE TEMP MODEL, then ML.GET_INSIGHTS / ML.DETECT_ANOMALIES), so the loop stays blocked for both queries, including model training.

#7161 fixes execute_sql only and leaves these three untouched on purpose.

Steps to Reproduce:
The repro script in #7160 should apply here too, with the execute_sql call replaced by one of these three tools. analyze_contribution and detect_anomalies also need a write_mode other than BLOCKED.

Expected Behavior:
Other tasks on the event loop keep running while these tools wait for BigQuery.

Observed Behavior:
From the code, the same as #7160: the event loop is blocked for the whole tool call, which for analyze_contribution and detect_anomalies covers both queries.

Environment Details:

  • ADK Library Version (pip show google-adk): main at 7ae1c9b
  • Desktop OS: N/A
  • Python Version (python -V): N/A

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: N/A, no model involved

🟡 Optional Information

Regression:
No, they have always been sync.

Additional Context:
The fix would follow #7161: make the three tools coroutines and run the blocking work in a thread with asyncio.to_thread. It makes sense to pick this up once #7161 is merged and its approach is settled, so the same pattern applies here.

For analyze_contribution and detect_anomalies, one open point is whether both queries go into a single to_thread call or each _execute_sql call gets its own.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bq[Component] This issue is related to Big Query integrationneeds review[Status] The PR/issue is awaiting review from the maintainer

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions