AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-495
  5. plan
  6. context.json
context.json(2.9 KB)· Apr 14, 2026
{
  "meta": {
    "agent": "planner",
    "task_id": "495",
    "title": "Fix token usage recording in InvocationResultListener",
    "created_at": "2026-04-14T12:00:00Z"
  },
  "inputs": [
    {
      "name": "issue-495",
      "type": "link",
      "ref": "https://github.com/AgentSDE/agent-core/issues/495",
      "notes": "Token usage recording broken after fire-and-forget refactor"
    },
    {
      "name": "invocation-result.listener.ts",
      "type": "file",
      "ref": "src/invoke/invocation-result.listener.ts",
      "notes": "Processes phase results but missing tokenUsage.record() call"
    },
    {
      "name": "token-usage.service.ts",
      "type": "file",
      "ref": "src/token-usage/token-usage.service.ts",
      "notes": "Has record(taskId, phase, usage) method — no changes needed"
    },
    {
      "name": "invoke.module.ts",
      "type": "file",
      "ref": "src/invoke/invoke.module.ts",
      "notes": "Missing TokenUsageModule import"
    }
  ],
  "outputs": [
    {
      "name": "plan",
      "type": "plan",
      "format": "md",
      "content": "plan.md"
    }
  ],
  "files": [
    {
      "path": "src/invoke/invoke.module.ts",
      "action": "modify",
      "reason": "Import TokenUsageModule to make TokenUsageService available"
    },
    {
      "path": "src/invoke/invocation-result.listener.ts",
      "action": "modify",
      "reason": "Inject TokenUsageService and call record() on phase results with usage data"
    },
    {
      "path": "src/invoke/invocation-result.listener.spec.ts",
      "action": "create",
      "reason": "Unit test for token usage recording behavior"
    }
  ],
  "steps": [
    {
      "id": "S1",
      "summary": "Wire TokenUsageModule into InvokeModule",
      "acceptance": [
        "TokenUsageModule is listed in InvokeModule imports array",
        "Application compiles without circular dependency errors"
      ],
      "depends_on": []
    },
    {
      "id": "S2",
      "summary": "Inject TokenUsageService and call record() in InvocationResultListener",
      "acceptance": [
        "TokenUsageService is lazy-loaded via ModuleRef in onModuleInit()",
        "record(taskId, phase, usage) is called when result.usage is non-null",
        "record() is not called when usage is null or missing"
      ],
      "depends_on": [
        "S1"
      ]
    },
    {
      "id": "S3",
      "summary": "Add unit test for token usage recording in InvocationResultListener",
      "acceptance": [
        "Test asserts record() is called with correct taskId, phase, and usage payload",
        "Test asserts record() is not called when usage is null",
        "npm run test passes"
      ],
      "depends_on": [
        "S2"
      ]
    }
  ],
  "risks": [
    {
      "risk": "Circular dependency when adding TokenUsageModule to InvokeModule",
      "mitigation": "Uses existing ModuleRef.get({ strict: false }) lazy-loading pattern already proven in the listener"
    }
  ],
  "assumptions": [
    "TokenUsageService.record() API is stable and requires no changes",
    "The usage field on SignalResult/PhaseResultData contains UsageData when Claude reports token usage"
  ],
  "open_questions": []
}
Plan