mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-04 10:52:13 +02:00
fix(telemetry): classify daemon query rejections as expected, not faults (#335)
* fix(telemetry): classify daemon query rejections as expected, not faults Semantic-layer query rejections and warehouse-execution rejections from the sl_query MCP tool were wrapped as generic Errors, so reportException filed them as PostHog $exception faults indistinguishable from real ktx bugs. The daemon already separates a caller rejection (planner ValueError -> exit 3 / HTTP 400) from a crash. The Node runner now carries that distinction as a typed KtxDaemonComputeError, and a shared throwClassifiedQueryError promotes daemon input-rejections and warehouse rejections to KtxQueryError while daemon crashes and native JS faults still reach Error Tracking. query_semantic_layer stops report_exception-ing expected ValueErrors, and a missing 'file:' secret now raises KtxExpectedError so absent .ktx/secrets/<conn>-password stops filing faults. * chore: sync uv.lock to ktx-daemon/ktx-sl 0.15.0
This commit is contained in:
parent
a651b82e2f
commit
5d17469601
10 changed files with 347 additions and 28 deletions
|
|
@ -125,7 +125,7 @@ def test_query_semantic_layer_emits_plan_and_sql_debug_events(
|
|||
assert "public.orders" not in captured.err
|
||||
|
||||
|
||||
def test_query_semantic_layer_reports_exception(monkeypatch) -> None:
|
||||
def test_query_semantic_layer_reports_unexpected_fault(monkeypatch) -> None:
|
||||
from ktx_daemon import semantic_layer as semantic_layer_module
|
||||
|
||||
reports: list[dict[str, object]] = []
|
||||
|
|
@ -133,12 +133,16 @@ def test_query_semantic_layer_reports_exception(monkeypatch) -> None:
|
|||
def fake_report(exception: BaseException, **kwargs: object) -> None:
|
||||
reports.append({"exception": exception, **kwargs})
|
||||
|
||||
monkeypatch.setattr(semantic_layer_module, "report_exception", fake_report)
|
||||
def boom(*_args: object, **_kwargs: object) -> None:
|
||||
raise RuntimeError("engine construction failed")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
monkeypatch.setattr(semantic_layer_module, "report_exception", fake_report)
|
||||
monkeypatch.setattr(semantic_layer_module.SemanticEngine, "from_sources", boom)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
query_semantic_layer(
|
||||
SemanticLayerQueryRequest(
|
||||
sources=[ORDERS_SOURCE, ORDERS_SOURCE],
|
||||
sources=[ORDERS_SOURCE],
|
||||
dialect="postgres",
|
||||
projectId="a" * 64,
|
||||
query={"measures": ["orders.order_count"]},
|
||||
|
|
@ -152,6 +156,32 @@ def test_query_semantic_layer_reports_exception(monkeypatch) -> None:
|
|||
assert reports[0]["project_id"] == "a" * 64
|
||||
|
||||
|
||||
def test_query_semantic_layer_does_not_report_expected_query_rejection(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
from ktx_daemon import semantic_layer as semantic_layer_module
|
||||
|
||||
reports: list[dict[str, object]] = []
|
||||
monkeypatch.setattr(
|
||||
semantic_layer_module,
|
||||
"report_exception",
|
||||
lambda *_args, **kwargs: reports.append(kwargs),
|
||||
)
|
||||
|
||||
# A planner ValueError is the engine refusing the agent's query — surfaced to
|
||||
# the caller and re-raised, but never filed as a ktx fault.
|
||||
with pytest.raises(ValueError, match="does not reference any source"):
|
||||
query_semantic_layer(
|
||||
SemanticLayerQueryRequest(
|
||||
sources=[ORDERS_SOURCE],
|
||||
dialect="postgres",
|
||||
query={"measures": ["count(*)"]},
|
||||
)
|
||||
)
|
||||
|
||||
assert reports == []
|
||||
|
||||
|
||||
def test_semantic_layer_request_rejects_project_id_field_name() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
SemanticLayerQueryRequest(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue