-
Notifications
You must be signed in to change notification settings - Fork 7
bridge: rename slack-bridge to broker-gateway #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benvinegar
wants to merge
5
commits into
main
Choose a base branch
from
bridge/rename-to-broker-gateway
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
697fb82
bridge: rename slack-bridge to broker-gateway
benvinegar 8ada869
tests: fix c8 include path after broker-gateway rename
benvinegar 132fc8d
bridge: fix stale slack-bridge refs in CI smoke test and gitignore
benvinegar 9a08de3
ci: add gated inference smoke test with nightly workflow
benvinegar e3e3242
ci: run inference smoke on every PR with haiku
benvinegar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| #!/usr/bin/env bash | ||
| # Inference smoke-test for baudbot. | ||
| # | ||
| # Verifies that the control-agent can complete at least one real LLM turn | ||
| # end-to-end via session-control RPC. | ||
| # | ||
| # Requires CI_ANTHROPIC_API_KEY in the environment (injected into the | ||
| # agent's .env before starting baudbot). | ||
| # | ||
| # Expects baudbot to be already installed and stoppable via `sudo baudbot`. | ||
|
|
||
| set -Eeuo pipefail | ||
|
|
||
| readonly AGENT_USER="baudbot_agent" | ||
| readonly AGENT_HOME="/home/${AGENT_USER}" | ||
| readonly AGENT_ENV="${AGENT_HOME}/.config/.env" | ||
| readonly CONTROL_DIR="${AGENT_HOME}/.pi/session-control" | ||
| readonly CONTROL_ALIAS="${CONTROL_DIR}/control-agent.alias" | ||
| readonly START_TIMEOUT_SECONDS=60 | ||
| readonly INFERENCE_TIMEOUT_SECONDS=120 | ||
| readonly EXPECTED_TOKEN="CI_INFERENCE_OK" | ||
|
|
||
| started=0 | ||
|
|
||
| log() { | ||
| printf '[inference-smoke] %s\n' "$*" | ||
| } | ||
|
|
||
| cleanup() { | ||
| local exit_code=$? | ||
| if [[ $started -eq 1 ]]; then | ||
| log "cleanup: stopping baudbot" | ||
| sudo baudbot stop >/dev/null 2>&1 || true | ||
| fi | ||
| exit "$exit_code" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| wait_for_control_socket() { | ||
| local deadline=$((SECONDS + START_TIMEOUT_SECONDS)) | ||
| local target="" | ||
|
|
||
| while (( SECONDS < deadline )); do | ||
| if [[ -L "$CONTROL_ALIAS" ]]; then | ||
| target="$(readlink -- "$CONTROL_ALIAS" 2>/dev/null || true)" | ||
| if [[ -n "$target" ]]; then | ||
| if [[ "$target" != /* ]]; then | ||
| target="${CONTROL_DIR}/${target}" | ||
| fi | ||
| if [[ -S "$target" ]]; then | ||
| printf '%s\n' "$target" | ||
| return 0 | ||
| fi | ||
| fi | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| dump_diagnostics() { | ||
| log "--- diagnostics ---" | ||
| sudo baudbot status 2>&1 || true | ||
| log "--- end diagnostics ---" | ||
| } | ||
|
|
||
| # Send a message via session-control RPC and wait for turn_end. | ||
| # Prints the assistant response content on success, exits non-zero on failure. | ||
| rpc_send_wait_turn_end() { | ||
| local socket_path="$1" | ||
| local message="$2" | ||
| local timeout_seconds="$3" | ||
|
|
||
| sudo -u "$AGENT_USER" python3 - "$socket_path" "$message" "$timeout_seconds" <<'PY' | ||
| import json | ||
| import socket | ||
| import sys | ||
|
|
||
| sock_path = sys.argv[1] | ||
| message = sys.argv[2] | ||
| timeout_seconds = int(sys.argv[3]) | ||
|
|
||
| send_cmd = {"type": "send", "message": message, "mode": "steer"} | ||
| subscribe_cmd = {"type": "subscribe", "event": "turn_end"} | ||
|
|
||
| client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| try: | ||
| client.settimeout(timeout_seconds) | ||
| client.connect(sock_path) | ||
|
|
||
| # Send both commands | ||
| client.sendall((json.dumps(send_cmd) + "\n").encode("utf-8")) | ||
| client.sendall((json.dumps(subscribe_cmd) + "\n").encode("utf-8")) | ||
|
|
||
| buf = b"" | ||
| send_response = None | ||
|
|
||
| while True: | ||
| chunk = client.recv(8192) | ||
| if not chunk: | ||
| print("connection closed before turn_end", file=sys.stderr) | ||
| sys.exit(1) | ||
| buf += chunk | ||
|
|
||
| while b"\n" in buf: | ||
| line, buf = buf.split(b"\n", 1) | ||
| line = line.strip() | ||
| if not line: | ||
| continue | ||
|
|
||
| try: | ||
| msg = json.loads(line.decode("utf-8", errors="replace")) | ||
| except json.JSONDecodeError: | ||
| continue | ||
|
|
||
| if msg.get("type") == "response": | ||
| cmd = msg.get("command", "") | ||
| if cmd == "send": | ||
| if not msg.get("success", False): | ||
| print(f"send failed: {msg.get('error', 'unknown')}", file=sys.stderr) | ||
| sys.exit(1) | ||
| send_response = msg | ||
| # Ignore subscribe response | ||
| continue | ||
|
|
||
| if msg.get("type") == "event" and msg.get("event") == "turn_end": | ||
| if send_response is None: | ||
| print("received turn_end before send response", file=sys.stderr) | ||
| sys.exit(1) | ||
| data = msg.get("data", {}) | ||
| assistant_msg = data.get("message", {}) | ||
| content = assistant_msg.get("content", "") | ||
| if not content: | ||
| print("turn completed but no assistant content", file=sys.stderr) | ||
| sys.exit(1) | ||
| print(content) | ||
| sys.exit(0) | ||
|
|
||
| print("stream ended without turn_end event", file=sys.stderr) | ||
| sys.exit(1) | ||
| except socket.timeout: | ||
| print("timeout waiting for inference response", file=sys.stderr) | ||
| sys.exit(1) | ||
| finally: | ||
| client.close() | ||
| PY | ||
| } | ||
|
|
||
| readonly CI_MODEL="anthropic/claude-haiku" | ||
|
|
||
| inject_ci_config() { | ||
| if [[ -z "${CI_ANTHROPIC_API_KEY:-}" ]]; then | ||
| log "ERROR: CI_ANTHROPIC_API_KEY is not set" | ||
| return 1 | ||
| fi | ||
| log "injecting CI API key and model override into agent .env" | ||
| sed -i "s|^ANTHROPIC_API_KEY=.*|ANTHROPIC_API_KEY=${CI_ANTHROPIC_API_KEY}|" "$AGENT_ENV" | ||
| # Use a cheap model for the smoke test — no need to burn Sonnet/Opus tokens. | ||
| if grep -q "^BAUDBOT_MODEL=" "$AGENT_ENV" 2>/dev/null; then | ||
| sed -i "s|^BAUDBOT_MODEL=.*|BAUDBOT_MODEL=${CI_MODEL}|" "$AGENT_ENV" | ||
| else | ||
| echo "BAUDBOT_MODEL=${CI_MODEL}" >> "$AGENT_ENV" | ||
| fi | ||
| } | ||
|
|
||
| main() { | ||
| inject_ci_config | ||
|
|
||
| log "starting baudbot" | ||
| sudo baudbot start | ||
| started=1 | ||
|
|
||
| log "waiting for control-agent socket" | ||
| local socket_path="" | ||
| if ! socket_path="$(wait_for_control_socket)"; then | ||
| log "control-agent socket did not become ready within ${START_TIMEOUT_SECONDS}s" | ||
| dump_diagnostics | ||
| return 1 | ||
| fi | ||
| log "control socket ready: ${socket_path}" | ||
|
|
||
| log "sending inference prompt (timeout ${INFERENCE_TIMEOUT_SECONDS}s)" | ||
| local response="" | ||
| if ! response="$(rpc_send_wait_turn_end "$socket_path" \ | ||
| "Reply with exactly: ${EXPECTED_TOKEN}" \ | ||
| "$INFERENCE_TIMEOUT_SECONDS")"; then | ||
| log "inference failed" | ||
| dump_diagnostics | ||
| return 1 | ||
| fi | ||
|
|
||
| # Validate response contains expected token | ||
| if [[ "$response" == *"$EXPECTED_TOKEN"* ]]; then | ||
| log "inference response contains expected token" | ||
| else | ||
| log "unexpected response (missing '${EXPECTED_TOKEN}'):" | ||
| log " ${response:0:500}" | ||
| dump_diagnostics | ||
| return 1 | ||
| fi | ||
|
|
||
| log "stopping baudbot" | ||
| sudo baudbot stop | ||
| started=0 | ||
|
|
||
| log "inference smoke passed" | ||
| } | ||
|
|
||
| main "$@" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The smoke test's
sedcommand forANTHROPIC_API_KEYinjection is fragile. It fails silently if the key doesn't exist in.env, which occurs when a non-Anthropic LLM is used.Severity: MEDIUM
Suggested Fix
Update the script to check if
ANTHROPIC_API_KEYexists in the.envfile before attempting to replace it. If it doesn't exist, append the key and value to the file. This mirrors the safer pattern already used forBAUDBOT_MODELin the same script.Prompt for AI Agent