Skip to content

Add CIJ_PROXY global download proxy (explicit config injection)#148

Open
yzx9 wants to merge 9 commits into
mainfrom
cij-proxy
Open

Add CIJ_PROXY global download proxy (explicit config injection)#148
yzx9 wants to merge 9 commits into
mainfrom
cij-proxy

Conversation

@yzx9

@yzx9 yzx9 commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a single CIJ_PROXY environment variable that proxies all backend downloads and serves as the fallback proxy for the LLM/VLM clients.

Before this, only the LLM/VLM API clients honored a proxy (COPILOTJ_LLM_PROXY); every download path — HuggingFace weights, the LiteLLM model DB, the BioImage model zoo, Tavily/DuckDuckGo research, and cellpose/stardist segmentation weights — had no proxy support, so none worked behind a restricted network.

What it covers

The proxy is passed explicitly to each download client — no global proxy env vars are set, so localhost services (Ollama at 127.0.0.1:11434, the bridge WebSocket, the plugin API) are never proxied:

Download point Mechanism
LLM/VLM API clients proxy = cfg.llm_proxy or cfg.cij_proxy
HuggingFace embeddings huggingface_hub.set_client_factory(...) (proxied httpx.Client), set once at startup
LiteLLM model DB (async / sync) aiohttp proxy= / urllib ProxyHandler
Tavily TavilyClient(proxies=…)
DuckDuckGo DDGS(proxy=…)
BioImage zoo + model download requests session.proxies
cellpose / stardist scoped temporary_proxy(cfg) — these libs only read HTTP_PROXY

cellpose/stardist have no explicit proxy parameter (raw urlopen/urlretrieve), so they're wrapped in the existing temporary_proxy context manager for the duration of the weight download only, then restored. This is the single place env vars are touched, and it's scoped + reverted.

Also fixes a latent bug where new_vlm_model_client ignored cfg.vlm_proxy.

Explicit config injection (no load_config() lookups)

Following the "explicit over global" preference, the download clients receive Config explicitly rather than calling load_config():

  • ddg_search, cellpose_segmentation, stardist_segmentationmake_*(cfg) factories (TOML functionfactory). cellpose/stardist use functools.partial (which FunctionTool already supports) to avoid re-indenting large functions; tool schemas are unchanged.
  • The model DB download path (download_db, get_model_capabilities, list_catalog_models, ensure_model_db_async) threads an optional cfg from the server / resolve_vision_config / model_listing.
  • The HuggingFace proxy is configured once at process startup (server._ensure_kb, appose_worker.start_server, scripts/rag_builder.py), so the get_embeddings singleton needs no cfg.

load_config() now remains only at genuine process boundaries (__main__, the CLI/startup entry) and as a defensive (cfg or load_config()) fallback in the rarely-hit model-DB cache-miss path.

Verification

  • just test166 passed (incl. test_agent_loader confirming the factory = tools resolve with correct schemas, test_model_info/test_model_listing for the cfg threading, and new test_proxy suites).
  • ruff check + format clean across the package.
  • New tests: copilotj/test/core/test_proxy.py, copilotj/test/util/test_proxy.py, plus a proxy_dict doctest.

Docs

CIJ_PROXY documented in .env.template, AGENTS.md (the CLAUDE.md target), and DEVELOPMENT.md (config table + .env.local template).

@yzx9 yzx9 marked this pull request as draft June 21, 2026 01:50
@yzx9 yzx9 force-pushed the cij-proxy branch 2 times, most recently from 9ad4195 to fbf7fb1 Compare June 23, 2026 07:38
@yzx9 yzx9 added the enhancement New feature or request label Jun 24, 2026
yzx9 and others added 5 commits June 30, 2026 14:18
JAVA8_HOME was only for ad-hoc Java 8 downgrade checks and is not needed to
build: the core targets Java 8 bytecode via the JDK 21 compiler's --release
flag, and the dev mvn exec:exec fork cannot run on Java 8 anyway (--add-opens
is Java 9+). Remove pkgs.jdk8 from both devShells and the justfile note.
- vite ^6.4.3 -> ^8.0.12 (resolves to 8.0.16; now Rolldown + Oxc + Lightning CSS)
- @tailwindcss/vite ^4.2.1 -> ^4.2.2 (required: Vite 8 support landed in 4.2.2)
- tailwindcss ^4.2.1 -> ^4.2.2 (lockstep with the vite plugin)
- @vitejs/plugin-vue ^5.2.4 -> ^6.0.7 (current major; 5.x also declares vite ^8)

No vite.config.ts / tsconfig / Node changes needed (Node already >=22.12 in the
nix shell, CI, and Dockerfile). vue-tsc, vite build, and prettier all pass.
Bumps [pypdf](https://github.com/py-pdf/pypdf) from 6.12.2 to 6.13.3.
- [Release notes](https://github.com/py-pdf/pypdf/releases)
- [Changelog](https://github.com/py-pdf/pypdf/blob/main/CHANGELOG.md)
- [Commits](py-pdf/pypdf@6.12.2...6.13.3)

---
updated-dependencies:
- dependency-name: pypdf
  dependency-version: 6.13.3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
fiji/fiji 'master' (the Fiji-Stable line) currently parents to pom-scijava 40.0.0, so this keeps the plugin aligned with the stable distribution while staying on Java 8 (no nix/CI toolchain change). Moves off 38.0.1: imglib2 6.3.0 -> 7.1.5, imagej2 2.15.0 -> 2.17.0, jackson 2.16.1 -> 2.18.0.

Supersedes Dependabot #115 (38.0.1 -> 44.0.0), which would raise the build's Java floor from 8 to 11.
syntax_error_counter in LeaderDriven.run() was never reset, so it tracked cumulative ReAct syntax errors across a whole dialog and could abort a task after 3 scattered, fully-recovered errors. Reset it to 0 at the recovery send_correction (the single choke point where the agent_resp-is-None branch routes), matching the existing tool_retry_counter reset idiom. A model that is genuinely stuck still aborts after max_syntax_errors consecutive errors.

Adds a regression test (test_leader_syntax_reset.py) covering both the cumulative-with-recovery case (now completes) and the 3-consecutive case (still aborts).

Assisted-by: Claude-Code:GLM-5.2
@yzx9 yzx9 changed the base branch from main to dev June 30, 2026 14:57
@yzx9 yzx9 requested a review from 00JackLu June 30, 2026 14:58
@yzx9 yzx9 marked this pull request as ready for review June 30, 2026 14:58
Comment thread copilotj/appose_worker.py Outdated
yzx9 added 4 commits June 30, 2026 23:49
Introduce CIJ_PROXY: a single env var that proxies all backend downloads
(HuggingFace weights, LiteLLM model DB, BioImage model zoo, Tavily/DDGS
web research, cellpose/stardist segmentation weights) and acts as the
fallback proxy for the LLM/VLM clients when COPILOTJ_LLM_PROXY /
COPILOTJ_VLM_PROXY are unset.

The proxy is passed explicitly to each download client — no global proxy
env vars are set, so localhost services (Ollama, bridge WS, plugin API)
are never proxied. cellpose/stardist, which only read HTTP_PROXY, are
wrapped in the existing scoped temporary_proxy context manager for the
weight download only. Also fixes a latent bug where new_vlm_model_client
ignored cfg.vlm_proxy.

The resulting download clients receive Config explicitly rather than via
load_config() lookups: ddg_search / cellpose_segmentation /
stardist_segmentation become make_*(cfg) factories (cellpose/stardist via
functools.partial, which FunctionTool already supports), the model DB
download path threads an optional cfg from the server, and the HuggingFace
proxy is configured once at process startup.

Adds proxy unit tests (copilotj/test/{core,util}/test_proxy.py) and a
proxy_dict doctest, and documents CIJ_PROXY in .env.template, AGENTS.md,
and DEVELOPMENT.md.
functools.partial breaks FunctionTool's parameter introspection, so the
LLM-visible schema for these tools was wrong. Use the same nested-def
closure pattern as make_tavily_search / make_ddg_search: make_*(cfg)
defines the inner tool function (closing over cfg) and returns it. The
inner Annotated signatures are unchanged.
new_vlm_model_client now passes proxy=cfg.vlm_proxy or cfg.cij_proxy, so VLM
prefers cij_proxy over llm_proxy. Update the test to assert the effective
chain (vlm_proxy > cij_proxy > llm_proxy; llm_proxy remains a last-resort
fallback via _new_model_client).
new_vlm_model_client passes allow_llm_proxy_fallback=False so
_new_model_client does not fall back to cfg.llm_proxy on the VLM path.
Effective VLM chain: vlm_proxy > cij_proxy. Update the test and the
DEVELOPMENT.md config table to match.
@yzx9 yzx9 changed the base branch from dev to main July 3, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants