From 8dc98e49b50e807489e01e973b34a0f059b4c9c5 Mon Sep 17 00:00:00 2001 From: frf12 Date: Mon, 9 Nov 2026 12:05:16 +0800 Subject: [PATCH 1/3] fix(api): declare 409 for artifact replacement --- .../src-tauri/src/transport/operations.json | 2 +- desktop/ui/src/generated/api.d.ts | 3 +- desktop/ui/src/generated/operations.ts | 2 +- openapi/powercontext.yaml | 4 + .../http/_generated/operations.py | 1 + src/powercontext/http/_generated/schema.py | 18 ++++ .../test_atomic_memory_replace_conflict.py | 89 +++++++++++++++++++ 7 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/test_atomic_memory_replace_conflict.py diff --git a/desktop/src-tauri/src/transport/operations.json b/desktop/src-tauri/src/transport/operations.json index 7a2f991d51..9ff9da7b81 100644 --- a/desktop/src-tauri/src/transport/operations.json +++ b/desktop/src-tauri/src/transport/operations.json @@ -1,5 +1,5 @@ { - "contractSha256": "3ea9f0661702254563e72d2291469b84a961730f572a32467f15458e7a979650", + "contractSha256": "ad2a39e2dd633c373dc8cd24af22a8923bcbda1c84fc3825ba21349f0496b878", "operations": { "get_liveness": { "method": "GET", diff --git a/desktop/ui/src/generated/api.d.ts b/desktop/ui/src/generated/api.d.ts index 888efc0493..6775f904af 100644 --- a/desktop/ui/src/generated/api.d.ts +++ b/desktop/ui/src/generated/api.d.ts @@ -2140,7 +2140,7 @@ export interface paths { get: operations["get_artifact"]; /** * Replace the current Artifact head - * @description Commit a complete next revision when If-Match identifies the current head. Replacing a Prompt requires current scope.admin authority, including switching to Auto and restoring an earlier revision. Artifact ownership does not authorize Prompt replacement after Scope role revocation. Topic Memory replacement also requires scope.admin and preserves independently versioned tags. Complete title, summary, and detail text replaces the head without semantic generation. Profile replacement uses the same conditional write. To roll back Profile, Prompt, Experience, Skill, Handoff, or Topic Memory, set restored_from_revision and reason. The server checks that the submitted canonical content matches that revision and differs from the current head, then commits a new revision. Atomic Memory replacement rejects both fields; restore Atomic Memory through its restoration flow. + * @description Commit a complete next revision when If-Match identifies the current head. Replacing merged or retired Atomic Memory returns 409 invalid_memory_state even when If-Match matches the current content revision. Replacing a Prompt requires current scope.admin authority, including switching to Auto and restoring an earlier revision. Artifact ownership does not authorize Prompt replacement after Scope role revocation. Topic Memory replacement also requires scope.admin and preserves independently versioned tags. Complete title, summary, and detail text replaces the head without semantic generation. Profile replacement uses the same conditional write. To roll back Profile, Prompt, Experience, Skill, Handoff, or Topic Memory, set restored_from_revision and reason. The server checks that the submitted canonical content matches that revision and differs from the current head, then commits a new revision. Atomic Memory replacement rejects both fields; restore Atomic Memory through its restoration flow. */ put: operations["replace_artifact"]; post?: never; @@ -10194,6 +10194,7 @@ export interface operations { 401: components["responses"]["Unauthorized"]; 403: components["responses"]["Forbidden"]; 404: components["responses"]["NotFound"]; + 409: components["responses"]["Conflict"]; 412: components["responses"]["PreconditionFailed"]; 422: components["responses"]["InvalidRequest"]; 428: components["responses"]["PreconditionRequired"]; diff --git a/desktop/ui/src/generated/operations.ts b/desktop/ui/src/generated/operations.ts index c34bccb535..7374618443 100644 --- a/desktop/ui/src/generated/operations.ts +++ b/desktop/ui/src/generated/operations.ts @@ -15,7 +15,7 @@ */ // Generated from openapi/powercontext.yaml. Do not edit. -export const contractSha256 = "3ea9f0661702254563e72d2291469b84a961730f572a32467f15458e7a979650"; +export const contractSha256 = "ad2a39e2dd633c373dc8cd24af22a8923bcbda1c84fc3825ba21349f0496b878"; export const operations = { "get_liveness": { "method": "GET", diff --git a/openapi/powercontext.yaml b/openapi/powercontext.yaml index d79b18c7f7..3c98beda2a 100644 --- a/openapi/powercontext.yaml +++ b/openapi/powercontext.yaml @@ -4532,6 +4532,8 @@ paths: summary: Replace the current Artifact head description: >- Commit a complete next revision when If-Match identifies the current head. + Replacing merged or retired Atomic Memory returns 409 invalid_memory_state even when If-Match + matches the current content revision. Replacing a Prompt requires current scope.admin authority, including switching to Auto and restoring an earlier revision. Artifact ownership does not authorize Prompt replacement after Scope role revocation. Topic Memory replacement also requires scope.admin and preserves independently versioned tags. @@ -4596,6 +4598,8 @@ paths: $ref: "#/components/responses/Forbidden" "404": $ref: "#/components/responses/NotFound" + "409": + $ref: "#/components/responses/Conflict" "412": $ref: "#/components/responses/PreconditionFailed" "422": diff --git a/src/powercontext/http/_generated/operations.py b/src/powercontext/http/_generated/operations.py index 110adef7a9..4ca531b492 100644 --- a/src/powercontext/http/_generated/operations.py +++ b/src/powercontext/http/_generated/operations.py @@ -3407,6 +3407,7 @@ class AccessRequirement(BaseModel): 401: {"$ref": "#/components/responses/Unauthorized"}, 403: {"$ref": "#/components/responses/Forbidden"}, 404: {"$ref": "#/components/responses/NotFound"}, + 409: {"$ref": "#/components/responses/Conflict"}, 412: {"$ref": "#/components/responses/PreconditionFailed"}, 422: {"$ref": "#/components/responses/InvalidRequest"}, 428: {"$ref": "#/components/responses/PreconditionRequired"}, diff --git a/src/powercontext/http/_generated/schema.py b/src/powercontext/http/_generated/schema.py index e81ac532ee..082a207259 100644 --- a/src/powercontext/http/_generated/schema.py +++ b/src/powercontext/http/_generated/schema.py @@ -4854,6 +4854,23 @@ "current " "head. " "Replacing " + "merged " + "or " + "retired " + "Atomic " + "Memory " + "returns " + "409 " + "invalid_memory_state " + "even " + "when " + "If-Match " + "matches " + "the " + "current " + "content " + "revision. " + "Replacing " "a " "Prompt " "requires " @@ -5019,6 +5036,7 @@ "401": {"$ref": "#/components/responses/Unauthorized"}, "403": {"$ref": "#/components/responses/Forbidden"}, "404": {"$ref": "#/components/responses/NotFound"}, + "409": {"$ref": "#/components/responses/Conflict"}, "412": {"$ref": "#/components/responses/PreconditionFailed"}, "422": {"$ref": "#/components/responses/InvalidRequest"}, "428": {"$ref": "#/components/responses/PreconditionRequired"}, diff --git a/tests/e2e/test_atomic_memory_replace_conflict.py b/tests/e2e/test_atomic_memory_replace_conflict.py new file mode 100644 index 0000000000..2023a4bad6 --- /dev/null +++ b/tests/e2e/test_atomic_memory_replace_conflict.py @@ -0,0 +1,89 @@ +# Copyright (c) 2026 OceanBase. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import annotations + +import asyncio +from pathlib import Path + +import httpx + +from powercontext.builtin.persistence.sqlite import SQLiteConfig +from powercontext.client import PowerContextClient +from powercontext.http import ( + AtomicMemoryInput, + AtomicMemoryWriteContent, + MergeAtomicMemoryRequest, + RememberMemoryRequest, +) +from powercontext.http._generated.operations import REPLACE_ARTIFACT +from powercontext.server.factory import create_server_app +from powercontext.server.settings import McpConfig, ServerSettings + + +def test_merged_atomic_memory_replace_returns_documented_conflict(tmp_path: Path) -> None: + app = create_server_app( + settings=ServerSettings( + database=SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'merge.db'}"), mcp=McpConfig(enabled=False) + ) + ) + + async def scenario() -> None: + async with ( + app.router.lifespan_context(app), + httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://testserver") as transport, + ): + client = PowerContextClient("http://testserver", http_client=transport, trust_transport_security=True) + scope_id = (await client.get_default_scope()).scope_id + inputs = [] + for text in ("Use strict transport models.", "Validate transport input."): + remembered = await client.remember_memory( + RememberMemoryRequest(scope_id=scope_id, kind="rule", text=text) + ) + record = remembered.records[0] + inputs.append(AtomicMemoryInput(artifact=record.artifact, state_version=record.state_version)) + original = inputs[0].artifact + path = f"/v1/scopes/{scope_id}/artifacts/atomic-memory/{original.artifact_id}" + head = await transport.get(path) + assert head.status_code == 200 + + merged = await client.merge_atomic_memories( + MergeAtomicMemoryRequest( + scope_id=scope_id, + inputs=inputs, + content=AtomicMemoryWriteContent(kind="rule", text="Validate input with strict transport models."), + ) + ) + successor = next(record for record in merged.records if record.state == "active") + successor_path = f"/v1/scopes/{scope_id}/artifacts/atomic-memory/{successor.artifact.artifact_id}" + successor_head = await transport.get(successor_path) + merged_head = await transport.get(path) + assert merged_head.headers["ETag"] == head.headers["ETag"] + + response = await transport.put( + path, + headers={"If-Match": head.headers["ETag"]}, + json={"content": {"kind": "rule", "text": "Edit the original memory."}}, + ) + assert response.status_code == 409 + assert response.json()["error"]["code"] == "invalid_memory_state" + assert (await transport.get(path)).json() == head.json() + assert (await transport.get(successor_path)).json() == successor_head.json() + + contract_response = await transport.get("/openapi.json") + assert contract_response.status_code == 200 + operation = contract_response.json()["paths"][REPLACE_ARTIFACT.path]["put"] + assert operation["responses"].get(str(response.status_code)) == {"$ref": "#/components/responses/Conflict"} + + asyncio.run(scenario()) From 87d7b5190c8216548b9c96d8203980c874f9996d Mon Sep 17 00:00:00 2001 From: frf12 Date: Mon, 9 Nov 2026 12:10:53 +0800 Subject: [PATCH 2/3] test(desktop): qualify artifact conflict contract --- desktop/VALIDATION.md | 35 +++++++++++++++++++ .../src/connections/compatibility.json | 22 ++++++++++++ 2 files changed, 57 insertions(+) diff --git a/desktop/VALIDATION.md b/desktop/VALIDATION.md index 0e41515ebd..6049ee85c5 100644 --- a/desktop/VALIDATION.md +++ b/desktop/VALIDATION.md @@ -2630,3 +2630,38 @@ uv run --no-sync python desktop/tests/real_server.py \ --product-qualification sqlite-source-plugins-c00dbf14-v1 \ --wheel desktop/.artifacts/source-framework-upgrade/powercontext-0.1.dev1509+gc00dbf145-py3-none-any.whl ``` + +## Artifact replacement conflict protocol qualification + +`sqlite-artifact-conflict-8dc98e49-v1` qualifies all thirteen Desktop protocol operations against +Server source `8dc98e49b50e807489e01e973b34a0f059b4c9c5`, whose OpenAPI contract declares the +existing `409 Conflict` response for Artifact replacement. + +- Normalized OpenAPI SHA-256: `ad2a39e2dd633c373dc8cd24af22a8923bcbda1c84fc3825ba21349f0496b878`. +- Wheel: `powercontext-1.5.1.dev220+g8dc98e49b-py3-none-any.whl`. +- Wheel SHA-256: `b55cb9e5fc48f81774113e5c36c08c6130ecfe593837defbca977a79db19f8e8`. +- Native debug probe SHA-256: `efd20544e7e393f3fe94b90c9b0ed8d80677fbe712b518361c16af248bda79ea`. + +All 749 packaged runtime files match the recorded Git source after CRLF normalization, with no +missing or extra runtime files. On 2026-11-09, macOS 26.2 ARM64, Python 3.12.15 and Rust 1.95.0 +passed anonymous loopback, static Bearer, HTTPS with explicit CA/base path, and enforced Provider +modes through the ordinary product ConnectionManager. The probe was built with the product +Cargo lock, without `ci-fixtures`, and with this bundled qualification record. + +The unchanged `desktop/tests/real_server.py` exercised discovery, Scope selection, statistics, +Memory save/search/revision reads and committed writes with lost responses without replay. +The Provider mode also verified Principal changes, same-identity revocation, scoped authorization +and 51 same-title Scopes. The report identifies `bundled-product` qualification in all four +successful cases. The wheel, source verification, build log and report are retained under ignored +`desktop/.artifacts/artifact-conflict/`. This qualifies the observed local SQLite protocol; +installed WebView, native credential persistence, other operating systems and release acceptance +remain outside this run. + +Reproduce against the recorded artifact: + +```sh +cargo build --locked --manifest-path desktop/src-tauri/Cargo.toml --example server_probe +uv run --no-sync python desktop/tests/real_server.py \ + --product-qualification sqlite-artifact-conflict-8dc98e49-v1 \ + --wheel desktop/.artifacts/artifact-conflict/powercontext-1.5.1.dev220+g8dc98e49b-py3-none-any.whl +``` diff --git a/desktop/src-tauri/src/connections/compatibility.json b/desktop/src-tauri/src/connections/compatibility.json index f1810c88f9..46c89dc9e3 100644 --- a/desktop/src-tauri/src/connections/compatibility.json +++ b/desktop/src-tauri/src/connections/compatibility.json @@ -1246,5 +1246,27 @@ "search_memory" ], "evidence": "desktop/VALIDATION.md#server-c00dbf14-source-plugin-protocol-qualification" + }, + { + "id": "sqlite-artifact-conflict-8dc98e49-v1", + "serverCommit": "8dc98e49b50e807489e01e973b34a0f059b4c9c5", + "contractSha256": "ad2a39e2dd633c373dc8cd24af22a8923bcbda1c84fc3825ba21349f0496b878", + "artifactSha256": "b55cb9e5fc48f81774113e5c36c08c6130ecfe593837defbca977a79db19f8e8", + "operations": [ + "get_access_principal", + "get_artifact_revision", + "get_capabilities", + "get_connection_identity", + "get_default_scope", + "get_liveness", + "get_readiness", + "get_scope", + "get_server_info", + "get_stats", + "list_scopes", + "remember_memory", + "search_memory" + ], + "evidence": "desktop/VALIDATION.md#artifact-replacement-conflict-protocol-qualification" } ] From d102ecda0969e55566db57e4cb5bc515024dbb92 Mon Sep 17 00:00:00 2001 From: frf12 Date: Thu, 3 Dec 2026 01:09:16 +0800 Subject: [PATCH 3/3] test(desktop): qualify refreshed artifact conflict contract --- .../src/connections/compatibility.json | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/desktop/src-tauri/src/connections/compatibility.json b/desktop/src-tauri/src/connections/compatibility.json index ac0e128811..86d49cc384 100644 --- a/desktop/src-tauri/src/connections/compatibility.json +++ b/desktop/src-tauri/src/connections/compatibility.json @@ -2001,5 +2001,26 @@ "remember_memory", "search_memory" ] + }, + { + "id": "sqlite-artifact-conflict-a9a4605a-v1", + "serverCommit": "a9a4605acca26e6c92b920744026472846dac664", + "contractSha256": "bbf07c32df6c28930ea85d8cfd82af021059314a0e1d8f532cd135ea22921f12", + "artifactSha256": "ab5e787600205f18ac610de025afa988df24b0f106f0d03b39a9c37a6a224a24", + "operations": [ + "get_access_principal", + "get_artifact_revision", + "get_capabilities", + "get_connection_identity", + "get_default_scope", + "get_liveness", + "get_readiness", + "get_scope", + "get_server_info", + "get_stats", + "list_scopes", + "remember_memory", + "search_memory" + ] } ]