Skip to content

fix(knowledge): preserve concurrent dropped event batches - #3483

Open
HootRock wants to merge 1 commit into
ag2ai:mainfrom
HootRock:fix-concurrent-dropped-event-batches
Open

HootRock wants to merge 1 commit into
ag2ai:mainfrom
HootRock:fix-concurrent-dropped-event-batches

Conversation

@HootRock

@HootRock HootRock commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Two concurrent EventLogWriter.persist_dropped() calls can list the same existing segments and select the same next filename. Replacing that file with write() silently loses one complete batch, including when the writers share a SqliteKnowledgeStore.

Append each serialized batch using the existing atomic KnowledgeStore.append() contract and terminate it with a newline. Writers that select the same segment then retain both batches as valid JSONL. Numeric segment allocation and final snapshot replacement remain unchanged; concurrent batches may appear in either append order.

The regression forces both public list() calls to return their snapshots before either writer persists. It exercises real memory, disk, and SQLite backends, checks two multi-event batches, and verifies subsequent dropped and final events still load in order. All three cases fail on current main because one batch disappears, and pass with this change.

Refreshed on current upstream main 1742d550b554e3ce2eb726d421b562c151eb27b9. The test import conflict is resolved by retaining both upstream KnowledgePlugin and the regression's KnowledgeStore imports. All current upstream knowledge tests are retained.

Local validation with Python 3.12.12 on Windows:

  • The three concurrent-batch cases fail with assertion errors on unchanged production code from this current main (one entire batch disappears), then pass with the fix.
  • python -m pytest test/knowledge -q: 117 passed, 27 skipped (existing platform/dependency skips).
  • python -m ruff check --no-fix ag2/knowledge/log.py test/knowledge/test_knowledge.py and python -m ruff format --check ag2/knowledge/log.py test/knowledge/test_knowledge.py: passed.
  • git diff --check HEAD: passed.
  • Independent agent review of the refreshed two-file diff, backend append contracts, and test evidence found no actionable correctness issues. The reviewer did not independently rerun tests.

The full repository suite, full pre-commit/mypy pipeline, Redis service, and cross-process filesystem behavior were not exercised locally. No model/provider calls were made.

Related issue number

Fixes #3482.

Checks

  • I've included any doc changes needed for https://docs.ag2.ai/. The affected method docstring now describes concurrent batches sharing a segment; no public API change.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed. Local checks above passed; upstream CI is pending.

AI assistance

Codex assisted with the diagnosis, code, regression test, PR text, and an independent agent review. The diff and claims were checked against the source and the observed failing/passing test results.

  • I understand the changes in this PR and can explain them in my own words.
  • I have verified that the PR description accurately reflects the actual diff.
  • If AI assistance was used, I reviewed, tested, and validated the generated code/text before submitting.

reviewed and tested locally.

@CLAassistant

CLAassistant commented Oct 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ag2/knowledge/log.py 93.84% <100.00%> (ø)

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HootRock
HootRock force-pushed the fix-concurrent-dropped-event-batches branch from 23a8c3b to 3743cd5 Compare November 27, 2026 05:33

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Concurrent dropped-event writes overwrite a SQLite log segment

2 participants