Skip to content

Commit cd28275

Browse files
committed
fix: use sync function for single query, avoid sync open() in async context
1 parent 3f0ca85 commit cd28275

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

codebase_rag/cli.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
connect_memgraph,
1919
export_graph_to_file,
2020
main_async,
21-
main_async_single_query,
2221
main_optimize_async,
22+
main_single_query,
2323
prompt_for_unignored_directories,
2424
style,
2525
update_model_settings,
@@ -247,11 +247,7 @@ def start(
247247

248248
try:
249249
if ask_agent:
250-
asyncio.run(
251-
main_async_single_query(
252-
target_repo_path, effective_batch_size, ask_agent
253-
)
254-
)
250+
main_single_query(target_repo_path, effective_batch_size, ask_agent)
255251
else:
256252
asyncio.run(main_async(target_repo_path, effective_batch_size))
257253
except KeyboardInterrupt:

codebase_rag/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,12 @@ def _initialize_services_and_agent(
10231023
return rag_agent, confirmation_tool_names
10241024

10251025

1026-
async def main_async_single_query(
1027-
repo_path: str, batch_size: int, question: str
1028-
) -> None:
1026+
def main_single_query(repo_path: str, batch_size: int, question: str) -> None:
10291027
_setup_common_initialization(repo_path)
10301028

10311029
with connect_memgraph(batch_size) as ingestor:
10321030
rag_agent, _ = _initialize_services_and_agent(repo_path, ingestor)
1033-
response = await rag_agent.run(question, message_history=[])
1031+
response = asyncio.run(rag_agent.run(question, message_history=[]))
10341032
print(response.output) # noqa: T201
10351033

10361034

codebase_rag/mcp/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414

1515
async def query_mcp_server(question: str) -> dict[str, str]:
16-
with open(os.devnull, "w") as devnull:
16+
devnull = open(os.devnull, "w") # noqa: ASYNC230, SIM115
17+
try:
1718
server_params = StdioServerParameters(
1819
command=sys.executable,
1920
args=["-m", "codebase_rag.cli", "mcp-server"],
@@ -37,6 +38,8 @@ async def query_mcp_server(question: str) -> dict[str, str]:
3738
except json.JSONDecodeError:
3839
return {"output": response_text}
3940
return {"output": "No response from server"}
41+
finally:
42+
devnull.close()
4043

4144

4245
@app.command()

0 commit comments

Comments
 (0)