Skip to content

fix(llminternal): omit metadata-only foreign parts from context - #1895

Merged
wolo-lab merged 7 commits into
google:mainfrom
jabrailkhalil:fix/foreign-metadata-parts
Nov 5, 2026
Merged

wolo-lab merged 7 commits into
google:mainfrom
jabrailkhalil:fix/foreign-metadata-parts

Conversation

@jabrailkhalil

@jabrailkhalil jabrailkhalil commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

My fix was merged on November 5 in 6caa3b8. Upstream Go CI passed on accepted head 29d1d771; the foreign-event converter and both regression-test files match my author-validated source below.

Closes: #1894

I drop foreign events containing only empty or metadata-only parts. Previously, a signature-only event could become the IncludeContents: "none" turn boundary and remove the preceding user input. Empty parts could also leave a bare For context: preamble.

Foreign events without a relay payload no longer start a visible turn. Mixed events retain their payloads and attached metadata/signatures. Own-agent history, usable compaction summaries, whitespace text and the existing empty-event contract are unchanged. I have not changed the API or dependencies.

I follow adk-python's media/code handling, retaining Go's existing server-tool and audio-transcription parts. #1360 still owns fencing; the discarded-event nil result must survive either merge order.

Testing plan

Author-validated source: 0fa3c4a84d4d7fdaaf7b0e9e5931fcd191cbd161. This review follow-up changes tests only. I added all seven thought-payload kinds with/without text, both alone and beside public text and a public payload of the same kind. Each case also checks that the stored event is unchanged.

I ran Linux/amd64 checks with Go 1.26.10 and CI-pinned golangci-lint 2.3.1:

  • Both modules pass readonly build, vet, uncached shuffled race tests, lint, formatting and go mod tidy -diff. Root: 7,262 test/subtest pass records, 2 skips; analytics: 1,555 pass records, no skips. All 105 tested packages pass.
  • The full request-conversion package passes three race-test repetitions. Narrowing the thought guard to require text fails exactly 14 new cases, with the 14 text-bearing controls passing. Removing the guard fails all 28 new cases.
  • The offline integration passes 6/6 scenarios through real Runner/session processing and deterministic model stubs.
  • A clean merge with current main beea418caa2b5cc9417251a37e7ee527ae7f99df passes workspace build and the full request-conversion package under the race detector.

The earlier f281 verification records the original-source regressions and 28 existing mutations. Its separate unmodified-baseline job had a tracing failure; I have not established its cause. The current local module runs above pass.

Payload cases are synthetic converter-shape tests. I have not tested live Gemini/provider acceptance, including output-only transcription parts. Nil-content boundaries and remote-agent conversion remain outside this PR. The upstream CI result above applies to the accepted head; the detailed author-run results refer to 0fa3c4a.

@indurireddy-TF

Copy link
Copy Markdown
Contributor

Hi @jabrailkhalil Thanks for putting together this PR! I verified the changes and confirmed parity with adk-Python. The changes look good and all tests pass successfully.
image
image
image

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

Thanks for checking the Python parity and running the tests!

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

I merged main 733b5257 into fd864faf; the three PR files are unchanged. Fresh Go 1.26.10 validation passes both modules: 8,766 tests/subtests, 2 skips, plus build/lint/format/tidy. The original-source control still fails 20 leaf cases, all 14 mutations are caught, and the offline Runner is 6/6. The description now separates these exact-head results from the earlier hosted run; no live-provider testing is claimed.

@indurireddy-TF
indurireddy-TF requested review from baptmont and removed request for kdroste-google and wojtas000 October 27, 2026 04:02

@karolpiotrowicz karolpiotrowicz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Must change before merge: the four fields now dropped when they stand alone in a part, VideoMetadata, MediaResolution, MediaProcessing and SpeechMetadata, have no test. Nothing fails if one of them is relayed again or a payload field is dropped by mistake.

I checked this against its base and against current main. Build, vet, gofmt and the full test suite give the same results with and without the change. The new tests fail on the base in the 20 cases the description lists and pass with the change. Every payload field of genai.Part in v1.74.0 still reaches the converted event. The fields now dropped when they stand alone (ThoughtSignature, PartMetadata, VideoMetadata, MediaResolution, MediaProcessing, SpeechMetadata) only qualify another payload. A 60-second fuzz run over random part shapes found no case where the stored event was modified, and no case where the result disagreed with "nil exactly when no part carries a payload".

Two related problems sit outside this diff and behave the same on the base, so they fit better as separate issues:

  • Another agent's event with no content at all still becomes the turn boundary under IncludeContents: "none". ConvertForeignEvent returns an event with nil content or zero parts unchanged (contents_processor.go#L801-L803). The skip at L776-L778 therefore does not fire, and the history builder then drops the event at L132-L139. I fed the contents processor a user message followed by another agent's event that carries only a state change, the shape agent.go#L371-L376 builds when an after-agent callback only writes state. The resulting request had no contents at all, with and without this change. It is the same failure as #1894, reached through empty content rather than metadata-only parts.
  • The remote-agent converter still relays these parts. presentAsUserMessage falls through to appending the raw part (remoteagent/v2/utils.go#L268-L270). An empty, signature-only or metadata-only part from another agent still comes out after a "For context:" header there.

This edits the same lines of internal/llminternal/contents_processor.go as #1769, #1913, #1706, #1376, #1360 and #1142, and does not merge cleanly with any of them. Whichever lands second will need a rebase.

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

I added the four requested standalone metadata cases in both normal history and current-turn selection in 045baa8af338, plus attached-metadata preservation checks. Production code is unchanged in this follow-up.

Exact-head validation passes build, vet, full race suites, lint/format and tidy in both modules: 8,774 test/subtest pass records, two existing skips. The original production file fails 28 leaf cases, including the eight new cases; all 22 predicate/retention mutations are caught, and the offline Runner passes 6/6 scenarios.

I retained the initial repeated-package telemetry failure and its captured-seed comparison in the testing plan; I have not established its cause or relaxed its assertions. Live-provider acceptance was not tested. I kept the nil-content boundary and remote-agent converter follow-ups out of this patch.

@karolpiotrowicz
karolpiotrowicz dismissed their stale review October 29, 2026 22:04

Every item in this review is addressed on the current head. The review that follows replaces it.

@karolpiotrowicz karolpiotrowicz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Must change before merge: two gaps in TestConvertForeignEvent_RetainsPayloadParts. Both are about the tests, not the production change.

A payload part with no metadata needs a case again. The latest commit added the four metadata fields to every case, so no case checks any more that ConvertForeignEvent keeps such a part in its output.

A metadata-only part next to a payload part needs a case. The new cases put each metadata-only part alone in its event, so nothing checks that it is also dropped when it sits beside a payload part.

The eight new cases cover the four fields from my earlier review. Each fails against the code before this PR and passes with it. I also cleared VideoMetadata from the part ConvertForeignEvent keeps, and all 14 cases of TestConvertForeignEvent_RetainsPayloadParts failed. The same happens for each of the other three fields. Every test that passes on the code before this PR also passes with it, both on this branch and on its merge with current main.

Signed-off-by: jabrailkhalil <jabrailkhalil@gmail.com>
Signed-off-by: jabrailkhalil <jabrailkhalil@gmail.com>
@karolpiotrowicz
karolpiotrowicz dismissed their stale review November 1, 2026 22:46

Every item this review raised is fixed and verified on the current head.

@karolpiotrowicz karolpiotrowicz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Must change before merge:

  • Add a test that fails when ConvertForeignEvent relays a thought part that carries a payload, including a thought part with no text. The payload kinds are the ones the conversion passes through unchanged, such as InlineData, FileData and ExecutableCode.

The if p.Thought check keeps another agent's private reasoning out of the current agent's context (contents_processor.go lines 810-815 at the PR head (f2810fa)). Before this PR, if the check stopped skipping an empty thought part (Thought: true and nothing else), the default: branch relayed that part. In that case TestConvertForeignEvent/EmptyTextThoughtExcluded and three cases of TestContentsRequestProcessor_ForeignThoughtCurrentTurn failed. With the explicit list of payload kinds (lines 829-833 at the same revision), the empty thought part matches no case and is dropped anyway. No test in internal/llminternal passes a thought part that carries a payload. So if a later edit stops the check skipping thought parts that have no text, another agent's thought payloads reach the current agent and no test fails.

I narrowed the check to skip only thoughts that have text (p.Thought && p.Text != ""). The whole package passes with that change on this branch, and the same change fails those four tests on the code before this PR. With that change, ConvertForeignEvent relayed a thought part with InlineData and no text into the current agent's context.

The two gaps in TestConvertForeignEvent_RetainsPayloadParts from my earlier review are closed. First I changed ConvertForeignEvent to keep a payload part only if it also has a ThoughtSignature or one of the four metadata fields the test sets. The seven cases with neither then failed. Next I changed ConvertForeignEvent to keep metadata-only parts that sit next to a payload part, and all 28 cases failed. The previous version of the test passed both changes.

Every test that passes on the code before this PR also passes on this branch and on its merge with current main.

@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

I added all seven thought-payload variants, with/without text and beside public siblings, in 0fa3c4a. Narrowing the guard fails exactly 14 cases; removing it fails all 28. Both modules pass race tests, build, vet, lint/format and tidy, and the offline Runner passes 6/6. Production code is unchanged. I haven't run live-provider tests.

@karolpiotrowicz
karolpiotrowicz dismissed their stale review November 3, 2026 21:55

Every item this review raised is fixed and verified on the current head.

@karolpiotrowicz karolpiotrowicz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new TestConvertForeignEvent_DropsThoughtPayloadParts closes the gap from my earlier review. It fails if the check that drops another agent's thought parts stops covering any of the seven relayed payload kinds, with or without text.

I ran it with the thought check in ConvertForeignEvent edited three ways at this head (0fa3c4a). Narrowing the check to p.Thought && p.Text != "" makes the 14 cases without text fail, and before this commit no test in the package failed under that edit. Exempting any one of the seven payload kinds fails that kind's four cases, and removing the check fails all 28.

Build, vet and the full test suite show no new failures on this head or on its merge with current main, compared with the code before this PR.

@wolo-lab
wolo-lab merged commit 6caa3b8 into google:main Nov 5, 2026
14 checks passed
wolo-lab added a commit that referenced this pull request Nov 16, 2026
wolo-lab added a commit that referenced this pull request Nov 16, 2026
…, #1748, #2101, #2083, #1895, #2202, #2248) (#2353)

* fix(llminternal): leave ${var} and \{var} placeholders literal (#1682)

* fix(llminternal): leave ${var} and \{var} placeholders literal

InjectSessionState substituted every {name} in an instruction, so text
such as "${expression}" or "\{expression}" either failed the LLM call
with "state key does not exist" or was silently rewritten.

adk-python skips placeholders preceded by $, { or \ via the negative
lookbehind (?<![\$\{\\]). RE2 has no lookbehind, so check the preceding
byte for each match instead, and port adk-python's test cases.

Closes: #1681

* docs(llmagent): name only $ and \ as literal placeholder prefixes

Fix the Config.Instruction doc, which wrongly listed { as a prefix that
keeps a placeholder literal; {{key}} is still substituted. Add the rule
to the GlobalInstruction and instructionutil.InjectSessionState docs.

Drop { from literalPlaceholderPrefixes since {+ always starts a match
at the first brace of a run, and add tests for a leading placeholder
(covers the startIndex > 0 guard) and for {{key}} substitution.

---------

Co-authored-by: Sasha <39381081+jjsasha63@users.noreply.github.com>
(cherry picked from commit d2b12e8)

* fix(llminternal): prevent silent context degradation by propagating systemic state failures (#1748)

(cherry picked from commit ac0388f)

* fix(llminternal): inject text artifacts loaded as inline data into instructions (#2101)

(cherry picked from commit 860c7da)

* fix(llminternal): do not start the current turn at a posted-back tool result (#2083)

(cherry picked from commit e847ba7)

* fix(llminternal): omit metadata-only foreign parts from context (#1895)

(cherry picked from commit 6caa3b8)

* fix(llminternal): show the user's answer to another agent's call as context (#2202)

(cherry picked from commit dba8afa)

* fix(llminternal): look past transfer_to_agent hand-overs for the current turn's start (#2248)

(cherry picked from commit 8662085)

---------

Co-authored-by: Sasha <39381081+jjsasha63@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata-only foreign events hide the user input with IncludeContents: "none"

4 participants