feat(diagnostics): add structured diagnostic logger for agent executions#239
Merged
snipcodeit merged 2 commits intomainfrom Mar 6, 2026
Merged
Conversation
Create lib/agent-diagnostics.cjs that captures per-agent telemetry including agent type, prompt hash, timestamps, turn count, exit reason, output size, and failure classification. Writes entries to .mgw/diagnostics/ as JSON files. Includes prune function for 30-day retention and read/query capabilities. All operations are non-blocking to ensure pipeline stability. Closes #230 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Plan, summary, and verification artifacts for issue #230. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Owner
Author
Testing ProceduresQuick Verificationnode -e "const d = require('./lib/agent-diagnostics.cjs'); console.log(Object.keys(d))"Expected output: Functional Testconst diag = require('./lib/agent-diagnostics.cjs');
// 1. Create and use a logger
const logger = diag.createDiagnosticLogger({
agentType: 'gsd-executor',
issueNumber: 999,
promptHash: diag.shortHash('test prompt'),
});
logger.start();
// simulate work...
logger.finish({ exitReason: 'success', turnCount: 10, outputSize: 2048 });
// 2. Read back
const entries = diag.readDiagnostics({ issueNumber: 999 });
console.log(entries); // Should show 1 entry
// 3. Prune (nothing to remove)
console.log(diag.pruneDiagnostics()); // { removed: 0, errors: 0, total: N }
// 4. Error handling
const errorLogger = diag.createDiagnosticLogger({ agentType: 'gsd-verifier', issueNumber: 998 });
errorLogger.start();
errorLogger.finish({ exitReason: 'error', error: new Error('agent timed out') });
const errEntries = diag.readDiagnostics({ issueNumber: 998 });
console.log(errEntries[0].failure_classification); // Should be non-nullNon-Blocking Verification// These should all return safe defaults, never throw
diag.writeDiagnosticEntry(null); // false
diag.readDiagnostics({ repoRoot: '/x' }); // []
diag.pruneDiagnostics({ repoRoot: '/x' }); // { removed: 0, errors: 0, total: 0 } |
This was referenced Mar 6, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/agent-diagnostics.cjs— a non-blocking diagnostic logger for GSD agent executions.mgw/diagnostics/<issue-number>-<timestamp>.jsonwith 30-day auto-pruningagent-errors.cjs->retry.cjs-> minimal classification for failure typingCloses #230
Milestone Context
Changes
lib/(core module)lib/agent-diagnostics.cjs(451 lines) — New module with 7 exports:getDiagnosticsDir()— Directory managementcreateDiagnosticLogger()— Factory pattern for agent invocation trackingwriteDiagnosticEntry()— Low-level JSON entry writerpruneDiagnostics()— 30-day retention enforcementreadDiagnostics()— Query with filters (issueNumber, agentType, since, limit)shortHash()— SHA-256 utility for prompt hashingDEFAULT_MAX_AGE_DAYS— Configurable retention constant.planning/(GSD artifacts)Test Plan
node -e "require('./lib/agent-diagnostics.cjs')")