Skip to content

Test#8

Merged
MikePfunk28 merged 7 commits into
masterfrom
test
Nov 9, 2025
Merged

Test#8
MikePfunk28 merged 7 commits into
masterfrom
test

Conversation

@MikePfunk28
Copy link
Copy Markdown
Owner

@MikePfunk28 MikePfunk28 commented Nov 9, 2025

merge test into main

Summary by CodeRabbit

  • New Features

    • More robust plan-to-issues import with label provisioning, retries, duplicate handling, and improved error reporting.
    • Distributed locking for connection workflows to prevent duplicate connection attempts and improve extraction reliability.
  • Chores

    • CI workflow now requires a configured token and fails fast if missing.
    • Updated platform compatibility timestamp.
    • Removed Sentry console logging integration.
  • Documentation

    • Removed an outdated review doc and reformatted plan checklist items.

…date documentation formatting

 Changes Made (convex/mcp.ts:11-114)

  1. Added Connection Guard (Line 12)
  const pendingConnections = new Map<string, Promise<void>>()

  2. Updated connectLLMText with Race Protection (Lines 19-66)
  - ✅ Checks if connection is already in progress → waits for it
  - ✅ Checks if already connected → returns immediately
  - ✅ Stores pending connection promise before starting
  - ✅ Cleans up in finally block to prevent memory leaks
  - ✅ Concurrent callers now wait for the same connection attempt

  3. Fixed extractText to Delegate (Lines 82-85)
  // OLD (race condition):
  await manager.connect({ ... })  // Multiple callers = multiple connects

  // NEW (safe):
  await ctx.runAction(internal.mcp.connectLLMText, {})  // Delegates to guarded function

  How It Works

  Before: Multiple concurrent extractText calls → All see "not connected" → All try to connect → Race condition

  After: Multiple concurrent calls → First starts connection, others wait for same promise → Only one connection
   attempt

  Benefits

  - 🛡️ Thread-safe: No duplicate connection attempts
  - 🚀 Efficient: Concurrent callers share the same connection
  - 🔒 Memory-safe: Automatic cleanup in finally block
  - 📝 Self-documenting: Clear inline comments
… token.

  Changes Made (.github/workflows/setup-github-projects_Version3.yml:31-42)

  Before:
  env:
    GH_TOKEN_SECRET: ${{ secrets.GH_TOKEN }}
    GITHUB_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}

  After:
  env:
    MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

  Key improvements:
  - ✅ Now uses your MY_GITHUB_TOKEN secret
  - ✅ Cleaner error handling if token is missing
  - ✅ Clear success message when authenticated

  Next Steps

  1. Commit the workflow:
  git add .github/workflows/setup-github-projects_Version3.yml
  git commit -m "fix: Use MY_GITHUB_TOKEN for issue creation"
  git push

  2. Run the workflow:
    - Go to GitHub Actions → "Import Plan to Issues"
    - Click "Run workflow"
    - Should now successfully create all 136 issues
@MikePfunk28 MikePfunk28 added this to the MVP ready milestone Nov 9, 2025
@MikePfunk28 MikePfunk28 self-assigned this Nov 9, 2025
Copilot AI review requested due to automatic review settings November 9, 2025 02:33
@MikePfunk28 MikePfunk28 added the bug Something isn't working label Nov 9, 2025
@MikePfunk28 MikePfunk28 added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 9, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 9, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Updates GitHub workflow to require MY_GITHUB_TOKEN; implements DB-backed distributed locking and connection state management for MCP (Convex) plus new MCP mutations and schema fields; adds import and retry logic to the GitHub import script; tweaks OpenAI Azure header usage; removes Sentry console integration; updates docs, .gitignore, and Cloudflare compatibility_date.

Changes

Cohort / File(s) Summary
GitHub workflow & script
\.github/workflows/setup-github-projects_Version3.yml, \.github/scripts/import-plan-to-issues.ps1
Workflow now requires MY_GITHUB_TOKEN (permissions: issues: write, contents: read); auth fails if token absent (no fallback). Import script: creates labels if missing, sanitizes titles, tracks failed tasks, adds retry logic with aggressive sanitization/truncation, logs outcomes and exits 0.
MCP control flow & persistence
convex/mcp.ts, convex/mcp_mutations.ts, convex/schema.ts
Replaces inline connection logic with DB-backed distributed locking via new mutations (acquireConnectionLock, updateConnectionStatus, storeConnection, storeExtraction, queries). connectLLMText and extractText use lock semantics and return alreadyConnected/waited paths; schema adds error field and documents connecting/failed states.
OCR / OpenAI client config
convex/lib/ocr/processDocument.ts
Azure provider now passes API key via headers: { 'api-key': ... } instead of defaultHeaders.
Observability
src/lib/sentry.ts
Removed Sentry console integration and enableLogs flag from initialization.
Cloudflare config
wrangler.json
Updated compatibility_date from 2024-09-23 to 2025-11-09.
Docs & ignore list
docs/plan.md, docs/coderabbit_review01.md, \.gitignore
docs/coderabbit_review01.md deleted; docs/plan.md formatting and checklist state changes; .gitignore edits add docs/coderabbit_review01.md (duplicate entry).

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant extractText
    participant connectLLMText
    participant MCPMutations as "mcp_mutations (DB)"
    participant MCPClient as "llm-txt client"

    Note right of Caller: New high-level MCP connect & extract flow

    Caller->>extractText: extractText(url)
    extractText->>connectLLMText: ensure connection(serverName)
    connectLLMText->>MCPMutations: acquireConnectionLock(serverName)
    alt acquired lock
        connectLLMText->>MCPClient: connect llm-txt
        MCPClient-->>connectLLMText: connected
        connectLLMText->>MCPMutations: storeConnection(serverName, "connected", now)
        connectLLMText-->>extractText: alreadyConnected: true
    else existing connecting (not acquired)
        connectLLMText->>MCPMutations: await lock outcome / check status
        connectLLMText-->>extractText: waited: true
    else failed to acquire (connected elsewhere)
        connectLLMText-->>extractText: alreadyConnected: true
    end
    extractText->>MCPClient: perform extraction
    alt extraction success
        extractText->>MCPMutations: storeExtraction(url, text, format, now)
        extractText-->>Caller: extracted text
    else extraction failure
        extractText->>MCPMutations: updateConnectionStatus(serverName, "failed", error)
        extractText-->>Caller: error
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay close attention to distributed lock correctness in convex/mcp_mutations.ts and race conditions between acquireConnectionLock and updateConnectionStatus.
  • Verify promise lifecycle and return flags (waited, alreadyConnected) in convex/mcp.ts to avoid deadlocks or leaked pendingConnections entries.
  • Review retry/sanitization/truncation edge cases and exit behavior in import-plan-to-issues.ps1.
  • Confirm Azure header change in convex/lib/ocr/processDocument.ts matches client expectations.
  • Ensure removal of Sentry console integration doesn't remove necessary runtime diagnostics.

Possibly related PRs

  • Test #5 — Overlaps on MCP connect/extract logic and related Convex changes; likely touches same functions.
  • Test #2 — Related Convex MCP and workflow/script changes, shares high-level feature area.

Poem

🐇 I hopped through locks and tokens bright,

I nudged the DB to stop the fight.
Retries and trims, labels in a line,
Sentry quieted, timestamps fine.
A rabbit cheers: one-flight, one light.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Test' is vague and generic, providing no meaningful information about the actual changes in the changeset, which include significant updates to CI/CD workflows, MCP integrations, Convex schema changes, and multiple file modifications. Revise the title to be descriptive and specific about the main changes, such as 'Add distributed MCP locking and connection management' or 'Refactor MCP integration with distributed locking and mutations'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test

Comment @coderabbitai help to get the list of available commands and usage tips.

@MikePfunk28 MikePfunk28 linked an issue Nov 9, 2025 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates configuration, removes deprecated code review artifacts, improves concurrency handling in MCP connections, and updates documentation formatting.

  • Removes Sentry console logging integration
  • Adds race condition protection for MCP server connections
  • Updates Cloudflare Workers compatibility date
  • Cleans up documentation formatting and removes duplicate content

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
wrangler.json Updates Cloudflare Workers compatibility_date to 2025-11-09
src/lib/sentry.ts Removes consoleIntegration and enableLogs configuration from Sentry initialization
docs/plan.md Converts completed checkmarks to unchecked tasks and fixes spacing inconsistencies
docs/coderabbit_review01.md Removes entire CodeRabbit review artifact file
convex/mcp.ts Adds single-flight connection guard pattern to prevent race conditions in MCP server connections
.gitignore Adds duplicate entry for docs/coderabbit_review01.md
.github/workflows/setup-github-projects_Version3.yml Changes authentication from built-in GITHUB_TOKEN to custom MY_GITHUB_TOKEN secret

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/plan.md Outdated
Comment thread convex/mcp.ts Outdated
Comment on lines +34 to +42
MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
run: |
$token = $env:GH_TOKEN_SECRET
$token = $env:MY_GITHUB_TOKEN
if ([string]::IsNullOrEmpty($token)) {
Write-Host "Using GITHUB_TOKEN for authentication."
$token = $env:GITHUB_TOKEN_SECRET
Write-Error "MY_GITHUB_TOKEN secret not found. Please add it to repository secrets."
exit 1
}
$token | gh auth login --with-token
Write-Host "Successfully authenticated gh CLI."
Write-Host "Successfully authenticated gh CLI with MY_GITHUB_TOKEN."
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

The workflow requires a custom MY_GITHUB_TOKEN secret but GITHUB_TOKEN is automatically available with the configured permissions (lines 11-13). Unless there's a specific reason to use a custom PAT (like needing access to other repositories), you should use the built-in GITHUB_TOKEN which follows the principle of least privilege and doesn't require manual secret management. Change to use secrets.GITHUB_TOKEN and update the variable name accordingly.

Copilot uses AI. Check for mistakes.
Comment thread docs/plan.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e4287b and 1a96cc5.

📒 Files selected for processing (7)
  • .github/workflows/setup-github-projects_Version3.yml (2 hunks)
  • .gitignore (1 hunks)
  • convex/mcp.ts (2 hunks)
  • docs/coderabbit_review01.md (0 hunks)
  • docs/plan.md (1 hunks)
  • src/lib/sentry.ts (0 hunks)
  • wrangler.json (1 hunks)
💤 Files with no reviewable changes (2)
  • src/lib/sentry.ts
  • docs/coderabbit_review01.md
🧰 Additional context used
🧬 Code graph analysis (1)
convex/mcp.ts (2)
convex/mcp.node.ts (1)
  • connectLLMText (16-30)
src/lib/mcp/client.ts (1)
  • getMCPManager (197-202)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Agent
  • GitHub Check: Cloudflare Pages

Comment thread docs/plan.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Nov 9, 2025

Deploying agentic-search with  Cloudflare Pages  Cloudflare Pages

Latest commit: cc2ac84
Status: ✅  Deploy successful!
Preview URL: https://f8583a8a.agentic-search.pages.dev
Branch Preview URL: https://test.agentic-search.pages.dev

View logs

MikePfunk28 and others added 3 commits November 8, 2025 21:52
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…issue creation process; ensure label existence, sanitize titles, and retry failed tasks. Update workflow to use GH_TOKEN for authentication and clean up .gitignore and schema definitions.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
convex/mcp.ts (1)

52-134: Connected status blocks fresh workers from ever establishing a session

When acquireConnectionLock returns { acquired: false, status: 'connected' } we bail out (either immediately or after a one-shot wait) without ever calling manager.connect. That works only for the process that originally set the status. A new Convex Node worker handling this action will find its local MCPClientManager has no session for llm-txt, yet we still return { success: true }. The follow-up extractText on that worker hits the same branch and eventually calls manager.callTool without a live connection, so the request fails (the manager rejects calls to unknown servers). In other words, once one instance marks the row as connected, every other instance is permanently locked out of establishing its own MCP connection.

We need to let a fresh worker rehydrate its own connection before declaring success. One straightforward fix is to treat the DB record as advisory: if lockResult.status === 'connected' but manager.getConnectedServers() is missing serverName, reacquire the lock (e.g. via a dedicated mutation that flips the row back to connecting) and then run manager.connect. Alternatively, stash an owner identifier in the connection row so only the owning worker returns alreadyConnected, while everyone else re-enters the connect path. Without this change, multi-instance deployments will intermittently fail every call routed to a cold worker.

♻️ Duplicate comments (1)
.github/workflows/setup-github-projects_Version3.yml (1)

34-41: Restore compatibility with the built-in token

Requiring MY_GITHUB_TOKEN makes every run fail unless that custom secret is configured, even though GitHub already injects GITHUB_TOKEN for this job and gh only needs GH_TOKEN to be set. Use the default token so the workflow works out of the box.(docs.github.com)

       - name: Authenticate gh CLI
         shell: pwsh
         env:
-          GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
+          GH_TOKEN: ${{ github.token }}
         run: |
-          if ([string]::IsNullOrEmpty($env:GH_TOKEN)) {
-            Write-Error "MY_GITHUB_TOKEN secret not found"
-            exit 1
-          }
-          Write-Host "Authenticated with MY_GITHUB_TOKEN"
+          if ([string]::IsNullOrEmpty($env:GH_TOKEN)) {
+            Write-Error "GH_TOKEN was not provided by the Actions runtime"
+            exit 1
+          }
+          Write-Host "Authenticated with default GITHUB_TOKEN"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e4a55c and cc2ac84.

⛔ Files ignored due to path filters (1)
  • convex/_generated/api.d.ts is excluded by !**/_generated/**
📒 Files selected for processing (8)
  • .github/scripts/import-plan-to-issues.ps1 (5 hunks)
  • .github/workflows/setup-github-projects_Version3.yml (2 hunks)
  • .gitignore (0 hunks)
  • convex/lib/ocr/processDocument.ts (1 hunks)
  • convex/mcp.ts (6 hunks)
  • convex/mcp_mutations.ts (1 hunks)
  • convex/schema.ts (1 hunks)
  • docs/plan.md (8 hunks)
💤 Files with no reviewable changes (1)
  • .gitignore
🧰 Additional context used
🧬 Code graph analysis (1)
convex/mcp.ts (2)
convex/mcp.node.ts (1)
  • connectLLMText (16-30)
src/lib/mcp/client.ts (1)
  • getMCPManager (197-202)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages

Comment thread convex/mcp_mutations.ts
Comment on lines +97 to +101
await ctx.db.patch(existing._id, {
status: args.status,
lastConnectedAt: Date.now(),
...(args.error && { error: args.error })
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Clear stale error details when status recovers

updateConnectionStatus only patches the error field when a new error string is supplied. After a failed attempt we persist an error message; on the next successful connection we set status: 'connected' but never clear that field. Any consumer reading the record will continue to see the old error even though the status is healthy. Please explicitly null out or remove error whenever we transition to a non-failed state (e.g. include error: undefined for 'connected'/'disconnected').

🤖 Prompt for AI Agents
In convex/mcp_mutations.ts around lines 97 to 101, the patch only sets the error
field when args.error is truthy, so after a failed attempt the persisted error
remains even when status is later set to 'connected' (or other non-failed
states); modify the patch to explicitly clear the error when transitioning to a
non-failed status by including error: undefined (or null) in the update when
args.status indicates recovery (e.g., 'connected' or 'disconnected'), while
still setting error to args.error when a real error string is provided.

@MikePfunk28 MikePfunk28 merged commit 5fd9d6e into master Nov 9, 2025
4 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Agentic-Search Nov 9, 2025
This was referenced Nov 11, 2025
Merged
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

localhost not connecting

2 participants