Reschedule a branch#

Reschedule one task and the work that depends on it, and leave the rest of the project where it is.

The scope is the task you name, its subtree, and its successors through links. Tasks outside the scope keep their dates.

Steps#

  1. Set subtree in the solve options to the task the branch starts from:

    const options = { subtree: { task: "design" } };
    
  2. Pass the options to project.solve. Pass your data on the first load, or null to reschedule the current state:

    const result = project.solve(null, options);
    
  3. Write the entries of result.updates back to your model. Each entry is a task in the scope that moved. The scoped dates become the accepted baseline.

The full example has two independent chains, backend → api and design → ui. Both successors start too early. The scoped solve fixes only the design branch:

import { Project } from "plen-js";

const data = {
  // 24/7 time keeps the example dates easy to check.
  config: { use_calendars: false },
  tasks: [
    { id: "backend", start_date: "2026-01-01 00:00", duration: 2 },
    { id: "api", start_date: "2026-01-01 00:00", duration: 1 },
    { id: "design", start_date: "2026-01-01 00:00", duration: 3 },
    { id: "ui", start_date: "2026-01-01 00:00", duration: 1 },
  ],
  links: [
    { id: "l1", source: "backend", target: "api", type: "fs" },
    { id: "l2", source: "design", target: "ui", type: "fs" },
  ],
};

const project = new Project();
const result = project.solve(data, { subtree: { task: "design" } });

for (const update of result.updates) {
  console.log(`${update.id} ${update.start_date}..${update.end_date}`);
}

Preview a branch#

To see what rescheduling a branch would do without changing the project, set the same subtree in the options of project.preview:

const preview = project.preview({}, { subtree: { task: "backend" } });

The preview scope applies to that call only. It doesn't touch the baseline or the cached solve result. A preview scope can also name a task that the same changes add.

Things to know#

  • Tasks outside the scope don't move until you solve them. In the example, the next project.solve(null) moves only api, because ui is already accepted.
  • The result cache is keyed on the whole options object. A different subtree replans from the accepted dates. The same subtree again returns the cached result without scheduling.
  • With includeUnchanged, a scoped solve reports every task in the scope, plus the out-of-scope tasks a sparse scoped solve would report.
  • On a project with a dependency cycle, nothing is scheduled, scoped or not. Check result.cycles.
  • An unknown or unscheduled task in subtree.task throws an InputError with path "subtree.task" and message unknown or unscheduled scope task. The project keeps its previous state and cached result. See Error handling.

Result#

The example prints one line. Only ui moves, to start after design ends. api still overlaps backend:

ui 2026-01-04 00:00..2026-01-05 00:00

Without subtree, the same solve also moves api to 2026-01-03 00:00.