Repository navigation
fix(proactive): persist care messages to thread history and track replies - #3133
Merged
Merged
Conversation
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.
Summary
Fixes #3064 — proactive care messages pushed to Dashboard (and IM) sessions were previously delivered through transport-only
Gateway.push_text_from_session, so nothing was persisted to LangGraph checkpoints orthread_messages, leaving unread badges pointing at empty conversations and agents blind to what they just asked.Phase 1: Persistence & non-disruptive delivery
AIMessage:ProactiveCareService._deliver()runs undergateway.run_in_session(...), re-validatescan_send()inside the session lock, binds the session's latest active thread (skipping empty placeholder threads, matchingcron's default strategy), appendsAIMessage(id="care:<ulid>:assistant")to bothharness.aappend_messages(...)andthread_message_repo.append_if_ready(...), then pushes viapush_session_text+ best-effortnotify_dashboard_push.Gateway.push_text_from_sessionremains transport-only.select_care_target_session): strictly selects IM DM (is_im_session&chat_type == "dm") or falls back to Dashboard DM, preventing private emotional care from targeting MCP sessions (channel_id="octop-agent-mcp"), IM group chats, peer/team rooms, or CLI sessions.ThreadMessageRepo.latest_human_activity(agent_id)(excluding syntheticcron:%prompts and AI messages), removing the 5-minute push-activity slack bug where a quick user reply within 5 minutes was ignored as our own push. Falls back tothread_repo.latest_user_activityfor unprojected legacy threads.HitlPendingStore.has_pending_for_agent(agent_id)so proactive care defers while an approval prompt is pending.Phase 2: Reply tracking & backoff
thread_id,message_id,care_text,status(sent/replied/ignored),replied_at, andreply_message_idplus indexes tocare_push_records(SQLite + PostgreSQL).GlobalProcessor._mark_care_repliedmarks the latest open care push on the thread asreplied(and older open pushes on that thread asignored) on genuine IM and Dashboard/CLI user turns (ignoring slash commands and HITL answers).ProactiveCareSchedulerscales the push interval viabackoff_interval_hours(1x for 0–1 unanswered, 2x for 2, 4x for 3+, capped at 7 days) and resets automatically once the user replies.Target branch
develop(feature / fix — default)main(release/*orhotfix/*only)Type of change
Test plan
tests/unit/proactive/test_proactive_service.py,test_scheduler.py,test_care_reply_tracking.py)pytest tests/unit/proactive tests/unit/gateway/test_gateway_push.py tests/unit/db/test_db_pool.py— 104 passedpytest tests/unit/db/test_runtime_replace_services.py tests/unit/gateway/test_gateway.py tests/unit/gateway/test_hitl_channel.py tests/unit/gateway/test_dashboard_ws.py— 69 passedruff check src tests,ruff format --check src tests,mypy src/octopChecklist
CHANGELOG.md(if user-facing)