fix(knowledge): let a torn WAL line degrade instead of failing the whole load #3675
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 470 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.368
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3675"
general
weight: 0.35
its-amann
Why are these changes needed?
EventLogWriter.load()reads a stream's event log: the numbered/log/{stream_id}.dropped-{n}.jsonlsegments, then the final/log/{stream_id}.jsonl. Every line is parsed withjson.loadsand indexed asrecord["type"]/record["data"]outside the per-record fallback that already handles unknown event types. So one bad line fails the whole load:JSONDecodeError,TypeErrororKeyError.Either exception aborts
load()entirely, which makes every event in the WAL unreadable — including all healthy segments and the final log. This matters because the loader is the resume path for sessions persisted byEventLogWriter, and the codebase's stated contract for unreadable records is to degrade, not fail: the existing fallback wrapscls.from_dictintry/exceptand emitsUnknownEvent, andag2/events/_serialization.pydocuments the same policy ("degrades to its raw value rather than failing the load and taking the whole event with it").The change moves line parsing under that same per-record contract: a line that does not parse into a
{type, data}record becomesUnknownEvent(type_name="", data={"raw": line}), preserving the raw text so nothing is lost. Recoverable records keep their exact degradation paths (unknown type →UnknownEvent(type_name=...); known type that failsfrom_dict→ unchanged).Two regression tests cover the torn-line case and the non-object-record case; both fail on
mainbefore the fix and pass after.Related issue number
None — self-found while running the knowledge test suite and reading
ag2/knowledge/log.pyonmain(fb3061e). I checked the tracker before preparing this (searches forpersist_dropped,EventLogWriter,JSONDecodeError, and dropped-segment terms, all states): no open issue or PR covers WAL load robustness. Open PR #3483 touchesag2/knowledge/log.pytoo, but for a different problem (concurrentpersist_droppedcalls overwriting a segment, inpersist_dropped); this change touches only_load_file, a different function, and I will rebase if it lands first.Checks
AI assistance
This change was prepared with the help of an AI coding assistant: the assistant located the issue, drafted the fix and the regression tests, and ran the targeted validation below. The submitter has reviewed the diff and the validation records, and can explain the change in their own words.
<!-- Validation performed locally before submitting (Windows 11, Python 3.13.9): new tests test_torn_line_degrades_to_unknown_event / test_non_object_line_degrades_to_unknown_event fail on main (JSONDecodeError / TypeError) and pass with the fix;
pytest test/knowledge/test_knowledge.py test/knowledge/test_plugin.py test/agent/test_knowledge_tool.py test/events/test_serialization.py→ 145 passed, 23 skipped (pre-existing platform/optional-deps skips);ruff checkandruff format --checkclean on both changed files. The unchecked boxes above are confirmed by the submitter before publishing. -->