Skip to content

Add a mock-LLM end-to-end test for new_task parent-to-child delegation #196

Done

Description

@w4ffl35

Problem

Recursive task decomposition (new_task: synchronous nested HeadlessSession, shared BudgetTracker, depth cap, checkpoint lineage) has only ever been unit-tested against fakes — docs/gap-audit.md records it has never run end-to-end, even against a mock LLM. The parent→child contract (handoff message, budget sharing, event-feed lineage) can drift without any integration signal.

Architecture (independent solution)

Add a mock-LLM end-to-end test; no real model, no cost:

  1. Use the existing e2e harness idiom (scripts/e2e/run.sh mock OpenRouter, or the FakeLlmClient DI in src/engine/__tests__/loop.test.ts if a full script is heavier than needed — pick the lighter one that still crosses a real parent→child boundary).
  2. Script the fake parent to call new_task once with a bounded child task; script the fake child to do one read/edit and complete. Assert: child session exists with correct parent lineage fields, child's spend debits the shared tracker (a child-only overspend trips the cap — the design's core risk), child checkpoints tag into the parent's lineage, parent resumes and completes after observing the child result.
  3. Wire it where the other engine tests run so npm test -- <filter> reaches it; keep runtime in the same class as neighboring suites.

Scope / non-goals

  • No real-LLM run (that needs an owner key/budget decision), no fixing the same-turn attempt_completion+new_task bug here (separate issue — if this test exposes it, file/link, don't silently fix).

Acceptance

  • Parent→child run passes deterministically offline, twice in a row.
  • Child-only budget overspend demonstrably trips the shared cap in the test.

Tests (happy / sad / bad)

This issue is a test; still cover: happy (delegation completes), sad (child errors → parent sees a tool error, not a hang), bad (child attempts recursion past depth cap → refused as tool error).

Contributor notes

Good first issue for someone comfortable with the existing fake-client tests. Start from src/engine/__tests__/loop.test.ts.

Activity

  1. added
    enhancement
    good first issue
    help wanted
    on Nov 29, 2026
  2. w4ffl35 commented on Dec 5, 2026

    @w4ffl35
    MemberAuthor

    Issue 196 — Closing Report

    Files changed

    • src/engine/tests/new-task.test.ts (happy-path delegation now does a real parent→child read+edit with lineage + resume assertions; helpers extracted, gate-clean)

    Baseline (before)

    ok   new_task: child completes and its result flows back to the parent
    ok   new_task: recursion depth cap refuses as a recoverable tool error (parent continues)
    ok   new_task: budget is SHARED — child spend trips the one cap (total parent+child)
    ok   new_task: called alongside another tool is refused, sibling still executes
    ok   new_task: child edits checkpoint into the SAME shadow-git history, lineage-tagged
    ok   new_task: child bounded failure surfaces as an honest error, not fabricated success
    ok   new_task: malformed child completion fails closed
    All 7 tests passed
    

    Baseline (after)

    Run 1: All 7 tests passed
    Run 2: All 7 tests passed
    ok   new_task: child read+edit, parent resumes (parent delegates via new_task; fake child reads seed.txt + writes child.txt via real tools; result flows back; parent+child event feeds carry parentSessionId/recursionDepth; parent completion lands after child result)
    (sad: child bounded failure → honest tool error, pre-existing suite; bad: depth-cap + malformed completion refusals, pre-existing suites)
    

    Boot check

    • npx tsc --noEmit: clean.
    • Per-file suites: new-task 7/7, uwuchat 11/11, uwuchat-contract 6/6, loop 112/112.
    • Full npm test: FAILS at pre-existing src/campaigncontrol/__tests__/repair-known-v2-cli.test.ts — identical failure on clean HEAD (verified via throwaway worktree at HEAD~1), unrelated to this change.

    Residual risk / notes

    • The same-turn attempt_completion+new_task interaction noted in the issue was NOT touched; if the new happy-path ever exposes it, file/link as follow-up.
    • Full-repo check-architecture reports 157 NEW findings on this branch vs 154 on clean HEAD~1; none name new-task/uwuchat files (grep verified); gate was already red before this change.

    PR: #203

  3. added a commit that references this issue on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions