Skip to content

statechart scripts: process cleanup, edge labels, and SANY error paths #1338

Backlog

Description

@kyro2606

Summary. A review of a copy of pstack/skills/statechart/scripts at ca782ed found seven defects. None of them is a security defect. Most of them are in the cleanup paths, where a stop or a failure can leave a process or a folder behind.

Items.

  1. kill.ts:12, process.kill(-pid, "SIGKILL"), and janitor.ts:12: on POSIX, the parent and the janitor kill the process group by its number also after the worker exits. The OS can give that number to a new process group.
  2. kill.ts:6 starts taskkill /pid <pid> /t /f and ignores its result. When the stop fails on Windows, the caller can wait until the worker ends.
  3. backends/mermaid.ts:100 and :123: drawnEdges joins the entry arrows into one composite state only when they have the same source (wayIn). When it joins two or more arrows, it drops the label of the outer arrow, also when the labels are equal. The labels go to the inner arrows.
  4. run.ts:243, sanyErrors, and run.ts:314-324: when the XML export of SANY exits with an error code (not a launch error), the script runs SANY again. It reads the full log into memory before it keeps 40 lines, and it does not check the exit code of that second run.
  5. statechart.ts:153 and :157-158: the entry moves the output and prints Wrote <out> before the finally block removes tmp. A long lock on tmp then gives exit code 2 with a chart on disk.
  6. statechart.ts:157-158: the finally block removes the stage folder first. When that remove throws, the script does not remove tmp.
  7. run.ts:104, joined(): it opens one file descriptor for each log and never closes it.

Suggested fixes. Item 1: kill the group only while the worker runs, or keep a handle to the process tree. Item 2: read the exit code of taskkill, and report a failure. Item 3: keep the outer label when the joined arrows have one label. Item 4: read the second log with a size limit, and check its exit code.

Items 5 and 6: remove tmp before the Wrote line. Give each remove of the finally block its own try. Then a failed remove of the stage folder does not skip the remove of tmp. Item 7: close each descriptor after the read.

Related. #1170 asks for taskkill on Windows. Item 2 is a different defect: kill.ts now starts taskkill, but it ignores the result.

Scope. We found these items in reviews of our copy. We did not test other scripts of the repository. On 2026-11-25 no commit after ca782ed changed pstack/skills/statechart/scripts/ (newest commit 41e4009).

Activity

  1. anoop16-web commented on Nov 25, 2026

    @anoop16-web

    Fix with java script

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions