Skip to content

fix: build hed-suggest into the image so suggest_hed_tags works - #599

Merged
neuromechanist merged 7 commits into
OpenScience-Collective:developfrom
bendichter:fix/hed-suggest-image
Oct 8, 2026
Merged

neuromechanist merged 7 commits into
OpenScience-Collective:developfrom
bendichter:fix/hed-suggest-image

Conversation

@bendichter

@bendichter bendichter commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #595.

Summary

suggest_hed_tags returns "Tag suggestion tool is not available" on every call in production, because the image has neither Node nor the hed-suggest program the tool runs.

This adds a build stage that builds hed-lsp's server package at a pinned commit, then copies it and the Node binary into the image and sets HED_LSP_PATH, which the tool already reads. There is no Python change.

  • The stage runs the program once and fails the build if "button press" does not return Button.
  • onnxruntime-node, onnxruntime-web and sharp are removed after a production-only install. They serve only --semantic, which the tool does not pass, and are about 340 MB of the 450 MB install.
  • .git, the VS Code client, docs and TypeScript sources are removed before the copy.

Tests

  • docker build -f deploy/Dockerfile . succeeds (linux/arm64, Docker under Colima).
  • In the built container with --network none, suggest_hed_tags.invoke({"search_terms": ["select object", "retention delay", "mouse click"], "top_n": 5}) returns tags in 0.24 s. Without the change it returns the error.
  • Image size: 1.03 GB before, 1.34 GB after (/opt/hed-lsp is 118 MB; the rest is the Node binary).
  • Not built for linux/amd64, and not run in the real deployment.

The measurements of what the working lookup changes for HED answers are in #595.

Review follow-up

Commits added to this branch after review (9d5ab0b to d682f49):

  • The build gate asks for Press from --top 10 "button press", a tag HED 8.4.0 defines. It asked for Button, which the schema does not define: hed-lsp's keyword map is not filtered against the schema, so some suggestions are not valid tags.
  • pnpm install runs with --ignore-scripts in both steps, so no dependency runs code during the build.
  • A comment in the Dockerfile says why --semantic cannot work in this image (onnxruntime-* is removed) and that the Node tag floats.
  • suggest_hed_tags drops a term that starts with -, so it cannot be read as an option, and runs the program with only PATH in its environment, so the server's secrets are not visible to it. The tool and module text now describe what the program does without --semantic, a keyword and schema-substring lookup, not "semantic search".
  • tests/test_tools/test_hed_suggest.py (new, 6 tests): five against a real executable on PATH, one against the real program, skipped when no build exists.
  • The Docker CI job runs suggest_hed_tags inside the built image with --network none.

Additional tests:

  • Docker job (linux/amd64) green at d682f49, including the new suggest_hed_tags step. Test (3.11), Test (3.12), Lint and Frontend Tests are green too.
  • The Node binary from the build stage runs in python:3.12-slim-bookworm on the deployment host (x86_64).
  • The embedding model neuromechanist/Qwen3-Embedding-0.6B-ONNX-Q8 exists on Hugging Face and can be pulled; the tool does not need it, because --semantic is off.

Not covered:

  • Not run in the real deployment.
  • hed-lsp's keyword map can still suggest tags the schema lacks (Button, Mouse). The prompt requires validate_hed_string on every tag, which catches them; filtering the map would be a change in hed-lsp.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The stage asserted "Button", which is not a tag in HED 8.4.0 (hed-lsp's keyword
map is not filtered against the schema). Assert "Press", which the pinned
commit returns for "button press" and the schema defines. Ran the pinned CLI
locally (macOS, Node 26): "button press" returns Press at --top 10. The Linux
image build is tested by CI only.
Comment only. With --semantic the program prints status lines to stdout ahead of
the JSON (seen locally), onnxruntime is stripped from the image, and the model
would download into a non-volume path. Also notes why the Node tag floats.
Not built; no code change.
onnxruntime-node's postinstall downloads a GPU package from nuget.org on amd64
(seen in the CI log), and the result is deleted afterwards, so a NuGet outage
would fail every image build. tsc and the program need no install scripts.
Tested locally: a --frozen-lockfile install with and without --prod and
--ignore-scripts compiles with tsc and the CLI returns suggestions, also with
onnxruntime and sharp removed (macOS, Node 26, pnpm 10.33.4). The Linux image
build is tested by CI only; drop this commit if CI shows the stage needs scripts.
suggest_hed_tags put every search term on the program's command line, and
hed-suggest reads an argument that starts with "-" as an option, so a term of
"--semantic" switched its mode. Such terms are no longer forwarded and map to
an empty list in the answer. The program also inherited the server's whole
environment, including the model provider keys; it now gets PATH only.

Adds tests/test_tools/test_hed_suggest.py: a real executable named hed-suggest on
PATH records what it receives, plus a test of the real program when a built
hed-lsp checkout exists (skipped otherwise). No mocks. 3 of the 6 tests fail on
the previous tools.py; all 6 pass now, with the real program run from a local
checkout under a PATH-only environment (macOS).
The tool description and two module docstrings called hed-suggest a semantic
search. The program runs a keyword map and a schema substring match; the
embedding mode is off and not in the image. The model-facing description now says
so, asks for short concrete terms, and says suggestions are candidates that can
include names HED 8.4.0 does not define (Button, Flash), so validate_hed_string
still decides. Docstrings only. tests/test_assistants, tests/test_tools and
tests/test_agents/test_hed.py pass (614 passed, 5 skipped, not network).
Nothing exercised the final image stage, so a bad COPY, PATH or HED_LSP_PATH
would ship and suggest_hed_tags would answer "not available" on every call
(issue OpenScience-Collective#595). The new step runs the real tool in osa-test:ci with --network none
and asserts no error key and the 8.4.0 tag Press for "button press".
Tested here: the workflow YAML parses, and the embedded script passes against a
locally built hed-lsp (macOS). The docker run itself can only be tested by CI.
@neuromechanist
neuromechanist merged commit e69ffc2 into OpenScience-Collective:develop Oct 8, 2026
7 checks passed
neuromechanist pushed a commit that referenced this pull request Oct 10, 2026
Retitles [Unreleased] to [0.8.18], as for earlier releases. Adds the entries
that were missing for #599 (hed-suggest in the image), #600 (HED prompt),
#601 (widget host styles) and #605 (live tests by hand), and one for the
DEFAULT_MODEL check at startup. Names the three classes that are accepted
(the other five are refused), and fixes a reference that pointed the wrong way.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019MtQNfPzMpGxEJFUciXbTN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants