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(scope): reject unregistered runtime partitions
  • Loading branch information
PsiACE committed Sep 2, 2026
commit 325f20d6e0c3c30c053f6f3ce95f2b6cb2a05a1f
25 changes: 11 additions & 14 deletions src/powercontext/builtin/runtime/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
RuntimeReadinessChecks,
)
from powercontext.builtin.runtime.statistics import RelationalScopedStatistics
from powercontext.builtin.scope import ScopeApplication, ScopeNotFoundError, ScopeSelection
from powercontext.builtin.scope import ScopeApplication, ScopeDescriptor, ScopeSelection
from powercontext.builtin.sources import (
ContentCapture,
ContentSource,
Expand Down Expand Up @@ -224,6 +224,7 @@ def __init__(self, code: str) -> None:
"external-skill-registry": "External Skill Registry is not configured",
"review": "Candidate Review services are not configured",
"scheduler": "Built-in Runtime scheduler is already started",
"scope": "Scope services are not configured",
"statistics": "Statistics services are not configured",
}
super().__init__(messages[code])
Expand Down Expand Up @@ -360,19 +361,12 @@ def __init__(self, runtime: BuiltinRuntime, scope_id: str) -> None:
self.scope_id = validate_scope_id(scope_id)

async def prepare(self, request: PrepareContextRequest, /) -> PreparedContext:
async with self._runtime._scope_operation(self.scope_id):
return await self._prepare(request)
async with self._runtime._scope_operation(self.scope_id) as scope:
return await self._prepare(request, scope)

async def _prepare(self, request: PrepareContextRequest, /) -> PreparedContext:
async def _prepare(self, request: PrepareContextRequest, scope: ScopeDescriptor, /) -> PreparedContext:
builder = PreparedContextBuilder()
scope_ids = [self.scope_id]
if self._runtime.scopes is not None:
try:
scope = await self._runtime.scopes.get(self.scope_id)
except ScopeNotFoundError:
pass
else:
scope_ids.extend(scope.context_references)
scope_ids = [self.scope_id, *scope.context_references]

memory_candidates: list[PreparedMemoryCandidates] = []
experience_candidates: list[PreparedExperienceCandidates] = []
Expand Down Expand Up @@ -1496,11 +1490,14 @@ async def _operation(self) -> AsyncIterator[None]:
self._lifecycle.notify_all()

@asynccontextmanager
async def _scope_operation(self, scope_id: str) -> AsyncIterator[None]:
async def _scope_operation(self, scope_id: str) -> AsyncIterator[ScopeDescriptor]:
scope = validate_scope_id(scope_id)
async with self._operation():
if self.scopes is None:
raise _RuntimeStateError("scope")
registered = await self.scopes.get(scope)
with self._scope_cache.lease(scope):
yield
yield registered

@asynccontextmanager
async def _scoped_operation(
Expand Down
59 changes: 37 additions & 22 deletions tests/builtin/review/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@
from powercontext.builtin.runtime import (
ApproveArtifactCandidateRequest,
BuiltinConfig,
BuiltinRuntime,
CaptureSource,
GenerateExperienceRequest,
GenerateSkillRequest,
ListArtifactCandidatesRequest,
SkillGenerationOrigin,
open_builtin_runtime,
)
from powercontext.builtin.scope import ScopeDraft


async def _create_scope(runtime: BuiltinRuntime, idempotency_key: str = "project") -> str:
assert runtime.scopes is not None
scope = await runtime.scopes.create(
ScopeDraft(title="Project", summary="Review generation tests", idempotency_key=idempotency_key)
)
return scope.scope_id


def _experience() -> ExperienceContent:
Expand Down Expand Up @@ -77,16 +87,17 @@ async def generate(self, value: ArtifactGenerationInput, /) -> SkillContent | No
def test_generation_without_model_fails_before_candidate_persistence() -> None:
async def scenario() -> None:
async with open_builtin_runtime(BuiltinConfig(database=SQLiteConfig())) as runtime:
captured = await runtime.sources.for_scope("project").capture(
scope_id = await _create_scope(runtime)
captured = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-1", content="bounded evidence", metadata={})
)

with pytest.raises(GenerationCapabilityUnavailableError):
await runtime.experience.for_scope("project").generate(
await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(sources=(captured.source_ref,))
)

inbox = await runtime.review.for_scope("project").list(ListArtifactCandidatesRequest())
inbox = await runtime.review.for_scope(scope_id).list(ListArtifactCandidatesRequest())
capabilities = await runtime.capabilities()
assert inbox.candidates == ()
assert capabilities.experience_generation is False
Expand All @@ -102,11 +113,12 @@ async def scenario() -> None:
BuiltinConfig(database=SQLiteConfig()),
experience_generator=generator,
) as runtime:
captured = await runtime.sources.for_scope("project").capture(
scope_id = await _create_scope(runtime)
captured = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-1", content="contract validation passed", metadata={})
)

result = await runtime.experience.for_scope("project").generate(
result = await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(
sources=(captured.source_ref,),
reason="Generate from a selected successful task.",
Expand All @@ -123,13 +135,14 @@ async def scenario() -> None:
BuiltinConfig(database=SQLiteConfig()),
experience_generator=no_op,
) as runtime:
captured = await runtime.sources.for_scope("project").capture(
scope_id = await _create_scope(runtime)
captured = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-2", content="nothing reusable", metadata={})
)
result = await runtime.experience.for_scope("project").generate(
result = await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(sources=(captured.source_ref,))
)
inbox = await runtime.review.for_scope("project").list(ListArtifactCandidatesRequest())
inbox = await runtime.review.for_scope(scope_id).list(ListArtifactCandidatesRequest())

assert result.generated is False
assert inbox.candidates == ()
Expand All @@ -144,25 +157,26 @@ async def scenario() -> None:
BuiltinConfig(database=SQLiteConfig()),
experience_generator=generator,
) as runtime:
first_source = await runtime.sources.for_scope("project").capture(
scope_id = await _create_scope(runtime)
first_source = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-1", content="contract validation passed", metadata={})
)
first_candidate = await runtime.experience.for_scope("project").generate(
first_candidate = await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(sources=(first_source.source_ref,))
)
assert first_candidate.candidate is not None
first_approval = await runtime.review.for_scope("project").approve(
first_approval = await runtime.review.for_scope(scope_id).approve(
ApproveArtifactCandidateRequest(
candidate_id=first_candidate.candidate.candidate_id,
expected_version=1,
)
)
assert first_approval.result_artifact is not None
later_source = await runtime.sources.for_scope("project").capture(
later_source = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-2", content="generation also had to run first", metadata={})
)

replacement = await runtime.experience.for_scope("project").generate(
replacement = await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(
sources=(later_source.source_ref,),
artifacts=(first_approval.result_artifact,),
Expand All @@ -174,7 +188,7 @@ async def scenario() -> None:
assert replacement.candidate.target == first_approval.result_artifact
assert generator.inputs[-1].target_evidence_id is not None
with pytest.raises(InvalidCandidateError):
await runtime.experience.for_scope("project").generate(
await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(
sources=(later_source.source_ref,),
target=first_approval.result_artifact,
Expand All @@ -194,22 +208,23 @@ async def scenario() -> None:
experience_generator=experience_generator,
skill_generator=skill_generator,
) as runtime:
captured = await runtime.sources.for_scope("project").capture(
scope_id = await _create_scope(runtime)
captured = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-1", content="contract validation passed", metadata={})
)
experience_candidate = await runtime.experience.for_scope("project").generate(
experience_candidate = await runtime.experience.for_scope(scope_id).generate(
GenerateExperienceRequest(sources=(captured.source_ref,))
)
assert experience_candidate.candidate is not None
approved = await runtime.review.for_scope("project").approve(
approved = await runtime.review.for_scope(scope_id).approve(
ApproveArtifactCandidateRequest(
candidate_id=experience_candidate.candidate.candidate_id,
expected_version=1,
)
)
assert approved.result_artifact is not None

generated = await runtime.skill.for_scope("project").generate(
generated = await runtime.skill.for_scope(scope_id).generate(
GenerateSkillRequest(
origin=SkillGenerationOrigin.EXPERIENCE,
sources=(captured.source_ref,),
Expand All @@ -223,17 +238,17 @@ async def scenario() -> None:
evidence.evidence_id.startswith("artifact:experience/")
for evidence in skill_generator.inputs[0].evidence
)
skill_approval = await runtime.review.for_scope("project").approve(
skill_approval = await runtime.review.for_scope(scope_id).approve(
ApproveArtifactCandidateRequest(
candidate_id=generated.candidate.candidate_id,
expected_version=1,
)
)
assert skill_approval.result_artifact is not None
usage = await runtime.sources.for_scope("project").capture(
usage = await runtime.sources.for_scope(scope_id).capture(
CaptureSource(source_id="task-2", content="Skill validation passed.", metadata={})
)
replacement = await runtime.skill.for_scope("project").generate(
replacement = await runtime.skill.for_scope(scope_id).generate(
GenerateSkillRequest(
origin=SkillGenerationOrigin.USAGE,
sources=(usage.source_ref,),
Expand All @@ -245,7 +260,7 @@ async def scenario() -> None:
assert replacement.candidate.target == skill_approval.result_artifact

with pytest.raises(InvalidCandidateError):
await runtime.skill.for_scope("project").generate(
await runtime.skill.for_scope(scope_id).generate(
GenerateSkillRequest(
origin=SkillGenerationOrigin.EXPERIENCE,
sources=(captured.source_ref,),
Expand Down
Loading