Skip to content

fix(tarko): prevent unnecessary environment_input events without contextual references#1301

Merged
ulivz merged 5 commits intomainfrom
fix/environment-input-contextual-references
Aug 29, 2025
Merged

fix(tarko): prevent unnecessary environment_input events without contextual references#1301
ulivz merged 5 commits intomainfrom
fix/environment-input-contextual-references

Conversation

@ulivz
Copy link
Member

@ulivz ulivz commented Aug 29, 2025

Summary

Fixes bug where environment_input events were generated for every user message, even when no @file or @dir contextual references were present.

Problem

  • AgentServer always passed environmentInput to Agent.run(), causing unnecessary events
  • No way to detect if contextual references actually existed
  • Wasted context and duplicate content in event streams

Solution

Simplified ContextReferenceProcessor interface:

// Returns expanded context only when references exist
processContextualReferences(query): Promise<string | null>

Updated controller logic:

const expandedContext = await processor.processContextualReferences(query, workspace);
const runOptions = {
  input: compressedQuery,
  ...(expandedContext && {
    environmentInput: { content: expandedContext, ... }
  })
};

Benefits

  • Only generates environment_input events when contextual references exist
  • Cleaner API with simple string | null return type
  • Proper detection of contextual references
  • Reduced code complexity

Checklist

  • Added or updated necessary tests
  • All tests passing
  • No breaking changes

@netlify
Copy link

netlify bot commented Aug 29, 2025

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit 83bb7f2
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/68b1e550286cb20008f59d33
😎 Deploy Preview https://deploy-preview-1301--agent-tars-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

ulivz added 4 commits August 30, 2025 01:10
…from query

Breaking change: ContextReferenceProcessor.processContextualReferences now returns
{ expandedContext, originalQuery } instead of merged string. This fixes the design
flaw where context and query were incorrectly combined.

- Fixed environment_input only sent when actual contextual references exist
- Improved conditional logic using expandedContext truthiness check
- Updated all tests to match new interface
- Better separation of concerns between context and user input
…readability

- Extracted common test helpers and mock setup
- Used vi.hoisted for proper mock initialization
- Reduced test file size by ~50% while maintaining coverage
- More focused test cases with better naming
Update all test snapshots to match the new return format:
{ expandedContext, originalQuery } instead of merged string

- Fixed 14 test cases in context-reference-processor.test.ts
- All tests now pass with new interface design
- Maintains full test coverage for error handling and edge cases
Remove redundant originalQuery return value - caller already has the query!

- Changed return type from { expandedContext, originalQuery } to string | null
- Only return expanded context when @file/@dir references exist
- Updated all tests to match simplified interface
- Eliminates pointless data duplication in API

Much cleaner design - no more 脱裤子放屁 anti-pattern!
@ulivz ulivz merged commit e394343 into main Aug 29, 2025
10 checks passed
@ulivz ulivz deleted the fix/environment-input-contextual-references branch August 29, 2025 17:45
@ulivz ulivz changed the title fix(tarko): prevent unnecessary environment_input events without contextual references fix(tarko): prevent unnecessary environment_input events without contextual references Aug 29, 2025
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.

1 participant

Comments