In mastra-ai/mastra commit #21564, Mastra Factory added a place for a linked repository to say how its own worktree should be put away before the generic reset begins. That matters because “clean up the sandbox” is deceptively broad: a generated project might need to stop a local service, remove a tool-specific cache, or undo a checkout arrangement before its workspace can be scrubbed, pooled, or destroyed.
The commit’s co-author record credits Mastra Code (openai/gpt-5.6-sol). That is public evidence that a coding agent participated; it is not a claim that an agent designed or wrote every part. The sharper engineering receipt is in the code. The new retirement coordinator serializes competing retirement requests for the same session, loads the linked repository’s command, and then keeps the rest of the cleanup path accountable to the session rather than to a hopeful shell script.
A hook gets a place in the recovery sequence
For a remote sandbox, Factory attempts the repository teardown, scrubs the released workspace, returns the sandbox to its repository-scoped pool, and invalidates cached session state. For a local sandbox, the hook runs before destruction. The accompanying tests make that order concrete: teardown must precede the git scrub, pooling, and invalidation; two simultaneous retirement requests must not run the hook twice.
That order is why this is more than another configuration field. It turns a project’s cleanup knowledge into a lifecycle boundary that the orchestrator can call from terminal work, explicit deletion, and destructive project cleanup. It also extends the earlier Factory pool-and-scrub work in a specific direction: the system already knew how to reclaim a workspace; now the linked repository gets a chance to leave it in a state the generic scrub understands.
A failed hook is a warning, not a clean bill of health
The test suite prevents the easy but wrong headline. In one case the teardown command exits with an error; Factory logs the failure and still scrubs, clears the session binding, and pools the remote sandbox. That is a sensible recovery choice—one broken project script should not leave a resource stranded forever—but it means the hook is best-effort. It does not certify that every project-specific trace is gone, and it does not make an arbitrary shell command safe.
Transferable building skill: make cleanup two contracts, not one
Builders can borrow the shape without copying Factory. Let the repository own its domain cleanup, but pair it with an independent platform postcondition: scrub or destroy the workspace, clear the session binding, and make duplicate retirement harmless. Test the order, the failed-hook path, the unavailable-machine path, and the concurrency path. A cleanup command can be useful; only those follow-on invariants make it safe to reclaim the resource.
These are main-branch implementation and test receipts, not proof of a shipped release, provider-wide reliability, or hardened isolation. The next signal worth watching is public integration coverage that runs a real configured teardown through a provider interruption and then proves that the next repository claim begins without stale state or credentials.