Commit b4e7b0f
authored
ufs-runner-mcp: fix path sandbox symlink regression, override warning, and output dedup (#101)
* ufs-runner-mcp: fix path sandbox, honest overrides, output dedup, async blocking
The path sandbox rejected every real RDHPCS mount (/scratch3, /work2/noaa,
...) since only the exact unnumbered prefix passed is_relative_to; fix by
allowing a digit suffix on the path component right after root while still
rejecting siblings like /work-attacker or /workfoo.
ufs_create_experiment documented flat overrides (dt_ocean, rnday, ibc, ...)
that have no matching {{placeholder}} in the schism_sandy_duck template, so
they were silently dropped while the tool still reported success; now
unmatched flat/namelist-group overrides and namelist write failures are
tracked and surfaced as an explicit warning section in the tool output.
collect_outputs globbed slurm-*.out separately even though the existing
"*.out" pattern already matches it, double-counting every Slurm log; dedupe
by resolved path instead.
All async tools called blocking UfsRunner methods (sbatch/sacct/scancel
subprocess calls, shutil.copytree, read_text/write_text, rglob) directly,
stalling the event loop for up to 30s per Slurm call; wrap those calls in
asyncio.to_thread at the tool layer.
* ufs-runner-mcp: fix review findings in path sandbox, overrides, dedup
Path sandbox: _prefix_matches resolved the input path but compared it
against the raw-string prefix, so a symlinked allowed root (common on
HPC sites, e.g. /work -> /lustre/work) got rejected — the same class of
"rejects real HPC mounts" bug the previous commit was meant to fix,
reintroduced via the digit-suffix matching logic. Now try two checks:
numbered-mount leniency on the raw prefix (unchanged, so /scratch3 style
siblings still work even if the base prefix is itself a symlink) and
symlink-transparent containment on the resolved prefix (fixes the
regression, and also resolves a relative env-supplied prefix against cwd
instead of silently no-op'ing). A configured prefix that resolves to just
"/" is now dropped with a warning instead of silently doing nothing or
becoming an accidental allow-all.
Override honesty: unmatched_flat_keys was computed against only the keys
that hit a literal {{placeholder}}, so overriding ocn_tasks/atm_tasks —
which drive OCN_petlist_bounds and total_tasks through
_compute_derived_vars without ever appearing as a placeholder themselves
— was falsely reported as having no effect, contradicting the feature's
own intent. Seed the matched-keys set with what _compute_derived_vars
actually consumes.
collect_outputs dedup: keying on the resolved path collapsed distinct,
both-meaningful directory entries that happen to point at the same file
(e.g. latest.nc -> history.nc), silently dropping one from the listing.
Key on the path relative to run_dir instead — this still catches the
original slurm-*.out double-count (same directory entry matched twice)
without merging legitimate symlinks.
ufs_list_templates still did blocking filesystem I/O directly in an
async function, unlike every other tool in this file. Move the logic
into a UfsRunner.list_templates method and call it via asyncio.to_thread,
matching the existing pattern.
Each fix was reproduced against the pre-fix code and reverified after;
6 new tests cover the symlink/relative/root-prefix path cases, the
ocn_tasks-alone override, and the symlinked-output listing.1 parent 3db7544 commit b4e7b0f
6 files changed
Lines changed: 558 additions & 54 deletions
File tree
- servers/ufs-runner-mcp
- src/ufs_runner_mcp
- tools
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
29 | 42 | | |
30 | 43 | | |
31 | 44 | | |
32 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
33 | 60 | | |
34 | 61 | | |
35 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
36 | 126 | | |
37 | 127 | | |
38 | 128 | | |
39 | 129 | | |
40 | 130 | | |
41 | 131 | | |
42 | 132 | | |
43 | | - | |
44 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
45 | 136 | | |
46 | 137 | | |
47 | 138 | | |
48 | | - | |
| 139 | + | |
49 | 140 | | |
50 | 141 | | |
51 | 142 | | |
| |||
0 commit comments