Skip to content

[Subtask]: D04 [baseline] Give taskRunner complete ownership of contexts on rejection and terminal completion #32282

Description

@XuPeng-SH

Parent Issue

Parent issue: #32278

Detail of Subtask

Catalog ID: D04
Origin: B - Pre-existing in the 4.2 baseline and retained on main
Evidence level: Reproduced resource retention

4.2 versus main: provenance

In 4.2, addToWait already creates WithCancelCause before queue admission, does not cancel rejected admissions, and removes only the map entry after normal completion. Main preserves both lifecycle gaps.

Design problem, impact, and existing responsibility

The parent context lives with the task runner. Deleting the running-map entry does not remove the parent cancelCtx.children reference. Cancellation in the heartbeat InvalidTask branch cannot reliably cover tasks already completed and removed. Retention grows with completed and rejected admissions.

Acceptance criteria

  • Contexts reach effective release after success, failure, rejected admission, exhausted retries, cancellation, and shutdown.
  • Use minimal behavioral/lifecycle regression tests; do not turn the diagnostic reflection of private cancelCtx fields into maintained tests.
  • Do not add a periodic sweeper for ownerless contexts. Preserve necessary completion and retry work.

Describe implementation you've considered

The creating taskRunner should cancel its context on rejection and at the actual terminal stage. Distinguish execution, retry, and completion acknowledgement so necessary completion SQL is not cancelled prematurely. Cleanup must not depend on a later heartbeat happening to observe the task.

Additional information

Existing investigation and validation limits

A probe follows production admission, result handoff, doTaskDone, and removal: after 1,000 completions or 1,000 rejected admissions, running=0 but the parent retains 1,000 children. Explicit terminal cancellation retains zero, and parent cancellation releases all. Normal and 100 race repetitions confirm this. Counts are not extrapolated into production RSS or inevitable OOM.

main investigation snapshot: pkg/taskservice/task_runner.go:415; pkg/taskservice/task_runner.go:675

4.2 baseline snapshot: pkg/taskservice/task_runner.go:409

The named probes are local diagnostic overlays, not committed repository tests. Their names identify the investigation; they cannot be selected directly from an ordinary checkout. Implement the smallest maintained contract regressions and reuse relevant CI/validation proportionally. Temporary evidence commits are not required.

Activity

  1. self-assigned this
    on Nov 5, 2026
  2. added theissue type on Nov 5, 2026
  3. changed the title [-][Subtask]: D04 [base] 由 taskRunner 统一释放拒绝及终态任务的自建 context[/-] [+][Subtask]: D04 [baseline] Give taskRunner complete ownership of contexts on rejection and terminal completion[/+] on Nov 5, 2026
  4. added a commit that references this issue on Nov 21, 2026
    f1ffbaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions