Files
fusion/packages/engine
ischindl 3d355465c7 feat(missions): done-credit via reverse lineage, feature re-point/unlink tools, and live unlink SSE (#3491)
## What this PR does

Closes three lifecycle gaps in the Mission → Milestone → Slice →
**Feature** model, where a feature links to exactly one delivery task
(single-valued `feature.taskId`, one-feature-one-task):

1. **Reverse-lineage done-credit** — a terminal, non-failed task
carrying a feature's reverse `missionLineage`
(featureId/sliceId/missionId) now credits the feature as satisfying its
acceptance criteria, independent of where the forward `feature.taskId`
points (e.g. a newer follow-up task). Credit is only applied when
**none** of the feature's lineage candidates is live, so a live
follow-up keeps the feature active. Fixes features that otherwise sit
"in-progress" forever after their delivering task completes.
2. **Re-point / unlink surface** — new `fn_feature_repoint_task` /
`fn_feature_unlink_task` agent tools (engine + CLI) backed by an atomic
`repointFeatureToTask` store primitive, so a mis-linked feature can be
re-attached to the correct delivery task or unlinked — without a manual
DB edit. Single-valued `feature.taskId` and one-feature-one-task
invariants are preserved; unlinking an already-unlinked feature errors
clearly. Classified as mutation tools, same class as the existing
`fn_feature_link_task`.
3. **Live SSE update** — the `feature:unlinked` store event is now
emitted over SSE (`event: feature:unlinked`) so the dashboard refreshes
immediately after a re-point/unlink instead of waiting for the next
poll.

## Why

The forward-only `feature.taskId` link made three real failure modes
unrecoverable from the product surface: stale done-features after task
replacement, permanently mis-linked features, and a stale dashboard
after a repair. This closes the feature lifecycle end-to-end.

## Invariants

- `feature.taskId` stays single-valued; one feature is linked to at most
one task at any time (atomic store primitive).
- Done-credit requires: terminal column, non-failed, and no live lineage
candidate.
- No new run-audit prose; store events carry ids/counts/outcomes only.

## Tests

- `mission-state-reconcile.test.ts` — reverse-lineage credit matrix
(live vs. terminal vs. failed candidates)
- `mission-store.pg.test.ts` — `repointFeatureToTask` atomicity +
invariants (PG; gate-safe auto-skip without Postgres)
- `agent-mission-tools.test.ts` — tool delegation (unlink / re-point
exactly once)
- `heartbeat-executor.test.ts`, `extension.test.ts` — tool exposure and
heartbeat interaction
- Changeset: `@runfusion/fusion: minor`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added tools to reassign a feature to another live task or remove its
task link.
- Unlinking resets the feature to a defined state and provides clear
errors when applicable.
  - Added live updates for feature unlink events.
- Improved reconciliation to recognize completed reverse-lineage work
while respecting active follow-up tasks and failures.
- Improved relationship consistency when concurrent task-link operations
occur.

- **Documentation**
- Documented feature linking, unlinking, reassignment, lifecycle events,
and reconciliation behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Fusion <noreply@runfusion.ai>
2026-08-19 21:01:56 -07:00
..
2026-07-31 18:03:13 -07:00
2026-08-18 22:16:44 -07:00
2026-08-18 22:16:44 -07:00