Repository navigation
fix(snapshots): obtain the DockerBackend instance from one shared singleton accessor (#20889) - #20893
Conversation
…gleton accessor (#20889)
|
Warning Review limit reachedYou'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. View limit details
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. |
✅ SSOT Configuration Compliance: Passing🎉 No new hardcoded values of either class — Known backlog in |
… against inline lazy_singleton use (#20889)
Auto-sync: merging
|
| 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 |
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 raisedAttributeError: 'function' object has no attribute '_snapshot_index'every run and everyDepends(get_docker_backend)endpoint received a function. The old tests patchedlazy_singletonwithreturn_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 bytasks/snapshot_cleanup.pyand byget_docker_backend()inapi/execution_snapshots.py(it returned the factory; same defect).autobot-backend/llc/deps.py: newservice_singleton(cls);service_depresolves through it. Both keep a lock-guarded dict (anlru_cachedoes 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 viaservice_singleton, soservice_dep(WorkItemService)handlers and direct callers share one instance.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.pyaliased its own second factories for WorkProductService and AttachmentService to the shared ones.WorkItemService,BudgetService,AgentWikiServiceandAttachmentServicenow 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.pybuildsWorkItemService(activity_log=self.activity_log), a per-call argument.llc/api/work_items.pyno longer binds_get_product_service/_get_attachment_serviceat import; it calls the accessors.liveness_monitor,dispatch_gate, adapter, agent tools, tool offload, attachment sweep, session work item); class-method patches targetllc.services.budget.BudgetService.tests/test_snapshot_cleanup.pyusescreate_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.pypatches the accessor.repo_tests/inline_lazy_singleton_20889_test.pyfails on (1) alazy_singleton/async_lazy_singletoncall 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 (asaliases, module aliases). Allowlists carry reasons:credential_gated_registry.pyandllc/deps.py(factory in a function),credential_store.py(reset_credential_storerebinds),board.pyand 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 pinsfloor=withgrowth=0until 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 forsprints.py(1213),work_items.py(1300) andtest_heartbeat_scheduler.py(1007).Verification
tests/test_snapshot_cleanup.pyagainst the old source:4 failed, 1 passed(AttributeError: 'function' object has no attribute '_snapshot_index'); on this branch: passes.lazy_singleton(WorkProductService)()insprints.py:AssertionError: lazy_singleton(...) used inline ... sprints.py:1113; restored, it passes.reach_roots_record_18808_test,reach_scope_claim_17844_testand the guard: 15 passed.ruff checkandscripts/check_python_file_size.pyon touched files: clean.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.pyandscripts/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 throughget_work_item_service().test_subscription_usage_20266.pynow patchesllc.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
WorkProductServiceand simpleName = <Managed>alias assignments (with control strings);service_depdocstring fixed.Claude Sonnet 5.5
🤖 Generated with Claude Code