Skip to content

feat(cron): share group task lists and allow admin deletion - #10785

Merged
Soulter merged 4 commits into
AstrBotDevs:masterfrom
mantoujun12:feat/cron-admin-group-task-management
Oct 26, 2026
Merged

Soulter merged 4 commits into
AstrBotDevs:masterfrom
mantoujun12:feat/cron-admin-group-task-management

Conversation

@mantoujun12

@mantoujun12 mantoujun12 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10782

Group task visibility should be shared by everyone in the current group, while changes remain subject to ownership checks. Previously, future_task required both the session and sender to match for every operation, so members could not list each other's tasks and AstrBot administrators could not remove them from chat.

This PR lets all group members list every task in the current group conversation, with creator=<sender_id> on each row (unknown for tasks without a recorded creator). Regular members can edit and delete only their own tasks. AstrBot administrators can additionally delete other members' tasks, including same-group WebUI or legacy tasks with no recorded chat creator. Editing remains limited to the creator.

Administrator privileges refer to AstrBot's configured administrators (admins_id), not platform group administrators. All access remains scoped to the current conversation. Private chats retain both session and sender isolation.

Permissions in the current group

Caller List Edit Delete
Regular member All tasks in the current group Own tasks only Own tasks only
AstrBot administrator All tasks in the current group Own tasks only All tasks in the current group

Implementation

  • Update future_task filtering and tool guidance for shared group visibility while preserving edit and delete authorization.
  • Display task creators to all group members; include same-group tasks without a recorded creator.
  • Prevent cron runs from starting after deletion begins, cancel and drain active runs, and keep deletion markers until concurrent deletions finish.
  • Update English and Chinese proactive-agent permissions and troubleshooting documentation.
  • Cover member/admin visibility, cross-session boundaries, private-chat isolation, creator display, ownership restrictions, and deletion races in unit tests.

No database schema, Dashboard API, dependency, or WebUI navigation/layout changes are included.

Validation

  • python -m pytest tests/unit/test_cron_tools.py tests/unit/test_cron_edit_validation.py tests/unit/test_cron_manager.py tests/unit/test_cron_service.py -q: 92 passed.
  • Expanded run also including tests/unit/test_cron_events.py: 105 passed, 1 failed. The failure is the existing log-capture assertion in test_missing_platform_does_not_record_send: the warning is printed but caplog.text is empty. The identical failure was reproduced in the untouched original checkout.
  • ruff format . and ruff check .: passed.
  • Explicit formatting and lint checks for the modified test file: passed.
  • git diff --check: passed.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/tools/cron_tools.py" line_range="315" />
<code_context>
+            same_session = _extract_job_session(job) == current_umo
+            can_delete = _job_belongs_to_current_sender(
+                job, current_umo, current_sender_id
+            ) or (same_session and _is_group_admin(context.context.event))
+            if not can_delete:
                 if same_session and not _extract_job_sender(job):
</code_context>
<issue_to_address>
**Deleted tasks still execute**

When a scheduled run's row lookup overlaps an admin deletion and returns the row before the deletion commits, `CronJobManager._run_job` adds its task to `_running_tasks` only after awaiting the row lookup, while `delete_job` removes the schedule and snapshots that set before deleting the row. A run that fetched the row but has not registered yet escapes cancellation and executes after the admin receives a deletion success.

Coordinate run registration and deletion (for example, with a per-job lock or deletion marker) so a run cannot start after deletion has begun.
</issue_to_address>

### Comment 2
<location path="astrbot/core/tools/cron_tools.py" line_range="47-56" />
<code_context>
     )


+def _is_group_admin(event: Any) -> bool:
+    """Check whether the event sender is an AstrBot admin acting in a group chat.
+
+    Args:
+        event: The current message event.
+
+    Returns:
+        True when the sender is an AstrBot admin and the event is a group message.
+    """
+    return event.get_message_type() == MessageType.GROUP_MESSAGE and event.is_admin()
+
+
</code_context>
<issue_to_address>
**Unneeded permission helper extraction**

When the helper is added to the existing tool implementation, `_is_group_admin` adds a helper to an existing function for a one-line predicate used at only two sites, without the repeated-logic or significant readability/length justification required by the rule.

Inline the predicate at its two call sites and remove `_is_group_admin`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and the change grants group-chat admins authority to delete other members’ scheduled tasks, including same-group tasks without a recorded creator; a mistaken deletion can cancel future runs and is not undone by reverting the code. This is a permission-boundary decision, so an overly broad grant may not produce an error that signals the policy is wrong.

Blocking findings: astrbot/core/tools/cron_tools.py:315


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/tools/cron_tools.py Outdated
Comment thread astrbot/core/tools/cron_tools.py Outdated
@Soulter Soulter changed the title feat(cron): let admins manage group future tasks feat(cron): share group task lists and allow admin deletion Oct 26, 2026
@Soulter
Soulter merged commit 8da7994 into AstrBotDevs:master Oct 26, 2026
23 checks passed
@mantoujun12
mantoujun12 deleted the feat/cron-admin-group-task-management branch October 26, 2026 15:41
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.

[Feature] 允许 AstrBot 超管在群聊中停止或删除其他成员创建的定时任务

2 participants