Skip to content

Fixes #34394: Allow draft conflict review - #34956

Merged
pmbrull merged 10 commits into
mainfrom
pmbrull/context-memory-conflict-drafts
Oct 9, 2026
Merged

pmbrull merged 10 commits into
mainfrom
pmbrull/context-memory-conflict-drafts

Conversation

@pmbrull

@pmbrull pmbrull commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #34394

Allow conflicting Unprocessed memories to enter Draft review, and allow a person to reject a Draft. Preserve an existing review reason when entering Draft; leaving Draft clears an unchanged stale reason. This lets Collate remove assessed conflicts from its reconciliation queue without changing Approved references or adding another status.

Companions: Collate #6965, AI Platform #1394. Existing ContextMemoryStatus values were introduced in #34785.

Type of change:

  • Bug fix

High-level design:

N/A — small lifecycle-policy fix. Extend the existing transition map with Unprocessed → Draft and Draft → Rejected. Preserve the reason on incoming Draft transitions and retain reason clearing for outgoing transitions. Approved and archived memories still cannot transition directly to Draft. No schema or migration changes.

Tests:

Use cases covered

  • An Unprocessed conflict becomes Draft with its answer and review reason preserved on PATCH and readback.
  • Human approval, rejection and explicit requeue from Draft clear an unchanged old review reason.
  • Approved references retain their existing lifecycle protections.

Unit tests

  • Added regression cases in ContextMemoryLifecycleTest and ContextMemoryStatusTransitionTest.
  • The affected runner passed 120 tests across eight classes, listed below.
  • A separate JaCoCo run passed 45 focused tests. ContextMemoryLifecycle line coverage: 94.7% (54/57). The changed ContextMemoryRepository lifecycle initialization: 100% (14/14). Whole ContextMemoryRepository coverage in this unit report is 13.2% (56/424); this report does not instrument the HTTP integration run or cover its unchanged CRUD implementation.
  • Spotless and all applicable pre-commit checks passed.

Backend integration tests

  • Added ContextMemoryLifecycleIT cases for entering Draft and for Draft → Approved, Rejected and Unprocessed.
  • The parallel Maven run succeeded: 2,044 tests total, 1,898 passed, 146 configured skips, zero failures/errors. The affected runner's selected-class aggregation differs from Maven's full total; its original report is preserved below.
  • The affected runner remains FAILED because it selects McpServiceResourceIT, an unchanged source containing only a package declaration and TODO comments, with no executable test class. This PR remains draft for that planner limitation.
  • Ran the remaining selected buckets separately: ConversationSchemaMigrationIT 2 passed; AgentSparqlResourceIT 22 passed, using the existing local openmetadata-fuseki:6.2.0 image through -DrdfContainerImage. The first RDF attempt was stopped while Docker's image build stalled, before any tests ran.
  • OSS modules built and installed from the feature branch with tests skipped after the test runs.

Local Java test run: FAILED

  • Commit: cf483d50f8ff (base origin/main) — uncommitted changes were present
  • Finished: 2026-10-08 14:47 UTC · 7.3 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-mcp (1 class), openmetadata-service (7 classes) 8 120 0 0 1.2 passed
integration mysql-elasticsearch · parallel 50 1892 0 140 6.1 FAILED
integration mysql-elasticsearch · isolated not run
integration mysql-elasticsearch · rdf not run

Selected but produced no report: McpServiceResourceIT (mysql-elasticsearch · parallel)

Tests run locally

  • unit · openmetadata-mcp (1 class), openmetadata-service (7 classes): CompanyContextToolTest (17 passed), ContextMemoryLifecycleTest (20 passed), ContextMemoryReconcilerTest (17 passed), ContextMemoryRepositoryTest (16 passed), ContextMemoryStatusTransitionTest (9 passed), EntityRepositoryEntityStatusTest (27 passed), OntologyMemoryDerivationServiceTest (7 passed), SemanticMemoryDuplicateFinderTest (7 passed)
  • integration · mysql-elasticsearch · parallel: 50 classes, 1752 tests executed (listed below)

Per-class counts come from failsafe's reports, which can credit a test to the wrong class when classes run concurrently; the step totals above are exact.

integration · mysql-elasticsearch · parallel: 50 classes

AIApplicationResourceIT (40 passed, 7 skipped), AIContextMcpIT (3 passed, 1 skipped), AIContextRestIT (82 passed, 7 skipped), AIFrameworkControlResourceIT (5 passed), AIGovernancePolicyResourceIT (5 passed, 1 skipped), AgentExecutionResourceIT (11 passed, 4 skipped), BaseEntityIT$ListEntityHistoryByTimestampPaginationTest (46 passed, 6 skipped), ConfigResourceIT (14 passed), ContextFileIT (30 passed, 3 skipped), ContextMemoryAnchorIT (1 passed), ContextMemoryIT (18 passed), ContextMemoryLifecycleIT (154 passed, 14 skipped), ContextMemorySourceEntityTiebreakIT (34 passed, 3 skipped), ContextMemoryStatusMigrationIT (1 passed), ConversationResourceIT (8 passed), DatabaseSmokeIT (17 passed, 3 skipped), GlossaryTermInheritedReviewerApprovalIT (5 passed), GlossaryTermMoveApprovalIT (4 passed), GlossaryTermRealizationIT (43 passed, 4 skipped), GlossaryTermRelationAdvancedIT (102 passed, 13 skipped), GlossaryTermRelationEdgeCasesIT (17 passed), GlossaryTermRelationEdgeIT (42 passed, 2 skipped), GlossaryTermRelationFixesIT (32 passed, 1 skipped), GlossaryTermRelationIT (0 passed), GlossaryTermRelationSettingsIT (148 passed, 19 skipped), GlossaryTermRelationSettingsPermissionsIT (17 passed), GlossaryTermRelationUsageIT (5 passed), GlossaryTermRelationsIT (29 passed, 2 skipped), GlossaryTermResourceIT (139 passed, 3 skipped), IngestionPipelineAgentTypeIT (2 passed), KnowledgePageHierarchyIT (1 passed), LLMModelResourceIT (31 passed, 4 skipped), LLMServiceResourceIT (7 passed, 1 skipped), McpContextMemoryVisibilityIT (14 passed, 4 skipped), McpExecutionResourceIT (78 passed, 13 skipped), McpIntegrationIT (9 passed), McpOAuthIT (39 passed), McpPermissionIT (37 passed, 4 skipped), McpSearchIT (2 passed), McpServerResourceIT (62 passed, 1 skipped), McpToolsValidationIT (15 passed, 1 skipped), McpUserContextIT (14 passed, 1 skipped), MetricAssetsIT (26 passed, 2 skipped), OntologyAiResourceIT (9 passed), OntologyChangeSetIT (5 passed), PersonaAIContextIT (5 passed), PromptTemplateResourceIT (35 passed, 3 skipped), SeedDataPresenceIT (4 passed), TableResourceIT (214 passed, 7 skipped), UserResourceIT (91 passed, 6 skipped)

Why these tests
  • area ai-mcp-context ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryLifecycle.java, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • called from entity ContextFile ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • called from entity ContextMemory ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryLifecycle.java, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • called from entity GlossaryTerm ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • called from entity KnowledgePage ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • called from entity OntologyAi ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • called from entity OntologyChangeSet ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • changed test ← openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ContextMemoryLifecycleIT.java, openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/ContextMemoryLifecycleTest.java, openmetadata-service/src/test/java/org/openmetadata/service/resources/context/ContextMemoryStatusTransitionTest.java
  • entity ContextMemory ← openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java
  • smoke ← code other than a test class changed
Commands
mvn -B package -pl openmetadata-mcp,openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=CompanyContextToolTest,ContextMemoryLifecycleTest,ContextMemoryReconcilerTest,ContextMemoryRepositoryTest,ContextMemoryStatusTransitionTest,EntityRepositoryEntityStatusTest,OntologyMemoryDerivationServiceTest,SemanticMemoryDuplicateFinderTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<50 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=ConversationSchemaMigrationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=rdf -Dit.test=AgentSparqlResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

Ingestion integration tests

Not applicable — no ingestion changes.

Playwright (UI) tests

Not applicable in this repository — no OSS UI changes. Companion Collate validation passed seven live memory scenarios with retries disabled, including conflicts becoming Draft, unchanged reruns, edits, explicit requeue, approval and rejection. Its PR records the tests run there.

Manual testing performed

  1. Rebuilt OSS dependencies and Collate; started Collate with the prepared Local Hybrid Postgres recipe environment and AI Platform on localhost.
  2. Used the supplied admin identity to PATCH the specifically reported legacy bot-annotated conflict from Unprocessed to Draft with If-Match; verified its answer and contradiction reason were unchanged, and its Approved reference retained its answer and version.
  3. In the live companion browser suite, reconciled a newly captured conflict to Draft, edited and reran it without another judge call, then explicitly requeued it and verified Draft again. Human approval and rejection remain outside reconciliation.

UI screen recording / screenshots:

Not applicable — no OSS UI change. The companion Collate PR includes the Draft conflict screenshot.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title follows the issue-linked format.
  • My PR is linked to a GitHub issue via Fixes Add OSS memory lifecycle and Context Center status filtering #34394.
  • The lifecycle reason rule is documented in code.
  • Added regression unit and integration tests and listed the actual results above.
  • JSON Schema migration: not applicable; existing ContextMemoryStatus values are unchanged.
  • UI recording: not applicable; no OSS UI change.
  • Ready-for-review gate: pending the affected runner's empty-test placeholder limitation; kept as draft.

Summary by Gitar

  • Optimistic locking:
    • Context memory writes now verify both version and updatedAt before storing
    • Consolidated edits bump updatedAt so conditional lifecycle writes stay distinct
  • Lifecycle transitions:
    • Allowed Unprocessed → Draft and Draft → Rejected transitions in ContextMemoryRepository
    • Preserved existing statusReason when entering Draft in ContextMemoryLifecycle
  • Review tracking:
    • Added lastReviewedAt, set when a memory becomes Approved or reconciliation revalidates it
    • Allowed Approved → Draft so Approved conflicts can return to human review
  • Search filtering:
    • Vector search now applies memoryScope, memoryType and pinned filters to the vector leg in VectorSearchQueryBuilder
    • Chunk docs carry memoryScope, memoryType and pinned on every chunk, with CHUNK_DOC_VERSION bumped to 8 for restamping

This will update automatically on new commits.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 8, 2026
pmbrull and others added 4 commits October 9, 2026 09:06
…last review

Collate's Memory Reconciliation now revalidates Approved memories once an
interval has passed. Two lifecycle gaps blocked it:

- Approved could not move to Draft, so a conflict the judge was unsure of,
  or one across audiences, had no route to a person. Approved -> Draft is
  now allowed; every retired stage still cannot go back to Draft.
- Nothing on the memory said it had been checked. lastReviewedAt records
  it: becoming Approved sets it (person or reconciliation), creating a
  memory as Approved sets it, a revalidation sets it, a PUT keeps it, and
  a change to it is recorded in version history.

ADR:2026-10-09-an-approved-memory-can-return-to-review-and-records-its-last-review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vector leg

Collate's per-question memory recall asks hybrid search for the user's
UserGlobal, non-Preference, unpinned memories. The lexical leg applied those
keys, but VectorSearchQueryBuilder dropped them as unrecognized, so a
Preference that was semantically close reached the recall through the knn
leg alone (found validating on a local stack: "revenue by region" returned
the Currency preference). Chunk documents already carry the three fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pmbrull

pmbrull commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Two commits added for Collate's revalidation of Approved memories (open-metadata/openmetadata-collate#7247) and per-question memory recall (open-metadata/openmetadata-collate#7246, open-metadata/ai-platform#1637):

  • e0b6f63d01 — lastReviewedAt on ContextMemory (set on becoming Approved, on create-as-Approved, and by a revalidation; kept on PUT; recorded in version history) and Approved → Draft. ADR:2026-10-09-an-approved-memory-can-return-to-review-and-records-its-last-review.
  • f3a221bbca — VectorSearchQueryBuilder applies memoryScope, memoryType and pinned; without it the knn leg ignored them and a Preference leaked into the recall (found on a local stack).

Verification: ContextMemoryStatusTransitionTest, ContextMemoryLifecycleTest, ContextMemoryRepositoryTest (58) and VectorSearchQueryBuilderTest (51) pass. ContextMemoryIT's invalid-transition case now uses Archived → Draft (not run locally). End to end on a local Postgres + OpenSearch + Collate + AI Platform stack built from this branch: a memory created as Approved carries lastReviewedAt; reconciliation moved Approved memories to Superseded / Invalidated / Draft and re-approvals recorded a lastReviewedAt-only version; the hybrid search returned only the requested memory kinds on both legs.

🤖 Generated with Claude Code

@pmbrull
pmbrull marked this pull request as ready for review October 9, 2026 12:45
@pmbrull
pmbrull requested a review from a team as a code owner October 9, 2026 12:45
Copilot AI balanced review requested due to automatic review settings October 9, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/, public/jsons/) have been automatically updated
based on JSON schema changes in this PR.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…e dedicated chunk index

The vector leg applies memoryScope, memoryType and pinned, but memory chunks
in the dedicated dynamic:false chunk index carried neither the fields nor
their mapping, so a query filtering on them matched no chunk there.

- VectorDocBuilder writes memoryScope, memoryType and pinned on every memory
  chunk; CHUNK_DOC_VERSION 7 -> 8 so an existing index gets the additive
  mapping (keyword, keyword, boolean) and the next Search Reindex restamps it.
- The chunk header records the kind and a change to it restamps the chunks:
  pinning or retyping a memory leaves the fingerprint alone, so without this
  its chunks would keep the old kind until the next reindex.
- The field names live on ContextMemoryIndex, shared by the entity index,
  the chunk docs and the query builder.

Verified on a local stack: after the upgrade the dedicated index answers a
UserGlobal / Note+Learning / unpinned query (0 chunks before), and pinning a
memory restamped its chunk without a reindex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 76%
76.32% (120415/157770) 62.28% (74588/119750) 63.71% (24910/39094)

The RDF writer emits every ContextMemory field, and RdfOntologyContractTest
requires each written predicate to be declared and marked om:Stored. The new
lastReviewedAt field was neither, failing everyWrittenPredicateIsDeclared and
writtenPredicatesAreNeverLabeledInferenceOnly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Keep DAO regression tests with the API they exercise so Collate can compile against upstream main.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Lifecycle and vector-filter changes could move valid memories out of answer grounding or omit matching memories when chunk metadata is stale.

Adds Unprocessed → Draft and Draft → Rejected lifecycle transitions, preserves existing review reasons when entering Draft, and records lastReviewedAt on approval and reconciliation. The vector search leg now applies memoryScope, memoryType and pinned filters, addressing the finding where kind filters hit fields absent from chunk docs and dropped vector hits. No open issues found.

✅ 1 closed
✅ Bug: Kind filters hit fields absent from chunk docs, dropping vector hits

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorSearchQueryBuilder.java:412-423
The new memoryScope, memoryType and pinned cases add term/terms clauses to the KNN filter. Memory vector hits come from chunk docs in a dedicated dynamic:false index. In that index, VectorDocBuilder.addContextMemoryFields writes only the share-config fields and status. The OpenSearchVectorService mapping declares neither of the new fields either. A filter on an unmapped field that the doc lacks matches nothing, so any query that sends these filters (e.g. Collate's UserGlobal/non-Preference/unpinned recall) gets zero memory chunks from the vector leg. Before this change, those keys were ignored and the leg returned results. The unit test only checks the JSON shape, so it can't catch this. To fix, write memoryScope, memoryType (enum value) and pinned onto memory chunk docs, add them to the chunk-index mapping (keyword/keyword/boolean), and bump CHUNK_DOC_VERSION so existing indices get the additive PUT _mapping and a reindex.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

❌ UI Checkstyle Failed

❌ Bundle Runtime Check

A route chunk loads but one of its chunks still exports undefined: a chunking change broke module initialisation. Run yarn build && yarn bundle:runtime locally.


Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@pmbrull
pmbrull added this pull request to the merge queue Oct 9, 2026
Merged via the queue into main with commit fe85c53 Oct 9, 2026
79 checks passed
@pmbrull
pmbrull deleted the pmbrull/context-memory-conflict-drafts branch October 9, 2026 19:27

This branch was previously deployed

1 inactive deployment
test — 9c3f61d7 Deployed Oct 9, 2026 by pmbrull via RDF Playwright execution #28145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add OSS memory lifecycle and Context Center status filtering

3 participants