Skip to content

fix(config): coerce slack.allowed_users entries instead of dropping them - #18579

Merged
iamwhatever merged 1 commit into
mainfrom
fix/17841-allowed-users-coercion
Nov 4, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/17841-allowed-users-coercion

Conversation

@dodgeblaster

@dodgeblaster dodgeblaster commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: kirocrew config get slack.allowed_users (and the dashboard Slack settings view) shows the saved allowed-users list instead of an empty one.

Reading slack.allowed_users back returned [] even when config.json on disk held a valid entry. The save had persisted, so it looked like the save failed when it had not, and operators retried the save repeatedly chasing a value that was already stored. The sibling field slack.tracking_channels (same object-list shape) round-tripped fine, so this was specific to allowed_users.

Why it matters

An operator cannot confirm their Slack user ID was saved through config get or the dashboard, which erodes trust in the config commands and causes repeated no-op retries. The value is read-only broken (Slack delivery still works because the gateway reads the file directly), but a config read that silently discards a stored value is a correctness bug that misleads every operator who hits it.

Not a goal

  • Changing the canonical entry shape. {"slack_id": "U...", "name": "..."} stays the shape the allowlist writer persists and every reader looks up.
  • Touching any other channel's allowlist (WeCom, Telegram, etc.).

What changed (motivation → approach → change)

The load path built the Slack config by filtering allowed_users down to entries carrying a truthy slack_id key. The common near-miss — a user_id key (the shape in the bug report) — matched nothing and was dropped, so the loaded list was empty and config get printed []. tracking_channels never had this because it already ran through a _validate_tracking_channels helper that coerces near-miss shapes rather than dropping them.

The fix gives allowed_users a matching _validate_allowed_users helper in config/sections_slack.py (beside its sibling _validate_tracking_channels). It keeps a canonical {"slack_id": ...} entry unchanged, moves a lone user_id value under slack_id (keeping name and other keys) with one warning per coercion, and ignores anything else — a bare string, a non-dict, or an entry with no usable id. config/section_builders.py's _build_slack_config now calls it in place of the inline filter, and config/sections.py (the facade) re-exports the new helper so the builder imports it the same way it imports its sibling.

The kept slack_id must be a non-empty string: slack/gateway_runtime/orchestrator_init.py builds a set of these ids at startup ({u["slack_id"] for u in cfg.slack.allowed_users}), so a non-string id (a list or dict from a hand-edited config) would raise TypeError: unhashable type there. Requiring a string id turns a startup crash into a dropped bad entry.

Backwards compatibility

Breaking: a slack.allowed_users entry whose slack_id is a non-string value (a list or dict, only reachable by hand-editing config.json) is now dropped at load instead of being carried through. The old inline filter kept it because it only checked truthiness; the gateway then crashed building its id set. This is a deliberate, narrow tightening — not a pure superset of the old loader.

Everything a normal save produces is unaffected: a canonical string-slack_id entry loads exactly as before, and the user_id-key near-miss now loads (coerced) instead of being dropped, which is the bug fix.

Reader: slack/gateway_runtime/orchestrator_init.py (builds the set[str] of allowed ids at startup) is the reader whose crash this tightening prevents; it now only ever sees hashable string ids.

Tests

test/test_config_loader_coercion.py::TestSlackAllowedUsersLoad (11 cases) exercises the full KiroCrewConfig.load() path: canonical slack_id pass-through; the issue's user_id-key coercion (value moved to slack_id, other keys kept, slack_id ordered first); slack_id winning when both keys are present; an empty slack_id falling through to user_id; a non-string slack_id and a non-string user_id both dropped (the deliberate tightening); a bare string and other junk ignored; a to_dict() → load() round-trip; and the warning being emitted on coercion but not on a clean value. prove.py confirms the catch: reverting only the production change reddens the five coercion cases.

Proof: PROVEN test/test_config_loader_coercion.py::TestSlackAllowedUsersLoad::test_user_id_key_is_coerced_to_slack_id_not_dropped, test/test_config_loader_coercion.py::TestSlackAllowedUsersLoad::test_user_id_coercion_keeps_other_keys_and_orders_slack_id_first, test/test_config_loader_coercion.py::TestSlackAllowedUsersLoad::test_empty_slack_id_falls_through_to_user_id, test/test_config_loader_coercion.py::TestSlackAllowedUsersLoad::test_non_string_slack_id_is_dropped, test/test_config_loader_coercion.py::TestSlackAllowedUsersLoad::test_coerced_entry_survives_to_dict_round_trip (head ae0702ce8ef4)

Manual verification

N/A — unit coverage exercises the real load path end to end, which is exactly the surface config get reads through. The dashboard Slack settings view does not expose allowed_users (dashboard/messaging_api/slack_settings.py), so this fix has no dashboard surface.

Screenshots / video

Why no screenshot: backend-only change (config loader); no frontend or rendered surface is touched.

Sibling sweep

Sibling: src/kiro_crew/config/sections_slack.py -- not affected -- its _validate_tracking_channels already coerces near-miss shapes and warns (it is the pattern this fix copies), and its ids are never hashed into a set, so the non-string tightening does not apply. No other allowed_users-style object-list field uses a drop-on-filter load path, so the defect has no second site.

Pattern harvest

Rule candidate: review-prompt
Pattern: an object-list config field whose loader filters on one required key silently drops near-miss entries, so config get reads back [] while the file holds a value. A new list-of-object config field should coerce the common near-miss shapes (as the sibling tracking_channels does) and warn, rather than filter-and-drop — and when a downstream reader hashes a field value, the loader must enforce that the kept value is the type the reader requires, rather than leaving a crash for startup.

Related Issues

Closes #17841

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 9, 2026
@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from 9902c46 to 2737694 Compare October 9, 2026 19:59
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of f912db48a647fd483dc1c8970fffc6541ead19b7 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f912db4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f912db48a647fd483dc1c8970fffc6541ead19b7 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision f912db48a647fd483dc1c8970fffc6541ead19b7 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 Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f912db48a647fd483dc1c8970fffc6541ead19b7 — 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 user_id alias is a point patch for one guessed key; it can be deleted later, so it is a note rather than a blocker.

Notes

  • Item 2 — symptom-level: config get slack.allowed_users returns [] while config.json holds a valid list #17841's repro is config set slack.allowed_users '[{"user_id": ...}]'. The underlying problem is that config set stores a shape the loader then drops without saying so. The patch rescues only the user_id spelling. Any other near-miss key ({"id": ...}, a bare "U...") still reads back []. Meanwhile user_id becomes a second spelling that has to be honoured forever, for a field the schema calls "Ignored for access: Slack is owner-only" (sections_slack.py:22). Subtraction: delete the user_id branch of _validate_allowed_users and refuse that value at write time with the existing _refuse_emitted_elsewhere_value (cli_config.py:796). That function already refuses values the loader would otherwise rewrite.

What this change ships

Inventory (5 items) — 4 justified

Intent: let an operator read back the Slack allowed-users list they saved, instead of an empty list — FIX.

  1. config get slack.allowed_users shows a saved user_id entry instead of [] — justified
  2. user_id is now a permanent alternate key for the Slack id in config — symptom-level
  3. An entry whose slack_id is not a string is now dropped at load instead of crashing gateway boot (orchestrator_init.py:90) — justified
  4. Loading the config logs a warning when it rewrites a user_id entry — justified
  5. _validate_allowed_users is re-exported from the config.sections facade (one consumer) — justified

[FIRST-PRINCIPLES-REVIEWED] f912db4

Description read

[DESCRIPTION-READ] 7ef92f12fc21c6aee61f57426f0b733844082e6b2bf0383617aaa2d9f31ff17a

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 Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f912db48a647fd483dc1c8970fffc6541ead19b7 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the fix is in the loader where the entries were being dropped, it follows the existing tracking_channels helper, and coerced entries widen no admission because orchestrator_init.py admits only the owner.

Notes

  • Any later config save (to_dict() → write) will rewrite a hand-edited user_id entry as slack_id in config.json without saying so. That is harmless and probably wanted, but neither the ## Backwards compatibility section nor the coercion warning mentions it.

[DESIGN-REVIEWED] f912db4

Description read

[DESCRIPTION-READ] 758f25191e147a37be83f9f57e3e5acb0ad09524588a06c8f8e7b3d7cfb9a7cf

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 Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed f912db48a647fd483dc1c8970fffc6541ead19b7 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f912db4

Verdict parsed from the review's SHA-scoped output markers for commit f912db48a647fd483dc1c8970fffc6541ead19b7.

False positive or not applicable? A repository writer can comment:
/ai-review override fable f912db48a647fd483dc1c8970fffc6541ead19b7 false-positive: <reason, 20 to 500 characters>

@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch 2 times, most recently from 7ecb200 to 5d7d681 Compare October 9, 2026 20:41
@dodgeblaster

Copy link
Copy Markdown
Contributor Author
  • span=c2b062f89868 — Coercion admits unhashable IDs and crashes gateway startup: fixed in 5d7d681.

Legitimate: slack/gateway.py builds {u["slack_id"] for u in cfg.slack.allowed_users}, so a list/dict slack_id raises TypeError at startup. The validator now keeps an entry only when its resolved id is a non-empty str; non-string slack_id/user_id values are dropped. Test test_non_string_slack_id_is_dropped asserts the surviving ids are hashable.

@dodgeblaster

Copy link
Copy Markdown
Contributor Author
  • span=bd4b0fed318d — empty slack_id clobbers the renamed user_id value: fixed in 5d7d681.

Legitimate: an entry like {"slack_id": "", "user_id": "U..."} built renamed = {"slack_id": "U..."} then .update() copied the empty slack_id back over it, losing the id while still counting as coerced. The rename now excludes both user_id and slack_id from the carried-over keys, and the empty slack_id is treated as not-usable so the entry falls through to user_id. Test test_empty_slack_id_falls_through_to_user_id locks this in.

@dodgeblaster

Copy link
Copy Markdown
Contributor Author
  • span=3b12f6249458 — bare-string coercion not justified (no writer stores bare strings): fixed in 5d7d681.

Agreed. The reported defect is a user_id KEY, not a bare string, and the only write path (slack/allowlist.py persists {"slack_id": ...} dicts) never stores a bare string. The bare-string branch was scope beyond the bug; it is removed. The validator now coerces only a dict user_id key, which is the shape the issue reproduced.

@dodgeblaster

Copy link
Copy Markdown
Contributor Author
  • span=3640ce9225e5 — the "invalid entries ignored" warning rides along, not needed by the fix: fixed in 5d7d681.

Agreed. Pre-change, non-conforming entries were dropped with no log line, and the core fix (coerce a user_id key to slack_id) does not depend on warning about dropped junk. The rejected-entries warning is removed; only the one user_id auto-coercion warning remains, since that path changes a stored value and the operator should know.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 9, 2026
@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from 5d7d681 to ae31a8f Compare October 15, 2026 15:56
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Rebased onto fresh origin/main (37fa963dac) to clear the BLOCKED merge state — the branch was ~1117 commits behind. Rebase was clean (no conflicts; the config/sections.py additions didn't collide). New head ae31a8fc5d. Re-verified locally after the rebase: isort/black/flake8/mypy clean, all 11 TestSlackAllowedUsersLoad regression tests pass. Remaining draft; CI re-running.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 15, 2026
@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from ae31a8f to 55d53ba Compare October 16, 2026 05:19
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Rebased onto main to pull in #20902's acp census fix (0694e63), which updates the test_acp_bindings.py frozen inventory for the approval_withdrawable member and approve_tool's new withdraw_if signature. That was the only inherited-main red previously gating this PR. New head 55d53bae92; config-only diff unchanged. Still draft.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 16, 2026
@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from 724dd65 to 21065ea Compare October 26, 2026 16:59
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Thanks — the mismatch is real, and I've corrected the claims to match the code rather than changing the code (the behavior is the intended one).

Fixed at head 21065eaaba:

  • Bare-string coercion claim dropped. The PR body and commit message no longer say a bare U…/W… string is converted. The code does if not isinstance(entry, dict): continue, so a bare string (and any non-dict) is ignored — the body now says exactly that. test_junk_entries_are_ignored already asserts a bare string is dropped, so no test claims the phantom behavior.

  • "Strict superset" claim dropped. Backwards compatibility now states the honest tightening: a non-string slack_id (a list/dict only reachable by hand-editing config.json) that the old truthiness filter kept is now deliberately dropped. slack/gateway_runtime/orchestrator_init.py builds {u["slack_id"] for u in cfg.slack.allowed_users} at startup, so a non-string id would raise TypeError: unhashable type there — requiring a string id turns a startup crash into a dropped bad entry. The body carries this as a Breaking: line with the reader named, framed as a narrow tightening, not a superset. test_non_string_slack_id_is_dropped pins it.

The reproduced bug (#17841 — a user_id-key near-miss read back as []) is still fixed: that entry is coerced to {"slack_id": …} with a warning. prove.py confirms the tests catch it (reverting the production change reddens the five coercion cases).

Only the PR text and commit message changed — no code change, so the tree is identical to the head you reviewed. Over to you for a re-review.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 26, 2026
@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from 21065ea to defc23d Compare October 26, 2026 17:54
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Rebased onto main 046b7e1eb2 (picks up the current base; the PR is no longer conflicting). The diff is unchanged — config-only, 4 files — and the claim corrections from the previous head are preserved. CI re-running.

@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from defc23d to e9f3d87 Compare October 26, 2026 18:28
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Rebased onto main 20c46e97d9 to pick up #24482/#24485 (the merged full-scan-guard xfail fix), which clears the previously-inherited test_crew_log_fullscan_guard.py red. Diff unchanged — config-only, 4 files. CI re-running.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 26, 2026
@dodgeblaster
dodgeblaster force-pushed the fix/17841-allowed-users-coercion branch from e9f3d87 to f722c49 Compare October 30, 2026 04:04
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Rebased onto main 9cca4edf31 (head f722c499fb). Main-red #24514 (the two shard-4 test_telegram_dispatcher.py tests) is fixed on this base, so the shard-4 and Coverage Gate reds on the previous head were stale. The diff is the same 4 config files (+166/−3), still one commit. Locally, the 11 TestSlackAllowedUsersLoad tests and the full test_telegram_dispatcher.py suite (99) pass.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 30, 2026
buluoray
buluoray previously approved these changes Oct 30, 2026

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

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

Approve at f722c499fbe02ad3c6309c0be67f6a01067afdfb.

Both points of @bolichen97's change request (on 724dd65) are addressed on this head. The description no longer claims bare U… strings are converted, and test_junk_entries_are_ignored pins that they are ignored. The non-string slack_id drop is now stated as a deliberate tightening, with slack/gateway_runtime/orchestrator_init.py named as the reader whose set build it protects, and test_non_string_slack_id_is_dropped pins it. @bolichen97, please re-review when you can, since your review is what holds the merge.

Why it is worth merging: slack.allowed_users grants no access (Slack is owner-only), so coercing a user_id entry widens nothing. It only makes config get read back what was saved instead of [], using the same pattern as _validate_tracking_channels.

Please fix before the squash lands, since auto-merge is armed and the description becomes the commit body:

  • The Goal says the dashboard Slack settings view shows the list. It does not expose allowed_users at all (dashboard/messaging_api/slack_settings.py:102-105, recorded in messaging.md). Please drop that clause.

Minor:

  • config/sections_slack.py:297 and the comments at test/test_config_loader_coercion.py:193 and :232 say slack/gateway.py builds the id set; it is slack/gateway_runtime/orchestrator_init.py, as the description says.

What I ran on this head: test_config_loader_coercion.py passes (110 passed). Making _usable_id accept any truthy value reddens test_non_string_user_id_is_not_coerced and test_non_string_slack_id_is_dropped. Restoring the old inline filter in _build_slack_config reddens six tests, including test_user_id_key_is_coerced_to_slack_id_not_dropped and test_coerced_entry_survives_to_dict_round_trip. I did not run config get against a real config or start the Slack gateway. CI on this head: 77 pass, 16 skipped, 0 failing.

@iamwhatever

Copy link
Copy Markdown
Contributor

Holding: bolichen97's CHANGES_REQUESTED review (on 724dd65) is still active. A later approval does not clear it, so this needs bolichen97 to re-review or dismiss.

The code is sound. _validate_allowed_users keeps a non-empty string slack_id, moves a string user_id under slack_id, and drops everything else (

def _validate_allowed_users(raw: list) -> list[dict]:
"""Validate and coerce ``slack.allowed_users`` entries to the canonical shape.
The canonical entry is ``{"slack_id": "U...", "name": "..."}`` — the key the
allowlist writer persists and every reader looks up. ``slack/gateway.py`` builds
a ``set`` of these ids, so a non-string ``slack_id`` (a list or dict from a
hand-edited config) would raise ``TypeError: unhashable type`` at gateway
startup; the id must therefore be a non-empty string to be kept.
A ``user_id`` key with no usable ``slack_id`` is the common near-miss spelling.
Its value moves under ``slack_id`` rather than being dropped: a dropped entry
makes ``config get slack.allowed_users`` read back ``[]`` while the write
succeeded, which reads as a failed save. Coercion emits one warning.
Accepted:
- ``{"slack_id": "U...", ...}`` with a non-empty string ``slack_id`` — passed
through (``name`` and any extra keys kept)
- ``{"user_id": "U...", ...}`` whose ``slack_id`` is absent or unusable and whose
``user_id`` is a non-empty string — the ``user_id`` value becomes ``slack_id``,
with a warning; other keys except ``slack_id``/``user_id`` are kept
Any other entry is ignored.
"""
if not raw:
return []
def _usable_id(value: object) -> str | None:
return value if isinstance(value, str) and value else None
result: list[dict] = []
coerced = 0
for entry in raw:
if not isinstance(entry, dict):
continue
if _usable_id(entry.get("slack_id")) is not None:
result.append(entry)
continue
user_id = _usable_id(entry.get("user_id"))
if user_id is not None:
# Move the near-miss ``user_id`` value under ``slack_id``. Build a new
# dict so the original is untouched and the key order reads ``slack_id``
# first; drop the source ``user_id`` and any unusable ``slack_id`` so
# neither clobbers the resolved id.
renamed = {"slack_id": user_id}
renamed.update({k: v for k, v in entry.items() if k not in ("user_id", "slack_id")})
result.append(renamed)
coerced += 1
if coerced:
logger.warning(
'Config: slack.allowed_users has %d entry(ies) with a "user_id" key — '
'auto-coerced to {"slack_id": "..."} format. '
'Prefer: [{"slack_id": "U...", "name": "..."}]',
coerced,
)
return result
). Dropping non-string ids keeps the stale-prune set build in orchestrator_init.py from crashing (
self._owner_id = creds.get(CRED_OWNER_ID, "")
# Multi-user access is disabled — only owner is authorized.
# Prune stale allowed_users entries from config and warn.
stale = {u["slack_id"] for u in cfg.slack.allowed_users} - (
{self._owner_id} if self._owner_id else set()
)
if stale:
logger.warning(
"Pruning %d stale allowlist entries (multi-user disabled): %s",
len(stale),
stale,
)
self._allowed_users = {self._owner_id} if self._owner_id else set()
). The coercion widens no access: is_allowed_user admits only the owner (
def is_allowed_user(user_id: str) -> bool:
"""Check if user_id is the owner.
Multi-user access is disabled for security — only the owner
(KIROCREW_OWNER_ID) is authorized to interact via Slack.
"""
if not user_id:
return False
return is_owner(user_id)
), and cfg.slack.allowed_users feeds only the stale-prune log and the display-name fallback. Both points of the change request look addressed in the current description: the bare-string claim is gone, and the non-string drop is stated as Breaking: with its reader named. The 11 new tests drive KiroCrewConfig.load(), and the five coercion cases would fail on the old inline filter. GPT and Opus report no findings, Design and First Principles PASS, UX skipped. All checks on this head are green.

AI findings judged non-blocking:

  • First Principles: Goal says the dashboard Slack settings view shows the list. description wording only; the fix covers config get, the settings view hides the field on purpose (
    "app_token_preview": _mask_secret(app),
    "owner_id": owner,
    "command": slack.command,
    # allowed_users / open_channels are deliberately NOT exposed: the
    # runtime enforces owner-only access in this build (is_allowed_user
    # ignores both), so surfacing editors would create access rules
    # that are never honored. Re-add when multi-user Slack lands.
    )
  • First Principles: WeCom allowed_users is an unfixed drop-on-filter sibling. out of scope per Not a goal; no in-repo writer produces a near-miss WeCom key and nothing user-visible is lost (
    allowed_users=[
    u
    for u in _safe_list(section.get("allowed_users"))
    if isinstance(u, dict) and u.get("userid")
    ],
    allow_all_users=section.read("allow_all_users", _safe_bool),
    )
  • First Principles: replace the user_id rename with drop-and-warn to keep one spelling. design preference; the rename widens nothing because Slack admission is owner-only (
    def is_allowed_user(user_id: str) -> bool:
    """Check if user_id is the owner.
    Multi-user access is disabled for security — only the owner
    (KIROCREW_OWNER_ID) is authorized to interact via Slack.
    """
    if not user_id:
    return False
    return is_owner(user_id)
    )
  • Design: description says the gateway reads the file directly. description wording; readers of cfg.slack.allowed_users are only the stale-prune log and the display-name fallback (
    self._owner_id = creds.get(CRED_OWNER_ID, "")
    # Multi-user access is disabled — only owner is authorized.
    # Prune stale allowed_users entries from config and warn.
    stale = {u["slack_id"] for u in cfg.slack.allowed_users} - (
    {self._owner_id} if self._owner_id else set()
    )
    if stale:
    logger.warning(
    "Pruning %d stale allowlist entries (multi-user disabled): %s",
    len(stale),
    stale,
    )
    self._allowed_users = {self._owner_id} if self._owner_id else set()
    )

Optional before the squash, since the description becomes the commit body: drop the dashboard clause from the Goal, and change slack/gateway.py to slack/gateway_runtime/orchestrator_init.py in the docstring at

allowlist writer persists and every reader looks up. ``slack/gateway.py`` builds
.

To clear: bolichen97 re-reviews this head.

Reviewed head: f722c49

— crew-pr-reviewer (r136)

config get slack.allowed_users returned [] while config.json held a valid
list: the loader filtered allowed_users to entries with a truthy slack_id,
so a near-miss user_id key was dropped silently. The write looked
successful but read back empty, which reads as a failed save.

Add _validate_allowed_users, mirroring the sibling tracking_channels
validator: a canonical {slack_id, ...} entry passes through, a lone
user_id value is moved under slack_id with one warning, and anything else
(a bare string, a non-dict, an entry with no usable id) is ignored. The
kept slack_id must be a non-empty string: the gateway builds a set of
these ids at startup, so a non-string id would raise TypeError there. Wire
the helper into _build_slack_config and re-export it through the sections
facade.

Closes #17841
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

Addressed at head f912db48a6 (rebased onto current main, still one commit, same 4 files).

Reply to @buluoray's review (on f722c499fb):

  • Minor, wrong reader path: fixed. The docstring at config/sections_slack.py and the two test comments in test/test_config_loader_coercion.py now name slack/gateway_runtime/orchestrator_init.py (the stale = {u["slack_id"] for u in cfg.slack.allowed_users} set build at line 90), matching the description. Comment-only change; test_config_loader_coercion.py passes (117).
  • Dashboard clause: agreed the dashboard Slack settings view does not expose allowed_users (dashboard/messaging_api/slack_settings.py, the "allowed_users / open_channels are deliberately NOT exposed" comment). I corrected the one non-frozen place that repeated the claim (Manual verification now says the fix has no dashboard surface). The Goal line itself is in the PR's frozen Goal section, which I am leaving untouched; a maintainer can drop the "(and the dashboard Slack settings view)" parenthetical before the squash if wanted. The code makes no dashboard claim.

On @bolichen97's change request (on 724dd65e26): both points were answered in code and text on the following heads (see the reply above from 2026-10-26) and are unchanged here. Bare U…/W… strings are ignored (if not isinstance(entry, dict): continue), pinned by test_junk_entries_are_ignored; the non-string slack_id drop is described as a deliberate tightening and pinned by test_non_string_slack_id_is_dropped. @bolichen97, a re-review on this head would clear the remaining hold.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Nov 2, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at f912db4.

Blocker: @bolichen97's CHANGES_REQUESTED review (on 724dd65) is still the active review state. A later approval or comment does not clear it, so bolichen97 needs to re-review this head or dismiss the request. Both of its points look answered: the description no longer claims bare U…/W… strings are converted, and the non-string slack_id drop is stated as a Breaking: tightening with its reader named.

The code is sound. _validate_allowed_users keeps a non-empty string slack_id, moves a string user_id under slack_id, and drops everything else (

def _validate_allowed_users(raw: list) -> list[dict]:
"""Validate and coerce ``slack.allowed_users`` entries to the canonical shape.
The canonical entry is ``{"slack_id": "U...", "name": "..."}`` — the key the
allowlist writer persists and every reader looks up.
``slack/gateway_runtime/orchestrator_init.py`` builds a ``set`` of these ids, so a non-string ``slack_id`` (a list or dict from a
hand-edited config) would raise ``TypeError: unhashable type`` at gateway
startup; the id must therefore be a non-empty string to be kept.
A ``user_id`` key with no usable ``slack_id`` is the common near-miss spelling.
Its value moves under ``slack_id`` rather than being dropped: a dropped entry
makes ``config get slack.allowed_users`` read back ``[]`` while the write
succeeded, which reads as a failed save. Coercion emits one warning.
Accepted:
- ``{"slack_id": "U...", ...}`` with a non-empty string ``slack_id`` — passed
through (``name`` and any extra keys kept)
- ``{"user_id": "U...", ...}`` whose ``slack_id`` is absent or unusable and whose
``user_id`` is a non-empty string — the ``user_id`` value becomes ``slack_id``,
with a warning; other keys except ``slack_id``/``user_id`` are kept
Any other entry is ignored.
"""
if not raw:
return []
def _usable_id(value: object) -> str | None:
return value if isinstance(value, str) and value else None
result: list[dict] = []
coerced = 0
for entry in raw:
if not isinstance(entry, dict):
continue
if _usable_id(entry.get("slack_id")) is not None:
result.append(entry)
continue
user_id = _usable_id(entry.get("user_id"))
if user_id is not None:
# Move the near-miss ``user_id`` value under ``slack_id``. Build a new
# dict so the original is untouched and the key order reads ``slack_id``
# first; drop the source ``user_id`` and any unusable ``slack_id`` so
# neither clobbers the resolved id.
renamed = {"slack_id": user_id}
renamed.update({k: v for k, v in entry.items() if k not in ("user_id", "slack_id")})
result.append(renamed)
coerced += 1
if coerced:
logger.warning(
'Config: slack.allowed_users has %d entry(ies) with a "user_id" key — '
'auto-coerced to {"slack_id": "..."} format. '
'Prefer: [{"slack_id": "U...", "name": "..."}]',
coerced,
)
return result
). Dropping non-string ids keeps the stale-prune set build from crashing (
# Multi-user access is disabled — only owner is authorized.
# Prune stale allowed_users entries from config and warn.
stale = {u["slack_id"] for u in cfg.slack.allowed_users} - (
{self._owner_id} if self._owner_id else set()
)
if stale:
logger.warning(
"Pruning %d stale allowlist entries (multi-user disabled): %s",
len(stale),
stale,
)
self._allowed_users = {self._owner_id} if self._owner_id else set()
), and Slack admission stays owner-only (
def is_allowed_user(user_id: str) -> bool:
"""Check if user_id is the owner.
Multi-user access is disabled for security — only the owner
(KIROCREW_OWNER_ID) is authorized to interact via Slack.
"""
if not user_id:
return False
return is_owner(user_id)
). The reader-path comments now name orchestrator_init.py. All checks on this head are green; GPT and Opus report no findings, Design and First Principles PASS, UX skipped.

AI findings judged non-blocking:

  • First Principles: user_id becomes a permanent alias; refuse it at write time instead. Design preference; the rename grants nothing because admission is owner-only (
    def is_allowed_user(user_id: str) -> bool:
    """Check if user_id is the owner.
    Multi-user access is disabled for security — only the owner
    (KIROCREW_OWNER_ID) is authorized to interact via Slack.
    """
    if not user_id:
    return False
    return is_owner(user_id)
    )
  • Design: a later save rewrites a hand-edited user_id entry as slack_id without saying so. It rewrites to the canonical shape and the load already warns (
    if coerced:
    logger.warning(
    'Config: slack.allowed_users has %d entry(ies) with a "user_id" key — '
    'auto-coerced to {"slack_id": "..."} format. '
    'Prefer: [{"slack_id": "U...", "name": "..."}]',
    coerced,
    )
    )

Minor, not blocking: the frozen Goal still names the dashboard Slack settings view, which hides allowed_users on purpose (

# allowed_users / open_channels are deliberately NOT exposed: the
). The author has flagged it for a maintainer to trim before the squash.

To clear: bolichen97 approves or dismisses the change request. No PR code was run locally; this review read the diff, callers and CI.

— crew-pr-reviewer (r141)

@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 f912db4, which replaces my earlier change request. The claim mismatch I raised is fixed. The description no longer promises to convert bare U…/W… user-id strings, and it now lists the dropped non-string slack_id as a Breaking change, with the reason: orchestrator_init.py builds a set of these ids, so a list or dict id would crash gateway startup.

_validate_allowed_users checks typed fields and exact keys, with no regex. A canonical string slack_id entry passes through unchanged. A lone user_id is moved under slack_id with one warning. An empty slack_id falls through to user_id. Any other entry is ignored. TestSlackAllowedUsersLoad covers each case through the full load() path.

Readiness passed, and every check passes; each cancelled run has a newer pass. The Opus, GPT, First Principles and Design lanes report no blocking findings, and UX was skipped. The existing auto-merge stays as it is.

@iamwhatever
iamwhatever merged commit ec88bcb into main Nov 4, 2026
98 of 115 checks passed
@iamwhatever
iamwhatever deleted the fix/17841-allowed-users-coercion branch November 4, 2026 10:21
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.

config get slack.allowed_users returns [] while config.json holds a valid list

4 participants