Skip to content

Comments

perf: strip bloated fields from session ingest, reducing payload 50-77%#503

Open
marius-kilocode wants to merge 2 commits intomainfrom
perf/strip-bloated-ingest-fields
Open

perf: strip bloated fields from session ingest, reducing payload 50-77%#503
marius-kilocode wants to merge 2 commits intomainfrom
perf/strip-bloated-ingest-fields

Conversation

@marius-kilocode
Copy link
Contributor

Summary

Strip bloated fields from session ingest items before storage in the Durable Object. These fields are only needed for local UI rendering and are not used by the cloud (share page, metrics, export).

What's Stripped

Field Where What it contains Typical size
session.data.summary.diffs[].before / .after Session items Full file content snapshots (before/after edit) 50-400KB per session
part.data.state.metadata.filediff.before / .after Part items (edit tool) Duplicate full file snapshots 50-300KB per session
part.data.state.metadata.diagnostics Part items (edit/write/apply_patch tools) ALL project LSP diagnostics, not just the edited file 100-500KB per session

Measured Impact

From two profiled sessions in the kilocode repo:

Session Ingest payload before After stripping Reduction
45 msgs, 164 parts 1,516KB 355KB 77%
40 msgs, 152 parts 811KB 389KB 52%

The remaining fields (file path, additions/deletions counts, diff text) are preserved — only the raw file content and project-wide diagnostics are removed.

Changes

  • New cloudflare-session-ingest/src/util/strip-ingest-bloat.tsstripIngestBloat(item) function that creates a new item with bloated fields removed (does not mutate input)
  • cloudflare-session-ingest/src/dos/SessionIngestDO.ts — apply stripIngestBloat() to each item in the ingest() method before JSON.stringify and storage
  • New cloudflare-session-ingest/src/util/strip-ingest-bloat.test.ts — 9 test cases covering session stripping, part stripping, passthrough for other types, graceful handling of missing fields, and immutability

Testing

119 tests passed across 10 files (including 9 new)

Companion PR

Kilo-Org/kilocode#6241 — filters diagnostics to only the edited file(s) in the local CLI tools, reducing what gets stored in the local SQLite database.

Strip summary.diffs[].before/after, metadata.filediff.before/after,
and metadata.diagnostics from ingest items before storage. These fields
contain full file snapshots and project-wide LSP diagnostics that are
only needed for local UI rendering, not cloud storage/export.

Measured reduction: 50-77% of ingest payload size per session.
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 24, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Clean, well-structured PR that strips bloated fields (summary.diffs[].before/.after, metadata.filediff.before/.after, metadata.diagnostics) from ingest items before size measurement and storage. The stripping is applied early in splitIngestBatchForDO so items that are only oversized due to bloat are not dropped.

Key observations:

  • Immutability is correctly maintained — all functions return new objects via spread, never mutating inputs (verified by test).
  • Null/undefined guards are thorough at each nesting level.
  • Test coverage is comprehensive: all three strip paths, pass-through for other types, graceful handling of missing fields, and an explicit no-mutation test.
  • The generic <T extends StrippableItem>(item: T): T signature preserves the discriminated union type through the call in ingest-batching.ts.
Files Reviewed (3 files)
  • cloudflare-session-ingest/src/util/ingest-batching.ts — Integration of stripIngestBloat call
  • cloudflare-session-ingest/src/util/strip-ingest-bloat.ts — New stripping logic
  • cloudflare-session-ingest/src/util/strip-ingest-bloat.test.ts — Comprehensive tests

Strip bloated fields in splitIngestBatchForDO before measuring item
size, so items that exceed the ~2MiB limit only because of file
snapshots or diagnostics are no longer dropped.

Cloudflare observability showed 226 items dropped as oversized and
130 DO OOM crashes in a 45-minute window. Moving the strip upstream
addresses both: items are measured post-strip, and the DO stores
smaller payloads reducing alarm memory pressure.
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