Skip to content

Fixes #34394: Add memory lifecycle and status filtering - #34395

Closed
pmbrull wants to merge 33 commits into
open-metadata:agent/lets-look-at-what-life-cycle-3from
pmbrull:pmbrull/memory-lifecycle-main
Closed

pmbrull wants to merge 33 commits into
open-metadata:agent/lets-look-at-what-life-cycle-3from
pmbrull:pmbrull/memory-lifecycle-main

Conversation

@pmbrull

@pmbrull pmbrull commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Replaced by #34647, targeting main after #34541 merged. GitHub closed this PR when its former base branch was removed; the prior discussion is retained here. Current validation evidence is in #34647.


Describe your changes

Fixes #34394. This PR is stacked on #34541, which introduces the shared entityStatus field and per-entity lifecycle declarations. Please merge #34541 first.

  • Context memories use the existing shared statuses: Draft, Approved, Deprecated, Rejected, and Archived. A memory with no stage starts Approved. Deprecated means it was superseded and requires its memory-specific supersededBy reference; Rejected means its claim was invalidated, with statusReason available to explain why. These outcomes do not add values to the shared EntityStatus enum.
  • Supersession requires a readable, live successor and rejects self-references. Status changes clear stale reasons and successor links. Direct reads and versions retain retired states. Legacy rows without a stored status behave as Approved on reads, writes, indexing, and proposal checks.
  • Ordinary lexical and vector search include only Approved memories; the Context Center status filter can select multiple stages and combines with text, asset, author, and sort. Rows and details show badges and reasons, and the successor link opens its memory.
  • Closing a memory opened from a link clears the URL selection and preserves unrelated query parameters. A pending lookup for a closed or replaced selection cannot reopen the modal or restore its old URL.
  • Direct reads and version history enforce anchor access. Nonowners cannot find anchored memories through ordinary search even when they can view the anchor; owners and admins can find Approved ones. The anchor decision cache is bounded.
  • Deprecated and Rejected memories cannot initiate glossary proposals, and an open draft cannot be applied after its source retires. Already applied glossary terms retain provenance.
  • The base PR owns the 2.1.0 migration; this PR changes no SQL migrations. Existing search indexes should reindex memory entities and chunks after upgrade. Chunk schema version 7 adds entityStatus to older chunk mappings.

Type of change

  • New feature
  • Bug fix

Tests

  • Modal regression fix: yarn jest on ContextCenterMemoriesPage.test.tsx, CreateMemoryModal.test.tsx, MemoriesView.test.tsx, and MemoryDerivedOntology.utils.test.ts with --runInBand — 39 passed. The page tests reproduce view/editor reopening and cover a successor response arriving after close.
  • Local Chromium: PW_PRESEEDED_STATE=true PLAYWRIGHT_IS_OSS=true PLAYWRIGHT_TEST_BASE_URL=http://127.0.0.1:3000 yarn playwright test playwright/e2e/Features/ContextCenterMemoryLifecycle.spec.ts --project=chromium --workers=1 — all 3 tests passed after refreshing the admin test session. The added regression exercises Cancel, Escape, Edit/Cancel, the close button, and successor navigation. A separate read-only test of the reported local memory link also passed.
  • Changed-file organize-imports, ESLint and Prettier passed. yarn lint:playwright completed with 0 errors (existing warnings). yarn token-audit still reports 83 errors in untouched stylesheets; this fix changes no styles.
  • mvn -pl openmetadata-spec clean install -DskipTests — generated Java enum rebuilt successfully.
  • mvn -pl openmetadata-service -Dtest=ContextMemoryLifecycleTest,ContextMemorySchemaTest,ContextMemoryStatusTransitionTest,ContextMemoryIndexTest,ContextMemorySearchVisibilityTest,OpenSearchVectorServiceTest,VectorDocBuilderChunkTest,VectorSearchQueryBuilderTest,OntologyChangePreflightTest,OntologyMemoryDerivationServiceTest -DfailIfNoTests=false test — 158 passed.
  • mvn -pl openmetadata-mcp -Dtest=CompanyContextToolTest -DfailIfNoTests=false test — 18 passed.
  • mvn -pl openmetadata-integration-tests -Dtest=ContextMemoryLifecycleIT,ContextMemoryAnchorIT,ContextMemoryStatusMigrationIT,OntologyChangeSetIT -DfailIfNoTests=false test — 43 reported, no failures (PostgreSQL). The concurrent runner's per-class report undercounted the memory classes, so they were rerun alone: Lifecycle 20/20 and Anchor 12/12.
  • After merging the latest Fixes #34540: Support a shared lifecycle stage on entities and let active workflows own it #34541 head, mvn -pl openmetadata-integration-tests -Dtest=ContextMemoryLifecycleIT,ContextMemoryAnchorIT,ContextMemoryStatusMigrationIT -DfailIfNoTests=false test — 33 passed, no failures. The focused service, MCP, and Jest runs passed again: 158, 18, and 36 tests respectively.
  • The base PR's ContextMemoryStatusMigrationIT passed against both PostgreSQL and MySQL after restoring its fixture unchanged.
  • mvn -pl openmetadata-integration-tests -Dtest=ContextMemoryLifecycleIT,ContextMemoryAnchorIT,OntologyChangeSetIT -DfailIfNoTests=false test — 42 passed.
  • mvn -pl openmetadata-service -Dtest=ContextMemoryReconcilerTest,OntologyMemoryDerivationQueueTest,SemanticMemoryDuplicateFinderTest,ContextMemoryLifecycleTest,ContextMemorySearchVisibilityTest,OpenSearchVectorServiceTest,VectorSearchQueryBuilderTest -DfailIfNoTests=false test — 130 passed. This fixes the two legacy-status failures reported by the previous full service CI run and covers legacy duplicate reuse.
  • After adding the legacy file-reuse assertion, mvn -pl openmetadata-service -Dtest=ContextMemoryReconcilerTest,OntologyMemoryDerivationQueueTest,SemanticMemoryDuplicateFinderTest -DfailIfNoTests=false test — 28 passed.
  • Full openmetadata-service-unit-tests CI on commit bf7bffae5c — 11,049 tests, 0 failures, 0 errors, 1 skipped. The previous two legacy-memory failures are resolved.
  • yarn jest --runInBand --passWithNoTests on the four focused Context Center suites — 36 passed.
  • Context Center Jest rerun after regeneration — 36 passed.
  • mvn -pl openmetadata-service,openmetadata-integration-tests,openmetadata-mcp spotless:apply and UI checkstyle on changed files — passed; Playwright spec ESLint/Prettier passed.
  • Playwright chromium-25 shard on bf7bffae5c ran the updated ContextCenterMemoryLifecycle.spec.ts: both lifecycle tests passed with Deprecated/Rejected. The shard finished 128 passed, 1 failed in ArticleReviewerWorkflow.spec.ts (article remained Draft instead of In Review); that workflow is outside this PR's changed files. Commit 445b016f2a only removes migration changes.

yarn tsc:check and yarn tsc:playwright remain red on errors outside the changed files; neither reported an error in the Context Center files or the lifecycle Playwright spec.

The full local mvn -pl openmetadata-service test run reached 11,048 tests with zero assertion failures and two errors in the unrelated K8sPipelineClientBotTokenBugTest: the local Okio/OkHttp classpath throws NoSuchMethodError: okio.Okio.socket(java.net.Socket). Running that class alone reproduces the same errors. Full service CI subsequently passed. One PostgreSQL/OpenSearch integration lane on bf7bffae5c had unrelated failures in TaskResourceIT pagination and AppOperationPermissionsIT HTTP setup; its memory migration test passed.

Local server and index evidence

Local Chromium ran the current OSS UI at :3000, proxied to the running backend at :8585. It verified Approved/Deprecated/Rejected labels, status filtering combined with text/author/sort, retired reasons and hidden proposal actions, successor navigation, and all modal close paths. The reported memory link closes and leaves the list usable. The UI served directly at :8585 belongs to a separate Collate workspace and needs to incorporate the updated OSS UI build.

An earlier new-memory semantic run was blocked by an embedding dimension mismatch: DJL produced 384-dimensional vectors while that chunk index required 512. Vector filter behavior is covered by the focused Java tests; a compatible vector index is needed for a live semantic rerun.

The maven-collate-ci check on this stacked PR has failed at dispatch because its workflow looks for the OSS base branch agent/lets-look-at-what-life-cycle-3 in open-metadata/openmetadata-collate, where that ref does not exist. No Collate files or workflows were changed here.

pmbrull added 15 commits October 1, 2026 17:44
Entity memories about restricted assets were visible through direct REST
reads. Check ViewBasic on the anchor for non-owners.

Search still relies on domain inheritance and search RBAC; asset policies
are not evaluated per result.
The by-name Company Context lookup omitted primaryEntity, so an anchored
memory appeared unanchored to the visibility check. Fetch the decision
fields before projecting the pill.

Query search remains governed by search RBAC and inherited domains.
History endpoints exposed earlier versions without checking the current
memory's visibility. Check the current memory before serving either
history endpoint.

Keep paging cursors when hidden memories are filtered from a list page
so callers can reach later visible rows.
Map supersession and dispute fields in every search locale and request
the relationship fields needed by memory docs during reindex.

Default an omitted status to Active on create. The generated model leaves
the schema default null, which broke lifecycle reads after regeneration.
Stamp lifecycle status on chunk docs and accept it in both vector query
builders. Non-Active transitions change the fingerprint to refresh the
filter fields; existing Active memories keep their fingerprint.
Preserve server-managed lifecycle fields on PUT so re-extraction cannot
reactivate a superseded memory or erase disputes.

Reject newly referenced memories the editor cannot read, and cache
anchor access decisions within each list page.
Search cannot evaluate an anchor's asset policy for each indexed hit.
Limit anchored Entity memories to owners and admins in lexical and vector
search; direct reads still allow asset readers.

Require an explicit unanchored marker so older documents fail closed
until reindexed. Stamp the marker on entity and chunk documents.
Keep retired memories available through direct lifecycle and version reads while excluding them from lexical, vector, and Company Context retrieval.
Allow status selection alongside search, asset, author, and sort filters while keeping ordinary search Active-only.

Preserve lifecycle fields on omitted-status PUT and prevent non-Active memories from proposing glossary terms. Extend API and UI coverage for these behaviors.
Reconcile Public memory visibility and index fields after the parent PR landed. Cover retired memory behavior in Playwright and align the deleted-source glossary expectation.

Refs open-metadata#34394
@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 1, 2026
@pmbrull
pmbrull marked this pull request as ready for review October 1, 2026 16:43
Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:43

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 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:57

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 removed the safe to test Add this label to run secure Github workflows on PRs label Oct 1, 2026

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 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 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 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 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.

@pmbrull

pmbrull commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

wait to merge until #34541 is in!!

@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ Generated Sources Need Update

The generated TypeScript types and/or dereferenced JSON schemas are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, they cannot be automatically committed.
Please generate and commit them manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
yarn parse-schema
git add src/generated/ src/jsons/ public/jsons/
git commit -m "Update generated TypeScript types and dereferenced schemas"
git push

After pushing the changes, this check will pass automatically.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

⚠️ Generated Sources Need Update

The generated TypeScript types and/or dereferenced JSON schemas are out of sync with the JSON schema changes.

Since this is a pull request from a forked repository, they cannot be automatically committed.
Please generate and commit them manually:

cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
yarn parse-schema
git add src/generated/ src/jsons/ public/jsons/
git commit -m "Update generated TypeScript types and dereferenced schemas"
git push

After pushing the changes, this check will pass automatically.

…n-metadata/OpenMetadata into pmbrull/memory-lifecycle-main
Map legacy migration values directly to shared statuses while retaining the 2.1.1 conversion for databases that stored preview values. Treat statusless memories as Approved in reconciliation, ontology derivation, and duplicate matching.

Refs open-metadata#34394
@gitar-bot

gitar-bot Bot commented Oct 5, 2026

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

🔴 High risk · Anchor-based authorization and lifecycle status changes alter memory access and visibility.

Adds memory lifecycle and status filtering with Draft, Approved, Deprecated, Rejected, and Archived states, alongside access controls and supersession validation. Resolves file-extracted knowledge pill visibility for non-admin users, legacy status normalization to prevent update failures, search inclusion of statusless memories, and chunk header schema alignment with entityStatus. No issues remain.

✅ 4 closed
✅ Bug: File-extracted knowledge pills drop out of search for non-admin users

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/ContextMemoryIndex.java:133-138 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/security/ContextMemorySearchVisibility.java:239-253 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorSearchQueryBuilder.java:275-289
ContextMemoryExtractor.toMemory creates every knowledge pill with primaryEntity = sourceRef (the context file/page), visibility = Entity, and updatedBy = admin, so setCreatorAsDefaultOwner makes admin the owner. The new search rule only lets non-owners match an Entity/Public memory when anchorId is unanchored (unanchoredOrgWideClause, and the same check in VectorSearchQueryBuilder.appendVisibleToUserClause). ContextMemoryIndex.anchorId writes the file's id for these pills. The result is that after reindex, every non-admin user stops getting file-extracted pills from lexical, hybrid and vector search, even though direct reads still allow them. The rule is meant to avoid leaking memories anchored to assets the user can't view, but a context file's readability already comes from its own shareConfig, which the file clause handles. The fix is to stamp anchorId as unanchored (or as a separate file-scoped marker) when the anchor is a contextFile/page source, or to skip the conservative anchor rule for those anchor types. Add an IT that searches for an extracted pill as a non-admin.

✅ Bug: Memories stored without a status can no longer be updated

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryLifecycle.java:59-73 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ContextMemoryRepository.java:758-768
On main, a memory created without a status was stored with status = null. The old guard skipped validation whenever either side was null, and there is no migration that backfills these rows. This delta removed that guard, so every update of such a legacy memory now fails.

  • PUT, or a PATCH that leaves status alone: updateLifecycle copies the original null status forward, and validateTransition(null, null) throws BadRequestException("A context memory requires a status"). Pinning, sharing, content edits and extraction re-PUTs on these pills are all rejected.
  • PATCH that sets a status: the code calls VALID_TRANSITIONS.getOrDefault(null, ...). VALID_TRANSITIONS is built with Map.of, which throws NullPointerException on a null key, so the request fails with a 500.

Fix: treat a missing stored status as Active before validating, in both applyUpdate and the PUT carry-forward. Alternatively, add a migration that backfills status = Active.

✅ Bug: Status-less legacy memories vanish from search, list, pills and proposals

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/ContextMemoryIndex.java:98-100 📄 openmetadata-spec/src/main/resources/json/schema/entity/context/contextMemory.json:37-49 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/CompanyContextTool.java:144 📄 openmetadata-service/src/main/java/org/openmetadata/service/ontology/OntologyChangePreflight.java:65-66 📄 openmetadata-ui/src/main/resources/ui/src/components/discovery/context-center/MemoryDerivedOntology/MemoryDerivedOntology.utils.ts:48-49 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/security/ContextMemorySearchVisibility.java:200-214
This PR removes "default": "Active" from memoryStatus in contextMemory.json. The generated POJO used to set ACTIVE when deserializing a stored row with no status; now it leaves the field null. The PR fixes PUT/PATCH for these legacy rows, but every read path still treats null as not Active:

  • ContextMemoryIndex.statusValue writes status: null into the index, and a reindex does the same.
  • Search requires term status=Active (or a terms query over the selected statuses).
  • So these memories disappear from ordinary/vector search and from the Context Center list, which now always sends statuses. They stay hidden even with every status selected.
  • CompanyContextTool.isExposablePill (getStatus() == ACTIVE), OntologyChangePreflight (!= ACTIVE) and the UI's isProposable (no longer accepts !memory.status) also reject them.

A memory comes back only after someone edits it, and that can't happen from the list because the list never shows it. The PR description says no migration is needed because a missing status counts as Active, but that is only true for the write path.

Fix: use ContextMemoryLifecycle.effectiveStatus (null → ACTIVE) in statusValue and in the Java status checks, and restore the !memory.status || fallback in the UI. Alternatively, add a migration that backfills status = Active.

✅ Performance: Chunk header requests status, but chunks store entityStatus

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:1274 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:1299-1300 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:1240-1249 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:282-283 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:329-330 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:1130
VectorDocBuilder.addContextMemoryFields writes the lifecycle stamp to chunk docs as ContextMemoryIndex.FIELD_STATUS (entityStatus). getChunkHeader asks for _source_includes=...,status,anchorId and then reads source.path("entityStatus"). That field is never fetched, so header.status() is always null. For a ContextMemory, memoryFilterChanged compares statusValue(memory) (for example "Approved") with null, so it always returns true. As a result, every memory update and reindex rebuilds and replaces all chunks even when nothing changed, and the staged backfill check alreadyBackfilled is never true for memories. To fix it, request entityStatus in the _source_includes list, using the same constants on the write side and the read side.

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

@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
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