code-graph-context 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -23,6 +23,12 @@ const CLAIM_TASK_BY_ID_QUERY = `
|
|
|
23
23
|
// Only claim if all dependencies are complete
|
|
24
24
|
WHERE incompleteDeps = 0
|
|
25
25
|
|
|
26
|
+
// Acquire exclusive lock to prevent race conditions
|
|
27
|
+
CALL apoc.lock.nodes([t])
|
|
28
|
+
|
|
29
|
+
// Double-check status after acquiring lock
|
|
30
|
+
WITH t WHERE t.status IN ['available', 'blocked']
|
|
31
|
+
|
|
26
32
|
// Atomic claim
|
|
27
33
|
SET t.status = 'claimed',
|
|
28
34
|
t.claimedBy = $agentId,
|
|
@@ -57,6 +63,7 @@ const CLAIM_TASK_BY_ID_QUERY = `
|
|
|
57
63
|
`;
|
|
58
64
|
/**
|
|
59
65
|
* Query to claim the highest priority available task matching criteria
|
|
66
|
+
* Uses APOC locking to prevent race conditions between parallel workers
|
|
60
67
|
*/
|
|
61
68
|
const CLAIM_NEXT_TASK_QUERY = `
|
|
62
69
|
// Find available tasks not blocked by dependencies
|
|
@@ -75,6 +82,12 @@ const CLAIM_NEXT_TASK_QUERY = `
|
|
|
75
82
|
ORDER BY t.priorityScore DESC, t.createdAt ASC
|
|
76
83
|
LIMIT 1
|
|
77
84
|
|
|
85
|
+
// Acquire exclusive lock to prevent race conditions
|
|
86
|
+
CALL apoc.lock.nodes([t])
|
|
87
|
+
|
|
88
|
+
// Double-check status after acquiring lock (another worker may have claimed it)
|
|
89
|
+
WITH t WHERE t.status = 'available'
|
|
90
|
+
|
|
78
91
|
// Atomic claim
|
|
79
92
|
SET t.status = 'claimed',
|
|
80
93
|
t.claimedBy = $agentId,
|
|
@@ -11,7 +11,7 @@ import { createErrorResponse, createSuccessResponse, resolveProjectIdOrError, de
|
|
|
11
11
|
*/
|
|
12
12
|
const COMPLETE_TASK_QUERY = `
|
|
13
13
|
MATCH (t:SwarmTask {id: $taskId, projectId: $projectId})
|
|
14
|
-
WHERE t.status
|
|
14
|
+
WHERE t.status IN ['in_progress', 'claimed'] AND t.claimedBy = $agentId
|
|
15
15
|
|
|
16
16
|
SET t.status = 'completed',
|
|
17
17
|
t.completedAt = timestamp(),
|
|
@@ -29,17 +29,21 @@ const COMPLETE_TASK_QUERY = `
|
|
|
29
29
|
|
|
30
30
|
// Check if waiting tasks now have all dependencies completed
|
|
31
31
|
WITH t, collect(waiting) as waitingTasks
|
|
32
|
+
|
|
33
|
+
// Unblock tasks that have all dependencies met
|
|
32
34
|
UNWIND (CASE WHEN size(waitingTasks) = 0 THEN [null] ELSE waitingTasks END) as waiting
|
|
33
35
|
OPTIONAL MATCH (waiting)-[:DEPENDS_ON]->(otherDep:SwarmTask)
|
|
34
36
|
WHERE otherDep.status <> 'completed' AND otherDep.id <> t.id
|
|
35
37
|
WITH t, waiting, count(otherDep) as remainingDeps
|
|
36
|
-
WHERE waiting IS NOT NULL AND remainingDeps = 0
|
|
37
38
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// Update status for tasks with no remaining deps (but don't filter out the row)
|
|
40
|
+
FOREACH (_ IN CASE WHEN waiting IS NOT NULL AND remainingDeps = 0 THEN [1] ELSE [] END |
|
|
41
|
+
SET waiting.status = 'available', waiting.updatedAt = timestamp()
|
|
42
|
+
)
|
|
41
43
|
|
|
42
|
-
WITH t,
|
|
44
|
+
WITH t, CASE WHEN waiting IS NOT NULL AND remainingDeps = 0 THEN waiting.id ELSE null END as unblockedId
|
|
45
|
+
WITH t, collect(unblockedId) as allUnblockedIds
|
|
46
|
+
WITH t, [id IN allUnblockedIds WHERE id IS NOT NULL] as unblockedTaskIds
|
|
43
47
|
|
|
44
48
|
RETURN t.id as id,
|
|
45
49
|
t.title as title,
|
|
@@ -112,16 +116,21 @@ const APPROVE_TASK_QUERY = `
|
|
|
112
116
|
|
|
113
117
|
// Check if waiting tasks now have all dependencies completed
|
|
114
118
|
WITH t, collect(waiting) as waitingTasks
|
|
119
|
+
|
|
120
|
+
// Unblock tasks that have all dependencies met
|
|
115
121
|
UNWIND (CASE WHEN size(waitingTasks) = 0 THEN [null] ELSE waitingTasks END) as waiting
|
|
116
122
|
OPTIONAL MATCH (waiting)-[:DEPENDS_ON]->(otherDep:SwarmTask)
|
|
117
123
|
WHERE otherDep.status <> 'completed' AND otherDep.id <> t.id
|
|
118
124
|
WITH t, waiting, count(otherDep) as remainingDeps
|
|
119
|
-
WHERE waiting IS NOT NULL AND remainingDeps = 0
|
|
120
125
|
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
// Update status for tasks with no remaining deps (but don't filter out the row)
|
|
127
|
+
FOREACH (_ IN CASE WHEN waiting IS NOT NULL AND remainingDeps = 0 THEN [1] ELSE [] END |
|
|
128
|
+
SET waiting.status = 'available', waiting.updatedAt = timestamp()
|
|
129
|
+
)
|
|
123
130
|
|
|
124
|
-
WITH t,
|
|
131
|
+
WITH t, CASE WHEN waiting IS NOT NULL AND remainingDeps = 0 THEN waiting.id ELSE null END as unblockedId
|
|
132
|
+
WITH t, collect(unblockedId) as allUnblockedIds
|
|
133
|
+
WITH t, [id IN allUnblockedIds WHERE id IS NOT NULL] as unblockedTaskIds
|
|
125
134
|
|
|
126
135
|
RETURN t.id as id,
|
|
127
136
|
t.title as title,
|
package/package.json
CHANGED