Auto-generated tile from GitHub (10 skills)
92
94%
Does it follow best practices?
Impact
92%
1.16xAverage score across 44 eval scenarios
Advisory
Suggest reviewing before use
A SaaS company runs a customer verification service that handles thousands of incoming requests per minute. Each request involves:
After load testing, the operations team discovered that p99 request latency spikes to over 500ms during peak load, even though each individual operation appears fast in isolation. The initial hypothesis is that the service is encountering a hidden resource contention problem — but they can't see it from regular application logs.
A senior engineer suspects the issue is related to how Node.js handles blocking operations internally. Your task is to analyze the provided service code, diagnose the root cause of the latency spikes, produce a corrected version of the service, and provide a startup script and monitoring code so the team can observe the fix working.
Produce the following files:
fixed-service.js — A corrected version of inputs/service.js that addresses the root cause(s) of the thread pool saturationstart.sh — A shell script to start the fixed service with the correct environment configuration for a production deployment on an 8-core machinediagnosis.md — An explanation of what caused the latency spikes and how the fix addresses itmonitoring.js — A self-contained Node.js script that measures and reports event loop health metrics relevant to detecting the bottleneck described in the diagnosisThe following file is provided as input. Extract it before beginning.
=============== FILE: inputs/service.js =============== 'use strict';
const http = require('node:http'); const dns = require('node:dns'); const fs = require('node:fs/promises'); const path = require('node:path');
// Path to the shared configuration file const CONFIG_FILE = path.join(__dirname, 'customer-config.json');
// Cache: populated once on startup, then used per-request let configCache = null;
async function loadConfig() { // Read entire config into memory on each cache miss const raw = await fs.readFile(CONFIG_FILE, 'utf8'); configCache = JSON.parse(raw); }
async function resolveCustomerHost(hostname) { // Resolve hostname to IP for verification return new Promise((resolve, reject) => { dns.lookup(hostname, (err, address) => { if (err) return reject(err); resolve(address); }); }); }
async function handleRequest(req, res) { try { // Ensure config is loaded if (!configCache) { await loadConfig(); }
// Parse customer info from request
const url = new URL(req.url, `http://${req.headers.host}`);
const customerId = url.searchParams.get('customer_id');
const hostname = url.searchParams.get('hostname') || 'example.com';
// Resolve hostname for every request
const ip = await resolveCustomerHost(hostname);
// Look up customer in config
const customerConfig = configCache?.[customerId];
if (!customerConfig) {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Customer not found' }));
return;
}
// Simulate verification
const verified = customerConfig.allowed_ips?.includes(ip) ?? false;
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
customer_id: customerId,
hostname,
resolved_ip: ip,
verified
}));} catch (err) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: err.message })); } }
const server = http.createServer(handleRequest);
// Attempt to tune thread pool at runtime (done before starting server) process.env.UV_THREADPOOL_SIZE = 8;
server.listen(3000, () => { console.log('Customer verification service listening on port 3000'); });
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
scenario-15
scenario-16
scenario-17
scenario-18
scenario-19
scenario-20
scenario-21
scenario-22
scenario-23
scenario-24
scenario-25
scenario-26
scenario-27
scenario-28
scenario-29
scenario-30
scenario-31
scenario-32
scenario-33
scenario-34
scenario-35
scenario-36
scenario-37
scenario-38
scenario-39
scenario-40
scenario-41
scenario-42
scenario-43
scenario-44
skills
documentation
fastify
init
linting-neostandard-eslint9
node
nodejs-core
rules
oauth
octocat
snipgrapher