-
Notifications
You must be signed in to change notification settings - Fork 135
chore: add debug scripts #3467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add debug scripts #3467
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR Review: Add Debug ScriptsSummaryThis PR adds debugging utilities to help visualize and analyze Rivet engine logs. The main additions are:
Code Quality & Best PracticesPositive Aspects
Issues & Suggestions1. Potential bugs in logfmt_to_gantt.tsLine 505, 508, 513: Potential runtime error when const wfId = task.metadata.workflow_id.substring(0, 8); // Could crash if undefinedThe code assumes const wfId = task.metadata.workflow_id?.substring(0, 8) || 'unknown';Line 225: No validation that const startTime = entries[0].ts;While there's a check at line 171, subsequent filtering (lines 177-208) could leave the array empty. The empty check at line 204 should be moved after the time filtering logic. 2. Logic issuesLines 188-191, 194-199: Inefficient array mutation entries.splice(0, entries.length, ...entries.filter(...));This creates a copy of the filtered array and splices it back. Better to use simple reassignment: const filtered = entries.filter(...);
entries.length = 0;
entries.push(...filtered);Or better yet, avoid mutation entirely and use a new variable. Lines 317-323: Operation matching logic is fragile for (const [k, task] of operationTasks.entries()) {
if (k.startsWith(entry.operation_name) && !task.end) {
task.end = entry.ts;
break;
}
}This matches by string prefix, which could incorrectly match operations with similar names (e.g., "operation" would match "operation_call"). Should use exact name matching with timestamp-based pairing. 3. Error handlingMissing error handling for:
Recommended pattern: try {
const content = readFileSync(inputFile, 'utf-8');
} catch (error) {
console.error(`Failed to read file ${inputFile}:`, error.message);
process.exit(1);
}4. Performance considerationsLine 317-323: Nested loop for operation matching - O(n²) complexity if many operations Line 188-199: Creating new arrays for filtering when could filter once and store result 5. Code style issuesHard-coded file paths: Lines 11, 145, 146 use
Magic numbers:
Inconsistent string concatenation: Mix of template literals and string concatenation Security ConcernsLow Risk Issues
Performance Considerations
Test CoverageMissing tests: No tests are included for these utilities. Recommended test cases:
Additional ObservationsPositive
Minor improvements
Overall AssessmentRecommendation: Approve with minor fixes These are useful debugging tools that will help with development and troubleshooting. The code is generally well-written but has some potential runtime errors that should be fixed before merging: Must fix:
Should fix:
Nice to have:
|
13210ec to
eb75b3a
Compare
Code ReviewThank you for adding these debug utilities! These tools will be valuable for debugging and analyzing Rivet engine execution. Positives
Code Quality Issues1. Potential null pointer exception (logfmt_to_gantt.ts:505, 508) 2. Inconsistent array mutation (logfmt_to_gantt.ts:188, 194) 3. Non-unique task keys (logfmt_to_gantt.ts:303) 4. Inefficient operation matching (logfmt_to_gantt.ts:317-323) Performance Considerations
Best Practices
Recommendations
Summary: Useful debugging tools with clean structure. Main concerns are null safety (critical) and large file handling. Recommend approval with suggested improvements for null safety. |
52ba96a to
9e07a2c
Compare
Code Review for PR #3467: Add Debug ScriptsThanks for adding these debug utilities! Overall, these are well-structured and useful tools. Here are my findings: ✅ Strengths
🐛 Issues Found1. Missing Error Handling (debug_mermaid.ts:11-12, logfmt_to_gantt.ts:157) 2. Potential -Infinity Bug (debug_mermaid.ts:38) 3. Performance: Inefficient Array Mutation (logfmt_to_gantt.ts:188-191) 4. Performance: Regex Recreation (logfmt_to_gantt.ts:51) 5. Type Safety (logfmt_to_gantt.ts:505, 508) 6. Edge Case (logfmt_to_gantt.ts:225, 391) 7. Code Duplication 💡 Suggestions
🔒 Security: ✅ ExcellentNo injection risks, no sensitive data handling issues. ✨ AssessmentQuality: ⭐⭐⭐⭐☆ | Maintainability: ⭐⭐⭐⭐☆ | Security: ⭐⭐⭐⭐⭐ Issues are mostly about robustness and performance, not critical bugs. Great work! |
9e07a2c to
52ba96a
Compare
Code Review for PR #3467: Add Debug ScriptsOverviewThis PR adds useful debugging utilities for analyzing Rivet engine logs. The code is well-structured and functional, but there are several areas for improvement. Strengths
|
Issues and Recommendations1. Type Safety IssuesIn logfmt_to_gantt.ts line 560 and debug_mermaid.ts line 97 the CommonJS pattern wont work properly in TypeScript ESM context: if (require.main === module) {
main();
}Recommendation: Since these are scripts with tsx shebangs simply call main directly at the bottom of the file. 2. Error Handling GapsFile I/O operations lack error handling throughout both scripts. For example in debug_mermaid.ts lines 11-12: const content = readFileSync(inputFile, 'utf-8');Recommendation: Wrap file operations in try-catch blocks to handle missing files or permission errors gracefully. |
3. Potential Bugsa) Confusing array mutation pattern in logfmt_to_gantt.ts lines 185-199: entries.splice(0, entries.length, ...entries.filter(entry => { }));This creates a temporary copy of the entire array which is memory-intensive. Better approach: const filtered = entries.filter(entry => { });
entries.length = 0;
entries.push(...filtered);b) Hardcoded placeholder date at logfmt_to_gantt.ts line 121: startTimeFilter = new Date('2000-01-01T' + timeStr + 'Z');Using a magic date for time-of-day comparisons is fragile. Extract to a named constant with clear explanation. |
4. Performance Considerationsa) Inefficient operation matching at logfmt_to_gantt.ts lines 324-332: for (const [k, task] of operationTasks.entries()) {
if (k.startsWith(entry.operation_name) && !task.end) {
task.end = entry.ts;
break;
}
}This O(n) linear search happens for every operation response. Consider tracking active operations separately with a Map. b) Memory usage for large files: Both scripts use readFileSync which loads entire files into memory. For large log files over 100MB consider streaming line-by-line using readline. |
5. Code Style and Conventionsa) Magic numbers without explanation at various lines: .substring(0, 50); // Line 95
.substring(0, 8); // Line 405
if (duration > 0.01) // Line 420Extract as named constants: const MAX_MERMAID_NAME_LENGTH = 50;
const WORKFLOW_ID_DISPLAY_LENGTH = 8;
const MIN_DURATION_TO_DISPLAY_MS = 0.01;b) Inconsistent quote style: Mix of single and double quotes throughout. Pick one style and stick to it. c) Missing documentation: Key functions like parseLogfmt sanitizeForMermaid and formatDuration would benefit from JSDoc comments. |
6. Security and TestingSecurity considerations:
Test coverage:
|
Prioritized RecommendationsHigh Priority - blocking:
Medium Priority - nice to have: Low Priority - polish: ConclusionThese are valuable debugging utilities that will help with workflow analysis. The core logic is solid and well-thought-out. The main issues are around error handling robustness and some TypeScript Node.js compatibility concerns. Recommendation: Request changes for high-priority items especially error handling and the require.main pattern then approve after those are addressed. |
52ba96a to
9e07a2c
Compare
Code ReviewOverviewThis PR adds helpful debugging scripts for analyzing Rivet Engine logs and visualizing execution timelines. The additions are well-structured and provide valuable tooling for development and debugging workflows. Positive Aspects ✅
Issues & Recommendations1. File Reading Error Handling
|
9e07a2c to
52ba96a
Compare
PR Review: Debug Scripts AdditionThanks for adding these debug utilities! Overall, this is a useful addition to the codebase for debugging and visualizing Rivet engine execution. Here's my detailed feedback: Code Quality & Best PracticesPositive Points:
Improvement Suggestions:
Potential Bugs
Performance Considerations
Security Concerns
Test CoverageMissing Tests:
Test Recommendations: // Example test cases to consider
describe('parseLogfmt', () => {
it('should parse valid logfmt line', () => { /* ... */ });
it('should handle quoted values with spaces', () => { /* ... */ });
it('should return null for invalid lines', () => { /* ... */ });
it('should strip ANSI color codes', () => { /* ... */ });
});Additional Suggestions
SummaryStrengths:
Priority Fixes:
Nice to Have:
This is solid debug tooling! With the suggested improvements, it'll be even more robust and maintainable. |
52ba96a to
9e07a2c
Compare
PR Review: Debug ScriptsThis PR adds useful debug scripts for analyzing Rivet Engine logs and Mermaid diagrams. Overall, the code is well-structured and functional for debug tooling. Here are my observations and recommendations: Strengths✅ Good utility value - These scripts solve real debugging needs (log visualization and Mermaid troubleshooting) Issues & Recommendations1. Potential Null Reference Bug 🐛Location: const wfId = task.metadata.workflow_id.substring(0, 8);Issue: When Fix: const wfId = task.metadata.workflow_id?.substring(0, 8) || 'unknown';2. Code DuplicationLocations: The duration calculation logic is duplicated. Consider extracting it to a helper function: function calculateTaskDuration(task: Task): number {
if (task.type === 'signal' && task.metadata.is_recv && task.metadata.send_ts) {
const sendTime = task.metadata.send_ts as Date;
const sendFrac = task.metadata.send_frac as number;
const durationMs = task.start.getTime() - sendTime.getTime();
const durationFracSec = task.startFracSec - sendFrac;
return durationMs + durationFracSec * 1000;
}
const durationMs = task.end\!.getTime() - task.start.getTime();
const durationFracSec = (task.endFracSec || 0) - task.startFracSec;
return durationMs + durationFracSec * 1000;
}3. Regex Parsing LimitationLocation: const regex = /(\w+)=(?:"([^"]*)"|(\S+))/g;Issue: This regex won't handle:
For debug scripts, this is probably acceptable, but worth documenting as a known limitation. 4. Type Safety ConcernLocation: [key: string]: any;Using 5. Package.json Metadata 📦Location: "description": "",
"main": "index.js",These fields are empty/incorrect. Consider:
6. Minor: Hardcoded PathsLocations: Multiple files use While fine for debug scripts, consider documenting this in the file comments or making paths configurable via environment variables for better cross-platform support (Windows doesn't use Security✅ No security concerns - These are development/debug tools with no external network access or sensitive data handling Testing
Performance✅ Efficient for debug tooling - Using Maps for lookups, single-pass parsing Suggested Minor Improvements
VerdictThis is good pragmatic debug tooling. The issues identified are minor and don't prevent merging, but fixing the null reference bug on lines 505/508 would prevent potential runtime errors. Recommendation: ✅ Approve with suggestion to fix the |
Merge activity
|

No description provided.