Repository navigation
Conversation
…lure (Graphify-Labs#1278) Closes Graphify-Labs#1278. label_communities now mirrors the extract path's adaptive recovery shape. When the LLM returns malformed JSON or a non-object payload for a batch, the batch is split at the midpoint and each half is retried recursively (capped at depth=3). Non-parse exceptions still propagate unchanged. Preserves the existing graceful-degradation contract: when retries exhaust at the base case, the original parse error re-raises so generate_community_labels still falls back to placeholders rather than silently returning empty. Added tests/test_label_retry.py - a stateful mock that simulates one malformed batch followed by clean sub-batches confirms all communities end up labeled. All 15 existing tests in tests/test_labeling.py pass unchanged.
Member
|
Merged to v8 in |
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.
What
Fixes #1278.
label_communitiespreviously logged-and-skipped any batch where the LLM returned malformed JSON or a non-object payload. On large graphs (the reporter's case: 121k nodes / 135 batches), a single failed batch silently lost ~100 community names with no recovery and no warning beyond the per-batch stderr line.This mirrors the recovery shape
_extract_with_adaptive_retryalready uses for the extract path: when a batch fails to parse, split it at the midpoint and retry each half recursively. Most transient LLM JSON glitches go away at the first or second split (smaller prompt → smaller output → less likely to truncate or mangle).Fix
_label_batch_with_retry()ingraphify/llm.py. Catches(json.JSONDecodeError, ValueError)from_parse_label_response, splitsbatch_cidsandbatch_linestogether atmid = len(batch_cids) // 2, recurses on each half withdepth + 1. Recursion capped atmax_depth=3(same as extract).raise. The retry net is intentionally narrow.label_communitiesis now a thin wrapper: builds slices, calls the helper, tracksfirst_errorandwrittenexactly as before. The outer graceful-degradation contract is preserved — when retries exhaust at the base case, the original parse error re-raises sogenerate_community_labelsstill falls back to placeholders rather than silently returning empty.Test
New
tests/test_label_retry.pyadds a unit test with a stateful mock that returns malformed JSON on the first call and clean JSON on subsequent (smaller) calls. Confirms:_call_llmwas called more than once (proving the retry actually happened)All 15 existing tests in
tests/test_labeling.pycontinue to pass — includingtest_label_communities_malformed_raises(the old contract is preserved) andtest_generate_community_labels_degrades_on_error(graceful fallback still works when retries exhaust).Design choices worth flagging
(json.JSONDecodeError, ValueError)(the two things_parse_label_responseraises). Network errors / config errors are not retried because they're not the recoverable case the issue describes.max_depth=3for consistency with_extract_with_adaptive_retry. Withbatch_size=100, this allows up to 8 leaf batches of ~12-13 communities each before giving up. If real-world cases need deeper recursion, that's a follow-up tuning.first_errortracking inlabel_communitiesstill fires. A partial-success edge case (left half succeeds, right half exhausts) loses the left half's labels — but in exchange, the existing graceful-degradation contract is preserved. The alternative (return empty dict at base case) breakstest_label_communities_malformed_raisessemantics.Notes
batch_size=100and Gemini backend. I was unable to reproduce the LLM-side malformed-JSON nondeterminism directly; the test uses a stateful mock to simulate the documented failure mode.llm.py— no API surface changes.tests/test_cli_export.py::test_export_wiki_accepts_edges_only_graph_jsonfails on unmodified v8 withKeyError: 'links'. Looks like the sameedges-vs-linkskey pattern already fixed inaffected.py(fix(affected): handle "edges"-keyed graph.json in load_graph (KeyError: 'links') #1280); the wiki export path appears to have been missed. Happy to follow up in a separate PR if useful.