Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
opensearch_client
What it is
Part of the Search feature. Typed client for Macro's search index: per-entity-type upsert/delete and search for documents, emails, channel messages, chats, agent sessions, calendar events, call records, and projects.
Start here
src/lib.rs:OpensearchClientconstruction (URL + basic auth).src/upsert/<entity>.rs+src/delete/<entity>.rs: one pair per indexed entity type — the shape each indexer must produce.src/search/builder.rs+src/search/unified.rs: the cross-entity search request builder and the unified result model.examples/: runnable usage beyond the README.
Scope
- Owns: index document shapes, OpenSearch request/response mapping, and the unified search query across entity types.
- Not here: the generic query DSL used to build those requests →
opensearch_query_builder; deciding what gets (re)indexed and when →search_service,services/search_processing_service.
Boundaries
- Depends on:
opensearch_query_builder,models_opensearch,models_search_cursor. - Used by:
models_search,search_service,services/document_storage_service,services/search_processing_service.
Recipes
- Index a new entity type: add
src/<entity>.rs(doc shape) →src/upsert/<entity>.rs+src/delete/<entity>.rs→ asrc/search/<entity>.rsquery if it needs its own search endpoint → wire intoservices/search_processing_service. - Property DATE filters use the existing nested
properties.date_valueepoch-millisecond projection; emit only supplied inclusive/exclusive bounds and use a negated nested exists query for missing dates.
Checks
cargo test -p opensearch_client(SQLX_OFFLINEunset; needs a running OpenSearch — seecrates/opensearch_query_builder/docker-compose.yml).
Gotchas
- Map a failed
.send()withOpensearchClientError::request_failedand a failed body read withdeserialization_failed. Both take anOpensearchOperation: add a variant for a new request rather than passing a name.request_failedclassifies the cause as aTransportFailure(timeout, connect, connection closed, other) and keeps the full source chain indetails; reqwest'sDisplayalone drops the cause. A body cut off by a transport failure also becomesRequestFailed, notDeserializationFailed. - Workspace feature unification enables reqwest's HTTP/2, so every request
from one process multiplexes over one connection, and a recycled connection
fails them all at once. Wrap each public
OpensearchClientmethod's request inretry::resend_on_lost_connection, which resends twice on a connection closed or refused before a complete response, never on a timeout or an error status. Every request must stay safe to resend: write by explicit id or by query. - Put
instrument(err)on the public method, not the inner function it retries, so a recovered attempt does not record an error span. - Requests time out after five minutes (
REQUEST_TIMEOUT); delete-by-query across a large mailbox runs for minutes.
Related
- Docs:
README.md,examples/