feat(coding-agent): report in-flight tool-call progress in agent_observe - #891
Open
Hotragn wants to merge 1 commit into
Open
feat(coding-agent): report in-flight tool-call progress in agent_observe#891Hotragn wants to merge 1 commit into
Hotragn wants to merge 1 commit into
Conversation
AgentObserveAgentSummary collapsed a child's entire set of in-flight tool calls into status: "tool" with no count and no time. A child three seconds into a fast bash call and a child forty minutes into one blocked on a subprocess that never exits produced byte-identical summaries, so an orchestrator had no way to express "treat a child stuck in one tool call for more than N minutes as wedged". The bash tool's timeout is optional with no default, so an indefinitely blocking call is ordinary behavior, not an error path. The agent runtime only tracked pending tool call ids, never when they started. Add AgentState.pendingToolCallStartedAt, keyed by the same ids as pendingToolCalls and cleared on tool_execution_end, reset, and run finish. Summaries now carry pendingToolCallCount plus, when something is in flight, oldestPendingToolCallStartedAt and pendingToolCallElapsedMs. Both the timestamp and the duration are reported: elapsed is what a policy reads directly, and the timestamp lets a caller recompute against its own clock or across polls. A passive subagent has no live agent, so it reports a count of zero. fixes PrimeIntellect-ai#822
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.
Fixes #822.
agent_observetold an orchestrator that a child was executing a tool call, never how long.AgentObserveAgentSummarycollapsed the whole in-flight set intostatus: "tool"— no count, no start time, no duration — so a child three seconds into a fastbashcall and a child forty minutes into one blocked on a subprocess that never exits produced byte-identical summaries. Sincebash'stimeoutis optional with no default, an indefinitely blocking call is ordinary behaviour rather than an error path, and there was no way to write "treat a child stuck in one tool call for more than N minutes as wedged" against the API.The time dimension did not exist
AgentStatetrackedpendingToolCallsas a bareSet<string>of ids; nothing anywhere recorded when a call started, so this could not be fixed in the coding-agent alone.packages/agentnow keepsAgentState.pendingToolCallStartedAt: ReadonlyMap<string, number>alongside it — populated in thetool_execution_startreducer, removed intool_execution_end, and cleared byreset()andfinishRun()exactly wherependingToolCallsis. It is replaced rather than mutated in place, matching how the existing set is updated, so snapshot readers keep seeing a stable value. It joins theOmitlists that keep runtime-owned state out ofinitialState, so it cannot be seeded from the outside.What summaries now carry
Every
AgentObserveAgentSummarygains:pendingToolCallCount— tool calls executing right now. Required, so a caller can always branch on it. A passive (non-resident) subagent has no live agent and reports0.oldestPendingToolCallStartedAt— epoch ms of the longest-running in-flight call. Absent when nothing is in flight.pendingToolCallElapsedMs— how long that call has been running, measured when the summary was built.Both the timestamp and the duration are reported deliberately: elapsed is what a policy reads directly, while the timestamp lets a caller recompute against its own clock or diff across two polls without trusting the daemon's wall clock.
summarizeInFlightToolCallsis a small exported pure function so all three fields have one definition and one test surface, and it clamps elapsed at0rather than reporting a negative duration if the clock moves backwards.The Python
agent_observeskill passes host payloads through unchanged, so the fields are available from the kernel with no skill change.SKILL.mddocuments them with the policy this issue asks for:Scope
statuswas already correct for a wedged child — it reports"tool", andlatestMessage.toolCallsnames the tools — so nothing about status classification changed. This adds only the missing time and count.No daemon schema revision:
AgentObserveAgentSummaryis carried insideagent_observe.*host-bridge results, not the daemon command/event wire types the schema id covers.Tests
packages/coding-agent/test/suite/regressions/822-agent-observe-tool-elapsed.test.ts(4 cases): the empty case reports a zero count and no timestamps; a three-call map picks the oldest start rather than the most recent and derives elapsed from it; a backwards clock yields0rather than a negative; and a live-session case runs two tools that block until released, asserting the tracked ids matchpendingToolCallsexactly, that the recorded starts are not earlier than the moment the turn began, that both calls are counted concurrently, and that the map is empty again once the run finishes.Three existing controller fixtures construct summaries by hand and were updated for the now-required count.
Verified:
npm run checkclean;packages/agentfull suite 69/69;agent-session-observe,agent-session-services, and the new suite 9/9.Note
Report in-flight tool-call count and elapsed time in
agent_observesummariespendingToolCallStartedAt: Map<string, number>toAgentStatein agent.ts, recording epoch ms start times keyed by tool call ID ontool_execution_startand cleared ontool_execution_end.summarizeInFlightToolCallsin agent-observe.ts to computependingToolCallCount,oldestPendingToolCallStartedAt, andpendingToolCallElapsedMsfrom the state map.listAgents/getAgentresponses; passive subagents without a live session reportpendingToolCallCount: 0.Macroscope summarized 3e1ac80.