HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
sql: a result the row cap cut short says truncated (#485)
Rudy Mizrahi Celekli79bab3314dcc
diff --git a/gateway/sql_plane.py b/gateway/sql_plane.pyindex cfda36c3..ef6a073c 100644--- a/gateway/sql_plane.py+++ b/gateway/sql_plane.py@@ -271,7 +271,9 @@ async def run_query(engine: str, dsn: str, sql: str, *, timeout: float = DEFAULTif engine not in ENGINES:raise SqlRefused(f"Unsupported database: {engine}. This build supports {', '.join(ENGINES)}.")checked = check_readonly(sql)- capped, added = with_limit(checked, max_rows)+ # One row past the cap is asked for, so _rows_out can see that there was more and say+ # `truncated`; with LIMIT max_rows the database never returns the row that would tell it.+ capped, added = with_limit(checked, max_rows + 1)out = await (_pg_query if engine == "postgres" else _mysql_query)(dsn, capped, timeout, max_rows)out["limit_applied"] = added and max_rows or Nonereturn outdiff --git a/gateway/tests/test_sql_plane.py b/gateway/tests/test_sql_plane.pyindex 7ae6e788..e8ae8e5a 100644--- a/gateway/tests/test_sql_plane.py+++ b/gateway/tests/test_sql_plane.py@@ -124,3 +124,37 @@ def test_connection_errors_do_not_echo_the_password():e = Exception('could not connect to postgresql://app:[email protected]:5432/analytics')cleaned = _clean_db_error(e)assert "hunter2" not in cleaned and "://***@" in cleaned+++# ── a capped answer says it was capped ───────────────────────────────────────────++def _engine_over(monkeypatch, n_rows: int):+ """A stand-in for the database that honours a trailing LIMIT, as both real engines do."""+ import asyncio+ import re as _re+ import sql_plane++ async def fake(dsn, sql, timeout, max_rows):+ m = _re.search(r"LIMIT (\d+)\s*$", sql)+ recs = [(i,) for i in range(n_rows)][: int(m.group(1)) if m else None]+ return sql_plane._rows_out(["x"], recs, max_rows)++ monkeypatch.setattr(sql_plane, "_pg_query", fake)+ return lambda sql, max_rows: asyncio.run(sql_plane.run_query("postgres", "", sql, max_rows=max_rows))+++def test_a_result_cut_by_the_row_cap_is_marked_truncated(monkeypatch):+ """The cap appended LIMIT max_rows, so the database never returned more than max_rows rows and+ `truncated` (len(records) > max_rows) could not be true: a caller was handed a partial answer+ as if it were the whole one."""+ run = _engine_over(monkeypatch, 100)+ out = run("SELECT x FROM big", 10)+ assert out["row_count"] == 10 and out["truncated"] is True and out["limit_applied"] == 10+++def test_a_result_within_the_cap_is_not_marked_truncated(monkeypatch):+ run = _engine_over(monkeypatch, 10)+ out = run("SELECT x FROM small", 10) # exactly the cap: nothing was left out+ assert out["row_count"] == 10 and out["truncated"] is False+ out = run("SELECT x FROM small", 50)+ assert out["row_count"] == 10 and out["truncated"] is False and out["limit_applied"] == 50