Skip to content

feat(bots): a Bot's chat carries the tools of an app its owner ticked it for (preview) - #37813

Open
chenmingwei23 wants to merge 2 commits into
mainfrom
feat/bot-chat-app-tools-v2
Open

chenmingwei23 wants to merge 2 commits into
mainfrom
feat/bot-chat-app-tools-v2

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #32983 (merged; permissions.bots). Merge order: the decision PR #37812 first (docs only; its entry supersedes both the conductor clause of the 2026-11-04 entry, decided by @iamwhatever, and the stock-conductor clause of the 2026-11-02 entry, for this one case, and needs both decision owners to restate it), then this PR.

Problem / Motivation

Goal: a Bot the owner ticked for an app can use that app's tools from its own chat, behind a default-off feature preview.

A Bot's own chat runs on the shared kirocrew-mate-conductor spec, which mounts only the platform servers. #32983 lets an app see and wake the Bots the owner ticked for it, and explicitly leaves out the other half: giving that Bot the app's tools in its own chat. So when an app wakes a Bot, the Bot has no way to read what the app wants or to answer through the app. Its only route is a worker, which costs a second turn and puts the Bot's words in the worker instead of its own chat. The 2026-11-04 entry sends new abilities to workers on the reasoning that a conductor only analyzes and dispatches; #37812 answers why a Bot's own chat is the exception (it is where the owner talks to the Bot and where its memory lives) and needs @iamwhatever to agree.

Why it matters

An owner who ticks a Bot for an app expects that Bot to work with the app, from its own chat, with its own memory and project. Today the wake arrives, and the Bot can only say it cannot see the app's data. The owner has no way to fix that short of rebuilding the Bot outside the Bot system.

Not a goal

  • Waking the Bot when it is @-mentioned: that is the app's job through feat(app-sdk): let an app read and wake the Bots the owner gives it #32983's wake route; this PR adds no wake.
  • Offering a server that none of the app's own agents declares (a top-level declaration); left as a commented shortcut.
  • Changing anything for a Bot that is not ticked, a scope the owner did not approve, or any Bot while the preview is off.
  • Writing the shared conductor spec file: it is still written from source.

What changed (motivation -> approach -> change)

Symptom -> cause -> fix:

  • Symptom: a woken Bot cannot call the app's tools.
  • Cause: a Bot's chat spec is the shared conductor file, the same for every Bot, and nothing adds to it per Bot. A Bot's worker, by contrast, gets a spec built per session (session_mcp_crewmate._crewmate_worker_spec -> mate_worker.worker_session_spec).
  • Fix: build the Bot's chat spec per session the same way. _crewmate_conductor_spec sits next to _crewmate_worker_spec (array hosts), and the KAS projection calls the same seam. Both call bot_chat_app_tools.conductor_session_spec, which adds an app's server to THIS Bot's chat only while all of these hold:
    1. the default-off bot_chat_app_tools feature preview is on;
    2. the app is installed and enabled;
    3. the app offers the server in a new manifest key, contributes.botChatServers: [{agent, server}], naming a server one of its own agents declares;
    4. the owner approved the app's tools Bot scope;
    5. the owner ticked this Bot for the app.

This extends #32983's field. Points 4 and 5 reuse #32983's grant instead of adding a second switch: permissions.bots gains a third scope, "tools", next to read and wake. It is staged and explicit-only like the other two, so an install approves nothing and the owner approves it on the app's page. The design decision is recorded in #37812 (a docs/decisions entry that narrows the 2026-11-04 conductor clause and the 2026-11-02 stock-conductor clause); whether tools belongs in permissions.bots or in a field of its own is the open question for the #32983 author.

Details:

  • The entry is rebuilt from the app agent's rendered spec with launch keys only (template_mcp_additions.ENTRY_KEYS), so no trust key such as autoApprove reaches the Bot's chat, and mounted as <app>:<server> with KIROCREW_SESSION_LABEL set to the chat's session so the server knows which Bot is calling. A server switched off under its own name (spec, Kiro global settings or any Crew MCP store) does not mount; its switched-off tools stay off as disabledTools; a malformed disabledTools refuses the server. A platform server of the same name wins. Tool calls still follow the Bot's own approvals.
  • Limit: Kiro CLI. A Bot whose chat runs on the Kiro CLI harness gets no app tools: Kiro CLI reads the agent file off disk and has no per-session channel, the same reason a Bot's worker is refused there (ACP_BACKENDS_MATE_WORKER_KIT). Its chat says so once, at the cold start. The cold-start notice is queued via AUTOMATION_NOTICE_KIND so the Bot receives it as an inject row on its next turn and tells its owner -- not as a Crew notice row in the chat. This follows docs/decisions/2026-10-09-crewmate-chat-draws-messages-only.md: runtime notices for a crewmate chat are injected into the crewmate's next turn, not drawn as gateway rows in the chat.
  • A change reaches a live chat. Each Bot chat's agent process records the servers it was started with. The bot-grants PUT, enable (including approving a held-back scope), update, and a switch of the preview each call after_app_change, which compares every live Bot chat with that record and queues a no-replay discard or reload. Disable, uninstall and trust withdrawal are different: they call stop_app_bot_chat_servers before after_app_change, which calls discard_conversation immediately without skip_if_busy, stopping the Bot's current turn. A Bot mid-turn is interrupted. Trust revoke returns two distinct 409 codes: teardown_incomplete (the app's own runtime could not be fully stopped -- grant is left in place) and bot_chat_stop_incomplete (the app teardown succeeded but some Bot chats could not be stopped -- grant is already removed, retry the Bot stop). The UI surfaces stop failures on disable and uninstall. Only ordinary grant changes (ticking or unticking a Bot) still take effect at the next idle boundary via the queued fresh-start path. A Bot whose servers were added, or whose entries an app update changed, reloads in place. A reload skips a chat whose fresh start is already queued, so disable then enable never starts two agent processes on one chat.
  • The preview is read through edition_locks.feature_previews, so it is off on LTS whatever is stored. An offer names an agent by its file stem; the rendered spec is found under the name that agent declares (_register_agents files it under that name).
  • The module reaches the session-label constants through agent_sdk.agent_specs.stamp_session_label, so application code still imports nothing from the ACP layer.
  • Settings > Developer > Feature previews gets an "App tools in bot chats" row; the app page's "Bots this app can reach" list gets a line for tools. All 12 locales are updated.
  • Docs: docs/app-kit/manifest-reference.md (contributes.botChatServers, the tools scope) and docs/system-specs/modules/app-kit-platform.md.
  • No code or text says anything about a specific app.

Backwards compatibility

Compatible: tools is a new optional scope and contributes.botChatServers a new optional key; manifests and grants that work today parse and behave the same, and with the preview off (the default) no Bot chat spec changes.

Removes nothing: the diff only adds a scope, a manifest key, a preview flag, a per-session spec builder, and security teardown hooks; the shared conductor spec and every existing grant are untouched.

Tests

  • test/test_bot_chat_app_tools.py (57 tests), among them: mount with label; preview gate; scope gate; ticked-Bot gate; only the app's own agent's server is offered; an offer finds an agent by the name its spec declares; the preview reads off under the LTS lock; a platform server wins; the array-host projection carries it for the conductor and not for other agents; no trust key reaches a mounted entry; a server or tool switched off under its own name stays off; a malformed disabledTools refuses the server; a Bot chat on Kiro CLI mounts nothing and is told once; a change starts lost Bots fresh and reloads gained ones; a tick undone before its reload applied keeps the conversation; registry updates and trust revokes reach Bot chats; a Bot chat's Claude deny rules cover its mounted servers. The module docstring maps each guarantee to the one-line change that reddens it; the five added for review findings were each run that way and went red.
  • test/test_config_live_server_appliers.py: the new dashboard.bot_chat_app_tools applier is registered and scoped.
  • Also run, green: test_app_bot_grant_routes, test_app_bot_access, test_app_bot_disabled_token, test_feature_previews_config, test_apps_routes_coverage_enable_disable, test_apps_uninstall_keep_specific, test_app_update_local_trust_switch, test_app_update_market_source_route, test_config_baseline; vitest AppDetailBotGrants.test.tsx, previewFlagServerSync.test.tsx, settingsSearchGovernance.test.ts, previewSurfaces.test.tsx (its info-tip count goes from 15 to 16 for the new row).
  • Lint on the changed files: flake8, black, isort. i18n-check clean, tsc --noEmit clean. Settings registry, UI index and config baseline regenerated on the current main.

Proof: not provable -- other: feature PR; each guarantee was reddened by hand as listed in the test module docstring

Manual verification

Pod run, real model, an app that offers one server and declares permissions.bots: ["tools", "wake"], three Bots in three projects, preview on:

  1. On the app's page the owner approves the bot scopes and ticks one Bot.
  2. The owner @-mentions that Bot in a group; the app wakes it through feat(app-sdk): let an app read and wake the Bots the owner gives it #32983's wake route. About a minute later the Bot, from its own chat, takes the item, answers in the group and closes it with the app's tools.
  3. The owner unticks it. Asked in its own chat, the Bot says it has no such tools, and it does not remember the earlier request: the conversation started fresh.
  4. A Bot that is not ticked cannot be woken (404).

Only the array-host (Claude) path ran in the pod; the KAS projection is covered by unit tests only.

The Kiro CLI notice has no pod run and no screenshot: on this gateway a Bot cannot be pinned to kiro (PUT /api/agents/<bot> with acp_backend: "kiro" answers 400, "acp_backend must be one of: (empty), claude, codex, kas"), so a Bot chat cannot be put on Kiro CLI from the product. Tests are the evidence instead:

  • test_a_bot_chat_on_a_harness_without_its_spec_mounts_nothing_and_says_so asserts the chat gets exactly one row, ("system", _HARNESS_NOTICE, "msg msg-info"), whose text is "This bot's engine can't use app tools, so they're off in this chat. Switch the bot to Kiro Agent, Claude Code or Codex to use them."; that a second cold start does not repeat it; that _MOUNTED stays empty (no app tools mounted); that a harness which carries the spec, or a Bot with no ticked app, gets no notice.
  • test_every_bot_chat_cold_start_reports_its_harness_to_the_notice asserts the allocation path records the harness (note_harness_without_app_tools), and test_the_turn_that_claims_a_new_bot_chat_posts_its_owed_notice runs a real dashboard turn (test/turn_harness.py) on a newly claimed session and asserts the notice lands in the chat exactly once; removing the deliver_harness_notice call in turn_admission turns it red.

Screenshots / video

Narrated pod run (ticking a Bot, the Bot answering through the app's tools, unticking it):

Revocation race fences: why three layers

Three separate mechanisms guard a Bot chat's app-server entries against stale state; each one covers a gap the others cannot:

  1. Per-app generation (_APP_GENERATIONS + _PROJECTION_GENS) -- fences in-flight projections at the three delivery call-sites. revoke_app_generation(app) bumps only that app's counter; conductor_session_spec snapshots each app's counter per alias before reading the grant table; check_and_filter_projection compares alias-by-alias. This matters for the Codex harness: codex folds whitespace in server names, so the sidecar must store the original alias keyed against its app's counter to match the folded form at delivery -- a single global epoch cannot link a folded name back to its original to know whether it changed. test_a_server_codex_registers_under_a_folded_name_is_revoked_on_untick goes red if this layer is removed (codex delivers team_app:my_server but the sidecar stores team-app:my server; without per-alias matching the folded alias is passed through after revocation).

  2. Change epoch (_CHANGE_EPOCH + _PROJECTION_EPOCH) -- fences the record_mounted path that harnesses take when they hand the session directly (without going through check_and_filter_projection first). after_app_change bumps the epoch, not the per-app counter, so a concurrent tick or preview change detected at record time triggers a reconcile without staling other projections. test_an_untick_during_a_first_projection_is_reconciled_once_it_records goes red if this layer is removed.

  3. Re-projection set (_REPROJECT_SLUGS) -- prevents the reconcile from treating a generation-mismatch drop as "harness-withheld". When check_and_filter_projection drops an entry because its per-app counter advanced, it records the alias in _REPROJECT_SLUGS; record_mounted then excludes it from _UNMOUNTED. Without this, after_app_change sees the alias in withheld, filters it out of now, concludes now == was, and schedules no reload -- the tools never come back. test_gen_dropped_entries_are_recovered_by_reconcile goes red if this layer is removed.

  4. _HAD_SIDECAR -- guards re-deliveries on the harness paths that bypass conductor_session_spec. Harnesses like KAS and the AcpClient array can call check_and_filter_projection more than once on the same session (once for the main array, once for a re-seed). The first call pops the sidecar; _HAD_SIDECAR lets the second call pass through rather than fail-closed. test_every_harness_settles_the_record_after_its_own_withholding and test_the_array_resolver_settles_the_record_from_what_it_hands_the_session go red if this guard is removed.

Security teardown

Disable, uninstall and trust revoke call stop_app_bot_chat_servers before the grant change is recorded. This stops discard_conversation on each Bot chat that is running the app's servers immediately, without skip_if_busy, so the Bot's current turn is interrupted. Trust revoke uses two distinct 409 codes: teardown_incomplete when the app's own runtime could not be stopped (grant kept, trust not revoked); bot_chat_stop_incomplete when trust was successfully revoked but some Bot chats could not be stopped (grant removed, retry the Bot stop).

Reason: after trust is revoked, the app's code must not keep executing in any Bot chat -- even a chat that is mid-turn. This is a security requirement. Grant changes (ticking or unticking a Bot) still take effect on the next turn via the existing queued fresh-start path.

Why the three delivery call-sites check per-app revocation generation (check_and_filter_projection / _APP_GENERATIONS). A conductor_session_spec projection reads the grant table and builds the sidecar in one blocking step; revoke_app_generation bumps only that app's counter before the grant table changes. The three call-sites (AcpRuntime mirror, AcpClient array, KAS projection) each call check_and_filter_projection, which compares the sidecar snapshot against the current counter and strips any entry whose generation advanced -- so a session that read a stale grant before the revocation cannot mount the revoked server. Using a per-app counter means an unrelated tick or untick for a different app does not stale the in-flight projection's entries for the first app.

Why all Claude Bot chat arrays go through the seed-lag check. runtime_session_setup._mirrored_session_mcp now calls the shared check that KAS and codex already called: if the session's seed spec is not yet available (the KAS lag window), the entire MCP array is withheld and the session starts with no app servers. This keeps app code out of a chat that is still being configured. The check is offloaded to a thread so it does not block the event loop during a cold start.

Why immediately stopped Bot chats are not also queued for a deferred fresh start. stop_app_bot_chat_servers removes each successfully stopped session from _MOUNTED before returning. The after_app_change reconcile that follows iterates _MOUNTED; because the stopped slugs are gone, it does not also queue a fresh start on the same sessions. Only sessions that could not be stopped immediately remain in _MOUNTED, so those may still receive a deferred reconcile on their next idle boundary.

Manual verification

Screenshots of the stop-failure UI were taken in a pod running head 192bad9, with API responses stubbed via page.route to inject real failure payloads. The stubbed response body drives actual rendering; no DOM was modified.

  • test_stop_app_bot_chat_servers_stops_a_busy_session_immediately: verifies discard_conversation is called without skip_if_busy.
  • test_stop_app_bot_chat_servers_returns_failure_when_discard_raises: verifies a session that cannot be stopped is reported as failed (not swallowed), which is what causes the disable warning and trust-revoke 409.
  • test_failed_bot_stop_counts_as_incomplete_in_blanket_revoke: verifies the 409 path.

Related Issues

Builds on #32983. Decision record: #37812.

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

Contributed under the project's Apache-2.0 license.

Screenshots

All screenshots taken in pod kc-bot-chat-v2pod running head 192bad9, with API responses
stubbed via page.route to inject real failure payloads. No DOM was modified; the UI renders
the stubbed response.

Feature Previews page -- "App tools in bot chats" row, (i) hint expanded (pod, genuine rendering):

App tools in bot chats -- summary: "Lets apps you allow add their tools to a bot's chat. The bot still asks before using them." Hint expanded: "To undo, untick the bot on the app's page or turn off this preview." (pod, genuine rendering)

Trust revoke 409 -- trust removed, app row removed (No apps trusted yet.), Bot chat still running, Retry stop button (Security panel, pod, page.route stubbed):

Trust removed. The bot atlas is still running auto-research's tools. Restart Kiro Crew to stop this bot's chat. App row removed -- No apps trusted yet. Open System settings to restart Kiro Crew link + Retry stop button (pod, page.route stubbed)

App page "Bots this app can reach" -- tools scope line, preview-off hint (app detail, pod, page.route stubbed):

Bots this app can reach -- tools scope: "Lets a bot you tick for this app use its tools in its own chat. Other bots don't change." Preview off: "Off until you turn on App tools in bot chats." (pod, page.route stubbed)

Uninstall warning -- bot chats still running after uninstall, app card removed (Library page, pod, page.route stubbed):

The bot atlas is still running with Auto Research's tools. It will not get new tools from it. Open System settings to restart Kiro Crew. (Library page, pod, page.route stubbed)

Disable warning -- not every step finished after disable, app card moved to Disabled section (Library page, pod, page.route stubbed):

Auto Research is disabled, but not every step finished. Details: atlas could not be stopped (Library page, pod, page.route stubbed)

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

UX-Verdict: PASS

Nothing blocks: the blind reader understood both primary controls, and every new notice and state appears in a screenshot.

Notes

  • SecurityPanelTrust.tsx passes the app slug as name to bot_chat_stop_incomplete_revoked_*, so shot-01 reads "auto-research's tools" while the Library shows "Auto Research". The reader asked "Is that the same app?" Pass appDisplayName instead.
  • The disable warning in shot-04 ("…Details: atlas could not be stopped") offers no restart link and no Retry stop, while the uninstall and trust-removal notices both do. Add the same restart_gateway_link action on disable. The backend text should also say "bot atlas".
  • In shot-05, the hint popover for bot_chat_app_tools_desc covers the label of the ACP runtime sharing row above it. That hint ("To undo, untick the bot…") is the only way to learn how to undo, so show it inline under the description.

[UX-REVIEWED] ccb39f9

Description read

[DESCRIPTION-READ] 6e2abea5431e45f2f175b1e4695644ead3bea9e42dbaee2e799541b41664afc1

That sha256 names everything this verdict read: the PR description, plus the 8 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 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the feature is a default-off preview, so the design can still be walked back. The revocation machinery is the long-term risk.

Notes

  • Revocation depends on about 20 process-global dicts in bot_chat_app_tools.py (_MOUNTED, _PENDING_CLOSE_APPS, _PROJECTION_GENS, _REVOCATION_FENCE, _FENCE_HOLD_COUNTS, and more). security_trusted_apps.py reads them directly as private globals to decide teardown. Every fence or hold-count branch added to the trust handler is a new place where a revoke can leave a Bot holding an app's tools. Put a single bot_chat_app_tools.affected_apps() / revoke(name) API behind those globals, so the security handler stops encoding the module's internal state machine.
  • This PR adds behaviour that 2026-11-04-conductors-stay-simple-and-new-abilities-go-to-workers.md currently forbids, and the superseding entry (docs(decisions): propose that a Bot's chat carries the app tools its owner ticked it for #37812) is not in the tree. It needs that entry to merge first, as the stated merge order says.
  • bot_chat_app_tools.py is a new 1,716-line module holding several jobs: mount projection, the pending-close retry/backoff drain, the harness notice, and the revoke fence. Split out the close/fence lifecycle now, before more review rounds are added to it.

[DESIGN-REVIEWED] ccb39f9

Description read

[DESCRIPTION-READ] 12fe8dd160bd2023f3408859105cae7c24635ede2f42f834d01291413b4fa89d

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 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ccb39f97b0b556b23d587418019fa508dac62153 — 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

The one premise risk is merge order: this reverses a recorded conductor decision whose superseding entry is not on base yet.

Notes

What this change ships

Inventory (10 items) — 9 justified

Intent: let a Bot that its owner ticked for an app use that app's tools from its own chat, behind a preview. ADDITION.

  1. New Settings › Feature previews row "App tools in bot chats", default off — justified
  2. Apps can offer a server to Bot chats through the contributes.botChatServers manifest key — justified
  3. New tools Bot scope, approved on the app page, with a new line in "Bots this app can reach" — justified
  4. A ticked Bot's own chat mounts the app's server, built per session on array hosts and KAS — inherited (decision not yet on base)
  5. A Bot on Kiro CLI gets a one-time cold-start notice that app tools are unavailable — justified
  6. Ticking or unticking a Bot, enable and update now reload or discard live Bot chats at the next idle point — justified
  7. Disable, uninstall and trust withdrawal now interrupt a Bot's current turn immediately — justified
  8. Trust revoke returns a new 409 code, bot_chat_stop_incomplete — justified
  9. Disable and uninstall now show Bot-chat stop failures in the UI — justified
  10. Seed-lag re-projection is marked for Bot chats and the check runs off the event loop — justified

[FIRST-PRINCIPLES-REVIEWED] ccb39f9

Description read

[DESCRIPTION-READ] 8d7b0c684c1a87c928c699c17dc9a1b63ee8858fa13ae85bee61ab87f6961a68

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 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging ccb39f97b0b556b23d587418019fa508dac62153. 3 of 4 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/acp/runtime_session_setup.py:875 -- Provisional mount records let revoked app code start

record_mounted, session_key, mounted_names(servers_dict), spelled
Trigger: A Bot cold-start records its projected servers, then waits at create_session’s admission gate while the owner revokes the app’s trust. stop_app_bot_chat_servers finds the mount, but discard_conversation finds no registered session and returns success.
Outcome: Revocation clears the mount record, yet the queued session/new subsequently launches the revoked server. Allocation invalidation rejects later registration; it does not prevent the server’s startup code from executing.
Anchor: residual/security
Fix: Track and cancel in-flight starts through actual session establishment, and confirm their termination before reporting successful revocation.
Sites: src/kiro_crew/acp/client_mcp_array.py:504; src/kiro_crew/acp/harness/kas.py:1506; src/kiro_crew/bot_chat_app_tools.py:1603.

BLOCKING -- src/kiro_crew/bot_chat_app_tools.py:419 -- A pending close exempts other Bots from an actively held revocation fence

not any(a == alias.split(":")[0] for _, a in _PENDING_CLOSE_APPS)
or (slug, alias.split(":")[0]) in _PENDING_CLOSE_APPS
Trigger: Bot A has an unconfirmed close for an app. During individual trust withdrawal, Bot B cold-starts after the stop snapshot but before app teardown disables the app; its fresh generation and current grant pass delivery.
Outcome: Bot A’s pending-close entry makes this predicate exempt Bot B even while _FENCE_HOLD_COUNTS holds the fence. Bot B mounts outside the stop snapshot and continues executing after trust removal until a separate cleanup runs.
Anchor: residual/security
Fix: Permit the other-Bot exemption only when pending closes alone retain the fence, never during an active revocation operation.
Sites: src/kiro_crew/bot_chat_app_tools.py:1531; src/kiro_crew/dashboard/handlers/security_trusted_apps.py:789.

BLOCKING -- src/kiro_crew/bot_chat_app_tools.py:730 -- Withheld-server fingerprints cause unnecessary Bot reloads

fp_entry = {k: v for k, v in entry.items() if k != "x-kirocrew-session-label"}
Trigger: A shared-KAS close remains unconfirmed and the Bot cold-starts without the still-enabled, granted app server. Delivery saves this fingerprint; an unrelated app change subsequently calls after_app_change.
Outcome: stamp_session_label already changed the entry’s environment and removed its marker, so stripping that marker cannot recover the original offer fingerprint. Reconciliation treats the unchanged, withheld server as an addition, restarting the Bot and posting reload notices again after subsequent app changes.
Anchor: defect
Fix: Save the original offer fingerprint from the projection rather than reconstructing it from a stamped or harness-translated delivery entry.
Sites: src/kiro_crew/bot_chat_app_tools.py:1333; translated deliveries at src/kiro_crew/acp/client_mcp_array.py:500 and src/kiro_crew/acp/runtime_session_setup.py:872.

BLOCKING -- src/kiro_crew/bot_chat_app_tools.py:863 -- App-server mounts reverse the recorded conductor boundary

mounted[alias] = stamp_session_label(entry, label)
Trigger: With the preview enabled, an installed app offers a server, its tools scope is approved, and the owner ticks the Bot; the conductor projection reaches this assignment.
Outcome: The Bot’s conductor mounts a non-platform MCP server, reversing the behavior recorded in docs/decisions/2026-11-04-conductors-stay-simple-and-new-abilities-go-to-workers.md. This head contains no superseding decision authorizing the exception.
Anchor: recorded-decisions-are-not-regressions
Fix: Land the dedicated, maintainer-approved superseding decision before this implementation.
Sites: src/kiro_crew/acp/session_mcp_crewmate.py:82; src/kiro_crew/acp/harness/kas.py:1356.

[BLOCK-MERGE] ccb39f9
[GPT-REVIEWED] ccb39f9

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F3 — MEDIUM/LOW. The fingerprint is built from an entry that has already been changed. stamp_session_label (src/kiro_crew/agent_sdk/agent_specs.py:308-310) removes the marker and adds KIROCREW_SESSION_LABEL to env. It runs before delivery (src/kiro_crew/bot_chat_app_tools.py:863), and the strip at :730 only removes the marker key, so the saved fingerprint is not the original offer's. after_app_change compares it with the unstamped bot_servers entry (:1313, :1337); the values never match, so :1344 treats the server as an addition. The Bot then reloads spuriously on every app change while the close stays pending. It is visible, and it stops once _drain_pending_close confirms the close (:1306).
The fix is cheap: save the unstamped offer fingerprint in a new map next to _PROJECTION_GENS (:861) when conductor_session_spec builds the projection, and read it at :730. The defect is in code this PR adds to stop exactly this reload loop, so the fix does not cost more than the harm.

[ADJUDICATION] ccb39f9 total=1 uphold=1 downgrade=0
UPHOLD F3 src/kiro_crew/bot_chat_app_tools.py:730 reason=harm-warrants-remedy
[GPT-ADJUDICATED] ccb39f9

[ADJUDICATION-FENCED] ccb39f9 fenced=3 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/acp/runtime_session_setup.py:875 -- A revocation that lands while a cold start waits at the admission gate is an ordinary timing combination, and running a revoked app's code is a governance-ceiling harm; I could not complete a rarity record.
UPHOLD-FENCED F2 src/kiro_crew/bot_chat_app_tools.py:419 -- A pending close only needs one unconfirmed close for the app, and another Bot cold-starting during trust withdrawal is plausible; the exemption weakens an active revocation fence, so there is no case for FLAG.
UPHOLD-FENCED F4 src/kiro_crew/bot_chat_app_tools.py:863 -- This assignment runs on the normal path (preview on, scope approved, Bot ticked), not an extreme one, so the rarity argument a FLAG needs does not exist.
[GPT-ADJUDICATED-FENCED] ccb39f9

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

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — 🔴 changes requested (blocking)

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

A trust revoke that raises after it takes the Bot revocation-fence hold never gives the hold back. The app then stays fenced out of every Bot chat until the gateway restarts, and granting trust again does not fix it.

BLOCKING — src/kiro_crew/dashboard/handlers/security_trusted_apps.py:795

_bot_stopped, _bot_failed = await bot_chat_app_tools.stop_app_bot_chat_servers(
    request.app.get("state"), name, hold_fence=True

Trigger: stop_app_bot_chat_servers(hold_fence=True) adds one to _FENCE_HOLD_COUNTS[name]. The only releases are _revocation_fence_clear(name, release_hold=True) on the teardown_incomplete return, the ConfigCorruptError and TrustSettingOverlayOwned handlers, and the final line; there is no try/finally around them. Anything else that propagates skips all four. One case: _mutate_agent_config → update_config_locked raises PendingEditBlocksSave (a ConfigWriteRefused) or OSError on the lock. The handler's own comment calls the preflight "not a guarantee": a hand edit of config.json that lands while Bot chats and the app runtime are being stopped gets past it.
Outcome: The request returns a 500 and the app is still trusted. _FENCE_HOLD_COUNTS[name] stays at 1 or more, so every later _revocation_fence_clear(name) returns early. A retried revoke adds one hold and releases one, so the count never reaches zero. _REVOCATION_FENCE keeps the app, record_mounted puts it in fenced_apps for every Bot, and every harness strips the app's tools from each Bot chat cold start until restart, even after trust is granted again.
Anchor: defect
Fix: Put everything from the hold_fence=True stop through the trust write in one try/finally that calls _revocation_fence_clear(name, release_hold=True) exactly once, and remove the separate per-branch release calls.

Notes:

  • stop_app_bot_chat_servers can list the same slug twice in failed: once from the pending-close pre-scan, and again from the _PENDING_CLOSE.get((slug, app_name)) branch for a slug that is still in _MOUNTED. The duplicate shows up in the 409 bots list and its error text.
  • bot_chat_app_tools.py is a new 1,716-line file, over the 1,600-line working target in keep-modules-small (that rule is non-blocking).

[BLOCK-MERGE] ccb39f9
[OPUS-REVIEWED] ccb39f9

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

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

@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 Nov 16, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch from 67e17c5 to 9085b1e Compare November 16, 2026 04:58
@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 Nov 16, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

The Opus 5.5 BLOCK (recorded-decisions-are-not-regressions, against the 2026-11-04 conductors-stay-simple entry) is handled in #37812, which now supersedes that entry for this one case and asks its decider to restate it. This PR waits for #37812 to merge, then rebases onto main. No code change here for that finding.

@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch from 9085b1e to ce3d5e1 Compare November 16, 2026 05:12
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 16, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch 3 times, most recently from 0026cc3 to 9d7e43e Compare November 16, 2026 05:45
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 16, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch 5 times, most recently from 4e452c3 to 9ad75a9 Compare November 16, 2026 08:44
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 16, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch from 9ad75a9 to d21ab47 Compare November 16, 2026 09:07
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 16, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch 4 times, most recently from 3c18c30 to 0cf88f1 Compare November 16, 2026 18:32
@github-actions github-actions Bot added 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: checking Automated validation is still running labels Nov 16, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch from 0cf88f1 to dc9f262 Compare November 17, 2026 04:09
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch from 49fd035 to d9e1d21 Compare November 17, 2026 06:02
@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 Nov 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch 9 times, most recently from 6073966 to b488128 Compare November 17, 2026 08:34
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 17, 2026
@chenmingwei23
chenmingwei23 force-pushed the feat/bot-chat-app-tools-v2 branch from b488128 to 5bf9427 Compare November 17, 2026 08:37
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Item 5 (the BLOCK) is addressed: the ## What changed section now says disable, uninstall and trust withdrawal stop Bot chats mid-turn via stop_app_bot_chat_servers, contrasting with ordinary grant changes that queue a fresh start. The description no longer says the queued path covers all withdrawals.

Item 7 is addressed: take_owner_notes is deleted. No production code called it; the stash confirms the two prompt_assembly.py call sites were already removed in a prior push. The function is gone from bot_chat_app_tools.py in this push.

Item 6 (noted, not a BLOCK): the three fence layers are retained with justification added in a new ## Revocation race fences: why three layers section. Each layer covers a gap the others cannot:

  • _APP_GENERATIONS + _PROJECTION_GENS: Codex folds whitespace in server names (my server -> my_server). The sidecar stores the original alias against its per-app counter; check_and_filter_projection uses that alias to match the folded form at delivery. A single epoch cannot link a folded name back to its original to know which app it belongs to. Removing this layer causes test_a_server_codex_registers_under_a_folded_name_is_revoked_on_untick to fail.
  • _REPROJECT_SLUGS: without it, a generation-mismatch drop lands in _UNMOUNTED; after_app_change sees withheld.get(a) == f, filters the alias out of now, concludes now == was, and schedules no reload. test_gen_dropped_entries_are_recovered_by_reconcile goes red.
  • _HAD_SIDECAR: some harness paths call check_and_filter_projection more than once per session. The second call finds no sidecar (popped by the first) and would fail-closed, stripping platform-only arrays. test_the_array_resolver_settles_the_record_from_what_it_hands_the_session goes red.

All three layers are verified by tests that go red when each one is removed. They are not duplicates of each other.

This branch has not been deployed

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

Labels

readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants