A coding loop focused on optimizing API performance to ensure P95 latency stays under a defined target threshold. This loop iteratively runs load tests, analyzes bottlenecks, and implements optimizations until the goal is achieved or maximum iterations are reached.
Keep API latency within target
Run this loop in any supported coding agent environment to continuously optimize API endpoints based on real-time load testing feedback.
Initialize Environment
Ensure api-load.js script exists with proper k6 load test configuration targeting the API endpoints.
Start Loop Execution
Execute the loop by prompting the agent to begin performance optimization cycles using k6 load testing.
Monitor Exit Condition
Allow the agent to iterate up to 10 times, automatically checking if P95 latency meets the target after each optimization.
Run load test
if P95 latency >= target
Analyze performance metrics and identify bottlenecks
after step 1
Implement performance optimizations
after step 2
API
This loop standardizes API error responses across the application to improve client-side error handling and debugging. It ensures all error responses follow a consistent structure (e.g., RFC 7807 Problem Details format) with appropriate HTTP status codes and machine-readable error codes.
API
Automatically detects and resolves issues in failing API integration endpoints through iterative testing and code modifications.
API
Automatically identifies and documents all undocumented API endpoints in the project. The agent iteratively generates OpenAPI/Swagger documentation until all endpoints meet the required documentation standards.
Re-run load test
after step 3
Check P95 against target and decide exit or repeat
if iterations < 10 and P95 >= target
Exit loop successfully
if P95 < target
Exit loop after max iterations
if iterations >= 10 and P95 still >= target
Start the "API Performance Budget" loop. Goal: Keep API latency within target Max iterations: 10 Between iterations run: k6 run api-load.js Exit when: P95 latency below target Optimize the API to meet the P95 latency target defined in the load test script. Run iterative optimizations until the target is achieved or 10 iterations are completed. Self-pace this loop. After each iteration, run `k6 run api-load.js` and evaluate the output, and only continue if the exit condition is not met (P95 latency below target). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.