Repository navigation
fix(reorganizer): optimize all graph tenants, run scheduled jobs, and survive non-JSON LLM output - #2481
Open
akushonkamen wants to merge 1 commit into
Open
fix(reorganizer): optimize all graph tenants, run scheduled jobs, and survive non-JSON LLM output#2481akushonkamen wants to merge 1 commit into
akushonkamen wants to merge 1 commit into
Conversation
… survive non-JSON LLM output - enumerate tenants via new get_all_user_names() (Neo4jGraphDB impl + BaseGraphDB fallback) and route both the _reorganize_needed trigger and the schedule jobs through _optimize_all_users(scope), isolating per-tenant failures; backends without the capability keep the previous single-tenant behavior - call schedule.run_pending() in the structure optimizer loop so the registered 100s jobs actually run instead of being dead code - make _parse_json_result return None for anything that is not a valid JSON object and short-circuit _summarize_cluster/_local_subcluster, so a malformed LLM reply skips the cluster instead of crashing the whole optimization round or silently writing empty parent nodes Fixes MemTensor#2480
4 tasks done
Collaborator
🤖 Open Code ReviewTarget: PR #2481 ✅ OpenCodeReview: Review complete: 0 finding(s) across 5 selected item(s). Generated by cloud-assistant via Open Code Review. |
Collaborator
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GraphStructureReorganizerhad three defects onmain@ a7367d0:_reorganize_neededtrigger and the scheduled jobs calloptimize_structure(scope=...)withoutuser_name, and the graph backends fall back toself.config.user_name, so only the default tenant (memosdefault) is ever optimized. Tenants written per-request via the REST API never receivePARENT/INFERS/FOLLOWSstructure edges.schedule.every(100).secondsjobs are registered, but the loop never callsschedule.run_pending(), so periodic reorganization is dead code.extract_first_to_last_bracereturnsNonefor text without braces and_parse_json_resultonly catchesJSONDecodeError(returning{}on that path), soNone/non-dict values flow intoresponse_json.get(...): anAttributeErrorkills the whole optimization round, and the{}path silently creates empty parent nodes viaembed("").Fix:
get_all_user_names()— implemented onNeo4jGraphDB, with a fallback default onBaseGraphDB; postgres/polardb behavior is unchanged._optimize_all_users(scope)enumerates the tenants actually present in the graph and runs the optimizer per tenant with per-tenant failure isolation; both the trigger and the scheduled jobs are routed through it. Backends without the new capability keep today's single-tenant behavior.schedule.run_pending()so the registered jobs actually run._parse_json_resultreturnsNonefor anything that is not a valid JSON object;_summarize_cluster/_local_subclustershort-circuit onNone, so a malformed LLM reply skips one cluster instead of crashing the round or writing empty parents.Related Issue (Required): Fixes #2480
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
New tests:
tests/memories/test_reorganizer.py(trigger routing, schedule execution,_parse_json_resultbehavior) andtests/graph_dbs/test_get_all_user_names.py(Neo4j implementation +BaseGraphDBfallback). Local venv, Python 3.12, repo @ 47a6f23.pytest tests/memories/test_reorganizer.py tests/graph_dbs/test_get_all_user_names.py -q→17 failed, 6 passed— every defect case red.25 passed.timeout 120 python -m pytest tests/graph_dbs -q→35 passed, 3 skipped(baseline 31 passed + 3 skipped + 4 new).timeout 300 python -m pytest tests/memories -q --ignore=tests/memories/activation/test_kv.py→87 passed, 3 failed. The 3 failures are all intests/memories/activation/test_item.py::TestKVCacheItemand reproduce identically with the fix stashed (baseline re-run: same 3 failed / 3 passed) — pre-existing and unrelated to this change.test_kv.pyrequirestorchand fails collection on the baseline as well (pre-existing environment gap), hence the--ignore.grep -c run_pending src/memos/memories/textual/tree_text_memory/organize/reorganizer.py→0before,1after.ruff check/ruff format: both test files fully pass; onsrc/the fix adds 2 newBLE001findings (blindexcept Exception), consistent with the pre-existing style in the same file; the pre-existing pagination block thatruff --fixwould rewrite was left untouched.Checklist
Reviewer Checklist
Transparency note: this fix and its tests were prepared with AI coding assistance (also disclosed in the issue claim comment).