Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions desktop/src-tauri/src/connections/compatibility.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
2 changes: 1 addition & 1 deletion desktop/src-tauri/src/transport/operations.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"contractSha256": "32a8aebe3ac5b5eb388e03e0b0e25fc95ea232b10b94caf16323bd369cd7bf69",
"contractSha256": "bbf07c32df6c28930ea85d8cfd82af021059314a0e1d8f532cd135ea22921f12",
"operations": {
"get_liveness": {
"method": "GET",
Expand Down
3 changes: 2 additions & 1 deletion desktop/ui/src/generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion desktop/ui/src/generated/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions openapi/powercontext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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":
Expand Down
1 change: 1 addition & 0 deletions src/powercontext/http/_generated/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
18 changes: 18 additions & 0 deletions src/powercontext/http/_generated/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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"},
Expand Down
89 changes: 89 additions & 0 deletions tests/e2e/test_atomic_memory_replace_conflict.py
Original file line number Diff line number Diff line change
@@ -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())