From b3b7dd6a1d8354cf53afb3be38e6dd07367123ff Mon Sep 17 00:00:00 2001 From: jasper-yl Date: Sun, 15 Nov 2026 02:07:07 -0800 Subject: [PATCH 1/6] docs(rfc): align the plugin interfaces RFC with the merged implementation Co-Authored-By: Claude Opus 5.5 --- docs/en/rfcs/2549-plugin-interfaces.md | 104 ++++++++++++++++--------- docs/zh/rfcs/2549-plugin-interfaces.md | 78 ++++++++++++------- 2 files changed, 117 insertions(+), 65 deletions(-) diff --git a/docs/en/rfcs/2549-plugin-interfaces.md b/docs/en/rfcs/2549-plugin-interfaces.md index fd35f6ccbe..bec9833441 100644 --- a/docs/en/rfcs/2549-plugin-interfaces.md +++ b/docs/en/rfcs/2549-plugin-interfaces.md @@ -273,6 +273,7 @@ search API and Prepared Context return 422 for the family. | `timeout_seconds` | 300 | Time limit for the whole invocation | | `transaction_timeout_seconds` | 30 | Time limit for the write transaction block, at most `timeout_seconds` | | `max_workers` | 1 | Concurrency limit across Scopes | +| `host_processes` | 1 | Suggested limit on this plugin's host processes in each Server process; deployers can override it per plugin, and plugins with heavy API requests can raise it | | `change_timeout_seconds` | 30 | Time limit for one user-change call, including its write transaction block | | `definitions` | `()` | The plugin's own Source types, registered when the plugin loads; see section 3 and reference section 2 | | `setup` | Required | See the table above | @@ -314,7 +315,7 @@ class IncidentReports: "report", source.ref.source_type, source.ref.source_id) written = await tx.put(artifact_id, content={"title": "Incident report", "summary": summary}, source_refs=[source.ref]) - # Write the owned index once the real artifact_id and revision are known; upsert by ID + # Write the owned index once the real artifact_id and revision are known, keyed by (artifact_id, revision) await self.index.upsert(request.scope_id, written.ref.artifact_id, written.ref.revision, vector) # The block ended normally: core commits the Artifact writes, the cursor advance, and the acknowledgment @@ -354,8 +355,9 @@ plugin = ArtifactPlugin( ``` If the block raises, core rolls back every Artifact write in it, the cursor stays put, and the same window is retried. -The plugin's own index is not part of core's transaction: the plugin upserts by stable ID, so a retry overwrites entries -left by the previous attempt, and reads from the owned index defer to core's current data (see reference 3.5). +The plugin's own index is not part of core's transaction: the plugin writes under `(artifact_id, revision)` and keeps +older revisions' entries until it cleans them up; core filters search results to current revisions, so entries left by +a rollback are never returned (see reference 3.5). ### 4.4 How callers use it @@ -424,8 +426,9 @@ invocation after it finishes. - **Startup**: Server checks each plugin directory in turn. A failed check (no `plugin.py`, import failure, an invalid declaration, or a family or Source type that conflicts with a built-in or another plugin) affects only that plugin; Server and the other plugins start normally. -- **Inspection** (all require `server.admin`, are read-only, and come from the startup check or the database, so every - Server role returns the same answer): +- **Inspection** (all require `server.admin` and are read-only): check results come from the startup check and are the + same on every Server role; failures found only after `setup` (such as a missing required method) appear only on + instances that start host processes, not on `background` instances: - `GET /v1/plugins`, `GET /v1/plugins/{name}`: each plugin's check result, kind, family or Source types, consumed Source types, triggers, and Scope range. - `GET /v1/plugins/{name}/scopes`: for each Scope, whether work is pending, the journal position consumed through, and @@ -436,11 +439,12 @@ invocation after it finishes. or changing that family through the generic APIs returns 404, as for a family that does not exist. A plugin Artifact's content usually records only digests or locations, while bodies, chunks, and files live in the plugin's own storage and cannot be interpreted without the plugin, so there are no reads without the plugin. New writes of the plugin's - Source types return 422. Redeploying a plugin with the same name + Source types return 404, as for an unknown Source type. Redeploying a plugin with the same name restores reads and continues generation from the existing cursor. The plugin's dedicated storage is not deleted with it; the deployer keeps or cleans it up. -- **Host processes**: core starts, reuses, and restarts them on demand; deployers neither configure nor manage them. - Host process starts, terminations, and restarts appear only in logs and metrics. +- **Host processes**: core starts them once a plugin loads, adds and removes them with load, and restarts them when they + stop responding. Deployers can tune each plugin's process limit and the total limit (see reference section 6) without + managing individual processes. Host process starts, terminations, and restarts appear only in logs and metrics. # Reference-level explanation @@ -458,7 +462,7 @@ class Interval(BaseModel): class Cron(BaseModel): expression: str - timezone: str = "Asia/Shanghai" + timezone: str | None = None # defaults to the time zone of the machine running Server class ArtifactPlugin(BaseModel): # fields in guide 4.2 family: str @@ -705,13 +709,16 @@ class ArtifactReads(Protocol): commits owned storage with its own clients; core takes no part and does not guarantee their consistency. Core's transaction is the only commit point for core data: data in owned storage takes effect only once a committed revision in core references it. This needs no two-phase commit; the following practice keeps them consistent: - 1. Write owned storage inside the write transaction block after receiving the `ArtifactSnapshot`, upserting by - `artifact_id`. A failed write to owned storage then rolls back the core writes too. - 2. If the write transaction fails to commit, owned storage may keep entries from that attempt. The retry processes the - same window, derives the same stable IDs, and overwrites them. - 3. Treat the owned index as a source of candidates: read each hit's current snapshot from core with `get`, and use that - snapshot's content and state. Entries left by rollbacks then cannot make the plugin read stale content. Plugins may - also rebuild their index from core data periodically. + 1. Write owned storage inside the write transaction block after receiving the `ArtifactSnapshot`, keyed by + `(artifact_id, revision)`, without overwriting other revisions' entries. A failed write to owned storage then rolls + back the core writes too. + 2. If the write transaction fails to commit, owned storage keeps an entry for an uncommitted revision while the current + revision's entry is still there. A background retry writes the same key again; user changes are not retried, and the + leftover entry is overwritten when that revision number is next written, or removed by periodic cleanup. + 3. In search, the plugin returns the exact revisions it matched, and core keeps only current, active revisions the + caller may read (reference section 7), so neither rollback leftovers nor older revisions' entries reach results. + Elsewhere, a plugin reading its owned storage defers to core's current snapshot. Plugins clean up older revisions' + entries periodically and may rebuild their index from core data. 4. Store large content (bodies, chunks, file bytes) as immutable records keyed by content digest: write and commit them to owned storage first, then commit an Artifact whose content carries that digest in the write transaction block. Do not key them by `(artifact_id, revision)`: after a write transaction rolls back, the same revision number is @@ -875,16 +882,34 @@ long-lived host process: | `render_artifact`, `search_artifacts` | Host process | | `generate` | Supervisor Worker | -- **Count and startup**: each Server process keeps at most one host process for each loaded plugin, starts it in the - background once the plugin loads, and reuses it afterward. Every plugin implements `render_artifact`, so every - loaded plugin has a host process. +- **A group of processes per plugin**: each Server process keeps a group of host processes for each loaded plugin, and + plugins never share a process. One plugin blocking, crashing, or being terminated does not affect the others, and + per-plugin dependency isolation later needs a separate interpreter per plugin anyway. +- **Count**: once a plugin loads, one host process starts and stays. Every plugin implements `render_artifact`, so every + loaded plugin has at least one. When all of the plugin's processes are busy and requests are queuing, core starts + another, up to the plugin's limit; extra processes stop after 5 idle minutes. The plugin's limit is its declared + `host_processes`, which deployers can override with `POWERCONTEXT_SERVER_PLUGIN_HOST_PROCESSES` (JSON keyed by plugin + name). Host processes of all plugins together stay within `POWERCONTEXT_SERVER_PLUGIN_TOTAL_HOST_PROCESSES`; at that + limit no process is added for load and requests queue on the existing ones. Each plugin's first, always-running + process is exempt from the total. A new process takes seconds to start, so extra + processes help only with sustained load. - **Execution**: the host process imports `plugin.py` once at startup and compares the declaration, and the writer runs inside the host process. One host process can serve several requests concurrently, up to a limit set in the Server - configuration. -- **Timeouts and failures**: each call has its own time limit (Source writes, presentation, and search use - Server's synchronous call limit; user changes use `change_timeout_seconds`). On a timeout, crash, or loss of response, core - terminates the process, in-flight requests return 503, and the process restarts after a backoff. During the backoff - the plugin's synchronous calls return 503; background calls are unaffected. + configuration; requests go to the process with the fewest in flight. +- **Timeouts**: each call has its own time limit (Source writes, presentation, and search use Server's synchronous call + limit; user changes use `change_timeout_seconds`). When a request exceeds its limit, core cancels only that request: + while the plugin awaits I/O the cancellation takes effect at once, the write transaction rolls back, the request returns + 504, and other requests in the same process are unaffected. +- **Loss of response**: host processes report a heartbeat to Server. When a plugin blocks the event loop (CPU-heavy work, + or a blocking call without `await`), cancellation cannot take effect and the heartbeat stops; past the heartbeat limit + core terminates the process, the timed-out request returns 504, and the process's other in-flight requests return 503. A + crash also returns 503 for in-flight requests. Plugins should move CPU-heavy work into `asyncio.to_thread` or into + background `generate`. +- **Restarts**: when the plugin has no usable host process, core restarts one after a backoff; during the backoff the + plugin's synchronous calls return 503, and background calls are unaffected. +- **Long work belongs in the background**: more processes only help requests that are slow but finish within their limit. + Work measured in minutes, such as parsing large files or embedding in bulk, should save its input, submit a Source, and + return at once from the API, leaving `generate` to process it in a Worker while the page polls for status. - **Code changes**: a host process does not re-import the plugin while it lives, and checks the code fingerprint when it starts. Restart Server after changing a plugin, the same rule as for Workers. - **Isolation**: as with Workers, the host process isolates ordinary failures and is not a sandbox for untrusted code. @@ -893,8 +918,8 @@ long-lived host process: directory, kind, declaration digest, check result, and the current host process state (not started, running, or in restart backoff). Routing user requests, starting host processes, and dispatching Workers all use this record. It is not persisted or synchronized across processes, and is rebuilt from the plugin directory when Server restarts. The -operational APIs return only the check results and declarations, which are the same on every process; host process state -is visible through logs and metrics. +operational APIs return check results, declarations, and permanent failures reported by this instance's host processes; +host process runtime state is visible through logs and metrics. ## 7. Public reads, presentation, and search @@ -944,13 +969,15 @@ class SearchResult(BaseModel): interprets them against the plugin's own indexes; a plugin raises `InvalidContent` for controls it does not support, and the API returns 422. Core keeps only matches that are active current revisions the caller may read, returns the exact revisions in the plugin's order, and adds the plugin's scores when `include_scores` is set. A plugin therefore cannot - return data the caller cannot see through search. + return data the caller cannot see through search. After filtering, results may number fewer than requested; core + does not fetch more. - **Prepared Context**: `assembly.sections` may list plugin families. Core calls `search_artifacts` with Prepared Context's `query`, the section's `limit`, and the request's byte budget, and fills the matched passages in section order as context entries that, like built-in entries, cite exact revisions and count toward the byte budget and the receipt; - entries beyond the budget are truncated or left out. A section may carry an - optional `search` with the fields of a search request other than `query` and `limit`, passed on to the plugin - unchanged; built-in families that carry `search` return 422. + entries beyond the budget are truncated or left out. When the plugin is unavailable (no usable host process, a + timeout, or a failed search), core omits that section and records why in the receipt, and the other sections are + returned as usual. A section may carry an optional `search` with the fields of a search request other than `query` + and `limit`, passed on to the plugin unchanged; built-in families that carry `search` return 422. - Review and Recall are not open to plugin families; those APIs return an explicit "not supported" error, and `GET /v1/capabilities` lists plugin families. @@ -973,7 +1000,7 @@ class SearchResult(BaseModel): the plugin directory is modified while Server runs, new Worker invocations and newly started host processes fail and ask for a restart, so one Server never mixes old and new code. Deployers should restart Server after a change. - Server instances in the `api` role run no background work, but they also check plugins and register families and - Source types for reads, search, Source writes, and user changes; they start host processes on demand and do not + Source types for reads, search, Source writes, and user changes; they start host processes and do not dispatch Workers. Instances in the `background` role receive no requests and start no host processes. - Adding or removing plugins at runtime (hot reload) and plugin-defined APIs are covered by [RFC #2579](https://github.com/oceanbase/powercontext/pull/2579), built on host processes. @@ -1054,6 +1081,7 @@ new format. | Changed | `POST /v1/context/prepare`: `ContextAssemblySection.family` changes from an enum to a string that may name a loaded plugin family; an optional `search` (the fields of a search request other than `query` and `limit`) applies to plugin families only; the family of receipt entries changes from an enum to a string that may name a plugin family | | Changed | The format version of Artifact revision records in export and restore increases by one and adds `metadata` | | Changed | The environment variable `POWERCONTEXT_SERVER_PLUGINS_DIR` replaces `POWERCONTEXT_SERVER_ARTIFACT_PLUGINS_DIR` | +| Added | Environment variables `POWERCONTEXT_SERVER_PLUGIN_HOST_PROCESSES` (JSON overriding host process limits by plugin name) and `POWERCONTEXT_SERVER_PLUGIN_TOTAL_HOST_PROCESSES` (total host process limit in each Server process) | After `openapi/powercontext.yaml` is updated per the table, `src/powercontext/http/_generated/` and each integration's operation table are regenerated. @@ -1073,11 +1101,12 @@ record one event. # Drawbacks -- **Host processes hold resources**: each Server process gets one more long-lived process for each plugin that needs - synchronous calls, and the count grows with instances in multi-instance deployments. Synchronous calls add one +- **Host processes hold resources**: each Server process gets at least one more long-lived process (about 150 MB each) + for each loaded plugin, more under load, and the count grows with instances in multi-instance deployments. Synchronous calls add one inter-process round trip and serialization. - **Synchronous calls depend on the plugin being available**: while a host process is crashed or in restart backoff, the - plugin's Source writes and user changes return 503; defects in plugin code show up directly as failed user requests. + plugin's Source writes and user changes return 503; defects in plugin code show up directly as failed user requests. A + plugin that blocks the event loop makes other requests in the same process fail with it. - **The write transaction holds locks**: the block holds database locks, which on SQLite block other writes. A plugin that does slow work in the block slows every write in Server until the block times out and rolls back. - **Plugin-owned storage is not guaranteed consistent with core data**: they are not in the same transaction, so a failed @@ -1102,7 +1131,8 @@ record one event. - **Content structure is not governed by core**: core does not validate a `content` schema, and plugins validate user-submitted content; plugins and applications must keep historical revisions interpretable. - **Presentation and search depend on the plugin**: presentation, search, and Prepared Context for plugin families go - through the host process and return 503 when the plugin is unavailable; without `search_artifacts`, a plugin's data cannot + through the host process; when the plugin is unavailable, presentation and search return 503 and Prepared Context + omits the section; without `search_artifacts`, a plugin's data cannot be used through generic search or Prepared Context. - **Servers may load different plugin versions**: core records which plugin version wrote each revision but does not stop instances from loading different versions; whether old and new versions can read and write the same data at once is the @@ -1171,11 +1201,11 @@ Reasons for this choice: | Question | Notes | | --- | --- | | Default limits for the write transaction block | Whether 30 seconds is right; whether SQLite and OceanBase need different defaults; per-block operation and byte limits | -| Host process defaults | Default synchronous call limit, per-host-process concurrency limit, and restart backoff | +| Host process defaults | Default synchronous call limit, per-host-process concurrency limit, heartbeat limit, idle stop time, total host process limit, and restart backoff | | Permission to create the dedicated database | When Server's database login cannot create databases, whether to allow falling back to tables prefixed by plugin name in core's database, besides the deployer creating the database in advance | | Plugin families in Recall | Prepared Context is covered; whether Recall should be, and how its candidates are defined | | Passages in generic search results | The generic search API returns only exact revisions, and the passages a plugin returns are used only by Prepared Context. Whether search results should add passages and their locations | -| Naming families and Source types | Whether they must start with the plugin name, so naming alone keeps plugins from taking over each other's families | +| Naming families and Source types | Whether they must start with the plugin name, so naming alone keeps plugins from taking over each other's families. With the prefix, core can map a family to its plugin directory even when `plugin.py` fails to import, and return 503 for that family instead of 404, distinguishing it from a removed plugin | | Search controls in Prepared Context | Letting built-in families accept a section's `search` too is a new optional field that leaves existing calls unaffected; a separate proposal is recommended. Removing or renaming Prepared Context's other feature-specific parameters is a breaking change that needs a new API version, so v1 leaves them as they are | | Shrinking the window | Built-in Atomic Memory shrinks the next Source window when the model times out. Plugins cannot affect the window size, so an oversized window keeps timing out. Whether plugins may request a smaller window for the Scope with an agreed exception | | Windows that keep failing | A Source window that always fails blocks later invocations in the Scope. Whether to offer an operation that skips it or moves it to a dead letter, and how to record skipped input | diff --git a/docs/zh/rfcs/2549-plugin-interfaces.md b/docs/zh/rfcs/2549-plugin-interfaces.md index f9a6170c79..eee9fae6ce 100644 --- a/docs/zh/rfcs/2549-plugin-interfaces.md +++ b/docs/zh/rfcs/2549-plugin-interfaces.md @@ -238,6 +238,7 @@ Prepared Context 对该 family 返回 422。 | `timeout_seconds` | 300 | 整次调用的时限 | | `transaction_timeout_seconds` | 30 | 写事务块的时限,不超过 `timeout_seconds` | | `max_workers` | 1 | 跨 Scope 的并发上限 | +| `host_processes` | 1 | 每个 Server 进程中本插件宿主进程数的建议上限,部署者可以按插件覆盖;接口请求较重的插件可以调大 | | `change_timeout_seconds` | 30 | 一次用户修改调用的时限,包括其中的写事务块 | | `definitions` | `()` | 插件自带的 Source 类型,随插件加载登记,见第 3 节和参考级说明第 2 节 | | `setup` | 必填 | 见上表 | @@ -277,7 +278,7 @@ class IncidentReports: "report", source.ref.source_type, source.ref.source_id) written = await tx.put(artifact_id, content={"title": "工单报告", "summary": summary}, source_refs=[source.ref]) - # 拿到真实的 artifact_id 与 revision 后写入自有索引,按 ID upsert + # 拿到真实的 artifact_id 与 revision 后写入自有索引,键为 (artifact_id, revision) await self.index.upsert(request.scope_id, written.ref.artifact_id, written.ref.revision, vector) # 块正常结束:core 提交 Artifact 写入、游标推进与完成确认 @@ -317,7 +318,8 @@ plugin = ArtifactPlugin( ``` 块内抛出异常时,core 回滚块内全部 Artifact 写入,游标不动,下次重试同一窗口。插件自有索引不在 core 的事务中: -插件按稳定 ID upsert,重试时会覆盖上一次留下的条目;读取自有索引时以 core 的当前数据为准(见参考级说明 3.5)。 +插件按 `(artifact_id, revision)` 写入,旧 revision 的条目保留到被清理;检索结果由 core 过滤为当前 revision,回滚留下的 +条目不会被返回(见参考级说明 3.5)。 ### 4.4 调用方怎么使用 @@ -381,7 +383,8 @@ Artifact 插件: - **启动**:Server 逐个检查插件目录。某个插件检查失败(缺少 `plugin.py`、导入失败、声明无效、family 或 Source 类型 与内置或其他插件冲突)只影响该插件,Server 和其他插件正常启动。 -- **查看**(都需要 `server.admin`,只读,数据都来自启动检查或数据库,任何 Server 角色都给出相同结果): +- **查看**(都需要 `server.admin`,只读):检查结果来自启动检查,任何 Server 角色都相同;`setup` 之后才发现的失败(例如 + 缺少必需方法)只出现在启动了宿主进程的实例上,`background` 角色的实例看不到: - `GET /v1/plugins`、`GET /v1/plugins/{name}`:每个插件的检查结果、类型、family 或 Source 类型、消费的 Source 类型、 触发方式和 Scope 范围。 - `GET /v1/plugins/{name}/scopes`:每个 Scope 是否有待处理的工作、已消费到的 journal 位置和当前 journal 位置。 @@ -390,9 +393,10 @@ Artifact 插件: - **停用**:从插件目录移走后重启。已保存的 Source、Artifact 和游标都保留,但该插件的 family 和 Source 类型不再注册:通用接口读取、检索或修改该 family 时返回 404,与不存在的 family 相同。插件 Artifact 的内容通常只 记录摘要或位置,正文、分块和文件在插件自己的存储中,没有插件就无法解释,因此不提供脱离插件的读取。插件 Source 类型的 - 新写入返回 422。重新部署同名插件时,读取恢复,生成从原游标继续。插件的专属存储 + 新写入返回 404,与未知的 Source 类型相同。重新部署同名插件时,读取恢复,生成从原游标继续。插件的专属存储 不随之删除,由部署者保留或清理。 -- **宿主进程**:由 core 按需启动、复用和重启,部署者不需要配置或管理。宿主进程的启动、终止和重启只体现在日志和指标中。 +- **宿主进程**:插件加载后由 core 启动,按负载增减,失去响应时重启。部署者可以调整每个插件的进程数上限和总上限(见参考 + 级说明第 6 节),不需要管理单个进程。宿主进程的启动、终止和重启只体现在日志和指标中。 # 参考级说明 @@ -408,7 +412,7 @@ class Interval(BaseModel): class Cron(BaseModel): expression: str - timezone: str = "Asia/Shanghai" + timezone: str | None = None # 默认为 Server 所在机器的时区 class ArtifactPlugin(BaseModel): # 字段见指南级说明 4.2 family: str @@ -616,11 +620,13 @@ class ArtifactReads(Protocol): - **插件自有存储**:插件的索引和其他存储(core 分配的专属存储,或插件自己连接的任何数据库、对象存储、向量库)不在 core 的事务中。插件用自己的客户端写入并提交自有存储,core 不参与,也不保证两者一致。core 的事务是核心数据的唯一提交点: 自有存储中的数据只有被 core 中已提交的 revision 引用后才算生效。这不需要两阶段提交,按下面的做法即可保持一致: - 1. 在写事务块内、拿到 `ArtifactSnapshot` 之后写自有存储,按 `artifact_id` upsert。这样自有存储的写入失败会让核心写入 - 一起回滚。 - 2. 写事务提交失败时,自有存储可能留下本次的条目。重试会处理同一窗口、得到同一个稳定 ID,覆盖这些条目。 - 3. 把自有索引当作候选来源:命中的 ID 用 `get` 读取 core 中的当前快照,以快照内容和状态为准。这样回滚留下的条目 - 不会让插件读到过期内容。插件也可以定期按 core 数据重建索引。 + 1. 在写事务块内、拿到 `ArtifactSnapshot` 之后写自有存储,键为 `(artifact_id, revision)`,不覆盖其他 revision 的条目。 + 这样自有存储的写入失败会让核心写入一起回滚。 + 2. 写事务提交失败时,自有存储会留下一个没有提交的 revision 的条目,而当前 revision 的条目仍在。后台调用重试时会再次 + 写入同一个键;用户修改没有重试,留下的条目在下一次写入同一 revision 号时被覆盖,或被定期清理。 + 3. 检索时,插件返回命中的精确 revision,core 只保留当前、active、调用者可读的 revision(参考级说明第 7 节),回滚 + 留下的条目和旧 revision 的条目都不会出现在结果中。插件在其他地方读取自有存储时,以 core 的当前快照为准。旧 + revision 的条目由插件定期清理,也可以按 core 数据重建索引。 4. 大块内容(正文、分块、文件字节)按内容摘要存成不可变的记录:先写入并提交到自有存储,再在写事务块中提交内容里 带有该摘要的 Artifact。不能用 `(artifact_id, revision)` 作为键:写事务回滚后,同一个 revision 号会再次分配给内容 不同的写入。按内容摘要存储时,重试写入同样的内容得到同一个键;提交失败只会留下没有被任何 revision 引用的记录, @@ -755,19 +761,31 @@ Artifact 插件的每次后台调用处理该 Scope 中游标之后的一个 Sou | `render_artifact`、`search_artifacts` | 宿主进程 | | `generate` | Supervisor Worker | -- **数量与启动**:每个 Server 进程为每个加载的插件维护至多一个宿主进程,插件加载后在后台启动,之后复用。插件都要实现 - `render_artifact`,所以每个加载的插件都有宿主进程。 +- **每个插件一组进程**:每个 Server 进程为每个加载的插件维护一组宿主进程,不同插件不共用进程。一个插件阻塞、崩溃或被 + 终止不影响其他插件;以后按插件隔离依赖时,每个插件也需要自己的解释器。 +- **数量**:插件加载后启动一个宿主进程并一直保留,插件都要实现 `render_artifact`,所以每个加载的插件至少有一个。本插件的 + 进程都在处理请求、且有请求排队时,core 再启动一个,直到本插件的上限;多出的进程空闲 5 分钟后停止。本插件的上限取 + 声明中的 `host_processes`,部署者可以用 `POWERCONTEXT_SERVER_PLUGIN_HOST_PROCESSES`(按插件名的 JSON)覆盖。所有插件的 + 宿主进程总数不超过 `POWERCONTEXT_SERVER_PLUGIN_TOTAL_HOST_PROCESSES`,达到总上限时不再为负载启动新进程,请求在已有进程上排队;每个插件常驻的第一个进程不受总上限限制。 + 新进程启动需要数秒,增加进程只对持续的负载有效。 - **执行**:宿主进程启动时导入一次 `plugin.py` 并核对声明,写入器在宿主进程中执行。一个宿主进程可以并发处理多个请求, - 并发上限由 Server 配置决定。 -- **超时与故障**:每次调用受各自的时限约束(Source 写入、展示和检索使用 Server 的同步调用时限,用户修改使用 - `change_timeout_seconds`)。超时、崩溃或失去响应时,core 终止该进程,进行中的请求返回 503,并在退避后重新启动;退避期间 - 该插件的同步调用返回 503,后台调用不受影响。 + 并发上限由 Server 配置决定;请求分给进行中请求最少的进程。 +- **超时**:每次调用受各自的时限约束(Source 写入、展示和检索使用 Server 的同步调用时限,用户修改使用 + `change_timeout_seconds`)。请求超过时限时,core 只取消这一个请求:插件在等待 I/O 时取消立即生效,写事务回滚,该请求 + 返回 504,同一进程中的其他请求不受影响。 +- **失去响应**:宿主进程定时向 Server 报告心跳。插件阻塞了事件循环(CPU 密集的计算、没有 `await` 的阻塞调用)时,取消 + 无法生效,心跳也会中断;超过心跳时限后 core 终止该进程,超时的请求返回 504,进程中其他进行中的请求返回 503。进程崩溃 + 时进行中的请求同样返回 503。插件应把 CPU 密集的工作放进 `asyncio.to_thread` 或后台的 `generate`。 +- **重启**:本插件没有可用的宿主进程时,core 在退避后重新启动;退避期间该插件的同步调用返回 503,后台调用不受影响。 +- **耗时的工作放到后台**:增加进程只能缓解"慢但能在时限内完成"的请求。解析大文件、批量计算向量等以分钟计的工作, + 插件应在接口中保存输入并提交 Source 后立即返回,由 `generate` 在 Worker 中处理,页面查询处理状态。 - **代码变更**:宿主进程在存续期间不重新导入插件,启动时核对代码指纹。修改插件后需要重启 Server,与 Worker 的规则一致。 - **隔离**:与 Worker 相同,宿主进程隔离普通故障,不是不可信代码的沙箱。 **已激活插件的内存记录**:每个 Server 进程在内存中记录本进程加载的插件:插件名、目录、类型、声明摘要、检查结果,以及 宿主进程的当前状态(未启动、运行中、重启退避)。路由用户请求、启动宿主进程和派发 Worker 都以这份记录为准。它不持久化, -也不跨进程同步;Server 重启后按插件目录重新建立。运维接口只返回各进程一致的检查结果和声明,宿主进程状态通过日志和指标查看。 +也不跨进程同步;Server 重启后按插件目录重新建立。运维接口返回检查结果、声明和本实例宿主进程报告的永久失败,宿主进程的 +运行状态通过日志和指标查看。 ## 7. 公开读取、展示与检索 @@ -814,11 +832,13 @@ class SearchResult(BaseModel): `admission`、`fusion`、`rerank`、`min_score` 等,`include_scores` 除外,它只决定 core 是否返回分数)原样交给 `search_artifacts`,由插件按自己的索引解释;插件不支持的参数 抛出 `InvalidContent`,接口返回 422。core 只保留命中中调用者有权读取的 active 当前 revision,按插件给出的顺序返回 - 精确 revision,`include_scores` 时附带插件给出的分数。插件因此不能借检索返回调用者看不到的数据。 + 精确 revision,`include_scores` 时附带插件给出的分数。插件因此不能借检索返回调用者看不到的数据。过滤后的结果可能 + 少于请求的数量,core 不补取。 - **Prepared Context**:`assembly.sections` 可以列出插件 family。core 以 Prepared Context 的 `query`、该项的 `limit` 和 请求的字节预算调用 `search_artifacts`,把命中的片段作为上下文条目按 section 顺序装填,与内置 family 一样带精确 revision - 引用、计入字节预算和回执,超出预算的条目被截断或省略。每项可以携带可选的 `search`,内容是检索请求中除 `query`、`limit` 以外的字段,原样转交插件;内置 family 携带 - `search` 时返回 422。 + 引用、计入字节预算和回执,超出预算的条目被截断或省略。插件不可用(宿主进程不可用、超时或检索失败)时,core 省略该 + section,在回执中记录省略的原因,其他 section 照常返回。每项可以携带可选的 `search`,内容是检索请求中除 `query`、 + `limit` 以外的字段,原样转交插件;内置 family 携带 `search` 时返回 422。 - Review 和 Recall 不对插件 family 开放,对应接口返回明确的“不支持”错误;`GET /v1/capabilities` 列出插件 family。 ## 8. 加载与生命周期 @@ -833,7 +853,7 @@ class SearchResult(BaseModel): - Worker 每次调用重新导入插件代码,导入前核对代码指纹(见 1.1)。插件目录在 Server 运行期间被修改后,新的 Worker 调用 和新启动的宿主进程都会失败并提示重启,不会出现同一个 Server 中新旧代码混用。部署者应在修改后重启 Server。 - `api` 角色的 Server 实例不运行后台任务,但也会检查插件并注册 family 和 Source 类型,用于读取、检索、Source 写入和用户 - 修改;它按需启动宿主进程,不派发 Worker。`background` 角色的实例不接收请求,不启动宿主进程。 + 修改;它启动宿主进程,不派发 Worker。`background` 角色的实例不接收请求,不启动宿主进程。 - 运行中增减插件(热加载)和插件自定义 API 见 [RFC #2579](https://github.com/oceanbase/powercontext/pull/2579),建立在宿主进程之上。 ## 9. 执行约束 @@ -901,6 +921,7 @@ class SearchResult(BaseModel): | 调整 | `POST /v1/context/prepare`:`ContextAssemblySection.family` 从枚举改为字符串,可以是已加载的插件 family;新增可选的 `search`(检索请求中除 `query`、`limit` 以外的字段),只对插件 family 生效;回执中条目的 family 从枚举改为字符串,可以是插件 family | | 调整 | 导出与恢复的 Artifact revision 记录格式版本加一,增加 `metadata` | | 调整 | 环境变量 `POWERCONTEXT_SERVER_PLUGINS_DIR` 取代 `POWERCONTEXT_SERVER_ARTIFACT_PLUGINS_DIR` | +| 新增 | 环境变量 `POWERCONTEXT_SERVER_PLUGIN_HOST_PROCESSES`(按插件名覆盖宿主进程数上限的 JSON)、`POWERCONTEXT_SERVER_PLUGIN_TOTAL_HOST_PROCESSES`(每个 Server 进程中宿主进程的总上限) | `openapi/powercontext.yaml` 按上表更新后重新生成 `src/powercontext/http/_generated/` 和各集成的操作表。 @@ -917,10 +938,10 @@ class SearchResult(BaseModel): # 缺点 -- **宿主进程常驻占用资源**:每个 Server 进程为每个需要同步调用的插件多一个常驻进程,多实例部署时数量随实例数增加。 - 同步调用多一次进程间往返和序列化。 +- **宿主进程常驻占用资源**:每个 Server 进程为每个加载的插件至少多一个常驻进程(每个约 150 MB),负载高时更多,多实例 + 部署时数量随实例数增加。同步调用多一次进程间往返和序列化。 - **同步调用依赖插件可用**:宿主进程崩溃或处于重启退避时,该插件的 Source 写入和用户修改返回 503;插件代码中的缺陷会 - 直接表现为用户请求失败。 + 直接表现为用户请求失败。阻塞事件循环的插件会让同一进程中的其他请求一起失败。 - **写事务持锁**:写事务块期间持有数据库锁,SQLite 上会阻塞其他写入。插件若在块内执行慢操作,会拖慢整个 Server 的写入, 直到块超时回滚。 - **插件自有存储与核心数据不保证一致**:两者不在同一事务中,提交失败可能在自有存储中留下条目。插件需要按稳定 ID 覆盖、 @@ -937,7 +958,8 @@ class SearchResult(BaseModel): 部署时,插件应从环境变量读取 family 等标识。 - **内容结构不受 core 治理**:core 不校验 `content` 的 schema,用户提交的内容由插件校验;历史 revision 的解释需要插件和 应用自行保持兼容。 -- **展示和检索依赖插件**:插件 family 的展示、检索和 Prepared Context 都要进入宿主进程,插件不可用时这些接口返回 503; +- **展示和检索依赖插件**:插件 family 的展示、检索和 Prepared Context 都要进入宿主进程,插件不可用时展示和检索返回 + 503,Prepared Context 省略该 section; 插件没有实现 `search_artifacts` 时,它的数据不能通过通用检索和 Prepared Context 使用。 - **多个 Server 的插件版本可能不一致**:core 记录每个 revision 由哪个插件版本写入,但不阻止不同实例加载不同版本;新旧 版本能否同时读写同一份数据,由插件负责。汇总各实例当前加载的版本需要维护一张实例登记表,留给插件安装的后续提案。 @@ -998,11 +1020,11 @@ class SearchResult(BaseModel): | 问题 | 说明 | | --- | --- | | 写事务块的时限与限额默认值 | 默认 30 秒是否合适;SQLite 与 OceanBase 是否采用不同默认值;单块操作数与字节上限 | -| 宿主进程的默认参数 | 同步调用时限、单个宿主进程的并发上限和重启退避的默认值 | +| 宿主进程的默认参数 | 同步调用时限、单个宿主进程的并发上限、心跳时限、空闲停止时间、宿主进程总上限和重启退避的默认值 | | 专属存储的建库权限 | Server 的数据库登录没有建库权限时,除了由部署者事先建库,是否允许退回到 core 库中按插件名前缀建表 | | 插件 family 接入 Recall | Prepared Context 已接入,Recall 是否需要接入、候选内容怎样定义 | | 通用检索结果带片段 | 通用检索接口目前只返回精确 revision,插件返回的片段只用于 Prepared Context。是否在检索结果中增加片段和位置 | -| family 与 Source 类型的命名 | 是否要求以插件名为前缀,从命名上避免不同插件冒用同一个 family | +| family 与 Source 类型的命名 | 是否要求以插件名为前缀,从命名上避免不同插件冒用同一个 family。要求前缀后,`plugin.py` 导入失败时 core 也能从 family 名找到对应的插件目录,对该 family 返回 503 而不是 404,与插件已移除区分 | | Prepared Context 的检索控制 | 内置 family 也接受每项的 `search`,是新增的可选字段,不影响现有调用,建议另行提案。Prepared Context 中其他按功能定制的参数,移除或改名是不兼容变更,需要新的 API 版本,不在 v1 中整理 | | 窗口大小的回退 | 内置 Atomic Memory 在模型超时时会缩小下一次的 Source 窗口。插件无法影响窗口大小,过大的窗口会持续超时。是否允许插件以约定的异常请求缩小该 Scope 的窗口 | | 持续失败的窗口 | 始终失败的 Source 窗口会阻塞该 Scope 的后续调用。是否提供跳过或转入死信的运维操作,以及如何记录被跳过的输入 | From d29878d529bdb8ab17d9b68fa17a1845370cf718 Mon Sep 17 00:00:00 2001 From: jasper-yl Date: Sun, 15 Nov 2026 03:02:45 -0800 Subject: [PATCH 2/6] docs(rfc): describe host process memory by its order instead of a fixed figure Co-Authored-By: Claude Opus 5.5 --- docs/en/rfcs/2549-plugin-interfaces.md | 8 +++++--- docs/zh/rfcs/2549-plugin-interfaces.md | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/en/rfcs/2549-plugin-interfaces.md b/docs/en/rfcs/2549-plugin-interfaces.md index bec9833441..932ef17093 100644 --- a/docs/en/rfcs/2549-plugin-interfaces.md +++ b/docs/en/rfcs/2549-plugin-interfaces.md @@ -1101,9 +1101,11 @@ record one event. # Drawbacks -- **Host processes hold resources**: each Server process gets at least one more long-lived process (about 150 MB each) - for each loaded plugin, more under load, and the count grows with instances in multi-instance deployments. Synchronous calls add one - inter-process round trip and serialization. +- **Host processes hold resources**: each Server process gets at least one more long-lived process for each loaded + plugin, more under load, and the count grows with instances in multi-instance deployments. Each host process is a + full interpreter with the core runtime and the plugin loaded, so its memory is of the same order as a Server + process's, and more for plugins with heavier dependencies. Synchronous calls add one inter-process round trip and + serialization. - **Synchronous calls depend on the plugin being available**: while a host process is crashed or in restart backoff, the plugin's Source writes and user changes return 503; defects in plugin code show up directly as failed user requests. A plugin that blocks the event loop makes other requests in the same process fail with it. diff --git a/docs/zh/rfcs/2549-plugin-interfaces.md b/docs/zh/rfcs/2549-plugin-interfaces.md index eee9fae6ce..c7750872f5 100644 --- a/docs/zh/rfcs/2549-plugin-interfaces.md +++ b/docs/zh/rfcs/2549-plugin-interfaces.md @@ -938,8 +938,9 @@ class SearchResult(BaseModel): # 缺点 -- **宿主进程常驻占用资源**:每个 Server 进程为每个加载的插件至少多一个常驻进程(每个约 150 MB),负载高时更多,多实例 - 部署时数量随实例数增加。同步调用多一次进程间往返和序列化。 +- **宿主进程常驻占用资源**:每个 Server 进程为每个加载的插件至少多一个常驻进程,负载高时更多,多实例部署时数量随实例数 + 增加。每个宿主进程都是完整的解释器,加载了 core 运行时和插件,内存占用与 Server 进程同一量级,插件依赖越多占用越大。 + 同步调用多一次进程间往返和序列化。 - **同步调用依赖插件可用**:宿主进程崩溃或处于重启退避时,该插件的 Source 写入和用户修改返回 503;插件代码中的缺陷会 直接表现为用户请求失败。阻塞事件循环的插件会让同一进程中的其他请求一起失败。 - **写事务持锁**:写事务块期间持有数据库锁,SQLite 上会阻塞其他写入。插件若在块内执行慢操作,会拖慢整个 Server 的写入, From b50c4ca9e5142fe01d5d2957ad2ccce3de1b9c06 Mon Sep 17 00:00:00 2001 From: jasper-yl Date: Sun, 15 Nov 2026 03:08:44 -0800 Subject: [PATCH 3/6] docs(rfc): say which requests get 503 when a blocked host process is terminated Requests still in flight when core terminates the process, including the one that blocked it, return 503; only requests that passed their own time limit before then return 504. The plugin guide said the same and is corrected with it. Co-Authored-By: Claude Opus 5.5 --- docs/en/docs/develop/plugins.md | 5 +++-- docs/en/rfcs/2549-plugin-interfaces.md | 4 ++-- docs/zh/docs/develop/plugins.md | 4 ++-- docs/zh/rfcs/2549-plugin-interfaces.md | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/en/docs/develop/plugins.md b/docs/en/docs/develop/plugins.md index e0cfd80ce0..0506468040 100644 --- a/docs/en/docs/develop/plugins.md +++ b/docs/en/docs/develop/plugins.md @@ -390,8 +390,9 @@ do not assume all requests reach the same process. - A host process handles several requests at once on one event loop. When a call runs past its time limit, core cancels only that request (its write transaction rolls back) and returns 504; other requests in the process are unaffected. - Blocking the event loop keeps cancellation from taking effect and also stops the host process's heartbeat. Five seconds - after the heartbeat stops, core terminates the process: the timed-out request returns 504, the process's other requests - return 503, and the process restarts after a backoff. Put CPU-heavy or synchronously blocking code in + after the heartbeat stops, core terminates the process: requests that passed their own time limit before then return + 504, requests still in flight at termination (including the one that blocked) return 503, and the process restarts + after a backoff. Put CPU-heavy or synchronously blocking code in `await asyncio.to_thread(...)`, and leave work that takes minutes to the background `generate`. - In Prepared Context, a plugin section is left out when the plugin is unavailable (a timeout, no available host process, or a failed search); the receipt records the family's failed search, and the other sections are returned as usual. diff --git a/docs/en/rfcs/2549-plugin-interfaces.md b/docs/en/rfcs/2549-plugin-interfaces.md index 932ef17093..ae000abc9f 100644 --- a/docs/en/rfcs/2549-plugin-interfaces.md +++ b/docs/en/rfcs/2549-plugin-interfaces.md @@ -902,8 +902,8 @@ long-lived host process: 504, and other requests in the same process are unaffected. - **Loss of response**: host processes report a heartbeat to Server. When a plugin blocks the event loop (CPU-heavy work, or a blocking call without `await`), cancellation cannot take effect and the heartbeat stops; past the heartbeat limit - core terminates the process, the timed-out request returns 504, and the process's other in-flight requests return 503. A - crash also returns 503 for in-flight requests. Plugins should move CPU-heavy work into `asyncio.to_thread` or into + core terminates the process. Requests that passed their own time limit before then return 504; requests still in + flight at termination, including the one that blocked, return 503. A crash also returns 503 for in-flight requests. Plugins should move CPU-heavy work into `asyncio.to_thread` or into background `generate`. - **Restarts**: when the plugin has no usable host process, core restarts one after a backoff; during the backoff the plugin's synchronous calls return 503, and background calls are unaffected. diff --git a/docs/zh/docs/develop/plugins.md b/docs/zh/docs/develop/plugins.md index 3bf1fe904a..42db8ae555 100644 --- a/docs/zh/docs/develop/plugins.md +++ b/docs/zh/docs/develop/plugins.md @@ -360,8 +360,8 @@ plugin = ArtifactPlugin( - 一个宿主进程同时处理多个请求,都在同一个事件循环上。调用超过时限时,core 只取消这个请求(写事务随之回滚)并返回 504, 同一进程中的其他请求不受影响。 -- 阻塞事件循环会让取消无法生效,宿主进程的心跳也随之中断。心跳中断 5 秒后 core 终止该进程:超时的请求返回 504,进程中的 - 其他请求返回 503,进程退避后重启。CPU 密集或同步阻塞的代码放进 `await asyncio.to_thread(...)`;需要几分钟的工作交给 +- 阻塞事件循环会让取消无法生效,宿主进程的心跳也随之中断。心跳中断 5 秒后 core 终止该进程:在此之前已经超过自身时限的 + 请求返回 504,终止时仍在进行中的请求(包括造成阻塞的那个)返回 503,进程退避后重启。CPU 密集或同步阻塞的代码放进 `await asyncio.to_thread(...)`;需要几分钟的工作交给 后台的 `generate`。 - Prepared Context 中的插件 section 在插件不可用(超时、宿主进程不可用或检索失败)时省略,回执中记录该 family 的检索 失败,其他 section 照常返回。 diff --git a/docs/zh/rfcs/2549-plugin-interfaces.md b/docs/zh/rfcs/2549-plugin-interfaces.md index c7750872f5..a46426fdee 100644 --- a/docs/zh/rfcs/2549-plugin-interfaces.md +++ b/docs/zh/rfcs/2549-plugin-interfaces.md @@ -774,8 +774,8 @@ Artifact 插件的每次后台调用处理该 Scope 中游标之后的一个 Sou `change_timeout_seconds`)。请求超过时限时,core 只取消这一个请求:插件在等待 I/O 时取消立即生效,写事务回滚,该请求 返回 504,同一进程中的其他请求不受影响。 - **失去响应**:宿主进程定时向 Server 报告心跳。插件阻塞了事件循环(CPU 密集的计算、没有 `await` 的阻塞调用)时,取消 - 无法生效,心跳也会中断;超过心跳时限后 core 终止该进程,超时的请求返回 504,进程中其他进行中的请求返回 503。进程崩溃 - 时进行中的请求同样返回 503。插件应把 CPU 密集的工作放进 `asyncio.to_thread` 或后台的 `generate`。 + 无法生效,心跳也会中断;超过心跳时限后 core 终止该进程。在此之前已经超过自身时限的请求返回 504,终止时仍在进行中的 + 请求(包括造成阻塞的那个)返回 503。进程崩溃时进行中的请求同样返回 503。插件应把 CPU 密集的工作放进 `asyncio.to_thread` 或后台的 `generate`。 - **重启**:本插件没有可用的宿主进程时,core 在退避后重新启动;退避期间该插件的同步调用返回 503,后台调用不受影响。 - **耗时的工作放到后台**:增加进程只能缓解"慢但能在时限内完成"的请求。解析大文件、批量计算向量等以分钟计的工作, 插件应在接口中保存输入并提交 Source 后立即返回,由 `generate` 在 Worker 中处理,页面查询处理状态。 From d5e106767058e518576fd8b548d992e9b7bf2012 Mon Sep 17 00:00:00 2001 From: jasper-yl Date: Sun, 15 Nov 2026 03:56:47 -0800 Subject: [PATCH 4/6] docs(rfc): keep the caller's submitted content as edit evidence and let plugin pages call their family's generic Artifact APIs RFC #2549: a plugin interprets the content of a generic create or edit, and core keeps the content as submitted as the lineage-only Source even when the plugin writes different content. RFC #2579: the Dashboard forwards a plugin page's calls to the generic Artifact APIs of the plugin's own family as the signed-in user, with the family filled in by the Dashboard. Co-Authored-By: Claude --- docs/en/rfcs/2549-plugin-interfaces.md | 9 ++++-- docs/en/rfcs/2579-plugin-reload-and-apis.md | 34 ++++++++++++++++----- docs/zh/rfcs/2549-plugin-interfaces.md | 6 ++-- docs/zh/rfcs/2579-plugin-reload-and-apis.md | 25 +++++++++++---- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/docs/en/rfcs/2549-plugin-interfaces.md b/docs/en/rfcs/2549-plugin-interfaces.md index ae000abc9f..cf9b01a8fe 100644 --- a/docs/en/rfcs/2549-plugin-interfaces.md +++ b/docs/en/rfcs/2549-plugin-interfaces.md @@ -790,8 +790,9 @@ class InvalidContent(Exception): # the plugin rejects the content; the - The write transaction in these calls allows only the matching write operation from the table, plus `set_tags` on the same Artifact; writing any other Artifact raises immediately. If the method returns normally without performing the required write, core rolls back and returns 502, meaning the plugin did not complete the contract. -- The plugin may normalize the content (for example, by filling default fields); the written content is what the plugin - submits. +- The plugin interprets the request's `content`. It may normalize the content (for example, by filling default fields), + or treat it as a description of one change and compute the content to write from it. The written content is what the + plugin passes to the writer. - `put` in `create_artifact` and `update_artifact` always appends a revision, even when the content equals the current revision. This matches edits to built-in families: every user edit has a new `lineage_only` Content Source (see 4.2), which needs a new revision to record it. @@ -808,7 +809,9 @@ class InvalidContent(Exception): # the plugin rejects the content; the - **Provenance**: as for built-in families, on create, edit, restore, and undo merge core stores the submitted content as an internal Content Source in the same transaction (`lineage_only`, with operation `artifact_create`, `artifact_replace`, `artifact_restore`, or `artifact_undo_merge`) and records it in lineage as the new revision's - direct source. Core writes these Sources, and they never enter a plugin's input window. + direct source. On create and edit, core stores the request's `content` as submitted; when the plugin writes different + content, this Source is still what the caller submitted, and the content the plugin wrote is in the new revision. Core + writes these Sources, and they never enter a plugin's input window. - **Merge registry**: the generic merge, forget, and restoration APIs sit on the registry of the shared merge engine ([RFC #1859](1859_artifact_merge.md)) and work for every registered family. Experience and Atomic Memory are the registered built-in families and use their own adapters; a plugin family is registered at load diff --git a/docs/en/rfcs/2579-plugin-reload-and-apis.md b/docs/en/rfcs/2579-plugin-reload-and-apis.md index 0746f18463..3b85f20951 100644 --- a/docs/en/rfcs/2579-plugin-reload-and-apis.md +++ b/docs/en/rfcs/2579-plugin-reload-and-apis.md @@ -62,8 +62,9 @@ Goals: 3. Plugins can declare their own HTTP APIs; core handles routing, authentication, authorization, request size, and time limits, and the plugin writes only handlers. 4. Writes to core data through plugin APIs follow the same permission and provenance rules as user changes in RFC #2549. -5. Plugin pages never get the user's PowerContext session and cannot use it to call any Server API other than their own - plugin's APIs. +5. Plugin pages never get the user's PowerContext session. A page can only ask the Dashboard to call, as the current + user, its own plugin's APIs and the generic Artifact APIs of its plugin's family; it cannot use the session to call any + other Server API. # Guide-level explanation @@ -221,6 +222,11 @@ plugin = ArtifactPlugin( - A page can link to, navigate to, or open external sites in a new window, for example handing search results to an external RAG service's page. Plugins are trusted code, so pages may reach external sites freely; core guarantees only that a page cannot borrow the user's PowerContext session. +- An Artifact plugin's page can also call the generic Artifact APIs (RFC #2549) of its plugin's family: read, history, + governance state, create, edit, merge, forget, restore, and tags. The Dashboard forwards these calls as the signed-in + user in the same way, and they are equivalent to calling the generic APIs directly: core handles permissions, version + preconditions, and provenance, and passes changes to the plugin's user change methods. The page declares no routes for + them. - Pages can only be static files (HTML, JavaScript, CSS, images, fonts), which core serves directly from the plugin's current version snapshot without running plugin code. @@ -230,6 +236,10 @@ Calls from a page: const client = powercontextPluginClient(); // a small script from core that wraps postMessage const { scopeId } = await client.context(); const result = await client.request("GET", `/knowledge-bases/${scopeId}/documents/${sourceId}/original`); + +// generic Artifact APIs of this plugin's family; the path follows /v1/scopes/{scopeId}/artifacts/{family} +const document = await client.artifacts("GET", `/${artifactId}`, { scopeId }); +await client.artifacts("PUT", `/${artifactId}`, { scopeId, json: { content }, ifMatch: document.etag }); ``` # Reference-level explanation @@ -538,11 +548,20 @@ class PluginPages(BaseModel): - **Hosting page**: `/dashboard/plugins/{name}` is a core Dashboard page that requires sign-in. It loads the plugin page in a sandboxed iframe and, after the iframe's first load, sends the page the current Scope, locale, and theme; it then - accepts request messages only from that iframe, requires the path to match a route the plugin declared, forwards the - request through a same-origin server-side call, and returns the result as a message (binary responses as a Blob). + accepts request messages only from that iframe, requires the path to match a route the plugin declared or to be a + generic Artifact API of the plugin's family, forwards the request through a same-origin server-side call, and returns + the result as a message (binary responses as a Blob). - **Server-side forwarding**: `/dashboard/plugins/{name}/api/...` is a Dashboard server route. It requires a Dashboard session and a `Sec-Fetch-Site` of `same-origin` (checking that `Origin` matches Server when the header is missing), and follows the Dashboard's existing approach of calling `/v1/plugins/{name}/api/...` as the session's identity. +- **Forwarding generic Artifact APIs**: `/dashboard/plugins/{name}/artifacts/{scope_id}/...` is a second Dashboard server + route with the same session and same-origin requirements. It calls `/v1/scopes/{scope_id}/artifacts/{family}/...` as + the session's identity, where the Dashboard fills in the family from the plugin's declaration and the page cannot + choose it. Create (`POST /dashboard/plugins/{name}/artifacts/{scope_id}`) becomes the plugin branch of the generic + create API, with the family also filled in by the Dashboard. The request's `If-Match` and body pass to the generic API + unchanged, and the response's status code, `ETag`, `Location`, and body are returned unchanged. The forwarding layer + makes no authorization decision and does not interpret content. A plugin that declares no family (a Source plugin) has + no such route. - **Session isolation**: the Dashboard session cookie is `HttpOnly`, `SameSite=Strict`, with path `/dashboard`. A plugin page is in an opaque origin, so its scripts cannot read the cookie, and Server does not accept forwarding requests with `Origin: null`. @@ -550,8 +569,9 @@ class PluginPages(BaseModel): prevent. The external page can also send `postMessage` to the hosting page and passes the `event.source` check. The hosting page therefore stops forwarding after the iframe's second load, so an external page cannot borrow the user's session. Plugin pages should be single-page applications; navigating between plugin pages also stops forwarding. -- **Scope**: the hosting page forwards only to routes the plugin declared; forwarded requests are still checked by core - against the caller's permissions, so a plugin page cannot use forwarding to reach Scopes the caller cannot access. +- **Scope**: the hosting page forwards only to routes the plugin declared and to the generic Artifact APIs of the + plugin's family; forwarded requests are still checked by core against the caller's permissions, so a plugin page cannot + use forwarding to reach Scopes the caller cannot access or Artifacts of another family. - **Page client script**: core serves a small script at `/dashboard/plugins/_client.js` that wraps this message protocol, and plugin pages can reference it directly. @@ -582,7 +602,7 @@ the same as in RFC #2549; Scopes created by plugins are ordinary Scopes; plugins | --- | --- | | Added | `/v1/plugins/{name}/api/...`: routes plugins declare | | Added | `GET /v1/plugins/{name}/openapi.json` | -| Added | `/dashboard/plugins/{name}`, `/dashboard/plugins/{name}/ui/...`, `/dashboard/plugins/{name}/api/...`, `/dashboard/plugins/_client.js` | +| Added | `/dashboard/plugins/{name}`, `/dashboard/plugins/{name}/ui/...`, `/dashboard/plugins/{name}/api/...`, `/dashboard/plugins/{name}/artifacts/{scope_id}/...`, `/dashboard/plugins/_client.js` | | Added | Routes a plugin declares with `mcp=True` appear as MCP tools on Server's MCP endpoint | | Added | `powercontext.plugins`: `PluginApi`, `Route`, `ApiRequest`, `BinaryResponse`, `ApiError`, `Caller`, `PluginPages`; the context's `require`, `reads`, `writer`, `sources`, and `scopes` | | Changed | `SourcePlugin` and `ArtifactPlugin` gain `api`, `pages`, `upgrade`, and `upgrade_timeout_seconds` fields | diff --git a/docs/zh/rfcs/2549-plugin-interfaces.md b/docs/zh/rfcs/2549-plugin-interfaces.md index a46426fdee..1b495cc7a5 100644 --- a/docs/zh/rfcs/2549-plugin-interfaces.md +++ b/docs/zh/rfcs/2549-plugin-interfaces.md @@ -689,7 +689,8 @@ class InvalidContent(Exception): # 插件拒绝内容;接口返回 42 - 这些调用中的写事务只允许上表对应的那一项写操作,以及对同一 Artifact 的 `set_tags`;写其他 Artifact 时立即抛出异常。 方法正常返回但没有完成要求的写操作,core 回滚并返回 502,表示插件没有按约定完成。 -- 插件可以规范化内容(例如补全默认字段),写入的内容以插件提交的为准。 +- 请求中的 `content` 由插件解释。插件可以规范化内容(例如补全默认字段),也可以把它当作对一次修改的描述,据此算出要 + 写入的内容。写入的内容以插件交给写入器的为准。 - `create_artifact`、`update_artifact` 中的 `put` 总是追加 revision,内容与当前 revision 相同时也一样。这与内置 family 的 编辑一致:每次用户编辑都有一条新的 `lineage_only` Content Source(见 4.2),需要一个新 revision 记录它。 - 插件应在写事务块中、拿到快照之后更新自己的存储,做法同 3.5。 @@ -702,7 +703,8 @@ class InvalidContent(Exception): # 插件拒绝内容;接口返回 42 在写事务中再次校验,期间被其他写入改变则回滚并返回 409。 - **溯源**:与内置 family 相同,新建、编辑、恢复和撤销合并时,core 在同一事务中把调用方提交的内容另存为一条内部 Content Source(`lineage_only`,操作分别为 `artifact_create`、`artifact_replace`、`artifact_restore`、`artifact_undo_merge`), - 作为新 revision 的直接来源记入 lineage。这类 Source 由 core 写入,不进入任何插件的输入窗口。 + 作为新 revision 的直接来源记入 lineage。新建和编辑时保存的是请求中的 `content` 原文;插件写入的内容与它不同时, + 这条 Source 仍是调用方提交的那一份,插件写入的内容在新 revision 中。这类 Source 由 core 写入,不进入任何插件的输入窗口。 - **合并注册表**:通用的合并、遗忘、恢复接口建立在共享合并引擎([RFC #1859](1859_artifact_merge.md))的注册表之上,对所有登记过的 family 生效。内置 family 登记了 Experience 和 Atomic Memory, 由各自的适配器处理;插件 family 在加载时登记,处理方式是转交给插件对应的方法。没有登记的 family 返回 422。 - **不提供预览**:Atomic Memory 的专用接口支持先预览恢复影响、再凭签名 token 执行。通用接口不提供预览,也就不需要签名 diff --git a/docs/zh/rfcs/2579-plugin-reload-and-apis.md b/docs/zh/rfcs/2579-plugin-reload-and-apis.md index 663e53e226..5ba2369249 100644 --- a/docs/zh/rfcs/2579-plugin-reload-and-apis.md +++ b/docs/zh/rfcs/2579-plugin-reload-and-apis.md @@ -50,7 +50,8 @@ RFC #2549 已经为热加载和自定义接口铺好了基础: 2. 每次调用从开始到结束只使用一个版本的插件代码,不会出现新旧代码混用,也不会出现用新声明提交旧代码结果的情况。 3. 插件可以声明自己的 HTTP 接口;core 负责路由、认证、授权、请求大小和时限,插件只写处理函数。 4. 插件接口对核心数据的写入与 RFC #2549 的用户修改遵循同样的权限和溯源规则。 -5. 插件页面拿不到用户的 PowerContext 会话,也不能借用户会话调用本插件接口之外的 Server 接口。 +5. 插件页面拿不到用户的 PowerContext 会话。它只能请 Dashboard 以当前用户的身份调用本插件的接口和本插件 family 的通用 + Artifact 接口,不能借用户会话调用其他 Server 接口。 # 指南级说明 @@ -191,6 +192,9 @@ plugin = ArtifactPlugin( 页面通过 `postMessage` 请 Dashboard 转发,Dashboard 以当前登录用户的身份调用。 - 页面可以链接、跳转或在新窗口中打开外部站点,例如把检索结果交给外部的 RAG 服务页面展示。插件是可信代码,页面访问外部 站点不受限制;core 只保证页面借不到用户的 PowerContext 会话。 +- Artifact 插件的页面还可以调用本插件 family 的通用 Artifact 接口(RFC #2549):读取、历史、治理状态、新建、编辑、合并、 + 遗忘、恢复和 tags。这些调用同样由 Dashboard 以当前用户的身份转发,与直接调用通用接口等价:权限、版本前置条件和溯源 + 都由 core 处理,修改交给插件的用户修改方法。页面不需要为此声明路由。 - 页面只能是静态文件(HTML、JavaScript、CSS、图片、字体),由 core 直接从插件的当前版本快照提供,不运行插件代码。 页面中的调用: @@ -199,6 +203,10 @@ plugin = ArtifactPlugin( const client = powercontextPluginClient(); // 由 core 提供的小脚本,封装 postMessage const { scopeId } = await client.context(); const result = await client.request("GET", `/knowledge-bases/${scopeId}/documents/${sourceId}/original`); + +// 本插件 family 的通用 Artifact 接口;路径接在 /v1/scopes/{scopeId}/artifacts/{family} 之后 +const document = await client.artifacts("GET", `/${artifactId}`, { scopeId }); +await client.artifacts("PUT", `/${artifactId}`, { scopeId, json: { content }, ifMatch: document.etag }); ``` # 参考级说明 @@ -456,18 +464,23 @@ class PluginPages(BaseModel): ### 3.2 宿主页面与转发 - **宿主页面**:`/dashboard/plugins/{name}` 是 core 的 Dashboard 页面,要求登录。它以沙箱 iframe 加载插件页面,iframe 第一次 - 加载后把当前 Scope、语言和主题发给页面;之后只接受来自该 iframe 的请求消息,路径必须匹配本插件声明的路由,再以同源 - 请求经服务端转发,结果用消息传回(二进制响应以 Blob 传回)。 + 加载后把当前 Scope、语言和主题发给页面;之后只接受来自该 iframe 的请求消息,路径必须匹配本插件声明的路由,或者是本插件 + family 的通用 Artifact 接口,再以同源请求经服务端转发,结果用消息传回(二进制响应以 Blob 传回)。 - **服务端转发**:`/dashboard/plugins/{name}/api/...` 是 Dashboard 的服务端路由,要求 Dashboard 会话,并要求请求的 `Sec-Fetch-Site` 为 `same-origin`(缺失时校验 `Origin` 与 Server 一致)。它沿用 Dashboard 现有的做法,以会话对应的身份 调用 `/v1/plugins/{name}/api/...`。 +- **通用 Artifact 接口的转发**:`/dashboard/plugins/{name}/artifacts/{scope_id}/...` 是另一条 Dashboard 服务端路由,会话和 + 同源要求与上一条相同。它以会话对应的身份调用 `/v1/scopes/{scope_id}/artifacts/{family}/...`,其中 family 由 Dashboard 按 + 该插件的声明填入,页面不能指定;新建(`POST /dashboard/plugins/{name}/artifacts/{scope_id}`)转成通用新建接口的插件分支, + family 同样由 Dashboard 填入。请求的 `If-Match` 和请求体原样传给通用接口,响应的状态码、`ETag`、`Location` 和响应体 + 原样返回。转发层不做授权判断,也不解释内容。没有声明 family 的插件(Source 插件)没有这条路由。 - **会话隔离**:Dashboard 的会话 cookie 是 `HttpOnly`、`SameSite=Strict`,路径为 `/dashboard`。插件页面处于不透明来源, 脚本读不到 cookie;Server 也不接受 `Origin: null` 的转发请求。 - **跳转后停止转发**:沙箱 iframe 可以把自己导航到外部站点,CSP 无法阻止。外部页面同样能向宿主页面发送 `postMessage`, 并且通过 `event.source` 校验。宿主页面因此在 iframe 第二次加载后停止转发,外部页面借不到用户会话。插件页面应实现为 单页应用;在插件页面之间跳转同样会停止转发。 -- **范围**:宿主页面只转发到本插件已声明的路由;转发后的请求仍由 core 按调用者权限检查,插件页面不能借此访问调用者无权 - 访问的 Scope。 +- **范围**:宿主页面只转发到本插件已声明的路由和本插件 family 的通用 Artifact 接口;转发后的请求仍由 core 按调用者权限 + 检查,插件页面不能借此访问调用者无权访问的 Scope 或其他 family 的 Artifact。 - **页面客户端脚本**:core 在 `/dashboard/plugins/_client.js` 提供一个小脚本,封装上述消息协议,插件页面可以直接引用。 ## 4. 执行约束 @@ -493,7 +506,7 @@ class PluginPages(BaseModel): | --- | --- | | 新增 | `/v1/plugins/{name}/api/...`:插件声明的路由 | | 新增 | `GET /v1/plugins/{name}/openapi.json` | -| 新增 | `/dashboard/plugins/{name}`、`/dashboard/plugins/{name}/ui/...`、`/dashboard/plugins/{name}/api/...`、`/dashboard/plugins/_client.js` | +| 新增 | `/dashboard/plugins/{name}`、`/dashboard/plugins/{name}/ui/...`、`/dashboard/plugins/{name}/api/...`、`/dashboard/plugins/{name}/artifacts/{scope_id}/...`、`/dashboard/plugins/_client.js` | | 新增 | 插件声明 `mcp=True` 的路由作为 MCP 工具出现在 Server 的 MCP 端点 | | 新增 | `powercontext.plugins`:`PluginApi`、`Route`、`ApiRequest`、`BinaryResponse`、`ApiError`、`Caller`、`PluginPages`;上下文的 `require`、`reads`、`writer`、`sources`、`scopes` | | 调整 | `SourcePlugin`、`ArtifactPlugin` 增加 `api`、`pages`、`upgrade` 和 `upgrade_timeout_seconds` 字段 | From db59e36fe2e465a2fb68947f9bf618e488f0f057 Mon Sep 17 00:00:00 2001 From: jasper-yl Date: Sun, 15 Nov 2026 04:15:46 -0800 Subject: [PATCH 5/6] docs(rfc): check governance state on writes after outside reads and let plugin APIs require artifact.write RFC #2549: a write to an Artifact read outside the transaction is also checked against the governance state version that was read, so a forget, restore, or merge after the read conflicts without the plugin passing a parameter. RFC #2579: ctx.require accepts artifact.write for an Artifact of the plugin's own family, for APIs that accept a request and change the Artifact later in generate. Co-Authored-By: Claude --- docs/en/rfcs/2549-plugin-interfaces.md | 7 ++++++- docs/en/rfcs/2579-plugin-reload-and-apis.md | 2 +- docs/zh/rfcs/2549-plugin-interfaces.md | 5 ++++- docs/zh/rfcs/2579-plugin-reload-and-apis.md | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/en/rfcs/2549-plugin-interfaces.md b/docs/en/rfcs/2549-plugin-interfaces.md index cf9b01a8fe..23bfaf8964 100644 --- a/docs/en/rfcs/2549-plugin-interfaces.md +++ b/docs/en/rfcs/2549-plugin-interfaces.md @@ -616,7 +616,7 @@ validation and raises immediately when a rule is violated: | Operation | Semantics | | --- | --- | -| `put(artifact_id, *, content, source_refs=(), artifact_refs=(), expected_revision=None)` | Creates revision 1 if absent; otherwise appends a revision on the current head. With `expected_revision`, a different current revision is a conflict; without it, the revision this invocation read outside the transaction is used (see 3.5), and nothing is checked if it was not read. Identical content to the current revision writes nothing and returns the current snapshot, and the supplied `source_refs` and `artifact_refs` are not recorded (see the write constraints below). `put` in user changes is the exception, see 4.1 | +| `put(artifact_id, *, content, source_refs=(), artifact_refs=(), expected_revision=None)` | Creates revision 1 if absent; otherwise appends a revision on the current head. With `expected_revision`, a different current revision is a conflict; without it, the revision this invocation read outside the transaction is used (see 3.5), and nothing is checked if it was not read. An Artifact read outside the transaction is also checked against the governance state version that was read (see 3.5). Identical content to the current revision writes nothing and returns the current snapshot, and the supplied `source_refs` and `artifact_refs` are not recorded (see the write constraints below). `put` in user changes is the exception, see 4.1 | | `revert(artifact_id, *, to_revision)` | Appends a new revision with a historical revision's content and records `restored_from_revision`; a forgotten or merge-frozen target is restored as well. Returns an `ArtifactChange`: the target's new snapshot plus exact references to the other Artifacts restored and retired with it | | `set_lifecycle(artifact_id, state, *, replacement_artifact_id=None)` | `deprecated` forgets, `active` restores, and `retired` is irreversible. Restoring uses shared restoration: it records a new revision with the same content, and an input frozen by a merge undoes that merge as one group. Forgetting and retiring append no revision. Returns the same as `revert`, so the plugin can update entries in its own index affected by the cascade | | `merge(inputs, *, into, content, source_refs=(), artifact_refs=())` | Follows the shared merge method ([RFC #1859](1859_artifact_merge.md)): takes the current revisions of `inputs`, creates `into`, records the merge, and freezes the inputs. `into` must be a new ID; when the same inputs are merged again after an undo, the plugin should include the input revisions in `stable_id` to avoid colliding with the retired result | @@ -704,6 +704,11 @@ class ArtifactReads(Protocol): transaction as the expected value. If a user changed the Artifact after the read, the write conflicts, the invocation rolls back, and it is rescheduled. This matches built-in Atomic Memory, which checks before committing whether the memories it read have changed, so a plugin write based on old content never silently overwrites a user change. + Forget, restore, and merge do not always change the revision, so core also checks the governance state version + (`governance_generation`) read outside the transaction: if the Artifact was forgotten, restored, or merged after the + read, the write conflicts in the same way. Core does this check automatically and the plugin passes no parameter; it + also applies when `expected_revision` is given. Changing tags does not change the governance state version and causes + no conflict. - **Plugin-owned storage**: the plugin's indexes and other storage (the dedicated storage core allocates, or any database, object store, or vector store the plugin connects to itself) are outside core's transaction. The plugin writes and commits owned storage with its own clients; core takes no part and does not guarantee their consistency. Core's diff --git a/docs/en/rfcs/2579-plugin-reload-and-apis.md b/docs/en/rfcs/2579-plugin-reload-and-apis.md index 3b85f20951..483820ac3d 100644 --- a/docs/en/rfcs/2579-plugin-reload-and-apis.md +++ b/docs/en/rfcs/2579-plugin-reload-and-apis.md @@ -450,7 +450,7 @@ in RFC #2549). Besides the RFC #2549 context (dedicated storage, models, logger) | Capability | Description | | --- | --- | -| `ctx.require(action, scope_id=None)` | Checks whether the caller has `scope.read`, `scope.contribute` (with `scope_id`), or `server.admin`, and raises otherwise, so the API returns 403. Used in `authenticated` routes and cross-Scope operations | +| `ctx.require(action, scope_id=None, *, artifact_id=None)` | Checks whether the caller has `scope.read`, `scope.contribute` (with `scope_id`), `server.admin`, or `artifact.write` on an Artifact of this plugin's family (with `scope_id` and `artifact_id`), and raises otherwise, so the API returns 403. Used in `authenticated` routes and cross-Scope operations; `artifact.write` is for APIs that accept a request and let `generate` change an existing Artifact later: that write happens in the background with no caller identity, so the check belongs at acceptance | | `ctx.reads(scope_id)` | A read-only Artifact view of the given Scope, checked against the caller's permissions before reading; `reads(...).reads(family)` reads other families | | `ctx.writer(scope_id)` | The Artifact plugin's writer, scoped to the given Scope and the plugin's family; usable only for a Scope whose `scope.contribute` was confirmed in this request | | `ctx.sources.submit(scope_id, definition, value)` | Submits one Source of a definition this plugin provides (a Source plugin, or an Artifact plugin that declares `definitions`), with the same validation, `resolve`, and Projections as the Source write APIs, and returns a `SourceRef`; usable only for a Scope whose `scope.contribute` was confirmed in this request | diff --git a/docs/zh/rfcs/2549-plugin-interfaces.md b/docs/zh/rfcs/2549-plugin-interfaces.md index 1b495cc7a5..097a40b0de 100644 --- a/docs/zh/rfcs/2549-plugin-interfaces.md +++ b/docs/zh/rfcs/2549-plugin-interfaces.md @@ -544,7 +544,7 @@ class ArtifactTransaction(ArtifactReads): | 操作 | 语义 | | --- | --- | -| `put(artifact_id, *, content, source_refs=(), artifact_refs=(), expected_revision=None)` | 不存在则新建 revision 1;已存在则按当前 head 追加 revision。给出 `expected_revision` 时,当前 revision 不一致即冲突;不给出时,使用本次调用在事务外读到的 revision(见 3.5),没有读过则不校验。内容与当前 revision 相同时不写入,返回当前快照,本次传入的 `source_refs` 和 `artifact_refs` 不会被记录(见下方写入约束)。用户修改中的 `put` 例外,见 4.1 | +| `put(artifact_id, *, content, source_refs=(), artifact_refs=(), expected_revision=None)` | 不存在则新建 revision 1;已存在则按当前 head 追加 revision。给出 `expected_revision` 时,当前 revision 不一致即冲突;不给出时,使用本次调用在事务外读到的 revision(见 3.5),没有读过则不校验。事务外读过的 Artifact 还会按读到的治理状态版本校验(见 3.5)。内容与当前 revision 相同时不写入,返回当前快照,本次传入的 `source_refs` 和 `artifact_refs` 不会被记录(见下方写入约束)。用户修改中的 `put` 例外,见 4.1 | | `revert(artifact_id, *, to_revision)` | 以历史 revision 的内容追加新 revision,记录 `restored_from_revision`;目标已被遗忘或被合并冻结时一并恢复。返回 `ArtifactChange`:目标的新快照,以及一并恢复和退役的其他 Artifact 的精确引用 | | `set_lifecycle(artifact_id, state, *, replacement_artifact_id=None)` | `deprecated` 为遗忘,`active` 为恢复,`retired` 不可逆。恢复走共享恢复流程:记录一个内容相同的新 revision,被合并冻结的输入会撤销冻结它的合并,按组恢复。遗忘和退役不追加 revision。返回值同 `revert`,插件据此同步更新自有索引中受级联影响的条目 | | `merge(inputs, *, into, content, source_refs=(), artifact_refs=())` | 沿用公共合并方法([RFC #1859](1859_artifact_merge.md)):以 `inputs` 的当前 revision 为输入,新建 `into`,记录合并关系并冻结输入。`into` 必须是新 ID;同一组输入在撤销后再次合并时,插件应把输入 revision 纳入 `stable_id`,避免与已退役的结果撞号 | @@ -617,6 +617,9 @@ class ArtifactReads(Protocol): - **事务外读取后写入**:插件在事务外读到某个 Artifact,又在写事务块中对它 `put` 而没有给出 `expected_revision` 时,core 以事务外读到的 revision 作为期望值。读取后该 Artifact 被用户修改,写入即冲突,本次调用回滚后重新调度。这与内置 Atomic Memory 在提交前核对所读记忆是否变化的做法一致,用户修改不会被插件基于旧内容的写入静默覆盖。 + 遗忘、恢复和合并不一定改变 revision,所以 core 同时核对事务外读到的治理状态版本(`governance_generation`):读取后该 + Artifact 被遗忘、恢复或合并,写入同样冲突。这项校验由 core 自动完成,插件不需要传入参数;给出 `expected_revision` + 时也照常进行。改 tags 不改变治理状态版本,不会引起冲突。 - **插件自有存储**:插件的索引和其他存储(core 分配的专属存储,或插件自己连接的任何数据库、对象存储、向量库)不在 core 的事务中。插件用自己的客户端写入并提交自有存储,core 不参与,也不保证两者一致。core 的事务是核心数据的唯一提交点: 自有存储中的数据只有被 core 中已提交的 revision 引用后才算生效。这不需要两阶段提交,按下面的做法即可保持一致: diff --git a/docs/zh/rfcs/2579-plugin-reload-and-apis.md b/docs/zh/rfcs/2579-plugin-reload-and-apis.md index 5ba2369249..f0bc58a62b 100644 --- a/docs/zh/rfcs/2579-plugin-reload-and-apis.md +++ b/docs/zh/rfcs/2579-plugin-reload-and-apis.md @@ -384,7 +384,7 @@ RFC #2549 的上下文(专属存储、模型、日志),自定义接口调 | 能力 | 说明 | | --- | --- | -| `ctx.require(action, scope_id=None)` | 检查调用者是否具备 `scope.read`、`scope.contribute`(需要 `scope_id`)或 `server.admin`,不具备时抛出异常,接口返回 403。用于 `authenticated` 路由和跨 Scope 的操作 | +| `ctx.require(action, scope_id=None, *, artifact_id=None)` | 检查调用者是否具备 `scope.read`、`scope.contribute`(需要 `scope_id`)、`server.admin`,或对本插件 family 中某个 Artifact 的 `artifact.write`(需要 `scope_id` 和 `artifact_id`),不具备时抛出异常,接口返回 403。用于 `authenticated` 路由和跨 Scope 的操作;`artifact.write` 用于先接受请求、之后由 `generate` 修改已有 Artifact 的接口:写入发生在后台,那时没有调用者身份,所以要在接受请求时检查 | | `ctx.reads(scope_id)` | 指定 Scope 的 Artifact 只读视图,读取前按调用者权限检查;可用 `reads(...).reads(family)` 读取其他 family | | `ctx.writer(scope_id)` | Artifact 插件的写入器,范围为指定 Scope 和本插件的 family;只能用于本次请求中已确认 `scope.contribute` 的 Scope | | `ctx.sources.submit(scope_id, definition, value)` | 提交一条本插件定义的 Source(Source 插件,或声明了 `definitions` 的 Artifact 插件),执行与 Source 写入接口相同的校验、`resolve` 和 Projection,返回 `SourceRef`;只能用于本次请求中已确认 `scope.contribute` 的 Scope | From 178fe26ddd6ba3089bdc2983cc48d126846c132b Mon Sep 17 00:00:00 2001 From: jasper-yl Date: Sun, 15 Nov 2026 04:48:45 -0800 Subject: [PATCH 6/6] docs(rfc): say when the plugin storage database is created and what happens when it cannot be RFC #2549: on OceanBase and seekdb core creates the plugin's database when the plugin loads and reuses an existing one. A missing database that cannot be created, or a name over 64 characters, leaves the plugin loaded and makes ctx.storage report the reason. A tenant or instance carries one deployment. Co-Authored-By: Claude --- docs/en/rfcs/2549-plugin-interfaces.md | 8 ++++++-- docs/zh/rfcs/2549-plugin-interfaces.md | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/en/rfcs/2549-plugin-interfaces.md b/docs/en/rfcs/2549-plugin-interfaces.md index 23bfaf8964..3c8c9dcca0 100644 --- a/docs/en/rfcs/2549-plugin-interfaces.md +++ b/docs/en/rfcs/2549-plugin-interfaces.md @@ -518,8 +518,12 @@ class PluginModels(Protocol): - **Dedicated storage**: core uses Server's existing database connection settings to allocate an area for the plugin on the same backend, with no additional database login: - SQLite: `plugins/.sqlite3` in the data directory. - - OceanBase / seekdb: a database named `powercontext_plugin_` (with `-` replaced by `_`), created by core on - first use. When Server's database login cannot create databases, the deployer creates it in advance. + - OceanBase / seekdb: a database named `powercontext_plugin_` (with `-` replaced by `_`) on the same tenant + or instance, created by core when the plugin loads and reused when it exists. When Server's database login cannot + create databases, the deployer creates it in advance. If the database is missing and cannot be created, or its name + exceeds 64 characters (a plugin name longer than 44), the plugin still loads, and accessing `ctx.storage` raises an + error that states the reason. A tenant or instance carries one deployment, so the name does not identify the + deployment. - The plugin manages its own tables and migrations; core does not read, migrate, or back up this area. It is not part of core's transactions, and its consistency with core data follows 3.5. - This area belongs to the whole plugin and is not isolated by Scope. The plugin partitions its data by `scope_id` and, diff --git a/docs/zh/rfcs/2549-plugin-interfaces.md b/docs/zh/rfcs/2549-plugin-interfaces.md index 097a40b0de..ee3f90e2b5 100644 --- a/docs/zh/rfcs/2549-plugin-interfaces.md +++ b/docs/zh/rfcs/2549-plugin-interfaces.md @@ -463,8 +463,10 @@ class PluginModels(Protocol): 连接)通过 `ctx.enter_async_context` 注册,Worker 调用结束或宿主进程停止时由执行器释放。 - **专属存储**:core 使用 Server 现有的数据库连接配置,在同一个后端上为插件分配一块空间,不需要额外的数据库账号: - SQLite:数据目录下的 `plugins/<插件名>.sqlite3`。 - - OceanBase / seekdb:名为 `powercontext_plugin_<插件名>` 的库(`-` 换成 `_`),首次使用时由 core 创建。Server 的数据库 - 登录没有建库权限时,由部署者事先建好。 + - OceanBase / seekdb:同一个租户或实例上名为 `powercontext_plugin_<插件名>` 的库(`-` 换成 `_`),插件加载时由 core + 创建,已存在则直接使用。Server 的数据库登录没有建库权限时,由部署者事先建好。库不存在又无法创建,或者库名超过 64 个字符 + (插件名超过 44 个字符)时,插件照常加载,访问 `ctx.storage` 时报错并说明原因。一个租户或实例只承载一套部署, + 库名因此不区分部署。 - 表结构和迁移由插件自己管理,core 不读取、不迁移、不备份这块空间。它不在 core 的事务中,与核心数据的一致性按 3.5 处理。 - 这块空间属于整个插件,不按 Scope 隔离。插件按 `scope_id` 划分自己的数据,并在读取时自行确认数据属于本次请求的 Scope, 不能只凭调用方给出的 ID 返回数据。