Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e393793
feat(scope): add durable organization and bindings
PsiACE Sep 2, 2026
a1d0fb0
feat(migration): register existing runtime scopes
PsiACE Sep 2, 2026
99e4088
feat(artifact): publish exact revisions across scopes
PsiACE Sep 2, 2026
bbd4c4a
refactor(scope): replace project reporting with selections
PsiACE Sep 2, 2026
5cce29b
feat(integrations): resolve server-owned scopes
PsiACE Sep 2, 2026
14278d2
test(scope): verify selection and plugin contracts
PsiACE Sep 2, 2026
5d5b550
docs(scope): explain server-owned organization
PsiACE Sep 2, 2026
605701b
refactor(scope): remove legacy runtime migration
PsiACE Sep 2, 2026
d8a637d
fix(scope): retry bindings without savepoints
PsiACE Sep 2, 2026
325f20d
fix(scope): reject unregistered runtime partitions
PsiACE Sep 2, 2026
f45cc69
fix(scope): serialize hierarchy mutations
PsiACE Sep 2, 2026
056dd9e
fix(codex): guard operations by scope mode
PsiACE Sep 2, 2026
5e35afd
fix(publication): reject incomplete memory copies
PsiACE Sep 2, 2026
83f5235
chore: merge master into scope runtime
PsiACE Sep 2, 2026
3daf855
fix(ci): escape plugin shell variable safely
PsiACE Sep 2, 2026
74abed5
chore: merge latest master into scope runtime
PsiACE Sep 3, 2026
015dc00
chore: merge latest master into scope runtime
PsiACE Sep 3, 2026
befc32f
chore: merge latest master into scope runtime
PsiACE Sep 3, 2026
3a14f3a
fix(runtime): preserve referenced scope recall
PsiACE Sep 3, 2026
a7e5e7b
fix(publication): make delivery atomic
PsiACE Sep 3, 2026
94b388a
docs: use registered scope identifiers
PsiACE Sep 3, 2026
e02e10d
chore: merge latest master into scope runtime
PsiACE Sep 3, 2026
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
Prev Previous commit
Next Next commit
fix(publication): reject incomplete memory copies
  • Loading branch information
PsiACE committed Sep 2, 2026
commit 5e35afde075f68f687d3f8263a48c17d619c5fa6
2 changes: 2 additions & 0 deletions openapi/powercontext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ paths:
post:
tags: [scopes]
summary: Publish one exact Artifact revision into another Scope
description: >-
Memory publication is rejected until its complete family-owned state can be created atomically in the target Scope.
operationId: publish_artifact
requestBody:
required: true
Expand Down
13 changes: 12 additions & 1 deletion src/powercontext/builtin/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ class ArtifactPublicationConflictError(PowerContextError, RuntimeError):
"""Report reuse of an idempotency key for a different publication."""


class ArtifactPublicationUnsupportedError(PowerContextError, RuntimeError):
"""Report an Artifact family that cannot yet form a complete target revision."""

def __init__(self, family: str) -> None:
self.family = family
super().__init__(f"Artifact publication is not supported for family: {family}")


class ArtifactPublicationApplication:
def __init__(
self,
Expand All @@ -103,13 +111,15 @@ async def _publish(self, request: ArtifactPublicationRequest) -> ArtifactPublica
await self._scopes.get(request.source.scope_id)
await self._scopes.get(request.target_scope_id)
async with self._database.transaction() as connection:
source = await self._artifacts.get(connection, request.source.scope_id, request.source.artifact)
if source.family == "memory":
raise ArtifactPublicationUnsupportedError(source.family)
existing = await self._find_request(connection, request.target_scope_id, request.idempotency_key)
if existing is not None:
if existing.source != request.source:
raise ArtifactPublicationConflictError(request.idempotency_key)
return existing

source = await self._artifacts.get(connection, request.source.scope_id, request.source.artifact)
content_digest = hashlib.sha256(dump_model(source.content, kind="artifact", name=source.family)).hexdigest()
target = await self._artifacts.copy_exact(
connection,
Expand Down Expand Up @@ -218,4 +228,5 @@ def _decode_publication(row: Mapping[Any, Any]) -> ArtifactPublication:
"ArtifactPublicationApplication",
"ArtifactPublicationConflictError",
"ArtifactPublicationRequest",
"ArtifactPublicationUnsupportedError",
]
4 changes: 4 additions & 0 deletions src/powercontext/http/_generated/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
"post": {
"tags": ["scopes"],
"summary": "Publish one exact Artifact revision into another Scope",
"description": "Memory publication is rejected "
"until its complete family-owned "
"state can be created atomically "
"in the target Scope.",
"operationId": "publish_artifact",
"requestBody": {
"content": {
Expand Down
8 changes: 8 additions & 0 deletions src/powercontext/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from powercontext.builtin.publication import (
ArtifactPublicationApplication,
ArtifactPublicationConflictError,
ArtifactPublicationUnsupportedError,
)
from powercontext.builtin.publication import (
ArtifactPublicationRequest as DomainArtifactPublicationRequest,
Expand Down Expand Up @@ -1544,6 +1545,13 @@ def _map_error(error: Exception) -> tuple[int, str, str, dict[str, Any] | None]:


def _map_scope_error(error: Exception) -> tuple[int, str, str, dict[str, Any] | None] | None:
if isinstance(error, ArtifactPublicationUnsupportedError):
return (
status.HTTP_422_UNPROCESSABLE_CONTENT,
"artifact_publication_unsupported",
"The Artifact family cannot be published as complete target state.",
{"family": error.family},
)
if isinstance(error, ArtifactPublicationConflictError):
return (
status.HTTP_409_CONFLICT,
Expand Down
51 changes: 50 additions & 1 deletion tests/builtin/test_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

import pytest

from powercontext.artifacts import ArtifactAddress
from powercontext.artifacts import ArtifactAddress, ArtifactRef
from powercontext.builtin.artifacts.memory import MemoryEntryInput
from powercontext.builtin.persistence.artifacts import ArtifactRepository
from powercontext.builtin.persistence.sqlite import SQLiteConfig, SQLiteProfile
from powercontext.builtin.persistence.tables import BUILTIN_TABLES
from powercontext.builtin.publication import (
ArtifactPublicationApplication,
ArtifactPublicationConflictError,
ArtifactPublicationRequest,
ArtifactPublicationUnsupportedError,
)
from powercontext.builtin.runtime import BuiltinConfig, open_builtin_contexts
from powercontext.builtin.scope import ScopeApplication, ScopeDraft
from powercontext.errors import ArtifactNotFoundError
from tests.builtin.persistence.contract import Report, ReportContent, ReportDraft


Expand Down Expand Up @@ -136,3 +140,48 @@ async def scenario() -> None:
)

asyncio.run(scenario())


def test_memory_publication_is_rejected_without_target_state() -> None:
async def scenario() -> None:
async with open_builtin_contexts(BuiltinConfig(database=SQLiteConfig())) as contexts:
source_scope = await contexts.scopes.create(
ScopeDraft(title="Source", summary="Private working state", idempotency_key="source")
)
target_scope = await contexts.scopes.create(
ScopeDraft(title="Target", summary="Accepted result", idempotency_key="target")
)
source = await contexts.get(source_scope.scope_id)
memory = await source.artifacts.memory.remember(
memory=None,
entries=(MemoryEntryInput(kind="decision", text="Keep publication state complete."),),
mode="append",
)
assert memory is not None
publications = ArtifactPublicationApplication(
contexts.database,
contexts.repositories.artifacts,
contexts.scopes,
id_factory=lambda: "pub_blocked",
)
request = ArtifactPublicationRequest(
source=ArtifactAddress(scope_id=source_scope.scope_id, artifact=memory.as_ref()),
target_scope_id=target_scope.scope_id,
idempotency_key="publish-memory",
)

for _ in range(2):
with pytest.raises(ArtifactPublicationUnsupportedError, match="family: memory") as raised:
await publications.publish(request)
assert raised.value.family == "memory"

target_address = ArtifactAddress(
scope_id=target_scope.scope_id,
artifact=ArtifactRef(family="memory", artifact_id="pub_blocked", revision=1),
)
assert await publications.get(target_address) is None
target = await contexts.get(target_scope.scope_id)
with pytest.raises(ArtifactNotFoundError):
await target.artifacts.memory.revision(target_address.artifact)

asyncio.run(scenario())
31 changes: 10 additions & 21 deletions tests/test_scope_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_scope_http_flow_rejects_stale_metadata_and_invalid_selection(tmp_path)
assert invalid.status_code == 422


def test_scope_http_flow_publishes_one_exact_artifact(tmp_path) -> None:
def test_scope_http_flow_rejects_incomplete_memory_publication(tmp_path) -> None:
app = create_server_app(
settings=ServerSettings(
database=SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'runtime.db'}"),
Expand All @@ -158,28 +158,17 @@ def test_scope_http_flow_publishes_one_exact_artifact(tmp_path) -> None:
"idempotency_key": "accepted-decision",
}

created = client.post("/v1/artifact-publications", json=request)
rejected = client.post("/v1/artifact-publications", json=request)
repeated = client.post("/v1/artifact-publications", json=request)

assert created.status_code == 201
assert repeated.status_code == 201
assert created.json() == repeated.json()
assert created.json()["source"] == request["source"]
assert created.json()["target"]["scope_id"] == target_scope_id
assert created.json()["target"]["artifact"]["revision"] == 1

conflicting = client.post(
"/v1/artifact-publications",
json={
**request,
"source": {
"scope_id": source_scope_id,
"artifact": {**memory, "revision": memory["revision"] + 1},
},
},
)
assert conflicting.status_code == 409
assert conflicting.json()["error"]["code"] == "artifact_publication_conflict"
assert rejected.status_code == 422
assert repeated.status_code == 422
assert rejected.json() == repeated.json()
assert rejected.json()["error"] == {
"code": "artifact_publication_unsupported",
"message": "The Artifact family cannot be published as complete target state.",
"details": {"family": "memory"},
}


def test_data_plane_rejects_an_unknown_scope(tmp_path) -> None:
Expand Down
Loading