Skip to content

fix(cache): sweep orphaned models tmp files on refresh - #131

Merged
pierreraby merged 1 commit into
mainfrom
fix/cache-tmp-cleanup
Oct 3, 2026
Merged

pierreraby merged 1 commit into
mainfrom
fix/cache-tmp-cleanup

Conversation

@pierreraby

Copy link
Copy Markdown
Collaborator

Fixes #130.

Background refresh is fire-and-forget (void this.refresh()), so a host exiting between the temp write and the rename leaves an orphaned commandcode-models.json.<pid>.tmp behind with no cleanup on the next startup.

This change:

  • makes the temp name unique per attempt (pid + timestamp + random) so concurrent hosts never share one,
  • sweeps temp files older than 1h on the next successful refresh (recent files are kept so a concurrent host's in-progress write survives).

Verified locally: typecheck clean, test-models 25/25 (incl. a new sweep test covering stale-removal + recent-preservation), test-runtime 11/11, test-pricing 8/8, prettier clean.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Memory benchmark

Compared base 99e2c0e with PR head 7b5b44b on the same GitHub-hosted darwin runner. Lower values are better.

Metric Base PR PR − Base Change
Stable RSS 120.1 MiB ± 0.3 MiB 119.9 MiB ± 0.9 MiB -0.3 MiB ± 0.9 MiB -0.2%
Physical footprint 66.7 MiB ± 0.5 MiB 67.0 MiB ± 0.4 MiB +0.1 MiB ± 0.4 MiB +0.1%
Physical peak 77.8 MiB ± 0.4 MiB 78.3 MiB ± 1.0 MiB +0.3 MiB ± 0.5 MiB +0.3%

Interpretation: No metric shows a clear Base-to-PR difference beyond its measured run-to-run variation.

Extension overhead above pi baseline

Metric Base overhead PR overhead Difference
Stable RSS +5.9 MiB ± 0.8 MiB +4.8 MiB ± 1.0 MiB -0.3 MiB ± 0.9 MiB
Physical footprint +3.5 MiB ± 0.4 MiB +3.7 MiB ± 0.7 MiB +0.1 MiB ± 0.4 MiB
Physical peak +4.1 MiB ± 0.8 MiB +4.6 MiB ± 0.8 MiB +0.3 MiB ± 0.5 MiB

Values are medians of 6 alternating, paired runs. The value after ± is the median absolute deviation (MAD). Each process was sampled 12 times after a 2500 ms warm-up.

Environment: pi 0.84.4, Bun 1.4.0, darwin arm64. RSS comes from ps; physical footprint and peak come from macOS footprint.

This is a comparative signal, not a pass/fail threshold. GitHub-hosted runner noise can affect absolute values.

@karaaslanz karaaslanz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 7b5b44b. The stale-temp sweep is bounded to old cache temp files, preserves recent concurrent writes, and uses unique per-attempt temp names. Exact-head typecheck and focused model/cache regressions passed locally, and the required CI/security checks are green. Approving.

@pierreraby
pierreraby merged commit 5783e9f into main Oct 3, 2026
15 checks passed
@pierreraby
pierreraby deleted the fix/cache-tmp-cleanup branch October 3, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

~/.pi/agent/ filling up with commandcode-models.json.*.tmp files

2 participants