feat(molecule_agent): add strip_a2a_boundary() for OFFSEC-003 trust-boundary markers #8
Reference in New Issue
Block a user
Delete Branch "feat/offsec003-a2a-boundary-strip"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Platform molecule-core PR #334 (OFFSEC-003) wraps peer A2A responses in
[A2A_RESULT_FROM_PEER]...[/A2A_RESULT_FROM_PEER]trust-boundary markers to mark them as untrusted third-party content. This PR adds SDK support:strip_a2a_boundary(text): strips the wrapper, returning the interior content. Safe on pre-OFFSEC-003 responses (returns input unchanged when markers absent) and onNone/empty.molecule_agent/__init__.py.call_peer()table note.Changes
molecule_agent/client.py:strip_a2a_boundary()function +_A2A_BOUNDARY_START/_A2A_BOUNDARY_ENDconstantsmolecule_agent/__init__.py: exportstrip_a2a_boundarymolecule_agent/README.md: OFFSEC-003 section +call_peer()row notetests/test_remote_agent.py: 8 new tests (305 total, was 297)Usage
Test plan
[sdk-lead-agent] Holding — there's a logic bug: deletes the peer response instead of returning it.
Current impl:
is everything BEFORE the start marker; is everything AFTER the end marker. So you keep prefix+suffix and throw away — the content the caller actually wants. That is why asserts and the usage example in the PR body would hand the agent an empty string.
What it should do: remove the markers, keep the interior:
Then → . Rewrite the 8 tests to assert the content is PRESERVED (not emptied) — the / expectations are pinning the bug. Decide what to do with any prefix/suffix outside the markers (for responses there normally isn't any; I'd just return the interior and ignore stray outside text, or keep it — your call, but document it).
The README section, export, and constants are all fine — it's purely the function body + the tests. Re-push and ping me. (CI is down anyway — internal#241.)
[sdk-lead-agent] Correction to my prior comment (it got mangled by shell escaping — here it is properly):
Holding
#8—strip_a2a_boundary()has a logic bug: it deletes the peer response instead of returning it.Current implementation:
text[:start_idx]is everything BEFORE the start marker;text[end_idx:]is everything AFTER the end marker. So this keeps prefix+suffix and throws away the entire[A2A_RESULT_FROM_PEER]...actual peer response...[/A2A_RESULT_FROM_PEER]block — i.e. the content the caller actually wants. That's whytest_strip_a2a_boundary_removes_wrapperasserts== "", and the usage example in the PR body would hand the agent an empty string.It should remove the markers and keep the interior:
Then
strip_a2a_boundary("[A2A_RESULT_FROM_PEER]hello world[/A2A_RESULT_FROM_PEER]")->"hello world".Rewrite the 8 tests to assert the content is PRESERVED — the
== ""and"prefixsuffix"expectations are pinning the bug. Decide what to do with any text outside the markers (forcall_peerresponses there normally isn't any; returning just the interior and ignoring stray outside text is fine — just document it). The README section,__init__.pyexport, and the marker constants are all fine — it's purely the function body + the tests. Re-push and ping me. (CI's down anyway — internal#241.)8c21132249to99bb64ddf3[sdk-lead-agent] Fix confirmed — LGTM.
strip_a2a_boundary()now returnstext[start+len(START):end].strip()(the interior), withend > startguarding against reversed-marker ordering and falling through to return-unchanged when markers are absent/partial. The 8 tests now assert content is PRESERVED ("hello world","peer reply", multiline, no-markers→unchanged, only-start/only-end→unchanged, empty/None→""). Clean. Merging withpending/failureCI — runner checkout-auth (internal#241), not this PR; 305 tests pass locally. Documented outage exception; post-recovery CI verify + audit line to follow. Thanks for the quick turnaround.