Skip to content

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

Open
easonLiangWorldedtech wants to merge 1 commit into
mainfrom
up-1
Open

feat(task): track task nesting depth with cycle-safe backfill#20
easonLiangWorldedtech wants to merge 1 commit into
mainfrom
up-1

Conversation

@easonLiangWorldedtech

Copy link
Copy Markdown
Owner

Part 1/8 of the task-tree series.

Description

Adds a validated depth to history items and a cycle-safe backfillTaskDepth() that propagates parent depth through the delegation tree, so every task knows its nesting level. Depth is surfaced for later use by settings validation, environment details, and history-tree display (later parts of this series).

Contract rules:

  • A persisted depth on the task itself is authoritative.
  • Otherwise the live parent's depth + 1 is used; the child inherits the parent's authority so a legacy non-authoritative parent never stamps its placeholder depth onto the child as a persisted fact.
  • Cycle, dangling-reference, and over-long chains resolve to undefined (treated as root) instead of persisting a bogus value.

Includes the single-open-invariant spec mock for backfillTaskDepth so unit tests pass standalone.

Test Procedure

  • pnpm --dir src exec vitest run core/task/__tests__/taskDepth.spec.ts core/task/__tests__/Task.spec.ts __tests__/single-open-invariant.spec.ts
  • New regression cases: non-authoritative parent inheritance (Task.spec.ts), exactly-MAX_DEPTH_WALK boundary (taskDepth.spec.ts).

Pre-Submission Checklist

  • Scope: one concern per PR (depth contract only)
  • Self-review performed
  • Tests added for new behavior (regression cases above)
  • Visual snapshot: not applicable (no UI change)
  • Documentation impact: none required

Part 1/8 of the task-tree series (upstream-ready recomposition).

Adds `depth` to HistoryItem and a cycle-safe `backfillTaskDepth()` that
propagates parent depth through the delegation tree, so every task knows its
nesting level. Depth is surfaced for later use by settings validation,
environment details, and history-tree display.

Includes the single-open-invariant spec mock for backfillTaskDepth (folded in
from the series' CI fix) so this PR passes unit tests standalone.

Depth contract hardening:
- Children inherit their live parent's depth authority instead of assuming it,
  so a legacy non-authoritative parent never stamps its placeholder depth onto
  the child as a persisted fact (regression test added).
- computeTaskDepth now processes an ancestor reached after exactly
  MAX_DEPTH_WALK hops; only strictly longer chains are rejected (boundary
  regression test added).
@easonLiangWorldedtech
easonLiangWorldedtech marked this pull request as ready for review August 17, 2026 02:42
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