Skip to content

Save AI chats locally and let users continue them - #37

Open
maun200 wants to merge 3 commits into
mainfrom
feature/ai-chat-history
Open

maun200 wants to merge 3 commits into
mainfrom
feature/ai-chat-history

Conversation

@maun200

@maun200 maun200 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What

The AI chat in the desktop app used to live only in browser memory, so a reload lost everything. Now every conversation is saved locally by the app and can be reopened and continued.

  • New projectzero/chats.py (ChatStore): one JSON file per chat under <config>/chats/<account-key>/<id>.json. Files are 0600 and dirs 0700, writes go through an atomic replace, and ids are validated (^[0-9a-f]{16}$, so paths can't traverse). Corrupt files are skipped.
  • New app endpoints behind the existing session guard: GET/POST /local/chats, GET/PUT/DELETE /local/chats/{id}. They return 409 when not signed in, 404 for unknown ids and 422 for bad bodies (role must be user/assistant, at most 500 messages, content up to 100k chars).
  • UI: a "Previous chats" list (newest first) in the sidebar, "+" for a new chat, "×" to delete (asks first). Opening a chat restores its messages and model. Each question and answer is saved right away. If a reply arrives after you switched chats, it goes into the chat it belongs to.
  • History is kept per account (coordinator URL + name, hashed) and survives sign-out. Chats are never sent to the coordinator, only the last 15 messages go out as context, same as before.
  • Fix: a job status without events (older coordinator) no longer breaks the request with "s.events is undefined".

Tests

  • tests/test_chats.py covers the store: roundtrip, ordering, account isolation, invalid ids and traversal, corrupt files, title trimming, permissions.
  • tests/test_client_app.py::test_chat_history_endpoints covers the endpoints: auth, 404/422 cases, account isolation across logout/login, delete.
  • pytest -q -m "not slow": 262 passed, 3 skipped. scripts/check_public_tree.py: 0 findings.
  • Manual E2E with headless Chromium against projectzero demo: ask twice, reload, reopen, continue, new chat, delete. No page errors, and the files on disk hold the expected message counts.

🤖 Generated with Claude Code

https://claude.ai/code/session_014XvdYnpnYBSTkq2tBgQTA3

maun200 and others added 3 commits November 12, 2026 23:52
One owner-only JSON file per conversation under <config>/chats/<account-key>/,
listed newest first, with create/read/update/delete endpoints behind the
existing session guard. Chats never go to the coordinator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014XvdYnpnYBSTkq2tBgQTA3
The AI chat now lists previous conversations (newest first) under the AI chat
entry, saves after every question and answer, reopens a chat with its model,
and offers New chat / delete. A reply that arrives after switching chats is
stored in the chat it belongs to. Also tolerate job status responses without
lifecycle events (older coordinators) instead of failing the request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014XvdYnpnYBSTkq2tBgQTA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014XvdYnpnYBSTkq2tBgQTA3
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T22:59:09.134569Z 6c155c7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c155c7f02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

s.status==="running"?(lastWorker?t("workingNamed",{worker:lastWorker}):t("working")):pendingText.textContent;
setPendingDots(pendingLine,busy);
pendingTimeline.replaceChildren(...s.events.map(e=>{const{text,cls}=eventLabel(e);
pendingTimeline.replaceChildren(...(s.events||[]).map(e=>{const{text,cls}=eventLabel(e);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard the remaining events read for older coordinators

When a coordinator returns job status without events, renderPending() still spreads s.events before reaching this fallback, so the status poll throws and the request falls into the error path instead of displaying the answer. Apply the empty-list fallback to that earlier read too.

Useful? React with 👍 / 👎.

if(s.status==="failed"||s.status==="cancelled"){setPendingDots(pendingLine,false);pendingText.textContent=t("noAnswer",{reason:s.error||s.status});refreshMe();return}}
setPendingDots(pendingLine,false);pendingText.textContent=t("tooLong")}
catch(e){setPendingDots(pendingLine,false);pendingText.textContent=t("error")+": "+e.message;state.ai.pop()}}
catch(e){setPendingDots(pendingLine,false);pendingText.textContent=t("error")+": "+e.message;conv.messages.pop();saveChat(conv,model)}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep submitted prompts when status polling fails

If the job was accepted but a later status poll fails temporarily, this catch removes the prompt from the conversation and saves the shorter history; if it was the chat’s only prompt, the chat is deleted. The job may still complete and consume credits, leaving the user without the submitted question in local history.

Useful? React with 👍 / 👎.

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