Skip to content

Commit 5cea1e0

Browse files
committed
chore: update settings and improve cascade_complete_taskless_steps safety and performance
- Added new Bash pattern for PGPASSWORD in settings.json - Included new mcp__sequentialthinking__sequentialthinking in settings - Enhanced cascade_complete_taskless_steps with iteration limit to prevent infinite loops - Added safety counter and exception handling for robustness - Improved documentation with detailed comments on safety and performance considerations
1 parent f462cf0 commit 5cea1e0

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.claude/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"Bash(./scripts/atlas-migrate-diff:*)",
55
"Bash(./scripts/atlas-migrate-hash:*)",
66
"Bash(./scripts/run-test-with-colors:*)",
7+
"Bash(PGPASSWORD=postgres psql -h 127.0.0.1 -p 50422 -U postgres -d postgres -c:*)",
78
"Bash(bin/run-test-with-colors:*)",
89
"Bash(cat:*)",
910
"Bash(cd:*)",
@@ -51,7 +52,8 @@
5152
"mcp__nx-mcp__nx_docs",
5253
"mcp__nx-mcp__nx_project_details",
5354
"mcp__nx-mcp__nx_workspace",
54-
"mcp__nx-mcp__nx_workspace_path"
55+
"mcp__nx-mcp__nx_workspace_path",
56+
"mcp__sequentialthinking__sequentialthinking"
5557
],
5658
"deny": []
5759
},

PLAN_cascade_complete_taskless_steps.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ This reduces cascade calls from 10,000 (every task) to 1 (when step completes)!
105105

106106
### The Cascade Function
107107

108-
Use a simple loop that completes all ready taskless steps:
108+
Use a simple loop that completes all ready taskless steps with safety measures:
109109

110110
```sql
111111
CREATE OR REPLACE FUNCTION pgflow.cascade_complete_taskless_steps(run_id uuid)
@@ -115,8 +115,16 @@ AS $$
115115
DECLARE
116116
v_total_completed int := 0;
117117
v_iteration_completed int;
118+
v_iterations int := 0;
119+
v_max_iterations int := 50; -- Safety limit matching worst-case analysis
118120
BEGIN
119121
LOOP
122+
-- Safety counter to prevent infinite loops
123+
v_iterations := v_iterations + 1;
124+
IF v_iterations > v_max_iterations THEN
125+
RAISE EXCEPTION 'Cascade loop exceeded safety limit of % iterations', v_max_iterations;
126+
END IF;
127+
120128
WITH completed AS (
121129
UPDATE pgflow.step_states
122130
SET status = 'completed',
@@ -133,24 +141,25 @@ BEGIN
133141
UPDATE pgflow.step_states ss
134142
SET remaining_deps = ss.remaining_deps - 1
135143
FROM completed c
136-
JOIN pgflow.deps d ON d.flow_slug = c.flow_slug
144+
JOIN pgflow.deps d ON d.flow_slug = c.flow_slug
137145
AND d.dep_slug = c.step_slug
138-
WHERE ss.run_id = c.run_id
146+
WHERE ss.run_id = c.run_id
139147
AND ss.step_slug = d.step_slug
140148
),
141149
-- Send realtime events and update run count...
142150
SELECT COUNT(*) INTO v_iteration_completed FROM completed;
143-
151+
144152
EXIT WHEN v_iteration_completed = 0;
145153
v_total_completed := v_total_completed + v_iteration_completed;
146154
END LOOP;
147-
155+
148156
RETURN v_total_completed;
149157
END;
150158
$$;
151159
```
152160

153161
**Performance**: 50 iterations once per step completion is acceptable
162+
**Safety**: Hard iteration limit prevents infinite loops from logic errors
154163

155164
### Integration Points
156165

0 commit comments

Comments
 (0)