Skip to content

fix(harness): retain classified stop cause before host cleanup - #571

Closed
AmirrezaFarnamTaheri wants to merge 1 commit into
tinyhumansai:mainfrom
AmirrezaFarnamTaheri:fix/retain-classified-stop-cause
Closed

AmirrezaFarnamTaheri wants to merge 1 commit into
tinyhumansai:mainfrom
AmirrezaFarnamTaheri:fix/retain-classified-stop-cause

Conversation

@AmirrezaFarnamTaheri

@AmirrezaFarnamTaheri AmirrezaFarnamTaheri commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

FailureScopeMiddleware::after_agent calls the host policy's finish_run hook before retaining the current classified stop cause. A host may legitimately clear its stop latch in that hook, so a classified failure recorded by a host callback can disappear from AgentRun::failure_cause at the end of the run. OpenHuman's classified_stop_cause_survives_the_latch_cleanup_on_agent_finish regression test exposes this ordering bug.

Change

Capture current_halt_cause before finish_run clears per-run evidence, only when the run does not already carry a cause. Keep an already recorded loop/middleware cause authoritative, and retain the existing cleanup behavior.

The new owner tests cover latch cleanup, preserving an existing cause, and an unclassified run. The middleware documentation now states the finish ordering.

Validation

  • rustfmt --edition 2024 --config skip_children=true on both changed Rust files: passed.
  • git diff --check: passed.
  • The patch applies cleanly to the pinned downstream TinyAgents integration based on a5b4d0f6b8b962b28c4288a8518773743e252343.
  • Focused owner tests: 3 passed, 0 failed with cargo test --manifest-path vendor/tinyagents/Cargo.toml --locked -p tinyagents-harness --no-default-features --lib failure_scope::finish_tests, against the exact patch in the public downstream integration 266ab91419ed55f111aed97313ba1d0e52f7d010.

No host-side fallback or change to failure classification, stop budgets, or latch ownership is introduced.

Downstream regression: AmirrezaFarnamTaheri/openhuman#17

Capture a host's current halt cause during after_agent before finish_run
clears its per-run latch. Preserve an existing AgentRun cause and keep
cleanup behavior unchanged. Cover classified, existing, and unclassified
finalization paths with owner-level regressions.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

AmirrezaFarnamTaheri added a commit to AmirrezaFarnamTaheri/tinyagents that referenced this pull request Oct 23, 2026
Backport the owner fix proposed in tinyhumansai#571 so host
finish_run cleanup cannot erase AgentRun.failure_cause. Keep an existing
cause authoritative and retain latch cleanup.

Source-commit: 83b4604
Source-PR: tinyhumansai#571
@M3gA-Mind

Copy link
Copy Markdown
Collaborator

Thanks. This is the right place for this fix. OpenHuman currently carries the same capture-before-finish_run on the host side (#8146), and this lets it go away. On current main the branch merges cleanly, and on our build of it fmt and clippy are clean, the harness lib passes (3311/0), and all 3 new finish tests pass.
It only fills failure_cause when nothing has recorded one, which keeps earlier causes authoritative. Please take it out of draft when you're ready, and we'll ask a maintainer to review it.

@M3gA-Mind

Copy link
Copy Markdown
Collaborator

Thanks @AmirrezaFarnamTaheri, this is the right fix. To get it landed we've carried your commit over unchanged, with your authorship kept, in #608, rebased onto current main. On our Linux CI runner it passes the full harness suite (3311/0), including your three finish tests, and removing the capture makes classified_cause_survives_host_latch_cleanup fail as expected. Closing this draft in favour of #608; the credit stays with you.

@M3gA-Mind M3gA-Mind closed this Nov 11, 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.

2 participants