Repository navigation
fix(cron): DM an app-owned cron's result to the owner, not its app tag - #30849
Conversation
A cron with no channel opens a Slack DM to `job.created_by`, falling back to the owner only when it is empty. A job an app registers for itself carries `app:<name>` there, and an imported one `import:<source>`. Neither is a Slack user id, so `conversations.open` fails with `user_not_found` on every run and the result, or the failure alert, reaches nobody. The gateway logs "Slack delivery failed (job succeeded)" once per run. Both legs now resolve the DM through `_cron_dm_user`: a namespaced or empty `created_by` goes to the install's owner; a person's Slack id is kept.
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: both Slack DM paths now share one owner-fallback rule, and a Slack user id in Notes
[DESIGN-REVIEWED] 1a63c94 Description read[DESCRIPTION-READ] 71b86a08c0bb33252bd8598c064a17d2cebb3469b305f64b75cafe0a84baee47 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The new helper fixes both places a cron DM is opened from What this change shipsInventory (4 items) — 4 justifiedIntent: when an app's or an imported cron job finishes or fails, its result and failure alert reach the install owner's Slack DM instead of failing on every run. FIX.
[FIRST-PRINCIPLES-REVIEWED] 1a63c94 Description read[DESCRIPTION-READ] 080a33b4acdc947deeb33a1dace8312179240fa1c1e4071b1086dbcb0a519467 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
|
@bolichen97 thanks for approving the runs. Could you click Re-run failed jobs on CI run 42128552215? Detect changed surface failed during checkout ( |
The gateway facade binds _cron_dm_user from the delivery owner, so the composition contract's _BASE_SURFACE needs its row. Without it, test_every_bound_owner_member_has_a_base_surface_row fails.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Reviewed on head 1a63c94. Both channel-less cron DM sites (the result in cron_delivery.py and the failure alert in cron_failure.py) now go through _cron_dm_user. An app: or import: creator goes to the owner, a Slack user id still gets its own DM, and an empty creator still falls back to the owner. The review ran the new tests on this head and they passed. Putting back main's job.created_by or self._owner_id turned exactly the three tests named in the Proof line red. The composition contract and runtime bindings tests also pass. The new tests use mocks only, with no sleeps, clocks or ports.
Done well: one helper serves both legs, so the result DM and the failure alert cannot pick different recipients.
Optional: open PR #29609 rewrites the same two lines with a guest:-only helper. Whichever PR lands second should fold both into one helper.
Optional: no test pins the "any colon" breadth of the tag check. One extra case such as guest:x going to the owner would make that choice explicit, and would also answer the Design lane note.
Optional: app-owned cron output now reaches the owner's Slack DM without checking the app's capabilities.messaging grant. The recipient is always the owner and redaction still runs. A maintainer may want to decide separately whether that grant should apply here.
bolichen97
left a comment
There was a problem hiding this comment.
Approving head 1a63c9401a. _cron_dm_user falls back to the owner only when created_by is empty or tagged with a :. The only colon-bearing values on main are the app:<name> (CronSDK) and import:<source> (onboarding_import) owner tags. A real Slack user id never has one (CronJob.created_by is documented as the creator's Slack id), so a person's own cron still goes to that person, and no one else's result is redirected to the owner. Both the result path and the failure-alert path use the same helper.
On this head, test_slack_gateway_composition_contract.py + test_slack_gateway_cron_exec_coverage_delivery.py gave 373 passed. CI and every review lane pass. I'll merge it now.
AI-assisted, sent by CommunityCrew
Problem / Motivation
Goal: An app's cron job delivers its result and its failure alert to the install owner's Slack DM instead of failing every run.
A cron with no channel opens a Slack DM to
job.created_byand falls back to the owner only when that is empty. A job an app registers for itself carriesapp:<name>there (CronSDK), and an imported job carriesimport:<source>. Neither is a Slack user id, soconversations.openfails withuser_not_foundand the gateway logs this on every run:Seen on 0.11.2.1 with a third-party app's hourly, non-silent job: 12 failures in 12 hours.
Why it matters
Every non-silent app or imported cron loses its Slack result, and every app or imported cron loses its Slack failure alert, which is the one notice that says a job has stopped working. The owner sees nothing in Slack and the log fills with a traceback per run.
Not a goal
created_byis still DM'd.job.channel, or silent handling.created_by.What changed (motivation → approach → change)
Symptom:
conversations.openwithusers=["app:<name>"]. Root cause: both DM legs treat any non-emptycreated_byas a Slack user. The value is an owner tag for app and imported jobs, and those tags always contain:, which a Slack user id never does.Change: a new
_cron_dm_user(job)inslack/gateway_runtime/delivery.pyreturnscreated_bywhen it names a person and the install owner when it is empty or a namespaced tag.cron_delivery.py(result) andcron_failure.py(failure alert) both resolve their DM through it. The two owners' "Orchestrator fields read" lines drop_owner_id, which they no longer read directly.Backwards compatibility
Compatible: a person's Slack id still opens their DM. Only a value that could never open a DM now falls back to the owner.
Removes nothing: the DM target only widens from "fail" to "the owner" for tagged creators.
Tests
TestCronChannelDelivery::test_the_result_dm_opens_to_a_person_never_an_owner_tag(4 cases): a person's id is kept;app:standup-digest,import:sched-7and an empty creator open the owner's DM; the result posts and the dedup anchor advances.TestCronFailureChannelDelivery::test_an_app_owned_cron_failure_alert_reaches_the_owner: a failingapp:standup-digestcommand cron alerts the owner's DM.Proof: PROVEN test/test_slack_gateway_cron_exec_coverage_delivery.py::TestCronChannelDelivery::test_the_result_dm_opens_to_a_person_never_an_owner_tag[app_owned_job], test/test_slack_gateway_cron_exec_coverage_delivery.py::TestCronChannelDelivery::test_the_result_dm_opens_to_a_person_never_an_owner_tag[imported_job], test/test_slack_gateway_cron_exec_coverage_delivery.py::TestCronFailureChannelDelivery::test_an_app_owned_cron_failure_alert_reaches_the_owner (head 1a63c94)
Commands run on this head:
Manual verification
On a 0.11.2.1 install, an app's non-silent hourly job logged the traceback above on every run. This change has not run on that install, so end-to-end delivery is covered by the tests above only.
Related Issues
N/A — found while debugging an app's hourly Slack delivery error.
Sibling sweep
Swept: git grep -nE "open_dm(_with_retry)?(" -- src/kiro_crew
Sibling: src/kiro_crew/slack/gateway_runtime/cron_failure.py:163 -- changed here
Sibling: src/kiro_crew/dashboard/messaging_api/proactive_send.py:1058 -- not affected -- target_user is a named Slack user from the send request, never created_by
Sibling: src/kiro_crew/slack/allowlist.py:319 -- not affected -- user_id comes from an allowlist request by a Slack user
Every other
open_dmcall site passes the owner id.Pattern harvest
Rule candidate: review-prompt
Pattern: an owner field that can hold a namespaced tag (
app:<name>,import:<source>) passed to an API that expects a Slack user idChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.