Skip to content

🤖 perf: reuse instruction sources during stream startup - #3951

Open
yanncabral wants to merge 1 commit into
coder:mainfrom
yanncabral:yanncabral/reuse-instruction-sources
Open

🤖 perf: reuse instruction sources during stream startup#3951
yanncabral wants to merge 1 commit into
coder:mainfrom
yanncabral:yanncabral/reuse-instruction-sources

Conversation

@yanncabral

Copy link
Copy Markdown

Summary

Load structured instruction sources once during stream startup and reuse that snapshot for both system-message assembly and tool-scoped instruction extraction. Existing buildSystemMessage() and readToolInstructions() wrappers remain available for callers that need load-and-build behavior.

Background

Stream startup previously loaded the same AGENTS.md/instruction sources while building the system message, then loaded them again while extracting tool instructions. Besides duplicate I/O, the two consumers could observe different file contents if instructions changed between reads.

Implementation

  • add pure helpers that assemble a system message and extract tool instructions from an existing InstructionSources value
  • return the loaded snapshot from buildStreamSystemContext() and reuse it for tool extraction
  • thread the snapshot through policy/model-driven system-context rebuilds within the same startup
  • retain the existing loading APIs and source-ordering/scoping behavior

Validation

  • TDD RED: the new stream-context regression initially failed because extractToolInstructionsFromSources was not exported
  • TDD GREEN: focused regression now verifies one snapshot produces both the expected prompt content and bash tool instructions
  • bun test src/node/services/systemMessage.test.ts src/node/services/streamContextBuilder.test.ts src/node/services/aiService.test.ts --timeout 30000 — 150 passed
  • targeted ESLint on all five changed files — passed (split into two invocations after the combined process was OOM-killed)
  • bun run tsgo --noEmit -p tsconfig.main.json — passed
  • Prettier check/write and git diff --check — passed
  • full make typecheck attempted: main-process typecheck passed, broad renderer typecheck was SIGKILL/OOM

Risks

The change touches startup context plumbing. Regression coverage retains the existing system-message matrix for sub-project, multi-project, global/compat, local, model/mode, Xum-only, and tool-scoped semantics, and asserts identity reuse at the AI service boundary.


Generated with xum • Model: openai:gpt-5.6-sol • Thinking: medium • Cost: unknown

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