Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cd5e482
docs(charts): specify additive scientific chart contract
dovvnloading Nov 18, 2026
725ec18
feat(charts): validate scientific series, error intervals and log dom…
dovvnloading Nov 18, 2026
0132cdf
feat(charts): mirror strict scientific validation in TypeScript
dovvnloading Nov 18, 2026
976f540
feat(charts): render scientific coordinates and errors in PNG/SVG
dovvnloading Nov 18, 2026
d4d8b18
feat(charts): add pure log10 scales and bounded ticks
dovvnloading Nov 18, 2026
9840824
feat(charts): shared scientific domains and honest log tick labels
dovvnloading Nov 18, 2026
ceda9bf
feat(charts): support precise logarithmic tick formatting
dovvnloading Nov 18, 2026
839de1c
feat(charts): interactive scatter and multiseries marks with uncertainty
dovvnloading Nov 18, 2026
f0db9e9
feat(charts): dispatch scientific marks, retain legacy line renderer
dovvnloading Nov 18, 2026
9283b2e
feat(charts): show scientific series and errors at overview LOD
dovvnloading Nov 18, 2026
ff1e573
feat(charts): accept validated model-generation scientific options
dovvnloading Nov 18, 2026
8e0edf9
test(evals): add scatter with asymmetric error-bar fixture
dovvnloading Nov 18, 2026
44f02c6
test(charts): strict scientific validation and historical fixture parity
dovvnloading Nov 18, 2026
3da7385
test(charts): verify React scatter, legends, errors and log scales
dovvnloading Nov 18, 2026
5fd126e
fix(charts): respect generated wire-type intersection guard
dovvnloading Nov 18, 2026
4e83559
fix(charts): keep extreme scientific data inside finite domains
dovvnloading Nov 18, 2026
3b3ae32
fix(charts): reject overflowed error spans and bound all scientific a…
dovvnloading Nov 18, 2026
a73d315
fix(charts): reject overflowing error intervals in React validation
dovvnloading Nov 18, 2026
cb4f199
fix(charts): let model schema generate named line and scatter series
dovvnloading Nov 18, 2026
0beca62
fix(charts): create valid numeric scatter fallback on model errors
dovvnloading Nov 18, 2026
7626478
test(charts): cover all five old shapes and overflowed uncertainty do…
dovvnloading Nov 18, 2026
cc11433
test(charts): catch extreme axis clipping and verify errorbar coordin…
dovvnloading Nov 18, 2026
9f4fd8c
docs(charts): clarify stored scatter discriminator and numeric range …
dovvnloading Nov 18, 2026
3e88da7
fix(charts): scale tiny scientific measurements relative to actual data
dovvnloading Nov 18, 2026
9ee7b35
test(charts): preserve visual resolution at tiny linear magnitudes
dovvnloading Nov 18, 2026
3874140
fix(charts): validate pooled multi-series uncertainty extrema
dovvnloading Nov 18, 2026
b1a0bc2
fix(charts): mirror pooled series-domain overflow checks in TypeScript
dovvnloading Nov 18, 2026
cf93caf
test(charts): reject pooled asymmetric multi-series overflow
dovvnloading Nov 18, 2026
beba8f6
test(charts): enforce finite pooled series errors in browser
dovvnloading Nov 18, 2026
cc87fb5
test(charts): exercise scientific model options and scatter fallback
dovvnloading Nov 18, 2026
708b4ac
fix(charts): scientific ticks for tiny linear and extreme values
dovvnloading Nov 18, 2026
c158e1b
fix(charts): use scientific tick math in line and scatter renderer
dovvnloading Nov 18, 2026
6bcc840
test(charts): render tiny scientific values with readable axis ticks
dovvnloading Nov 18, 2026
87de4b9
fix(charts): report series length mismatches before aggregate cap
dovvnloading Nov 18, 2026
d6b4ce7
fix(charts): preserve specific length mismatch errors in frontend
dovvnloading Nov 18, 2026
3eb1945
fix(charts): keep scientific tick labels exact and within axis domain
dovvnloading Nov 18, 2026
3bfd633
test(charts): keep mismatch error priority at the series cap
dovvnloading Nov 18, 2026
e01280d
test(charts): preserve close scientific tick values without rounding
dovvnloading Nov 18, 2026
d10841f
fix(tests): assert migrated fields explicitly through node.state
dovvnloading Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions backend/api/intents_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,42 @@ def register_chart_intents(

publish_scene = make_publish_scene(bus)

async def generate_chart(parent_node_id, chart_type):
def chart_source_options(chart_type, options):
"""Only the four scientific capabilities are requestable. Options
steer extraction; they never supply, fabricate or override data."""
if options is None or options == {}:
return ""
if not isinstance(options, dict):
raise ChartDataError("chartOptions must be an object")
allowed = {"multipleSeries", "errorBars", "xScale", "yScale", "xUnit", "yUnit"}
unknown = set(options) - allowed
if unknown:
raise ChartDataError("Unsupported chartOptions: " + ", ".join(sorted(map(str, unknown))))
if chart_type not in ("line", "scatter"):
raise ChartDataError("Scientific chartOptions require line or scatter")
lines = []
for key in ("multipleSeries", "errorBars"):
if key in options:
if not isinstance(options[key], bool):
raise ChartDataError(f"{key} must be a boolean")
if options[key]:
lines.append("Extract " + ("multiple named series" if key == "multipleSeries"
else "per-point error magnitudes") +
" only where they are explicitly stated in the source.")
for key in ("xScale", "yScale"):
if key in options:
if options[key] not in ("linear", "log10"):
raise ChartDataError(f"{key} must be linear or log10")
lines.append(f"Use {key}={options[key]} exactly.")
for key in ("xUnit", "yUnit"):
if key in options:
value = options[key]
if not isinstance(value, str) or not value.strip() or len(value.strip()) > 160:
raise ChartDataError(f"{key} must be a nonempty unit of at most 160 characters")
lines.append(f"Use {key}={value.strip()!r} exactly.")
return "\n".join(lines)

async def generate_chart(parent_node_id, chart_type, chartOptions=None):
if not parent_node_id or parent_node_id not in document.nodes:
notifications.show(
"Please select a valid node to branch from before generating a chart.",
Expand All @@ -58,8 +93,20 @@ async def generate_chart(parent_node_id, chart_type):
await bus.publish("notification")
return None

try:
option_prompt = chart_source_options(normalized_chart_type, chartOptions)
except ChartDataError as exc:
notifications.show(str(exc), "warning")
await bus.publish("notification")
return None

branch_history = document.chat_branch_history(parent_node_id)
source_text = _chart_source_text(branch_history)
if option_prompt:
source_text = (
"Requested scientific chart options (only extract values present in the source):\n"
+ option_prompt + "\n\n" + source_text
)

result_holder: dict[str, str] = {}

Expand Down Expand Up @@ -89,7 +136,17 @@ async def _on_success(result):
# shape and chart_error set, same "degrade gracefully, never
# drop the request" contract as the agent's own internal
# fallback chain.
chart_data = _placeholder_chart_data(normalized_chart_type)
if normalized_chart_type == "scatter":
# The legacy helper lives in backend/canvas.py (outside
# this feature's edit scope) and only constructs
# categorical placeholders. Scatter needs real numeric
# x coordinates even for an error-state chart.
chart_data = canonicalize_chart_data({
"type": "scatter", "title": "Chart",
"xValues": [1.0, 2.0], "values": [1.0, 1.0],
}, "scatter")
else:
chart_data = _placeholder_chart_data(normalized_chart_type)
chart_error = f"The generated chart data could not be validated: {exc}"
# ADR-010 stage 10.1: agent provenance - this node is produced by
# a model generation, not a direct user action (stage 10.5's
Expand Down
70 changes: 70 additions & 0 deletions backend/evals/fixtures/chart/scatter_calibration_error_bars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "scatter_calibration_error_bars",
"kind": "chart",
"input": {
"chart_type": "scatter",
"source_text": "Calibration data: concentrations (mg/L) 1, 10, 100. Control response (mV): 0.9, 1.8, 3.2, with y uncertainties +/-0.1, -0.1/+0.3, +/-0.2 respectively. Treatment response (mV): 1.1, 2.1, 3.5. Concentration uncertainties: +/-0.05 at 1, -1/+2 at 10, +/-10 at 100. Use log10 for concentration."
},
"scripted_response": "{\"type\":\"scatter\",\"title\":\"Calibration\",\"xAxis\":\"Concentration\",\"yAxis\":\"Response\",\"xUnit\":\"mg/L\",\"yUnit\":\"mV\",\"xScale\":\"log10\",\"yScale\":\"linear\",\"xValues\":[1,10,100],\"series\":[{\"name\":\"Control\",\"values\":[0.9,1.8,3.2],\"xError\":[0.05,[1,2],10],\"yError\":[0.1,[0.1,0.3],0.2]},{\"name\":\"Treatment\",\"values\":[1.1,2.1,3.5]}]}",
"expected": {
"version": 1,
"title": "Calibration",
"xAxis": "Concentration",
"yAxis": "Response",
"xUnit": "mg/L",
"yUnit": "mV",
"xScale": "log10",
"yScale": "linear",
"xValues": [
1,
10,
100
],
"series": [
{
"name": "Control",
"values": [
0.9,
1.8,
3.2
],
"xError": [
[
0.05,
0.05
],
[
1,
2
],
[
10,
10
]
],
"yError": [
[
0.1,
0.1
],
[
0.1,
0.3
],
[
0.2,
0.2
]
]
},
{
"name": "Treatment",
"values": [
1.1,
2.1,
3.5
]
}
]
}
}
99 changes: 99 additions & 0 deletions backend/tests/test_chart_intents_scientific.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""Model-driven scatter request options and failure-state regression coverage."""

import asyncio

from backend.api.intents_chart import register_chart_intents
from backend.domain.graph import SceneDocument
from backend.events import SessionBus
from backend.notifications import NotificationState


class FakeChartAgent:
def __init__(self, response=None):
self.calls = []
self.response = response

async def start_chart_generation(self, **kwargs):
self.calls.append(kwargs)
if self.response is not None:
await kwargs["on_success"](self.response)


def _setup(response=None):
bus = SessionBus("scientific-chart-intent")
document = SceneDocument()
notifications = NotificationState()
bus.register_topic("scene", document.scene_payload)
bus.register_topic("notification", notifications.payload)
agent = FakeChartAgent(response)
register_chart_intents(bus, document, notifications, agent)
root = document.add_chat_node(0, 0, "Concentrations 1, 10; response 2, 3.", is_user=True)
return bus, document, notifications, agent, root.id


def test_model_driven_scatter_requests_advanced_options_and_creates_a_chart():
response = {
"type": "scatter", "xValues": [1, 10],
"series": [{"name": "Control", "values": [2, 3], "yError": [0.1, [0.2, 0.3]]}],
"xScale": "log10", "xUnit": "mg/L", "yUnit": "mV",
}

async def run():
bus, document, _, agent, root = _setup(response)
node_id = await bus.dispatch_intent("scene", "generateChart", [
root, "scatter", {
"multipleSeries": True, "errorBars": True, "xScale": "log10",
"xUnit": "mg/L", "yUnit": "mV",
},
])
assert node_id in document.nodes
assert document.nodes[node_id].state.chart_type == "scatter"
assert "type" not in document.nodes[node_id].state.chart_data # v1 generated scene validator
assert document.nodes[node_id].state.chart_data["series"][0]["yError"] == [[0.1, 0.1], [0.2, 0.3]]
assert len(agent.calls) == 1
prompt = agent.calls[0]["source_text"]
assert "multiple named series" in prompt
assert "per-point error magnitudes" in prompt
assert "xScale=log10" in prompt
assert "xUnit='mg/L'" in prompt
assert "yUnit='mV'" in prompt
assert "Concentrations 1, 10" in prompt

asyncio.run(run())


def test_chart_options_are_strict_and_do_not_dispatch_invalid_requests():
async def run():
bus, _, notifications, agent, root = _setup()
for options, message in [
({"xScale": "ln"}, "xScale must be linear or log10"),
({"errorBars": "yes"}, "errorBars must be a boolean"),
({"newFeature": True}, "Unsupported chartOptions"),
({"xUnit": ""}, "xUnit must be a nonempty unit"),
]:
result = await bus.dispatch_intent("scene", "generateChart", [root, "scatter", options])
assert result is None
assert notifications.payload()["message"] == message or message in notifications.payload()["message"]
assert agent.calls == []

result = await bus.dispatch_intent("scene", "generateChart", [root, "bar", {"yScale": "log10"}])
assert result is None
assert "require line or scatter" in notifications.payload()["message"]
assert agent.calls == []

asyncio.run(run())


def test_invalid_model_scatter_result_gets_a_valid_numeric_placeholder():
async def run():
bus, document, _, _, root = _setup({
"type": "scatter", "xScale": "log10", "xValues": [0, 1], "values": [1, 2],
})
node_id = await bus.dispatch_intent("scene", "generateChart", [root, "scatter"])
assert node_id in document.nodes
assert document.nodes[node_id].state.chart_type == "scatter"
assert "log10 axis" in document.nodes[node_id].state.chart_error
assert document.nodes[node_id].state.chart_data["xValues"] == [1.0, 2.0]
assert "type" not in document.nodes[node_id].state.chart_data

asyncio.run(run())
Loading
Loading