Skip to content

set_autonomy_status erases per-schedule enabled intent (force-enables every schedule) #1945

Closed

Description

@AndriiPasternak31

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 memory

So 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: false is 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: "* * * * *" with enabled: 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

  1. Enabling autonomy no longer enables schedules that were explicitly disabled by an owner (or authored disabled).
  2. Disabling autonomy no longer destroys per-schedule enabled intent — re-enabling autonomy restores the prior per-schedule state rather than setting all.
  3. The agent-level gate remains authoritative for whether anything fires at all (autonomy_enabled = 0 ⇒ no cron fire, unchanged — src/scheduler/service.py:844).
  4. Migration-safe for existing rows: agents whose per-schedule intent was already flattened must not change behavior on upgrade.
  5. 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 loop
  • docs/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 here
  • docs/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

  1. added
    priority-p2
    type-bug
    theme-reliability
    complexity-medium
    on Aug 2, 2026
  2. added
    status-in-progress
    on Aug 3, 2026
  3. self-assigned this
    on Aug 3, 2026
  4. added
    status-in-dev
    and removed
    status-in-progress
    on Aug 3, 2026
  5. removed
    status-in-dev
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-mediumpriority-p2theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions