Repository navigation
fix(observability): count turns_completed in the Linear and Jira comments - #1082
abhiramshaji-cyber wants to merge 5 commits into
Conversation
…ents After aws-samples#1075 the CLI and the web console show turns_completed, the count max_turns limits, while the completion comments on Linear and Jira still printed turns_attempted. One task could show two different turn counts, and the comment could print a number above the limit. The Linear and Jira completion comments, the turns metric of the Jira iteration comment and the final status the orchestration reconciler writes now read turns_completed. As in the CLI, a recorded 0 or a missing value is no count; these handlers have no agent_turn event to fall back to, so the comment shows the existing placeholder instead of turns_attempted. Refs aws-samples#919
isadeks
left a comment
There was a problem hiding this comment.
Looks good. I checked the switch against the writers: the agent's terminal write sets turns_attempted and turns_completed together (agent/src/pipeline.py, agent/src/task_state.py), and the cancel path writes neither, so no record can carry the old count without the new one. The four touched test files pass locally (366 tests). Two small non-blocking notes inline.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1082 +/- ##
=======================================
Coverage ? 93.83%
=======================================
Files ? 406
Lines ? 117335
Branches ? 13039
=======================================
Hits ? 110098
Misses ? 6635
Partials ? 602 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The Linear and Jira completion comments printed a different turn count from
bgagent status, sometimes above the limit, and now they print the same count the limit applies to.Hey @krokoko, hope you're doing well! Thank you for the breakdown of what was left after #1075, it made this one really easy to pick up. I switched exactly the four reads you listed and kept everything else as it was.
Area
cdk— infrastructure, handlers, constructsagent— Python runtime / Docker imagecli—bgagentclientdocs— guides or design sources (docs/guides/,docs/design/)tooling— rootmise.toml, scripts, CI workflowsRelated
Closes #919
Changes
What this code is for
When a task ends,
dispatchToLinearanddispatchToJirainfanout-task-events.tspost a completion comment withcost • turns • duration. For orchestration iterations,renderIterationCommentand the reconciler'sparseTerminalTaskRecordbuild the same Jira status line. All of them read the turn count off the task record.Before this PR
A Jira user starts a task with
max_turns80. The model answers 62 times; the SDK's own counter reaches 90.turns_completed: 62andturns_attempted: 90on the task record.bgagent statusreadsturns_completed(format.ts#L643) and shows62 / 80.dispatchToJirareadstask.turns_attempted(fanout-task-events.ts#L2030), and the Linear path does the same (#L1692).renderIterationCommentusesmetric('turns_attempted')(jira-iteration-comment.ts#L53) andparseTerminalTaskRecordreadsimg.turns_attempted(orchestration-reconciler.ts#L291).turns: 90 / 80while the CLI says62 / 80.After this PR
Same task, same record.
turns_completedinstead, through the samecoerceNumericOrNull(or the stream imageN/Sparse in the reconciler), and then through one sharedcompletedTurnsOrNull.turns: 62 / 80, matching the CLI and the console.turns_completedis missing,0, negative or not a number gets the existingturns: —, neverturns_attempted.The diagram
flowchart LR classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827 classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px classDef good fill:#c8f0c8,stroke:#008800,color:#111827,stroke-width:3px subgraph BEFORE["BEFORE: comment says 90 / 80"] direction TB B1["task ends, record has 62 and 90"] --> B2["dispatchToJira / renderIterationComment"] B2 --> B3["coerceNumericOrNull"] B3 --> B4{"read task.turns_attempted"} B4 -->|"SDK count, not what max_turns limits"| B5["turns: 90 / 80"] B4 -->|"field missing"| B6["turns: —"] end subgraph AFTER["AFTER: comment says 62 / 80"] direction TB A1["task ends, record has 62 and 90"] --> A2["dispatchToJira / renderIterationComment"] A2 --> A3["coerceNumericOrNull"] A3 --> A4{"THE CHANGE: read turns_completed"} A4 -->|"the count max_turns limits"| A5["turns: 62 / 80, same as CLI"] A4 -->|"missing or 0, as in the CLI"| A6["turns: — as before"] end B1 ~~~ A1 class B1,B2,B3,B6 box class A1,A2,A3,A6 box class B4,B5 bad class A4,A5 good linkStyle 3 stroke:#cc0000,stroke-width:5px linkStyle 8 stroke:#008800,stroke-width:5px style BEFORE fill:#fff5f5,stroke:#cc0000,color:#111827 style AFTER fill:#f3fff3,stroke:#008800,color:#111827The Jira final status renderer and the callers that hand it a turn count, Functions view in Architect
The change
fanout-task-events.ts: bothturns:args (Linear, which also feeds the Linear agent session activity, and Jira) readtask.turns_completed. This is the fix.jira-iteration-comment.ts: the fallback status readsmetric('turns_completed').orchestration-reconciler.ts:parseTerminalTaskRecordparsesturns_completedinstead ofturns_attempted.shared/numeric.ts: newcompletedTurnsOrNull, which keeps a count only when it is a finite number above 0. All four sites use it, so they share one rule for "no count" (a recorded 0 is no count, matching the CLI'srecorded || ...). Before, three sites used|| null, which let a negative through, while the reconciler checked finite and above 0.parseTerminalTaskRecordgets simpler with it, so its complexity record drops from 71 to 70.turns_completedand notturns_attempted; the max turns case shows100 / 100; cases for a missing,0or unparseableturns_completedin the three handler test files; the Linear agent session fixture getsturns_completedand a test that the final activity shows9 / 100;numeric.test.tscoverscompletedTurnsOrNullfor 1, 27, 100 and for undefined, null, 0, -0, -3, NaN and ±Infinity.What changes for a user
bgagent statusand the console, and it can no longer exceedmax_turns.turns_attemptedstays on the record for debugging; nothing reads it for display anymore.One question, only because it would change the fallback: the CLI falls back to the newest
agent_turnevent when the record has no count, but these handlers have no access to the events table, so I took the placeholder—as the default. Every terminal write from the agent sets both counters together, so I think that case is only a task that never ran the agent. Would you like the event lookup here as well, or is the placeholder fine? Happy to change it either way, and any feedback or tips are very welcome.Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.