Skip to content

fix(opencode): Add a poller to opencode CLI inbox delivery to drain s…#210

Merged
haofeif merged 6 commits into
awslabs:mainfrom
patricka3125:fix/opencode-message-delivery
Apr 29, 2026
Merged

fix(opencode): Add a poller to opencode CLI inbox delivery to drain s…#210
haofeif merged 6 commits into
awslabs:mainfrom
patricka3125:fix/opencode-message-delivery

Conversation

@patricka3125

@patricka3125 patricka3125 commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Overview

Adds a temporary OpenCode-specific inbox delivery poller to prevent opencode_cli assign/send_message callbacks from getting stuck in pending after the supervisor TUI settles.

OpenCode can become idle without emitting another pipe-pane log update, so the existing watchdog-backed LogFileHandler may never get a file-modified event to re-check pending inbox messages. This change keeps the existing immediate-delivery and watchdog paths unchanged, but adds a small pending-message-driven fallback for OpenCode only: every inbox polling interval, the server finds OpenCode terminals with pending inbox messages and reuses the existing check_and_send_pending_messages() delivery helper.

Addresses Issue #203.

This is intentionally scoped as a stopgap. It documents and accepts the existing duplicate-wakeup race between immediate delivery, watchdog delivery, and this poller; PR #115 should replace these paths with a single coordinated delivery engine.

Key Changes

File Change
src/cli_agent_orchestrator/clients/database.py Add list_pending_receiver_ids_by_provider() to query distinct receiver terminal IDs with pending inbox messages for a specific provider
src/cli_agent_orchestrator/services/inbox_service.py Add poll_opencode_pending_messages() which scans pending opencode_cli receivers and calls the existing delivery helper per receiver
src/cli_agent_orchestrator/api/main.py Start and shut down an async opencode_inbox_delivery_daemon() alongside the existing flow daemon and watchdog observer
test/clients/test_database.py Add unit coverage for the provider-scoped pending receiver query
test/services/test_inbox_service.py Add unit coverage for OpenCode polling, including continuing after one receiver delivery attempt fails
test/api/test_api_endpoints.py Add unit coverage for the async poller daemon and update lifespan test setup for the new background task

Test Plan

  • uv run --group dev python -m black src/cli_agent_orchestrator/api/main.py src/cli_agent_orchestrator/clients/database.py src/cli_agent_orchestrator/services/inbox_service.py test/api/test_api_endpoints.py test/clients/test_database.py test/services/test_inbox_service.py
  • uv run --group dev pytest test/services/test_inbox_service.py test/clients/test_database.py test/api/test_api_endpoints.py::TestOpenCodeInboxDeliveryDaemon test/api/test_api_endpoints.py::TestLifespan -q47 passed
  • git diff --check
  • OpenCode callback smoke: started local cao-server, installed analysis_supervisor, data_analyst, report_generator, and developer for opencode_cli, then ran uv run --group dev pytest -m e2e test/e2e/test_assign.py::TestOpenCodeCliAssign::test_assign_with_callback -v -s1 passed in 62.41s
  • OpenCode assign profile smoke: uv run --group dev pytest -m e2e test/e2e/test_assign.py::TestOpenCodeCliAssign::test_assign_data_analyst test/e2e/test_assign.py::TestOpenCodeCliAssign::test_assign_report_generator -v -s2 passed in 114.04s

@patricka3125 patricka3125 marked this pull request as draft April 27, 2026 19:00
@patricka3125

Copy link
Copy Markdown
Collaborator Author

todo -

  1. mark code changes with reference to this PR and event driven architecture PR for long term solution
  2. update opencode CLI document noting that temporary fix is implemented

@haofeif haofeif added the enhancement New feature or request label Apr 28, 2026
@patricka3125

patricka3125 commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator Author

Manual OpenCode smoke test completed. The OpenCode polling fix is working. Tested with all agent profiles running on DeepSeek V4 Flash.

Scenario Result Evidence
Supervisor assigns to 3 data analysts Passed Created data_analyst terminals d35a1264, 87db9273, b58aaa9b
Supervisor handoff to 1 report agent Passed Created report_generator terminal 001a0bf4; supervisor received template
3 data analysts sent messages to supervisor Passed All three worker panes reported successful send_message to supervisor 0902d7f9
Supervisor receives all 3 analyst messages Passed Inbox rows 122, 123, 124 all reached delivered
Supervisor got report agent result Passed Supervisor summary marked report handoff as template received
Supervisor completed the job Passed Supervisor summary reported all tasks complete and orchestration verified

Key fix validation: Dataset B and Dataset C messages initially appeared as pending inbox rows, then the OpenCode polling fallback delivered them to the supervisor successfully.

@patricka3125 patricka3125 marked this pull request as ready for review April 28, 2026 18:51

@haofeif haofeif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haofeif haofeif merged commit 1f2a048 into awslabs:main Apr 29, 2026
8 checks passed
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@340b79d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/cli_agent_orchestrator/api/main.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #210   +/-   ##
=======================================
  Coverage        ?   92.49%           
=======================================
  Files           ?       60           
  Lines           ?     4994           
  Branches        ?        0           
=======================================
  Hits            ?     4619           
  Misses          ?      375           
  Partials        ?        0           
Flag Coverage Δ
unittests 92.49% <92.59%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants