Skip to content

Fixes #37454: Leave memory extraction interrupted by a server stop for recovery - #37455

Merged
pmbrull merged 10 commits into
mainfrom
pmbrull/memory-extraction-survives-stop
Nov 12, 2026
Merged

pmbrull merged 10 commits into
mainfrom
pmbrull/memory-extraction-survives-stop

Conversation

@pmbrull

@pmbrull pmbrull commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #37454

A normal server stop no longer fails a document's memory extraction silently, and it never retries anything without a person.

Type of change:

  • Bug fix

High-level design:

  • One stop rule. Interruptions.isStopInterruption(failure) (in jobs) treats a failure as a stop when any of these holds:

    • the server is stopping (ServerStopping);
    • the thread was interrupted;
    • an InterruptedException is in the cause chain.

    The text stage, both memory stages (files and articles) and the worker use it, so a document and its job reach the same verdict.

  • Memory stage. A CONTEXT_MEMORY_EXTRACTION job that ends in a stop interruption stays RUNNING, and the stale-job reaper requeues it. The file keeps ExtractingContext, and the article keeps its status.

    • Every other job type is still marked FAILED: Collate's admin-ops jobs depend on that.
    • Real failures still fail.
  • Text stage. A stop interruption stamps the file Failed with Interrupted by a server stop, through the existing conditional write.

    • No job is queued, and nothing retries it automatically.
    • A failure the run determines itself keeps its own message, such as no object storage or an empty read.
    • A crash leaves no stamp, so the startup scan resumes the file as before.
  • Shutdown order.

    • ServerStopping's hook is registered early in OpenMetadataApplication.run().
    • The asset service's shutdown hook raises the flag before it closes storage. JVM hooks run in no fixed order, so without this a read on a closed client could fail before the flag is set.
  • Logs. Stop paths log the root cause.

  • Record: new docs/decisions/2026-11-09-a-server-stop-leaves-memory-extraction-for-recovery.md.

Tests:

Use cases covered

  • A stop during memory extraction leaves the file ExtractingContext (or the article in progress), and its job stays RUNNING. A real LLM failure still marks it Failed.
  • A stop during text extraction marks the file Failed with Interrupted by a server stop, and queues no memory job. This holds both for an interrupt in the cause chain and when the asset service has already closed.
  • A failure the run determines itself during a stop keeps its own message, and so does a text failure with no stop.
  • The worker leaves only memory-extraction jobs for recovery; every other job type is still marked FAILED.
  • Timeouts (SocketTimeoutException, HttpTimeoutException) are not stop interruptions.

Unit tests

  • The updated focused set passed 71 tests across six classes. The exact class list is in the local Java evidence below.
  • The peer-completion regression failed before the fix in both Processed and ExtractingContext cases. It now preserves the peer run's text and status when an older stopped run reports failure.
  • Self-review at 512c15e1e1330d5e8500e9bfa48bc04ffdf16505 found no unanswered Important findings.
  • Spotless, the decision-record check, and Java impact ownership passed.

Backend integration tests

Local Java test run: PASSED

  • Commit: 512c15e1e133 (base origin/main)
  • Finished: 2026-11-11 10:40 UTC · 1.2 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 8 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (6 classes) 6 71 0 0 1.2 passed
  • Impacted, not run locally: 4 classes (listed in the details)

The focused run passed on the refreshed head. Earlier verification ran ContextMemoryExtractionIT with 7 passing tests before the main update. A manual stop/restart with multi-chunk extraction and full affected coverage remain pending.

Focused Java test details

Local Java test run: PASSED — details

  • Commit: 512c15e1e133 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (6 classes): AssetServiceFactoryTest (2 passed), ContextFileProcessingServiceTest (30 passed), GenericBackgroundWorkerTest (19 passed), InterruptionsTest (5 passed), OpenMetadataApplicationTest (1 passed), PageContextProcessingEngineTest (14 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=AlertingArchitectureTest,AssetServiceFactoryTest,BackgroundJobCleanupSchedulerTest,ContextFileProcessingServiceTest,ContextMemoryExtractionJobHandlerTest,ContextProcessingUpdatesTest,GenericBackgroundWorkerTest,InterruptionsTest,OntologyPublicationStatusResolverTest,OpenMetadataApplicationAuthReloadTest,OpenMetadataApplicationPushFeedUpgradeTest,OpenMetadataApplicationTest,PageContextProcessingEngineTest,SearchSettingsMergeUtilRepositoryResolutionTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<495 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=<34 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=rdf '-Dit.test=<37 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=parallel -Dit.test=AlertStateIT,BundleWarmupCertificationIT,ContainerCacheCorrectnessIT,EntityCacheWriteOrderIT,OneTransactionFlushAtomicityIT,RelationshipCacheInvalidationIT,TagRenameCacheIT,UncachedReadIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=global-state -Dit.test=CredentialRedisDownIT,CredentialRedisNoRoundTripIT,SessionRedisMultiNodeIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=parallel -Dit.test=FlattenedChildrenHighlightSearchIT,InheritedFieldPropagationRecoveryIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=global-state -Dit.test=PatchTableEmbeddingIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Impacted, not run locally (4)
  • RdfCatalogScaleIT → only with -DrdfCatalogScale=true, which no CI lane sets
  • ReindexBenchmarkIT → nightly: openmetadata-nightly k8s-java-it (scale-it)
  • EntityLoaderSmokeUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
  • SearchAvailableAllKindsDuringReindexUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=AssetServiceFactoryTest,ContextFileProcessingServiceTest,GenericBackgroundWorkerTest,InterruptionsTest,OpenMetadataApplicationTest,PageContextProcessingEngineTest -Dsurefire.failIfNoSpecifiedTests=false

UI screen recording:

Not applicable: backend-only change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have added tests (unit / integration) and listed them above.
  • Self-review against REVIEW.md: a task review, a whole-branch review, a re-review of its fix wave, and a re-review of the text-stage change. No Critical or Important finding remains.
  • Known limitations:
    • While the server is stopping, a thrown parse failure also reads Interrupted by a server stop; Retry then shows the real error.
    • A stop whose Failed stamp can't land keeps the file in progress until the next startup, as after a crash.
  • Decision check: the record above.

Merge order: Retry comes from #37479. Until it merges, a text stage a stop interrupts reads Failed with that reason and no Retry button, so its owner uploads it again. Merging with #37479: conflicts in ContextFileProcessingService, PageContextProcessingEngine and ContextFileProcessingServiceTest are additions on both sides (imports, one @AfterEach method each). Keep both.

Related: open-metadata/openmetadata-collate#8444 cites this PR's record, and raises ServerStopping in its gRPC client's shutdown hook.

🤖 Generated with Claude Code


Summary by Gitar

  • Text stage:
    • Stamps a stop-interrupted file Failed with Interrupted by a server stop via recordTextFailure
    • Removes ContextFileRecoveryScheduler and its test, so no sweep resubmits text-stage files

This will update automatically on new commits.

A normal stop interrupts the background-job threads, and the LLM clients
turn the interrupt into an LLMCompletionException. Every file and article
being extracted was marked Failed and its job FAILED, so nothing retried
them, while a crash left both in progress and recovered.

A stop now leaves them as a crash would:
- the file and article engines skip the Failed stamp when the run was
  interrupted (the thread flag, or an InterruptedException in the cause
  chain) and rethrow, so the job does not complete;
- the text stage abandons an interrupted run, leaving the file Analyzing
  for the startup scan;
- the worker leaves a memory extraction job that ends during stop()
  RUNNING, for the stale-job reaper to requeue.

Other job types still fail on stop: nothing requeues them, and a RUNNING
Collate admin-ops job blocks new jobs of its type. A real LLM failure
still marks the document Failed and the job FAILED.
Text extraction runs on a pool a stop never interrupts, but the asset
service's own shutdown hook closes object storage under it, so a stop
still stamped files Failed. The engines and the worker now share one
rule, Interruptions.isStopInterruption: ServerStopping is set, the
thread was interrupted, or an InterruptedException caused the failure.
The worker leaves a memory extraction job RUNNING under the same rule,
so a document and its job can no longer disagree. The ServerStopping
hook is now registered at startup, before any resource starts work.

The decision is recorded in docs/decisions/
2026-11-09-a-server-stop-leaves-memory-extraction-for-recovery.md.
The asset-service shutdown hook and the ServerStopping hook start
together with nothing ordering them, so a text read failing on the
just-closed client could still see the flag unset and stamp the file
Failed. The asset hook now raises ServerStopping itself before it
closes, and the decision record states the ordering.
In a surge-first rollout the new server runs its startup scan before
the old one stops, so files that stop leaves Uploaded or Analyzing have
no job and nothing resubmits them. Every server now sweeps every five
minutes and resubmits such files once they have been idle for 30
minutes. ExtractingContext stays with the stale-job reaper.

Also:
- the asset-service shutdown hook registers a task the tests run;
- the stop-path logs name the failure;
- timeouts are pinned as real failures;
- the decision record and Javadocs describe each stage's actual
  recovery.
ContextFileStaleTextStageQueryIT inserts context files years back and
asserts exactly which ones the sweep's query returns: stranded Uploaded
and Analyzing files with a snapshot, inside the one-day look-back,
oldest first, at most 50. It also pins the window and look-back edges.
@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Nov 9, 2026
The stale text-stage sweep resubmitted files unclaimed and uncapped,
every five minutes, from every server, for a day. That re-ran the AI
step automatically.

A text stage that a normal stop cuts short is now stamped Failed with
"Interrupted by a server stop", and its owner or an admin recovers it
with Retry. A crash still leaves no stamp, so the startup scan resumes
it. The memory stage is unchanged: it stays in progress, with its job
RUNNING for the stale-job reaper.

Also: the stop logs name the root cause, and the worker shares one
helper for a job left for recovery.
@pmbrull
pmbrull marked this pull request as ready for review November 10, 2026 13:11
@pmbrull
pmbrull requested a review from a team as a code owner November 10, 2026 13:11
@pmbrull
pmbrull requested review from TeddyCr and a balanced review from Copilot November 10, 2026 13:11

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 insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 10, 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 November 11, 2026 10:49

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 insufficient remaining quota. Try requesting a review at a lower effort level.

@gitar-bot

gitar-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 2 closed / 2 findings

Changes shutdown recovery for memory and text extraction; misclassified interruptions could strand work or cause failed extraction jobs to be retried.

Preserves memory extraction runs interrupted by a server stop so they resume after restart, and marks interrupted text-stage runs as Failed with Interrupted by a server stop for manual Retry. Resolved the stale updatedAt sweep issue on resubmitted Analyzing files and the stop stamp overwriting a peer run's finished text result.

✅ 2 closed
✅ Bug: Resubmitted Analyzing file keeps stale updatedAt, so it's swept every pass

📄 openmetadata-service/src/main/java/org/openmetadata/service/context/center/ContextFileProcessingService.java:214-228 📄 openmetadata-service/src/main/java/org/openmetadata/service/context/center/ContextFileRecoveryScheduler.java:43-44
When the sweep resubmits a file stuck in Analyzing, the rerun starts with markAnalyzing. That update writes Analyzing over Analyzing and null over a null processingError, so nothing changes. EntityUpdater.storeUpdateWithOptimisticLocking then takes its no-change branch (EntityRepository.java ~12890), which restores original.getUpdatedAt() and stores nothing. The row's updatedAt stays older than 30 minutes for the whole rerun. That causes two problems:

  1. Duplicate runs. Every 5-minute sweep resubmits the same file while the rerun is still parsing. A slow extraction stacks up parallel parses of the same file. The 30-minute window was supposed to prevent this; the ADR says it sits "far above any legitimate run", but that only holds if the window starts when the run starts.
  2. Repeated retries. A rerun that is abandoned without a write never moves the row. Examples are the currentContent == null path in extractText, or another stop interruption. The file is then resubmitted every 5 minutes until it ages out of the 1-day lookback, up to about 288 times. There's no claim or attempt cap to stop it.

This is the main case the sweep exists for: a stop leaves the file Analyzing. Uploaded files don't hit this, because their first markAnalyzing really changes the status.

Fix: have the sweep claim the file before it queues the run, so the claim bumps updatedAt. For example, run a conditional update that refreshes updatedAt (or records an attempt or claim timestamp). Or record a sweep-attempt marker and skip files claimed recently.

✅ Edge Case: Stop stamp can overwrite a peer run's finished text result

📄 openmetadata-service/src/main/java/org/openmetadata/service/context/center/ContextFileProcessingService.java:315-327 📄 openmetadata-service/src/main/java/org/openmetadata/service/context/center/ContextFileProcessingService.java:512-526
This commit makes recordTextFailure write Failed / Interrupted by a server stop whenever a stop interrupts a run. Before, a stopped run wrote nothing. applyFailure (lines 512-543) only checks that contentId is still the head. It does not check that the row is still Analyzing.

The removed ADR text covered a surge-first rollout: the new server's startup scan resubmits an Analyzing file while the old server is still parsing it. If the new server's run finishes first, the old server's later stop stamp overwrites the finished result:

  • With the LLM disabled, a Processed file goes to Failed.
  • With the LLM enabled, an ExtractingContext file reads Failed until its memory job marks it Processed.

Before this commit, the stopped run left the row alone, so this could not happen.

Fix: for the stop case only, make the updater return null (skip the write) unless the file and content are still Analyzing.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@pmbrull

pmbrull commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Local Java test run: PASSED — details

  • Commit: 512c15e1e133 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (6 classes): AssetServiceFactoryTest (2 passed), ContextFileProcessingServiceTest (30 passed), GenericBackgroundWorkerTest (19 passed), InterruptionsTest (5 passed), OpenMetadataApplicationTest (1 passed), PageContextProcessingEngineTest (14 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=AlertingArchitectureTest,AssetServiceFactoryTest,BackgroundJobCleanupSchedulerTest,ContextFileProcessingServiceTest,ContextMemoryExtractionJobHandlerTest,ContextProcessingUpdatesTest,GenericBackgroundWorkerTest,InterruptionsTest,OntologyPublicationStatusResolverTest,OpenMetadataApplicationAuthReloadTest,OpenMetadataApplicationPushFeedUpgradeTest,OpenMetadataApplicationTest,PageContextProcessingEngineTest,SearchSettingsMergeUtilRepositoryResolutionTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<495 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=<34 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=rdf '-Dit.test=<37 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=parallel -Dit.test=AlertStateIT,BundleWarmupCertificationIT,ContainerCacheCorrectnessIT,EntityCacheWriteOrderIT,OneTransactionFlushAtomicityIT,RelationshipCacheInvalidationIT,TagRenameCacheIT,UncachedReadIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pcache-tests -DintegrationTests.lane=global-state -Dit.test=CredentialRedisDownIT,CredentialRedisNoRoundTripIT,SessionRedisMultiNodeIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=parallel -Dit.test=FlattenedChildrenHighlightSearchIT,InheritedFieldPropagationRecoveryIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Ppostgres-opensearch -DintegrationTests.lane=global-state -Dit.test=PatchTableEmbeddingIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Impacted, not run locally (4)
  • RdfCatalogScaleIT → only with -DrdfCatalogScale=true, which no CI lane sets
  • ReindexBenchmarkIT → nightly: openmetadata-nightly k8s-java-it (scale-it)
  • EntityLoaderSmokeUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
  • SearchAvailableAllKindsDuringReindexUIIT → nightly: openmetadata-nightly k8s-java-it (ui-it + embedded JavaUIIT)
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=AssetServiceFactoryTest,ContextFileProcessingServiceTest,GenericBackgroundWorkerTest,InterruptionsTest,OpenMetadataApplicationTest,PageContextProcessingEngineTest -Dsurefire.failIfNoSpecifiedTests=false

@pmbrull
pmbrull merged commit 510fb3e into main Nov 12, 2026
68 checks passed
@pmbrull
pmbrull deleted the pmbrull/memory-extraction-survives-stop branch November 12, 2026 07:17
sonika-shah added a commit that referenced this pull request Nov 12, 2026
Resolve conflicts with the squashed #37581 (identical content) and with
#37455, which added a CONTEXT_MEMORY_EXTRACTION check and recovery tests
written against the removed BackgroundJob.JobType enum. Both now compare
against BackgroundJobTypes; the "every type but memory extraction" case
lists the same values as strings.
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.

Context Center: a normal server stop marks documents being extracted Failed and never retries them

4 participants