Python CLI exits successfully when a local SQL query fails
On main 0e2945878817b8f19811aa2712a8acaa9a50319e, both omi local sql and omi local call execute_sql can exit successfully when Desktop reports a SQL execution failure. In JSON mode, the error is written to stdout and the process still exits 0, so a script checking the documented exit-code contract treats a failed query as successful.
The Desktop executor returns SQL Error: The local database could not complete that query. from its database error handler. The local API bridge only recognizes the Error: prefix, so this result is wrapped in HTTP 200 with ok: true. The Python client unwraps it without preserving the failure.
I prepared a small patch at the Python local-client response boundary that recognizes this existing execute_sql failure representation for both CLI entry points. It returns exit 1, sends errors to stderr, and keeps stdout empty in JSON mode. Successful empty results and column headings beginning with SQL Error: still succeed, and other tools may still return the same words as ordinary content. The patch matches the complete Desktop failure message and includes eleven regression/control cases and a short update to the agent documentation.
Validation uses the real CLI main() entry point with intercepted HTTP responses and synthetic configuration. The four failure cases fail against unchanged production code; all eleven pass with the patch. The focused local-client suite passes all 57 tests. The full CLI run has 348 passes, one Windows-only skip, and one existing failure in test_transport_failure_during_login_leaves_saved_config_unchanged, which also failed before this change. Black, isort, and git diff --check pass. Repository-wide make preflight completes successfully in a full working-tree checkout; its 90-day failure-class history check is skipped because the Git history is shallow. I have not tested this against a running Desktop application or real account.
Following the contribution guide's invitation to propose paid fixes, @josancamon19, would you approve US$10 for this focused CLI fix, tests, and documentation, payable after acceptance and merge through the documented PayPal process? This work was prepared with OpenAI Codex. No bounty is approved or earned, and payment details would be provided privately only when needed.
Prepared patch for review: CLI fix, eleven test cases, and documentation
This is the locally tested patch against 0e2945878817b8f19811aa2712a8acaa9a50319e; it is not yet a pull request. It is included here to make the proposed paid scope directly reviewable. The baseline test failure and shallow-history preflight limitation described above still apply.
diff --git a/docs/doc/developer/cli/agents.mdx b/docs/doc/developer/cli/agents.mdx
index e3d7b64..9b27926 100644
--- a/docs/doc/developer/cli/agents.mdx
+++ b/docs/doc/developer/cli/agents.mdx
@@ -35,6 +35,11 @@ omi --json memory list --limit 25 | jq '.[] | {id, content, category}'
These codes are **part of the contract** — they won't shift between minor
versions. Branch on them in your harness without parsing English errors.
+Local SQL execution failures return exit code `1` from both `omi local sql`
+and `omi local call execute_sql`, including when Desktop wraps the error in
+an HTTP 200 response. With `--json`, the error goes to stderr and stdout stays
+empty. A successful query with no rows still returns exit code `0`.
+
## Authentication: API key vs browser OAuth
The CLI supports both — but for **agents** specifically, the API-key path is
diff --git a/sdks/python-cli/omi_cli/local_client.py b/sdks/python-cli/omi_cli/local_client.py
index b6d10da..717c6f2 100644
--- a/sdks/python-cli/omi_cli/local_client.py
+++ b/sdks/python-cli/omi_cli/local_client.py
@@ -75,7 +75,13 @@ class LocalOmiClient:
self._maybe_log(name, response)
if not (200 <= response.status_code < 300):
raise self._error_from_response(response)
- return _unwrap_tool_response(_safe_parse_json(response))
+ result = _unwrap_tool_response(_safe_parse_json(response))
+ # Desktop reports this SQL failure as text inside an ok:true envelope.
+ # Match its full message: successful table headings can start with
+ # "SQL Error:" too. Both `local sql` and `local call` share this boundary.
+ if name == "execute_sql" and result == "SQL Error: The local database could not complete that query.":
+ raise CliError(message=result, exit_code=1)
+ return result
def list_tools(self) -> Any:
"""Return Desktop-local tool descriptors."""
diff --git a/sdks/python-cli/tests/test_local_sql_errors.py b/sdks/python-cli/tests/test_local_sql_errors.py
new file mode 100644
index 0000000..4542713
--- /dev/null
+++ b/sdks/python-cli/tests/test_local_sql_errors.py
@@ -0,0 +1,103 @@
+"""The Desktop SQL failure response must remain a failure at the CLI boundary."""
+
+from __future__ import annotations
+
+import json
+
+import httpx
+import pytest
+import respx
+
+from omi_cli import config as cfg
+from omi_cli.main import main
+
+LOCAL_URL = "http://127.0.0.1:47778"
+# ChatToolExecutor.executeSQL returns this string on a database error.
+SQL_ERROR = "SQL Error: The local database could not complete that query."
+SQL_COMMANDS = [
+ ["local", "sql", "SELECT * FROM missing_table"],
+ ["local", "call", "execute_sql", "--args-json", '{"query":"SELECT * FROM missing_table"}'],
+]
+
+
[email protected]
+def local_profile(config_path):
+ config = cfg.load()
+ profile = config.get_profile("default")
+ profile.local_api_url = LOCAL_URL
+ profile.local_token = "synthetic_local_token"
+ cfg.save(config)
+
+
[email protected]("command", SQL_COMMANDS)
[email protected]("json_mode", [False, True])
+def test_local_sql_error_exits_nonzero(local_profile, monkeypatch, capsys, command, json_mode):
+ monkeypatch.setattr("sys.argv", ["omi", *(["--json"] if json_mode else []), *command])
+ # LocalAgentAPIServer currently wraps SQL errors in an HTTP 200 / ok:true
+ # envelope because its HTTP error check recognizes only the "Error:" prefix.
+ envelope = {"ok": True, "name": "execute_sql", "content_type": "text/plain", "result": SQL_ERROR}
+ with respx.mock(base_url=LOCAL_URL, assert_all_called=True) as router:
+ route = router.post("/v1/local/tool").mock(return_value=httpx.Response(200, json=envelope))
+ with pytest.raises(SystemExit) as exc:
+ main()
+
+ assert exc.value.code == 1
+ assert route.call_count == 1
+ assert json.loads(route.calls[0].request.content)["name"] == "execute_sql"
+ captured = capsys.readouterr()
+ assert captured.out == ""
+ if json_mode:
+ assert json.loads(captured.err)["error"] == SQL_ERROR
+ else:
+ assert SQL_ERROR in captured.err
+
+
[email protected]("command", SQL_COMMANDS)
[email protected]("json_mode", [False, True])
+def test_local_sql_empty_result_still_succeeds(local_profile, monkeypatch, capsys, command, json_mode):
+ monkeypatch.setattr("sys.argv", ["omi", *(["--json"] if json_mode else []), *command])
+ envelope = {"ok": True, "name": "execute_sql", "content_type": "text/plain", "result": "No results"}
+ with respx.mock(base_url=LOCAL_URL, assert_all_called=True) as router:
+ router.post("/v1/local/tool").mock(return_value=httpx.Response(200, json=envelope))
+ main()
+
+ captured = capsys.readouterr()
+ assert captured.err == ""
+ if json_mode:
+ result = json.loads(captured.out)
+ assert result == ({"rows": [], "columns": [], "row_count": 0} if command[1] == "sql" else "No results")
+ else:
+ assert "No results" in captured.out
+
+
+def test_other_tool_can_return_sql_error_text_as_data(local_profile, monkeypatch, capsys):
+ monkeypatch.setattr("sys.argv", ["omi", "--json", "local", "call", "get_daily_recap"])
+ envelope = {"ok": True, "name": "get_daily_recap", "content_type": "text/plain", "result": SQL_ERROR}
+ with respx.mock(base_url=LOCAL_URL, assert_all_called=True) as router:
+ router.post("/v1/local/tool").mock(return_value=httpx.Response(200, json=envelope))
+ main()
+
+ captured = capsys.readouterr()
+ assert json.loads(captured.out) == SQL_ERROR
+ assert captured.err == ""
+
+
[email protected](
+ "command,json_mode",
+ [
+ (["local", "sql", "SELECT 1 AS 'SQL Error: count'"], False),
+ (["local", "call", "execute_sql", "--args-json", '{"query":"SELECT 1 AS \'SQL Error: count\'"}'], True),
+ ],
+)
+def test_sql_error_column_heading_is_successful_data(local_profile, monkeypatch, capsys, command, json_mode):
+ monkeypatch.setattr("sys.argv", ["omi", *(["--json"] if json_mode else []), *command])
+ # SQLQueryResultProjection.format starts successful output with column names.
+ table = "SQL Error: count\n--------------------\n1\n\n1 row(s)"
+ envelope = {"ok": True, "name": "execute_sql", "content_type": "text/plain", "result": table}
+ with respx.mock(base_url=LOCAL_URL, assert_all_called=True) as router:
+ router.post("/v1/local/tool").mock(return_value=httpx.Response(200, json=envelope))
+ main()
+
+ captured = capsys.readouterr()
+ assert (json.loads(captured.out) if json_mode else captured.out.rstrip()) == table
+ assert captured.err == ""
For provenance: I authored the patch/tests proposed in this issue before PR #13411 was opened. That PR was opened by another account and lists me as a co-author. I did not authorize submission on my behalf. Please hold any bounty attribution decision until authorship is clarified.