Skip to content

Redundant S3 reads during write_note and edit_note add ~1s latency #708

@phernandez

Description

@phernandez

Problem

Both edit_note and write_note read the same file from S3 multiple times within a single tool call. The content was just written — it should be passed through in-memory instead of re-fetched.

edit_note: 3 S3 reads of the same file

From trace 019d49a39cffc28f742bca0fd6a8793f (10.4s edit_note):

Step S3 Op Duration Purpose
entity_service.edit.read_file get_object 0.40s Read current content to apply edit operation
search.index.read_content get_object 0.32s Re-read to build search index rows
api.knowledge.edit_entity.read_content get_object 0.28s Re-read for API response

Total wasted: ~0.6s on redundant S3 round-trips.

The write path also has this pattern:

  • entity_service.edit.write_file → S3 put (0.43s) — write the file
  • Then immediately reads it back twice

write_note: 4-5 S3 calls per write

Aggregated data (40 write_note calls today):

  • Average 4.1 S3 calls per write_note
  • Average 2.4 ASGI round-trips per write_note

Similar pattern: write file, then re-read for search indexing and response building.

resolve_permalink in create_entity: 1.1s avg

entity_service.create.resolve_permalink averages 1.1s (P95: 2.4s) across 49 calls. This likely involves sequential DB lookups that could be optimized or cached since the entity was just created.

Aggregated Evidence (last 12h, 60+ calls each)

Span Avg P50 P95 Calls
edit_entity.write_entity 3.25s 3.21s 4.53s 82
create_entity.write_entity 3.34s 3.13s 5.22s 52
entity_service.edit.write_file (S3 put) 0.47s 0.35s 1.29s 81
entity_service.edit.read_file (S3 get) 0.42s 0.33s 1.20s 82
entity_service.create.write_file (S3 put) 0.37s 0.33s 0.53s 49
entity_service.create.resolve_permalink 1.12s 0.82s 2.41s 49

Proposed Fix

  1. After writing a file to S3, keep the content in memory and pass it to the search indexer and response builder instead of re-reading from S3
  2. Investigate resolve_permalink — may be doing unnecessary DB lookups for freshly-created entities

This would save ~0.6-1s per edit/write operation.

Metadata

Metadata

Assignees

Labels

cloudBasic Memory CloudenhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions