Skip to content

feat(gateway): report the routed tier in enqueue answers - #70

Open
rockbox37 wants to merge 2 commits into
mainfrom
feat/report-tier-in-enqueue-answers
Open

rockbox37 wants to merge 2 commits into
mainfrom
feat/report-tier-in-enqueue-answers

Conversation

@rockbox37

Copy link
Copy Markdown
Collaborator

What

The gateway's enqueue answers now say which tier the router picked for the job: "tier":"fast", "browser" or "stealth".

  • REST POST /v1/scrape and POST /v1/extract (the 202 answer, EnqueueResponse.Tier).
  • MCP tool results for scrape, extract, get_repository_content and extract_transcript ("tier" in the result JSON).

The field is omitempty, so nothing that reads these answers today is affected. Crawl answers are unchanged.

Why

This is the engine half of G-6 in the cloud's monetization plan (credits per request). The published pricing is fast 1 credit, browser 2, stealth 5, but the cloud billing layer in front of this gateway cannot tell which tier a job ran on: the router picks it from the URL, and nothing in the answer said which. The cloud will read this field to price a job. This PR only reports the fact; the engine knows nothing about credits.

The cloud PR follows, and charges 1 credit whenever the field is absent, so the two can be deployed in either order.

Notes

  • In every handler the single decision := ClassifyURL(...) value drives the plan gate (IsTierAllowed), the stream (StreamForTier) and now the reported tier, so the reported tier is the tier the job is queued on. mcpTranscript reports fast (its constant gate), on its own stream.
  • A caller cannot lower the reported tier: it comes only from the URL classification, never a request field. Revealing it discloses nothing new: every handler already refuses a disallowed tier with "this URL requires the stealth tier".
  • Not in this PR: crawl answers (a later G-6 change prices crawls per page), and an extract surcharge. I checked: nothing in the engine produces extracted_data today (/v1/extract enqueues an ordinary scrape job with the schema in its payload, no worker reads extract_schema, and ai/extractor.py is not wired into the job pipeline), so the pricing docs' +10 credits for extraction would currently charge for work that is not delivered. That is a separate question for whoever owns the extraction work.
  • Stealth has a stream (stealth_jobs) but no worker in the deploy configs consumes it, so a stealth job never completes and expires. Pricing it is harmless until a worker exists.

Review

/preflight-loop (Jev triaged it: the one-line production changes fast-passed; the new test file was escalated to all five lanes). No P0 to P2 in correctness, security, performance or compliance. The simplification lane's three P2s were test maintainability (a duplicated no-Redis fake and MCP helpers, and a header that over-claimed coverage); all fixed in the second commit, which also makes the tests assert that the job is queued on the stream for the tier it reports.

Tests

gateway/tier_answer_test.go: REST scrape and extract and MCP scrape and extract, each for a fast and a browser URL, assert the answer's tier and the stream the job was queued on; the JSON field is checked set and unset. They use the existing recordingQueue fake and public IP literals, so they need no Redis and no DNS. Dropping the field, or always reporting fast, fails them. go test ./... in gateway/ passes (it needs network for the existing DNS-resolving tests). Not covered: get_repository_content and extract_transcript (they need a platform host or a live transcript worker); their production change is the same one line.

The router picks a job's tier (fast, browser, stealth) from its URL, so a caller
cannot know it in advance, and nothing in the answer said which one ran. A
billing layer in front of the gateway prices a job by its tier and had to guess.

The REST scrape and extract answers (202) and the MCP scrape, extract,
get_repository_content and extract_transcript tool results now carry "tier".
The crawl answers are unchanged. The field is omitted when unset, so nothing
that reads these answers today is affected.
…ests

The tier tests carried their own no-Redis fake and MCP request helpers where
queue_order_test.go and mcp_test.go already have them. They now use those, and
the recorder also notes each XADD's stream, so the tests check that a job is
queued on the stream for the tier it reports. The file header says exactly what
is covered (the REST and MCP scrape and extract answers; the platform and
transcript tool results are not tested; crawl does not carry the tier yet), and
the tier JSON test reads the field from the decoded object.
Comment thread gateway/mcp.go
return mcpToolSuccess(c, rpc, map[string]interface{}{
"success": true,
"job_id": jobID,
"tier": string(TierFast),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 (50% confidence) — gateway/mcp.go:628 — Incorrect tier metadata. Callers and billing systems are hurt: transcript responses report fast for jobs handled on the separate transcript worker path, so tier-based pricing can classify transcript work incorrectly.

Suggestion
Report the tier that accurately represents transcript processing, or expose the worker path separately.
Pipeline annotations (3)

[reanchored: fast found at line 602, not cited line 628]
[rescued: non-security priority]
[capped: confidence below P1 floor]

Contested (false-positive): check before fixing

The MCP success response at lines 625–630 includes success, job_id, strategy, and video_id—not tier; TierFast is used for the plan check and route-decision log at lines 600–624.

Check first:

  • gateway/mcp.go:252 (calls mcpTranscript)

@deft-slizard deft-slizard Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Machine-readable verdict
{
  "slizard_verdict": {
    "schema_version": 1,
    "decision": "comment",
    "severity": {
      "P0": 0,
      "P1": 0,
      "P2": 1,
      "P3": 0
    },
    "confidence": 0.8695,
    "decision_confidence": 0.4,
    "finding_count": 1,
    "findings_by_source": {
      "llm": 1,
      "deterministic": 0,
      "unknown": 0
    },
    "merge_impact": "non-blocking",
    "version": "slizard v0.3.8991",
    "skip_llm": false,
    "head_sha": "6851fbfdac99df07c1bff078e99f6b340f6565d8"
  }
}
**SLizard Review** — 1 finding(s) across 1 file(s)

P2 · gateway/mcp.go:602-628 · confidence 0.50 · fp:aa64c2ced7b10a13

gateway/mcp.go:628 — Incorrect tier metadata. Callers and billing systems are hurt: transcript responses report fast for jobs handled on the separate transcript worker path, so tier-based pricing can classify transcript work incorrectly.

1 contested by a second-opinion check (listed last); see the Contested block on each inline comment before fixing.

Blast radius — top callers (15 shown · 43 affected)
  • testApp — gateway/main_test.go (hop 1)
  • transcriptAppWithRedis — gateway/youtube_test.go (hop 1)
  • TestCallerOwnerAnonymous — gateway/main_test.go (hop 1)
  • TestCallerOwnerHashes — gateway/main_test.go (hop 1)
  • TestCrawlFormatValidation — gateway/main_test.go (hop 2)
  • TestCrawlMaxPagesCapped — gateway/main_test.go (hop 2)
  • TestCrawlRequiresAuth — gateway/main_test.go (hop 2)
  • TestExtractBlockedOnFreePlan — gateway/main_test.go (hop 1)
  • TestExtractRequiresSchema — gateway/main_test.go (hop 1)
  • TestExtractUnavailableWithoutEndpoint — gateway/main_test.go (hop 2)
  • TestRateLimiterHeadersPresent — gateway/main_test.go (hop 2)
  • TestScrapeRejectsSSRF — gateway/main_test.go (hop 2)
  • TestScrapeRequiresAuth — gateway/main_test.go (hop 2)
  • TestScrapeValidatesBody — gateway/main_test.go (hop 2)
  • callPlatformTool — gateway/mcp_test.go (hop 2)

Roots: callerOwner (gateway/main.go), loadTranscriptWorker (gateway/main.go), NewApp (gateway/main.go), platformToolError (gateway/mcp.go), transcriptWorkerGate (gateway/mcp.go). Heuristic call graph; wide PRs may omit.

Review coverage

  • Reviewed files: gateway/main.go, gateway/mcp.go, gateway/models.go, gateway/queue_order_test.go, gateway/tier_answer_test.go
  • Skipped files: none
  • Source: github @ 6851fbfdac99

Context used

  • Static findings: 6
  • Static tools: osv-sca
  • Graph/blast radius: 45 changed node(s), 43 affected node(s)
  • Vector context chunks: 25
  • Context availability: full
  • Review categories: default
  • Deterministic checks: 2535/2535 passed
  • Degraded context: LLM findings concentrated in 1/5 changed files.

Suggested verification

  • (agent) Independently inspect each SLizard finding against the referenced file, surrounding code, and linked context before accepting or dismissing it.
  • (static) Review 6 deterministic/static finding(s) included in the evidence set.
  • (test) Run the repository tests that exercise the changed files and any failing scenario described by P0/P1 findings.

Agent verification brief

  • PR/CR: deftai/cheetah#70
  • Head SHA: 6851fbfdac99df07c1bff078e99f6b340f6565d8
  • Decision: comment
  • Highest-risk claims: P2 gateway/mcp.go:602 Incorrect Tier Metadata (0.50)
  • Reviewed files: gateway/main.go, gateway/mcp.go, gateway/models.go, gateway/queue_order_test.go, gateway/tier_answer_test.go
  • Skipped files: none
  • Evidence sources: static analysis, call graph/blast radius, vector context, deterministic checks
  • Known blind spots: LLM findings concentrated in 1/5 changed files.
  • Fingerprints: each finding has fp:… (16 hex). Collect from bot review bodies or inline slizard-meta.fingerprint.
  • Label (write+ required): @slizard label <fp> <fp|tp|risk> [reason] — top-level OK; multi-line batch after @slizard label. fp/risk quiet this PR (posted findings + actionable brief/check summary); tp corpus only. See docs/finding-fingerprints.md.

Decision: comment
Merge impact: non-blocking
Review confidence: 0.40
Decision confidence: 0.40
Finding confidence: 0.50
Reason: Findings are advisory under the current severity/confidence policy.
Severity counts: P0: 0, P1: 0, P2: 1, P3: 0
Important files: gateway/mcp.go (P2, 1 finding(s), confidence 0.50)
Review scope: 5 files, 157 additions, 3 deletions

Estimated LLM cost for this review: ~$0.05 (estimate from list prices, not a charge).

slizard v0.3.8991

@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · This PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Adds the routed tier to REST scrape and extract answers and MCP job answers.

  • Enqueue answers now show the tier the gateway picked for each job.

Reviews (1) · Last reviewed commit: "test(gateway): reuse the queue recorder ..." · Reviewed by Greptile

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