shareAI-lab/learn-claude-code · error · ValueError

Assignment for {owner} is no longer active

Error message

Assignment for {owner} is no longer active

What it means

While resolving an owner's working directory, the system loads the task recorded in the owner's assignment lease and requires it to still be owned by that owner with status 'in_progress' or 'completed'. If the task was reassigned, reset to 'pending', or otherwise mutated, the lease is stale and ValueError is raised rather than silently returning the wrong cwd.

Source

Thrown at s13_agent_teams/code.py:404

    path, error = _registered_worktree(task.worktree)
    return (path or WORKDIR), error


def assignment_cwd(owner: str) -> Path:
    with task_lock:
        assignment = teammate_assignments.get(owner)
        task = _owner_in_progress(owner)
        if task and (not assignment or assignment.get("task_id") != task.id):
            cwd, error = task_worktree_cwd(task)
            if error:
                raise ValueError(error)
            assignment = {"task_id": task.id, "cwd": cwd}
            teammate_assignments[owner] = assignment
        elif not assignment:
            return WORKDIR
        task = load_task(str(assignment["task_id"]))
        if task.status not in {"in_progress", "completed"} or task.owner != owner:
            raise ValueError(f"Assignment for {owner} is no longer active")
        cwd, error = task_worktree_cwd(task)
        if error:
            raise ValueError(error)
        if cwd.resolve() != Path(assignment["cwd"]).resolve():
            raise ValueError(f"Assignment cwd changed for task {task.id}")
        return cwd


def release_completed_assignment(owner: str) -> bool:
    """Release a completed cwd lease only at a model turn boundary."""
    with task_lock:
        assignment = teammate_assignments.get(owner)
        if not assignment:
            return False
        task = load_task(str(assignment["task_id"]))
        if task.status != "completed" or task.owner != owner:
            return False
        teammate_assignments.pop(owner, None)

View on GitHub (pinned to 985456f4ad)

Solutions

  1. When reassigning or resetting a task, also clear the previous owner's entry in teammate_assignments (call release_completed_assignment or drop the lease) in the same locked section.
  2. Catch this ValueError in the owner loop and have the owner fall back to the main WORKDIR and re-claim work.
  3. Avoid hand-editing task owner/status for assigned tasks.

Example fix

# before (reassign without dropping lease)
task.owner = new_owner
save_task(task)  # old owner's next cwd_for() raises

# after
with task_lock:
    task.owner = new_owner
    save_task(task)
    teammate_assignments.pop(old_owner, None)
Defensive patterns

Strategy: fallback

Validate before calling

def assignment_active(owner: str) -> bool:
    with task_lock:
        a = teammate_assignments.get(owner)
        if not a:
            return False
        try:
            t = load_task(str(a['task_id']))
        except ValueError:
            return False
        return t.owner == owner and t.status in {'in_progress', 'completed'}

Try / catch

try:
    cwd = owner_cwd(owner)
except ValueError as exc:
    if 'no longer active' in str(exc):
        with task_lock:
            teammate_assignments.pop(owner, None)  # drop stale lease
        cwd = WORKDIR  # fall back to main workspace this turn
    else:
        raise

Prevention

When it happens

Trigger: A teammate's in-progress task is reassigned to another agent or its status reset to 'pending' while its assignment lease still points at it; the task JSON is hand-edited; a test resets task state without clearing teammate_assignments.

Common situations: Rebalancing work between agents mid-run; manual intervention in .tasks/; restart flows that reload tasks but not assignment leases.

Related errors


AI-assisted analysis of shareAI-lab/learn-claude-code@985456f4ad (2026-08-14). Data as JSON: /api/errors/701757c72fe6a5ed. Report an issue: GitHub.