Repository navigation
Build: Update CPEX to 0.2.3 - #1234
Conversation
Signed-off-by: Frederico Araujo <[email protected]>
This comment was marked as off-topic.
This comment was marked as off-topic.
huang195
left a comment
There was a problem hiding this comment.
Summary
The bump is clean. ABI 2 is unchanged (the SDK's expectedFFIABIVersion, CPEX_FFI_ABI and the tarball's FFI_ABI all say 2). The v0.2.3 musl assets exist and their sha256 and cosign identity match. Both go.mod files are tidy, and no stale 0.2.2 references remain. Switching to PayloadModified is the right fix, and it fixes more than the PR says: v0.2.2 already returned a payload on every allowed pipeline (executor.rs allowed_with). So before this PR every allowed request went through the body re-serializer, and a request no parser claimed failed closed with "body modification requested but no protocol parser claimed this traffic" (502). That is worth putting in the PR body.
The main gap: ModifiedExtensions has the same "present means modified" problem, so every allowed CPEX call still records modify. Inline comment 1 has the repro. It predates this PR, so a follow-up is fine.
Verified locally on darwin-arm64 against the real v0.2.3 FFI:
go test -race -tags cpex ./plugins/cpex/passes.go vetpasses with and without-tags cpex.cortex-cpexbuilds with thecpexprofile.go mod tidy -diffis clean incoreandcmd/cortex-cpex.- A throwaway probe drove a real
InvokeByNameand printed what comes back from an allow-all pipeline.
Outside the diff (no line to anchor to):
core/plugins/cpex/README.md:308:podman build -f cmd/cortex-cpex/Dockerfile -t authbridge-cpex:latest .has the breakage this PR fixes in the demo Makefile. WithoutCPEX_FFI_VERSION,CPEX_FFI_ABIandGO_BUILD_TAGSit fails. Line 311 also says the ABI version lives inCPEX_FFI_VERSION; it lives inCPEX_FFI_ABI.core/plugins/cpex/manager_cpex.go:103-104: theInvokedoc comment says body modifications "log a WARN but don't rewrite pctx.Body". That is stale, sinceapplyBodyModFromCMFrewrites MCP, inference and A2A bodies.
Author: araujof (MEMBER — maintainer)
Areas reviewed: Go (core/plugins/cpex), Go modules, Dockerfile/build args, demo Makefile + scenario scripts, docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (note that no CI job runs the new cpex-tagged tests; see inline)
| } | ||
|
|
||
| if len(p.ModifiedPayload) > 0 || len(p.ModifiedExtensions) > 0 { | ||
| if p.PayloadModified || len(p.ModifiedExtensions) > 0 { |
There was a problem hiding this comment.
suggestion: len(p.ModifiedExtensions) > 0 has the same "present means modified" problem this PR fixes for the payload. The executor builds every allowed result with modified_extensions: Some(extensions) (crates/cpex-core/src/executor.rs allowed_with, in both 0.2.2 and 0.2.3), and the FFI serializes it whenever it is Some (crates/cpex-ffi/src/lib.rs ~L864).
Repro against the real v0.2.3 FFI, with an audit/logger-only APL route and no mutation:
tool=get_weather continue=true payloadModified=false len(ModifiedPayload)=90 len(ModifiedExtensions)=73 -> decision=modify reason="policy modified headers/labels"
tool=unrouted_tool continue=true payloadModified=false len(ModifiedPayload)=90 len(ModifiedExtensions)=75 -> decision=modify reason="policy modified headers/labels"
So DecisionAllow / "all policies passed" is unreachable in practice, and every allowed CPEX invocation shows modify in the session timeline. The same predicate at L312 also means applyExtensionChanges Sets every echoed header on every request, which collapses multi-value headers into the comma-joined form flattenHeaders sent.
0.2.3 has no extensions_modified counterpart to payload_modified. Options: diff the returned headers/labels against what buildCMF sent and report modify only on a real change, or ask upstream for the flag. This predates the PR, so a tracked follow-up is fine.
| if len(pres.ModifiedPayload) > 0 { | ||
| if pres.PayloadModified { | ||
| if len(pres.ModifiedPayload) == 0 { | ||
| return fmt.Errorf("CPEX marked payload modified but returned no payload") |
There was a problem hiding this comment.
suggestion: The only producer of "flag set, no bytes" I could find is an FFI serialize failure. cpex_invoke drops the payload but keeps payload_modified, and records the cause in result.errors as plugin <ffi>, code ffi_serialize_error (crates/cpex-ffi/src/lib.rs ~L845-860). This error drops that context, so an operator only sees "marked payload modified but returned no payload". Consider appending the pres.Errors messages. Failing closed here is the right call.
| func TestUnchangedPayloadIsNotApplied(t *testing.T) { | ||
| // CPEX 0.2.3 returns a final payload on every allowed pipeline. Its | ||
| // presence alone must not trigger a body rewrite or a modify decision. | ||
| pres := &rcpex.PipelineResult{ |
There was a problem hiding this comment.
suggestion: This fixture leaves ModifiedExtensions nil, but real CPEX never returns that on an allowed pipeline (see the comment on manager_cpex.go:866). So the DecisionAllow assertion passes against a result shape production never sees. The "decoded payload must not be applied" half is real and worth keeping. Once the extensions predicate is fixed, give this fixture realistic echoed extensions (what buildCMF sent) so it guards the behaviour that actually happens.
| if err := applyModificationsToPctx(&pipeline.Context{}, pres, false); err == nil || !strings.Contains(err.Error(), "no payload") { | ||
| t.Fatalf("missing modified payload error = %v", err) | ||
| } | ||
| if got := mapResult(pres).Decision; got != DecisionModify { |
There was a problem hiding this comment.
suggestion: The real path cannot reach this state. When applyModificationsToPctx errors, Invoke returns DecisionError plus the error (manager_cpex.go:173-186) before mapResult runs (L189), and plugin.go routes that through fail_open (502 when false). So asserting DecisionModify here suggests a flagged-but-empty payload yields modify, which it never does. I'd drop this assertion, or test at the Invoke/plugin level that the outcome is DecisionError.
| // Copyright 2026 | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //go:build cpex |
There was a problem hiding this comment.
suggestion: These are the first cpex-tagged tests, and no CI job runs them:
go-ci-corerunsgo test ./...without tags.cortex-cpexis excluded from the cmd matrix (ci.yaml~L186).- The Dockerfile builds but never runs
go test.
For now they only run on a laptop with the FFI. This worked for me:
curl -fsSLO https://github.com/contextforge-org/cpex/releases/download/v0.2.3/cpex-ffi-v0.2.3-darwin-arm64.tar.gz && tar xzf cpex-ffi-*.tar.gz
GOWORK=off CGO_ENABLED=1 CGO_LDFLAGS="-L$PWD -lcpex_ffi -lm" go -C core test -race -tags cpex ./plugins/cpex/
Worth a follow-up Linux job that links the musl .a (it is already fetched and verified by the Dockerfile's ffi stage). At minimum, document the command next to the "Unit tests (no cgo)" line in core/plugins/cpex/README.md.
| ) | ||
|
|
||
| func TestUnchangedPayloadIsNotApplied(t *testing.T) { | ||
| // CPEX 0.2.3 returns a final payload on every allowed pipeline. Its |
There was a problem hiding this comment.
nit: This is not new in 0.2.3. v0.2.2's allowed_with already set modified_payload: Some(payload), and the 0.2.3 CHANGELOG says it "never answered 'did anything change?'". 0.2.3 adds the flag. Saying so would also explain why this is a bug fix and not just a bump.
| @@ -0,0 +1,42 @@ | |||
| // Copyright 2026 | |||
There was a problem hiding this comment.
nit: This is the only .go file in the repo with a Copyright/SPDX header (git grep -l SPDX -- '*.go' returns just this file), and "Copyright 2026" names no holder. The sibling files in this package have no header, so I'd drop these two lines to match.
| "$$s"; \ | ||
| done | ||
| "$$s" || status=1; \ | ||
| done; exit $$status |
There was a problem hiding this comment.
nit: The status propagation is correct, but few failures reach it:
- No scenario asserts an HTTP status or a policy outcome. They print
Expected:notes and run curl without-f. call_get_compensation(and the other_lib.shhelpers) run_print_response "$(_post_tool …)". A command substitution inside an argument does not tripset -e, so even a refused proxy connection exits 0 there.
What propagates today is mint/Keycloak failures plus curl failures in 04 and 06, which assign resp=$(curl …). If the authorization/redaction/delegation assertions from the PR description are scripted somewhere, putting them in-tree would make make scenarios a real check.
| -f cmd/cortex-cpex/Dockerfile \ | ||
| --build-arg CPEX_FFI_VERSION=$$(cat cmd/cortex-cpex/CPEX_FFI_VERSION | tr -d '[:space:]') \ | ||
| --build-arg CPEX_FFI_ABI=$$(cat cmd/cortex-cpex/CPEX_FFI_ABI | tr -d '[:space:]') \ | ||
| --build-arg GO_BUILD_TAGS="$$(GOWORK=off go -C scripts/profile-tags run . cpex)" \ |
There was a problem hiding this comment.
nit: build-images now needs go on the host, but preflight checks only kind/kubectl/docker. Without Go this prints go: command not found, then fails in the Dockerfile with "GO_BUILD_TAGS is required". A @command -v go >/dev/null || { echo "missing: go"; exit 1; } line in preflight would make that failure clearer.
Updates the CPEX Go SDK and FFI to 0.2.3 and uses the new payload mutation flag. Fixes the HR demo image build and scenario failure reporting.
Validated with Go race tests, the nine HR demo scenarios, and assertions for authorization, redaction, delegation, and session isolation.
Related to #683.
Summary by CodeRabbit