feat: implement scope organization runtime for RFC #1345 - #1401
Conversation
There was a problem hiding this comment.
license-eye has checked 978 files.
| Valid | Invalid | Ignored | Fixed |
|---|---|---|---|
| 704 | 21 | 253 | 0 |
Click to see the invalid file list
- integrations/codex/plugins/powercontext/hooks/bind_tools.py
- integrations/codex/plugins/powercontext/hooks/session_binding.py
- integrations/codex/plugins/powercontext/scripts/scope_binding.py
- src/powercontext/builtin/handoff_report/init.py
- src/powercontext/builtin/handoff_report/adapters.py
- src/powercontext/builtin/handoff_report/canonical.py
- src/powercontext/builtin/handoff_report/errors.py
- src/powercontext/builtin/handoff_report/protocols.py
- src/powercontext/builtin/handoff_report/rendering.py
- src/powercontext/builtin/scope/init.py
- src/powercontext/builtin/scope/application.py
- src/powercontext/builtin/scope/errors.py
- src/powercontext/builtin/scope/models.py
- src/powercontext/builtin/scope/repository.py
- src/powercontext/server/static/handoff-report.js
- src/powercontext/server/static/scope-selection.js
- src/powercontext/server/templates/pages/handoff_report.html
- tests/builtin/test_scope_application.py
- tests/codex_plugin/test_scope_binding.py
- tests/test_handoff_report.py
- tests/test_scope_api.py
Use this command to fix any missing license headers
```bash
docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix
</details>
POWERCONTEXT: AGENT <-> SCOPE INTERACTION MAPA Scope is server-owned. Agent, session, workspace, repository, SCENARIO 1: NEW AGENT SESSIONFirst prompt: SCENARIO 2: RESUME OR REUSE AN EXISTING SCOPEResume the same session: Start a new session with a workspace binding: Explicitly reuse or switch to Scope Y: Next request uses Scope Y: SCENARIO 3: CREATE A NEW ISOLATED SCOPEExplicit switch: SCENARIO 4: MULTIPLE AGENTSShare all state: Both sessions are bound separately to Scope X. Shared inside Scope X:
Isolate independently continuable work: Create children: Parent means organization only. It does not inherit or share data. SCENARIO 5: READ FROM OR DELIVER ACROSS SCOPESDirect Context Reference: Deliver one accepted result: Publication copies only the selected Artifact revision. KEY RULES
|
907b730 to
605701b
Compare
| try: | ||
| scope = await self._runtime.scopes.get(self.scope_id) | ||
| except ScopeNotFoundError: | ||
| pass |
There was a problem hiding this comment.
Swallowing ScopeNotFoundError makes an unregistered Scope behave like a valid legacy partition. On this head, capturing a Source under project:orphan succeeded, but list_scopes and an all selection contained only the default Scope, leaving the durable data invisible to Statistics, Dashboard, and Handoff Report. Please validate every current-scope data-plane operation through ScopeApplication (with an explicit migration path for legacy partitions) instead of continuing after this exception.
| _allow(dict(tool_input)) | ||
| return 0 | ||
| if operation not in _SCOPE_BOUND_OPERATIONS: | ||
| return 0 |
There was a problem hiding this comment.
This pass-through leaves 14 OpenAPI operations marked x-powercontext-scope-mode: current outside the binding guard, including prepare_context, flush_memory, and prepare_handoff. A prepare_context PreToolUse payload with scope_id: "agent-selected" produces no hook output, so the model-supplied Scope is neither replaced nor denied. Please derive or validate this set against the generated OpenAPI metadata and add a contract test that every current operation is guarded.
| target_scope_id, | ||
| artifact_type, | ||
| ref, | ||
| source.content, |
There was a problem hiding this comment.
Copying only source.content is insufficient for the Memory family. Publishing an exact Memory revision on this head returned a new memory/pub_*@1, but reading an entry through that target citation raised ArtifactNotFoundError, and the target Scope still had no current Memory. The entry versions/heads and target head integration were not copied. Please make Memory publication family-aware and atomic, or reject it until the complete target state can be created.
| self._database = database | ||
| self._repository = ScopeRepository() if repository is None else repository | ||
| self._id_factory = generate_scope_id if id_factory is None else id_factory | ||
| self._write_lock = asyncio.Lock() |
There was a problem hiding this comment.
This lock only serializes writes within one ScopeApplication instance. With two server instances sharing OceanBase, concurrent A.parent=B and B.parent=A updates can both validate the old graph and commit different rows; the FK and per-row version checks do not detect the resulting cycle. Please serialize relationship mutations at the database level (or use a retryable serializable/locked ancestor check) and cover this race with two application instances.
Which issue or RFC does this PR close?
Implements the runtime design in #1345.
Rationale for this change
Scope is the durable boundary for memory ownership, isolation, sharing, and reporting. The runtime and Agent integrations need to use the same server-owned Scope model instead of Project, Workstream, or client-generated Scope identifiers.
What changes are included in this PR?
Are there any user-facing changes?
Yes. This is a breaking change:
How was this change tested?
make checkmake testmake contract-testmake docs-testmake harness-checkAI usage statement
OpenAI Codex was used for code analysis, implementation, tests, and documentation editing.