fix(server): hide browser-context scaffolding in the new-tab agent chat#1095
fix(server): hide browser-context scaffolding in the new-tab agent chat#1095Nikhil (shadowfax92) wants to merge 1 commit into
Conversation
The new-tab Agents chat renders the active turn's prompt as the user bubble. For sidepanel-initiated turns that prompt is the wrapped formatUserMessage output, so the bubble leaked the '## Browser Context … <USER_QUERY>…</USER_QUERY>' scaffolding while the side panel showed the clean query. getActiveTurn now unwraps the prompt on read via the canonical unwrapBrowserosAcpUserMessage — the same read-time strip getHistory and extractLastUserMessage already apply. Fixes the leak for every /chat/active consumer without duplicating logic or touching the LLM input.
|
Greptile (@greptileai) review |
|
Claude (@claude) review |
|
Claude finished Nikhil (@shadowfax92)'s task in 1m 27s —— View job Code Review
Overall: LGTM — clean, minimal, well-targeted fix. The approach is sound: read-time normalization at the Implementation (
|
✅ Tests passed — 1105/1110
|
Greptile SummaryThis PR fixes a UX bug where the new-tab Agents chat displayed raw browser-context scaffolding (
Confidence Score: 5/5Safe to merge — the change is a small, well-scoped read-time transformation at a single boundary, and the stored prompt is left untouched. The fix is a one-liner that reuses the existing, well-tested unwrapBrowserosAcpUserMessage helper; the null/empty/clean guard is correct; and three targeted unit tests confirm all edge cases. No LLM prompt content, stored state, or existing read paths are affected. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as New-Tab Agent UI
participant Route as GET /chat/active
participant Service as AgentHarnessService
participant Registry as TurnRegistry
participant Helper as unwrapBrowserosAcpUserMessage
UI->>Route: "GET /chat/active?agentId=…"
Route->>Service: getActiveTurn(agentId)
Service->>Registry: getActiveFor(agentId, 'main')
Registry-->>Service: "ActiveTurn (status=running)"
Service->>Registry: describe(turnId)
Registry-->>Service: "ActiveTurnInfo { prompt: "## Browser Context…<USER_QUERY>question</USER_QUERY>" }"
Service->>Helper: unwrapBrowserosAcpUserMessage(prompt)
Helper-->>Service: "question"
Service-->>Route: "{ …, prompt: "question" }"
Route-->>UI: ActiveTurnInfo (clean prompt)
UI->>UI: Render user bubble with "question"
Reviews (1): Last reviewed commit: "fix(server): strip browser-context scaff..." | Re-trigger Greptile |
Greptile SummaryThis PR fixes a UI bug where the new-tab Agents chat leaked the raw
Confidence Score: 5/5Safe to merge — the change is a small, isolated read-time normalisation with no effect on the prompt sent to the LLM or on history/listing paths. The fix reuses an already-tested, idempotent helper and adds correct null guards. Three new unit tests cover the wrapped, null, and clean-prompt cases. The affected scope is a single method on a single read boundary, and the stored data is never mutated. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as New-Tab Agent UI
participant Route as /chat/active Route
participant Service as AgentHarnessService
participant Registry as TurnRegistry
participant Helper as unwrapBrowserosAcpUserMessage
UI->>Route: GET /chat/active (agentId)
Route->>Service: getActiveTurn(agentId)
Service->>Registry: getActiveFor(agentId, 'main')
Registry-->>Service: ActiveTurn (or null)
Service->>Registry: describe(turn.turnId)
Registry-->>Service: "ActiveTurnInfo { prompt: "## Browser Context…<USER_QUERY>…" }"
Service->>Helper: unwrapBrowserosAcpUserMessage(prompt)
Helper-->>Service: "clean user query"
Service-->>Route: "{ ...info, prompt: "clean user query" }"
Route-->>UI: ActiveTurnInfo (clean prompt)
UI->>UI: Renders clean user bubble
Reviews (2): Last reviewed commit: "fix(server): strip browser-context scaff..." | Re-trigger Greptile |
Summary
## Browser Context … <USER_QUERY>…</USER_QUERY>prompt scaffolding in the user-message bubble, while the side panel showed only the clean query (see before/after below).prompt(fromGET /chat/active). For side-panel-initiated turns that stored prompt is the wrappedformatUserMessageoutput, andgetActiveTurnreturned it verbatim — the one read path that didn't strip.getActiveTurnnow unwraps the prompt on read via the canonicalunwrapBrowserosAcpUserMessage, the same read-time stripgetHistoryandextractLastUserMessagealready apply.Design
Read-time normalization in
AgentHarnessService.getActiveTurn, mirroring howgetHistoryde-scaffolds on read. The genericTurnRegistrykeeps storing the faithful prompt (no layering violation), and the canonical unwrap helper is reused with zero duplicated logic. The change touches only the/chat/activeread boundary — never the prompt sent to the LLM, and not the already-correct history/listing paths. Anullprompt passes through unchanged, and the helper is idempotent so already-clean (new-tab-initiated) prompts are untouched.Test plan
agent-harness-service.test.ts:## Browser Context … <USER_QUERY>prompt surfaces viagetActiveTurnas the clean inner query;nullprompt passes through;bun testacross service + acpx-runtime + agents-route suites: 66/66 pass.bunx biome checkclean;tsc --noEmitexit 0.Out of scope
userSystemPrompt(pre-existing limitation shared withgetHistory; the^## Browser Contextanchor won't match behind a prefix).🤖 Generated with Claude Code