feat(batch): support external device task workflow#78
Conversation
| @@ -1198,7 +1554,7 @@ func (h *BatchHandler) AdjustBatchTasks(c *gin.Context) { | |||
| } | |||
| var batch batchStatusRow | |||
| if err := tx.Get(&batch, | |||
There was a problem hiding this comment.
CRITICAL: AdjustBatchTasks acquires the batch row lock before acquiring the order row lock. tryAdvanceOrderStatus (called by CompleteTasks) locks the order first and then updates batches. This inconsistent lock ordering can cause deadlocks when both operations run concurrently on the same order and batch (each holds one lock and waits for the other). Fix: always lock the order before the batch. For example, first read the batch's order_id using a non-locking SELECT, then lock the order with FOR UPDATE, and finally lock the batch with FOR UPDATE.
|
|
||
| if info.Status == "in_progress" && completedCount == info.TargetCount { | ||
| if info.Status == "in_progress" && completedCount >= info.TargetCount { | ||
| if _, err := tx.Exec( |
There was a problem hiding this comment.
HIGH: After executing the UPDATE to set order status='completed', the code does not check RowsAffected(). If another concurrent request already completed the order, this UPDATE will affect 0 rows, but the function still calls finalizeOpenBatchesAfterOrderCompletedTx and sends recorder notifications. This causes duplicate finalization and spurious device cancellations. Fix: capture sql.Result, check RowsAffected(), and return early if 0 rows were updated.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
HIGH
Other Observations (not in diff)
Files Reviewed (8 files)
Fix Link: Fix these issues in Kilo Cloud Reviewed by step-3.5-flash · 2,439,796 tokens |
Pull Request Checklist
Please ensure your PR meets the following requirements:
Summary
This PR adds the Keystone backend support for an external-device operator workflow, including collector-owned batch task completion by task group and the design documentation for the mobile handoff payload.
Motivation
batch_id.Changes
Modified Files
[internal/api/handlers/batch.go](internal/api/handlers/batch.go)- Adds data-collector task-group completion for planned batch tasks and enforces dispatch/adjustment quota boundaries.[internal/api/handlers/batch_test.go](internal/api/handlers/batch_test.go)- Adds and updates coverage for external-device completion, task-group validation, quota enforcement, ownership checks, and terminal batch rejection.[internal/api/handlers/auth.go](internal/api/handlers/auth.go)- Includes workstation robot type capability metadata in/auth/meso Synapse can select the correct operator workflow.[internal/api/handlers/order.go](internal/api/handlers/order.go)- Aligns order completion and open-batch finalization behavior with the planned-task workflow.[internal/server/server.go](internal/server/server.go)- Registers the collector completion route.[docs/designs/production-units.md](docs/designs/production-units.md)- Updates production-unit quota semantics for task-row-based dispatch.[docs/designs/task-manage.md](docs/designs/task-manage.md)- Updates task management behavior for external-device completion.Added Files
[docs/designs/external-device-mobile-task-flow.md](docs/designs/external-device-mobile-task-flow.md)- Documents the external-device mobile task flow, backend behavior, copy payload shape, and acceptance criteria.Deleted Files
Type of Change
Impact Analysis
Breaking Changes
None
Backward Compatibility
Fully backward compatible. Existing robot types continue to use the Axon workflow unless
robot_types.capabilities.requires_axonis explicitly set tofalse.Testing
Test Environment
keystone-worktree2Test Cases
Manual Testing Steps
No manual browser or device testing was performed for this backend PR.
Test Coverage
Command run:
go test ./...Screenshots / Recordings
Not applicable for this backend and documentation PR.
Performance Impact
Documentation
Related Issues
Additional Notes
Reviewers
@reviewer1 @reviewer2
Notes for Reviewers
[internal/api/handlers/batch.go](internal/api/handlers/batch.go).Checklist for Reviewers