Skip to content

fix(snapshots): obtain the DockerBackend instance from one shared singleton accessor (#20889) - #20893

Merged
mrveiss merged 8 commits into
mainfrom
issue-20889-snapshot-cleanup
Nov 7, 2026
Merged

mrveiss merged 8 commits into
mainfrom
issue-20889-snapshot-cleanup

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

lazy_singleton(X) returns a factory, not an instance. The nightly snapshot cleanup and the snapshot API dependency used the factory as the backend, so the cleanup raised AttributeError: 'function' object has no attribute '_snapshot_index' every run and every Depends(get_docker_backend) endpoint received a function. The old tests patched lazy_singleton with return_value=MagicMock(), which hid it.

The same class of mistake exists in the LLC routes: lazy_singleton(X)() called inline builds a fresh factory, hence a fresh instance, per call, so nothing is shared. The fix is one module-level factory per class, defined once, plus a guard so a new inline use fails CI.

What Changed

  • autobot-backend/services/execution/docker_backend_accessor.py (new): get_docker_backend_singleton, built once. Used by tasks/snapshot_cleanup.py and by get_docker_backend() in api/execution_snapshots.py (it returned the factory; same defect).
  • autobot-backend/llc/deps.py: new service_singleton(cls); service_dep resolves through it. Both keep a lock-guarded dict (an lru_cache does not lock a miss, so two threads could each build a different instance).
  • autobot-backend/llc/services/accessors.py (new): get_work_item_service, get_budget_service, get_work_product_service, get_attachment_service, get_agent_wiki_service, all via service_singleton, so service_dep(WorkItemService) handlers and direct callers share one instance.
  • Inline lazy_singleton(X)() replaced: llc/api/agent_api.py (WorkItemService at 74, 127, 144, 246; BudgetService 200; WorkProductService 286; AttachmentService 421; AgentWikiService 546, 569), llc/api/sprints.py:1115, llc/api/_common.py:223, llc/tests/test_agent_stub_routes_15905.py:135. llc/api/work_items.py aliased its own second factories for WorkProductService and AttachmentService to the shared ones.
  • Direct constructions of WorkItemService, BudgetService, AgentWikiService and AttachmentService now call the accessors: llc/api/agent_wiki.py (was a module-level _svc), llc/api/budget.py:199,227,290, llc/api/context.py:37, llc/agent_tools.py:147, llc/scheduler/ (heartbeat_scheduler, liveness_monitor, dispatch_gate, budget_watchdog, attachment_file_sweep), llc/adapters/autobot_agent_adapter.py:415, cli/agent_wiki.py, llc/services/agent_hire_service.py, llc/services/finding_proposal_service.py, llc/kb/context_builder.py, chat_workflow/tiered_context_sources.py, api/chat.py. All constructors take no per-call arguments and hold no per-call state (sessions are passed per method). Left on purpose: llc/services/board.py builds WorkItemService(activity_log=self.activity_log), a per-call argument. llc/api/work_items.py no longer binds _get_product_service / _get_attachment_service at import; it calls the accessors.
  • Tests that replaced the class now replace the accessor (liveness_monitor, dispatch_gate, adapter, agent tools, tool offload, attachment sweep, session work item); class-method patches target llc.services.budget.BudgetService.
  • Tests: tests/test_snapshot_cleanup.py uses create_autospec(DockerBackend, instance=True) injected through the real factory (set_for_test), plus regression tests for the accessor and the API dependency. llc/tests/test_agent_context_tenant_scope.py patches the accessor.
  • Guard: repo_tests/inline_lazy_singleton_20889_test.py fails on (1) a lazy_singleton / async_lazy_singleton call that is itself called or attribute-accessed, (2) one built inside a function or lambda body, (3) a direct construction of an accessor-managed class outside the accessors. Imports are resolved per file from the AST (as aliases, module aliases). Allowlists carry reasons: credential_gated_registry.py and llc/deps.py (factory in a function), credential_store.py (reset_credential_store rebinds), board.py and the accessor/registry homes (construction). Test files are exempt from (2) and (3). It has control strings for each shape (alias, in-function, lambda, await). Reach floor = the population (8058), because a new guard pins floor= with growth=0 until it lands (RATCHET_BASELINES.md, ci(guards): reach floor= literals computed from the merge base, not committed (177 pins in 126 files) #19676).
  • scripts/python_file_size_known_large.py: ceilings lowered for sprints.py (1213), work_items.py (1300) and test_heartbeat_scheduler.py (1007).

Verification

  • tests/test_snapshot_cleanup.py against the old source: 4 failed, 1 passed (AttributeError: 'function' object has no attribute '_snapshot_index'); on this branch: passes.
  • Guard against a re-introduced lazy_singleton(WorkProductService)() in sprints.py: AssertionError: lazy_singleton(...) used inline ... sprints.py:1113; restored, it passes.
  • LLC tests covering the touched services plus the snapshot tests: 50 passed. reach_roots_record_18808_test, reach_scope_claim_17844_test and the guard: 15 passed.
  • ruff check and scripts/check_python_file_size.py on touched files: clean.
  • Host evidence (the 05:00 run after the builtin updater logs a deleted count with zero errors) is not yet available.

Refs #20889

Single-issue rationale: a high-priority defect fix; Refs not Closes because the host-evidence criterion needs a post-update 05:00 run.

Merged with main after #20478 landed (T85). Conflicts resolved in llc/agent_tools.py, llc/api/budget.py, llc/scheduler/heartbeat_scheduler.py, llc/scheduler/liveness_monitor.py and scripts/python_file_size_known_large.py: #20478's parent rule table and work-items hierarchy are kept, with the accessor routing applied on top (get_work_item_service() / get_budget_service()). One new direct construction introduced by #20478 (llc/services/portability_import.py) is routed through get_work_item_service(). test_subscription_usage_20266.py now patches llc.services.budget.BudgetService.ingest_cost_event, since the scheduler no longer imports the class. Guard floor repinned to the live population (8093); size table set to the measured counts.

Model Used

Review follow-ups: the guard now also covers WorkProductService and simple Name = <Managed> alias assignments (with control strings); service_dep docstring fixed.

Claude Sonnet 5.5

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 02c53be and 1658109.

Files ignored due to path filters: 1

  • scripts/python_file_size_known_large.py is excluded by !scripts/python_file_size_known_large.py
Files selected for processing: 47

  • autobot-backend/api/chat.py
  • autobot-backend/api/execution_snapshots.py
  • autobot-backend/chat_workflow/llc_tool_output_offload_test.py
  • autobot-backend/chat_workflow/session_work_item_test.py
  • autobot-backend/chat_workflow/tiered_context_sources.py
  • autobot-backend/cli/agent_wiki.py
  • autobot-backend/llc/adapters/autobot_agent_adapter.py
  • autobot-backend/llc/agent_tools.py
  • autobot-backend/llc/api/_common.py
  • autobot-backend/llc/api/agent_api.py
  • autobot-backend/llc/api/agent_wiki.py
  • autobot-backend/llc/api/budget.py
  • autobot-backend/llc/api/context.py
  • autobot-backend/llc/api/sprints.py
  • autobot-backend/llc/api/work_items.py
  • autobot-backend/llc/deps.py
  • autobot-backend/llc/kb/context_builder.py
  • autobot-backend/llc/scheduler/attachment_file_sweep.py
  • autobot-backend/llc/scheduler/budget_watchdog.py
  • autobot-backend/llc/scheduler/dispatch_gate.py
  • autobot-backend/llc/scheduler/heartbeat_scheduler.py
  • autobot-backend/llc/scheduler/liveness_monitor.py
  • autobot-backend/llc/scheduler/schedule_entry_test.py
  • autobot-backend/llc/services/accessors.py
  • autobot-backend/llc/services/agent_hire_service.py
  • autobot-backend/llc/services/attachment_outbox_19756_test.py
  • autobot-backend/llc/services/finding_proposal_service.py
  • autobot-backend/llc/services/portability_import.py
  • autobot-backend/llc/tests/test_adapter_budget_company_scope.py
  • autobot-backend/llc/tests/test_agent_context_tenant_scope.py
  • autobot-backend/llc/tests/test_agent_hire_adapter_availability_12681.py
  • autobot-backend/llc/tests/test_agent_hires_auth.py
  • autobot-backend/llc/tests/test_agent_stub_routes_15905.py
  • autobot-backend/llc/tests/test_agent_tools.py
  • autobot-backend/llc/tests/test_autobot_agent_adapter.py
  • autobot-backend/llc/tests/test_budget_provision.py
  • autobot-backend/llc/tests/test_dispatch_gate_19240.py
  • autobot-backend/llc/tests/test_haiku_tier.py
  • autobot-backend/llc/tests/test_heartbeat_scheduler.py
  • autobot-backend/llc/tests/test_liveness_monitor.py
  • autobot-backend/llc/tests/test_subscription_usage_20266.py
  • autobot-backend/services/execution/docker_backend_accessor.py
  • autobot-backend/tasks/snapshot_cleanup.py
  • autobot-backend/tests/test_snapshot_cleanup.py
  • repo_tests/_reach_roots_record.py
  • repo_tests/inline_lazy_singleton_20889_test.py
  • repo_tests/reach_scope_claim_17844_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Auto-sync: merging main into issue-20889-snapshot-cleanup conflicts

The sync aborted the merge and pushed nothing. Conflicts are information, so it never resolves one itself. Below, for each conflicted file, are the commits that touched it on each side since the merge base 409c615dfa. Merge main in yourself and push; the label clears on the first run that finds this branch 0 behind.

autobot-backend/llc/scheduler/heartbeat_scheduler.py

side commit subject issue refs
main 9c3926adf7 Merge main into issue-20202-auth-failure (auto-sync) [skip ci] none
main cc404ca661 Merge main into issue-20202-auth-failure (auto-sync) [skip ci] none
main cf6a674108 fix(company-os): record subscription-login usage as tokens, never fail a finished run over dollars (#20266) #20266
main 42567dff0b Merge remote-tracking branch 'origin/main' into issue-20202-auth-failure none
main 7ab3436cdc fix(company-os): a failed registry run charges the tokens it spent, and main merged (#20202) #20202
this branch 6ae3b6c2a7 fix(llc): route direct service constructions through the shared accessors and widen the singleton guard (#20889) #20889

@mrveiss
mrveiss merged commit c16ff8b into main Nov 7, 2026
2 of 4 checks passed
mrveiss added a commit that referenced this pull request Nov 7, 2026
@mrveiss
mrveiss deleted the issue-20889-snapshot-cleanup branch November 7, 2026 12:41
@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Landed on main via merge train #21028 (merge commit 22097e0); every commit of head 1658109 is in main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working priority: high sync-conflict Set by the branch sync (#19548)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant