Preserve native Hermes browser discovery during gateway startup #326
No reviewers
Labels
No labels
area:authentication
area:flake-utilities
area:performance
area:tbd
host:chaos
host:cosmos
host:electra
host:fleet
host:lena
host:lyra
host:mass-storage
host:media1
host:nimmog-de
host:nova
host:pangolin
host:pangolin-vps
host:phone
host:router
host:vega
investigation
phase:cutover
phase:deploy
phase:mcp
phase:module
phase:packaging
phase:prep
phase:validation
priority:high
priority:medium
project:attic-postgres-lyra-rollout
project:auto-update-reliability
project:auto-update-remediation
project:declarative-purity-cleanup
project:external-review
project:fleet-boundary-cleanup
project:host-facts-refactor
project:lyra-nixos-deploy
project:lyra-service-stack-migration
project:nebula-mesh-network
project:nix-idioms-hygiene
project:nixos-build-deployment-pipeline
project:security-hardening
project:service-stack-migration
project:vega-sillytavern-cutover
project:wiki-rebuild
repo:numtide/flake-utils
repo:numtide/nix-auth
repo:numtide/nixos-passthru-cache
repo:numtide/nix-relay
service:auto-update
service:gitlab
service:hermes
service:mem0
service:nix
service:sillytavern
service:slskd
service:synthseek
service:tdarr
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
nimmo/nixos-config!326
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/hermes-browser-entrypoint"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hermes's deployed gateway still selected PM's generic Linux agent-browser after MR #325. Gateway startup prepends its upstream package directory to sys.path, bypassing the original PYTHONPATH tools overlay and restoring PM-first discovery.
Install a targeted Python import hook for tools.browser_tool_install so patched native discovery survives that prepend. Other tools continue loading from the same upstream venv. Keep the explicit native agent-browser/Chromium paths and strict patch compatibility checks.
Add a flake regression check covering the shipped hermes wrapper/console entry point, cached PM precedence after gateway bootstrap, sibling-tool imports, invalid native overrides and upstream PM behavior without an override. The entry-point case supplies only an isolated CLI-body shim via PYTHONPATH and requires the shipped wrapper to install the hook and explicit native runtime paths. No cache deletion or migration code is needed.
Validation:
Refs #321. Milestone: Hermes reported configuration gaps. This repair has not been deployed. Keep #321 open until browser tools succeed from Hermes's normal gateway after deployment; the required deployment no-op follow-up is also still pending.
Automated code review
Reviewed commit:
51fd3d71f099eed7a6c0e5d5c90d610409f7eb96Verdict: Ready to merge
No blocking or important findings were retained, and deterministic checks passed. Suggestions remain advisory.
Overall assessment
The supplied change swaps the overlay's
tools/__init__.py__path__append for asitecustomize.pymeta-path finder that interceptstools.browser_tool_installbefore the gateway'ssys.path.insert(0, project_root)can restore upstream discovery, and adds anix flake checkderivation that replays that bootstrap against the packaged venv. Within the supplied material the pieces are consistent:hermes-browser-tools.patchtouches onlytools/browser_tool_install.py, so dropping the__init__.pycopy and the two-filecp/chmodloop keepspatch --fuzz=0 -p1applicable to the single remaining copy (hermes-browser-package.nix:29,32); the overlaytools/directory now has no__init__.py, sotoolsresolves to the upstream venv package and the sibling-tool test matches that; the patch readsHERMES_AGENT_BROWSERat call time inside_find_agent_browser, which is what the four test bodies assume;wrapProgramstill prefixes the overlay directory and setsHERMES_AGENT_BROWSER/AGENT_BROWSER_EXECUTABLE_PATHexactly as before (hermes-browser-package.nix:36-39); and the check binds toself.nixosConfigurations.vega.config.services.hermes-agent.package, the only consumer of this module (modules/services/hermes.nix:186-191, enabled only from hosts/vega/default.nix:268), following the same pattern as the existinghermes-fleet-sshcheck. I found no defect demonstrably wrong in the supplied code; the retained finding is a coverage gap in the new check, and the remaining concerns depend on upstream Hermes internals that are not in this checkout.Blocking findings
None.
Important findings
None.
Suggestions
The check runs
${package.hermesVenv}/bin/pythonafterexport PYTHONPATH=${package}/lib/hermes-nixos-browser(flake.nix:233-235). The only shipped mechanism that installs the new hook iscp ${./hermes-browser-sitecustomize.py} "$out/lib/hermes-nixos-browser/sitecustomize.py"pluswrapProgram "$out/bin/hermes" --prefix PYTHONPATH : "$out/lib/hermes-nixos-browser"(modules/common/hermes-browser-package.nix:31,36-37);$out/bin/hermesis never executed by the check, even though postInstall still asserts it exists and is executable (hermes-browser-package.nix:19-22).Impact: The check proves the finder works when PYTHONPATH is supplied by hand, not that the packaged entry point actually loads
sitecustomize. AwrapProgramregression, a renamed entry point, or an interpreter invoked with-S/-Iwould keepnix flake checkgreen while the deployed gateway silently reverts to PM's cached browser - the failure mode this MR exists to prevent.Suggested fix: Add an assertion in the check that drives
$package/bin/hermes(or otherwise proves the wrapped entry point resolvestools.browser_tool_installto the overlay copy) so the delivery mechanism, not only the hook, is covered.Tests and validation
Questions
sitecustomizemodule? CPython imports only the firstsitecustomizeon sys.path, and the overlay directory is placed first bywrapProgram(hermes-browser-package.nix:36-37), so an existing one would now be shadowed - and the finder is prepended tosys.meta_pathfor every process inheriting that PYTHONPATH, including Hermes' subprocesses, not only the gateway.agent_browser_runnable(native)a pure existence/executability check, or does it execute the binary? Test 1 (scripts/test-hermes-browser-runtime.py:33-34) calls_find_agent_browser(validate=True)withHERMES_AGENT_BROWSER=${pkgs.lib.getExe pkgs.agent-browser}(flake.nix:234); if it executes, the check becomes sandbox/network-sensitive.tools/browser_tool_originguaranteed to exist upstream, and ishermes_clia source package directly under the venv's site-packages? Test 2 derivesproject_rootfromPath(find_spec('hermes_cli').origin).parent.parent(scripts/test-hermes-browser-runtime.py:14) and assertsPath(browser_tool_origin.__file__).parent == project_root / 'tools'(line 45); a namespace package or extension module would makeoriginNone and fail the check for reasons unrelated to this fix.tools/__init__.pyimportbrowser_tool_installeagerly at package import? If so,sys.modules['tools.browser_tool_install']would already be populated whenfrom tools import browser_tool_installruns, the meta-path finder would never be consulted, and the unpatched module would be used - the previous__path__overlay did not depend on that.site(e.g.-S,-I, or a subprocess with a rebuilt environment), wheresitecustomizenever runs and discovery reverts to PM?Review limitations
hermes-agentflake input (github:NousResearch/hermes-agent, flake.nix:37) is not vendored in this checkout, so upstreamtools/browser_tool_install.py,tools/__init__.py,tools/browser_tool_origin,hermes_cli, thehermesVenv/python.sitePackagespassthru, and the tail of_find_agent_browserbeyond the hunk in modules/common/hermes-browser-tools.patch could not be inspected; the check's assumptions about those names are unverified.nix flake checkbuilds or only type-checks the new derivation was not verified against this repository's CI configuration.Diff coverage
README.md: reviewed — included in a context-limited batchflake.nix: reviewed — included in a context-limited batchmodules/common/hermes-browser-package.nix: reviewed — included in a context-limited batchmodules/common/hermes-browser-sitecustomize.py: reviewed — included in a context-limited batchscripts/test-hermes-browser-runtime.py: reviewed — included in a context-limited batchReview metadata
Implemented review #74's valid coverage suggestion in
3fa41a3. The fifth regression executes the shipped package/bin/hermes wrappers and console script with an isolated CLI-body shim, removes inherited HERMES_AGENT_BROWSER and Chromium overrides, and supplies only the shim via PYTHONPATH. It then performs the gateway path prepend, checks the overlay module origin, checks native selection against a cached PM record, and verifies the wrapper supplied Chromium. Sibling Hermes CLI modules remain upstream. The test fails on the deployed package and passes on the repaired package. Full nix flake check (including all five browser cases), Ruff and diff checks pass.Pinned-source answers to advisory questions:
Normal deployed-gateway browser acceptance remains pending after review and deployment; #321 stays open.
Automated code review
Reviewed commit:
3fa41a39ef080e068a6f2f84a0e741a7b05d911bVerdict: Ready to merge
No blocking or important findings were retained, and deterministic checks passed. Suggestions remain advisory.
Overall assessment
The change swaps the PYTHONPATH
tools/overlay (copy of upstreamtools/__init__.py+browser_tool_install.pywith an appended__path__) for asitecustomize.pymeta-path finder that intercepts the exact fullnametools.browser_tool_installand loads the patched overlay copy, plus a newhermes-browser-runtimeflake check that runs the packagedbin/hermesentry point and four probe cases through a simulated gatewaysys.path.insert(0, project_root)bootstrap. The unchangedhermes-browser-tools.patchstill targets onlytools/browser_tool_install.py, sopatch --fuzz=0 -p1remains applicable to the single copied file. The overlay layout and the test wiring are internally consistent: the overlay dir is prepended to PYTHONPATH bywrapProgram(modules/common/hermes-browser-package.nix:37) and by the flake check (flake.nix:229), sositecustomize.pyat the overlay root is the module Python resolves at startup, andos.path.dirname(__file__)(sitecustomize:13) points at that same overlay root, matching the test assertionPath(installer.__file__) == expected / 'tools/browser_tool_install.py'. I found no defect that would break evaluation or the build; the two concrete regressions are a narrowed build-time layout guard and an unbounded subprocess call in the new check script.Blocking findings
None.
Important findings
None.
Suggestions
probe() runs its subprocess without a timeout, unlike the packaged-entrypoint case in the same file (scripts/test-hermes-browser-runtime.py:81; high confidence)
The
probe()helper callssubprocess.run([sys.executable, "-c", BOOTSTRAP + assertions], cwd=..., env=..., check=False, capture_output=True, text=True)with notimeoutargument, while the sibling call at line 63 passestimeout=30(line 70). Two probes callinstaller._find_agent_browser(validate=True), which the unchanged patch (hermes-browser-tools.patch) implements asusable = agent_browser_runnable if validate else ...; if not usable(native), i.e. a readiness check on the native binary exported at flake.nix:231. Every other subprocess helper in this repository bounds its calls (scripts/test-codex-http-mcp.py:39timeout=5, scripts/nixos-pin-lifecycle.py:83timeout: int = 7200).Impact: A hang inside the native
agent-browserreadiness check leaves thehermes-browser-runtimederivation blocked indefinitely instead of failing, so the authoritative gatenix flake check(.forgejo/workflows/attic-cache.yml:140) can stall rather than report a regression failure; the packaged-entrypoint case would have surfaced the same hang as a TimeoutExpired failure.Suggested fix: Pass an explicit
timeoutto thesubprocess.runinprobe()(the same bound used by the packaged-entrypoint case) so a hung native binary surfaces as a failed check rather than a stalled one.Build-time guard no longer asserts the upstream
toolspackage layout that the new import hook depends on (modules/common/hermes-browser-package.nix:14; medium confidence)The required-file loop was narrowed from
for file in __init__.py browser_tool_install.py; dotofor file in browser_tool_install.py; do, and the copy fromcp "$upstream_tools/"{__init__,browser_tool_install}.pytocp "$upstream_tools/browser_tool_install.py"(diff of this file). The overlaytools/directory therefore has no__init__.pyand no__path__.appendline, so the only way the patched copy is reached is through the parenttoolspackage resolving from${hermesVenv}/${python.sitePackages}/tools— an assumption the new test asserts at runtime (test_other_tools_still_come_from_upstream:Path(browser_tool_origin.__file__).parent == project_root / 'tools'). The remaining build-time checks are only-x "$out/bin/hermes"andgrep -Fq 'def _find_agent_browser('on the single file.Impact: A Hermes revision that stops shipping
toolsas a regular package on the venv path (namespace package, renamed directory) now builds successfully and fails only at gateway startup, moving a layout regression out of thenix flake checkgate that ai-review.md treats as authoritative; the previous overlay caught it at build time.Suggested fix: Keep asserting that
$upstream_tools/__init__.pyexists, or add a build-time proof thattools.browser_tool_installresolves through the installed hook, so the layout assumption the new mechanism relies on is still caught during the package build.Tests and validation
Questions
sitecustomize.pyunder${hermesVenv}/${python.sitePackages}? The overlay directory is prepended to PYTHONPATH (modules/common/hermes-browser-package.nix:37, flake.nix:229), and Python imports only the firstsitecustomizefound onsys.path, so an upstream one would be silently shadowed by modules/common/hermes-browser-sitecustomize.py.tools.browser_tool_install? The finder matches only that literal string (hermes-browser-sitecustomize.py:10) and returnsNonefor anything else, so an aliased or differently qualified import would load the unpatched upstream module.agent-browserandchromiumfromnixpkgs.legacyPackages.x86_64-linux(flake.nix:229-231), while the deployed package is built with the host'spkgs(inherit pkgs libat modules/services/hermes.nix:188-190). Are those the same binaries on vega, or could an overlay make the check exercise a different native binary than the service sets?test_packaged_entrypoint_installs_hook_and_native_paths, which also assertsinstaller._find_agent_browser(validate=True) == os.environ['HERMES_BROWSER_TEST_NATIVE']. Which specific cases were observed failing?Review limitations
tools/browser_tool_install.py(unpatched),tools.browser_tool_origin,hermes_cli,agent_browser_runnable, and_agent_browser_candidate_presentwere not supplied, so the test assertions against them and the module's own import style could not be verified.nix flake check, the newhermes-browser-runtimederivation, the Hermes package build, and any formatter/linter were not run, so the reported validation results come only from the untrusted MR text.browser_execopening example.com, the interpreter-shutdown cleanup warning, PM precedence in the deployed gateway) is not reproducible from the supplied material.test_other_tools_still_come_from_upstream,test_without_native_override_upstream_pm_behavior_is_preserved) appear to pass identically with or without the overlay, but no supplied repository rule requires that coverage, so this was not reported as a defect.modules/common/hermes-browser-package.nixis imported only bymodules/services/hermes.nix, which onlyhosts/vega/default.nix:42includes.Diff coverage
README.md: reviewed — included in a context-limited batchflake.nix: reviewed — included in a context-limited batchmodules/common/hermes-browser-package.nix: reviewed — included in a context-limited batchmodules/common/hermes-browser-sitecustomize.py: reviewed — included in a context-limited batchscripts/test-hermes-browser-runtime.py: reviewed — included in a context-limited batchReview metadata
Review #75 follow-up: implemented the valid unbounded-probe suggestion in
295004b. Every regression subprocess now has timeout=30. Ruff and full nix flake check pass, including all five browser cases.The proposed regular-package guard is not required by this import hook. An isolated fixture with tools as a namespace package (no init.py; tools.file is None) successfully loads browser_tool_install through the identical finder. If upstream renames tools or removes browser_tool_install.py, the existing required-file check already rejects the build. If module resolution or sibling imports change, hermes-browser-runtime runs in nix flake check and fails; it is incorrect that this would escape that gate. The actual pinned upstream package remains regular and side-effect free. No speculative init.py requirement added.
Additional answers: the current interpreter has no default sitecustomize; source inspection and the real browser_exec canary show the exact tools.browser_tool_install imports. The packaged-entrypoint test compares wrapper-selected native agent-browser with the flake-check expected path, so different service/check agent-browser binaries would fail it. The old package failed test_native_browser_wins_over_cached_pm_after_gateway_bootstrap and test_missing_native_binary_fails_instead_of_using_pm_cache in the original four-case suite; the added test_packaged_entrypoint_installs_hook_and_native_paths also fails against that old package. Three old-package failures have therefore been independently observed across the two runs.
The new current head requires its own review; the monitoring deadline remains unchanged. No merge or deployment performed.
The authorized one-hour monitoring window has ended. Implemented review #74's actual packaged-entrypoint coverage in
3fa41a3and review #75's subprocess timeout in295004b; both were validated with Ruff and full nix flake check before pushing. The unsupported regular-package layout claim received an evidence-backed response.Final observed head:
295004ba7e. CI test passed; its AI review remains pending, so the older Ready to merge verdicts do not establish current-head review completion. The heartbeat has been removed, with no extension or replacement. No merge or deployment performed. #321 remains open for normal deployed-gateway browser acceptance and the deployment no-op evidence.Automated code review
Reviewed commit:
295004ba7e52681533d98f2be8d4b77a725bd908Verdict: Ready to merge
No blocking or important findings were retained, and deterministic checks passed. Suggestions remain advisory.
Overall assessment
Strict validation pass over the initial review. The changed files are internally consistent with each other and with the checked-out code:
modules/common/hermes-browser-package.nixkeeps the layout guards it still needs under the new scheme (upstream_tools/browser_tool_install.pypresence,grep -Fq 'def _find_agent_browser(',patch --fuzz=0), copies only the one module the unchangedhermes-browser-tools.patchhunks target, and installssitecustomize.pyat the root of the same directory the existingwrapProgram --prefix PYTHONPATHalready prepends;modules/services/hermes.nix:188setsservices.hermes-agent.packagefrom that module and the module already readsold.passthru.hermesVenv, soflake.nix:235(self.nixosConfigurations.vega.config.services.hermes-agent.package) andpackage.hermesVenvare valid references; Hermes is composed only on Vega (grepoverhosts/matches onlyhosts/vega/default.nix), so themodules/common/placement does not widen host scope.scripts/test-hermes-browser-runtime.pyderives the upstream root fromfind_spec('hermes_cli').originconsistently in both the entry-point test and the probes, and itssys.path.insert(0, project_root)bootstrap is exactly the case the meta-path finder is meant to survive. I found no defect that is demonstrably caused by the supplied diff. All three initial-review findings were dropped: thesitecustomizeshadowing/skipping concern (finding 1) and the droppedtools/__init__.pylayout guard (finding 2) both depend on upstream Hermes venv contents that were not supplied and describe hypothetical future revisions, not a change-induced defect; finding 2's second half (collapsing the single-elementfor file in browser_tool_install.pyloop) is stylistic only. The flake-check blast-radius concern (finding 3) is a scope/design observation, not a defect: the check is a deliberate regression check, AGENTS.md and.forgejo/ai-review.mdstate thatnix flake checkis the authoritative gate without any rule that checks must be evaluation-only, and the gate already runs non-evaluation subprocess work (checks.x86_64-linux.formatting = treefmtEval.config.build.check self;at flake.nix:216).Blocking findings
None.
Important findings
None.
Suggestions
None.
Tests and validation
Questions
sitecustomize(or any othersitecustomizereachable at interpreter startup) thatcp ${./hermes-browser-sitecustomize.py} "$out/lib/hermes-nixos-browser/sitecustomize.py"now shadows, and would that module's side effects be lost for the gateway process?scripts/test-hermes-browser-runtime.py:112importsfrom tools import browser_tool_origin; is that a real upstream module in the Hermes venv'stools/package? No other file in this checkout references that name, so the regression's 'other tools still come from upstream' assertion cannot be confirmed against supplied material.bin/hermesentry point resolvemainthroughhermes_cli.mainas a submodule attribute, as the test's generated shim assumes ((shim / "main.py").write_text("def main(): ...")plus an__init__.pythat only appends__path__)? If the console script importsmainfromhermes_cli/__init__instead, the entry-point regression would fail for a reason unrelated to browser discovery.browser_execpath re-exec a Python interpreter with-S,-E, or-I, which would skipsiteinitialization and therefore never install the meta-path finder? Nothing in the supplied entry point or module records at runtime that the hook was installed.Review limitations
nix flake check, the repaired package building, five regressions passing, the deployed package failing two native-selection cases) are taken as stated, not verified.hermes-agentpackage source was not supplied: its venv layout,bin/hermesentry point,tools/package contents,pmAPI, and therun_gatewaysys.path prepend are known only through this repository's overlay and the PR text, so no behaviour of that unchanged upstream code could be confirmed.modules/common/hermes-browser-tools.patchis unchanged by this PR; I confirmed only that its hunks targettools/browser_tool_install.py, not that they still match the current upstream source.second_pass,max_diff_bytes, and batch settings in.forgejo/ai-review.ymlconfigure the review runner, not repository behaviour, and were not treated as evidence.Diff coverage
README.md: reviewed — included in a context-limited batchflake.nix: reviewed — included in a context-limited batchmodules/common/hermes-browser-package.nix: reviewed — included in a context-limited batchmodules/common/hermes-browser-sitecustomize.py: reviewed — included in a context-limited batchscripts/test-hermes-browser-runtime.py: reviewed — included in a context-limited batchReview metadata
Pre-merge integration validation with updated main
6825bbf(auto-updated flake inputs) is complete. The update advances Hermes from 6e7b83a to d97007c along with Home Manager, llm-agents, NUR, Paseo and Trilium. An isolated merge checkout combines that exact base with reviewed head295004b, without changing the MR head or invalidating review #76.The exact combined tree passes full nix flake check, including five browser regressions, and the real Hermes package builds as /nix/store/yzvxx8w5qz5hvjlra3nqxcyckcsl9ci4-hermes-agent-0.0.0. An isolated browser_exec canary using the updated package and gateway path prepend opened example.com and returned Example Domain through the harness. Explicit cleanup ran; the same previously recorded upstream interpreter-shutdown warning followed. Remaining evaluation warnings are upstream stdenv deprecations; ignored temporary evaluation-cache contention did not prevent successful validation.
Current-head review #76 is Ready to merge with no findings, and MR CI passed. Merging with the user's explicit authorization; #321 remains open for deployment, normal-gateway browser acceptance and the deployment no-op evidence.