Skip to content

Commit f7c2477

Browse files
author
Meli
committed
Merge origin/main into carl/relay-primary-agent-config
Brings in a121907 (buzz-agent request_permission gate, #5712) and 931747c (staging dev relay image workflow, #6709). Clean merge, no conflicts; no files overlap with this branch. Co-authored-by: Meli <5aaa86bce934fc3445fc254aab560a40923f10252f92107e665073dede0e04d3@buzz.block.builderlab.xyz> Signed-off-by: Meli <5aaa86bce934fc3445fc254aab560a40923f10252f92107e665073dede0e04d3@buzz.block.builderlab.xyz>
2 parents 63f8621 + a121907 commit f7c2477

14 files changed

Lines changed: 2796 additions & 299 deletions

File tree

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
name: Staging dev relay image
2+
3+
# Publishes pre-merge relay runtime images for bb-block staging only.
4+
#
5+
# Operators run this workflow from the default branch and provide a target ref in
6+
# this repository. GitHub's workflow_dispatch permission model limits triggering
7+
# to collaborators who can run repository workflows; no actor allowlist is kept
8+
# here. The target ref is resolved to an immutable commit SHA before checkout,
9+
# and the published tag is derived from that full SHA.
10+
11+
on:
12+
workflow_dispatch:
13+
inputs:
14+
target_ref:
15+
description: "Branch, tag, refs/heads/*, or refs/tags/* in block/buzz to publish for bb-block staging"
16+
required: true
17+
type: string
18+
19+
permissions: {}
20+
21+
env:
22+
IMAGE_NAME: ghcr.io/block/buzz-staging-dev
23+
ECR_REPOSITORY: 929862310821.dkr.ecr.us-west-2.amazonaws.com/ghcr.io/block/buzz-staging-dev
24+
25+
jobs:
26+
resolve:
27+
name: Resolve target ref
28+
runs-on: ubuntu-24.04
29+
timeout-minutes: 5
30+
permissions:
31+
contents: read
32+
outputs:
33+
target_sha: ${{ steps.resolve.outputs.target_sha }}
34+
image_tag: ${{ steps.resolve.outputs.image_tag }}
35+
steps:
36+
- name: Require reviewed workflow from main in canonical repository
37+
env:
38+
DISPATCH_REF: ${{ github.ref }}
39+
REPOSITORY: ${{ github.repository }}
40+
run: |
41+
set -euo pipefail
42+
if [ "$REPOSITORY" != "block/buzz" ]; then
43+
echo "::error::Staging dev relay image publication is restricted to block/buzz"
44+
exit 1
45+
fi
46+
47+
if [ "$DISPATCH_REF" != "refs/heads/main" ]; then
48+
echo "::error::Dispatch this workflow from main, not $DISPATCH_REF"
49+
exit 1
50+
fi
51+
52+
- name: Resolve target ref in this repository
53+
id: resolve
54+
env:
55+
TARGET_REF_INPUT: ${{ inputs.target_ref }}
56+
GITHUB_REPOSITORY: ${{ github.repository }}
57+
run: |
58+
set -euo pipefail
59+
60+
target_ref=$(printf '%s' "$TARGET_REF_INPUT" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
61+
62+
if [ -z "$target_ref" ]; then
63+
echo "target_ref must not be empty" >&2
64+
exit 1
65+
fi
66+
67+
if [ ${#target_ref} -gt 255 ]; then
68+
echo "target_ref is too long" >&2
69+
exit 1
70+
fi
71+
72+
if [[ ! "$target_ref" =~ ^[A-Za-z0-9._/@-]+$ ]]; then
73+
echo "target_ref contains unsupported characters; use a branch, tag, or full refs/heads/* or refs/tags/* name" >&2
74+
exit 1
75+
fi
76+
77+
case "$target_ref" in
78+
-*|*..*|*.lock|refs/pull/*|pull/*|*/pull/*)
79+
echo "target_ref is not an allowed repository branch/tag/ref" >&2
80+
exit 1
81+
;;
82+
esac
83+
84+
workdir=$(mktemp -d)
85+
trap 'rm -rf "$workdir"' EXIT
86+
git -C "$workdir" init --quiet
87+
git -C "$workdir" remote add origin "https://github.com/${GITHUB_REPOSITORY}.git"
88+
89+
fetch_commit() {
90+
local ref=$1
91+
git -C "$workdir" fetch --no-tags --depth=1 origin "$ref" >/dev/null 2>&1
92+
git -C "$workdir" rev-parse --verify "FETCH_HEAD^{commit}"
93+
}
94+
95+
target_sha=""
96+
if [[ "$target_ref" == refs/heads/* || "$target_ref" == refs/tags/* ]]; then
97+
target_sha=$(fetch_commit "$target_ref") || {
98+
echo "target_ref did not resolve in ${GITHUB_REPOSITORY}: $target_ref" >&2
99+
exit 1
100+
}
101+
else
102+
if target_sha=$(fetch_commit "refs/heads/${target_ref}"); then
103+
:
104+
elif target_sha=$(fetch_commit "refs/tags/${target_ref}"); then
105+
:
106+
else
107+
echo "target_ref did not resolve as a branch or tag in ${GITHUB_REPOSITORY}: $target_ref" >&2
108+
exit 1
109+
fi
110+
fi
111+
112+
target_sha=$(printf '%s' "$target_sha" | tr '[:upper:]' '[:lower:]')
113+
if [[ ! "$target_sha" =~ ^[0-9a-f]{40}$ ]]; then
114+
echo "resolved target SHA is invalid: $target_sha" >&2
115+
exit 1
116+
fi
117+
118+
image_tag="dev-sha-${target_sha}-run-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
119+
{
120+
echo "target_sha=${target_sha}"
121+
echo "image_tag=${image_tag}"
122+
} >> "$GITHUB_OUTPUT"
123+
124+
printf "Resolved \`%s\` to \`%s\`; image tag \`%s\`.\n" "$target_ref" "$target_sha" "$image_tag" >> "$GITHUB_STEP_SUMMARY"
125+
126+
build:
127+
name: Build staging relay runtime (${{ matrix.platform }})
128+
runs-on: ${{ matrix.runner }}
129+
needs: resolve
130+
timeout-minutes: 60
131+
permissions:
132+
contents: read
133+
packages: write
134+
strategy:
135+
fail-fast: false
136+
matrix:
137+
include:
138+
- platform: linux/amd64
139+
runner: ubuntu-24.04
140+
arch: amd64
141+
- platform: linux/arm64
142+
runner: ubuntu-24.04-arm
143+
arch: arm64
144+
steps:
145+
- name: Checkout resolved target
146+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
147+
with:
148+
ref: ${{ needs.resolve.outputs.target_sha }}
149+
fetch-depth: 1
150+
persist-credentials: false
151+
152+
- name: Set up Docker Buildx
153+
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
154+
with:
155+
buildkitd-config-inline: |
156+
[worker.oci]
157+
max-parallelism = 2
158+
159+
- name: Log in to GHCR
160+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
161+
with:
162+
registry: ghcr.io
163+
username: ${{ github.repository_owner }}
164+
password: ${{ secrets.GITHUB_TOKEN }}
165+
166+
- name: Extract metadata
167+
id: meta
168+
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
169+
with:
170+
images: ${{ env.IMAGE_NAME }}
171+
labels: |
172+
org.opencontainers.image.title=Buzz staging dev relay
173+
org.opencontainers.image.description=Pre-merge Buzz relay runtime image for bb-block staging only
174+
org.opencontainers.image.licenses=Apache-2.0
175+
org.opencontainers.image.revision=${{ needs.resolve.outputs.target_sha }}
176+
177+
- name: Build and push runtime image by digest
178+
id: build
179+
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
180+
with:
181+
context: .
182+
file: ./Dockerfile
183+
target: runtime
184+
platforms: ${{ matrix.platform }}
185+
labels: ${{ steps.meta.outputs.labels }}
186+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
187+
cache-from: |
188+
type=registry,ref=${{ env.IMAGE_NAME }}-buildcache:${{ matrix.arch }}
189+
cache-to: |
190+
type=registry,ref=${{ env.IMAGE_NAME }}-buildcache:${{ matrix.arch }},mode=max,compression=zstd
191+
192+
- name: Export digest
193+
env:
194+
DIGEST: ${{ steps.build.outputs.digest }}
195+
run: |
196+
set -euo pipefail
197+
mkdir -p /tmp/digests-release
198+
touch "/tmp/digests-release/${DIGEST#sha256:}"
199+
200+
- name: Upload digest
201+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
202+
with:
203+
name: staging-dev-relay-digests-${{ matrix.arch }}
204+
path: /tmp/digests-release/*
205+
if-no-files-found: error
206+
retention-days: 1
207+
208+
merge:
209+
name: Publish staging relay runtime manifest
210+
runs-on: ubuntu-24.04
211+
needs:
212+
- resolve
213+
- build
214+
timeout-minutes: 15
215+
permissions:
216+
contents: read
217+
packages: write
218+
steps:
219+
- name: Download per-arch digests
220+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
221+
with:
222+
path: /tmp/digests
223+
pattern: staging-dev-relay-digests-*
224+
merge-multiple: true
225+
226+
- name: Set up Docker Buildx
227+
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
228+
229+
- name: Log in to GHCR
230+
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
231+
with:
232+
registry: ghcr.io
233+
username: ${{ github.repository_owner }}
234+
password: ${{ secrets.GITHUB_TOKEN }}
235+
236+
- name: Create and push manifest list
237+
id: manifest
238+
working-directory: /tmp/digests
239+
env:
240+
IMAGE_NAME: ${{ env.IMAGE_NAME }}
241+
IMAGE_TAG: ${{ needs.resolve.outputs.image_tag }}
242+
run: |
243+
set -euo pipefail
244+
digests=()
245+
for digest in *; do
246+
digests+=("${IMAGE_NAME}@sha256:${digest}")
247+
done
248+
249+
docker buildx imagetools create -t "${IMAGE_NAME}:${IMAGE_TAG}" "${digests[@]}"
250+
merged_digest=$(docker buildx imagetools inspect "${IMAGE_NAME}:${IMAGE_TAG}" \
251+
--format '{{json .Manifest}}' | jq -r '.digest')
252+
echo "digest=${merged_digest}" >> "$GITHUB_OUTPUT"
253+
254+
- name: Deployment summary
255+
env:
256+
IMAGE_NAME: ${{ env.IMAGE_NAME }}
257+
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
258+
IMAGE_TAG: ${{ needs.resolve.outputs.image_tag }}
259+
TARGET_SHA: ${{ needs.resolve.outputs.target_sha }}
260+
MERGED_DIGEST: ${{ steps.manifest.outputs.digest }}
261+
run: |
262+
{
263+
echo "### Published bb-block staging dev relay image"
264+
echo
265+
echo "**Source commit:** \`${TARGET_SHA}\`"
266+
echo "**GHCR image:** \`${IMAGE_NAME}:${IMAGE_TAG}\`"
267+
echo "**Manifest digest:** \`${MERGED_DIGEST}\`"
268+
echo
269+
echo "Set bb-block staging BPCI values to:"
270+
echo '```yaml'
271+
echo "buzz:"
272+
echo " image:"
273+
echo " repository: ${ECR_REPOSITORY}"
274+
echo " tag: ${IMAGE_TAG}"
275+
echo '```'
276+
} >> "$GITHUB_STEP_SUMMARY"

‎crates/buzz-agent/src/agent.rs‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::hints::SkillEntry;
1414
use crate::llm::Llm;
1515
use crate::mcp::McpRegistry;
1616
use crate::mcp::ResultBudget;
17+
use crate::permission::PermissionDecision;
1718

1819
use crate::types::{
1920
AgentError, CacheTotalState, ContentBlock, HistoryItem, PricingIdentity, ProviderStop,
@@ -142,6 +143,14 @@ pub struct RunCtx<'a> {
142143
pub system_prompt: &'a str,
143144
pub llm: &'a Llm,
144145
pub mcp: &'a Arc<McpRegistry>,
146+
/// Process-wide permission broker (owned by `App`). Every LLM-issued MCP
147+
/// tool call asks the client to authorize it through this broker before
148+
/// executing. Shared across all sessions so the global admission cap bounds
149+
/// simultaneously-outstanding asks process-wide.
150+
pub permissions: &'a Arc<crate::permission::PermissionBroker>,
151+
/// ACP protocol version negotiated at `initialize`, fixed for the
152+
/// connection. Selects the `session/request_permission` wire shape.
153+
pub protocol_version: u32,
145154
/// Skills discovered at session creation; used by the built-in `load_skill` tool.
146155
pub skills: &'a [SkillEntry],
147156
pub wire: &'a WireSender,
@@ -882,8 +891,10 @@ impl RunCtx<'_> {
882891
total: MAX_TOOL_RESULT_BYTES,
883892
text: self.cfg.max_tool_result_text_bytes,
884893
};
885-
let cancel = self.cancel.clone();
894+
let mut cancel = self.cancel.clone();
886895
let sem = Arc::clone(&sem);
896+
let permissions = Arc::clone(self.permissions);
897+
let protocol_version = self.protocol_version;
887898
set.spawn(async move {
888899
// Acquire a permit; if the semaphore is closed (cancel),
889900
// emit a terminal wire update and skip the call.
@@ -894,6 +905,37 @@ impl RunCtx<'_> {
894905
return (i, InvokeOutcome::Failed("cancelled".into()));
895906
}
896907
};
908+
// Argument-shape validation BEFORE the ask: a malformed
909+
// non-object argument can never execute, so reject it locally
910+
// without prompting the user to approve a doomed call.
911+
if let Err(e) = crate::mcp::validate_arg_shape(&call.name, &call.arguments) {
912+
let msg = e.to_string();
913+
emit_failed(&wire, &session_id, &call, &msg).await;
914+
return (i, InvokeOutcome::Failed(msg));
915+
}
916+
// Ask the client to authorize this call. The broker owns the
917+
// full correlation lifecycle and races cancellation internally;
918+
// every non-authorizing outcome fails closed.
919+
match permissions
920+
.request_permission(&wire, protocol_version, &session_id, &call, &mut cancel)
921+
.await
922+
{
923+
PermissionDecision::Allowed => {}
924+
PermissionDecision::Denied(msg) => {
925+
emit_failed(&wire, &session_id, &call, msg).await;
926+
return (i, InvokeOutcome::Failed(msg.into()));
927+
}
928+
PermissionDecision::Cancelled => {
929+
emit_failed(&wire, &session_id, &call, "cancelled").await;
930+
return (i, InvokeOutcome::Failed("cancelled".into()));
931+
}
932+
}
933+
// Cancellation recheck: a cancel may have landed while we
934+
// waited for approval. Do not start the call in that case.
935+
if *cancel.borrow() {
936+
emit_failed(&wire, &session_id, &call, "cancelled").await;
937+
return (i, InvokeOutcome::Failed("cancelled".into()));
938+
}
897939
emit_in_progress(&wire, &session_id, &call).await;
898940
let outcome = invoke_tool_inner(&mcp, &call, timeout, budget, cancel).await;
899941
match &outcome {

0 commit comments

Comments
 (0)