Skip to content

Refresh shared Topic Memory without changing its artifact ID - #2987

Draft
xixi-box wants to merge 3 commits into
oceanbase:masterfrom
xixi-box:fix/issue-2986-07f4190-b78a8e87
Draft

xixi-box wants to merge 3 commits into
oceanbase:masterfrom
xixi-box:fix/issue-2986-07f4190-b78a8e87

Conversation

@xixi-box

@xixi-box xixi-box commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #2986

Which issue or RFC does this PR close?

Closes #2986.

Rationale for this change

The publication key was bound to an exact source revision. A newer revision of the same Topic returned HTTP 409, and readers of a shared copy could not see which source revision it represented.

What changes are included in this PR?

  • Bind each Topic Memory publication key to its source Topic and target Artifact. Commit a changed newer revision, its provenance, and its search projection together while retaining the target ID.
  • Skip older, repeated, or identical-content revisions. Keep each exact provenance record and continue using the existing database schema.
  • Update the HTTP contract, generated bindings, and English and Chinese documentation. Record Desktop compatibility for the tested Linux SQLite Server wheel.

Are there any user-facing changes?

Topic Memory publication requires scope.contribute in both Scopes. Successful publication responses report created, skipped, or replaced in X-Publication-Outcome. A published revision's details include published_from with the exact source Scope, Artifact, and revision. Other supported families retain the existing authorization and revision conflict rules.

How was this change tested?

Tests: uv run --locked pytest -v tests/e2e/test_topic_memory_generic_api.py::test_topic_publication_refresh_preserves_target_and_exact_provenance.
Result: uv run --locked pytest -q tests/e2e/test_topic_memory_generic_api.py tests/builtin/test_publication.py tests/test_access_http.py (base): 61 passed
Result: uv run --locked pytest -v tests/e2e/test_topic_memory_generic_api.py::test_topic_publication_refresh_preserves_target_and_exact_provenance (base): 1 failed with HTTP 409 artifact_publication_conflict instead of HTTP 201
Result: uv run --locked pytest -v tests/e2e/test_topic_memory_generic_api.py::test_topic_publication_refresh_preserves_target_and_exact_provenance (patched): 1 passed
Result: uv run --locked pytest -q tests/e2e/test_topic_memory_generic_api.py tests/builtin/test_publication.py tests/test_access_http.py tests/builtin/persistence/test_topic_memory.py tests/e2e/test_artifact_tags.py tests/e2e/test_owner_recovery_http.py: 166 passed
Result: uv run --locked pytest -q tests/e2e/test_topic_memory_generic_api.py::test_index_failure_rolls_back_create_replace_and_publication tests/e2e/test_access_control_regressions.py::test_topic_memory_generic_writes_and_publication_use_scope_authority: 3 passed
Result: uv run --locked pytest -q tests/e2e/test_access_control_regressions.py tests/e2e/test_runtime_server.py tests/e2e/test_portable_archive.py -k 'topic_memory_generic_writes or publication or sdk_handoff_lifecycle': 11 passed, 2 skipped for unavailable non-SQLite backends, 261 deselected
Result: uv run --locked pytest -q tests/test_mcp.py tests/e2e/test_mcp_transport.py: 18 passed
Result: uv run --locked python .powercontext/osscout/publication_archive.py: restored both publication edges and retried an older source successfully
Result: uv run --locked ty check: passed
Result: uv run --locked ruff check --no-fix $(git diff --name-only -- '*.py'): passed
Regression coverage: tests/e2e/test_topic_memory_generic_api.py.

AI usage statement

OpenAI Codex (GPT-6) implemented the change, ran the checks, and authored this description.

Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
@hireview001 hireview001 added module:core Core: PR changes under src/ module:desktop Primary module: desktop app and platform integration labels Dec 2, 2026
@hireview001

Copy link
Copy Markdown
Collaborator

The affected modules are Core, Desktop. @hidb4ai, please coordinate follow-up. Core: @hidb4ai @frf12 @Fengzdadi @beatenevo; Desktop: @PsiACE @knqiufan. Please coordinate the review of the affected changes.

Record an existing SQLite publication opened and refreshed by the candidate without changing its target identity, history, or retry semantics. Keep the required installed-release acceptance matrix unchanged.

Assisted-by: OpenAI Codex
@xixi-box
xixi-box requested a review from beatenevo as a code owner December 3, 2026 02:36

xixi-box commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

I followed up on the upgrade preflight in dd5e427. I created a Topic Memory publication with the base Server source (07f4190), closed it, then opened the same SQLite database with the candidate and refreshed using the original key. The target ID stayed the same, both exact provenance edges remained readable after restart, delayed and same-content retries were skipped, and search returned only the current content.

The local upgrade policy check and 166 focused tests passed. I also repeated the old-database check against GitHub’s current merge preview. The commit records the compatibility rationale and digest without changing the required upgrade matrix. The installed-release upgrade cases, including native seekDB and OceanBase, still need to run in CI.

CI update: the upgrade preflight passed. The Dify job stopped at the generated-contract check, so I regenerated the two tool declarations and the bundled contract in dc58864. Those are the only files changed. The generator check, 85 Dify plugin tests and 3 Dify HTTP/SQLite tests passed locally on the same tree as GitHub’s new merge preview. The hosted Dify run and installed-release upgrade results are still pending.

@xixi-box
xixi-box requested a review from yihong0618 as a code owner December 3, 2026 03:33

@Fengzdadi Fengzdadi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed description and the regression tests. I reviewed dc58864 against current master (9e40f89); the branch merges cleanly. I ran the checks below on dd5e427; dc58864 changes only the three regenerated Dify files.

One blocking issue, in _publish_artifact_access (inline): a user with scope.contribute in both Scopes can replace the head of an existing shared Topic through a refresh, while the same user still gets 403 for a direct replace.

What I checked:

  • Refresh works as described on the merge result. A newer, changed source revision appends a target revision under the same Artifact ID with X-Publication-Outcome: replaced, retries of older and already published source revisions return skipped, and each published target revision's published_from names its exact source revision.
  • A refreshed publication survives a portable archive round trip. After both Scopes are restored into an empty database, both target revisions keep published_from, retries of source revisions 1 and 2 return skipped, and a new source revision refreshes the restored copy and its search index.
  • The leading-space internal keys can't collide with client keys, because ArtifactPublicationRequest rejects untrimmed idempotency_key values.
  • forget and GET …/governance return 422 for Topic Memory, so a refresh can't target a forgotten copy.
  • scripts/generate_api.py --check, scripts/generate_js_operations.py --check and scripts/schema_release.py check --base-ref against current master pass. The related publication, access, Topic Memory, archive, MCP, contract, Desktop and dashboard suites pass on the merge result and on master.
  • The new Desktop record matches this head's contract (ddf2bd3e…) and covers every operation in operations.json.
  • The Dify files in dc58864 match a local run of integrations/dify/generate_contract.py, and its --check passes on the merge result.

CI: on dc58864 it had only started when I checked. On dd5e427 the unit and e2e jobs passed, dify-tools failed at the contract check that dc58864 fixes, and the remaining jobs were cancelled after the new push.

Design notes (non-blocking):

  • response_model_exclude_unset=True also changes created_by on rollback revisions (inline).
  • Removing the Scope-row UPDATE at the start of _publish leaves the publication, Topic Memory and access tests passing. The extended race test pauses the older request in embed(), before its write transaction starts, so it exercises the recheck but not this lock, which the comment says serializes publications across server processes. A test that holds one request inside its write transaction would protect it.
  • The new Desktop record's serverCommit is working-tree-sha256:1a98d826…. Nothing in the repository computes that digest, and rebuilt_profile() requires a 40-hex commit, so the wheel d7915689… can't be traced to source. #2246 added three records like this, so it follows precedent; qualifying from a pushed commit, or adding the build command and version string to the PR description, would make it checkable.
  • README: the new bullet ends its bold title with a period (。 in the Chinese and Japanese files), while its neighbors end theirs with a colon (:).

Comment on lines +7033 to +7034
(AccessAction.SCOPE_CONTRIBUTE, ResourceRef.scope(_mapping_text(source, "scope_id"))),
(AccessAction.SCOPE_CONTRIBUTE, ResourceRef.scope(_nested_request_value(payload, "target_scope_id"))),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lowers Topic Memory publication from scope.admin to scope.contribute in both Scopes. Combined with refresh, a user with scope.contribute in both Scopes can now change an existing shared Topic in the target, which RFC 1614 reserves for administrators: §7 keeps "Replace and replace tags" at scope.admin, and §13 says "Scope administration governs changes to existing shared knowledge".

I checked this on the merge result with one user who has scope.contributor in both Scopes:

  1. An administrator publishes source revision 1 to the target with key K, then edits the target copy (target revision 2).
  2. The contributor's PUT on the target Topic returns 403.
  3. After the source moves to revision 2, the contributor posts the publication with key K and source revision 2. It returns 201 with X-Publication-Outcome: replaced, and the target head becomes revision 3 with the source content, replacing the administrator's edit.

On master, the contributor gets 403 for both a first publication and the refresh. With SCOPE_ADMIN restored on these two lines, the only failure in the access, publication and Topic Memory suites is test_topic_memory_generic_writes_and_publication_use_scope_authority, whose grants this PR lowered to scope.contributor. So the refresh feature doesn't depend on the lower permission.

Please keep scope.admin in both Scopes for Topic Memory publication here, and revert the RFC, OpenAPI description, docs and access test to match. #2986 asks for scope.contribute, but RFC 1614 records the opposite decision with a rationale. Lowering it belongs in an RFC 1614 change that also decides which rule a refresh follows: a first publication resembles Create (scope.contribute), while a refresh resembles Replace (scope.admin).

Whichever rule stays, please document that a refresh replaces edits made to the copy in the target Scope. _find_request deliberately reads the latest publication "even if the target has since received a local edit", and neither topic-memory.md mentions it.

Comment on lines +1690 to +1691
_add_route(app, GET_ARTIFACT_REVISION, get_artifact_revision, response_model_exclude_unset=True)
_add_route(app, GET_ARTIFACT, get_artifact, response_model_exclude_unset=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design note (non-blocking): response_model_exclude_unset=True affects more than published_from. _transport_actor builds AccessPrincipal(type=…, id=…) without description, so for a Profile rollback revision these two routes now return created_by as {"type": "user", "id": "…"}, while GET …/revisions still returns "description": null for the same revision. Master returns "description": null on all three. Passing description=None in _transport_actor makes the three routes match again; I checked that change against the same rollback.

@Fengzdadi

Copy link
Copy Markdown
Collaborator

This feature hasn't been approved yet, so I'll convert the PR into a draft.

@Fengzdadi
Fengzdadi marked this pull request as draft December 3, 2026 04:05
@Fengzdadi

Copy link
Copy Markdown
Collaborator

A follow-up to my review, with two points for when this moves forward.

  1. beatenevo's comment on #2986 lists the decisions this change needs before implementation:

    • what the publication key means and when it still returns 409, including the UNIQUE(target_scope_id, idempotency_key) constraint and the migration and archive questions;
    • whether the target stays an independent copy that the target Scope can edit;
    • separate authorization rules for a first publication and a refresh;
    • how SDK and CLI users see the outcome, since the Python client doesn't expose X-Publication-Outcome;
    • acceptance criteria.

    Of these, my review touched only the authorization rule and the overwrite of target-side edits. I'd settle the rest on the issue first, then align this PR with the result.

  2. I confirmed the admin-only case from point 3 of that comment. On the merge result with current master, a principal that holds only the scope.admin role in both Scopes gets 403 when it publishes a Topic, while master returns 201 for the same request. Its PUT replace of the source Topic returns 200 on both. ROLE_ACTIONS maps the scope.admin role to the scope.admin action alone, so after this change an administrator also needs scope.contribute in both Scopes to publish a Topic. Keeping scope.admin, as my review asks, avoids that.

    To reproduce: grant one principal scope.admin in two Scopes, as _grant in tests/e2e/test_access_control_regressions.py does, create a Topic in the first, and POST /v1/artifact-publications to the second as that principal.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:core Core: PR changes under src/ module:desktop Primary module: desktop app and platform integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(topic-memory): refresh cross-scope publications and expose source provenance

3 participants