Repository navigation
fix(cdk): settle a failed child's issue only once per task - #1083
abhiramshaji-cyber wants to merge 3 commits into
Conversation
isadeks
left a comment
There was a problem hiding this comment.
Thanks, the marker approach reads cleanly and the PR's own tests pass locally (112 in orchestration-reconciler.test.ts). I checked the behaviour on this head with a few throwaway tests against the same store harness. Two things I'd change before merge, one trade-off to confirm with the maintainer, and one open question. Details inline.
- A DynamoDB error on the marker write now fails the whole record, and the retry reverts the issue again.
- That same gap means a hand move can still be undone when the first delivery dies between the tracker calls and the marker write.
- Marking after a failed tracker call is a deliberate choice here, but it means a short tracker outage leaves a failed sub-task showing ✅ for good.
- Question on a failed iteration under the same task id (not verified).
On the question in the description: the marker is a new stored attribute on the child row, and cdk/AGENTS.md lists DynamoDB schema changes under ask-first, so it is good that you raised it. If it stays, it should be added to the row type and the orchestrator design doc.
| // what a later run did). | ||
| const settleChannel = channelForMeta(snapshot.meta); | ||
| if (settleChannel && !plan.terminalSucceeded && !stale && !isIntegrationNode(subIssueId)) { | ||
| if (settleChannel && !plan.terminalSucceeded && !stale && !settled && !isIntegrationNode(subIssueId)) { |
There was a problem hiding this comment.
Two points on the skip.
Trade-off to confirm. The description says the marker is written even when the tracker call failed, and there is a test for it, so this is intended. The cost: with the tracker down for the first delivery and back for the next two, I saw the marker set and the issue never reverted or given ❌ (0 successful reverts, 0 ❌ reactions). Before this PR a later write healed it. A middle ground would be to let a thrown tracker error fail the record so the stream retries it within its normal retry window, and still mark once that window is over. Worth a decision from the maintainer either way.
Question, not verified. A reply on a failed sub-task starts an iteration while the row keeps the same child_task_id. If that iteration fails, cascadeRestack returns at "source task not successful" without settling the issue. Can the issue be left in a running state there? If so, a later write on the original task used to revert it and now will not. I did not trace the iteration path, so this may be a non-issue.
There was a problem hiding this comment.
Thank you for testing the outage case and for the iteration question, both were really worth digging into.
On the trade off, one thing I found while tracing it: the real adapters never throw here. revertIssueToNotStarted returns false on any failure, swapReaction returns false when a request fails, Slack's reaction swap does the same, and Jira has neither call. So a tracker outage shows up as false, and for the revert false also means "left alone on purpose" (the issue isn't in a started state because a person already moved it). Letting a failed tracker call fail the record would mean having the adapters report a retryable failure separately. graphqlRequest already works out retryable for 5xx and 429, so it's doable. The stream retries 3 times with bisect, so the retry window is short. For now I kept it as it was: settle once, even if the tracker call didn't land. @krokoko, would you rather have the retry on a retryable tracker failure? Happy to add it either way.
On the question: I traced it, and yes, it can happen. An iteration task carries linear_issue_id = the child issue. The agent moves it to In Progress when it starts (react_task_started, not read only) and leaves it there on failure (react_task_finished moves it only on success). replyToIterationComment sets ❌ on the comment but, by design, leaves the state ("On failure, leave the state … Never demote"). Before this PR the issue only came back to Todo if the original task record happened to get another write, which is the same write this PR stops. If it would help, I could revert the issue in the failure branch of replyToIterationComment, behind the existing once per iteration ack_replied_at claim, so a late write can't repeat it. Since that changes a documented choice, I left it out for now. Would you like it here, or in a separate PR?

What replyToIterationComment calls, Functions view in Architect
…aws-samples#1073) A DynamoDB error on the marker write failed the record after the issue was already reverted, and the retry reverted it again. The marker is now claimed with a conditional write before the tracker calls, so a failed claim leaves the issue untouched and a retry after the claim never settles twice. Adds settled_task_id to the row type and the design doc.
|
Hey @isadeks, hope you're doing well! Thanks a lot for such a careful review, and for running the throttle and outage cases, that made both problems really clear. I pushed a fix for both blockers. The marker is now claimed with a conditional write before the tracker calls, so a DynamoDB error fails the record before the issue is touched, and a retry after the claim never reverts it again. On the two open points, I kept the current behaviour and wrote up what I found in the thread so @krokoko can decide: whether to retry a tracker call that fails, and whether a failed iteration should move its issue back. Happy to change either one. |
|
Hi @abhiramshaji-cyber , thank you for this ! It was closed by #1084 , if you want to assign an issue to yourself please let us know on a ticket to avoid duplicated work on our end! |
When a subtask fails, its issue is now moved back and given ❌ exactly once, so neither a later write on its task record nor a retry of the same record undoes a move a person made.
Hey @krokoko, hope you're doing well! Your write up made this really easy to follow, thank you, especially the second delivery trick in the build gate test, which reproduced it straight away.
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 #1073
Changes
What this code is for
reconcileTerminalChildincdk/src/handlers/orchestration-reconciler.tsruns for every stream record of a finished task that belongs to an orchestration. It writes the verdict onto the child row, and for a child that did not succeed (step 1b) it callsrevertStateandreplaceIssueReaction(..., 'failed')on the subtask's issue.Before this PR
A subtask opens a pull request whose build is red, and a person fixes it and moves the Linear issue to "In Review".
COMPLETED,build_passed = false) arrives. Step 1 writeschild_status = failedunderchild_task_id = :tid AND (child_status = :running OR child_status = :s).failed(thechild_status = :shalf of the condition), so nothing marks the record as out of date.revertIssueToNotStartedmoves the issue back to Todo and the reaction goes back to ❌.After this PR
Same subtask, same person, same later push.
child_status = failedas before.claimSettlewritessettled_task_id = TAunderchild_task_id = :tid AND child_status = :failed AND (attribute_not_exists(settled_task_id) OR settled_task_id <> :tid). It succeeds, so step 1b reverts the issue and sets ❌.claimSettlefails its condition becausesettled_task_idis alreadyTA.If DynamoDB throws on the
claimSettlewrite (a throttle), the record is reported for retry before the issue is touched, and the retry settles it once. If the record fails after the claim, or the Lambda times out during the tracker calls, the retry finds the claim and does not settle again.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: every later write reverts the issue"] direction TB B1["later write on task TA"] --> B2["reconcileTerminalChild"] B2 --> B3["step 1: child_status = failed"] B3 --> B4{"row already failed for TA"} B4 -->|"condition passes"| B5["step 1b: issue back to Todo, reaction ❌"] B4 -->|"row moved on"| B6["out of date, issue left alone"] end subgraph AFTER["AFTER: settled once per task"] direction TB A1["later write on task TA"] --> A2["reconcileTerminalChild"] A2 --> A3["step 1: child_status = failed"] A3 --> A4{"THE CHANGE: claimSettle before tracker calls"} A4 -->|"settled_task_id already TA"| A5["step 1b skipped, issue stays In Review"] A4 -->|"first claim for TA"| A6["step 1b runs once"] 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:#111827A terminal task record from handler through reconcileTerminalChild to the settle, Functions view in Architect
The change
claimSettle(L538 to L552) claimssettled_task_idwith a conditional write, and step 1b runs only when that claim wins (L669). The claim also requireschild_task_id = :tidandchild_status = failed, so a row released to a new task or repaired between the verdict and the claim keeps its issue as it is.settled_task_idis a new optional attribute on the child row (DynamoDB schema change, ask first undercdk/AGENTS.md). It is inOrchestrationChildRowand in a new "Orchestration table" section ofdocs/design/ORCHESTRATOR.md.completed_atyou suggested, because the stream isNEW_IMAGEonly (task-table.ts L142) and a window still reverts a hand move that lands inside it. Would you rather have the window anyway, or this marker? Happy to switch.cdk/test/handlers/orchestration-reconciler.test.ts: a repeated later write, a settle whose tracker call failed, a marker left by an earlier task, a throttled claim, a failure after the claim, and a row released or repaired between the verdict and the claim.What changes for a user
falsetoday rather than throwing), and whether a failed iteration should move its issue back.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.