Skip to content

fix(cron): DM an app-owned cron's result to the owner, not its app tag - #30849

Merged
KiroCrewCaptain merged 2 commits into
kirodotdev:mainfrom
leozhad:fix/app-cron-dm-owner
Nov 11, 2026
Merged

KiroCrewCaptain merged 2 commits into
kirodotdev:mainfrom
leozhad:fix/app-cron-dm-owner

Conversation

@leozhad

@leozhad leozhad commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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_by and falls back to the owner only when that is empty. A job an app registers for itself carries app:<name> there (CronSDK), and an imported job carries import:<source>. Neither is a Slack user id, so conversations.open fails with user_not_found and the gateway logs this on every run:

ERROR kiro_crew.slack.gateway: Cron job '<app>/<job>': Slack delivery failed (job succeeded)
...
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://slack.com/api/conversations.open, status: 200)

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

  • No change to what a person-scheduled job does: a Slack user id in created_by is still DM'd.
  • No change to channel-origin delivery, job.channel, or silent handling.
  • No change to how apps or imports tag created_by.

What changed (motivation → approach → change)

Symptom: conversations.open with users=["app:<name>"]. Root cause: both DM legs treat any non-empty created_by as 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) in slack/gateway_runtime/delivery.py returns created_by when it names a person and the install owner when it is empty or a namespaced tag. cron_delivery.py (result) and cron_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-7 and 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 failing app:standup-digest command 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:

python3 -m pytest test/test_slack_gateway_cron_exec_coverage_delivery.py test/test_slack_gateway_composition_contract.py \
  test/test_cron_alert_after_failures.py test/test_cron_failure_alert_one_spelling.py test/test_open_dm_retry.py   # 448 passed
python3 -m pytest test/test_gateway_runtime_bindings.py test/test_slack_gateway_composition_contract.py \
  test/test_slack_gateway_cron_exec_coverage_delivery.py   # 414 passed (head 1a63c9401a9e)
black --check / isort --check-only / flake8 on the changed files   # clean
mypy src/kiro_crew/slack/gateway.py src/kiro_crew/slack/gateway_runtime/   # no issues in 33 files
COMMENT_HISTORY_BASE_REF=$B python3 scripts/check_comment_history.py   # passed
BRAND_BASE_REF=$B python3 scripts/check_brand_name.py                  # passed
python3 scripts/local-gate.py   # related backend tests: 23618 passed; the 26 failures are in test_chat_voice, test_cli TestDoctor, test_acp_* and others that fail the same way on unmodified main in this sandbox (no voice engine, no kiro-cli)

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_dm call 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 id

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

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.
@leozhad
leozhad requested review from a team and KiroCrewCaptain as code owners November 5, 2026 23:17
@leozhad
leozhad requested a review from dodgeblaster November 5, 2026 23:17
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention fork Pull request from a fork (external contributor) labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 1a63c9401a9e4bf1065a2c617d9432f72d36ac6f via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: both Slack DM paths now share one owner-fallback rule, and a Slack user id in created_by is still DM'd as before.

Notes

  • _cron_dm_user checks for a : anywhere in the value instead of looking for the two known tags, app: and import:. The CronJob.created_by field says it holds a Slack user id, so any value with a colon goes to the owner. That includes person keys a future caller might store there. Checking the tag prefixes would make the rule match what the description says it does.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 1a63c9401a9e4bf1065a2c617d9432f72d36ac6f touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 1a63c9401a9e4bf1065a2c617d9432f72d36ac6f via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The new helper fixes both places a cron DM is opened from created_by. A grep for job.created_by or self._owner_id finds 2 sites, both changed, so no sibling is left unfixed.

What this change ships

Inventory (4 items) — 4 justified

Intent: 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.

  1. When an app-owned (app:<name>) or imported (import:<source>) cron job finishes with no channel set, its result now goes to the owner's DM instead of failing with user_not_found. — justified
  2. The failure alert for a tagged cron job now reaches the owner's DM the same way. — justified
  3. A person's Slack id in created_by still gets the DM, and an empty creator still falls back to the owner. — justified
  4. The orchestrator has a new _cron_dm_user method, pinned in the composition-contract surface test. — justified

[FIRST-PRINCIPLES-REVIEWED] 1a63c94

Description read

[DESCRIPTION-READ] 080a33b4acdc947deeb33a1dace8312179240fa1c1e4071b1086dbcb0a519467

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 1a63c9401a9e4bf1065a2c617d9432f72d36ac6f via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 1a63c94

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 1a63c9401a9e4bf1065a2c617d9432f72d36ac6f via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 1a63c94

@leozhad

leozhad commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks for approving the runs. Could you click Re-run failed jobs on CI run 42128552215?

Detect changed surface failed during checkout (fatal: protocol error: bad pack header) before any PR code ran. Coverage Gate then failed closed, which is what turns PR Readiness red. Fast Gate and all four AI reviews passed on c4e1003.

@bolichen97 bolichen97 closed this Nov 11, 2026
@bolichen97 bolichen97 reopened this Nov 11, 2026
@bolichen97 bolichen97 closed this Nov 11, 2026
@bolichen97 bolichen97 reopened this Nov 11, 2026
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.
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 11, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 11, 2026 04:38

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@KiroCrewCaptain
KiroCrewCaptain merged commit a2724bf into kirodotdev:main Nov 11, 2026
101 of 105 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 11, 2026

@bolichen97 bolichen97 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.

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

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

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants