Repository navigation
fix(chat): add bounded diagnostics for conversation fallbacks #2292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devswha
merged 6 commits into
devswha:main
from
YuuuXie:fix/copilot-unavailable-diagnostics
Oct 28, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10ca4c2
fix: diagnose conversation fallbacks without exposing private state
edb82ec
fix(diagnostics): keep shell panes out of the failure log and episode…
devswha 44ef36f
fix(chat): distinguish peer conflicts in Copilot handoffs
2fe076f
fix(chat): retain maintainer corrections to bounded diagnostic episodes
2ddad70
fix(diagnostics): report an agent pane without a folder instead of tr…
devswha 063afe4
chore(diagnostics): preserve maintainer missing-folder classification
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Maintenance | ||
| - Conversation fallbacks and recoveries now emit sanitized, rate-limited diagnostic episodes, | ||
| including the failed Copilot identity stage without logging session IDs or transcript paths. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { expect, it, spyOn } from "bun:test"; | ||
| import { ConversationDiagnostics } from "./conversation-diagnostics.ts"; | ||
| import { COPILOT_UNAVAILABLE_REASONS, ConversationReadPending, ConversationUnavailable } from "./conversation-shared.ts"; | ||
|
|
||
| function fixture() { | ||
| let now = 0; | ||
| const lines: string[] = []; | ||
| const diagnostics = new ConversationDiagnostics((line) => lines.push(line), () => now); | ||
| return { diagnostics, lines, records: () => lines.map((line) => JSON.parse(line)), advance: (ms: number) => { now += ms; } }; | ||
| } | ||
|
|
||
| it("logs only fixed failure stages and opaque request correlation, never exception or pane contents", () => { | ||
| const { diagnostics, records, lines } = fixture(); | ||
| const secret = "/private/session-token\ntranscript"; | ||
| const error = new ConversationUnavailable(secret, undefined, "copilot_process_lookup_failed"); | ||
| Object.assign(error, { path: secret, sessionId: secret }); | ||
| diagnostics.unavailable(secret, error, "00000000-0000-4000-8000-000000000001"); | ||
| diagnostics.unavailable("other pane", new ConversationUnavailable(secret), secret); | ||
| expect(records()[0]).toMatchObject({ | ||
| event: "conversation.failed", operation: "conversation.copilot_process_lookup_failed", | ||
| code: "conversation_unavailable", request_id: "00000000-0000-4000-8000-000000000001", | ||
| }); | ||
| expect(records()[1]).toMatchObject({ operation: "conversation.unknown" }); | ||
| expect(records()[1].request_id).toBeUndefined(); | ||
| expect(lines.join("\n")).not.toContain("private"); | ||
| expect(lines.join("\n")).not.toContain("session-token"); | ||
| }); | ||
|
|
||
| it("coalesces repeated reasons and rapid recoveries without losing the episode correlation", () => { | ||
| const { diagnostics, records, advance } = fixture(); | ||
| for (let i = 0; i < 100; i++) { | ||
| diagnostics.unavailable("pane", new ConversationUnavailable("no_session_path")); | ||
| diagnostics.recovered("pane"); | ||
| } | ||
| expect(records()).toHaveLength(2); | ||
| expect(records()[1]).toMatchObject({ event: "conversation.recovered", episode_id: records()[0].episode_id }); | ||
| advance(30_000); | ||
| diagnostics.unavailable("pane", new ConversationReadPending()); | ||
| expect(records()[2]).toMatchObject({ | ||
| operation: "conversation.read_pending", code: "conversation_read_pending", failures: 100, suppressed: 99, | ||
| }); | ||
| }); | ||
|
|
||
| it("bounds output even when pane keys rotate past the retained episode limit", () => { | ||
| const { diagnostics, records, advance } = fixture(); | ||
| for (let i = 0; i < 300; i++) diagnostics.unavailable(`pane-${i}`, new ConversationUnavailable("no_session_id")); | ||
| expect(records()).toHaveLength(16); | ||
| advance(30_000); | ||
| diagnostics.recovered("pane-299"); // its failure was never shown: no orphan recovery | ||
| diagnostics.recovered("pane-0"); // retired with the oldest keys: nothing left to close | ||
| expect(records()).toHaveLength(16); | ||
| diagnostics.unavailable("new-pane", new ConversationUnavailable("no_session_id")); | ||
| expect(records()).toHaveLength(17); | ||
| }); | ||
|
|
||
| it("keeps episodes apart while the line budget is spent", () => { | ||
| const { diagnostics, records, advance } = fixture(); | ||
| for (let i = 0; i < 16; i++) diagnostics.unavailable(`pane-${i}`, new ConversationUnavailable("no_session_path")); | ||
| diagnostics.recovered("pane-0"); // no line left in this window, but the episode still ends | ||
| expect(records()).toHaveLength(16); | ||
| advance(30_000); | ||
| diagnostics.unavailable("pane-0", new ConversationUnavailable("no_session_path")); | ||
| expect(records()[16]).toMatchObject({ event: "conversation.failed", failures: 1 }); | ||
| expect(records()[16].episode_id).not.toBe(records()[0].episode_id); | ||
| }); | ||
|
|
||
| it("keeps an agent pane without a folder in its failure episode", () => { | ||
| const { diagnostics, records, advance } = fixture(); | ||
| diagnostics.unavailable("copilot", new ConversationUnavailable("no_session_path", undefined, "copilot_process_lookup_failed")); | ||
| diagnostics.unavailable("copilot", new ConversationUnavailable("no_recognized_transcript", undefined, "agent_cwd_missing")); | ||
| advance(30_000); | ||
| diagnostics.unavailable("copilot", new ConversationUnavailable("no_recognized_transcript", undefined, "agent_cwd_missing")); | ||
| expect(records().map((record) => record.event)).toEqual(["conversation.failed", "conversation.failed"]); | ||
| expect(records()[1]).toMatchObject({ operation: "conversation.agent_cwd_missing", episode_id: records()[0].episode_id, failures: 3 }); | ||
| }); | ||
|
|
||
| it("does not count a pane without an agent conversation as a failure", () => { | ||
| const { diagnostics, records } = fixture(); | ||
| for (let i = 0; i < 50; i++) diagnostics.unavailable(`shell-${i}`, new ConversationUnavailable("no_recognized_transcript")); | ||
| expect(records()).toEqual([]); | ||
| diagnostics.unavailable("copilot", new ConversationUnavailable("no_session_path", undefined, "copilot_process_lookup_failed")); | ||
| diagnostics.unavailable("copilot", new ConversationUnavailable("no_recognized_transcript")); // its agent left: the episode ends | ||
| expect(records().map((record) => record.event)).toEqual(["conversation.failed", "conversation.recovered"]); | ||
| }); | ||
|
|
||
| it("keeps the logging interval monotonic across wall-clock corrections", () => { | ||
| const { diagnostics, records, advance } = fixture(); | ||
| const wall = spyOn(Date, "now").mockReturnValue(100_000); | ||
| try { | ||
| diagnostics.unavailable("pane", new ConversationUnavailable("no_session_path")); | ||
| wall.mockReturnValue(1); | ||
| advance(29_999); | ||
| diagnostics.unavailable("pane", new ConversationUnavailable("no_session_path")); | ||
| expect(records()).toHaveLength(1); | ||
| advance(1); | ||
| diagnostics.unavailable("pane", new ConversationUnavailable("no_session_path")); | ||
| expect(records()).toHaveLength(2); | ||
| } finally { wall.mockRestore(); } | ||
| }); | ||
|
|
||
| it("accepts every code-owned Copilot diagnostic without accepting a forged stage", () => { | ||
| const { diagnostics, records } = fixture(); | ||
| for (const diagnostic of COPILOT_UNAVAILABLE_REASONS) { | ||
| diagnostics.unavailable(diagnostic, new ConversationUnavailable("no_session_path", undefined, diagnostic)); | ||
| } | ||
| const forged = new ConversationUnavailable("no_session_path"); | ||
| Object.defineProperty(forged, "diagnostic", { value: "private-token" }); | ||
| diagnostics.unavailable("forged", forged); | ||
| expect(records().map((record) => record.operation)).toEqual([ | ||
| ...COPILOT_UNAVAILABLE_REASONS.map((reason) => `conversation.${reason}`), "conversation.unknown", | ||
| ]); | ||
| }); | ||
|
|
||
| it("does not change response handling when its writer fails", () => { | ||
| const diagnostics = new ConversationDiagnostics(() => { throw new Error("log unavailable"); }); | ||
| expect(() => diagnostics.unavailable("pane", new ConversationReadPending())).not.toThrow(); | ||
| expect(() => diagnostics.recovered("pane")).not.toThrow(); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { ConnectionDiagnostics } from "./connection-diagnostics.ts"; | ||
| import { UNAVAILABLE_DIAGNOSTICS, ConversationReadPending, ConversationUnavailable } from "./conversation-shared.ts"; | ||
|
|
||
| const REASONS = [ | ||
| ...UNAVAILABLE_DIAGNOSTICS, "branch_unreadable", "transcript_missing", "no_session_path", | ||
| "no_session_id", "no_recognized_transcript", "pane_not_found", "session_not_written", "copilot_resume_unknown", | ||
| ]; | ||
| /** A pane with no agent conversation (a plain shell): its scrollback is the expected view, not a failure. */ | ||
| const EXPECTED = new Set(["no_recognized_transcript"]); | ||
| const INTERVAL_MS = 30_000; | ||
| const MAX_LINES = 16; | ||
|
|
||
| /** Keys stay private; only fixed reasons and server-generated request IDs leave the process. */ | ||
| export class ConversationDiagnostics { | ||
| private readonly episodes: ConnectionDiagnostics; | ||
| private windowAt = -Infinity; | ||
| private lines = 0; | ||
|
|
||
| constructor(write: (line: string) => void = (line) => console.warn(line), private now: () => number = () => performance.now()) { | ||
| // The budget bounds the output only: episodes still open and close while it is spent. | ||
| this.episodes = new ConnectionDiagnostics("conversation", (line) => { | ||
| if (!this.available()) return false; | ||
| this.lines++; | ||
| write(line); | ||
| return true; | ||
| }, () => performance.timeOrigin + now()); | ||
| } | ||
|
|
||
| private available(): boolean { | ||
| const at = this.now(); | ||
| if (at - this.windowAt >= INTERVAL_MS) { this.windowAt = at; this.lines = 0; } | ||
| return this.lines < MAX_LINES; | ||
| } | ||
|
|
||
| unavailable(key: string, error: ConversationUnavailable | ConversationReadPending, requestId?: string): void { | ||
| if (error instanceof ConversationUnavailable && error.diagnostic === undefined && EXPECTED.has(error.message)) { | ||
| this.recovered(key, requestId); | ||
| return; | ||
| } | ||
| const pending = error instanceof ConversationReadPending; | ||
| const reason = pending ? "read_pending" : REASONS.find((reason) => reason === (error.diagnostic ?? error.message)) ?? "unknown"; | ||
| this.episodes.failed(key, pending ? "conversation_read_pending" : "conversation_unavailable", { | ||
| operation: `conversation.${reason}`, request_id: requestId, | ||
| }); | ||
| } | ||
|
|
||
| recovered(key: string, requestId?: string): void { | ||
| this.episodes.recovered(key, { operation: "conversation", request_id: requestId }); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.