Skip to content

feat(agents): Logging support for agent sessions#28491

Open
mike12345567 wants to merge 22 commits inton8n-agentsfrom
n8n-agents-logging
Open

feat(agents): Logging support for agent sessions#28491
mike12345567 wants to merge 22 commits inton8n-agentsfrom
n8n-agents-logging

Conversation

@mike12345567
Copy link
Copy Markdown
Contributor

Summary

  • Add agent execution logging: each agent message cycle is recorded as an n8n execution with metadata (tokens, cost, model, tool calls, working memory, HITL status)
  • New execution_threads table + migration to group executions by conversation thread, tracking session-level aggregates (total tokens, cost, duration)
  • ExecutionRecorder extracts structured data from agent stream chunks; AgentExecutionService persists execution records and manages thread lifecycle
  • Frontend: sessions list view, session inspection (token usage, tool call I/O, working memory snapshots, HITL suspension indicators)
  • RichInteractionCard component renders rich_interaction tool calls inline in session detail
  • Title generation improvements: better thread titles with emoji support
  • Agents also appear in the global executions list alongside workflow executions

Screenshots

Recent conversations (sessions):
image

Table listing sessions in the executions section (see switcher on the right):
image

Detailed timeline of the session (tool calls, HITL, etc):
image

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

@mike12345567 mike12345567 requested a review from a team as a code owner April 14, 2026 15:58
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Bundle Report

Changes will increase total bundle size by 82.75kB (0.18%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
editor-ui-esm 45.94MB 82.75kB (0.18%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: editor-ui-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/typescript.worker-*.js 30 bytes 10.88MB 0.0%
assets/worker-*.js 3.14MB 3.16MB 17560.22% ⚠️
assets/worker-*.js -3.14MB 17.9kB -99.43%
assets/constants-*.js 30 bytes 3.14MB 0.0%
assets/constants-*.js 224 bytes 542 bytes 70.44% ⚠️
assets/src-*.js 2.23kB 2.43MB 0.09%
assets/dist-*.js 114 bytes 5.46kB 2.13%
assets/core-*.js 2.94kB 628.12kB 0.47%
assets/router-*.js 810 bytes 120.7kB 0.68%
assets/AgentBuilderView-*.js 2.6kB 78.82kB 3.41%
assets/ExecutionsView-*.js 9.27kB 45.28kB 25.75% ⚠️
assets/AgentSessionTimelineView-*.js (New) 27.29kB 27.29kB 100.0% 🚀
assets/AgentBuilderView-*.css 921 bytes 25.36kB 3.77%
assets/AgentSessionTimelineView-*.css (New) 18.12kB 18.12kB 100.0% 🚀
assets/ExecutionsView-*.css 2.81kB 11.55kB 32.21% ⚠️
assets/AgentSessionsListView-*.js (New) 8.0kB 8.0kB 100.0% 🚀
assets/agentSessions.store-*.js (New) 3.39kB 3.39kB 100.0% 🚀
assets/AgentSessionsListView-*.css (New) 2.86kB 2.86kB 100.0% 🚀
assets/AgentView-*.js (New) 940 bytes 940 bytes 100.0% 🚀
assets/AgentView-*.css (New) 123 bytes 123 bytes 100.0% 🚀

Files in assets/AgentBuilderView-*.js:

  • ./src/features/agents/components/AgentHomeContent.vue → Total Size: 351 bytes

Files in assets/AgentSessionTimelineView-*.js:

  • ./src/features/agents/components/RichInteractionCard.vue → Total Size: 363 bytes

Files in assets/agentSessions.store-*.js:

  • ./src/features/agents/composables/useAgentThreadsApi.ts → Total Size: 815 bytes

  • ./src/features/agents/agentSessions.store.ts → Total Size: 2.33kB

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 14, 2026

Merging this PR will improve performance by 17.8%

⚡ 1 improved benchmark
✅ 31 untouched benchmarks
⏩ 20 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
vm: Simple Property - small data 2.2 ms 1.9 ms +17.8%

Comparing n8n-agents-logging (81043f8) with n8n-agents (817669f)

Open in CodSpeed

Footnotes

  1. 20 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@mike12345567 mike12345567 changed the title N8n agents logging feat(agents): Logging support for agent sessions Apr 14, 2026
@mike12345567 mike12345567 removed the request for review from a team April 14, 2026 16:16
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

Performance Comparison

Comparing currentlatest master14-day baseline

Idle baseline with Instance AI module loaded

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
instance-ai-heap-used-baseline 186.49 MB 186.34 MB (σ 0.24) +0.1%
instance-ai-rss-baseline 343.98 MB 372.63 MB (σ 22.95) -7.7% ⚠️

Memory consumption baseline with starter plan resources

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
memory-heap-used-baseline 114.83 MB 113.86 MB (σ 0.84) +0.9% ⚠️
memory-rss-baseline 226.00 MB 284.98 MB (σ 42.51) -20.7% ⚠️

docker-stats

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
docker-image-size-n8n 1280.00 MB 1269.76 MB (σ 0.00) +0.8%
docker-image-size-runners 393.00 MB 391.63 MB (σ 11.06) +0.3%
How to read this table
  • Current: This PR's value (or latest master if PR perf tests haven't run)
  • Latest Master: Most recent nightly master measurement
  • Baseline: Rolling 14-day average from master
  • vs Master: PR impact (current vs latest master)
  • vs Baseline: Drift from baseline (current vs rolling avg)
  • Status: ✅ within 1σ | ⚠️ 1-2σ | 🔴 >2σ regression

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12 issues found across 38 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/cli/src/modules/agents/agent-execution.service.ts">

<violation number="1" location="packages/cli/src/modules/agents/agent-execution.service.ts:105">
P2: Regex doesn't strip the angle brackets from Slack-style mentions (`<@U0ANB4K6611>`). The pattern matches `@U0ANB4K6611` inside the brackets but leaves `<` and `>` in the output, producing `<@AgentName>` instead of `@AgentName`. Extend the pattern to match the full `<@…>` wrapper as well.</violation>

<violation number="2" location="packages/cli/src/modules/agents/agent-execution.service.ts:239">
P0: Custom agent: **Security Review**

Authorization bypass: executions are deleted before verifying thread ownership. An authenticated user who knows a `threadId` from another project can destroy its executions by calling `DELETE /projects/{own-project}/agents/v2/threads/{victim-thread-id}`. The ownership check via `deleteByIdAndProjectId` only runs after the unconditional `executionRepository.delete({ threadId })`. Verify ownership first, then delete executions.</violation>
</file>

<file name="packages/frontend/editor-ui/src/features/agents/components/AgentHomeContent.vue">

<violation number="1" location="packages/frontend/editor-ui/src/features/agents/components/AgentHomeContent.vue:32">
P2: New user-facing strings are hard-coded in English instead of going through i18n, so this UI will not localize correctly.</violation>

<violation number="2" location="packages/frontend/editor-ui/src/features/agents/components/AgentHomeContent.vue:174">
P2: The session row is click-only on a `<div>`, which makes session selection inaccessible to keyboard users.</violation>
</file>

<file name="packages/frontend/editor-ui/src/features/execution/executions/views/ExecutionsView.vue">

<violation number="1" location="packages/frontend/editor-ui/src/features/execution/executions/views/ExecutionsView.vue:53">
P2: Using raw `route.query.view` to skip initialization breaks workflow execution loading when `view=agents` is present but Agents is disabled.</violation>

<violation number="2" location="packages/frontend/editor-ui/src/features/execution/executions/views/ExecutionsView.vue:74">
P2: Visibility-change auto-refresh restart uses query-only mode detection, so workflow auto-refresh can remain stopped when `view=agents` is set but Agents is unavailable.</violation>
</file>

<file name="packages/frontend/editor-ui/src/features/agents/components/RichInteractionCard.vue">

<violation number="1" location="packages/frontend/editor-ui/src/features/agents/components/RichInteractionCard.vue:187">
P3: Replace hard-coded dimensions with design system sizing tokens.</violation>
</file>

<file name="packages/cli/src/modules/agents/agents.service.ts">

<violation number="1" location="packages/cli/src/modules/agents/agents.service.ts:346">
P1: Do not skip recording when `recorder.suspended` is true. Set `hitlStatus` to `'suspended'` if the agent suspends again, so intermediate tool calls are not lost.</violation>
</file>

<file name="packages/frontend/editor-ui/src/features/agents/views/AgentSessionsListView.vue">

<violation number="1" location="packages/frontend/editor-ui/src/features/agents/views/AgentSessionsListView.vue:127">
P2: The session status cell is hardcoded to “success”, so non-success threads will be displayed with incorrect status.</violation>
</file>

<file name="packages/cli/src/modules/agents/agents.controller.ts">

<violation number="1" location="packages/cli/src/modules/agents/agents.controller.ts:147">
P2: `limit` parsing allows negative values; enforce a minimum bound before passing to thread queries.</violation>
</file>

<file name="packages/frontend/editor-ui/src/features/agents/agentSessions.store.ts">

<violation number="1" location="packages/frontend/editor-ui/src/features/agents/agentSessions.store.ts:83">
P2: Handle refresh errors inside the auto-refresh timer callback; otherwise a single failed fetch stops all subsequent auto-refresh cycles.</violation>
</file>

<file name="packages/cli/src/modules/agents/execution-recorder.ts">

<violation number="1" location="packages/cli/src/modules/agents/execution-recorder.ts:184">
P2: New tool-call events are marked successful before completion, so suspended or missing-result calls can be incorrectly reported as success.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant UI as Frontend (Sessions/Executions)
    participant API as Agents Controller
    participant AS as Agent Service
    participant AES as Agent Execution Service
    participant ER as Execution Recorder
    participant AR as Agent Runtime
    participant DB as Database (Postgres/SQLite)

    Note over UI, DB: Agent Message Execution & Logging Flow

    UI->>API: POST /agents/:id/chat (message)
    API->>AS: executeForChat()
    AS->>AR: stream()
    
    loop Stream Processing
        AR->>AS: StreamChunk (text, tool-call, etc)
        AS->>UI: Relay Chunk
        AS->>ER: NEW: record(chunk)
        opt NEW: Working Memory Update
            AR->>AR: WorkingMemoryStreamFilter
            AR->>ER: chunk (type: 'working-memory-update')
        end
    end

    opt CHANGED: Title Generation (First message)
        AR->>AR: generateThreadTitle()
        Note right of AR: NEW: Request JSON with title + emoji
        AR->>DB: Save thread title & metadata
    end

    AR-->>AS: Stream Finished
    
    AS->>ER: NEW: getMessageRecord()
    ER-->>AS: { tokens, cost, toolCalls, timeline, etc }

    AS->>AES: NEW: recordMessage()
    AES->>DB: CHANGED: findOrCreate ExecutionThread
    Note right of DB: Tracks session aggregates (cost, tokens)

    alt Cycle Suspended (HITL)
        AES->>DB: NEW: Insert Execution (status: 'success', hitlStatus: 'suspended')
    else Cycle Completed
        AES->>DB: NEW: Insert Execution (mode: 'agent', threadId: xxx)
        AES->>DB: NEW: Insert Metadata (tokens, model, tool outputs, timeline)
        AES->>DB: NEW: Update Thread (increment total tokens/cost)
        
        opt Was Resumed
            AES->>DB: NEW: backfillSuspendedExecutions()
            Note right of DB: Propagates model/usage to previous suspended records
        end
    end

    Note over UI, DB: Session Retrieval Flow

    UI->>API: GET /threads?agentId=...
    API->>AES: getThreads()
    AES->>DB: Query execution_threads
    DB-->>AES: Thread list + aggregates
    AES->>DB: Query execution_metadata (latest userMessage)
    AES-->>API: Paginated threads
    API-->>UI: 200 OK (Displays in Global Executions or Agent Sessions)

    UI->>API: GET /threads/:threadId
    API->>AES: getThreadDetail()
    AES->>DB: Query execution_entity + metadata where threadId
    DB-->>AES: Chronological execution list
    AES-->>API: Thread + Timeline data
    API-->>UI: 200 OK (Renders RichInteractionCards & Timeline)
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

mike12345567 and others added 2 commits April 14, 2026 18:17
…olumn

- Watch route query to initialize executions store when switching from
  agents view back to workflows (was skipped on mount)
- Always record resumed HITL executions even if they suspend again,
  so chained approval/form flows appear in the session timeline
- Remove hardcoded success status column from session list tables
  since per-thread status is not tracked

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Verify thread ownership before deleting executions (prevents
  cross-project data destruction via known threadId)
- Fix Slack mention regex to handle <@U0ANB4K6611> angle bracket format
- Clamp thread list limit to 1-100 (prevent negative values)
- Default tool-call timeline events to success=false until result
  confirms completion
- Catch errors in auto-refresh timer so cycle continues on failure
- Gate agents view checks on module availability, not just query param
- Use design system tokens for RichInteractionCard dimensions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant