Fix agent reply targeting: use mention post ID instead of root post ID#6
Closed
Fix agent reply targeting: use mention post ID instead of root post ID#6
Conversation
Merged
Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix potential bug regarding reply target in grok.ts
Fix agent reply targeting: use mention post ID instead of root post ID
Jan 28, 2026
groupthinking
approved these changes
Feb 6, 2026
groupthinking
approved these changes
Feb 6, 2026
| @@ -61,12 +62,12 @@ export class GrokService { | |||
| const data: any = await response.json(); | |||
There was a problem hiding this comment.
Unexpected any. Specify a different type.
This was referenced Feb 9, 2026
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
Addresses unresolved review comments from PRs #6, #13, #25, #26: - src/index.ts: Add console.log→stderr redirect with unknown[] type - src/services/xapi.ts: Use URLSearchParams, add Array.isArray guard, add since_id pagination, use unknown type, avoid mutating sort - src/services/agent.ts: Add bounded memory pruning with safe iterator, process mentions oldest-first for chronological ordering - .github/workflows: Add permissions blocks, check labels exist before adding, use pull_request_target for fork PR support - README.md: Add Contributing section with absolute paths - Add CONTRIBUTING.md, PR_TITLE_GUIDE.md, pull_request_template.md Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
PR #26 fixes (with review feedback incorporated): - Redirect console.log to stderr for MCP stdout (unknown[] type) - Use URLSearchParams for mentions URL + wire up since_id - Add Array.isArray() guard in fetchThread - Copy tweets array before sorting + unknown type in parseThread - Cap processedMentions with safe {value, done} iterator - Process mentions oldest-first for chronological pruning PR #6 fix (with review feedback): - Add mentionPostId param to analyzeAndDecide for reply targeting - Replace any type with specific type in Grok response parsing Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
… safety, Array.isArray guards, Set pruning Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
This was referenced Feb 9, 2026
Closed
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
…rams, Array.isArray guards, safe iterators, chronological pruning, README fixes Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
…RLSearchParams, Array.isArray guard, safe iterators, reply targeting Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
This commit applies all actionable review feedback from multiple pending PRs: ## PR #26 - Console.log redirect and type improvements - Added console.log redirect to stderr in main() to prevent MCP protocol conflicts - Used unknown[] instead of any[] for type safety - Refactored fetchMentions() to use URLSearchParams for cleaner URL construction - Added lastMentionId tracking for efficient pagination - Added Array.isArray guard in fetchThread() for safer data handling - Changed parseThread() to use proper typed parameters and copy array before sort ## PR #6 - Pass mention post ID for accurate replies - Added mentionPostId parameter to analyzeAndDecide() and simulateAnalysis() - Updated all callers to pass mention.post.id - Fixed response.json() type with proper type assertion - Fixed parseGrokResponse to use mentionPostId instead of root_post.id - Updated examples.ts to pass mention.post.id ## PR #13 - GitHub Actions workflows with review feedback - Created .github/workflows/auto-label.yml for PR auto-labeling - Created .github/workflows/pr-checks.yml for CI builds - Created .github/workflows/issue-triage.yml for automatic issue triage - Created .github/labeler.yml configuration for auto-labeling - All workflows use secure permissions and latest action versions ## Additional improvements from review feedback - Added MAX_PROCESSED_MENTIONS constant (10000) to prevent unbounded memory growth - Reversed mention processing order (oldest-first) for better chronological handling - Added safe pruning logic using iterator pattern to cap Set size - Improved type safety throughout with unknown[] and proper type assertions All changes compile successfully with TypeScript. No tests to run.
This was referenced Feb 9, 2026
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
- xapi.ts: Use URLSearchParams for mentions URL with since_id support - xapi.ts: Add Array.isArray() guard before parseThread() in fetchThread - xapi.ts: Add Array.isArray() guard in searchTweets - xapi.ts: Change any to unknown in parseThread parameter type - agent.ts: Process mentions oldest-first and add safe iterator pruning - grok.ts: Replace any with typed response, fix as any cast - auto-label.yml: Add permissions: pull-requests: write - issue-triage.yml: Add permissions: issues: write - pr-checks.yml: Add permissions: pull-requests: write, fix syntax check - README.md: Fix double space and improve wording Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
- Add Array.isArray guard in fetchThread (xapi.ts) - Use URLSearchParams for mentions URL construction (xapi.ts) - Add since_id pagination tracking for mentions (xapi.ts) - Add console.log→stderr redirect for MCP transport (index.ts) - Add memory pruning with safe iterator for processedMentions (agent.ts) - Process mentions oldest-first for chronological pruning (agent.ts) - Replace any with unknown/proper types (xapi.ts, grok.ts) - Fix CODEOWNERS invalid usernames to @groupthinking - Add permissions blocks to all workflow files - Add label existence check in issue-triage workflow Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI
added a commit
that referenced
this pull request
Feb 9, 2026
- Add console.log→stderr redirect with unknown[] type (PR #26) - Use URLSearchParams for mentions URL + since_id pagination (PR #26) - Add Array.isArray() guard in fetchThread() (PR #26) - Add Set pruning with safe { value, done } iterator (PR #26) - Process mentions oldest-first for chronological pruning (PR #26) - Use [key: string]: unknown in parseThread, spread sort (PR #26) - Add mentionPostId param for correct reply targeting (PR #6) - Fix any type in Grok response parsing (PR #6) - Fix README broken list numbering (PR #4) Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Owner
|
Superseded — reply targeting fix consolidated into main via PR #42 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The agent was replying to the conversation root instead of the specific post where it was mentioned, breaking reply threading.
Root Cause
GrokService.analyzeAndDecide()received the thread context but not the mention post ID. It defaulted to usingthread.root_post.idas the reply target, causing all replies to target the conversation root regardless of where the mention occurred.Changes
mentionPostIdparameter toanalyzeAndDecide()andsimulateAnalysis()agent.tsandexamples.tsmentionPostIdastarget_post_idinstead ofthread.root_post.idExample Flow
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.