Skip to content

feat(tasks): run lifecycle script on task creation#1888

Open
Godzilaa wants to merge 1 commit intogeneralaction:mainfrom
Godzilaa:ghostpatch/generalaction-emdash-1756
Open

feat(tasks): run lifecycle script on task creation#1888
Godzilaa wants to merge 1 commit intogeneralaction:mainfrom
Godzilaa:ghostpatch/generalaction-emdash-1756

Conversation

@Godzilaa
Copy link
Copy Markdown

@Godzilaa Godzilaa commented May 5, 2026

  • Adds a create-task checkbox to run the configured Run lifecycle script after provisioning.
  • Threads runScriptOnCreate through task creation params.
  • Starts the existing lifecycle runner in the main process and logs failures without blocking task creation.

Validation passed: pnpm run format:check, pnpm run typecheck, pnpm run lint, pnpm run test

…-task checkbox to run the configured Run lifecycle script after provisioning.\n- Threads runScriptOnCreate through task creation params.\n- Starts the existing lifecycle runner in the main process and logs failures without blocking task creation.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Greptile Summary

This PR adds a "Run script after task creation" toggle to the Create Task modal that fires the project's configured run lifecycle script immediately after a task is provisioned, without blocking task creation on the result.

  • src/shared/tasks.ts adds an optional runScriptOnCreate boolean to CreateTaskParams.
  • create-task-modal.tsx reads the project's run script setting via getProjectSettingsStore, conditionally renders the Switch, and passes runScriptOnCreate && hasRunScript through all three creation strategies.
  • createTask.ts fires runLifecycleScript with void after provisioning and captures any error with a log.warn, ensuring failures do not surface to the user.

Confidence Score: 4/5

Safe to merge; the change is additive and existing guards prevent any unintended script execution.

The implementation is clean and the double guard prevents accidental execution. The trade-off worth noting is that when both the run script and an initial conversation are provided, the script executes concurrently with the agent rather than before it.

src/main/core/tasks/operations/createTask.ts — the ordering of the lifecycle script relative to createConversation is worth a second look for use cases where runScriptOnCreate and initialConversation are both set.

Important Files Changed

Filename Overview
src/main/core/tasks/operations/createTask.ts Adds non-blocking lifecycle script invocation after provisioning; workspaceId access is safe, error is caught and logged, but the script races with any initialConversation that is also provided.
src/renderer/features/tasks/create-task-modal/create-task-modal.tsx Adds runScriptOnCreate switch, gated behind hasRunScript, correctly threaded through all three creation strategies and reset on project change.
src/shared/tasks.ts Adds optional runScriptOnCreate field to CreateTaskParams; additive, non-breaking change.

Sequence Diagram

sequenceDiagram
    participant UI as CreateTaskModal
    participant TM as taskManager
    participant LS as runLifecycleScript
    participant CC as createConversation

    UI->>TM: createTask(params)
    TM->>TM: provisionTask(project, task)
    TM-->>UI: provisionResult

    alt params.runScriptOnCreate
        TM-)LS: void runLifecycleScript({ type: 'run' }) [fire-and-forget]
    end

    alt params.initialConversation
        TM->>CC: await createConversation(...)
        CC-->>TM: done
    end

    Note over TM,LS: Script and conversation can run concurrently
Loading

Comments Outside Diff (1)

  1. src/main/core/tasks/operations/createTask.ts, line 231-254 (link)

    P2 Lifecycle script races with initial conversation

    runLifecycleScript is fired-and-forgotten, then createConversation is await-ed immediately after. When both runScriptOnCreate and initialConversation are set, the AI agent can begin executing commands in the workspace while the run script is still running. If the run script configures the environment (e.g., installs dependencies or starts a service the agent needs), the agent may encounter a partially initialised workspace on startup.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/main/core/tasks/operations/createTask.ts
    Line: 231-254
    
    Comment:
    **Lifecycle script races with initial conversation**
    
    `runLifecycleScript` is fired-and-forgotten, then `createConversation` is `await`-ed immediately after. When both `runScriptOnCreate` and `initialConversation` are set, the AI agent can begin executing commands in the workspace while the `run` script is still running. If the run script configures the environment (e.g., installs dependencies or starts a service the agent needs), the agent may encounter a partially initialised workspace on startup.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/main/core/tasks/operations/createTask.ts:231-254
**Lifecycle script races with initial conversation**

`runLifecycleScript` is fired-and-forgotten, then `createConversation` is `await`-ed immediately after. When both `runScriptOnCreate` and `initialConversation` are set, the AI agent can begin executing commands in the workspace while the `run` script is still running. If the run script configures the environment (e.g., installs dependencies or starts a service the agent needs), the agent may encounter a partially initialised workspace on startup.

Reviews (1): Last reviewed commit: "feat(tasks): run lifecycle script on tas..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant