Skip to content

Skill /tmp scratch files leak when a run ends before its final cleanup step #612

Open

Description

@sarahxsanders

What's happening

The docs-only skills the wizard runs (e.g. remediate-3000, cross-sell-3000 in context-mill) write JSON scratch files to /tmp/ across their steps, and delete them only in their final step.

If a run ends before reaching that final step, an [ABORT], an error, a rate-limit, or a kill, those files are left behind. The wizard never sweeps them.

Example leftovers:

  • /tmp/posthog-remediation-plan.json, /tmp/posthog-remediation-env.json
  • /tmp/posthog-cross-sell-opportunities.json, /tmp/posthog-cross-sell-plan.json, /tmp/posthog-cross-sell-env.json

Why the wizard can't catch it today

The wizard only understands two things a skill emits: [STATUS] and [ABORT]. On [ABORT] it kills the run and calls wizardAbort(), which runs only the functions registered in cleanupFns. None of those touch the skill's /tmp/ files. The wizard uses fixed /tmp/ paths (src/utils/paths.ts) and has no knowledge of the skill's scratch filenames, so it can't sweep them as-is.

Relevant code:

  • src/lib/agent/agent-interface.ts (~1097-1118): [ABORT] detection, kills the run
  • src/lib/agent/wizard-abort.ts: the cleanupFns list that runs on abort/exit
  • src/utils/paths.ts: fixed /tmp/ paths, no managed temp dir

Impact

Low-harm: filenames are fixed so the next full run overwrites them, and /tmp/ clears on reboot. But interrupted runs leave orphaned files, which is confusing for anyone inspecting /tmp/ and slightly untidy.

Options

  1. Wizard-level sweep (this repo): register a cleanup in the wizardAbort / cleanupFns path that removes known skill temp paths on any exit, including abort and error. Needs a convention for which paths to sweep (e.g. a glob like /tmp/posthog-*-plan.json, *-env.json, *-opportunities.json), which couples the wizard to skill filenames.

  2. Skill-level self-heal (context-mill): have each skill rm -f its own temp files at the START of step 1, before writing anything, so an interrupted prior run gets cleaned on the next run. No wizard changes, and the skill already knows its own filenames. This is the lower-coupling fix.

Leaning toward option 2 for new skills, but filing here so the wizard team can decide whether a generic exit-time sweep is worth owning for all skills.

Repro

Run a skill that writes /tmp/ scratch files, interrupt it before the final step (e.g. trigger an [ABORT] or Ctrl-C), then check /tmp/ for leftover posthog-*.json files.

Activity

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