Repository navigation
fix(agent): report session-cumulative total_turns in completion logs - #728
Conversation
total_turns was sourced from the per-request AgentContext.Turns, which is rebuilt from 0 for every user message, so it always read 1 in normal back-and-forth chat. Repoint it to the session-cumulative sessionTurns counter, and log the per-request model-round count separately as run_turns. Observability only: AgentContext.Turns, MaxTurns, and the turn limiter are unchanged. Closes #727
Follow-up to PR review: - total_turns was emitted three times per completion (completing-state entry and success, plus the idle-reached event loop); log it once at the turn-complete boundary, reading sessionTurns directly. - Drop run_turns: outside a tool-call loop it is always 1, so it only added noise. - The StateContext.SessionTurns accessor added earlier in this PR is now unused; remove it.
The "system reminder injected" debug log carried the per-request agentCtx.Turns as "turn", which is 1 for every normal chat message (it only climbs inside a tool loop). session_turn already carries the meaningful cumulative count, so drop the noisy field. ReminderQuery.Turn (used to gate reminders) and the TUI debug-stream event are unchanged.
|
@claude Can you review this? any leftovers? missing cleanups? use /go /go-spec-reviewer |
|
Claude finished @edenreich's task in 7m 42s —— View job Review: PR #728 -
|
## [0.128.0](v0.127.0...v0.128.0) (2026-07-03) ### 🚀 Features * **chat:** make status indicators selectable with /tools and /a2a views ([#732](#732)) ([6882de0](6882de0)), closes [#717](#717) [#717](#717) ### 🐛 Bug Fixes * **agent:** drop redundant Idle transition that errored on every run ([#726](#726)) ([469ec64](469ec64)), closes [#722](#722) [#725](#725) * **agent:** report session-cumulative total_turns in completion logs ([#728](#728)) ([0d8fb08](0d8fb08)), closes [#727](#727) * **a2a:** route active A2A reads and HasPending through the job supervisor ([#693](#693)) ([#721](#721)) ([dcd0670](dcd0670)), closes [#718](#718) [#719](#719) [#720](#720) * **keybindings:** stop "unknown keybinding action" log flood ([#724](#724)) ([c828426](c828426)), closes [#714](#714) [#722](#722) * **a2a:** unify background-job liveness, clear, and cancel on the supervisor contract ([#730](#730)) ([eb37fd0](eb37fd0)), closes [#693](#693) [#720](#720) [#718](#718) [#719](#719) * **logging:** use structured key/value form at misused call sites ([#729](#729)) ([cd96028](cd96028)), closes [#722](#722) [#724](#724) [#724](#724) [#723](#723) * **tools:** wait for pipe readers before reaping detached bash shells ([#716](#716)) ([e1d0d84](e1d0d84)), closes [#696](#696) ### ⚡ Performance Improvements * **tui:** cache per-entry rendering and keep the Update loop responsive ([#731](#731)) ([8c9db0d](8c9db0d)) ### 📚 Documentation * **a2a:** add SKILL.md documentation for Agent2Agent protocol ([defcd57](defcd57)) ### 🔧 Build System * **deps:** bump golang.org/x/net from 0.47.0 to 0.55.0 in /examples/mcp/mcp-server ([#715](#715)) ([990803b](990803b)) ### 🧹 Maintenance * **flox:** bump dev deps ([d0c8f6b](d0c8f6b))
|
🎉 This PR is included in version 0.128.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
The
total_turnsfield in the agent completion logs always read1in normal back-and-forth chat. It was sourced from the per-requestAgentContext.Turns, which is rebuilt from0for every user message, so it could only ever reflect the current message's model-round count — never the conversation's running total. On top of that it was emitted three times per completion (two of them microseconds apart). Pure observability bug; nothing keys off the value.Fix
Log
total_turnsonce, at the turn-complete boundary inprocessEvents("agent reached Idle state - turn complete"), sourced from the session-cumulativeAgentServiceImpl.sessionTurns— anatomic.Int64already maintained right alongsideTurns, previously read only for reminder cadence. The two redundantcompleting.gocopies are dropped (the "finalizing" trace keepsqueue_empty; the duplicate "completed successfully" line is removed).Observability only —
AgentContext.Turns,MaxTurns, and thectx.Turns >= ctx.MaxTurnslimiter are untouched. Also drops a stale inline comment onApprovalDelivery.Test
No log-observer harness exists in the repo (tests default to
zap.NewNop()) and no behaviour branches on the value, so no new log-assertion test is warranted.agent_reminder_emission_test.goalready asserts the session-vs-per-request counter distinction this fix relies on, andTestHandleCompletingStatecovers the completing-state path.go build ./...,golangci-lint(0 issues), and fullgo test ./...all pass.Closes #727