Skip to content

Processes are now tasks#2035

Merged
domenkozar merged 1 commit into
mainfrom
process-tasks
Jul 25, 2025
Merged

Processes are now tasks#2035
domenkozar merged 1 commit into
mainfrom
process-tasks

Conversation

@domenkozar

@domenkozar domenkozar commented Jul 24, 2025

Copy link
Copy Markdown
Member

Fixes #1471

Processes defined in processes are now automatically available as tasks with the devenv:processes: prefix. This enables running individual processes as tasks and defining dependencies between tasks and processes.

Future work is also supporting Health Checks: F1bonacc1/process-compose#371

{ pkgs, ... }: {
  processes.app-server.exec = "python -m http.server 8080";

  tasks = {
    "myapp:setup-data" = {
      exec = "echo 'Setting up data...'";
      before = [ "devenv:processes:app-server" ];
    };
    "myapp:cleanup" = {
      exec = ''
        echo "Server stopped, cleaning up..."
        rm -f ./server.pid
        rm -rf ./tmp/cache/*
      '';
      after = [ "devenv:processes:app-server" ];
    };
  };
}

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 24, 2025

Copy link
Copy Markdown

Deploying devenv with  Cloudflare Pages  Cloudflare Pages

Latest commit: 03e9657
Status: ✅  Deploy successful!
Preview URL: https://8c32867a.devenv.pages.dev
Branch Preview URL: https://process-tasks.devenv.pages.dev

View logs

@claude

claude Bot commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

Claude finished @domenkozar's task —— View job


Code Review Progress

  • Read and analyze all changed files
  • Review core implementation in processes.nix and process-compose.nix
  • Analyze task state handling in devenv-tasks
  • Review test coverage and documentation
  • Provide comprehensive review feedback

Review Feedback

Potential Bugs & Issues

1. Task Name Validation Missing (src/modules/processes.nix:142)

name = "devenv:processes:${name}";

Process names aren't validated for task name compatibility. Invalid characters (spaces, special chars) in process names could create malformed task names.

2. Namespace Collision Risk (src/modules/processes.nix:140-147)
The devenv:processes: prefix could conflict with user-defined tasks. Consider adding validation to prevent users from creating tasks with this reserved prefix.

3. Circular Dependency Detection Gap
No validation prevents circular dependencies between processes-as-tasks and regular tasks. A process could depend on a task that depends on the same process.

4. Process Arguments Lost (src/modules/process-managers/process-compose.nix:128-129)
The process-compose command construction doesn't preserve process-specific arguments when switching from direct execution to task execution. The is_elevated check partially addresses this but other arguments may be lost.

Performance Considerations

1. Added Execution Overhead (src/modules/process-managers/process-compose.nix:128)
Every process now goes through an extra layer (devenv-tasks run --mode all) instead of direct execution. This adds startup latency and memory overhead for each process.

2. Task Resolution on Every Process Start
Each process startup now triggers full task dependency resolution, even for processes without dependencies. Consider lazy evaluation or caching.

Code Quality & Best Practices

1. Magic String Detection (devenv-tasks/src/task_state.rs:293)

let is_process = self.task.name.starts_with("devenv:processes:");

Hardcoded string should be a constant or derived from the same source as the prefix in processes.nix:142.

2. Inconsistent Error Handling (devenv-tasks/src/task_state.rs:300-301,315-316)
Process output logging uses eprintln! directly instead of the structured logging used elsewhere in the function. Consider using the tracing framework consistently.

3. Task State Mutation (src/modules/processes.nix:139-147)
The task creation directly mutates config.tasks. Consider using lib.mkMerge or explicit merging to make the operation more transparent.

Security Concerns

1. Command Injection Potential (src/modules/processes.nix:151)

"${name}: exec ${config.task.package}/bin/devenv-tasks run --mode all devenv:processes:${name}"

Process names are directly interpolated into shell commands without escaping. Malicious process names could inject commands.

Test Coverage

1. Limited Edge Cases (tests/process-tasks/devenv.nix)
The test only covers basic before/after dependencies. Missing tests for:

  • Invalid process names
  • Circular dependencies
  • Process failure scenarios
  • Multiple processes with complex dependency chains
  • Process name collision with existing tasks

2. No Error Condition Testing
No tests verify error handling when tasks fail, processes crash, or dependencies can't be resolved.

Documentation

1. Migration Path Missing
Documentation doesn't explain potential breaking changes or migration steps for existing users with complex process setups.

2. Performance Impact Not Documented
Users aren't warned about the added execution overhead for processes.

Suggested Improvements

  1. Add process name validation in processes.nix
  2. Implement circular dependency detection
  3. Consider making the devenv:processes: prefix configurable
  4. Add comprehensive error handling tests
  5. Document performance implications
  6. Use constants for the task prefix string across files

Fixes #1471

Processes defined in `processes` are now automatically available as tasks
with the `devenv:processes:` prefix. This enables running individual
processes as tasks and defining dependencies between tasks and processes.

Future work is also supporting Health Checks: F1bonacc1/process-compose#371

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@domenkozar domenkozar merged commit 7d79ed9 into main Jul 25, 2025
251 of 277 checks passed
PetarKirov added a commit to blocksense-network/blocksense that referenced this pull request Sep 18, 2025
… breaking change

Devenv broke process-compose for flake-based projects with this change:
cachix/devenv#2035

The workaround is to set a default value for the `exec` option, as its
used here:
https://github.com/cachix/devenv/pull/2035/files#diff-7104fdcadefcb5687bbdaeda5d6db909155e0dc3f83f8d97ace3302590aa098eR144

Co-authored-by: reo101 <pavel.atanasov2001@gmail.com>
PetarKirov added a commit to blocksense-network/blocksense that referenced this pull request Sep 18, 2025
…es are now tasks"

Devenv broke process-compose for flake-based projects with this change:
cachix/devenv#2035

The workaround is to set a default value for the `exec` option, as its
used here:
https://github.com/cachix/devenv/pull/2035/files#diff-7104fdcadefcb5687bbdaeda5d6db909155e0dc3f83f8d97ace3302590aa098eR144

Co-authored-by: reo101 <pavel.atanasov2001@gmail.com>
PetarKirov added a commit to blocksense-network/blocksense that referenced this pull request Sep 18, 2025
…es are now tasks"

Devenv broke process-compose for flake-based projects with this change:
cachix/devenv#2035

The workaround is to set a default value for the `exec` option, as its
used here:
https://github.com/cachix/devenv/pull/2035/files#diff-7104fdcadefcb5687bbdaeda5d6db909155e0dc3f83f8d97ace3302590aa098eR144

Co-authored-by: reo101 <pavel.atanasov2001@gmail.com>
PetarKirov added a commit to blocksense-network/blocksense that referenced this pull request Sep 18, 2025
…es are now tasks"

Devenv broke process-compose for flake-based projects with this change:
cachix/devenv#2035

The workaround is to set a default value for the `exec` option, as its
used here:
https://github.com/cachix/devenv/pull/2035/files#diff-7104fdcadefcb5687bbdaeda5d6db909155e0dc3f83f8d97ace3302590aa098eR144

Co-authored-by: reo101 <pavel.atanasov2001@gmail.com>
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.

Generalize tasks to processes

1 participant