Repository navigation
Let assigned agents react to comments on their tasks - #843
Conversation
An agent assigned to a task only picked up new comments when it was @-mentioned in them: handleMentions was the single path from a comment to an agent, and it never looked at the task's assignees. The automation workaround (comment_added -> trigger_ai_agent) retriggers on the agent's own reply and cannot batch comments. Add two per-agent settings, off by default: - assigned_comment_trigger: a comment by a person on a task the agent is assigned to starts a comment_mention conversation for it. Comments by agents never count, so a reply cannot retrigger its author, and a comment that already mentions the agent triggers through the mention path only. - assigned_comment_window_minutes (default 2, 0 = immediate): further comments on the same task during the window are batched into the same conversation. The first comment fixes when it starts; later ones append their text to agent_pending_comment_triggers, one row per agent and task, and worker.AssignedCommentScheduler fires the due rows under a leader lock, in the same shape as WaitScheduler. The conversation is authorized as the last person who commented and queues behind parallelism_limit like any other trigger. Settings flow through the agent DTOs, the settings form (with translations) and the agent overview docs. Closes Paca-AI#841
There was a problem hiding this comment.
Important
Two concurrency defects in the batching path can permanently drop a person's comment or start the same conversation twice, and one smaller gap lets service-account comments through.
Approach: sound — the trigger reuses the existing mention conversation path and the triggergate authorization instead of adding a parallel dispatcher, and batching is opt-in and bounded.
Reviewed changes
- Data model — migration
000100adds the two agent settings and the pending-batch table; agent select/insert/update carry the new columns. - Trigger path —
handleAssignedAgentsruns afterhandleMentionson a person's comment, starting immediately or queuing per(agent, task); the mention refactor sharesstartCommentConversation. - Scheduler —
AssignedCommentSchedulerfires due batches every 15s under a Valkey leader lock, wired into start/stop. - API + UI — domain/DTO/handler plumbing with a 0–1440 clamp, plus the settings switch and window input with locale strings.
- Docs + tests — new "Comments on assigned tasks" section and five in-memory activity-service cases.
ℹ️ A queued batch is not re-checked against the agent's current state
Turning the setting off or unassigning the agent during a window still fires the already-queued batch; with assigned_comment_window_minutes up to 24h that can be a long and surprising delay. Re-loading the agent (and its current assignees) in FireDuePendingCommentTriggers would close it, or the behaviour could be documented as intended.
Technical details
# Queued batches ignore later opt-out / unassignment
## Affected sites
- `services/api/internal/service/task/activity_service.go:390-408` — `FireDuePendingCommentTriggers` fires from the row only; it never reloads the agent or the task.
- `services/api/internal/service/task/activity_service.go:361-366` — opt-in is checked only when the comment is queued.
## Required outcome
- Decide whether disabling the setting (or unassigning the agent) should cancel a pending batch. If yes, re-check `agent.AssignedCommentTrigger` and the agent's current assignee membership before firing; if no, state it in the docs so the 2-minute default is not mistaken for "immediate off".deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
Address review findings on the assigned-comment trigger: - A comment appended between ListDue's snapshot and the unconditional delete was removed unseen and lost. Replace Delete with Claim, a delete conditional on the last comment id the scheduler read: when a comment arrived since, the row is left for the next tick, which then carries it. The same claim makes a batch fire at most once. - The scheduler's leader lock was never renewed, so a tick that outlived its TTL let another replica process the same rows. Renew the token before every batch, as WaitScheduler does, and stop once it is lost. - A service account commenting through an API key passed as a person. Require a human member instead of only excluding agents. - A batch queued before the setting was turned off, or before the agent was unassigned, still fired when its window elapsed. Re-check both before firing and drop the batch otherwise. Cover each with a test, plus the scheduler's lock handling.
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the new commit keeps the single shared conversation path and replaces the racy delete with an atomic claim, which is the right layer for the at-most-once guarantee.
Reviewed changes
- Atomic batch claim —
Deleteis replaced byClaim(agentID, taskID, lastCommentID), which only removes the row while itslast_comment_idstill matches theListDuesnapshot; a comment that lands mid-run is kept for the next tick and a batch fires at most once even if replicas overlap. - Fire-time re-check —
pendingCommentStillWantedreloads the agent and task assignees before each batch and drops it when the setting was turned off or the agent was unassigned; lookup failures leave the row for retry. - Human-only authors —
handleAssignedAgentsnow requiresMemberType == "human", so service-account commenters no longer trigger, with a new regression test. - Leader lock renewal — the scheduler renews its token before every batch and stops the tick when the lock is lost; a lost lock is never released or stolen back, and new scheduler tests cover acquire/skip/mid-tick loss.
- Tests and docs — activity-service cases for the mid-run comment, opt-out, unassignment and
proceedstop signal, plus the updated overview wording.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
|
Hi @sebathi, thanks for this PR, nice work! 🙌 Could we use a stream consumer here, like our other consumers, instead of a separate scheduler? It would keep things consistent and make horizontal scaling easier.
|
Replace AssignedCommentScheduler with AssignedCommentConsumer, a consumer group on the activity stream like the other task listeners. It reads task.comment.added, queues the comment for every assigned agent that opted in, and fires the due batches from the same read loop. Nothing runs on the request that posts the comment any more, and there is no scheduler or leader lock: every replica sweeps, and the atomic claim keeps a batch to one conversation. A zero window is a batch that is due at once, so both paths fire through the same claim. A lookup failure leaves the event unacked for the reclaimer, and a batch ignores a comment it already ends with, so a redelivery is not recorded twice.
|
Makes sense, done in a8573f9. One thing worth a look: the batching window still needs something to fire the batches when they come due, and a stream can't do that by itself. I put that sweep in the consumer's own read loop (right after a read that queued a comment, otherwise every 15s) instead of a separate worker. There is no leader lock; every replica sweeps, and each batch is claimed with a conditional If you would rather not have the sweep there at all, the alternative is to drop the window and always trigger immediately. Happy to go that way if you prefer it simpler. I updated the PR description to match. |
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the new commit moves assigned-comment detection onto the activity stream (api.assigned_comment_trigger group) and keeps the atomic Claim as the at-most-once mechanism, replacing the leader-locked scheduler without adding a parallel dispatch path.
Reviewed changes
- Replaced the leader-locked scheduler with a stream consumer —
worker.AssignedCommentConsumerreadstask.comment.addedfrompaca.activitiesthrough its own consumer group starting at$, decodes the activity payload, and acks non-comment, edited, authorless and malformed entries untouched. - Took queueing off the request path —
handleAssignedAgentsbecameHandleAssignedComment(projectID, taskID, commentID, actorMemberID, content), which re-resolves the author by member id (rejecting agents and service accounts), loads the task, skips @-mentioned agents and appends to each opted-in agent's batch. - Swept due batches without a lock —
FireDuePendingCommentTriggerslost itsproceedcallback and now fires right after a read that queued a batch or every 15s; the existingClaimfence keeps it at-most-once across replicas, and the re-check of opt-in/assignment still runs before the claim. - Made batch append idempotent — the upsert now carries
WHERE agent_pending_comment_triggers.last_comment_id <> EXCLUDED.last_comment_id, so a redelivered comment that is already the row's last is a no-op. - Updated wiring, docs and tests —
app.gostarts/stops the consumer, the overview describes the consumer model, and tests cover ack/redelivery, untouched entries, sweep scheduling, the two-replica claim and a partial lookup failure.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Closes #841.
Problem
An agent assigned to a task only picks up new comments when it is @-mentioned in them.
handleMentionsinactivity_service.gois the single path from a comment to an agent and never looks at the task's assignees. The automation workaround (comment_added→trigger_ai_agent) refires on the agent's own reply comment and cannot batch comments (see the issue).Change
Two per-agent settings, off by default, on both project and global agents:
assigned_comment_trigger— a comment by a person on a task the agent is assigned to starts acomment_mentionconversation for it, as an @-mention would. Comments by agents, service accounts and the platform itself (an automation'sadd_comment) never count, so a reply cannot retrigger its author. A comment that already @-mentions the agent triggers through the mention path only, never twice. The commenter must be allowed to use the agent, as with a mention (sametriggergatepath).assigned_comment_window_minutes(default 2,0= immediate) — further comments on the same task during the window are batched into the same conversation. The first comment fixes when it starts; later ones append their text toagent_pending_comment_triggers(one row per agent and task). The conversation message is the collected comments separated by blank lines; the conversation'scomment_idis the last one.The resulting conversation queues behind
parallelism_limitlike any other trigger, so nothing changes in dispatch.How it runs
worker.AssignedCommentConsumeris a consumer group (api.assigned_comment_trigger) onpaca.activities, a peer of the autofill, auto-assign and automation listeners, shaped afterQuestionNotificationConsumer(own group starting at$,streamReclaimerfor unacked entries). Nothing runs on the request that posts the comment.task.comment.addedit callsActivitySvc.HandleAssignedComment, which appends the comment to the pending batch of every assigned agent that opted in. A zero window is just a batch that is due at once.DELETE ... WHERE last_comment_id = <the one read>, so it starts one conversation however many replicas read it, and a comment that lands mid-sweep leaves the batch for the next pass.Files
migrations/000100_add_agent_assigned_comment_trigger.sql— twoagentscolumns plus the pending table.domain/agent/comment_trigger.go,repository/postgres/comment_trigger_repository.go— pending batch type and repository (append / list due / claim).service/task/activity_service.go—HandleAssignedCommentandFireDuePendingCommentTriggersfor the consumer.AddCommentandhandleMentionsare as on master; the mention trigger and the new one sharestartCommentConversation.worker/assigned_comment_consumer.go,bootstrap/app.go— consumer and wiring.apps/web:Agenttype and payloads, a switch plus a window input in the agent settings form, translations in all locales.docs/ai-agent/overview.md— new "Comments on assigned tasks" section under the comment-mention trigger.Tests
activity_service_test.go, with in-memory fakes: zero window, setting off, comment by the agent, comment by a service account, agent already mentioned (exactly one trigger), a two-minute window that batches two comments and fires once, the same event delivered twice, a lookup failure returned for redelivery, a comment arriving mid-sweep, the same batch read by two replicas, and a batch dropped after the setting is turned off or the agent is unassigned.assigned_comment_consumer_test.go, with miniredis: a comment is handed over and acked, a failed one stays pending, other entries (other topics, edited comments, comments with no author, undecodable payloads) are acked untouched, the sweep is due after queueing and on the interval, and the running loop picks up a new comment.go vet ./...andgo test ./... -racepass inservices/api;tsc --noEmit,biome checkand the locale parity test pass inapps/web.Not covered
No Postgres-backed test for the new repository (those are skipped without
PACA_TEST_PG_DSN). The MCP server does not expose agent settings, so it is untouched.