Skip to content

fix(agents): preserve volatile context source order#4457

Merged
KyleAMathews merged 4 commits into
mainfrom
fix/sigint-context-order
Jun 2, 2026
Merged

fix(agents): preserve volatile context source order#4457
KyleAMathews merged 4 commits into
mainfrom
fix/sigint-context-order

Conversation

@KyleAMathews
Copy link
Copy Markdown
Contributor

@KyleAMathews KyleAMathews commented Jun 1, 2026

Summary

Remove a global .sort() by at timestamp in assembleContext() that was undoing the semantic reordering performed by reorderInterruptedRuns(). 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 their at (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 through materializeTimeline()reorderInterruptedRuns() to produce the correct model-facing sequence. The at field 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

  • The CI hardening commit (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.ts

Files changed

File Change
packages/agents-runtime/src/context-assembly.ts Remove volatileMessages.sort() call
packages/agents-runtime/test/use-context-volatile-interleave.test.ts Update existing test expectations, add at assertions, three-source ordering test, and end-to-end integration test wiring materializeTimeline through assembleContext
.github/CODEOWNERS Require admin review for .github/ changes
.github/workflows/benchmarking.yml Drop CONTRIBUTOR from trigger, add fork-PR guard
.github/workflows/load_test.yml Add fork-PR guard
.github/workflows/ts_tests.yml Downgrade packages: writeread
.github/workflows/changesets_release.yml Remove cache: pnpm from setup-node
.changeset/fix-sigint-context-order.md Changeset for @electric-ax/agents-runtime patch

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Electric Agents Desktop Builds

Build artifacts for commit 8c57408.

Platform Status Artifact
macOS Apple Silicon Passed DMG
macOS Intel Passed DMG
Windows x64 Passed Installer
Linux x64 Passed AppImage / deb

Workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Electric Agents Mobile Build

Android preview build for commit 8c57408.

Platform Profile Status Build
Android preview Passed EAS build

Workflow run

Copy link
Copy Markdown
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

This is changing the configuration of several CI workflows that seem unrelated to the goal of this PR.

Comment thread .github/workflows/changesets_release.yml
KyleAMathews and others added 4 commits June 2, 2026 15:30
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>
@kevin-dp kevin-dp force-pushed the fix/sigint-context-order branch from 4d135d7 to 8c57408 Compare June 2, 2026 13:31
@KyleAMathews KyleAMathews merged commit 1a7d72e into main Jun 2, 2026
17 checks passed
@KyleAMathews KyleAMathews deleted the fix/sigint-context-order branch June 2, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants