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" + ] } ] diff --git a/desktop/src-tauri/src/transport/operations.json b/desktop/src-tauri/src/transport/operations.json index 822b84492c..d05a217258 100644 --- a/desktop/src-tauri/src/transport/operations.json +++ b/desktop/src-tauri/src/transport/operations.json @@ -1,5 +1,5 @@ { - "contractSha256": "32a8aebe3ac5b5eb388e03e0b0e25fc95ea232b10b94caf16323bd369cd7bf69", + "contractSha256": "bbf07c32df6c28930ea85d8cfd82af021059314a0e1d8f532cd135ea22921f12", "operations": { "get_liveness": { "method": "GET", diff --git a/desktop/ui/src/generated/api.d.ts b/desktop/ui/src/generated/api.d.ts index 7c8f0155c0..8d0baa6cf2 100644 --- a/desktop/ui/src/generated/api.d.ts +++ b/desktop/ui/src/generated/api.d.ts @@ -2368,7 +2368,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. Plugin families accept their own content unchanged; the plugin's next invocation sees the new revision. + * @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. Plugin families accept their own content unchanged; the plugin's next invocation sees the new revision. */ put: operations["replace_artifact"]; post?: never; @@ -10889,6 +10889,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 725c378c6d..dfc23be59d 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 = "32a8aebe3ac5b5eb388e03e0b0e25fc95ea232b10b94caf16323bd369cd7bf69"; +export const contractSha256 = "bbf07c32df6c28930ea85d8cfd82af021059314a0e1d8f532cd135ea22921f12"; export const operations = { "get_liveness": { "method": "GET", diff --git a/openapi/powercontext.yaml b/openapi/powercontext.yaml index 188957c6d5..6f8cf084d6 100644 --- a/openapi/powercontext.yaml +++ b/openapi/powercontext.yaml @@ -4984,6 +4984,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. @@ -5047,6 +5049,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 9c88c6b402..410f044936 100644 --- a/src/powercontext/http/_generated/operations.py +++ b/src/powercontext/http/_generated/operations.py @@ -3741,6 +3741,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 955d7aac9b..d3d8a4bfa0 100644 --- a/src/powercontext/http/_generated/schema.py +++ b/src/powercontext/http/_generated/schema.py @@ -5723,6 +5723,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 " @@ -5891,6 +5908,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())