Skip to content

entity_communities: a namespace that fails no longer skips the rest of the pass - #2131

Merged
zlareb1 merged 7 commits into
mainfrom
fix/entity-communities-namespace-failure
Dec 4, 2026
Merged

zlareb1 merged 7 commits into
mainfrom
fix/entity-communities-namespace-failure

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The entity_communities worker keeps going when one namespace's edge read, partition or write fails. The failure is noted on the pass, and every other namespace still gets its communities.

Why

run_entity_communities loops over _namespaces_with_edges, which returns the consolidation opt-ins and then the walked namespaces, each ORDER BY org, namespace. The loop body (_edges, _partition in a thread, ch.insert) had no handler. A namespace whose read, partition or write raised therefore ended the pass. Because the order is the same on every pass, the same namespaces after it were skipped on every pass, and the pass recorded one failure for the whole worker.

  • Failing case: a pass over o/a, o/b where o/a's edge read raises, or its insert raises. The RuntimeError leaves run_entity_communities and o/b is never read or written.
  • Pattern: any exception from one namespace's own work leaves the loop.
  • Change: each namespace's work runs in its own try. On Exception the pass appends org/ns to the new EntityCommunitiesResult.failed, logs a warning with the traceback, calls pass_context.note_failure(e, "org/ns") and moves on to the next namespace. It also drops what the pass had recorded for that namespace (truncated, hubs_dropped, hub_fraction_used, giant), so the result names a namespace that raised only in failed. This is how code_graph_stats and knowledge_source_sync treat one repository or source. pass_context.PassStopped and asyncio.CancelledError are BaseExceptions, so a stopped pass or a lost lease still ends the pass before any further write (tests/unit/test_pass_stop.py covers this path).

Scope and risk

  • server/memory/app/entity_communities.py: the per-namespace try, the failed field, and the handler's removal of what the pass recorded for the failed namespace.
  • server/memory/workers/entity_communities.py: the pass outcome and its log line gain a failed count.
  • tests/unit/degraded_unnoted.txt: the new handler is listed as logged_only_nonanswer. It is a background pass with no response path, and the failure reaches the pass's ledger row through note_failure.
  • What is unchanged: the namespace selection, the edge read, the partition and the rows written for a namespace that succeeds. If an insert fails partway, the effect for that namespace is the same as before; the only difference is that the pass continues.
  • The supervisor counts a pass with noted failures toward the worker's failure streak, as it counted a raised pass, so a namespace that fails every pass keeps the worker visibly unhealthy.
  • Cadence: a raised pass of this worker waited its full interval (6 h; failure_hold_seconds, since the interval is longer than the deadline). A pass with a noted failure goes through next_interval_seconds instead. It waits worker_partial_retry_s (default 3600 s), doubled for each such pass in a row and capped at the interval. While one namespace keeps failing, the whole pass reruns after 1 h, 2 h and 4 h, then settles at 6 h. This is the supervisor's existing rule for partial passes. docs/reference/workers.md says a partial pass keeps its normal interval; that is wrong today for every worker and is left for a separate change.

Compatibility, rollout and rollback

  • Wire: none. The worker's pass outcome gains a failed key, the count of namespaces that raised.
  • Operator steps: none.
  • Rollback: reverting leaves no rows or migrations behind.
  • Rolling upgrade: none. N-1 and N write the same rows; only the handling of a failed namespace differs.

Tests

  • New: test_a_failing_namespace_does_not_skip_the_rest_of_the_pass[read], [partition] and [write] in tests/unit/test_entity_communities.py. In a pass over o/a and o/b, o/a's edge read, its partition or its insert raises. o/a is the fused graph of test_entity_communities_walked.py with one weaker pair past max_edges_per_namespace, so a pass that writes it records its truncation, a dropped hub, an escalated fraction and a giant community; the test asserts that it does, as a precondition. It then asserts that o/b's rows are the only insert, that failed == ["o/a"], that the result with failed cleared equals a clean pass over o/b alone, and that the pass context noted one RuntimeError labelled o/a. On main every parameter fails with the RuntimeError raised out of run_entity_communities. Leaving any one of the four removals out of the handler fails [partition] and [write]; [read] raises before anything is recorded.
  • New: test_the_worker_outcome_counts_failed_namespaces: the worker's pass outcome carries failed, the count of namespaces that raised.
  • .venv/bin/python -m pytest -q -p randomly tests/unit/test_entity_communities.py tests/unit/test_entity_communities_walked.py tests/unit/test_pass_stop.py tests/unit/test_package_contracts.py tests/unit/test_worker_registry_snapshot.py: 44 passed.
  • .venv/bin/python -m pytest -q tests/unit/test_degraded_unnoted.py: 2 passed, with main merged at 43e6e58, which lists the mcp_worker_enrollment_flow.py::_spend::1 handler (test_degraded_unnoted lists the enrollment challenge spend, so main's unit job passes #2132).
  • ruff format --check and ruff check over the tree, scripts/gates/function_length_gate.py and scripts/gates/check_no_secrets.py pass. mypy on the two changed server files reports no issues. The local scripts/gates/mypy_gate.py reports only server/clients/mcp_source.py and server/llm/vertex_auth.py, which fail because packages are missing from this environment. CI runs the full unit suite and the mypy gate.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked: the stop signal and a cancel are BaseExceptions and are not caught; the new test fails before the change and passes after it.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: none are affected.
  • A new migration is additive and numbered after the latest on main; no migration in this PR.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version: no plugin file changed.
  • The frontend builds and its tests pass, if frontend/ changed: not changed.
  • Docs under docs/ describe the system as it now is: no doc describes the per-namespace failure behaviour.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

…f the pass

run_entity_communities walked the namespaces in a stable (org, namespace) order with no
per-namespace handler, so an edge read, partition or write that raised for one namespace
ended the pass and skipped every namespace after it, on every pass. Each namespace's work
now runs in its own try: a failure is logged, noted on the pass with
pass_context.note_failure, listed in EntityCommunitiesResult.failed (the pass outcome's
`failed` count) and the pass goes on. PassStopped and a cancel are BaseExceptions and
still end the pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 4, 2026 9:15am UTC
loom-telemetry Ready Ready Preview Dec 4, 2026 9:15am UTC

Request Review

zlareb1 and others added 6 commits December 4, 2026 14:09
…t write

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…s-namespace-failure

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@zlareb1
zlareb1 merged commit f189681 into main Dec 4, 2026
81 checks passed
@zlareb1
zlareb1 deleted the fix/entity-communities-namespace-failure branch December 4, 2026 09:21
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.

1 participant