Skip to content

fix(mcp): count pending approvals accurately#878

Merged
JSONbored merged 3 commits into
mainfrom
codex/fix-pending-approval-count-in-mcp-tool
Jun 19, 2026
Merged

fix(mcp): count pending approvals accurately#878
JSONbored merged 3 commits into
mainfrom
codex/fix-pending-approval-count-in-mcp-tool

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The MCP gittensory_get_automation_state tool reported pendingActionCount using the length of a paginated list, which was capped by the list API default limit and could undercount repos with >200 pending approvals.
  • Maintainer tooling needs an accurate total backlog count rather than a page-size value to make correct decisions and surface true queue size.

Description

  • Add pendingAgentActionConditions helper to centralize the repoFullName/status filter logic used by list and count queries in src/db/repositories.ts.
  • Add countPendingAgentActions which performs a SQL count(*) with the shared filters so callers can obtain the true total.
  • Update getAutomationState in src/mcp/server.ts to call countPendingAgentActions and report pendingActionCount and the human summary from that value.
  • Add regression test reports the total pending-approval count beyond the list page size to test/unit/mcp-automation-state.test.ts that seeds 201 pending actions and asserts the MCP tool reports 201.

Testing

  • Ran the focused unit tests with npx vitest run test/unit/mcp-automation-state.test.ts --reporter=verbose, and the test file passed (all tests succeeded).
  • Ran the TypeScript typecheck with npm run typecheck, which completed successfully with no type errors.
  • Verified the new regression test asserts the corrected behavior by seeding 201 pending rows and observing the MCP tool return 201 as expected.

Codex Task

@ghost

ghost commented Jun 18, 2026

Copy link
Copy Markdown

gittensory · advisory review

Reviewed 4 changed file(s) — two independent AI reviewers.

Changed files: src/db/repositories.ts, src/mcp/server.ts, test/unit/agent-approval-queue.test.ts, test/unit/mcp-automation-state.test.ts

Suggested action:Safe to merge — both reviewers found no blocking issues.

Reviewer A · gpt-oss-120b — recommends ✅ merge
The PR introduces a reusable condition builder and a new countPendingAgentActions function, updates the MCP automation state to use the count instead of fetching full rows, and adds comprehensive tests for filtering and pagination edge cases. The changes are well‑scoped, type‑safe, and maintain existing behavior.

Suggestions

  • Consider exporting the pendingAgentActionConditions helper (or documenting it as internal) to avoid accidental external use.
  • Add a brief comment on countPendingAgentActions explaining why it omits pagination limits (to clarify intent).

Worth double-checking

  • Ensure no other parts of the code rely on listPendingAgentActions for counting; the new function should be used consistently.
  • Verify that the added import of countPendingAgentActions does not create an unused-import lint error in other parts of server.ts.

Reviewer B · nemotron-3-120b-a12b — recommends ✅ merge
The PR adds a dedicated countPendingAgentActions function to accurately count pending agent actions without list limits, replacing the previous approach of fetching a capped list and taking its length. Changes include a reusable conditions helper, the new count function, updates to the MCP server to use the count, and comprehensive tests verifying filtering and behavior beyond the 200-row list limit. The fix resolves inaccuracy in the automation state's pending approval count and is well-tested.

Suggestions

  • Consider adding a test for countPendingAgentActions with status filter alone (already covered) and repo filter alone (covered) to ensure no regression.
  • In src/mcp/server.ts, the variable name 'pendingActionCount' is clear, but ensure consistency if this pattern is used elsewhere (no immediate issue).

Worth double-checking

  • Verify that the count function's handling of empty conditions (undefined) matches the list function's behavior (no WHERE clause). The current implementation uses conditions.length === 0 ? undefined : and(...conditions) which is correct.
  • Ensure the MCP tool's return type remains a number (it does) and that consumers expect a number (they do, as the summary string and data field use it numerically).

@ghost

ghost commented Jun 18, 2026

Copy link
Copy Markdown

Note

Gittensory Gate skipped

PR closed before full evaluation. No late first comment was created.

Signal Result Evidence Action
Gate result ⚠️ Skipped #878 is no longer open. No action.

💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

@ghost ghost added the gittensory:reviewed label Jun 18, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@JSONbored
JSONbored force-pushed the codex/fix-pending-approval-count-in-mcp-tool branch from 67ed0a2 to cb012bd Compare June 18, 2026 22:21
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.72%. Comparing base (25b77f1) to head (4413983).

Files with missing lines Patch % Lines
src/db/repositories.ts 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #878      +/-   ##
==========================================
- Coverage   96.72%   96.72%   -0.01%     
==========================================
  Files         109      109              
  Lines       14750    14758       +8     
  Branches     5340     5343       +3     
==========================================
+ Hits        14267    14274       +7     
  Misses         95       95              
- Partials      388      389       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
gittensory-ui 4413983 Commit Preview URL

Branch Preview URL
Jun 19 2026, 06:01 AM

@JSONbored
JSONbored merged commit f6a7121 into main Jun 19, 2026
20 of 21 checks passed
@JSONbored
JSONbored deleted the codex/fix-pending-approval-count-in-mcp-tool branch June 19, 2026 06:05
@github-actions github-actions Bot mentioned this pull request Jun 19, 2026
12 tasks
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