Skip to content

Phase 2 plan failure has no replan loop (brainDigest→replan) #17

Description

@kuro-agent

Context

src/api.ts:1530 has a long-standing TODO from Akari (P1):

// TODO (Akari P1): no replan loop for phase 2 failures — add brainDigest→replan in future

When a phased accomplish call's Phase 2 planEngine.execute() rejects, we currently:

  1. Log the error
  2. Mark the Phase 2 plan as completed (cleanup)
  3. Schedule the entry for deletion after 1h
  4. Fall back to returning the Phase 1 result as if Phase 2 didn't happen

The Phase 1 wait-mode path (src/api.ts:1571-) does honor MAX_REPLAN_ROUNDS = 3 with brainDigest-driven replan. Phase 2 doesn't. This is a behavioral asymmetry.

What "done" looks like

  • Phase 2 failures trigger up to MAX_REPLAN_ROUNDS replan attempts via brainDigest, mirroring the Phase 1 flow
  • Each replan attempt is persisted via persistPlanHistory with a discriminating event (e.g. replan-attempted)
  • A test exercises the failure → replan → success path and the failure → replan-exhausted path

Why P1, not P0

Caller still gets some result (Phase 1's), so the system isn't broken — just under-recovering on multi-phase goals. Surface area is one branch; the fix is bounded.

Acceptance

  • TODO comment removed, replaced with link to this issue
  • Behavior parity test added in tests/api.phased.spec.ts (or nearest existing suite)
  • No regression in current Phase 2 success path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions