{"record":{"id":"45580dc62851f3c7","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"context-offload-build-l3-report-failed-report","errorCode":null,"errorMessage":"[context-offload] build L3 report failed: ${reportErr}","messagePattern":"\\[context-offload\\] build L3 report failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"MemoryCore/src/offload/hooks/after-tool-call.ts","lineNumber":339,"sourceCode":"          event,\n          contextWindow: _contextWindow,\n          mildThreshold: _mildThreshold,\n          aggressiveThreshold: _aggressiveThreshold,\n          tokensBefore: _tokensBefore,\n          tokensAfter: _tokensAfter,\n          messagesBefore: _msgsBefore,\n          messagesAfter: _msgsAfter,\n          durationMs: _compDuration,\n          aboveMild: _tokensBefore >= _mildThreshold,\n          aboveAggressive: _tokensBefore >= _aggressiveThreshold,\n          mildReplacedCount: _compResult.mildReplacedCount ?? 0,\n          aggressiveDeletedCount: _compResult.aggressiveDeletedCount ?? 0,\n          emergencyTriggered: _compResult.emergencyTriggered ?? false,\n          emergencyDeletedCount: _compResult.emergencyDeletedCount ?? 0,\n        });\n        reportL3Trigger(backendClient ?? null, report, logger);\n      } catch (reportErr) {\n        logger.warn(`[context-offload] build L3 report failed: ${reportErr}`);\n      }\n    }\n\n    // Trace full messages snapshot at end of after_tool_call\n    if (event.messages && Array.isArray(event.messages)) {\n      traceMessagesSnapshot({\n        sessionKey: stateManager.getLastSessionKey(),\n        stage: \"after_tool_call.end\",\n        messages: event.messages,\n        label: `tool=${event.toolName}`,\n        extra: {\n          toolName: event.toolName,\n          toolCallId,\n          pendingCount: stateManager.getPendingCount(),\n          activeMmdFile: stateManager.getActiveMmdFile() ?? null,\n          l15Settled: stateManager.l15Settled,\n        },\n        logger,","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/offload/hooks/after-tool-call.ts#L321-L357","documentation":"Inside the after_tool_call hook, after compaction completes, the plugin builds an L3 trigger report (token accounting) and hands it to reportL3Trigger for upload to the backend /store. The report construction/upload kick-off is wrapped in try/catch so a reporting failure never disrupts the agent loop; it is logged as this warning. The message interpolates the underlying error, e.g. a TypeError from a missing stateManager field or an exception thrown by buildL3TriggerReport.","triggerScenarios":"buildL3TriggerReport(...) throws while assembling the report — typically when _compResult or stateManager fields are undefined/null in a shape the code does not expect (e.g. a compaction result missing mildReplacedCount internals accessed beyond the ?? defaults), or when reportL3Trigger throws synchronously on a malformed backendClient; the backendClient ?? null guard covers null but not a client whose methods throw.","commonSituations":"Partial compaction results after a server error returned a degraded payload; plugin version mismatch where CompactionResult gained/lost fields; custom backendClient implementations that throw synchronously; corrupt in-memory stateManager state after a hot plugin reload.","solutions":["Read the interpolated reportErr in the log — it names the exact property or call that failed.","Verify the compaction result shape matches what buildL3TriggerReport expects (upgrade/downgrade plugin and server to matching versions).","Confirm stateManager was initialized for this session (no undefined snapshot fields).","If a custom backendClient is passed, ensure reportL3Trigger-compatible methods do not throw synchronously.","This only affects telemetry/token accounting, not compaction itself — the conversation continues normally; fix at leisure."],"exampleFix":"// before: report build crashes on missing compaction detail\nmildReplacedCount: _compResult.mildReplacedCount ?? 0,\naggressiveDeletedCount: _compResult.aggressiveDeletedCount ?? 0,\n// after: harden the whole compaction-derived report input against null\nconst comp = _compResult ?? {};\n// ...\nmildReplacedCount: comp.mildReplacedCount ?? 0,\naggressiveDeletedCount: comp.aggressiveDeletedCount ?? 0,\nemergencyTriggered: comp.emergencyTriggered ?? false,","handlingStrategy":"type-guard","validationCode":"const comp = _compResult ?? {};\nconst safeReportInput = {\n  mildReplacedCount: typeof comp.mildReplacedCount === \"number\" ? comp.mildReplacedCount : 0,\n  aggressiveDeletedCount: typeof comp.aggressiveDeletedCount === \"number\" ? comp.aggressiveDeletedCount : 0,\n  emergencyTriggered: comp.emergencyTriggered === true,\n  emergencyDeletedCount: typeof comp.emergencyDeletedCount === \"number\" ? comp.emergencyDeletedCount : 0,\n};","typeGuard":"function isReportableCompaction(c: unknown): c is CompactionResult {\n  return c !== null && typeof c === \"object\" &&\n    (\"mildReplacedCount\" in c || \"aggressiveDeletedCount\" in c);\n}","tryCatchPattern":"try {\n  const report = buildL3TriggerReport({ /* normalized inputs */ });\n  reportL3Trigger(backendClient ?? null, report, logger);\n} catch (reportErr) {\n  logger.warn(`[context-offload] build L3 report failed: ${reportErr}`);\n  // telemetry only — do not rethrow\n}","preventionTips":["Normalize the compaction result (default every optional field) before building the report.","Keep plugin and server versions aligned so CompactionResult shapes match.","Wrap all telemetry-building code in its own try/catch, separate from compaction logic.","If the log recurs, capture reportErr.stack to pinpoint the undefined field quickly."],"tags":["telemetry","reporting","hook","null-safety"],"backgroundTag":"telemetry-report-build-failed","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}