agent-orchestrator/packages
Harshit Singh Bhandari 71253105cd
refactor(core): replace spawn rollback ladder with CleanupStack (#1616)
* refactor(core): replace spawn rollback ladder with CleanupStack

Replace the four nested try/catch + cleanupSpawnWorkspaceAndMetadata
helper in _spawnInner with a single LIFO CleanupStack. Each side
effect (reserved metadata, workspace, prompt files, runtime handle)
pushes its undo as soon as the resource exists; on success we
dismiss(), on failure we runAll().

Why: adding a new spawn step previously required extending every
prior cleanup block. Easy to forget; no compiler check. The stack
makes rollback structural — a new step pushes one cleanup, no risk
of leaving prior resources behind. runAll() is fault-tolerant by
design: a throwing cleanup never short-circuits the rest.

Behavior is preserved. Adds characterization tests for the worker
spawn rollback paths (none existed before — only spawnOrchestrator
was covered):
  - workspace.create failure cleans reserved metadata
  - runtime.create failure destroys worktree + cleans metadata
  - postLaunchSetup failure destroys runtime + worktree + metadata
  - one cleanup throwing does not skip subsequent cleanups

Refs #1603 (PR 1 of the ao spawn refactor plan).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(core): make CleanupStack runAll() terminal, symmetric with dismiss()

Address review feedback on PR #1616: previously `dismiss()` → `push()` was
a documented no-op but `runAll()` → `push()` would silently queue cleanups
that fired on a subsequent `runAll()`. Asymmetric and surprising.

Set `this.dismissed = true` at the top of `runAll()` so both terminal
states (success via dismiss, failure via runAll) reject further pushes
identically. Add a regression test pinning the new symmetric behavior.

The "idempotent runAll" test continues to pass (early-return path now
fires via the dismissed flag instead of the empty-stack short-circuit).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(core): surface CleanupStack errors and cover postCreate rollback

Address review feedback on PR #1616:

- Pass an onError callback to cleanupStack.runAll() in _spawnInner that
  logs cleanup failures via console.error. The previous /* best effort */
  pattern silently swallowed errors during rollback; now the same errors
  are surfaced for debugging without changing behavior (cleanup errors
  still don't propagate, subsequent cleanups still run).
- Add a characterization test for the workspace.postCreate failure path.
  This was the only rollback path without a test — the stack handled it
  correctly already, but pinning it down prevents regression.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 22:43:21 +05:30
..
ao chore: align workspace package.json versions with npm registry (#1587) 2026-05-01 15:31:04 +05:30
cli feat: add SQLite-backed activity event logging layer (#1528) 2026-05-01 21:13:20 +05:30
core refactor(core): replace spawn rollback ladder with CleanupStack (#1616) 2026-05-03 22:43:21 +05:30
integration-tests refactor(core): storage redesign — projectId-based paths, JSON metadata (#1466) 2026-04-28 17:55:53 +05:30
plugins fix(agent-claude-code): fold underscores in Claude project slug (#1611) (#1612) 2026-05-03 20:40:18 +05:30
web feat(web): add 'Open orchestrator' to sidebar 3-dot menu (#1615) 2026-05-03 20:39:57 +05:30