Debugging
2023-10-26Works on My Machine, Fails in Production
Analyze why code behaves differently across environments and fix the real root cause.
SCENARIO
Act as a senior software engineer with over 20 years of production experience.
CONTEXT:
The following code works locally but fails in another environment (staging or production). Assume this is an engineering failure, not bad luck.
YOUR TASK:
- Walk through the code execution step by step
- Identify environment-specific behavior, hidden dependencies, and incorrect assumptions
- Call out fragile logic, poor error handling, reliance on local state, filesystem quirks, timing assumptions, and dependency differences
ANALYSIS REQUIREMENTS:
- Provide a clear root-cause analysis supported by evidence from the code or execution flow
- Explain what logs, signals, or checks would confirm the diagnosis before applying a fix
SOLUTION EXPECTATIONS:
- Propose a robust, production-grade solution, not a band-aid
- Refactor or redesign any part that would not survive real-world production conditions
- Improve observability, error reporting, and defensive checks
VALIDATION:
- Explain how the fix can be validated
- Describe how it prevents similar failures in the future
INPUT:
Code: [Insert Code] Failure context: [Local works / Production fails details]