fix(agents): preserve volatile context source order#4457
Merged
Conversation
Contributor
Contributor
Electric Agents Mobile BuildAndroid preview build for commit
|
kevin-dp
approved these changes
Jun 2, 2026
Contributor
kevin-dp
left a comment
There was a problem hiding this comment.
This is changing the configuration of several CI workflows that seem unrelated to the goal of this PR.
kevin-dp
reviewed
Jun 2, 2026
Add at-value assertions, three-source ordering test, and end-to-end integration test wiring timelineMessages SIGINT reorder through assembleContext. Remove explanatory comment per project conventions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4d135d7 to
8c57408
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remove a global
.sort()byattimestamp inassembleContext()that was undoing the semantic reordering performed byreorderInterruptedRuns(). When SIGINT races ahead of buffered runtime writes, the interrupted assistant run now correctly appears before the interrupt marker in the model transcript.Root Cause
assembleContext()collected volatile messages from all sources, then globally sorted them by theirat(stream offset) value. Meanwhile,reorderInterruptedRuns()in the timeline layer intentionally reorders aborted runs before the SIGINT signal that raced ahead of them—giving the model a coherent transcript where the partial response precedes the interruption.The global sort undid this reordering: the SIGINT (lower offset, because it's appended directly by the server) was placed before the aborted run output (higher offset, because it's buffered through the runtime producer). The model then saw an interruption marker before any assistant output, breaking transcript coherence.
Approach
Remove the
volatileMessages.sort()call entirely. Volatile sources already return messages in their intended order—timelineMessages()projects throughmaterializeTimeline()→reorderInterruptedRuns()to produce the correct model-facing sequence. Theatfield is preserved as metadata for budget truncation ranges and load tools, but no longer drives global ordering.Key invariant: volatile messages appear in source-registration order (all messages from source A, then all from source B, etc.), with each source's internal order preserved exactly as returned.
Trade-off: budget truncation under pressure now drops messages from earlier-registered sources first (instead of oldest-by-timestamp first). This is the intended behavior—source ordering is more semantically meaningful than raw stream offsets.
Non-goals
2a95b8a17) is bundled here but independent—it adds CODEOWNERS for.github/, fork-PR guards on benchmarking/load-test workflows, and least-privilege permission tightening.Verification
cd packages/agents-runtime pnpm vitest run test/use-context-volatile-interleave.test.ts pnpm vitest run test/timeline-context.test.tsFiles changed
packages/agents-runtime/src/context-assembly.tsvolatileMessages.sort()callpackages/agents-runtime/test/use-context-volatile-interleave.test.tsatassertions, three-source ordering test, and end-to-end integration test wiringmaterializeTimelinethroughassembleContext.github/CODEOWNERS.github/changes.github/workflows/benchmarking.yml.github/workflows/load_test.yml.github/workflows/ts_tests.ymlpackages: write→read.github/workflows/changesets_release.ymlcache: pnpmfrom setup-node.changeset/fix-sigint-context-order.md@electric-ax/agents-runtimepatch