fix: drop redundant on_trace kwarg from Agent.run#2091
Conversation
ApprovabilityVerdict: Needs human review This refactor introduces a behavioral change in trace discard timing during retries. An unresolved review comment identifies a potential bug where the live dashboard may show incorrect 'pending' status during retry backoff instead of the failed attempt. You can customize Macroscope's approvability policy. Learn more. |
Agent.run returns the Trace, so a public on_trace(trace) callback on it is redundant for the standalone agent — no external caller passed it. Its only consumer was _EpisodeAgent injecting a watch closure for mint-time observation (stamp the seat's standing, feed the episode's live view, discard abandoned retry attempts), which the base retry loop drives just as well. Make mint-observation an internal protected mechanism instead: base Agent grows no-op _observe/_discard hooks; _run_once fires _observe at mint (via RolloutRun's on_trace); the retry loop calls _discard when abandoning an attempt. _EpisodeAgent overrides both — no per-call closure, no public kwarg. Live-dashboard streaming and per-agent retry discard are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b77d617 to
408b45a
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 408b45a. Configure here.
| break | ||
| history.extend(trace.errors) | ||
| # This attempt is abandoned; drop it from any live view before backoff. | ||
| self._discard(trace) |
There was a problem hiding this comment.
Live view pending during retry
Medium Severity
Calling _discard before retry backoff removes the failed trace from slot.traces while the env-rollout is still in flight. With a single agent, the live dashboard treats an empty in-progress slot as queued (pending) until the next attempt mints, instead of showing the failed attempt during the wait.
Reviewed by Cursor Bugbot for commit 408b45a. Configure here.


Summary
Agent.runreturns theTrace, so a publicon_trace(trace)callback on it is redundant for the standalone agent — and no external caller ever passed it._EpisodeAgent, which injected a per-callwatchclosure to observe each trace at mint (stamp the seat'sagent.name/trainable, feed the episode's live view, discard abandoned retry attempts). The base retry loop already knows each attempt, so it can drive this directly.Agentgrows no-op_observe/_discardhooks;_run_oncefires_observeat mint (viaRolloutRun'son_trace); the retry loop calls_discardwhen it abandons an attempt for backoff._EpisodeAgentoverrides both — no per-call closure, no public kwarg.slot.tracesfed at mint) and per-agent retry discard are behaviorally unchanged.Breaking
Agent.run/_EpisodeAgent.runno longer accept theon_tracekeyword. It was never part of the advertised API (solver.run(task)), had no callers outside the internalwatchplumbing, and callers already get the trace as the return value. For mint-time/live observation inside an env, keep going throughEnv.run_episode(on_trace=...)(unchanged).🤖 Generated with Claude Code
Note
Medium Risk
Breaking removal of Agent.run's on_trace and a behavior-sensitive change to when abandoned retry traces leave live views (now via base retry loop + _discard); episode streaming should be unchanged but callers relying on the old kwarg must migrate.
Overview
Removes the public
on_tracekwarg fromAgent.runand_EpisodeAgent.run. Mint-time trace handling is now internal: baseAgentdefines no-op_observe/_discardhooks,_run_oncewiresRolloutRuntoself._observe, and the retry loop calls_discardon abandoned attempts before backoff._EpisodeAgentoverrides those hooks to stamp seatname/trainable, forward to the episode’son_trace/on_discard, and drop superseded traces from live views—replacing the previous per-runwatchclosure (including discard-on-retry logic inlined there).Reviewed by Cursor Bugbot for commit 408b45a. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Drop
on_traceparameter fromAgent.runand replace with_observe/_discardhookson_tracecallback parameter fromAgent.runandAgent._run_once; callers passing it will now get aTypeError._observeand_discardhook methods toAgentthat subclasses can override;_observefires when a trace is minted,_discardfires when a retried attempt is abandoned before backoff._EpisodeAgentoverrides both hooks to stamp traces with seat metadata and forward events to episode-level callbacks, replacing the previous per-runwatch()closure.on_tracetoAgent.runor_EpisodeAgent.runwill break with aTypeError.Macroscope summarized 408b45a.