fix(audit): fix PluralisticDeliberationOrchestrator cultural sensitivity audit logging
Problem: - Cultural sensitivity checks were executing successfully but failing to create audit logs - Error: "memoryProxy.getCollection is not a function" - 12 blog posts analyzed, 0 audit logs created Root Cause: 1. _auditCulturalSensitivity() was calling getMemoryProxy() and trying to use non-existent getCollection() method 2. Method was using fire-and-forget pattern (.catch()) instead of awaiting 3. Used 'context' field instead of 'metadata' field for custom data Fix: 1. Use this.memoryProxy.auditDecision() instead of direct collection access 2. Await the audit call to ensure it completes before method returns 3. Store detailed assessment data in 'metadata' field (AuditLog schema) 4. Add memoryProxyInitialized check for safety 5. Map concerns to violations array with inst_081 ruleId Result: - ✅ 12 audit logs created (one per blog post analyzed) - ✅ Full metadata stored (risk_level, concerns, suggestions, audience) - ✅ Violations properly tracked for inst_081 (Cultural Sensitivity rule) - ✅ No more "Failed to create audit log" errors Tested: - node scripts/cultural-sensitivity-retrospective.js --report-only - All 12 posts analyzed successfully with audit logs - 1 post flagged for western_ethics_only pattern with full violation details Location: src/services/PluralisticDeliberationOrchestrator.service.js:852-893 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
5966684da9
commit
1e37019c28
1 changed files with 30 additions and 18 deletions
|
|
@ -755,12 +755,8 @@ class PluralisticDeliberationOrchestrator {
|
|||
assessment.recommended_action = 'SUGGEST_ADAPTATION';
|
||||
}
|
||||
|
||||
// Audit log
|
||||
this._auditCulturalSensitivity(assessment).catch(error => {
|
||||
logger.error('[PluralisticDeliberationOrchestrator] Failed to audit cultural sensitivity check', {
|
||||
error: error.message
|
||||
});
|
||||
});
|
||||
// Audit log (await to ensure it completes before method returns)
|
||||
await this._auditCulturalSensitivity(assessment);
|
||||
|
||||
logger.info('[PluralisticDeliberationOrchestrator] Cultural sensitivity assessment complete', {
|
||||
risk_level: assessment.risk_level,
|
||||
|
|
@ -854,29 +850,45 @@ class PluralisticDeliberationOrchestrator {
|
|||
* @private
|
||||
*/
|
||||
async _auditCulturalSensitivity(assessment) {
|
||||
try {
|
||||
const memoryProxy = await getMemoryProxy();
|
||||
const collection = await memoryProxy.getCollection('auditLogs');
|
||||
if (!this.memoryProxyInitialized) {
|
||||
logger.debug('[PluralisticDeliberationOrchestrator] Cultural sensitivity audit skipped - MemoryProxy not initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
await collection.insertOne({
|
||||
timestamp: new Date(),
|
||||
try {
|
||||
await this.memoryProxy.auditDecision({
|
||||
sessionId: assessment.context.sessionId || 'cultural-sensitivity-check',
|
||||
action: 'cultural_sensitivity_assessment',
|
||||
service: 'PluralisticDeliberationOrchestrator',
|
||||
action: 'cultural_sensitivity_check',
|
||||
decision: assessment.recommended_action,
|
||||
context: {
|
||||
rulesChecked: ['inst_081'], // Phase 3 Cultural Sensitivity rule
|
||||
violations: assessment.culturally_sensitive ? [] : assessment.concerns.map(c => ({
|
||||
ruleId: 'inst_081',
|
||||
severity: assessment.risk_level,
|
||||
description: c.detail,
|
||||
context: c.audience_context
|
||||
})),
|
||||
metadata: {
|
||||
content_type: assessment.context.content_type,
|
||||
audience: assessment.context.audience,
|
||||
risk_level: assessment.risk_level,
|
||||
concerns_count: assessment.concerns.length,
|
||||
culturally_sensitive: assessment.culturally_sensitive
|
||||
},
|
||||
metadata: {
|
||||
culturally_sensitive: assessment.culturally_sensitive,
|
||||
concerns: assessment.concerns,
|
||||
suggestions: assessment.suggestions
|
||||
suggestions: assessment.suggestions,
|
||||
recommended_action: assessment.recommended_action
|
||||
}
|
||||
});
|
||||
|
||||
logger.debug('[PluralisticDeliberationOrchestrator] Cultural sensitivity audit logged', {
|
||||
risk_level: assessment.risk_level,
|
||||
decision: assessment.recommended_action
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('[PluralisticDeliberationOrchestrator] Failed to create audit log', { error: error.message });
|
||||
logger.error('[PluralisticDeliberationOrchestrator] Failed to audit cultural sensitivity', {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue