Skip to content

fix(subagent): stop the injection notice contradicting its own reason - #14286

Merged
bolichen97 merged 1 commit into
mainfrom
drive/6002-injection-notice
Sep 26, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
drive/6002-injection-notice

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Replaces #6002 by @leonlaiyc — reopened in-repo so the fork PR's checks can reach passed. The author's commit is cherry-picked unchanged; @leonlaiyc is credited as Co-authored-by.

Problem / Motivation

When a subagent finishes but its result cannot be handed back, the notice tells the reader "The agent finished but result delivery timed out." — even when nothing timed out. Four of the six notify_injection_failed call sites pass a different reason (a dead provider, a died ACP process, a raw exception string, the last injection-failure reason after the attempt cap), and the notice prints that reason on the line right above the outcome line. So the message contradicts itself:

Agent `a1` ❌ ACP process died
Task: ...
The agent finished but result delivery timed out.

Why it matters

The reader is an LLM deciding whether to retry. A wrong mechanism is not cosmetic: "timed out" invites a retry that the real cause (a dead process) does not warrant. #5900 made every other terminal branch outcome-aware and left exactly this one residual.

What changed (motivation → approach → change)

The completed-branch line in _injection_notice_outcome (src/kiro_crew/subagent.py) asserted a timeout the record does not know. The fix states only the outcome and leaves the cause to reason, which every caller already sets. The line now reads "The agent finished, but its result could not be delivered." A real timeout loses nothing: its callers still say "timed out" in reason. The spec (docs/system-specs/common/injected-messages.md) and the function docstring are updated to record that this line names no mechanism.

Backwards compatibility

Compatible: this changes only the human/LLM-facing wording of one terminal notice. No field, type, or contract that main accepts changes.

Tests

test/test_subagent_coverage.py gains cases that lock the completed-branch notice to a mechanism-free outcome string and assert it no longer says "timed out" when the reason is not a timeout, alongside the existing per-branch coverage.

Manual verification

N/A — unit coverage sufficient. _injection_notice_outcome is a pure function of the record and is unit-tested per branch.

Related Issues

no linked issue: residual named by a reviewer on merged #5900, not a tracked issue.

Pattern harvest

Not generalizable: a one-off wording contradiction in a single terminal branch that #5900's sweep missed; no rule class generalizes from it.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

`_injection_notice_outcome`'s completed branch asserts "result delivery timed
out", but only two of the six `notify_injection_failed` call sites pass a
timeout. `slack/gateway.py` sends "provider dead after prompt-busy retries",
"ACP process died", a raw `str(exception)` from a failed injection turn, and
the last injection-failure reason after the attempt cap — and the notice prints
that reason on the line directly above the outcome line, so the message
contradicts itself:

    Agent `a1` ❌ ACP process died
    Task: ...
    The agent finished but result delivery timed out.

The reader is an LLM deciding whether to retry, so the wrong mechanism is not
cosmetic.

State only the outcome and leave the cause to `reason`, which already carries
it. A real timeout loses nothing: its callers say so in `reason`, and the old
copy said "timed out" twice.

Residual named by the reviewer on merged #5900. Spec updated in the same commit
per AGENTS.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com>
@iamwhatever
iamwhatever requested review from a team and hoang-phan98 September 26, 2026 21:01
@iamwhatever iamwhatever added the drive-to-green PR claimed by drive-to-green pipeline label Sep 26, 2026
@iamwhatever iamwhatever self-assigned this Sep 26, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 26, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Intent: Make the completed-branch subagent injection notice state only the outcome, so it stops asserting "result delivery timed out" one line above a non-timeout reason. The cause already lives in reason.
Not a goal: Reworking the other terminal branches (#5900 already made them outcome-aware), or changing any field, type, or contract.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 3c161b7bc01649820ba91a8f192fc8de33eeb38f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 3c161b7

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 3c161b7bc01649820ba91a8f192fc8de33eeb38f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3c161b7

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3c161b7bc01649820ba91a8f192fc8de33eeb38f: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 3c161b7bc01649820ba91a8f192fc8de33eeb38f — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

One stale sibling of the old copy survives: website/src/test/SubagentCompletionCard.test.tsx:90 still carries "result delivery timed out" as a "byte-shaped" fixture — confirm the glyph-based parser truly doesn't care.

The defect is derived, not asserted: terminal.py:827-829 prints reason one line above the outcome line, and I counted the six notify_injection_failed call sites — four pass non-timeout reasons (slack/gateway.py:9164,9185,10062,10350), two pass timeouts, matching the docstring's claim. The new parametrized test asserting "timed out" not in msg fails on base, giving the fix checkable provenance. The one deleted pin (test_completed_keeps_the_finished_copy) is the fix itself, declared, with the contradiction it pinned quoted in the description. Spec updated same-commit per the AGENTS.md invariant. Grep for the old literal found 1 remaining match repo-wide, the frontend fixture named above.

What this change ships

Inventory (5 items) — 5 justified

Intent: FIX — stop the completed-branch injection notice claiming a timeout that contradicts the reason printed above it.

  1. The completed-run failure notice now says the result "could not be delivered" instead of "timed out" — justified
  2. Spec injected-messages.md records the new line and that it names no mechanism — justified
  3. _injection_notice_outcome docstring explains why the line names no mechanism — justified
  4. New tests lock the line against contradicting any caller's reason — justified
  5. Two existing tests renamed/re-pinned to the new copy — justified

[FIRST-PRINCIPLES-REVIEWED] 3c161b7

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 3c161b7bc01649820ba91a8f192fc8de33eeb38f — this comment is updated in place on each push.

Review details

Nothing blocks — two advisory findings on the new copy's premise.

FINDING — src/kiro_crew/subagent.py:2066 — the docstring's premise ("reason above it already carries one") is false on the dashboard injection path: slack/gateway.py:10056 does _reason = str(t.exception()), and the exception there is the bare TimeoutError() that bounded_chat_turn → asyncio.wait_for (dashboard/turn_dispatch.py:424) raises, whose str() is "", so the notice renders Agent \id` ❌ /Task: …/"The agent finished, but its result could not be delivered."with no cause anywhere — the one path where the removed "delivery timed out" wording was correct (same blank reachesError: on the card, sinceextra.get("error", "timed out")gets a present-but-empty key) → Fix: in the untouched caller,_reason = str(t.exception()) or type(t.exception()).name(or default an emptyreasoninsidenotify_injection_failed_impl`); not fixable inside the changed line.

FINDING — test/test_subagent_coverage.py:1637 — the new pin's comment claims The reasons the four non-timeout call sites actually pass, verbatim., but "AcpError: stream closed while waiting for result" and "no active session for parent" appear nowhere in src/; the real fourth and fifth sites pass str(t.exception()) (gateway.py:10056, empty on a timeout) and "; ".join(_inject_failure_reasons) whose members are f"attempt {_attempt} failed: {exc}" / f"attempt {_attempt} timed out after …" (gateway.py:10295, 10318), so the list asserts call-site fidelity it does not have and excludes the one reason shape that leaves the new copy cause-less → Fix: use the strings the call sites really produce (including "") or drop the "verbatim" claim.

[OPUS-REVIEWED] 3c161b7

Verdict parsed from the review's SHA-scoped output markers for commit 3c161b7bc01649820ba91a8f192fc8de33eeb38f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3c161b7bc01649820ba91a8f192fc8de33eeb38f: <one-sentence reason>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 26, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=88a3825dcf3c — docstring premise on the empty-reason path

rebutted (advisory, out of this PR's scope). The finding is correct that slack/gateway.py does _reason = str(t.exception()), and a bare TimeoutError() stringifies to "", so on that one path no cause is printed. But that is a pre-existing gap in an untouched caller, not something this change introduces or worsens: before this PR the completed branch printed "delivery timed out" for that same empty-reason case, which was equally not sourced from reason and was wrong for the five non-timeout callers. This PR's intent is only to stop the completed-branch line asserting a mechanism the record does not know; defaulting an empty reason in notify_injection_failed_impl / the gateway caller is a separate fix in code this diff does not touch. Widening here would pull slack/gateway.py and dashboard/turn_dispatch.py into a wording PR. Deferring the caller fix to its own change; keeping this diff to the completed-branch line.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: no

  • span=032e355145d5 — test comment over-claims "verbatim"

rebutted (advisory, no code defect). The finding is right that two of the four strings in NON_TIMEOUT_REASONS are representative reason shapes rather than literal call-site strings, so the word "verbatim" over-states it. The list's purpose is only to feed a parametrized case per non-timeout reason; the test's actual assertion — that the completed-branch notice contains no timeout wording for any non-timeout reason — holds for every string in the list and for "", so no test behaviour is wrong. The claim is a comment-wording inaccuracy, not a coverage gap, and correcting one word does not change what the test locks in. Leaving the passing test as-is rather than re-firing the whole check wave for a comment adjective; noting the wording here so the record is honest.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the full diff. Required gate PR Readiness green on the current head, no blocking reviews. Approving.

@bolichen97
bolichen97 enabled auto-merge (squash) September 26, 2026 22:55
@bolichen97
bolichen97 merged commit ee09462 into main Sep 26, 2026
98 of 106 checks passed
@bolichen97
bolichen97 deleted the drive/6002-injection-notice branch September 26, 2026 22:56
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 26, 2026
@NicholasRBowers NicholasRBowers removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 26, 2026
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.

4 participants