Fix #105: don't crash collecting actor tracebacks for finished coroutines#698
Merged
Conversation
…ines
Agent.actor_tracebacks() called actor.traceback() for every actor, which
delegates to mode's coroutine/async-generator stack formatter. A coroutine
or async generator that has finished naturally has no stack frame
(cr_frame/ag_frame is None), and mode raises
RuntimeError('cannot find stack of coroutine') for it.
Traceback collection happens in wait_empty around shutdown and rebalances
purely for logging, so a single finished actor must not abort the whole
collection (and, with it, a clean shutdown). Catch the RuntimeError per
actor and substitute a placeholder message instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #698 +/- ##
==========================================
+ Coverage 94.14% 94.16% +0.02%
==========================================
Files 104 104
Lines 11136 11142 +6
Branches 1201 1202 +1
==========================================
+ Hits 10484 10492 +8
+ Misses 551 549 -2
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Agent.actor_tracebacks()iterated every actor callingactor.traceback(), which delegates tomode's coroutine / async-generator stack formatter. A coroutine or async generator that has finished naturally has no stack frame (cr_frame/ag_frameisNone), andmoderaisesRuntimeError('cannot find stack of coroutine')when asked to format it.Traceback collection runs inside
Consumer.wait_emptyaround shutdown and rebalances, purely to log agent state. Because the old code built the list in one comprehension, a single finished actor aborted the whole collection — and with it a clean shutdown/rebalance.Fixes #105.
How
Collect tracebacks one actor at a time and catch
RuntimeErrorper actor, substituting a short placeholder (Could not extract traceback for actor <actor>: <exc>) instead of letting it propagate. This mirrors the workaround several users adopted via a customAgentsubclass, but folds it into faust itself so no subclass is required.Test
Added
test_actor_tracebacksandtest_actor_tracebacks__missing_stackintests/unit/agents/test_agent.py: the first confirms normal collection, the second confirms aRuntimeError('cannot find stack of coroutine')from one actor is swallowed into a placeholder while a sibling actor's traceback is still returned.🤖 Generated with Claude Code
Generated by Claude Code