feat: session-based conversation reuse for event-triggered automations#118
Draft
malhotra5 wants to merge 1 commit into
Draft
feat: session-based conversation reuse for event-triggered automations#118malhotra5 wants to merge 1 commit into
malhotra5 wants to merge 1 commit into
Conversation
#105) Adds session routing infrastructure so related webhook events (e.g. all comments on the same GitHub PR) can be routed to the same running sandbox rather than spawning a fresh sandbox per event. ## Changes ### schemas.py - New model with (JMESPath), , , and (queue|restart|drop) - — opt-in per automation - — count of events routed to existing sessions ### models.py - New enum (ACTIVE, EXPIRED, DEAD) - New table — tracks the sandbox owning a session - New table — queues events for active/dead sessions ### migrations/versions/005_session_tables.py - Creates and tables with appropriate indexes (compound lookup on automation_id + session_key + status) ### utils/session.py (new) - — JMESPath extraction with safe fallback - — DB lookup - — creates ACTIVE session record for a run - — stores event and bumps session.last_event_at - — optimistic-locking transition to DEAD ### event_router.py - Session routing: when a matched automation has session config, extract the session key and look up an active session. If found, queue as PendingSessionEvent; if not, create a new run as before. ### dispatcher.py - After successful dispatch, calls which creates an record when the trigger has session config. ### watchdog.py - After marking a stale run terminal, calls so the event router stops routing to the dead sandbox. ### tests/test_session.py (new) - 30 tests covering validation, with session, edge cases, and . ## What's NOT yet implemented - Agent-server event queue endpoints () — these live in the SDK repo (OpenHands/software-agent-sdk) and are required for the SDK to poll pending events from the sandbox. - Preset script session mode loop (SDK-side polling of pending events). - auto-requeue logic (watchdog extension). Co-authored-by: openhands <openhands@all-hands.dev>
|
🚀 Deploy Preview PR Created/Updated A deploy preview has been created/updated for this PR. Deploy PR: https://github.com/OpenHands/deploy/pull/4309 Once the deploy PR's CI passes, the automation service will be deployed to the feature environment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #105
Adds the foundational infrastructure for session-based conversation reuse: related webhook events (e.g. all comments on the same GitHub PR, messages in the same Slack thread) can now be routed to the same running sandbox rather than spawning a fresh sandbox per event.
Changes
schemas.pySessionConfigmodel withkey_expr(JMESPath expression to extract session key from payload),idle_timeout_seconds,session_timeout_seconds, andon_sandbox_death(queue|restart|drop)EventTrigger.session: SessionConfig | None— opt-in session routing per automationEventResponse.events_queued— count of events routed to existing sessions (backward compatible, defaults to0)models.pySessionStatusenum (ACTIVE,EXPIRED,DEAD)AutomationSessiontable — tracks which sandbox owns each sessionPendingSessionEventtable — queues events for delivery to the active sandboxmigrations/versions/005_session_tables.pyautomation_sessionsandpending_session_eventstables with compound indexes for the primary lookup patternutils/session.py(new)extract_session_key(key_expr, payload)— JMESPath key extraction with safe fallback toNoneget_active_session(automation_id, session_key, session)— DB lookup with expiry checkcreate_session(...)— createsACTIVEsession recordqueue_pending_event(...)— stores event and bumpssession.last_event_atmark_session_dead(run, session)— optimistic-locking transition toDEADevent_router.pySession routing in
receive_event:PendingSessionEvent(no new run created)dispatcher.py_maybe_create_session()creates anAutomationSessionrecord when the trigger has session configwatchdog.pymark_session_dead()so the event router stops routing events to the dead sandboxtests/test_session.py(new)30 tests covering
SessionConfigvalidation,EventTriggerwith session,extract_session_keyedge cases, andEventResponse.events_queued.Usage Example
What's NOT yet implemented (follow-up work)
POST/GET/DELETE /api/workspace/events) inOpenHands/software-agent-sdk— required for the SDK to poll pending events from inside the sandboxon_sandbox_death = "restart"auto-requeue — watchdog extension to immediately create a new run with queued eventsThis PR was created by an AI agent (OpenHands) on behalf of the user.
@malhotra5 can click here to continue refining the PR