Skip to content

feat(scheduled-tasks): migrate jobs agent to scheduled tasks agent#5090

Merged
Sg312 merged 6 commits into
stagingfrom
dev
Jun 16, 2026
Merged

feat(scheduled-tasks): migrate jobs agent to scheduled tasks agent#5090
Sg312 merged 6 commits into
stagingfrom
dev

Conversation

@Sg312

@Sg312 Sg312 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds scheduled tasks agent
Companion: https://github.com/simstudioai/copilot/pull/313

Type of Change

  • New feature

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

waleedlatif1 and others added 6 commits June 15, 2026 20:24
Adds a new `scheduledtask` resource type so a scheduled task can be opened
and viewed as a tab in Chat:
- registry config (Calendar icon, label, tab/dropdown renderers)
- add-resource dropdown listing (workspace jobs)
- embedded detail viewer (status, schedule, next/last run, prompt, recent runs)
- "Open in scheduled tasks" action + query invalidation
- contract enum + route validation so the resource persists

Agent-side mention/OpenResource wiring is left as a follow-up.
…sistence

Dedupes the placeholder-title set that the chat-resource route and the
server-side persistence merge each defined separately. They had already
drifted ('Log' was missing from persistence); a single shared
GENERIC_RESOURCE_TITLES keeps title-upgrade behavior consistent, including
the new 'Scheduled Task' placeholder.
…task viewer

- Render a 'couldn't load' state when the schedules query errors, instead of
  falsely claiming the task was deleted (uses React Query isError)
- Use a stable composite key for jobHistory rows so same-second timestamps
  don't collide
Adds a first-class 'scheduledtask' ChatContext kind so a scheduled-task
resource maps to a real context (not a generic docs fallback), fixing the
exhaustive RESOURCE_TO_CONTEXT map that broke the build:
- ChatContext union + CHAT_CONTEXT_KIND_REGISTRY (Calendar chip)
- resource→context mapping, context validity check, clipboard portability

Agent-side consumption of the kind remains a follow-up.
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jun 16, 2026 3:53am

Request Review

@github-actions github-actions Bot added the requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep label Jun 16, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Cross-repo companion check

One or more companion PRs aren't merged into staging yet. Merging this without them will leave copilot and sim out of sync — merge them in lockstep.

  • simstudioai/copilot#313OPEN, not merged (targets staging) — feat(scheduled-tasks): migrate job system to scheduled tasks

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR migrates the "jobs agent" to a "scheduled tasks agent" by renaming the underlying tool identifiers (jobscheduled_task, manage_jobmanage_scheduled_task, complete_jobcomplete_scheduled_task, etc.) throughout the copilot stack, and surfaces the new scheduledtask resource type end-to-end in the mothership view.

  • Tool rename: Generated catalog and schema entries for ManageJob, CompleteJob, UpdateJobHistory, and GetJobLogs are replaced by their ScheduledTask-prefixed equivalents; handler dispatch in register-handlers.ts is updated accordingly while the underlying executor functions remain unchanged.
  • Resource system extension: scheduledtask is added as a recognized MothershipResourceType with extraction, deletion detection, invalidation, chip-codec, and context-registry support; the shared GENERIC_RESOURCE_TITLES set is extracted to types.ts to avoid duplication.
  • UI: New EmbeddedScheduledTask display component and EmbeddedScheduledTaskActions are added; backward-compatibility aliases (job, Job Agent) are retained in SUBAGENT_LABELS and TOOL_UI_METADATA so historical transcripts still render correct labels.

Confidence Score: 5/5

Safe to merge — the rename is consistent across all layers and backward-compat aliases are in place for historical transcripts.

The tool rename is applied consistently from the generated catalog, handler registration, schedule-execution prompt builder, and wasCompletedByTool check through to the UI display titles and resource extraction logic. The underlying executor functions are reused unchanged, so no behavioral regression is introduced. Backward-compat aliases for job and Job Agent are retained in SUBAGENT_LABELS and TOOL_UI_METADATA so old chat transcripts continue to render correctly. The new scheduledtask resource type is wired up completely — type enum, extraction, deletion detection, invalidation, chip codec, context registry, and the embedded display component — with matching test coverage added.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tool-executor/register-handlers.ts Tool IDs updated to new scheduled-task names; underlying executor functions (executeManageJob, executeCompleteJob, executeUpdateJobHistory) are reused unchanged — the mapping is correct.
apps/sim/lib/copilot/resources/extraction.ts ManageScheduledTask added to both extraction and deletion logic; read-only ops correctly return []; delete op naturally returns [] from extractResourcesFromToolResult (no jobId in delete result), while extractDeletedResourcesFromToolResult handles it via result.deleted[].
apps/sim/background/schedule-execution.ts wasCompletedByTool check updated to complete_scheduled_task; buildJobPrompt prompts are updated so all future executions (including existing until_complete jobs) will use the new tool name.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx EmbeddedScheduledTask and EmbeddedScheduledTaskActions added; component fetches all workspace schedules and finds by ID, consistent with other embedded resource components.
apps/sim/lib/copilot/resources/types.ts scheduledtask added to MothershipResourceType; GENERIC_RESOURCE_TITLES extracted as a shared constant, eliminating the duplicated local Set definitions in persistence.ts and route.ts.
apps/sim/lib/copilot/tools/handlers/resources.ts resolveResource extended for scheduledtask: verifies workspaceId, queries workflowSchedule filtered by sourceType='job' and isNull(archivedAt) — correct authorization boundary.
apps/sim/app/workspace/[workspaceId]/home/types.ts ScheduledTask added to TOOL_UI_METADATA and SUBAGENT_LABELS; backward-compat job alias retained for historical transcripts — well-handled migration.
apps/sim/lib/copilot/resources/persistence.ts Local GENERIC set replaced with imported GENERIC_RESOURCE_TITLES; deduplication logic unchanged.
apps/sim/app/workspace/[workspaceId]/home/hooks/stream/stream-helpers.ts ManageJob/ManageJobOperation replaced by ManageScheduledTask/ManageScheduledTaskOperation in both resolveToolDisplayTitle and resolveStreamingToolDisplayTitle; display strings updated to 'scheduled task' variants.
apps/sim/lib/copilot/resources/extraction.test.ts New test cases added for create, update, list/get (no-op), delete extraction, and non-delete deletion guard — good coverage of the new ManageScheduledTask extraction path.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Agent as Scheduled Task Agent
    participant Exec as schedule-execution.ts
    participant Tools as register-handlers.ts
    participant DB as workflowSchedule DB
    participant UI as EmbeddedScheduledTask

    Exec->>Agent: buildJobPrompt (instructs to call manage_scheduled_task / complete_scheduled_task)
    Agent->>Tools: manage_scheduled_task (create/update/delete)
    Tools->>DB: executeManageJob handler
    DB-->>Tools: "{ jobId, title, ... }"
    Tools-->>Agent: result

    Agent->>Tools: complete_scheduled_task (if until_complete lifecycle)
    Tools->>DB: executeCompleteJob handler
    DB-->>Tools: "{ completed: true }"

    Exec->>Exec: "wasCompletedByTool = toolCalls.some(tc => tc.name === 'complete_scheduled_task')"

    Note over Exec: extractResourcesFromToolResult reads jobId from result
    Exec->>UI: "{ type: 'scheduledtask', id: jobId, title }"

    UI->>DB: useWorkspaceSchedules(workspaceId)
    DB-->>UI: schedules[]
    UI-->>UI: "find(s => s.id === scheduleId) → render details"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Agent as Scheduled Task Agent
    participant Exec as schedule-execution.ts
    participant Tools as register-handlers.ts
    participant DB as workflowSchedule DB
    participant UI as EmbeddedScheduledTask

    Exec->>Agent: buildJobPrompt (instructs to call manage_scheduled_task / complete_scheduled_task)
    Agent->>Tools: manage_scheduled_task (create/update/delete)
    Tools->>DB: executeManageJob handler
    DB-->>Tools: "{ jobId, title, ... }"
    Tools-->>Agent: result

    Agent->>Tools: complete_scheduled_task (if until_complete lifecycle)
    Tools->>DB: executeCompleteJob handler
    DB-->>Tools: "{ completed: true }"

    Exec->>Exec: "wasCompletedByTool = toolCalls.some(tc => tc.name === 'complete_scheduled_task')"

    Note over Exec: extractResourcesFromToolResult reads jobId from result
    Exec->>UI: "{ type: 'scheduledtask', id: jobId, title }"

    UI->>DB: useWorkspaceSchedules(workspaceId)
    DB-->>UI: schedules[]
    UI-->>UI: "find(s => s.id === scheduleId) → render details"
Loading

Reviews (2): Last reviewed commit: "fix(scheduled-tasks): open on edit/creat..." | Re-trigger Greptile

@Sg312

Sg312 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

@greptile

Comment on lines +224 to +227
case ManageScheduledTask.id: {
// Read-only ops never auto-open; only create/update surface the task.
const op = getOperation(params)
if (op === 'list' || op === 'get') return []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Explicitly excluding the delete operation prevents the UI from attempting to auto-open a deleted scheduled task if the API response shape ever changes to include a jobId field alongside the deleted array. Currently it works because the delete handler returns { deleted, notFound } with no jobId, but the intent is clearer and safer with an explicit guard.

Suggested change
case ManageScheduledTask.id: {
// Read-only ops never auto-open; only create/update surface the task.
const op = getOperation(params)
if (op === 'list' || op === 'get') return []
case ManageScheduledTask.id: {
// Read-only ops never auto-open; only create/update surface the task.
const op = getOperation(params)
if (op === 'list' || op === 'get' || op === 'delete') return []

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@Sg312 Sg312 merged commit 91666b5 into staging Jun 16, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-mothership-merge Has a companion PR on the mothership/copilot side — merge in lockstep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants