-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor(history): store task history in external file #8524
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found some issues that need attention. See inline comments.
| try { | ||
| const taskHistoryUri = vscode.Uri.joinPath(this.globalStorageUri, "taskHistory.jsonl") | ||
| const fileContent = await vscode.workspace.fs.readFile(taskHistoryUri) | ||
| const lines = fileContent.toString().split("\n").filter(Boolean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P0: fileContent is a Uint8Array; calling toString() returns "[object Uint8Array]" in Node, breaking JSONL parsing and causing an empty history. Decode the buffer first.
| const lines = fileContent.toString().split("\n").filter(Boolean) | |
| const lines = new TextDecoder("utf-8").decode(fileContent).split("\n").filter(Boolean) |
| try { | ||
| const taskHistoryUri = vscode.Uri.joinPath(this.globalStorageUri, "taskHistory.jsonl") | ||
| const content = tasks.map((task) => JSON.stringify(task)).join("\n") + "\n" | ||
| await vscode.workspace.fs.writeFile(taskHistoryUri, Buffer.from(content)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Atomicity/consistency: writing directly to the final file risks partial writes and bypasses our atomic write conventions. If we keep JSONL, write to a temp file then rename to the target to approximate an atomic replace.
| await vscode.workspace.fs.writeFile(taskHistoryUri, Buffer.from(content)) | |
| const tmpUri = vscode.Uri.joinPath(this.globalStorageUri, "taskHistory.jsonl.tmp") | |
| await vscode.workspace.fs.writeFile(tmpUri, Buffer.from(content)) | |
| await vscode.workspace.fs.rename(tmpUri, taskHistoryUri, { overwrite: true }) |
| }, | ||
| workspace: { | ||
| fs: { | ||
| readFile: vi.fn().mockRejectedValue(Object.assign(new Error("FileNotFound"), { code: "FileNotFound" })), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Missing positive-path coverage: readFile is always mocked to reject, so readTaskHistoryFile's success path (decoding and parsing JSONL) is never exercised. Add a test case that resolves readFile with a valid Uint8Array (e.g., new TextEncoder().encode('{"id":"1"}\n')) and assert that taskHistory is populated.
temporary, this is for Hannes to try out