Skip to content

feat(task): track task nesting depth with cycle-safe backfill - #10

Merged
easonLiangWorldedtech merged 1 commit into
main-task-treefrom
pr-1-depth-tracking
Aug 16, 2026
Merged

feat(task): track task nesting depth with cycle-safe backfill#10
easonLiangWorldedtech merged 1 commit into
main-task-treefrom
pr-1-depth-tracking

Conversation

@easonLiangWorldedtech

Copy link
Copy Markdown
Owner

Summary

Part of the Task Tree plan (issue #9, upstream Zoo-Code-Org#856). PR-1 introduces nesting depth tracking for tasks — the foundation for maxNestingDepth enforcement and auto-flatten in later PRs.

Changes

  • packages/types/src/history.ts: optional depth: z.number().int().min(0) on HistoryItem (root = 0). Optional so legacy records stay valid.
  • packages/types/src/task.ts: CreateTaskOptions.depth? and TaskLike.depth.
  • src/core/task/Task.ts: readonly depth + depthAuthoritative. Constructor precedence: persisted value > live parent (parent.depth + 1) > root (0). A legacy child resumed without its live parent is marked non-authoritative so a placeholder 0 is never written back to history.
  • src/core/task-persistence/taskMetadata.ts: persists depth only when a valid number is supplied.
  • src/core/webview/ClineProvider.ts: backfillTaskDepth() — on createTaskWithHistoryItem, tasks the constructor could not resolve walk the parentTaskId chain through the in-memory store / global state and persist the computed depth (bounded, cycle-safe).
  • src/core/task/taskDepth.ts (new): pure computeTaskDepth(taskId, ownDepth, lookup) helper — handles persisted values, ancestor depths, roots, cycles, dangling refs, and over-long chains.

Tests

  • New unit suite core/task/__tests__/taskDepth.spec.ts (8 cases: persisted value, invalid depth fall-through, root derivation, nearest-ancestor depth, cycle, dangling ref, over-long chain, self-reference).
  • Task.spec.ts: 4 new constructor cases (root=0 authoritative; child = parent+1; persisted beats live parent; legacy child without live parent is non-authoritative).

Verification

  • pnpm run check-types — all 14 packages pass.
  • Narrowest suites: taskDepth.spec.ts (8/8), Task.spec.ts (96/96), taskMessages.spec.ts (4/4), provider rehydration specs ClineProvider.flicker-free-cancel.spec.ts + checkpointRestoreHandler.spec.ts (17/17).
  • ESLint clean on all touched files; no suppression count changes.

Notes

  • No behavior change for existing tasks: depth is additive and optional everywhere; saves only include it when authoritative.

- Add optional depth (root = 0) to HistoryItem schema, CreateTaskOptions and TaskLike

- Derive depth in the Task constructor: persisted value > live parent (+1) > root (0); mark legacy children resumed without their live parent as non-authoritative so a placeholder 0 is never persisted

- Persist depth via taskMetadata() only when authoritative

- Backfill depth for resumed legacy tasks in createTaskWithHistoryItem by walking the parentTaskId chain through the history store / global state (bounded, cycle-safe)
@easonLiangWorldedtech
easonLiangWorldedtech merged commit 59a22e2 into main-task-tree Aug 16, 2026
8 of 11 checks passed
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.

2 participants