Skip to content

[Agent Chat feedback] - Step 4: Share one loopback server between agent channels - #3610

Draft
zeroliu wants to merge 1 commit into
zeroliu/grill-issue-672from
zeroliu/loopback-server-helper
Draft

zeroliu wants to merge 1 commit into
zeroliu/grill-issue-672from
zeroliu/loopback-server-helper

Conversation

@zeroliu

@zeroliu zeroliu commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Relates to Brevilabs/obsidian-copilot-private#672

Why

Copilot now runs two local-only HTTP servers on 127.0.0.1 that agents call back into: the self-host web search bridge (#165) and the feedback MCP server this stack adds. Each one hand-writes the same setup: listen on a random port without keeping Obsidian alive, settle a pending start when the plugin closes first, read a capped request body, and write JSON replies. The two copies have already drifted. The feedback server caps its body at 64 KiB of UTF-8 bytes, while the search bridge counts characters, so a search body of 30,000 CJK characters (about 90 KB) passes a cap meant to stop at 64 KiB.

What

Both servers run on one shared implementation, so a lifecycle or size-cap fix lands once.

Situation Before After
Agent sends a search body over 64 KiB of UTF-8 but under 65,536 characters Accepted and sent to the search provider 413 "Request body is too large.", no provider call
Plugin closes while either server is still starting Pending start fails with "…is closed." Same
Any other request to either server Current status codes and bodies Same

Non goal

  • Changing either server's routes, auth, or replies.
  • Changing the 64 KiB limit itself.
  • Moving any other Copilot HTTP code onto the helper.

Screenshot

Not applicable: this PR changes local server plumbing with no rendered change.

Risk

High

Criterion Status Reason
No behavior change, or a cosmetic/copy/docs/config change visible where it renders, or deterministic tests cover the changed behavior ✅ loopbackServer tests cover serving, close-before-listen, close-after-listen, split UTF-8 chunks and the byte cap; the existing search-bridge and feedback-server suites run both servers end to end, now including a 90 KB CJK search body
A defect would fail CI or be obvious on first use ✅ Both servers' suites run real loopback HTTP in CI
A revert fully restores prior state, including persisted data ✅ Nothing is persisted
No auth, permissions, secrets, or input-handling surface changes ❌ Moves request-body reading for two agent-facing endpoints into shared code, and tightens the search bridge's size cap
No public API, plugin API, message, or on-disk contract changes ✅ Both servers' wire behavior is unchanged apart from the size cap
No core-path concurrency, async-lifecycle, or state-machine changes ❌ Server start and close move into the helper
No hot-path behavior lacks deterministic coverage ✅ Every lifecycle path of the helper has a test
No new dependency ✅ Dependency manifests are unchanged
Human-only behavior stays in one feature area and surfaces quickly ✅ A broken server shows on the first self-host search or feedback card

Review: inspect startLoopbackServer and readRequestText in src/utils/loopbackServer.ts, createSelfHostWebSearchAgentBridge and handleAgentSearchRequest in src/LLMProviders/selfHostServices.ts, and createFeedbackMcpServer in src/agentMode/session/feedback/feedbackMcpServer.ts, line by line. Then run Verification.

Verification

  1. Install this build in a test vault with self-host mode on, a search key set, and OpenCode configured.
  2. In an OpenCode Agent Chat, ask a question that needs a web search; the answer cites search results as before.
  3. In the same chat, tell the agent its last answer was wrong and that you are frustrated; a feedback card appears as in the previous step.
  4. Disable and re-enable the Copilot plugin, then repeat steps 2 and 3; both still work, and no error about a closed server appears in the Copilot log.

@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
obsidian-copilot-docs Ignored Ignored Oct 14, 2026 10:11pm UTC

Request Review

@zeroliu

zeroliu commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T21:55:40.195299Z b823c86 Manual request
ℹ️ 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.

@zeroliu
zeroliu added this pull request to stack #3595 October 13, 2026 21:52
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: b823c8656a

ℹ️ 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".

@zeroliu
zeroliu force-pushed the zeroliu/loopback-server-helper branch from b823c86 to c078242 Compare October 14, 2026 21:50
The feedback MCP server and the self-host web search bridge each hand-wrote
the same 127.0.0.1 server: lazy listen, unref, settling a pending start on
close, a capped body read, and JSON responses. Both now use
startLoopbackServer, readRequestText and writeJson. The search bridge's body
cap now counts UTF-8 bytes instead of UTF-16 characters, like the feedback
server's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zeroliu
zeroliu force-pushed the zeroliu/loopback-server-helper branch from c078242 to ae48e14 Compare October 14, 2026 22:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant