Skip to content

Terminal background-completion turns are sent without instructionContext, so instructions/skills are dropped (regression in 1.131.0) #330561

Closed

Description

@abmahdy

Does this issue occur when all extensions are disabled?

Not applicable — this is in runInTerminalTool / chatServiceImpl in VS Code core, with a contributing short-circuit in the bundled Copilot Chat prompt renderer.

Version

Broken: 1.131.0 (Copilot Chat 0.59.0)
Last known good: 1.127.0 (Copilot Chat 0.55.0)

Steps to Reproduce

  1. In agent mode, start a long-running background terminal command that outlives the turn (e.g. gh pr checks <n> --watch).
  2. Let the turn end while the command is still running. (Sleeping the machine makes this reliable, but sleep is not required — any command finishing after the turn ends will do.)
  3. When the command completes, VS Code auto-sends a system-initiated chat request:
// RunInTerminalTool, onCommandFinished
this._chatService.sendRequest(sessionId,
  `[Terminal ${t} notification: command completed${exit}. …]\nTerminal output:\n${out}`,
  { ...opts, queue: "steering", isSystemInitiated: true, terminalExecutionId: t })
  1. The model replies as if it has no context — e.g. "I'm ready to help — what would you like me to work on?" — and any repo instructions, AGENTS.md, and skills are absent for that turn.

What happens

That auto-sent turn is built without instructions and without the automatic-context pass. Prompt-token composition from one session, three consecutive requests:

request type promptTokens composition
2 user message 152,632 System 23% · Tools 68% · Messages 8% · ToolResults 3%
3 terminal-completion (isSystemInitiated=true) 29,520 Tools 95% · Messages 5% · System 0%
4 user message 177,124 normal

~29K is tool definitions only. Request 4 shows conversation history was never actually lost — only that one turn was blind.

The persisted transcript shows the system-initiated request carrying variableData: { variables: [] }, while the turns on either side carry copilot-instructions.md and AGENTS.md as automaticallyAdded promptFiles.

Root cause

runInTerminalTool.ts captures only four fields when registering the background-completion notification:

// src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts:3035
const sendOptions: { userSelectedModelId?, modeInfo?, userSelectedTools?, agentIdSilent? } = {};
if (lastRequest) {
    sendOptions.userSelectedModelId = lastRequest.modelId;
    sendOptions.modeInfo            = lastRequest.modeInfo;
    sendOptions.agentIdSilent       = lastRequest.response?.agent?.id;
    sendOptions.userSelectedTools   = constObservable(lastRequest.userSelectedTools);
}

instructionContext is not among them. The chat service then bails out early:

// chatServiceImpl.ts:1490
const collectInstructions = async () => {
    const ctx = options?.instructionContext;
    if (!ctx) { return []; }   // ← whole ComputeAutomaticInstructions pass skipped

So no copilot-instructions.md, no AGENTS.md, no .instructions.md, no skills catalog for that request.

This compounds with an intentional short-circuit in the Copilot Chat prompt renderer, which also drops the environment/context body for system-initiated turns:

if (this.props.isSystemInitiated) return <UserMessage>{this.props.request}</UserMessage>;

Net result: the model receives a bare [Terminal … completed] string.

Regression range

Scanned persisted sessions for system-initiated turns:

date version promptTokens verdict
2026-07-20 1.127.0 / copilot 0.55.0 247,512 (Messages 18%) fine
2026-07-28 1.127.0 / 0.55.0 171,125 (Messages 15%) fine
2026-07-30 1.127.0 / 0.55.0 387,255 (Messages 36%) fine — fired 33h after the turn ended
2026-08-10 1.131.0 / 0.59.0 not recorded broken
2026-08-11 1.131.0 / 0.59.0 29,520 broken

Points to 1.131.0 / Copilot Chat 0.59.0.

Suggested fix

Pass instructionContext through, mirroring what chatWidget.ts:2884 does for user-initiated turns:

const sendOptions: {
    userSelectedModelId?: string;
    modeInfo?: IChatRequestModeInfo;
    userSelectedTools?: IObservable<UserSelectedTools>;
    agentIdSilent?: string;
    instructionContext?: IChatSendRequestOptions['instructionContext'];
} = {};
if (lastRequest) {
    …
    // Without this the notification turn runs with no instructions/skills attached.
    sendOptions.instructionContext = {
        modeKind: lastRequest.modeInfo?.kind ?? ChatModeKind.Agent,
        enabledTools: lastRequest.userSelectedTools,
    };
}

One change covers all three call sites (input-needed :3160, completed :3216, terminal-exited :3291) since they all spread sendOptions.

Whether the isSystemInitiated renderer short-circuit should also be relaxed is a separate judgement call for the Copilot Chat side — fixing instructionContext alone restores instructions and skills, which is the bulk of the loss.

Existing issues checked

Searched microsoft/vscode and microsoft/vscode-copilot-release; nothing appears to track this mechanism.

  • microsoft/vscode#328533 — missing confirmation for subagent tool after steering (open, different)
  • microsoft/vscode#327607, #326244, #327387 — other steering-message bugs, all closed pre-1.131
  • vscode-copilot-release#14145 — generic "loses earlier chat context" umbrella, no mechanism identified

Workaround

Run long pollers (--watch and similar) synchronously so they complete inside the turn, or simply re-prompt afterwards — the conversation history is intact; only the auto-sent turn is affected.

Happy to open a PR with the change above if maintainers agree with the direction.

Activity

  1. added
    bug
    chat-terminal
    on Aug 13, 2026
  2. added
    unreleased
    insiders-released
    and removed
    unreleased
    on Aug 13, 2026
  3. locked and limited conversation to collaborators on Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugchat-terminalinsiders-releasedverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions