Repository navigation
feat(automations): add foundation — types, storage, scheduler, leader election - #323745
Merged
Ben Villalobos (benvillalobos) merged 10 commits intoJun 30, 2026
Merged
Conversation
…, leader election Introduces the Automations subsystem core: - IAutomation types and IAutomationSchedule (interval-based: manual/hourly/daily/weekly) - DST-safe computeNextRunAt scheduling logic - IAutomationService with persistent JSON ledger (StorageScope.APPLICATION) - Optimistic concurrency via revision counter for cross-window safety - Leader election to ensure single scheduler instance across windows - AutomationScheduler: periodic tick loop checking due automations - Feature gate: chat.automations.enabled setting mirrored to context key - Unit tests for scheduling logic Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces the foundational infrastructure for Chat Automations (scheduled agentic tasks) across the workbench and sessions layers, including domain types, schedule computation, persistence, scheduling with leader election, telemetry hooks, and unit tests. It wires the feature behind chat.automations.enabled and sets up the core scheduler/leader election mechanics for multi-window safety.
Changes:
- Added Automations domain model + schedule math (
computeNextRunAt) with DST-aware local wall-clock semantics and tests. - Added service contracts (workbench) and sessions-layer implementation for persistent storage + run ledger, including optimistic revisioning.
- Added sessions-layer scheduler + leader election and registered contributions/settings, plus unit tests for scheduler/election/service.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/common/automations/schedule.test.ts | Adds unit tests for schedule computation including DST edge cases. |
| src/vs/workbench/contrib/chat/common/automations/schedule.ts | Implements DST-aware next-run computation and localized day-of-week labels. |
| src/vs/workbench/contrib/chat/common/automations/automationTelemetry.ts | Defines GDPR-classified telemetry events for Automations lifecycle and runs. |
| src/vs/workbench/contrib/chat/common/automations/automationSessionTypes.ts | Adds workbench-side bridge interface for enumerating session types per folder. |
| src/vs/workbench/contrib/chat/common/automations/automationService.ts | Introduces the Automations service contract (CRUD + run ledger operations). |
| src/vs/workbench/contrib/chat/common/automations/automationsEnabled.ts | Defines settings/constants + context key for feature gating and run timeout default. |
| src/vs/workbench/contrib/chat/common/automations/automationRunner.ts | Adds runner contract (IAutomationRunner) for executing an automation run. |
| src/vs/workbench/contrib/chat/common/automations/automationDialogService.ts | Adds workbench-to-sessions dialog service bridge interface for future UI. |
| src/vs/workbench/contrib/chat/common/automations/automation.ts | Adds core domain types: automation, schedule, run status/trigger. |
| src/vs/sessions/sessions.common.main.ts | Registers the Automations contribution in the sessions entrypoint. |
| src/vs/sessions/contrib/automations/test/browser/automationService.test.ts | Adds unit tests for the sessions-layer AutomationService persistence/ledger semantics. |
| src/vs/sessions/contrib/automations/test/browser/automationScheduler.test.ts | Adds scheduler-core tests (leadership, catch-up, timeout, toggle behavior). |
| src/vs/sessions/contrib/automations/test/browser/automationLeaderElection.test.ts | Adds leader election tests (staleness, disposal, TOCTOU readback, error paths). |
| src/vs/sessions/contrib/automations/browser/automationService.ts | Implements persistent storage-backed AutomationService with observables and revisioning. |
| src/vs/sessions/contrib/automations/browser/automationScheduler.ts | Implements scheduler core with leader gating, crash recovery, and per-run timeout handling. |
| src/vs/sessions/contrib/automations/browser/automations.contribution.ts | Registers DI singletons, settings, context-key mirroring, and a toggle command contribution. |
| src/vs/sessions/contrib/automations/browser/automationLeaderElection.ts | Implements storage-backed multi-window leader election with heartbeat + TOCTOU nonce guard. |
Review details
- Files reviewed: 17/17 changed files
- Comments generated: 6
- Review effort level: Low
- Add _unsupportedSchema guard to recordRunStart and updateRun - Localize CRASH_RECOVERY_REASON string via nls.localize() - Move imports above registerSingleton call in contribution file - Fix test comment referencing wrong helper name (buildLocalDate -> localDate)
- Add _unsupportedSchema guard to markStaleRunsFailed and advanceNextRunAt - Replace boolean telemetry flags with actual enum values (permissionLevel, isolationMode) - Remove hasProviderId, hasSessionTypeId, hasModelId, hasMode, hasPermissionLevel flags - Add scope: ConfigurationScope.MACHINE to runTimeoutMinutes setting
AutomationSchedulerCore (and its leader election heartbeat/storage writes) are now only constructed when the feature setting is enabled. Uses MutableDisposable for clean teardown on runtime toggle. Addresses CCR feedback: avoid 30s heartbeat timer + storage writes when the feature is disabled.
Wrap advanceNextRunAt + runOneWithTimeout in try/catch so a failure in one automation does not abort dispatch of remaining due automations.
Adds vs/sessions/contrib/automations to the translation resources so nls.localize calls pass the eslint translation-remind rule.
- Normalize permissionLevel/isolationMode in createAutomation and mergeAutomation: reject unknown values to keep persisted data and GDPR-classified telemetry low-cardinality. - Wrap persist() storage read and write in try/catch so storage failures degrade gracefully instead of breaking the scheduler.
…al dispatch - Move scheduler registration from AfterRestored to Eventually — background concern that doesn't need to block workbench restore. - Remove re-read-before-write in persist() — refreshFromStorage via onDidChangeValue already handles cross-window sync. Eliminates redundant JSON.parse on every mutation and the misleading optimistic concurrency check that overwrote anyway. - Document that _pendingRuns serializes dispatch intentionally.
Replace all em dashes with periods or semicolons. Remove TOCTOU acronym. Replace multiplication sign with plain x.
Ben Villalobos (benvillalobos)
force-pushed
the
bv/automations-1-foundation
branch
from
June 30, 2026 20:53
26eaa02 to
67d6a9e
Compare
Ben Villalobos (benvillalobos)
marked this pull request as ready for review
June 30, 2026 21:14
Ben Villalobos (benvillalobos)
enabled auto-merge (squash)
June 30, 2026 21:14
Ben Villalobos (benvillalobos)
disabled auto-merge
June 30, 2026 21:14
Ben Villalobos (benvillalobos)
enabled auto-merge (squash)
June 30, 2026 21:17
Ben Villalobos (benvillalobos)
disabled auto-merge
June 30, 2026 23:18
roblourens
approved these changes
Jun 30, 2026
This was referenced Jul 1, 2026
Merged
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automations PR 1 (Foundation)
Context
This is the first PR in a 4-part stack that adds Automations to VS Code, scheduled agentic tasks that run Copilot prompts against a workspace on a recurring cadence (manual, hourly, daily, weekly). Local-only for now.
This PR lays the infrastructure: types, persistent storage, a multi-window-safe scheduler with leader election, and the runner contract.
Gated behind
chat.automations.enabled(machine-scoped).Architecture
classDiagram class IAutomation { +id: string +name: string +prompt: string +schedule: IAutomationSchedule +enabled: boolean +folderUri: URI +nextRunAt?: Date } class AutomationService { +automations: IObservable~IAutomation[]~ +runs: IObservable~IAutomationRun[]~ +create() / update() / delete() +recordRunStart() / updateRun() -storage: IStorageService } class AutomationScheduler { -tick every 60s (leader only) +dispatchDue(trigger) +markStaleRunsFailed() -runOneWithTimeout() } class AutomationLeaderElection { +isLeader: IObservable~boolean~ -heartbeat every 30s -stale threshold: 90s -TOCTOU nonce guard } class IAutomationRunner { +runOnce(automation, trigger, windowId, token) } AutomationScheduler --> AutomationLeaderElection : checks leadership AutomationScheduler --> AutomationService : reads due automations AutomationScheduler --> IAutomationRunner : dispatches runs AutomationService --> IStorageService : persists (APPLICATION scope)Scheduler Flow
sequenceDiagram participant S as Scheduler (60s tick) participant L as LeaderElection participant AS as AutomationService participant R as Runner S->>L: isLeader? alt not leader S-->>S: skip tick else leader S->>AS: get enabled automations where nextRunAt ≤ now loop each due automation S->>AS: advanceNextRunAt(id) [preemptive bump] S->>R: runOnce(automation, trigger, token) R->>AS: recordRunStart → updateRun(running) R-->>R: send prompt via sessions layer R->>AS: updateRun(completed/failed) end endIncludes tests for schedule math (DST edge cases, all cadences).
Design Decisions