Skip to content

[Feat]: Automations / Event-driven trigger type with document.entered_folder #3

Closed
CREDO23 wants to merge 1188 commits into
devfrom
feature-automations-v2
Closed

[Feat]: Automations / Event-driven trigger type with document.entered_folder #3
CREDO23 wants to merge 1188 commits into
devfrom
feature-automations-v2

Conversation

@CREDO23

@CREDO23 CREDO23 commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a generic in-process EventBus (app/event_bus/) with a typed EventCatalog and class-based pub/sub — decoupled from Celery (SRP)
  • Introduces document.entered_folder as the first built-in event type, published via SQLAlchemy after_commit hooks (ORM-level CDC, no pg_notify daemon)
  • Adds the event trigger type for automations, mirroring the schedule trigger pattern (source → selector → inputs → dispatch)
  • Fixes bulk_move_documents to use ORM objects so session hooks fire correctly
  • Fixes frontend Zod schema to accept event trigger type
  • Fixes JSON editor to coerce numeric strings back to numbers (filter value type safety)

Test plan

  • Move a document into a watched folder and confirm the automation fires
  • Confirm the summary note is created in the destination folder (using {{ inputs.folder_id }} in the query)
  • Confirm no automation fires when moving to an unwatched folder
  • Run unit tests: uv run pytest tests/unit/

CREDO23 and others added 30 commits May 20, 2026 09:42
LiteLLM normalizes every provider's cache fields onto
usage.prompt_tokens_details (cached_tokens + cache_creation_tokens).
The earlier fallback to usage.cache_read_input_tokens /
usage.cache_creation_input_tokens was wrong: Anthropic-shaped fields
only live there via a trailing setattr loop, and the canonical field
name on the wrapper is cache_creation_tokens (not _input_tokens).
embed_texts holds a threading.Lock and runs a sync embedding call inside
search_knowledge_base, an async coroutine on the KB priority middleware
critical path. Blocking the event loop here stalls every other coroutine
on the worker (SSE keepalives, concurrent chat requests, background
tasks). Wrap in asyncio.to_thread so the embed runs on the default
executor pool while the loop keeps serving.
_create_document and _update_document run on the chat critical path
when the filesystem subagent writes via the user's chat turn. Both
called embed_texts synchronously inside an async coroutine, blocking
the event loop for the duration of the embed.
generate_document_summary and create_document_chunks are async helpers
called from the chat path and from many connector indexers. Both wrapped
embed_text/embed_texts directly inside the coroutine, blocking the event
loop for the full duration of the embedding call.
_restore_in_place_document and _reinsert_document_from_revision are
async helpers invoked by the synchronous-feeling POST /api/threads/.../revert
route; both ran embed_texts inline, blocking the event loop while the
HTTP client waited.
…orkers

Connector kb_sync_services (gmail, onedrive, google_calendar, jira),
streaming indexers (discord, luma, teams) and the file-processor save
path all called embed_text inside async coroutines, blocking the
background worker's event loop for the duration of the embed. Wrap each
call site in asyncio.to_thread so concurrent indexing tasks stop
serialising on the embed.
…ile-hook

fix: use shared useIsMobile (768px) in SidebarSlideOutPanel (MODSetter#1359)
…tive 429 recovery

The preflight pattern probed the LLM with a 1-token ping before each
cold turn (when requested_llm_config_id==0, llm_config_id<0, and the
45s healthy TTL had expired) to detect 429s before fanning out into
planner/classifier/title-gen. To absorb its ~1-5s RTT cost we built the
agent speculatively in parallel; on 429 we discarded the build and
repinned.

Three problems with that design:

1. False security. Provider rate limits are token-bucket. A 1-token
   ping consumes ~5 tokens; the real request consumes 10-50K. The
   probe can return 200 while the real call still 429s.
2. Pure overhead in the common case. On warm-agent-cache turns the
   probe dominates wall time: ~2.5s of TTFT pure tax for ~99% of users
   who never see a 429.
3. The in-stream recovery loop (catch of _is_provider_rate_limited
   gated by not _first_event_logged) already does the right thing
   reactively: mark_runtime_cooldown -> resolve_or_get_pinned_llm_config_id
   with exclude_config_ids={previous} -> rebuild agent -> retry the
   stream. Preflight was never the only safety net; it was a redundant
   probe in front of one.

Changes:
- Delete _preflight_llm, _settle_speculative_agent_build, and the
  _PREFLIGHT_TIMEOUT_SEC / _PREFLIGHT_MAX_TOKENS constants.
- Drop the parallel agent_build_task / preflight_task plumbing in
  both stream_new_chat and stream_resume_chat; build the agent inline
  with await _build_main_agent_for_thread(...).
- Drop the unused is_recently_healthy / mark_healthy imports here
  (still exported from auto_model_pin_service since OpenRouter
  catalogue refresh and a few tests reference clear_healthy).
- Remove the obsolete preflight + settle-speculative tests from
  test_stream_new_chat_contract.py.

Net: -447 LOC. ~2.5s removed from TTFT on every cold preflight-eligible
turn. 429 recovery path is unchanged - same repin/rebuild/retry, just
not paid in advance on the healthy path.
…t LLM

Adds an optional planner LLM role wired through KnowledgePriorityMiddleware
so KB query rewriting, date extraction, and recency classification run on a
cheap model (e.g. gpt-4o-mini, Haiku, Azure nano) instead of the user's
chat LLM. Operators opt in by setting is_planner: true on exactly one
global config; without it, behavior is unchanged.
Splits the OpenAI-family gate into per-param predicates so AZURE and
AZURE_OPENAI configs now receive prompt_cache_key for backend routing
affinity (Microsoft auto-caches GPT-4o+ deployments at >=1024 tokens;
the key clusters same-prefix requests on the same GPU pool and raises
hit rate on turn 2+). prompt_cache_retention stays opted out for Azure
because litellm 1.83.14's Azure transformer would drop it silently;
revisit when Azure's supported params list is updated.
Release v0.0.24: UI revamp, multi-agent parallelization, citations & HITL improvements
Skip the ~1-3s MCP initialize + list_tools handshake on every cache miss
by reading tool definitions from the connector row we already load. Lazy
populate on first miss, self-heal on corrupt cache, zero schema migration.
MODSetter and others added 24 commits May 28, 2026 22:35
- Deleted the `search_surfsense_docs` tool and its associated files, streamlining the agent's toolset.
- Updated various components and prompts to remove references to the now-removed tool, ensuring consistency across the codebase.
- Adjusted documentation to direct users to the SurfSense documentation link for product-related queries instead.
feat: added basic UI for automations and removed surfsense docs in chat related code.
A standalone, domain-agnostic pub/sub seam: an EventBus that owns its
subscriber registry and streams Event values from producers to listeners
in process. Boundary-crossing (Celery/DB/workers) is left to subscribers,
keeping the bus single-responsibility. Includes the immutable Event value
object and full unit coverage.
@CREDO23 CREDO23 changed the title feat(automations): event-driven trigger type with document.entered_folder [Feat(automations)]: Event-driven trigger type with document.entered_folder May 29, 2026
@CREDO23 CREDO23 changed the title [Feat(automations)]: Event-driven trigger type with document.entered_folder [Feat]: Automations / Event-driven trigger type with document.entered_folder May 29, 2026
@CREDO23 CREDO23 force-pushed the feature-automations-v2 branch 2 times, most recently from b0f08f8 to 38b7385 Compare May 29, 2026 21:25
@CREDO23

CREDO23 commented May 29, 2026

Copy link
Copy Markdown
Owner Author

Closing — opened by mistake on the wrong repo.

@CREDO23 CREDO23 closed this May 29, 2026
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.

6 participants