Invalidate step cache when a plugin is (re-)installed
Yuchen Yuan
0894ed2
If a user re-uploads a plugin with the same kind + params, every
in-memory step-cache entry whose prefix covered that kind would
otherwise stay valid — the next run hit-served a result computed
by the OLD plugin code. Confirmed by code review: install_plugin_zip
overwrote the on-disk handler but never touched _step_cache.
Fix is a sidecar map of prefix_key → set of node types covered by
that prefix. _cache_put populates it; install_plugin_zip calls a
new invalidate_step_cache_for_node_type(kind) helper to evict any
entry that includes the affected kind. LRU eviction was updated
to drop both the cache entry and the sidecar entry in sync.
Unit-tested locally (4 scenarios: plugin invalidate, builtin
invalidate, no-match, LRU sync) — all green.
Global code-quality polish: DRY + named constants + leak cleanup
Yuchen Yuan+1: Claude Opus 4.7 (1M context)
57f0b3e
Targeted refactor pass based on a structured audit. Pure
maintainability wins; no behaviour changes.
Frontend: collapse 8 popovers into one hook
8 components (AuthButton, ThemeSwitcher, MoreMenu, PapersPopover,
SupportPopover, DevelopersPopover, BlockPicker, PresetPicker) each
carried an identical 16-line "close on mousedown + Escape" effect
block. Extracted to lib/useDismissOn.ts; ~150 lines deleted, one
hook to audit instead of eight.
useDismissOn(open, rootRef, useCallback(() => setOpen(false), []))
Behaviour is intentionally identical to the inlined block so older
git-blame on the call sites stays coherent.
Backend: consolidate effective-user-id resolution
routes/plugins.py and routes/workflow.py each carried a subtly
different implementation of "session cookie wins over query_user_id,
anon hf_ prefix is reserved". Pulled into
auth_service.resolve_effective_user_id(request, query, *, required).
- required=True path raises ValueError → routes/plugins maps to 400
- required=…
Full audit pass: leak fixes, sign-in clarity, functional bugs
Yuchen Yuan+1: Claude Opus 4.7 (1M context)
4c566b4
Triggered by user request "全方位的检查、测试" covering visualization,
user comprehension, page logic, ease-of-use, science, info leakage,
and security. Three parallel audits ran (info-leak, sign-in clarity,
visual/a11y, functional/scientific); fixes batched below.
Critical functional bugs
- workflow_service.run_pipeline + run_pipeline_stream now call
plugin_service.hydrate_from_dataset_if_needed before dispatch.
Without this, a logged-in user running a pipeline on a fresh
container (or on the mirror Space) would see "plugin not found"
even though it sits safely in their HF Datasets backing store.
- plugin_runner._scrub_scalars / _scrub_value drop NaN and ±Inf
instead of passing them through. Standard JSON has no representation
for either; model_dump_json emits NaN/Infinity which the browser's
JSON.parse refuses, so any plugin returning a numerically degenerate
scalar used to make the entire /run response fail to parse client-
side. NaN → dropped from scalars dict; Inf → nul…
What this lets users do
- Anyone can click "Sign in" in the top bar and authenticate with their
Hugging Face account (OpenID Connect via the HF OAuth flow). No
account creation, no password management on our side.
- Each signed-in user gets their own private namespace for uploaded
plugins. Other users (and other browsers from the same person)
cannot see them.
- Plugins uploaded while signed in are mirrored to a private HF
Dataset repo (qudastudio/quda-user-data) so they survive container
restarts and follow the user across devices.
- Guest (anonymous) mode is fully preserved: visitors can still drop
a .zip without signing in; those plugins continue to live in /tmp
and are per-browser, exactly as before.
Architecture
Browser ──cookie──▶ FastAPI ──HfApi──▶ HF Dataset (private)
│
└──▶ /tmp (volatile cache)
Identity = session cookie's hf_<username> (when signed in)
∥ anon UUID query par…
Polish pass on plugin Upload modal
Yuchen Yuan+1: Claude Opus 4.7 (1M context)
4d0158a
Detail review surfaced four small but meaningful items.
Storage listener over-fires (App.tsx)
- Was triggered by any quda.* key — included pane widths, theme,
live-IBM toggle. Tightened to e.key === "quda.pluginsRev" so only
actual plugin upload/delete events refetch. bumpPluginsRev() already
writes that exact key.
Duplicate-install regex collision (UploadPluginModal)
- /already have a plugin/i matched both the per-kind duplicate AND the
5-plugin cap message, so a user at cap who clicked Install on a
sample saw a green success banner. Tightened to
/already have a plugin with kind=/i so only the idempotent case
surfaces as a friendly hint; the cap is now an honest error.
- Added a Content-Type guard after the example zip fetch so a captive
portal serving an HTML 200 surfaces "got <type>, not a .zip" instead
of the confusing manifest-parse error from the backend.
Modal UX restructure
- Examples-first ordering when installedPlugins.length === 0 — a
first-time visito…
Plugin protocol Phase 5: final audit fixes + polish
Yuchen Yuan+1: Claude Opus 4.7 (1M context)
d06bf19
Defence-in-depth fixes from the security/UX/scientific audits:
Backend safety:
- Reject `\` and absolute paths in zip entry names (defensive even on
Linux containers).
- Cap stdin payload at 50 MB in the subprocess wrapper before parsing.
- Drop the full `/tmp/quda_plugins/<user>/<kind>/` path from the
"handler.py missing" error message — user already knows their kind.
Frontend UX:
- QNode now renders a red-bordered tombstone card with a "?" badge and
a "plugin not installed" hint when a referenced plugin has been
deleted, instead of silently disappearing.
- App.tsx listens for `storage` events on `quda.*` keys to refresh the
plugin list across tabs.
- UploadPluginModal title now reads "Upload your own block" with a
one-line explanation of what plugins do.
- TrySlide adds a "Upload your own block" tip alongside the Export .py
one so new users discover the plugin workflow.
Docs:
- README.md gains a User plugins section pointing to PLUGIN_SDK.md.
- PLUGIN_SDK.md adds a "…
Plugin protocol Phase 1: backend service + subprocess runner
Yuchen Yuan
34125c4
Three new backend modules to support user-uploaded plugin blocks:
* plugin_service.py — manifest schema (Pydantic), per-user storage
under /tmp/quda_plugins/<user_id>/, zip upload + validation:
- max 1 MB zip, ≤ 50 entries, ≤ 512 KB per file
- allowlist: .py / .json / .txt / .md only
- rejects path traversal (.., leading /)
- rejects reserved kinds (collisions with built-in block types)
- rejects > 5 plugins per user (count cap)
- validates manifest.json against PluginManifest schema (kind format,
family enum, hex color, unique param keys, …)
* plugin_runner.py — subprocess execution with safety measures:
- 10-minute hard timeout (subprocess.run(timeout=600))
- 1 GB virtual memory cap via RLIMIT_AS in preexec_fn
- 11-minute CPU time cap via RLIMIT_CPU
- os.nice(10) so a busy plugin doesn't starve FastAPI
- env stripped to allowlist (PATH, PYTHONPATH, HOME, TMPDIR, …)
— drops IBM_QUANTUM_TOKEN and any other Space secrets
- cwd set to plugin's own dire…