Repository navigation
Description
Problem
set_autonomy_status_logic writes the autonomy flag to every schedule on the agent, unfiltered and in both directions:
# src/backend/services/agent_service/autonomy.py:93-99
schedules = db.list_agent_schedules(agent_name)
for schedule in schedules:
schedule_id = schedule.id
if schedule_id:
db.set_schedule_enabled(schedule_id, enabled) # no filter, no memorySo per-schedule enabled intent is destroyed on the first toggle:
- A schedule the owner deliberately disabled is silently re-enabled the next time autonomy is turned on.
- A schedule's declared/authored
enabled: falseis equally erased. - There is no record of the prior per-schedule state, so turning autonomy off and back on is lossy — it is not a pause/resume, it is a set-all.
The agent-level autonomy flag and the per-schedule enabled flag are two different concepts sharing one write path. Only one of them survives.
Why this matters more now (trinity-enterprise#89)
ent#89 makes agent creation materialize a template's declared schedules: block (up to MAX_DECLARED_SCHEDULES = 20, and the reader accepts * * * * *). Before it, a newly created agent had zero schedules, so the clobber had nothing to clobber — you only met it after hand-creating schedules and hand-disabling some.
Now a single template choice can put 20 rows on a fresh agent, and one unrelated autonomy toggle arms all of them at once (~28,800 LLM turns/day at every-minute cadence, on the operator's own key). Verified end to end:
- reader accepts 20/20 entries at
cron: "* * * * *"withenabled: true - nothing fires while
agent_ownership.autonomy_enabled = 0— the scheduler gates on it (src/scheduler/service.py:844). This gate is what currently holds. - the toggle then enables all 20 unconditionally via the loop above
The capability is not new — there has never been a per-agent schedule cap, so 20 deliberate API calls always achieved the same. What changed is the friction: one template + one toggle.
This is also why ent#89 deliberately honors a declared enabled: true rather than forcing it off. Forcing False at creation would prevent nothing, because the first toggle overwrites the row either way. Fixing the clobber is the real control — for both the ent#89 path and the pre-existing manual one.
Acceptance criteria
- Enabling autonomy no longer enables schedules that were explicitly disabled by an owner (or authored disabled).
- Disabling autonomy no longer destroys per-schedule
enabledintent — re-enabling autonomy restores the prior per-schedule state rather than setting all. - The agent-level gate remains authoritative for whether anything fires at all (
autonomy_enabled = 0⇒ no cron fire, unchanged —src/scheduler/service.py:844). - Migration-safe for existing rows: agents whose per-schedule intent was already flattened must not change behavior on upgrade.
- Regression test naming this issue: disable one of two schedules → toggle autonomy off → toggle on → the disabled one is still disabled.
Design note
The likely shape is separating "paused by autonomy" from "disabled by the owner" rather than adding a snapshot/restore blob — a second boolean (or a disabled_by discriminator) on agent_schedules keeps the state explicit and survives an interrupted toggle. Either way this is a dual-track schema change (SQLite migrations.py and an Alembic revision, invariant #9) if a column is added, so an implementation that avoids new schema is worth weighing first.
References
src/backend/services/agent_service/autonomy.py:93-99— the unconditional loopdocs/memory/requirements/scheduling.md§10.16 → "Documented caveat (pre-existing, and the actual control)" — where ent#89 names this as the real guard and defers it heredocs/security-reports/cso-diff-2026-08-02-ent89-template-schedules.md— finding 1 (MEDIUM, LLM cost amplification), with the traced exploit path- trinity-enterprise#89 — the change that raised the blast radius
Activity
fix(autonomy): stop the toggle from erasing per-schedule enabled inte…
feat(templates): materialize a template's declared schedules: at agen…