perf(details): batch Conversation Details plugin loading, reuse frames & staged reveal #32

Closed
gabrielvidal wants to merge 0 commits from details-panel-perf into main
pull from: details-panel-perf
Owner

Summary

Optimizes the Conversation Details panel loading from up to ~42 HTTP requests + 10 simultaneous Python subprocesses down to 1 batched data request (plus 1 cached HTML bundle on cold start and 0 sandbox-frame fetches after first load), while keeping plugin iframes alive across conversation switches and revealing data-backed cards together in one smooth beat with zero blank-box flashes.

Key changes

  • Manifest & UI descriptors (backend/plugins/manifest.py, backend/plugins/routes.py, docs/plugins.md): Added optional ui.slots[].query (declaring a slot's initial readOnly action + parameterized $conversationId/$sessionId payload) and ui.slots[].reuseFrame (boolean opt-in to keep the iframe mounted across conversation switches), exposed via GET /api/plugins/ui without changing existing plugins' approval fingerprints.
  • Batched reads & HTML bundle (backend/plugins/batch.py, backend/plugins/routes.py, backend/plugins/proxyroutes.py):
    • Added POST and GET /api/plugins/batch-read (up to 32 readOnly items, bounded per-batch concurrency of 5 so one drawer never saturates REQUEST_SCRIPT_SLOTS=12, shared singleflight deduplication, per-item error isolation, and a 512-entry versioned cache: 30 s for finished conversations, 3 s for running ones, 5 s otherwise — invalidated on plugin lifecycle mutations, non-readOnly POSTs, and hub/changed).
    • Unified action authorization into batch.resolve_call() shared by single-action and batch routes.
    • Added GET /api/plugins/ui-bundle?where=<place> returning all active slot HTML documents in one payload with ETag / 304 Not Modified.
    • Registered both routes under plugins.use in backend/authz/routes.py and updated backend/authz/matrix.golden.txt.
  • Cacheable, pooled /sandbox-frame.html (backend/core/csp.py, backend/main.py, frontend/vite.config.ts, frontend/src/lib/sandboxFrame.ts):
    • Backend serves /sandbox-frame.html?v=<sha256[:12]> with Cache-Control: public, max-age=31536000, immutable while keeping Content-Security-Policy: sandbox ... (unversioned or mismatched requests stay no-cache).
    • Frontend replaces ever-incrementing ?n=seq with a build-hashed ?v=<hash>&p=<poolSlot> recycled on unmount/release, eliminating Chromium's cache lock and reducing repeat frame navigations to 0 HTTP requests.
  • Frontend single-request preload, HTML bundling, frame reuse & staged reveal (frontend/src/business/plugins/api.ts, pluginData.ts, pluginQueries.ts, components/PluginSlots.tsx, frontend/src/business/conversations/components/BatchReveal.tsx, pages/Conversation.tsx, frontend/src/mock/handlers.ts):
    • usePluginSlotHtmlBundle("conversation.details") loads all slot HTML in one request (staleTime: Infinity, invalidated by SSE plugins) and seeds individual slot caches + IndexedDB.
    • preloadDetailSlots() fires one batch-read right as the drawer mounts for all visible non-stashed slots (using manifest query + parameterized learned-preload fallback), seeding pluginQueries with a 10 s fresh window so booting frames paint synchronously with 0 extra requests; concurrent unpreloaded reads within 25 ms auto-coalesce into one batch.
    • Desktop Details drawer stays mounted across conversation switches once shown; reuseFrame slots keep a static init so switching conversations sends onUpdate without tearing down 16 iframes.
    • Staged batch reveal (BatchReveal.tsx): core + pure-snapshot cards render immediately, all plugin cards use startEmpty, a compact "Loading details…" indicator shows while the batch is in flight (capped at 1 s), and data-backed cards fade in together in one beat.
    • Mock backend (frontend/src/mock/handlers.ts) implements /api/plugins/ui-bundle and /api/plugins/batch-read.

Key decisions

  • Single batch endpoint + manifest preload + auto-batch fallback (over inlining in GET /api/conversations/{id} or declarative rewrite): Preserves the "thread goes first" paint rule and full plugin HTML/chart freedom while collapsing all detail reads into one request from the very first cold visit (with automatic learned-preload fallback for third-party plugins without manifest query).
  • Bounded parallel subprocess pool + short per-conversation server cache (over direct hub-bridge bypass): Keeps full subprocess sandboxing for every plugin, prevents one drawer from starving the 12-slot global semaphore, and answers repeat visits to finished conversations in a few milliseconds.
  • Staged batch reveal (over full-drawer skeleton barrier or uncoordinated pop-in): Shows Title, Tags, ID, Cost, Footprint, Plan %, and Cost charts immediately with zero network wait, eliminates blank 100–210 px empty-slot flashes, and reveals all data-backed plugin cards together.
  • Coordinated two-repo rollout: Companion PR in ai-agent-plugins adds query + reuseFrame across all 16 conversation.details slots; both PRs are backwards-compatible in either merge order.

Changelog

  • Changed: Conversation Details panel now loads plugin widget HTML and data in a single batched request, caches sandbox frames immutably, keeps opted-in widget frames alive across conversation switches, and reveals data-backed cards together without blank-box flashes.
  • Added: ui.slots[].query and ui.slots[].reuseFrame plugin manifest options, GET|POST /api/plugins/batch-read, and GET /api/plugins/ui-bundle.

Test notes

  • Backend: Added backend/test_plugin_details_batch.py (11 tests covering manifest validation, batch POST/GET, concurrency, partial errors, cache/invalidation, ui-bundle ETag/304, and immutable sandbox-frame.html). Verified passing per-module: test_plugin_details_batch.py (11), test_authz.py (19), test_authz_matrix.py (2), test_csp.py (7), test_plugin_widget_platform.py (11), test_stage2_platform.py (7), plus all 33 test_plugin*.py, test_batch1_platform.py, test_machine_wake.py, and test_gate.py.
  • Cross-repo manifest check: Validated all 67 plugin manifests (including all 16 updated conversation.details slots) in ai-agent-plugins against the updated backend/plugins/manifest.py.
  • Frontend: npx tsc --noEmit clean, npm run build succeeds, npm test 1,098 passed (only pre-existing FreshContext.test.tsx known failure from scripts/test-known-failures.txt), including new batchLoading.test.tsx (6), updated pluginQueries.test.ts (13), and sandboxFrame.test.ts (11).
  • Live mock preview: https://fedora.tail5edf31.ts.net:5301/?mock=1 (screenshots attached below in dark and light themes).
  • Deployment: Developed on EVOX2 — deploy from the Homelab after review and merge (paired with the companion ai-agent-plugins PR).

Screenshots

fedora_2026-11-28_123052.png
fedora_2026-11-28_123133.png

## Summary Optimizes the Conversation Details panel loading from up to ~42 HTTP requests + 10 simultaneous Python subprocesses down to **1 batched data request** (plus 1 cached HTML bundle on cold start and 0 sandbox-frame fetches after first load), while keeping plugin iframes alive across conversation switches and revealing data-backed cards together in one smooth beat with zero blank-box flashes. ## Key changes - **Manifest & UI descriptors (`backend/plugins/manifest.py`, `backend/plugins/routes.py`, `docs/plugins.md`)**: Added optional `ui.slots[].query` (declaring a slot's initial `readOnly` action + parameterized `$conversationId`/`$sessionId` payload) and `ui.slots[].reuseFrame` (boolean opt-in to keep the iframe mounted across conversation switches), exposed via `GET /api/plugins/ui` without changing existing plugins' approval fingerprints. - **Batched reads & HTML bundle (`backend/plugins/batch.py`, `backend/plugins/routes.py`, `backend/plugins/proxyroutes.py`)**: - Added `POST` and `GET /api/plugins/batch-read` (up to 32 `readOnly` items, bounded per-batch concurrency of 5 so one drawer never saturates `REQUEST_SCRIPT_SLOTS=12`, shared `singleflight` deduplication, per-item error isolation, and a 512-entry versioned cache: 30 s for finished conversations, 3 s for running ones, 5 s otherwise — invalidated on plugin lifecycle mutations, non-`readOnly` POSTs, and `hub/changed`). - Unified action authorization into `batch.resolve_call()` shared by single-action and batch routes. - Added `GET /api/plugins/ui-bundle?where=<place>` returning all active slot HTML documents in one payload with `ETag` / `304 Not Modified`. - Registered both routes under `plugins.use` in `backend/authz/routes.py` and updated `backend/authz/matrix.golden.txt`. - **Cacheable, pooled `/sandbox-frame.html` (`backend/core/csp.py`, `backend/main.py`, `frontend/vite.config.ts`, `frontend/src/lib/sandboxFrame.ts`)**: - Backend serves `/sandbox-frame.html?v=<sha256[:12]>` with `Cache-Control: public, max-age=31536000, immutable` while keeping `Content-Security-Policy: sandbox ...` (unversioned or mismatched requests stay `no-cache`). - Frontend replaces ever-incrementing `?n=seq` with a build-hashed `?v=<hash>&p=<poolSlot>` recycled on unmount/release, eliminating Chromium's cache lock and reducing repeat frame navigations to 0 HTTP requests. - **Frontend single-request preload, HTML bundling, frame reuse & staged reveal (`frontend/src/business/plugins/api.ts`, `pluginData.ts`, `pluginQueries.ts`, `components/PluginSlots.tsx`, `frontend/src/business/conversations/components/BatchReveal.tsx`, `pages/Conversation.tsx`, `frontend/src/mock/handlers.ts`)**: - `usePluginSlotHtmlBundle("conversation.details")` loads all slot HTML in one request (`staleTime: Infinity`, invalidated by SSE `plugins`) and seeds individual slot caches + IndexedDB. - `preloadDetailSlots()` fires one `batch-read` right as the drawer mounts for all visible non-stashed slots (using manifest `query` + parameterized learned-preload fallback), seeding `pluginQueries` with a 10 s fresh window so booting frames paint synchronously with 0 extra requests; concurrent unpreloaded reads within 25 ms auto-coalesce into one batch. - Desktop Details drawer stays mounted across conversation switches once shown; `reuseFrame` slots keep a static `init` so switching conversations sends `onUpdate` without tearing down 16 iframes. - Staged batch reveal (`BatchReveal.tsx`): core + pure-snapshot cards render immediately, all plugin cards use `startEmpty`, a compact "Loading details…" indicator shows while the batch is in flight (capped at 1 s), and data-backed cards fade in together in one beat. - Mock backend (`frontend/src/mock/handlers.ts`) implements `/api/plugins/ui-bundle` and `/api/plugins/batch-read`. ## Key decisions - **Single batch endpoint + manifest preload + auto-batch fallback (over inlining in `GET /api/conversations/{id}` or declarative rewrite)**: Preserves the "thread goes first" paint rule and full plugin HTML/chart freedom while collapsing all detail reads into one request from the very first cold visit (with automatic learned-preload fallback for third-party plugins without manifest `query`). - **Bounded parallel subprocess pool + short per-conversation server cache (over direct hub-bridge bypass)**: Keeps full subprocess sandboxing for every plugin, prevents one drawer from starving the 12-slot global semaphore, and answers repeat visits to finished conversations in a few milliseconds. - **Staged batch reveal (over full-drawer skeleton barrier or uncoordinated pop-in)**: Shows Title, Tags, ID, Cost, Footprint, Plan %, and Cost charts immediately with zero network wait, eliminates blank 100–210 px empty-slot flashes, and reveals all data-backed plugin cards together. - **Coordinated two-repo rollout**: Companion PR in `ai-agent-plugins` adds `query` + `reuseFrame` across all 16 `conversation.details` slots; both PRs are backwards-compatible in either merge order. ## Changelog - Changed: Conversation Details panel now loads plugin widget HTML and data in a single batched request, caches sandbox frames immutably, keeps opted-in widget frames alive across conversation switches, and reveals data-backed cards together without blank-box flashes. - Added: `ui.slots[].query` and `ui.slots[].reuseFrame` plugin manifest options, `GET|POST /api/plugins/batch-read`, and `GET /api/plugins/ui-bundle`. ## Test notes - **Backend**: Added `backend/test_plugin_details_batch.py` (11 tests covering manifest validation, batch POST/GET, concurrency, partial errors, cache/invalidation, `ui-bundle` ETag/304, and immutable `sandbox-frame.html`). Verified passing per-module: `test_plugin_details_batch.py` (11), `test_authz.py` (19), `test_authz_matrix.py` (2), `test_csp.py` (7), `test_plugin_widget_platform.py` (11), `test_stage2_platform.py` (7), plus all 33 `test_plugin*.py`, `test_batch1_platform.py`, `test_machine_wake.py`, and `test_gate.py`. - **Cross-repo manifest check**: Validated all 67 plugin manifests (including all 16 updated `conversation.details` slots) in `ai-agent-plugins` against the updated `backend/plugins/manifest.py`. - **Frontend**: `npx tsc --noEmit` clean, `npm run build` succeeds, `npm test` 1,098 passed (only pre-existing `FreshContext.test.tsx` known failure from `scripts/test-known-failures.txt`), including new `batchLoading.test.tsx` (6), updated `pluginQueries.test.ts` (13), and `sandboxFrame.test.ts` (11). - **Live mock preview**: `https://fedora.tail5edf31.ts.net:5301/?mock=1` (screenshots attached below in dark and light themes). - **Deployment**: Developed on EVOX2 — deploy from the Homelab after review and merge (paired with the companion `ai-agent-plugins` PR). ## Screenshots ![fedora_2026-11-28_123052.png](https://git.gabvdl.xyz/attachments/f8d52d10-5e57-40b3-9e2b-83319a4fef45) ![fedora_2026-11-28_123133.png](https://git.gabvdl.xyz/attachments/e3e093d5-9a60-4dd4-a452-6831040132ce)
gabrielvidal self-assigned this 2026-11-28 12:33:07 +01:00
gabrielvidal added 1 commit 2026-11-28 12:33:07 +01:00
Author
Owner
Merged into `main` as 52a0fc2e by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/01a221fa-1e3e-7447-a970-dee68df49b40.
gabrielvidal closed this pull request 2026-11-28 13:02:00 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#32