Skip to content

Build: Update CPEX to 0.2.3 - #1234

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
araujof:feat/cpex_0.2.3
Oct 2, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
araujof:feat/cpex_0.2.3

Conversation

@araujof

@araujof araujof commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Bug Fixes
    • Payload changes are now applied based on whether a modification was requested. If a payload change is requested without payload data, the operation reports an error instead of silently skipping it. Unmodified payloads continue to be allowed without decoding.
    • Demo scenario runs now report failures even when later scenarios succeed.
  • Documentation
    • Updated the demo policy’s syntax note to reflect CPEX v0.2.3.

Signed-off-by: Frederico Araujo <[email protected]>
@coderabbitai

This comment was marked as off-topic.

@araujof araujof linked an issue Oct 2, 2026 that may be closed by this pull request
@araujof
araujof marked this pull request as ready for review October 2, 2026 19:21
@araujof
araujof requested a review from a team as a code owner October 2, 2026 19:21

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 vet passes with and without -tags cpex.
  • cortex-cpex builds with the cpex profile.
  • go mod tidy -diff is clean in core and cmd/cortex-cpex.
  • A throwaway probe drove a real InvokeByName and 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. Without CPEX_FFI_VERSION, CPEX_FFI_ABI and GO_BUILD_TAGS it fails. Line 311 also says the ABI version lives in CPEX_FFI_VERSION; it lives in CPEX_FFI_ABI.
  • core/plugins/cpex/manager_cpex.go:103-104: the Invoke doc comment says body modifications "log a WARN but don't rewrite pctx.Body". That is stale, since applyBodyModFromCMF rewrites 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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: These are the first cpex-tagged tests, and no CI job runs them:

  • go-ci-core runs go test ./... without tags.
  • cortex-cpex is 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread demos/hr-cpex/Makefile
"$$s"; \
done
"$$s" || status=1; \
done; exit $$status

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh helpers) run _print_response "$(_post_tool …)". A command substitution inside an argument does not trip set -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.

Comment thread demos/hr-cpex/Makefile
-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)" \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@huang195
huang195 merged commit ccb33e4 into rossoctl:main Oct 2, 2026
30 checks passed
@araujof
araujof deleted the feat/cpex_0.2.3 branch October 5, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Test: Verify Cortex authz capabilities end-to-end (at least OPA)

2 participants