Skip to content

feat(core): Cache agent knowledge sandboxes with lazy file materialization#31866

Draft
bjorger wants to merge 23 commits into
agent-184-feature-kb-sandboxfrom
agent-240-feature-agents-kb-sandbox-integration
Draft

feat(core): Cache agent knowledge sandboxes with lazy file materialization#31866
bjorger wants to merge 23 commits into
agent-184-feature-kb-sandboxfrom
agent-240-feature-agents-kb-sandbox-integration

Conversation

@bjorger
Copy link
Copy Markdown
Contributor

@bjorger bjorger commented Jun 6, 2026

Summary

  • Reuse stable per-agent knowledge sandbox workspaces instead of rebuilding a full-corpus sandbox for each operation.
  • Materialize only missing or stale files on demand, using manifest entries with per-file binary-data hashes for freshness.
  • Route CSV operations through backend file streaming so they do not require sandbox materialization.
  • Keep sandbox invalidation focused on delete paths, and add focused coverage for cache lifecycle, materialization, stream writes, and UI/tool behavior.

How to test

To enable the Knowledgebase / Sandboxing add those variables to your .env

N8N_AGENTS_AI_SANDBOX_ENABLED=true
N8N_AGENTS_AI_SANDBOX_PROVIDER=daytona
N8N_AGENTS_AI_SANDBOX_IMAGE=daytonaio/sandbox:0.5.0
N8N_AGENTS_AI_SANDBOX_TIMEOUT=300000
N8N_AGENTS_AI_SANDBOX_NAME_PREFIX=
DAYTONA_API_URL=https://app.daytona.io/api
DAYTONA_API_KEY=dtn_XYZ

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/AGENT-240/feature-agents-kb-sandbox-integration

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)

Co-authored-by: Cursor <cursoragent@cursor.com>
@n8n-assistant n8n-assistant Bot added cla-signed core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jun 6, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

Performance Comparison

Comparing currentlatest master14-day baseline

loads S-tier workflow @tier:S

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
canvas-cold-load-S-ms 4333.00 ms 4333.00 ms 4175.60 ms (σ 388.55) +0.0% +3.8%

docker-stats

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
docker-image-size-runners 395.00 MB 395.00 MB 401.20 MB (σ 2.06) +0.0% -1.5% 🔴
docker-image-size-n8n 1423.36 MB 1536.00 MB 1450.22 MB (σ 66.31) -7.3% -1.9%

Idle baseline · instance-ai

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
instance-ai-heap-used-baseline 140.59 MB 140.59 MB 137.73 MB (σ 2.84) +0.0% +2.1% ⚠️
instance-ai-rss-baseline 271.50 MB 271.50 MB 330.60 MB (σ 58.91) +0.0% -17.9% ⚠️

Idle baseline · agents

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
agents-rss-baseline 399.19 MB 399.19 MB 350.32 MB (σ 46.78) +0.0% +14.0% ⚠️
agents-heap-used-baseline 141.75 MB 141.75 MB 137.39 MB (σ 3.53) +0.0% +3.2% ⚠️

Idle baseline · memory

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
memory-rss-baseline 262.11 MB 262.11 MB 324.25 MB (σ 46.38) +0.0% -19.2% ⚠️
memory-heap-used-baseline 137.20 MB 137.20 MB 131.67 MB (σ 3.52) +0.0% +4.2% ⚠️
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

bjorger and others added 4 commits June 6, 2026 15:24
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the knowledge-base module gate so file management and search_knowledge are always available while keeping node tools opt-in.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

Grind results — pre-merge flake detection (N=50)

File Passes
packages/frontend/editor-ui/src/app/stores/settings.store.test.ts 50/50 ✅
packages/frontend/editor-ui/src/features/agents/__tests__/AgentBuilder.readonly.test.ts 50/50 ✅
packages/frontend/editor-ui/src/features/agents/__tests__/AgentBuilderView.test.ts 50/50 ✅

Spawn-per-iteration mode. Catches post-teardown async flakes that vitest --repeat misses. See DEVP-198 for design notes.

bjorger and others added 12 commits June 6, 2026 17:05
Stage the CSV runner at the Daytona bake root and harden sandbox knowledge-base coverage around streaming, materialization, command routing, and gate removal.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use unique knowledge sandbox names and rely on the configured image instead of baking a per-run image, avoiding stale failed sandbox reuse and Daytona build failures.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Key cached workspaces by the full knowledge corpus instead of selected
files, materialize all files once while scoping search/read commands, and
best-effort invalidate caches on upload, delete, and agent removal. Align
Daytona sandbox naming with Instance AI via N8N_AGENTS_AI_SANDBOX_NAME_PREFIX.
Reuse per-agent knowledge sandboxes while materializing only the files required for each operation so scoped reads/searches avoid full-corpus churn.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep focused lazy-materialization coverage while removing redundant scenario tests from the agent knowledge sandbox suite.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove unused compatibility wrappers and manifest metadata now that sandbox freshness is resolved per file.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bjorger bjorger changed the title feat: add agent knowledge sandbox workspace primitives feat(core): Cache agent knowledge sandboxes with lazy file materialization Jun 7, 2026
bjorger and others added 5 commits June 7, 2026 19:12
Wrap subarray results in Buffer.from() so chunk writes pass ESLint's no-unsafe-argument rule.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Serialize workspace invalidation behind active sandbox operations, use configured sandbox command timeouts, and narrow materialization types to remove placeholder metadata.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant