Skip to content

bug: scheduler create_execution never populates execution origin columns #1970

Closed

Description

@vybe

Summary

schedule_executions carries five execution-origin columns for audit (source_user_id, source_user_email, source_agent_name, source_mcp_key_id, source_mcp_key_name), but the scheduler's create_execution() never writes them — they are NULL on every scheduler-created row. triggered_by records that a run was manual, but never who triggered it. Once server logs roll, "did anyone trigger this run, and who?" becomes unanswerable from the database.

This is an audit-completeness gap, not a vulnerability — no access control depends on these columns.

Component

Scheduler (database layer) / Backend (schedules router)

Priority

P2 — executions run correctly; the attribution metadata is simply absent.

Error

No error is raised. The failure is silent and only visible on inspection:

triggered_by         = manual
source_user_id       = NULL
source_user_email    = NULL
source_agent_name    = NULL
source_mcp_key_id    = NULL
source_mcp_key_name  = NULL

Observed as NULL across the entire execution history of an actively used schedule (100+ runs, mixed schedule and manual).

Location

  • File: src/scheduler/database.py
  • Line: 373 — create_execution()
  • Function: create_execution() — the INSERT column list omits all five source_* columns
cursor.execute("""
    INSERT INTO schedule_executions (
        id, schedule_id, agent_name, status, started_at, message, triggered_by,
        model_used, attempt_number, retry_of_execution_id
    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (...))

Root Cause

The columns exist in the schema and the backend's own database layer supports them (src/backend/database.py accepts source_user_id and siblings), but the scheduler is a separate service with its own DB module, and its create_execution() was never extended to match. Nor does the signature accept them — there is no parameter to thread a caller identity through:

def create_execution(
    self, schedule_id, agent_name, message,
    triggered_by="schedule", model_used=None,
    attempt_number=1, retry_of_execution_id=None,
) -> Optional[ScheduleExecution]:

The identity is available at the point of origin — the backend's trigger endpoint authenticates the caller (user or MCP key) before delegating — but it is dropped at the backend → scheduler hop, which forwards only schedule_id in the URL path.

Consequence: for cron-triggered runs NULL is correct and harmless. For triggered_by='manual' runs the attribution exists only in MCP-server / backend logs, bounded by log retention, so the durable record cannot answer who initiated a run.

Reproduction Steps

  1. Trigger any agent schedule manually (MCP trigger_agent_schedule, or the backend trigger endpoint) as an authenticated user or MCP key.
  2. Query the resulting row:
    SELECT triggered_by, source_user_id, source_user_email,
           source_agent_name, source_mcp_key_id, source_mcp_key_name
    FROM schedule_executions ORDER BY started_at DESC LIMIT 1;
  3. Observe triggered_by = 'manual' with all five source_* columns NULL.

Suggested Fix

Thread the authenticated caller from the backend trigger endpoint through to create_execution().

  1. src/backend/routers/schedules.py — forward the caller identity in the POST body to the scheduler's trigger endpoint (currently identity-free):
response = await client.post(
    f"{SCHEDULER_URL}/api/schedules/{schedule_id}/trigger",
    json={
        "source_user_id": current_user.id,
        "source_user_email": current_user.email,
        "source_mcp_key_id": mcp_key.id if mcp_key else None,
        "source_mcp_key_name": mcp_key.name if mcp_key else None,
    },
    timeout=10.0,
)
  1. src/scheduler/main.py — read that payload in _trigger_handler() and pass it down through _execute_manual_trigger().

  2. src/scheduler/database.py — accept the fields and include them in the INSERT:

def create_execution(
    self, schedule_id, agent_name, message,
    triggered_by="schedule", model_used=None,
    attempt_number=1, retry_of_execution_id=None,
    source_user_id=None, source_user_email=None,
    source_agent_name=None, source_mcp_key_id=None, source_mcp_key_name=None,
) -> Optional[ScheduleExecution]:

Cron-triggered runs keep passing NULL, which is the correct value for them.

Note this composes with the sibling issue on execution_id: undefined — both are fixed most cleanly by creating the execution record synchronously in _trigger_handler(), at which point the caller identity is still in scope. Worth sequencing them together.

Environment

  • Observed on a deployed instance running 1d3863d5
  • Confirmed still present at 4d743fdb (2026-07-27) — create_execution() INSERT column list is unchanged

Related

  • src/scheduler/database.py — create_execution()
  • src/backend/database.py — backend equivalent, which does accept source_*
  • src/backend/routers/schedules.py — manual trigger delegation (identity dropped here)
  • Sibling gaps in the same manual-trigger path filed separately (undefined execution_id; silent lock-denied cron tick)

Activity

  1. added
    priority-p2
    type-bug
    theme-security
    status-ready
    on Aug 3, 2026
  2. added
    status-in-progress
    and removed
    status-ready
    on Aug 4, 2026
  3. self-assigned this
    on Aug 4, 2026
  4. dolho commented on Aug 4, 2026

    @dolho
    Contributor

    /claim — picking this up. Branch: fix/1970-scheduler-execution-origin.

  5. github-actions commented on Aug 4, 2026

    @github-actions

    @dolho This issue is already assigned to dolho. Use /unclaim first if you want to take over.

  6. dolho commented on Aug 4, 2026

    @dolho
    Contributor

    PR: #1974

  7. added
    complexity-low
    on Aug 4, 2026
  8. added
    status-in-dev
    and removed
    status-in-progress
    on Aug 4, 2026
  9. removed
    status-in-dev
    on Aug 17, 2026
  10. added a commit that references this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p2theme-securitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions