Skip to content

feat: implement S3 Plugin Store and Asset Handling - #761

Merged
pikann merged 4 commits into
masterfrom
feature/implement-s3-plugin-store
Nov 15, 2026
Merged

pikann merged 4 commits into
masterfrom
feature/implement-s3-plugin-store

Conversation

@pikann

@pikann pikann commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Installed plugins (backend WASM, plugin.json, migrations, and the frontend / MCP / skills bundles) can now live in the object-storage bucket instead of folders. One setting chooses where: PLUGINS_STORE=local|s3.

  • local (the default everywhere except the one-click templates) behaves exactly as before: the four PLUGINS_*_DIR folders, shared between the API and the gateway.
  • s3 keeps everything in the STORAGE_* bucket under PLUGINS_S3_PREFIX (default plugins). No shared volume, no ReadWriteMany StorageClass, and the bucket stays private.

Before this, PLUGINS_STORE=s3 only read the WASM, manifest and migrations. The installer, skills, frontend and MCP bundles were still folder-only, and the S3 client ignored STORAGE_ENDPOINT, so it could not have worked against RustFS.

How it works

Store interface. Store is now an interface with two implementations, localStore and s3Store. NewStore is the only place that reads PLUGINS_STORE; the installer, runtime, migration runner and skills reader depend only on the interface.

{prefix}/<plugin-id>/backend.wasm | plugin.json | migrations/*.sql
{prefix}/<plugin-id>/frontend/... | mcp/... | skills/<skill>/SKILL.md
  • The installer extracts to a temp dir, then writes through the Store (PutBackend, PutTree); uninstall is DeleteAll. In s3 mode plugin.json is uploaded last and a reinstall clears the old objects first.
  • The S3 store reuses the attachment storage client (storage.S3Client.Raw()), so it honours the same endpoint and credentials as the rest of the app.
  • Skills are read through a SkillReader; every Store implements it.

Serving assets without making the bucket public. The gateway can't sign S3 requests, so in s3 mode Caddy forwards /plugins/*, /plugins-mcp/* and /plugins-skills/* to a new public API route, GET /api/v1/plugin-assets/{kind}/{name}/*, which streams from the store (Store.OpenAsset). Only frontend, mcp and skills are reachable; backend.wasm, plugin.json and migrations never are. Paths that could leave a bundle return 404. Cache headers match what Caddy does today (remoteEntry.js is no-cache, other files max-age=900, immutable), with ETag / If-None-Match.

Caddy. The three Caddyfiles (deploy/caddy/Caddyfile, Caddyfile.dev, and the Helm copy) pick plugin_frontend_local|s3 and plugin_mcp_skills_local|s3 from PLUGINS_STORE (default local), on both the public :80 block and the internal :8080 block. Set the same value on the API and the gateway.

Migrating an existing install. New command api migrate-plugins [--dry-run] copies the plugins in the local folders into the bucket. It never changes the folders, reads each backend.wasm back to verify it, and is safe to re-run; one failing plugin doesn't stop the others. Switching PLUGINS_STORE does not move plugins by itself, so run it first (documented in docs/plugins/backend-plugin-system.md, "Plugin Storage Location").

Deployment changes

  • Compose (prod, dev, e2e), Helm (api.plugins.store, schema-validated): PLUGINS_STORE is passed to the API and the gateway. Defaults stay local. With Helm store: s3 the plugins PVC is not created and nothing is mounted.
  • One-click templates now use s3: AWS lite, GCP lite, Render, and DigitalOcean App Platform. The plugin volumes and PLUGINS_*_DIR settings are removed there. On DigitalOcean (no gateway) the ingress rewrites /plugins* onto the API route.
  • Docs and env examples updated (backend-plugin-system.md, marketplace.md, .env.example, .env.production.example, Helm READMEs).

Things worth a close look

  • New public route. GET /api/v1/plugin-assets/{kind}/{name}/* is unauthenticated (like the static files it replaces) and is added to the open-route allow-list in authorization_test.go.
  • Shared S3 client settings. storage.NewS3Client now sets RequestChecksumCalculation / ResponseChecksumValidation to WhenRequired. The SDK's newer default (a CRC32 on every PutObject) is handled inconsistently by S3-compatible stores such as GCS and RustFS. This client is shared with attachments, so it applies there too.
  • Deleting objects one at a time. deletePrefix uses DeleteObject per key instead of the batch DeleteObjects, because GCS's S3 interoperability layer has no multi-object delete. A plugin is at most a few hundred small files.
  • Content types come from the extension (.md, .wasm, .json handled explicitly) so both modes serve the same types.
  • smithy-go is now a direct dependency in go.mod.

Testing

  • Unit tests: in-memory fake S3 (pagination, reinstall clears stale objects, a plugin whose name prefixes another's is left alone, unsafe names rejected), OpenAsset in both modes, the assets handler (headers, 304, 404, traversal), and MigrateLocalToStore (dry run, a broken plugin, re-run is idempotent).
  • Go e2e: test/e2e/plugin_runtime_test.go can now run against the RustFS testcontainer with PACA_E2E_PLUGIN_STORE=s3. All 10 TestE2EPluginRuntime_* tests pass in that mode.
  • Docker e2e stack in s3 mode: ran migrate-plugins against its RustFS and fetched the frontend, MCP and skills files through the gateway (correct content types and cache headers; backend.wasm and traversal return 404).
  • Full Playwright suite (chromium) against that stack in s3 mode: 1353 passed, 13 skipped (skipped in the specs themselves), 0 failed; two tests (auth/mfa.spec.ts:641, projects/conversations.spec.ts:980) failed once and passed on retry, unrelated to plugins.
  • Dev compose stack with PLUGINS_STORE=s3: migrated the 9 plugins in plugins/local and loaded their files and backends from the bucket.
  • Helm: helm lint and helm template in default, store=s3, and nfsProvisioner.enabled cases; a bad store value is rejected by the schema.

Not verified

  • Against real AWS S3 or Google Cloud Storage (only RustFS).
  • The AWS, GCP, Render and DigitalOcean templates were not deployed. On DigitalOcean, whether /plugins also matches /plugins-mcp and /plugins-skills (the longer prefixes are listed first), and the ingress rewrite, need a check on a first deploy.
  • The AWS and GCP lite templates download the Caddyfile from releases/latest, so they need a release that includes the new Caddyfile and API image before s3 mode works there.
  • Helm was rendered but not installed on a cluster.
  • HEAD requests on the plugin-assets route are not routed (browsers use GET).

Notes for upgrading

Plugins installed under one mode are not visible under the other. Run api migrate-plugins (with the folders still mounted) before switching an existing deployment to s3; to go back, set PLUGINS_STORE=local, since the folders are never modified.

- Introduced a fake S3 implementation for testing the plugin store.
- Added functionality to handle plugin assets via HTTP, including frontend, MCP, and skills bundles.
- Enhanced the S3 client to manage checksum headers conditionally.
- Updated the SkillsHandler to support reading skills from the plugin store.
- Created tests for the new plugin asset handling and skills functionality.
- Modified the router to include routes for serving plugin assets.
- Implemented migration logic for local to S3 plugin store.
- Ensured that the plugin store can handle both local and S3 configurations in end-to-end tests

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues. The Store abstraction, the s3 implementation and the gateway plumbing hold up under inspection. The findings are documentation that still describes the local-folder-only store, one CI coverage gap for the bucket-backed e2e path, and a local/s3 parity nit in the new asset handler.

Reviewed changes

  • Store interface — plugin.Store now abstracts backend, migrations and the three bundles; installer, Runtime, MigrationRunner and skills depend on it instead of folder paths.
  • S3 store — new s3Store behind the S3API subset interface: prefix-scoped deletes (trailing /, so a.b never deletes a.bc), extension-derived content types, NoSuchKey → ErrAssetNotFound.
  • Asset serving — public GET /api/v1/plugin-assets/{kind}/{name}/* streaming frontend/MCP/skills files, with ETag/304 and the gateway's cache policy; backend files are unreachable.
  • Local → bucket migration — MigrateLocalToStore plus api migrate-plugins [--dry-run], verifying each uploaded backend.wasm by reading it back.
  • Skills — SkillReader replaces the skills directory in SkillsHandler and ListSkills*.
  • Deploy wiring — PLUGINS_STORE propagated to api and gateway across compose, Helm, CFN, GCP, DO and Render; Caddy selects plugin_frontend_* / plugin_mcp_skills_* snippets; Helm drops the RWM volume and PVC in s3 mode.
  • Shared storage client — checksums switched to WhenRequired and Raw() exposed so the plugin store reuses the attachment client's endpoint and credentials.

ℹ️ Deployment docs still describe plugins as local-folder-only

The templates now put plugins in the object bucket, but the user-facing deployment guide still tells operators the opposite: docs/deployment/one-click.md says installed plugins are lost on restart for AWS lite (line 79) and live on the instance's ephemeral disk for GCP lite (line 95), and that plugins are "not usable" on DO App Platform (line 121) and Render (line 166) — all four now set PLUGINS_STORE=s3 and route /plugins* to the API. docs/plugins/skills-plugin-system.md:121 has the same problem for skills. Neither file is in this diff, so the docs will contradict the shipped behaviour on merge.

Technical details
# Stale plugin-storage claims after PLUGINS_STORE=s3

## Affected sites
- `docs/deployment/one-click.md:79` — "installed plugins live on the task's ephemeral disk and are lost when it restarts" (AWS lite). `paca-lite.cfn.yaml` now sets `PLUGINS_STORE=s3` on the api, writing to the `${Bucket}` that the template keeps on delete.
- `docs/deployment/one-click.md:95` — "installed plugins live on the instance's ephemeral disk" (GCP lite). `deploy-lite.sh` now uses the Cloud Storage bucket.
- `docs/deployment/one-click.md:121` — "Plugins are not usable on App Platform yet (no shared disk, no gateway to serve their assets)". `.do/deploy.template.yaml` now adds ingress rewrites for `/plugins-mcp`, `/plugins-skills` and `/plugins` onto the API, so no gateway or disk is needed.
- `docs/deployment/one-click.md:166` — "Plugins are not usable on Render yet … installs vanish on restart". `render.yaml` now sets `PLUGINS_STORE=s3` on `paca-api` and the gateway, and the gateway image bakes `deploy/caddy/Caddyfile`.
- `docs/plugins/skills-plugin-system.md:121` — "The installer extracts this tarball to `{PLUGINS_SKILLS_DIR}/{pluginId}/` and the gateway serves it at `/plugins-skills/{pluginId}/`". Only true for `PLUGINS_STORE=local`; in s3 mode the bundle lands at `{PLUGINS_S3_PREFIX}/{pluginId}/skills/` and is streamed by the API.

## Required outcome
- Each platform section states what actually happens now (plugins persist in the platform's object store; no shared volume needed), and keeps any remaining real caveat (e.g. the unverified RustFS permission issue on Render, which is about attachments too).
- The skills doc distinguishes `local` from `s3`, the way `docs/plugins/backend-plugin-system.md` and `docs/plugins/marketplace.md` already do in this PR.

ℹ️ The bucket-backed e2e path never runs in CI

newPluginE2EStore only takes the s3 branch when PACA_E2E_PLUGIN_STORE=s3, and nothing in the repo sets that variable — not deploy/docker-compose.e2e.yml, not .github/workflows/e2e-tests.yml, which runs go test ./test/e2e/... and starts the RustFS testcontainer that branch depends on. The new path is exercised by the fakeS3 unit tests, but never against a real S3-compatible backend, which is the part most likely to differ.

Technical details
# PACA_E2E_PLUGIN_STORE is unreferenced

## Affected sites
- `services/api/test/e2e/plugin_runtime_test.go:98-130` — `newPluginE2EStore` reads `PACA_E2E_PLUGIN_STORE`; the s3 branch requires `sharedStorageEndpoint` (RustFS testcontainer).
- `.github/workflows/e2e-tests.yml:115-119` — starts the compose stack and the testcontainer, but passes no plugin-store variable.

## Required outcome
- The s3 store is exercised at least once per run, e.g. a workflow step (or matrix entry) that runs `./test/e2e/...` with `PACA_E2E_PLUGIN_STORE=s3`, or an explicit note that the branch is manual-only.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Directory URLs serve index.html — the asset handler maps an empty or trailing-slash wildcard to index.html (matching Caddy's file_server), with tests for both the hit and the missing-index.html 404.
  • S3 e2e path now runs in CI — a second test-e2e step in api-pr-ci.yml runs TestE2EPluginRuntime with PACA_E2E_PLUGIN_STORE=s3 against the RustFS testcontainer the suite already starts.
  • Deployment docs match the shipped behaviour — AWS lite, GCP lite, DigitalOcean and Render sections now describe bucket-backed plugins (PLUGINS_STORE=s3) while keeping the real caveats (untested ingress rewrite, RustFS disk permissions, GCS interop); skills-plugin-system.md distinguishes local from s3, and backend-plugin-system.md gains the storage table plus migration procedure.
  • MigratedPlugin rename — migration report type renamed, no stale references.

Verified at 70276c7: go build ./... succeeds and the handler package tests pass. My note about the empty-wildcard 404 is resolved, and the RustFS-backed e2e step is a sound place for the s3 branch: TestMain starts RustFS whenever PACA_E2E=1, and each test uses a unique plugin name, so the shared bucket under -parallel 4 cannot collide.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — the store and asset-serving changes in this push hold up; two minor touch-ups below.

Reviewed changes

  • Upload-then-prune in the S3 store — PutTree/PutBackend now list the existing prefix, upload every new object, and only then delete the leftovers through the new shared deleteKeys, so a failed upgrade leaves the previous install readable.
  • Tolerant batch deletes — deleteKeys skips keys in keep, keeps going after individual DeleteObject failures and returns errors.Join; DeleteAll/deletePrefix now route through it.
  • Migration listing parity — ListMigrations ignores objects nested under migrations/, matching localStore's ReadDir semantics and removing the basename collision a nested file could cause.
  • Weak If-None-Match — ifNoneMatchHit handles *, comma-separated lists and W/ prefixes, which the local store's weak ETags (W/"…") and Caddy's gzip revalidation both need; the handler doc now records why Range requests are unsupported.
  • Tests — upgrade-failure retention, nested-migration filtering and a conditional-request table.

ℹ️ PR description still describes delete-then-upload

The "How it works" bullet still reads "a reinstall clears the old objects first", which e6b25b1 deliberately inverted. Since the description carries into the merge commit, it is worth a one-line edit so it does not contradict the shipped ordering.

Technical details
# PR body describes superseded ordering

## Affected sites
- PR #761 body, "How it works" section — "In s3 mode `plugin.json` is uploaded last and a reinstall clears the old objects first."
- `services/api/internal/platform/plugin/store_s3.go:182-223` (`PutTree`) and `:147-180` (`PutBackend`) — uploads first, prunes via `deleteKeys` afterwards.

## Required outcome
- The description says the new objects are uploaded before the stale ones are pruned, and that a failed upload therefore keeps the previous install intact.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit a7de83e into master Nov 15, 2026
11 checks passed
@pikann
pikann deleted the feature/implement-s3-plugin-store branch November 15, 2026 05:30
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.

1 participant