mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7870] [MERGED] fix(packages): stop old agent package copies piling up on disk #7978
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7978
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7870
Author: @SpicyMarinara
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/package-disk-cleanup📝 Commits (1)
8aec11afix(packages): stop old agent package copies piling up on disk📊 Changes
6 files changed (+483 additions, -6 deletions)
View changed files
📝
docs/CONFIGURATION.md(+1 -0)📝
docs/TROUBLESHOOTING.md(+2 -0)📝
docs/development/optional-agent-packages.md(+9 -0)📝
packages/server/src/services/capability-packages/capability-module-runtime.service.ts(+80 -4)📝
packages/server/src/services/capability-packages/package-manager.service.ts(+38 -2)➕
scripts/regressions/capability-package-disk-cleanup.regression.ts(+353 -0)📄 Description
Linked issue
Closes #7858
Part of #7858: this is the disk-cleanup part (plan Lane 3, contract lane "E-disk"). The client host namespace is #7869 and the runtime services are #7868; the Agents rebuild is Pasta-Devs/Marinara-Agents#1487. This PR is independent of both and can merge in either order with #7869 (contract merge order: E-client and E-disk first, then E-server, then the Agents PR).
Why this change
Downloaded agent packages take about 3.6 times their own size on disk, and part of it never goes away:
data/capability-runtime-snapshots. A crash, a force-quit, a killed Termux process or a power cut skips the copy's cleanup, and nothing ever removes it. On the maintainer's machines: 467 MB (208 orphaned copies) in one data folder and 2.2 GB (1,328 copies) in another.client.js(46–56% of its bytes), although the server never loads it.capability-packages/versions/<id>keeps every version ever installed. Only uninstall removes them.Users can't fix this themselves safely, and they shouldn't have to. After this PR the Engine cleans up on its own.
Decisions this PR relies on (lead decisions, made while the maintainer was asleep, quoted from the binding contract):
globalThis.__MARINARA_HOST__ = { version: 1, ... }. (Not touched here.)engine.min. (Not touched here; this PR does not change the capability API.)versions/(pruning makes that small).stagingbefore the Agents PR.capability-runtime-snapshotsandversions/<id>/<v>entries other than the current and previous version.Contract decisions used: C12 (each Engine PR says
Closes #7858) and C14 (new regressions go in new files).What changed
capabilityModuleRuntime.start()first calls the newsweepCapabilityRuntimeSnapshots(), which deletes every entry ofcapability-runtime-snapshotsexcept the sharednode_moduleslinks. No copy can be live in a new process. It makes read-only (0400) files and folders writable and retries when a plain delete fails (Windows needs this), never follows links, logs one info line with the count and size, and never throws. Only the storage writer-lease holder gets there:start()runs afterstorage.open, which a second Engine on the same data folder fails withStorageWriterLeaseError.createVerifiedRuntimeSnapshot()no longer copies the manifest's client entrypoint. Every other verified file is still copied, so Quartermaster's server still readsicons/besideserver.mjs. A copy's own cleanup (deactivate, update, stop) now uses the same delete-with-retry.capabilityPackageManager.pruneVersions(packageId?)keepsversionandpreviousVersion(what rollback restores) inversions/<id>and deletes the other version folders. It runs at the end ofstart()(all packages), after a successful hot activation (activatePackage), and after an install whose result isactive/ready(packages without server code). It skips packages that arerestart-requiredorreadiness: "pending", ids missing from the registry (including records a newer Engine wrote), records whose id differs from the manifest id, and files that are not version folders. It never touchesinstalled.json, update decisions,.install-*folders, package data, chats or settings. The about-me-keeper prune and uninstall are unchanged.docs/development/optional-agent-packages.mdgets "Disk use: runtime copies and kept versions" at the end of "Runtime and restart behavior".docs/CONFIGURATION.md(Package lifecycle and storage) anddocs/TROUBLESHOOTING.md(Downloadable agent problems) get one short note each saying the cleanup is automatic. No[docs-i18n]issue: the held release translation PR covers docs.scripts/regressions/capability-package-disk-cleanup.regression.ts(see Validation).Measured footprint
43 agents installed in three rounds on one temp
DATA_DIR, as a long-time user would have them: Agentsmaincatalog atfdcfde30a(2026-10-05), then the currentmaincatalog (533ae29de), then the currentstagingcatalog. Thenkill -9, then a normal start. Every package endedactive/readyin both runs.client.jsclient.jsRemoved 15 old package runtime copies (17.0 MB)andRemoved old capability package versions: long-term-memory@1.4.4.Validation
pnpm checkpasses locallyCONTRIBUTING.mdWhat the agent ran on macOS (Node 24.16.0), for the reviewer to repeat or check:
pnpm check: passed.node scripts/run-regressions.mjs --filter scripts/regressions/capability-package-disk-cleanup.regression.ts: passed. With a tempDATA_DIR, it checks:buildApp()on the same data folder and stops withStorageWriterLeaseError. Every stale copy and every version folder is still there afterwards.start()removes the stale copies, including 0400 files and a copy whose folder is read-only. A negative control shows that a plainrmfails on that folder withEACCES. The sharednode_modulesstays, and a link target outside the copies is untouched.server.mjs,icons/,manifest.jsonand thenode_moduleslink but noclient.js. The package server reads its own icon from the copy and sees noclient.js. Deactivating and stopping remove the copies.start()).restart-requiredandpendingpackages keep every version. Also untouched: an unregistered id, a record from a newer Engine, a record whose id is not its manifest id, a file inversions/<id>,.install-*, update decisions, and a package data folder.node scripts/run-regressions.mjs --filter capability: all 20 capability regressions pass, includingcapability-package-lifecycle. Alsorobustness-shutdown-safety,robustness-runtime-diagnostics,startup-inject-gateandscene-package-originpass.server.mjs,agents.json,icons/(21 files),manifest.jsonandnode_modules, andfind capability-runtime-snapshots -name client.jsfound nothing.Manual verification notes
Risky work (filesystem deletion in the data folder), claim boundary:
node_modules. Runtime copies no longer contain the client entrypoint.versions/<id>keeps only the current and previous version once a package has started. No package data, chat, setting or registry file is deleted.DATA_DIR, package activation, rollback.capabilityModuleRuntime.start,createVerifiedRuntimeSnapshotand its cleanup,activatePackage,capabilityPackageManager.install, newcapabilityPackageManager.pruneVersions, and newsweepCapabilityRuntimeSnapshots.install()(live: Beholder 1.3.12 → 1.3.14; nothing older to remove).rmcannot delete the read-only fixture; restart-required, pending, unregistered and mismatched ids keep everything; package data is unchanged.duand file listings of the tempDATA_DIRbefore and after; the server's own log lines.node_modulesjunction.Manually verify, for Mari:
data/capability-runtime-snapshotsholds only the live copies (one folder per installed agent with server code, plusnode_modules) and thatdata/capability-packages/versions/<id>keeps at most two versions.data/capability-runtime-snapshotsbefore (467 MB and 2.2 GB on your two checkouts), start Marinara, and check it again. WithLOG_LEVEL=infothe log showsRemoved N old package runtime copies.node_modulesjunction).capability-runtime-snapshotsholds only live copies after a restart.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)Docs changed:
docs/development/optional-agent-packages.md,docs/CONFIGURATION.md,docs/TROUBLESHOOTING.md. Translations: covered by the held release translation PR (no[docs-i18n]issue, per the lead's instruction). NoCHANGELOG.md, version or storage-format change.UI evidence (if applicable)
No UI change.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.