Skip to content

[Bug] Windows Task Scheduler: "Ghost Jobs" due to Directory-Based Scoping and Missing CLI Prompt Arguments #13

Description

@danieliyahu1

After discussion with gemini this is what he told me:

Description:
I have encountered an issue where jobs created via the Windows Task Scheduler backend appear to be "Ready" in the OS but fail to produce results and are inaccessible via the opencode agent. There appear to be two underlying causes:

Scope ID Desync: Jobs are isolated based on a hash of the Current Working Directory (process.cwd()). Moving between IDEs (e.g., VS Code to IntelliJ) or subfolders causes jobs to "disappear."

Invalid CLI Syntax: The generated schtasks command is missing the required prompt/command arguments after the -- separator, leading to execution errors.

Environment:
OS: Windows 10/11

Plugin: opencode-scheduler

Backend: schtasks

Steps to Reproduce:
Open a terminal in a specific project directory.

Schedule a job: Schedule a task every 10 minutes to [Task Description].

The agent reports success, and Get-ScheduledTask shows the task in Windows.

Change the terminal directory (e.g., move into a subfolder) or open the project in a different IDE.

Run list_jobs or get_job [Name].

Actual Behavior:
Scope Issue: The job is missing from get_job or appears as a "ghost" because the deriveScopeId(process.cwd()) has changed.

Execution Issue: When the task runs in Windows, it triggers the following error:
Error: You must provide a message or a command

Checking the Windows Task Action, the arguments are:
run --title "My Task Title"
(Note: It is missing the -- "[Prompt]" part required by the CLI).

Technical Analysis (from Plugin Source):

  1. Directory-Based Scoping Logic:
    In the current implementation, currentScopeId() relies on process.cwd():

TypeScript
function currentScopeId(): string {
return deriveScopeId(process.cwd())
}
If a user switches from a root project folder to a subfolder, the scopeId changes, and the plugin can no longer locate the .json job definition in ~/.config/opencode/scheduler/scopes/[ID]/jobs, even though the task still exists in Windows.

  1. Incomplete Invocation Snapshot:
    In buildOpencodeArgs, if the agent doesn't pass a specific prompt or command during the schedule_job call, the CLI command generated for Windows is invalid.
    The Windows Task Scheduler runs:
    opencode run --title "Task Name"
    But the CLI expects:
    opencode run --title "Task Name" -- "My Prompt Instructions"

Suggested Fixes:
Scope Persistence: Allow the user to define a static scopeId in a config file or environment variable to prevent jobs from "disappearing" when moving between directories.

Argument Validation: Ensure buildOpencodeArgs throws a validation error if the resulting command doesn't include a prompt or a command, preventing "Ready but empty" tasks in Windows.

Path Normalization: Consider using the project root (if inside a Git repo) instead of process.cwd() to derive the Scope ID.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions