Skip to content

Commit 56afaef

Browse files
authored
fix(lark): converge dual-mentioned group source ownership across binding toggles (#10054)
Rebase onto latest main (#10052) while preserving unmodified provider message ancestry for flat source-context replies, scoping multi-App Goal listener targets via goal_topic_profile, and persisting shared per-source completion receipts so late or replayed deliveries after Worker/Manager binding toggles never emit duplicate group replies while uncompleted sources retain an explicit recovery path. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 2a0a08b commit 56afaef

8 files changed

Lines changed: 840 additions & 261 deletions

File tree

‎loopx/extensions/lark/docs/lark-event-inbox.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,22 @@ inside that source topic. Existing configs without the field retain the legacy
610610
`source_thread` policy. `reply.editorial_style=bullet_points_preferred` projects
611611
an operator hint for structured replies; the command preserves line breaks.
612612

613+
In an ordinary group, a top-level human message can mention both the manager
614+
Bot and a worker Bot in the same chat. When the provider identifies both Bots
615+
and the worker has an executable managed Session route, the worker handles the
616+
request and replies once in place while the manager retains the message as
617+
context (`worker_co_addressed`). Shared source-handling state under the runtime
618+
root converges both listeners onto the first verified reply across binding
619+
changes: disabling the worker after it has replied does not start a manager Turn
620+
on late manager delivery or replay, and enabling the worker after the manager
621+
has already answered while the worker was unavailable does not emit a second
622+
worker reply. If neither listener has produced a verified completion receipt and
623+
the initially expected handler becomes unavailable, redelivery recovers through
624+
the active route; fresh source message IDs reselect from current bindings.
625+
Display names alone do not select a worker, an explicit thread keeps its
626+
existing routing, and the binding's pinned topic can identify the Goal without
627+
making a top-level provider message a thread reply.
628+
613629
Manager answers and delegated conclusions use a rich `post` with one Markdown
614630
node, preserving paragraphs, lists and code indentation. The extension supplies
615631
exact JSON to the existing CLI transport: it does not fetch Markdown images or

‎loopx/extensions/lark/event_inbox.py‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ def _event_from_payload(
467467
event["reply_context_verified"] = False
468468
elif addressing_source:
469469
event["addressing_source"] = addressing_source
470+
if payload.get("worker_co_addressed") is True:
471+
# Keep the provider mention counts, but this manager item is context
472+
# unless recovery promotes it before any completion receipt exists.
473+
event["worker_co_addressed"] = True
474+
event["addressed_to_bot"] = False
470475
return event
471476

472477

@@ -522,7 +527,10 @@ def _event_attention_kind(
522527
bot_display_name: str,
523528
capture_scope: str,
524529
) -> str | None:
525-
if event.get("historical_context_only") is True:
530+
if (
531+
event.get("historical_context_only") is True
532+
or event.get("worker_co_addressed") is True
533+
):
526534
return None
527535
normalized = dict(event)
528536
normalized["addressed_to_operator"] = bool(
@@ -812,6 +820,41 @@ def ingest_lark_event_inbox(
812820
}
813821

814822

823+
def promote_lark_event_inbox_co_addressed_item(
824+
*, project: str | Path, config_path: str | Path, message_id: str
825+
) -> bool:
826+
"""Restore direct manager addressing when a deferred item recovers uncompleted."""
827+
828+
if not MESSAGE_ID_PATTERN.fullmatch(message_id):
829+
return False
830+
config = load_lark_event_inbox_config(project=project, config_path=config_path)
831+
if not config["enabled"]:
832+
return False
833+
path = Path(config["inbox_path"]) / f"{message_id}.json"
834+
try:
835+
payload = json.loads(path.read_text(encoding="utf-8"))
836+
except (OSError, json.JSONDecodeError):
837+
return False
838+
if not isinstance(payload, dict) or payload.get("worker_co_addressed") is not True:
839+
return False
840+
updated = dict(payload)
841+
updated.pop("worker_co_addressed", None)
842+
updated.pop("addressed_to_bot", None)
843+
normalized = _event_from_payload(
844+
updated,
845+
bot_display_name=str(config["reply"].get("bot_display_name") or ""),
846+
bot_app_id=str(config["reply"].get("bot_app_id") or ""),
847+
bot_open_id=str(config["reply"].get("bot_open_id") or ""),
848+
allow_text_addressing=config["capture_scope"] == "addressed_only",
849+
)
850+
if normalized is None:
851+
return False
852+
write_private_json_atomic(
853+
path, {"schema_version": EVENT_SCHEMA_VERSION, **normalized}
854+
)
855+
return True
856+
857+
815858
def inspect_lark_event_inbox(
816859
*, project: str | Path, config_path: str | Path, limit: int = 20
817860
) -> dict[str, Any]:

0 commit comments

Comments
 (0)