Trellis icon indicating copy to clipboard operation
Trellis copied to clipboard

[Bug] task.py create and start silently replace an in-progress active task

Open cuipengcx90 opened this issue 4 months ago • 1 comments

Bug Description

task.py create and task.py start can silently replace the active task for a session even when the existing task is in_progress.

This is a platform-independent containment failure. In a Pi cross-window incident, an incorrect Trellis context key reached task.py; normal create then rewrote the other window's active pointer. The underlying Pi context-resolution bug is reported separately. This issue covers the lifecycle behavior that made that key-resolution failure destructive.

The current template auto-activates a newly created task in cmd_create (packages/cli/src/templates/trellis/scripts/common/task_store.py:432,470). cmd_start also directly calls set_active_task (packages/cli/src/templates/trellis/scripts/task.py:73,124). Neither command checks whether the current session already owns a nonterminal task, asks for an explicit task switch, or preserves state on conflict.

This is related to closed #397, which identified the surprising pointer move during batch creation. The remaining gap is more severe:

  • --no-start is opt-in, so ordinary create still switches the active pointer.
  • start has no equivalent opt-in/confirmation guard.
  • A wrong or inherited context key can therefore replace an unrelated in_progress task without any user-visible switch decision.

Steps to Reproduce

Use any Trellis project with a stable session context key:

export TRELLIS_CONTEXT_ID=repro-session

python3 ./.trellis/scripts/task.py create "Task A" --slug task-a --no-start
python3 ./.trellis/scripts/task.py start task-a
python3 ./.trellis/scripts/task.py current --source
# Expected current task before the conflict: .trellis/tasks/<date>-task-a

python3 ./.trellis/scripts/task.py create "Task B" --slug task-b
python3 ./.trellis/scripts/task.py current --source
# Actual: current task is now .trellis/tasks/<date>-task-b

Task A remains in_progress, but its session pointer has been replaced by planning Task B.

The same replacement happens when directly starting a planning task:

export TRELLIS_CONTEXT_ID=repro-session
python3 ./.trellis/scripts/task.py start task-b
python3 ./.trellis/scripts/task.py current --source
# Actual: current task remains Task B; no explicit switch was required.

In the observed incident, another Pi window held a different native Pi session ID but reached the same Trellis context key. Its normal task.py create replaced the active unified-permission task, and the original window subsequently received the other task's context.

Expected Behavior

Creating a new task must not silently abandon a session's existing nonterminal task.

Suggested contract:

  1. When the current session points to a planning, in_progress, or review-like task, task.py create creates the new task but preserves the existing pointer by default.
  2. task.py start <task> rejects a switch away from a different nonterminal task unless the caller passes an explicit --switch flag.
  3. On rejection, neither the active pointer nor either task's status changes.
  4. --switch makes the transition intentional and visible in command output.

An append-only transition record containing previous task, requested task, context key, timestamp, command, and explicit-switch flag would make future incidents auditable, but the minimum required behavior is preserving the existing task unless a switch is explicit.

Trellis Version

0.6.9

Node.js Version

v26.5.0

Operating System

macOS 15.0 (24A8332)

cuipengcx90 avatar Jul 31 '26 14:07 cuipengcx90

The Pi-specific root cause is now documented in #512. This issue intentionally remains the platform-independent containment layer: even after a wrong context key reaches task.py, normal create/start should not silently replace an in_progress task.

cuipengcx90 avatar Jul 31 '26 14:07 cuipengcx90