Repository navigation
Fix what a blind agent trial of the MCP tools found - #29
Merged
Merged
Conversation
A thickness of 0 is how the profile and both windows say "not entered", and the thin-film formulas multiply by it: every row's rho_ohm_cm was exactly 0 while sigma_S_cm was NaN, and the spot statistics reported a resistivity of 0 with an uncertainty of 0. A zero resistivity in a data file reads as a measurement. It has been so since thickness moved to micrometres in August 2025. calculate_resistivity now gives NaN for a thin-film model with no positive thickness, so the rows, the sample events (null on the wire), the footer statistics and both four-point panels have no resistivity either. The PySide6 summary export calls the same function instead of repeating the formula. The semi-infinite model does not read the thickness and still gives one.
GET /schema/settings listed vsource_run_continuous and isource_run_continuous among the override keys of every mode, because allowed_override_keys added both control keys to each. Only the voltage source reads the first and only the current source the second; to any other mode they were accepted and then ignored, which tells a client they do something. Each control key now belongs to its mode, and a strict request that sends another mode's flag is refused as a key the mode does not have.
A run request could name visa_library and gpib_interface in its overrides: both were offered by GET /schema/settings, passed the resolver and reached Keithley2400, which hands a library path to pyvisa to load with ctypes. That let the agent token load a library of its choosing, which the profile route refuses it (M3 in the MCP design), and let any request open a Prologix interface the machine is not set up with. Both are machine-local, like gpib_address, and are now profile-owned: the run uses this machine's, and a request that names either is refused with the key.
POST /settings/resolve, and so the MCP check_settings, was silent about two things a run then warns about or quietly does: a sampling rate above what the timing settings can deliver (derived.max_rate_hz said 4.79 Hz against 10 Hz asked, and the run sampled as fast as it could), and a four-point worst-case power above fpp_power_warn_w, which the run's pre-flight logs. The desktop worked the rate warning out for itself; an agent had to. The resolver now returns warnings, each the keys the judgement reads and a message, beside the issues. They are not issues and never make a start fail. The rate is judged with the timing model derived already uses, for the modes that read on a timer; the power with two functions now in calculations.py that the run's pre-flight calls too, so the preview and the run cannot disagree. SettingsWarning is exported to the contracts, and the desktop shows the backend's warnings in place of its own rate comparison.
describe_mode gave key names and values only: no choices for an enum such as fpp_model or auto_zero, no bounds, no units, no meaning. An agent learned what a key accepted by being refused. It also showed auto_zero "on" and filter_count 10 for four_point and vdp while the profile held "once" and 5, with nothing to say that those two modes always run with their own (MODE_TIMING_OVERRIDES). GET /schema/settings now gives, per mode, each override key's JSON-schema fragment from the pydantic models (type, choices, bounds, default, description) with a unit taken from the key's name, and the values the mode fixes. The models gain short descriptions where a key's name or choices do not explain it, such as which fpp_model formula applies and when the F84 corrections take over. describe_mode turns that into one line per key: the value a user's run would have, in its unit, and whether it comes from the profile or is fixed by the mode (naming the profile's value when it is not used), the default, what the key accepts, and what it means. It reads all of it over HTTP, as the MCP package must.
get_profile showed allow_agents: false to an agent that the backend had let in with --allow-agents. The key is this machine's stored switch, not what is in force, and the agent in the trial took it to mean it was not allowed to act. Being connected is the answer an agent needs, so the MCP tool leaves the key out and says why; the API is unchanged. list_instruments said the address a run uses is the profile's gpib_address, "set by a person". A run's overrides cannot name it, but the API does let any role edit it in the profile; what is true for an agent is that no tool here changes the profile. The description now says so, and to ask the user when the address is wrong.
Resistance and the source modes have no sample count. To take N readings an agent waited for samples:N and then called stop_run; the round trip between the two calls let a run asked for 20 readings write 57. wait_for takes then_stop: when the condition holds, the same call stops the run and waits, within the same timeout, for it to end, and returns the final status with stopped true and how the run ended. While it will stop the run it looks every 0.1 s instead of 0.5 s, so the file holds N rows or a few more: those read in that tenth of a second and the one in flight when the stop lands. A prompt or a timeout does not stop the run. Because it may now stop a run, wait_for no longer claims to only read. get_run_summary takes first_rows, to summarise exactly the N rows that were wanted; the result says how many rows the file has.
A vdP run with a thickness of 0 was refused ("needs a sample thickness
greater than 0 cm"), and the PySide6 window held Start at a thickness
prompt, while a four-point run takes 0 as "not given" and reports Rs.
Nothing in F76 Method A but the resistivity reads the thickness: the
sheet resistance is eq. (1) and (2) divided by it, and the homogeneity
ratio |rho_A - rho_B| / rho_av does not change with it. ResistaMet
implements no other check that needs it.
calculate_van_der_pauw now works in sheet resistance, through
vdp_sheet_resistance_pair, and multiplies by the thickness only when
one is given; otherwise the resistivities are NaN. The resolver drops
its thickness check, the run's log says there is no rho, the event's
resistivities are nullable (null on the wire, NaN in the file footer),
and both result panels show none. The PySide6 window no longer prompts.
The start_run description said vdP runs stop at prompts only a person
can answer, and nothing about how many or when. An agent could not
tell the user that someone has to stay at the bench.
describe_mode('vdp') now carries the prompts, as vdp_run.py raises
them: the touch-safety question first when the compliance is at or
above the threshold, then one rewiring prompt before each of the four
F76 geometries, each with the output off and timing out after
prompt_timeout_s. start_run says the same in short. An end-to-end test
has a person answer the four prompts of a run without a thickness and
finds the sheet resistance and no resistivity in the file.
docs/mcp.md: describe_mode's lines and vdP prompts, the warnings in check_settings, get_profile without allow_agents, wait_for's then_stop and get_run_summary's first_rows, with a section on taking a fixed number of readings. docs/api.md: the warnings of POST /settings/resolve and the keys and fixed values of GET /schema/settings. The design note's tool table follows, and its open item on bounds and units is closed.
The fpp_thickness_um description said a thickness of 0 leaves the sheet resistance; with the ASTM F84 corrections in use it does not, because F(w/S) needs the thickness and the row's Rs is NaN. It now says so. The desktop's van der Pauw thickness field gets the hint the four-point one has, now that 0 is allowed there.
The description said any key it lists can be changed for one run, but a mode-fixed key (auto_zero and filter_count in four_point and vdp) is replaced whatever an override says. It now says only the keys the mode does not fix can be changed.
At a pending prompt, wait_for("run_ended") and wait_for("state:running")
returned at once with fired "prompt" and waited_s 0, while the prompt
told the agent to tell the user and wait for the run. An agent could
not wait for the person at all.
A prompt the agent has already been shown, in any tool's reply, now
ends a wait only when until is "prompt". The server remembers the last
pending prompt it showed. Any other prompt still ends the wait at once:
one raised between start_run's reply and the first wait was pending
when the wait began but never shown, and waiting through it would leave
nobody telling the person. A wait that went through a prompt says so
in prompt_at_start, with still_pending. The person answering then shows
as the next prompt, the run's end or state:running; no answer yet, as
the timeout. The tool description and the who_answers text say how to
wait for a person.
check_settings answered "ok": true next to "agent_may_start": false for valid settings beyond the agent limits, and read quickly, ok looks like leave to start. The verdict is now can_start, first in the reply: true only when the settings are valid and the agent limits allow them, so start_run would accept them. ok stays, described as what it is, the settings being valid. The API's resolve reply is unchanged: the window reads ok for its own runs, which the agent limits do not bound.
The resolver copied the machine's allow_agents into every run's measurement settings, so the run_started event of a run an agent had started said allow_agents: false. The switch says who may drive the instrument, not how a run measures, and no run reads it. It is now left out of the resolved settings, as agent_limits always was, and a request that sends it is still refused by name. The data files never carried it: their header is built from named keys (build_metadata), for CSV, HDF5 and the legacy JSON alike. A test holds the event and the file to that.
The wiring of each geometry was said in words only in the run's log
line ("connect Force HI->C2, ...; press Measure."); the prompt an agent
reads and passes on carried source_high, sense_low and bare integers.
The prompt's detail now has message, one sentence with the four
contacts, and the log line is that same sentence.
"Press Measure" stays: both windows answer the prompt with a button
labelled Measure (the PySide6 tab's "Measure Geometry 1 of 4", the
desktop view's "Measure"); proceed is that button's answer on the API,
and the MCP description now says so. The desktop rendered a geometry
prompt only inside the van der Pauw view, so a run an agent started
while another view was open waited unseen. A dialog now shows the
message there and opens the view.
describe_mode('vdp') said a person would be asked to rewire four
times, but not to what, so an agent could not tell anyone beforehand
what the run would ask of them. GET /schema/settings now gives the vdp
entry a wiring list: each geometry's Force HI/LO and Sense HI/LO
contacts and the message its prompt will carry, built from
f76_geometries and wiring_message, as the run's prompts are. It also
gives the prompt timeout, its default and the most a start may ask
for. describe_mode passes both on; against a backend without them it
says nothing of either.
stop_run's reply was state "stopping" with the prompt the stop had just released still under pending_prompt. The run thread clears its prompt only when it wakes from the wait, a moment after the stop or the answer, and the status read the stored prompt until then. RunControl.pending_prompt is now None once the prompt has its answer or the run is finishing, so the status, the state (awaiting_prompt ends with the answer) and the answer route agree; an answer after a stop is refused, as the route already refused it once the status showed no prompt.
The trial found keys with no description in describe_mode, among them every four-point outline and position key, the compliances and their range switches, the aux sensor keys and the run-until-stopped flags. Each now says what the run does with it, read from the code that uses it: which fpp_model formulas read fpp_spacing_cm; that compliance rows are flagged, and four-point ones give lower bounds; what fpp_edge_warn_pct compares and when; why warn is the only fpp_position_correction; which side of a rectangle is which against the array angle; that with res_auto_range on the instrument chooses the test current while the file name and params.test_current_A still give the requested one. The run-until-stopped flags say they do what a duration of 0 does and exist for the window's checkbox. fpp_model opens with the default case: Rs = 4.532 x V/I, no corrections. The isource and vdp siblings of the keys named get the same.
The worst-case power warning said the power and the threshold and nothing about which setting gave the power, in the settings preview and in the run's log alike. It is |I| x V_compliance, so the text now says to lower fpp_voltage_compliance, with the largest compliance that would clear the threshold at the current set, or fpp_current. The preview and the log share the sentence (formatting.py), and the preview's keys put the compliance first, as the one to change first.
wait_for waits through the prompt the agent was last shown, but that is
remembered by the MCP server process. A client that starts a new server
for every call, or reconnects, forgets it, and in the third usability
trial wait_for('run_ended') at a van der Pauw prompt came back at once
five times, so the agent fell back to polling.
Add two forms that carry what the wait needs in the call itself.
until='prompt_answered' holds once the prompt pending when the call
began is pending no longer (answered, released, or the run ended), and
the status says what came next. ignore_prompt_id names a prompt that
does not end a run_ended, state: or samples: wait (and makes 'prompt'
wait for the next one); with prompt_answered it is the prompt the agent
expects, so one the person reached before the wait began is reported,
not waited on unheard.
who_answers now gives the stateless call with the prompt's id filled
in, and the tool description and server instructions recommend it. The
remembered prompt still works as before.
With res_auto_range on, the default, the instrument's auto-ohms chooses the test current and voltage limit per range. In the third trial an agent asked for 1 mA, the instrument used 100 mA, and the file name and params.test_current_A still said 1 mA. check_settings now returns notes, a list, and for a resistance run in auto range one says the current and limit are the instrument's choice, that I_meas records the current that flowed, and that res_auto_range false makes res_test_current the current sourced. The touch-safety note moves into the same list. It is not an API warning: the window's users chose auto range knowing what it does.
A sweep's header was point,V_source,I_meas,compliance whatever was sourced. The sweep engine returns VOLT,CURR,STAT in that order either way, so a current-sourced sweep wrote its measured voltage under V_source and its sourced current under I_meas. A current sweep's header is now point,V_meas,I_source,compliance; a voltage sweep's is unchanged, and the columns keep their order and units. The HDF5 and legacy exporters take the same column list. The desktop results view finds either pair, and splits the legs on the sourced column: I_source when the header says so, and for older files params.source_function, as before. docs/outputs.md said a current sweep's columns were I_source then V_meas, which no version wrote.
configure_sweep never wrote :SYST:RSEN, so a sweep ran in whatever
state the connect step's *RST left: remote sense off, 2-wire, with no
way to ask for 4.
Add sweep_measurement_type ('2-wire' by default, '4-wire') to the sweep
settings and DEFAULT_SETTINGS. configure_sweep writes :SYST:RSEN ON or
OFF before the sweep engine is set up, as configure_resistance does
before selecting the ohms function, and the file header records it as
params.measurement_type. The PySide6 sweep tab and the desktop sweep
panel offer it as each offers resistance's wiring.
The default keeps what every sweep did. Its configure sequence gains
the explicit :SYST:RSEN OFF, a no-op after *RST; the sweep goldens are
regenerated for it and a 4-wire golden added.
calculations_vdp applies it and still exports the name. A reader that may not import the calculations, as the MCP server may not, can now state the threshold the run used from the one definition.
In the third trial the agent dug a van der Pauw result out of the events, as bare sheet_resistance, rho_avg and sheet_resistance_uncertainty with no units, and fitted a sweep itself. get_run_summary now adds a result block, per mode, with a unit on every number, a one-line headline, and a line saying what the uncertainties are: standard uncertainties, k = 1, with the Keithley datasheet accuracy taken as one standard deviation as accuracy.py does. Rows in compliance are left out and counted. - resistance, source_v, source_i: the main quantity's mean and SD, and the mean per-reading instrument uncertainty from the file. - four_point: Rs, and rho and sigma when there is a thickness, with u_stat, u_inst and u_total from the file's spot_stats; from the rows while the run is going. - vdp: R_s and rho with their uncertainty, and the F76 homogeneity verdict with its criterion and threshold. - sweep: a least-squares fit of the measured quantity on the sourced one, in plain Python: R with its standard error, the intercept, n and r2. Either header form of a sweep file is read. The existing fields are unchanged.
PEEKPerformer
force-pushed
the
stack/26-mcp-server
branch
from
November 16, 2026 18:33
7db2d21 to
d142cde
Compare
PEEKPerformer
force-pushed
the
stack/27-trial-fixes
branch
from
November 16, 2026 18:33
a045540 to
3f0a17b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A blind usability trial of the MCP server ran an agent that knew nothing about the code. Using only the tools, it ran four lab tasks against the simulator and then reviewed the tools. This PR fixes what it found, plus one problem found while fixing them.
Four-point resistivity was written as 0 when no thickness was given (a data-file fix).
rho_ohm_cm= 0 whilesigma_S_cmwas NaN, and the spot statistics reported ρ = 0 ± 0.A run's overrides could choose the VISA library. That is a file path pyvisa loads as code, and any token could set it this way.
visa_libraryandgpib_interfaceare now profile-owned, likegpib_address, and a run request naming either is refused.The settings preview now warns about what the run will warn about.
POST /settings/resolvereturns non-blockingwarnings:The run's pre-flight check and the preview call the same functions. The desktop now shows the backend's warnings instead of computing the rate one itself.
override_keysoffered both run-until-stopped flags to every mode. Each flag now belongs only to its own mode.describe_modenow says what each setting accepts.GET /schema/settingsgives each key's type, choices, bounds, default, unit and a short description, and lists the values a mode always uses. That explains why four-point showedauto_zero: "on"while the profile says"once".MCP:
get_profileleaves outallow_agents, which misled the agent into doubting it was allowed to act.wait_for(..., then_stop=true)stops a run once its condition holds, which is the way to take a fixed number of readings. The trial's agent asked for 20 and got 57.get_run_summary(first_rows=N)summarises only the first N rows.describe_mode('vdp')andstart_rundescribe the van der Pauw prompts up front: touch-safety first if the run is hazardous, then four rewiring prompts with the output off.van der Pauw runs without a thickness and report sheet resistance only, as four-point already did. F76 sheet resistance and the homogeneity check do not need one.
Stack
Part 27 of 28. Targets
stack/26-mcp-server. Merge bottom-up with Rebase and merge. This PR's tree isphase0/reviewable-baseline(f801c5b) exactly.A third trial added a scripted colleague answering the van der Pauw prompts. The agent completed all four tasks, and its findings are fixed in the last six commits:
wait_for(until="prompt_answered")andignore_prompt_idwait for a person without relying on the server's memory between calls.V_source,I_measwhile holding the measured V and the sourced I. They are nowV_meas,I_source, and the readers accept both forms.sweep_measurement_type, defaulting to 2-wire. Every sweep now sends:SYST:RSEN OFF/ONbefore its setup. After*RSTthat changes nothing, but it has not been run on hardware, so please check it at the next bench session.get_run_summarygains aresultblock with units: a sweep resistance fit with its standard error, the vdP homogeneity criterion, and the four-point u_stat/u_inst/u_total. The uncertainties are stated as standard (k = 1).check_settingsnotes that auto-range resistance lets the instrument choose the current.Type of change
Hardware testing
The fixes come from a trial against the simulator. A second blind trial on these fixes went much further. The agent took exactly N readings in two calls, and it started a vdP run and handed it to a person. Its findings are fixed in the last eight commits:
wait_forcan wait through a prompt the agent has already relayed to a person.check_settingsleads withcan_start.allow_agentsstays out of run settings.describe_mode('vdp')lists all four wirings. The desktop raises a dialog for a rewire prompt from a run it did not start.Test suite
QT_QPA_PLATFORM=offscreen pytest tests/ -vpasses locally — 4102 passed, 51 skipped, 20 xfailed (desktop 146/146)How to verify:
Behaviour change
rho_ohm_cm, not 0.visa_libraryorgpib_interfacein its overrides is refused.Checklist
README.md/ version history if user-visible