You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(company-os): native AutoBot-agent runs are never charged to a budget (cost forwarding unwired) #20883
Native AutoBot-agent runs are never charged to any budget: no cost event, no budget counter update, and no BudgetExhausted hard stop (#8215, #15859) for this adapter.
Evidence
autobot-backend/llc/adapters/autobot_agent_adapter.py:380_forward_cost returns early when self._budget_session_factory is None, before any ingest.
autobot-backend/llc/adapters/autobot_agent_adapter.py:171,194 the factory is an optional constructor argument defaulting to None.
autobot-backend/llc/scheduler/heartbeat_scheduler.py:846 the only non-test construction is AutoBotAgentAdapter(agent_config=adapter_config): no factory passed.
grep -rn "budget_session_factory" autobot-backend --include=*.py | grep -v /tests/ returns only the adapter itself (lines 171, 179, 194, 380, 414); nothing outside it supplies a value.
Second defect, same code
autobot-backend/llc/adapters/autobot_agent_adapter.py:414-415 does async with self._budget_session_factory() as session: then BudgetService().ingest_cost_event(...) and never commits. Even with a factory wired, a successful ingest rolls back on exit unless the factory itself commits. PR #20222 makes the hard-stop path persist by committing inside the service before raising; the success path is not covered.
Impact
No spend is recorded for native AutoBot-agent runs.
Budget limits cannot stop these runs, so the M2.6 goal (every LLM call records a cost event; over-budget agents stop) is not met for this adapter.
Fix direction
Wire the factory at the construction site in heartbeat_scheduler.py using a committing session scope (autobot_shared/db_session.async_session_scope, commit-on-exit, rollback-on-error), so the success path persists as well as the hard-stop path. Reuse the hosting service's session maker per db_session.py guidance.
Acceptance criteria
A native run's tokens produce a cost event and a budget counter update (test through the real heartbeat construction path, not an injected factory).
A run over the limit hard-stops with BudgetExhausted, and its spend persists after the run (test reads the counter from a fresh session).
The adapter no longer silently skips forwarding when no factory is configured in production wiring (guard or test asserting the scheduler passes one).
Landed with merge train #21454 (8781966), member PR #21434. Checked against origin/main at 8781966, by reading code and tests; tests were not run here.
Criterion
Status
Evidence
A native run's tokens produce a cost event and a budget counter update (test through the real heartbeat construction path)
partly delivered; counter update needs a real database read
Construction path wired: llc/scheduler/heartbeat_scheduler.py:843 passes budget_session_factory=budget_session_scope (llc/scheduler/usage_billing.py:46, a committing scope). test_native_agent_cost_charged_20883.pytest_run_with_usage_produces_one_committed_cost_event_for_the_agents_budget runs _dispatch_autobot_agent and asserts one ingest_cost_event and one commit, but the BudgetService and session are fakes, so no counter is read.
A run over the limit hard-stops with BudgetExhausted, and its spend persists (test reads the counter from a fresh session)
partly delivered; persistence needs a real database read
test_hard_stop_still_stops_the_run asserts BudgetExhausted propagates. Persistence of the hard-stop spend rests on the service committing before it raises (#20202); no test here reads a counter from a fresh session.
The adapter no longer silently skips forwarding when no factory is configured in production wiring
delivered by code, ticked now
heartbeat_scheduler.py:843; guard test_scheduler_construction_site_passes_a_budget_session_factory asserts the kwarg is callable
Also delivered and not in the criteria: a lost non-budget charge is logged at ERROR with traceback and does not fail the run (autobot_agent_adapter.py:426; test_a_lost_charge_is_logged_at_error_with_traceback_and_does_not_fail_the_run). It is only logged, not recorded anywhere a user can see; follow-up #21432.
Still open: the first two criteria, which need a counter read from a real database. The issue stays open.
Closure evidence on origin/main after #21955 (merge 52a2fe50e). All ACs are ticked.
AC1.llc/tests/test_native_agent_cost_persists_20883.py:116 drives the real _dispatch_autobot_agent construction path with the real BudgetService on SQLite. A run under its limit records a cost event and updates the counter.
AC2. Same file, :124. A run over its limit hard-stops with BudgetExhausted, and its spend persists when read from a fresh session.
AC3 was already ticked. The scheduler passes the factory at llc/scheduler/heartbeat_scheduler.py:844 (budget_session_factory=budget_session_scope), and that scope commits.
Host evidence, local install on maind8cbd91925 (includes #21955), 2026-11-21. Read-only. No native AutoBot-agent heartbeat run happened between the restart (21:20 Riga) and the check: 0 runs for every visible agent, and the backend log since then shows only router and watchdog startup for cost and budget. The charge path therefore had nothing to charge, and this is not host proof. The cost routes report lifetime totals only. Proof needs a native run on the install, then a check of its cost event.
Activity
fix(company-os): FakeAsyncSession carries info, so the shared session…
test(company-os): charge test drives the real session scope protocol …
fix(company-os): a lost native or registry run charge is logged at er…
refactor(company-os): heartbeat scheduler hands its post-start resche…
github-actions commentedon Nov 13, 2026
Landed via the merge train (#21454, merge
87819661d3) via #21434mrveiss commentedon Nov 13, 2026
Landed with merge train #21454 (8781966), member PR #21434. Checked against origin/main at 8781966, by reading code and tests; tests were not run here.
llc/scheduler/heartbeat_scheduler.py:843passesbudget_session_factory=budget_session_scope(llc/scheduler/usage_billing.py:46, a committing scope).test_native_agent_cost_charged_20883.pytest_run_with_usage_produces_one_committed_cost_event_for_the_agents_budgetruns_dispatch_autobot_agentand asserts oneingest_cost_eventand one commit, but theBudgetServiceand session are fakes, so no counter is read.BudgetExhausted, and its spend persists (test reads the counter from a fresh session)test_hard_stop_still_stops_the_runassertsBudgetExhaustedpropagates. Persistence of the hard-stop spend rests on the service committing before it raises (#20202); no test here reads a counter from a fresh session.heartbeat_scheduler.py:843; guardtest_scheduler_construction_site_passes_a_budget_session_factoryasserts the kwarg is callableAlso delivered and not in the criteria: a lost non-budget charge is logged at ERROR with traceback and does not fail the run (
autobot_agent_adapter.py:426;test_a_lost_charge_is_logged_at_error_with_traceback_and_does_not_fail_the_run). It is only logged, not recorded anywhere a user can see; follow-up #21432.Still open: the first two criteria, which need a counter read from a real database. The issue stays open.
fix(company-os): charge native AutoBot-agent runs to the agent's budg…
Merge pull request #21955 from mrveiss/issue-21942
mrveiss commentedon Nov 21, 2026
Closure evidence on
origin/mainafter #21955 (merge52a2fe50e). All ACs are ticked.llc/tests/test_native_agent_cost_persists_20883.py:116drives the real_dispatch_autobot_agentconstruction path with the realBudgetServiceon SQLite. A run under its limit records a cost event and updates the counter.:124. A run over its limit hard-stops withBudgetExhausted, and its spend persists when read from a fresh session.llc/scheduler/heartbeat_scheduler.py:844(budget_session_factory=budget_session_scope), and that scope commits.fix(company-os): hide agents of deleted companies, bulk-assign modal …
mrveiss commentedon Nov 21, 2026
Host evidence, local install on
maind8cbd91925(includes #21955), 2026-11-21. Read-only. No native AutoBot-agent heartbeat run happened between the restart (21:20 Riga) and the check: 0 runs for every visible agent, and the backend log since then shows only router and watchdog startup for cost and budget. The charge path therefore had nothing to charge, and this is not host proof. The cost routes report lifetime totals only. Proof needs a native run on the install, then a check of its cost event.