Skip to content

feat(bots): run grok bots over acp and remove the direct runtime - #104

Merged
nixuuu merged 1 commit into
feat/bots-harness-1from
feat/bots-harness-2
Nov 4, 2026
Merged

nixuuu merged 1 commit into
feat/bots-harness-1from
feat/bots-harness-2

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 4, 2026

Copy link
Copy Markdown
Member

Stage 2 of bots on official harnesses (on top of #97).

  • Grok bots run through the Grok CLI over our ACP adapter as hidden, resumable sessions (session/load), isolated home per bot, every built-in tool/permission denied, Canopy bot tools via MCP through the bus — same guarantees as Claude/Codex (durability, offline queue, cancel/retry, transcript rebuild).
  • Direct runtime removed: apps/gateway/src/bots/model.ts and everything only it used (direct HTTP model calls, chat-completions mapping, completion caps, endpoint-key decryption for bots) are gone, with the old variant-B paths, the "bots need an endpoint/proxy instance" copy and their tests. Existing bots migrate to harness turns on a worker picked by the stage-1 rule; bots without an eligible worker show a clear state.
  • Guard: a test fails CI if a direct LLM endpoint call (/v1/messages, /v1/responses, /chat/completions, provider HTTP SDK clients) is reintroduced outside fixtures. Repo audit: none left.
  • The stack was rebased onto dev (incl. fix(worker): generate grok titles through the grok cli #101); stage 1's migration is now 0070_bot_harness.

Checks: install, gen:check, typecheck, lint, format:check, check:tmp (1086 pass, 154 skip, 0 fail), web build; 22 gateway↔worker integration tests for Grok bot turns, migration of an old-runtime bot and the guard. Browser checked Grok bot creation/conversation and the updated copy in light/dark at desktop and phone widths. Paid live tests opt-in, not run.

Draft until the stack is done.

@nixuuu
nixuuu added this pull request to stack #105 November 4, 2026 21:14
@nixuuu
nixuuu force-pushed the feat/bots-harness-2 branch from 3fe630a to c66ad0b Compare November 4, 2026 21:49
@nixuuu
nixuuu force-pushed the feat/bots-harness-2 branch from c66ad0b to ab4e474 Compare November 4, 2026 23:06
@nixuuu
nixuuu marked this pull request as ready for review November 4, 2026 23:12
@nixuuu
nixuuu force-pushed the feat/bots-harness-2 branch from ab4e474 to d78e6b1 Compare November 4, 2026 23:26
@nixuuu
nixuuu merged commit 7a7d4f2 into dev Nov 4, 2026
18 of 23 checks passed
@nixuuu
nixuuu deleted the feat/bots-harness-2 branch November 4, 2026 23:33
nixuuu added a commit that referenced this pull request Nov 4, 2026
)

Stage 3 (final) of bots on official harnesses, on top of #104.

- **Errors:** harness failures in bot turns (Claude SDK, Codex
app-server, Grok ACP: not signed in / expired login, missing CLI, model
not found, usage limit, proxy/endpoint, network, process exit, cut-off
stream, worker offline, pinned worker without the bot's instance) map
onto the shared reply error classes from #94, with actions in the bot
conversation: sign in on that worker, open provider settings, change
model, pick another worker ("Runs on"), retry, show details. Reuses the
thread turn error codes.
- **Runtime switch finished:** regression pass over routines/schedules,
handoffs, wakeups, connectors through the bus, create-bot, approvals,
multi-bot mentions and bot settings. Fixed: Grok `create_bot`, Claude
assistant errors, Codex startup recovery.
- **Runs on:** defaults confirmed (desktop local mode → its own worker;
server → first eligible worker) with guidance when no worker has the
bot's provider.
- Migration `0071`, docs updated.

Checks: install, gen:check, typecheck, lint, format:check, check:tmp
(1106 pass, 154 skip, 0 fail), web build; merges cleanly into current
dev. Paid live tests and native shells not run; the mobile app keeps its
generic failure bubble.

Draft until the stack merges.
nixuuu added a commit that referenced this pull request Nov 9, 2026
Codex bots could refuse Canopy tools with “approval policy is never”
before the request reached the gateway. Allow Canopy's authenticated MCP
transport at the harness level so the gateway can enforce bot approvals,
protected actions, standing rules and connector grants.

## Changes and cause

- Set `default_tools_approval_mode = "approve"` only on Codex bots'
Canopy MCP server, on both start and resume. Unannotated MCP tools
otherwise default to native approval, which Codex's internal `never`
policy refuses. Keep native `never`, the read-only sandbox, disabled
sandbox networking and the bot tool catalog unchanged.
- Add Grok's `MCPTool(canopy__*)` allow rule for bots and ordinary
threads. Its `ask` mode otherwise routes MCP permission requests through
ACP, where bot callbacks deny native permissions. Other MCP servers,
native tools and text-only generation keep their existing checks.
- Keep Claude's existing explicit Canopy tool allowlist.
`CLAUDE_SDK_CAN_USE_TOOL_SHADOWED` is expected for these tools: the
allowlist bypasses the SDK prompt, while the gateway still authorizes
execution.
- Turn native Canopy MCP refusals into actionable bot failures,
including Codex/Claude harnesses that subsequently report completion.
Use the same approval labels in the bot context and create-bot card as
in settings. Gateway validation accepts `safe`, `always`, `full_auto`,
defaulting empty values to `safe`; there is no bot `never` option.

The Codex refusal was reproduced with the installed official Codex
0.164.0 app-server, a local scripted Responses endpoint and the real
HTTP MCP transport. Removing the approval override makes that regression
fail; restoring it executes the gateway callback. Upstream
`request_mcp_tool_user_approval` confirms the native refusal and
`AppToolApproval::Approve` bypass. Ordinary Codex threads use
`dynamicTools`; a real app-server regression verifies `ask_user`,
`spawn_thread` and `send_message` in full auto.

No proto, migration or gateway authorization change. Documentation now
describes the harness/gateway approval boundary in Polish.

## Validation

- Gateway↔worker integration covers all 3 providers × all 3 bot approval
policies: protected `create_bot` has no effect before approval, then
creates a bot owned by the caller. Each provider also starts a full-auto
thread without a card. Native Codex/Claude denial fixtures verify
actionable failures, even after a completed harness turn.
- Focused bot harness, harness-error, approval-rule, isolation and Codex
adapter/permission tests passed. Isolation checks use the installed
Claude, Codex and Grok CLIs. Grok approval routing is covered with a
controlled ACP fixture and generated config; no paid live inference was
run.
- `bun install --frozen-lockfile`, `bun run typecheck`, `bun run lint`,
`bun run format:check`, `bun run gen:check` and the web build passed.
The changed packages and integration tests were typechecked again after
the final edits.
- Full local `check:tmp` intentionally omitted on the shared machine as
requested; CI remains the full-suite gate. No UI tests or browser/E2E
run.

## Copy audit — docs/copy.md §8

- `Approval policy: safe` → `Ask for approval: For actions that need
care` (and the corresponding shared labels for other policies). The card
and bot context now match the actual settings.
- Native refusal prose → “The agent CLI blocked this Canopy tool before
approval. Update the worker, then retry.” States the failure and the
recovery action without suggesting a nonexistent bot setting. Native
diagnostics remain sanitized.
- New user-facing copy uses English, sentence case, the glossary and
short sentences. No buttons, empty states, layout changes, color-only
cues or “soul” copy. Width/name checks are not applicable to the
unchanged layout; browser checks were not run.

Fixes: #97
Fixes: #104
nixuuu added a commit that referenced this pull request Nov 10, 2026
When a bot is replying, Stop now occupies the send button on web/desktop
and mobile, including while the next message is being drafted. It
retains the received partial reply with “Stopped by you”, interrupts the
worker harness, and accepts the next message immediately.

The RPC and linked-home routing already existed. The web control lived
in the header, and mobile hid Stop as soon as the draft contained text.
Gateway interruption changed the logical turn without atomically
persisting worker cancellation or retaining its streamed text. Worker
ACK could precede harness shutdown; Claude's SDK abort returns before
process exit, and Grok's ACP cancellation can leave a blocked prompt
alive.

## Behavior and durability

- Stop affects one current visible reply, including a reply waiting for
a worker or approval. With no running visible reply, it stops the oldest
queued visible message. Other queued messages, future routines and
reminders remain. Hidden routines are affected only when waiting for a
visible approval/question.
- One owner-scoped transaction saves the partial answer, marks the turn
and harness interrupted, expires that turn's pending cards, invalidates
its lease, and persists cancellation in the worker outbox. Late output
is acknowledged without changing the saved reply or authorizing tools.
- Cancellation survives gateway disconnection/restart. Worker admission
honors cancellation that overtakes a replayed run. ACK waits for harness
shutdown; the next reply waits for that ACK, avoiding BUSY races. Claude
uses the existing process-tree spawn hook, Codex retains scoped
app-server teardown, and Grok disposes its isolated ACP process on
abort.
- Existing `RunBotTurn`/`InterruptBotTurn` and `bot_harness_v1` remain
the compatibility boundary. No proto, migration or native mobile
changes. Stop cannot undo effects completed before cancellation.

Mobile coordination: the only shared thread-composer change is an
optional `stopWhileRunning` prop in `ComposerBox.tsx`, defaulting to
false. Bot composer wiring opts in; the thread composer keeps its
existing behavior. Please preserve this prop when combining the separate
mobile thread-composer work.

## Validation

- Regression reproduced against the original gateway interruption: the
expected partial answer and stopped marker were absent.
`bots-stop.test.ts`: 6 pass covering Claude/Codex/Grok, process exit,
immediate next input, queued input, late replay, owner scoping, offline
cancellation and gateway/worker restart.
- `bots-harness.test.ts`: 24 pass; Claude round-trip/approval tests
rerun after the process teardown change: 2 pass.
`bot-adapters-stop.test.ts`: 3 pass with blocked fake CLIs, process exit
before resolution and already-aborted admission. Worker journal tests:
10 pass, including cancellation before admission across reopen.
- Linked-home Stop test: 1 pass; existing questions/restart/interrupt
test: 1 pass. Multi-gateway files ran separately. Only fake provider
harnesses were used for the new coverage; no UI test suites were added.
- `bun install`, `bun run typecheck`, `bun run lint`, `bun run
format:check`, `bun run gen:check`, and `bun run --filter @canopy/web
build` passed. Full local `check:tmp` intentionally omitted per task; CI
is the full-suite gate.
- Real browser: light/dark at 1280×800 and 390×844, short/typical/long
bot names, empty/nonempty drafts, reachable Stop, stopped marker,
preserved draft and restored Send. The private fixture waits for an
eligible worker; provider shutdown is verified by integration/adapter
tests.

Production fingerprints generated using `bunx [email protected]
fingerprint:generate --platform <ios|android> --build-profile production
--json --non-interactive` match current dev (`9355f128`) exactly:

| Platform | dev and branch hash |
| --- | --- |
| iOS | `6ddec9ef559ee0095ac33e94ff9418a942053b17` |
| Android | `5f6eae3ab278f1cd543e9ed763f923a319b65ec9` |

## Copy audit — docs/copy.md §8

| Before | After | Reason |
| --- | --- | --- |
| Header “Stop”; mobile Stop hidden with a draft | Composer control
labelled “Stop reply” on web; existing mobile “Stop” | Verb-led,
accessible action in the send position, always reachable during a reply.
|
| No durable stopped note/partial answer | “Stopped by you” following
the retained partial answer | Names the completed action and its actor
without a failure message. |
| “Could not stop the bot” / mobile “Could not stop the bot. Check the
connection and retry.” | “Could not stop the reply. Check the connection
and retry.” | States what failed and one recovery action; consistent
across clients. |

Audit passed: sentence case, concise existing glossary terms, no new
jargon, no repeated status fact or new empty state, no decorative
sentences. Labels are available to assistive technology and through the
existing tooltip/control text. Short, typical and long names were
checked at desktop and phone widths.

Related: #97
Related: #104
nixuuu added a commit that referenced this pull request Nov 21, 2026
Grant the Linux bot sandbox write access to the resolved session directory so ACP can open and resume turns outside the worker temporary directory.

Fixes: #104
nixuuu added a commit that referenced this pull request Nov 21, 2026
## Summary

Grok's Linux read-only sandbox follows the sessions symlink to Canopy's
durable storage. When that storage is outside the writable temporary
directory, ACP fails to open the bot session before reaching the model
endpoint.

The bot launcher adds the resolved session directory to a private
sandbox profile that extends `read-only`. It keeps the existing session
layout and allows a fresh CLI process to resume the same conversation.

Fixes: #104

## Verification

- Reproduced `Permission denied` with the official CLI and durable
storage outside the worker temporary directory. The regression test now
creates that layout and checks session creation, transcript recovery,
and resume.
- Six targeted Grok adapter tests passed through `check:tmp`. Lint for
the edited TypeScript files and `git diff --check` also passed.
- An isolated bot turn on Linux returned `OK` from `grok-4.7` through a
live CLIProxyAPI connection.
- The full gate runs in GitHub CI.
nixuuu added a commit that referenced this pull request Nov 21, 2026
## Change

Grok sends reasoning as separate ACP items. The gateway now uses each
item's type to keep reasoning out of the streamed and saved bot reply.
Codex bots can still stream text deltas before an item start.

The fix applies to replies processed by the updated gateway.

## Verification

- The new regression test reproduced the leak before the fix and passed
after it. It checks the live reply after the gateway records a reasoning
delta and checks the saved reply once the bot finishes.
- 32 integration tests passed across `bots-harness.test.ts` and
`bots-stop.test.ts`. The Grok regression passed again on the final diff.
- Lint, formatting and `git diff --check` passed for the edited files.
GitHub CI runs the full verification gate.

Fixes: #104
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.

1 participant