Skip to content

fix: return full Perplexity responses and reliable completion status - #8

Open
MrJ55 wants to merge 2 commits into
hanzili:mainfrom
MrJ55:fix/response-extraction
Open

fix: return full Perplexity responses and reliable completion status#8
MrJ55 wants to merge 2 commits into
hanzili:mainfrom
MrJ55:fix/response-extraction

Conversation

@MrJ55

@MrJ55 MrJ55 commented Aug 6, 2026

Copy link
Copy Markdown

Fix response extraction truncation + stuck WORKING status

Problem

  1. Truncated answers: getAgentStatus collected every [class*="prose"] block but returned only the last one, so long Perplexity answers came back as their final fragment (e.g. only the last bullet of a multi-section answer).
  2. Stuck WORKING: the completion heuristic matched streaming words ("Working", "Searching", "Analyzing"…) against the whole page body — and the answer text itself often contains those words — so comet_poll never flipped to completed once the answer was done.

Changes (src/comet-ai.ts only)

  • Join all prose blocks with containment dedup (Perplexity nests prose elements; innerText includes descendants) → complete, non-duplicated answers.
  • Raise the response cap 8000 → 30000 chars.
  • Reorder status detection: hasAskFollowUp && hasProseContent && !hasActiveStopButtoncompleted before the working-text branch. ("Ask a follow-up" UI only appears when streaming finished.)
  • Harden against undefined CDP evaluate results (dead tab / navigate race / closed browser) — no more Cannot read properties of undefined (reading 'toUpperCase').

Verification

  • Tested end-to-end against live Perplexity threads (search mode) via the MCP gateway: comet_poll returns the full deduplicated answer; status flips to completed even when the answer text contains streaming words.
  • Manual CDP evaluations confirm status=completed with the complete response length.

Notes

  • dist/ is gitignored; only the TypeScript source is included.

MrJ55 added 2 commits August 6, 2026 10:09
getAgentStatus truncated long answers to their final fragment and could get
stuck reporting WORKING after the answer finished streaming.

Fixes:
- Join ALL [class*="prose"] blocks with containment dedup instead of taking
  only the last element - long answers are returned in full, without
  duplicated nested content.
- Raise the response cap from 8000 to 30000 chars.
- Completion detection: "Ask a follow-up" + prose wins over the
  working-text heuristic, so answers whose text contains words like
  "Working"/"Searching"/"Analyzing" no longer leave comet_poll stuck on
  WORKING.
- Harden getAgentStatus against undefined CDP evaluate results (dead tab,
  navigate race, closed browser) so callers never crash on status.toUpperCase().

Verified end-to-end against live Perplexity threads (search mode) through the
MCP gateway: comet_poll returns the complete, deduplicated answer.
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