feat(cloudflare): support explicit APP_PID for shared-identity deployments#490
Open
zhuzhuyule wants to merge 1 commit intomasterfrom
Open
feat(cloudflare): support explicit APP_PID for shared-identity deployments#490zhuzhuyule wants to merge 1 commit intomasterfrom
zhuzhuyule wants to merge 1 commit intomasterfrom
Conversation
…ments
When Media Kit is deployed alongside sibling CF Workers that share one
Blocklet Server identity (e.g. aigne-hub + payment-kit + media-kit all
mounted under one logical instance), the current `instanceDid: 'auto'`
path in ensureRegistered() causes two problems:
1. The derived DID (from APP_SK via fromSecretKey) does not match the
intended permanent DID (derived from APP_PSK). blocklet-service's
registerApp() then finds a stale row via findInstancesByAppSk() and
triggers migrateInstanceDid(), moving all settings/memberships/
security_rules/audit_logs from one instance_did to another.
2. Media Kit always writes appName="Media Kit" into the shared
instance's app:name row, overwriting whatever branding the owning
component (e.g. aigne-hub) set. In a multi-minute race with the
other component's own registerApp() call, app:name oscillates with
each worker's schedule, and user-facing login pages flicker.
Fix: treat env.APP_PID as an opt-in "shared identity mode" flag.
- When APP_PID is set: pass it as explicit instanceDid, pass APP_PSK
(new optional secret) for delegation, and skip appName /
appDescription so we never overwrite the owner's branding.
- When APP_PID is unset: fall back to the old 'auto' behaviour with
Media Kit's own appName (unchanged for single-tenant deploys).
Deployment notes:
- Set APP_PID as a plain var in wrangler.toml/[vars] (public DID).
- Set APP_PSK as a secret via `wrangler secret put APP_PSK` — this is
the 64-byte ED25519 expanded permanent signer key; leave unset for
single-tenant deployments.
Verified against a staging deployment of aigne-hub + payment-kit +
media-kit sharing APP_PID=zNKWm5HBg...; after this patch,
blocklet-service settings stay stable under the shared DID and
app:name="AIGNE Hub (Staging)" no longer flips on media-kit boot.
There was a problem hiding this comment.
Files selected (2)
- cloudflare/src/types.ts (1)
- cloudflare/src/worker.ts (1)
Files not summarized due to errors (2)
- cloudflare/src/types.ts (nothing obtained from anthropic)
- cloudflare/src/worker.ts (nothing obtained from anthropic)
Files not reviewed due to errors (2)
- cloudflare/src/types.ts (no response)
- cloudflare/src/worker.ts (no response)
Review comments generated (0)
- Review: 0
- LGTM: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in "shared identity" mode so Media Kit can be deployed as a sibling CF Worker to other components (e.g. `aigne-hub`, `payment-kit`) that share a single Blocklet Server identity, without the three workers stomping on each other's `blocklet-service` instance registration.
Background
In a shared-identity deployment, all sibling workers have the same `BLOCKLET_APP_SK` / `BLOCKLET_APP_PSK` secrets but each wants blocklet-service to treat them as components of one `instance_did` (the hub's permanent DID). The current `instanceDid: 'auto'` path causes two concrete problems:
Both effects were observed live against a staging deployment where `aigne-hub` + `payment-kit` + `media-kit` share `APP_PID=zNKWm5...`. After this patch the shared row stays stable.
Test plan
Deployment notes
Add to your wrangler config for shared-identity mode:
```toml
[vars]
APP_PID = "zNK..." # explicit permanent DID of the logical instance
```
```bash
Set the optional PSK secret (64-byte ED25519 expanded hex)
wrangler secret put APP_PSK
```
Leave both unset for single-tenant deployments — existing behaviour is preserved.