Purpose: Systematic workflow for fixing bugs in existing code.
STOP. Present the following questions to the developer and wait for their answers. Do not read code, run tests, or start investigating until the developer has answered these questions. Do not infer or assume answers.
If the developer cannot provide reproduction steps, ask for logs, error messages, or a description of expected vs actual behavior.
-
"What is the unexpected behavior you are seeing?"
- Get a clear description of what is going wrong.
-
"What should happen instead? What is the expected behavior?"
-
"How do you reproduce this bug? What are the steps?"
- If the developer cannot reproduce it, ask:
- "Do you have any error messages or stack traces?"
- "Do you have a trackingId from the logs?"
- "When did this start happening? Was there a recent code change?"
- If the developer cannot reproduce it, ask:
-
"Which layer do you think is affected?"
- Plugin (
cc.ts) - Service (
services/*) - Core (
services/core/*) - Types
- Not sure (this is fine — you will investigate)
- Plugin (
-
"Are there any error messages or stack traces you can share?"
-
"Is there a trackingId from the logs associated with this bug?"
Before proceeding to investigation, verify:
- Unexpected behavior described by developer
- Expected behavior described by developer
- Reproduction steps provided (or logs/error messages if steps are unknown)
- Affected layer identified (or "not sure" — which is acceptable)
If the description is too vague to start investigating (e.g., "it's broken"), ask targeted follow-up questions. Do not proceed until you have enough context to know where to look.
Only proceed here after Section A questions are answered.
- Read the affected code — trace the execution flow
- Identify where behavior diverges from the developer's expected behavior
- Check the call chain: plugin -> service -> core
# Run tests for the affected area
yarn workspace @webex/contact-center test:unit -- <path_to_specific_file>Are there tests that should have caught this? Do they pass incorrectly?
A. Async/Promise Issues
// Bug: Not awaiting promise
this.services.agent.stateChange({data});
// Fix: Await the promise
await this.services.agent.stateChange({data});B. Missing Error Handling
// Bug: Error swallowed
try {
await operation();
} catch (e) {}
// Fix: Proper error handling
try {
await operation();
} catch (error) {
const {error: detailedError} = getErrorDetails(error, method, module);
throw detailedError;
}C. Event Listener Leaks
// Bug: Listener not removed
this.on('event', handler);
// Fix: Store reference and remove
this.handler = (data) => { /* handle */ };
this.on('event', this.handler);
// Later in cleanup:
this.off('event', this.handler);D. Type Mismatches
// Bug: Accessing wrong property
const id = response.data.agentId; // But it's response.agentId
// Fix: Check actual response structure
const id = response.agentId;E. Missing Null Checks
// Bug: Crashes if undefined
const name = this.agentConfig.teams[0].teamName;
// Fix: Optional chaining
const name = this.agentConfig?.teams?.[0]?.teamName;STOP. Before writing any fix, present your findings to the developer:
## Bug Analysis Summary
**Bug**: [one-sentence description]
**Root cause**: [what is actually wrong in the code]
**Affected file(s)**: [file paths and line numbers]
**Root cause category**: [A/B/C/D/E from patterns above, or other]
### Proposed Fix:
- [What will change in which file]
- [What the code will look like after the fix]
### Risk Assessment:
- Could this fix break anything else? [Yes/No — if yes, what]
- Backward compatible? [Yes/No]
### Tests to Add:
- [Regression test description]
---
Does this analysis look correct? Should I proceed with this fix? (Yes / No / Adjust)
Wait for developer confirmation before implementing the fix.
After developer approval:
// 1. Make the minimal fix
// 2. Add/update logging if it helps debugging
LoggerProxy.log('Processing data', {
module: MODULE,
method: METHOD,
data: { relevantField: value }, // Add context
});
// 3. Ensure error handling is complete
try {
// fixed code
} catch (error) {
LoggerProxy.error(`Operation failed: ${error}`, {
module: MODULE,
method: METHOD,
});
// ... proper error handling
}describe('methodName - Bug Fix', () => {
it('should handle [specific scenario that was buggy]', async () => {
// Arrange: Setup the conditions that triggered the bug
const bugTriggerInput = { /* ... */ };
// Act: Execute the fixed code
const result = await service.methodName(bugTriggerInput);
// Assert: Verify correct behavior
expect(result).toEqual(expectedResult);
});
it('should not throw error when [edge case]', async () => {
// Test the specific edge case that was failing
});
});- Fix is minimal and focused
- No unrelated changes
- LoggerProxy used (no console.log)
- Error handling complete
- Regression test added
- All existing tests still pass
- Test covers the specific bug scenario
# Lint
yarn workspace @webex/contact-center test:style
# All tests
yarn workspace @webex/contact-center test:unit
# Build
yarn workspace @webex/contact-center build:srcIf the bug affected documented behavior:
- Update JSDoc if behavior changed
- Update the affected service's
AGENTS.mdif API behavior changed (find via rootAGENTS.mdService Routing Table) - Update the affected service's
ARCHITECTURE.mdif data flow changed
Bug fix is complete when:
- Root cause identified and confirmed with developer
- Fix implemented after developer approval
- Regression test added
- All tests pass
- Build succeeds