Skip to content

run workspace teardown after a runtime restart - #3154

Open
thedhruvhegde wants to merge 1 commit into
generalaction:mainfrom
thedhruvhegde:fix/teardown-after-restart
Open

run workspace teardown after a runtime restart#3154
thedhruvhegde wants to merge 1 commit into
generalaction:mainfrom
thedhruvhegde:fix/teardown-after-restart

Conversation

@thedhruvhegde

@thedhruvhegde thedhruvhegde commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

summary

archive/delete only ran the .emdash.json teardown script while the workspace was still in the in-memory activation map. after an app restart that map is empty, so archived then deleted tasks skipped teardown and leaked simulators / other setup resources.

deactivate now runs teardown once whenever lastActivatedAt is set, then clears it so a second deactivate stays a no-op.

closes #2886

test plan

  • activate a workspace with a teardown script, restart emdash, archive/delete the task, confirm the script ran
  • live archive still runs teardown once
  • pnpm --dir packages/core exec vitest run src/runtimes/workspace-registry/node/api/activation.contract.test.ts

@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes workspace teardown survive runtime restarts by using the durable workspace path and lastActivatedAt marker when no in-memory activation exists.

  • Runs teardown for a durably activated workspace after restart.
  • Clears lastActivatedAt after teardown so subsequent deactivation remains idempotent.
  • Adds contract coverage for cold teardown and the second-deactivation no-op.
  • Updates durable record timestamps when activation state is cleared.

Confidence Score: 5/5

The PR appears safe to merge, with the restart teardown path and its durable idempotence behavior implemented consistently.

No actionable failure remains: durable state reaches deactivation, teardown runs through the existing lifecycle runner, and the activation marker is cleared through the serialized persistence path.

Important Files Changed

Filename Overview
packages/core/src/runtimes/workspace-registry/node/activation.ts Extends deactivation to recover durable activation state after restart and clears the marker after one teardown attempt.
packages/core/src/runtimes/workspace-registry/node/runtime.ts Supplies durable workspace state to deactivation and records mutation time independently from the nullable activation timestamp.
packages/core/src/runtimes/workspace-registry/node/api/activation.contract.test.ts Verifies teardown executes once after recreating the runtime and remains a no-op on repeated deactivation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Deactivate workspace] --> B{In-memory activation exists?}
  B -->|Yes| C[Abort and await background scripts]
  B -->|No| D{Durable lastActivatedAt is set?}
  D -->|No| E[Return no-op]
  D -->|Yes| F[Use durable workspace path]
  C --> G[Resolve lifecycle configuration]
  F --> G
  G --> H[Run time-boxed teardown]
  H --> I[Publish inactive state]
  I --> J[Clear durable lastActivatedAt]
  J --> K[Kill workspace sessions]
Loading

Reviews (1): Last reviewed commit: "run workspace teardown after a runtime r..." | Re-trigger Greptile

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.

[bug]: Archived tasks never run the teardown script

1 participant