From 1832591310e0d955340f7244c1021428cc28b2d6 Mon Sep 17 00:00:00 2001
From: Tom Beckenham <34339192+tombeckenham@users.noreply.github.com>
Date: Fri, 27 Nov 2026 19:00:49 +1100
Subject: [PATCH] dashscope: follow model-info links and read pages with no
Context limits section (#772)
decision-model.md became an overview page linking decision-model-stable.md;
qwen-audio-3.1-live.md has a capabilities table and no Context limits
section. Both threw 'parsed 0 context-limit rows' on every poll. The
overview page is now followed once (the fact source names the page read),
and a model page with no limits section gives its model null limits. A
limits section that parses nothing still throws. DOCS_CACHE_VERSION v50.
---
src/server/providers/adapters/dashscope.ts | 6 +-
.../providers/dashscope-model-limits.test.ts | 82 +++++++++++++++++++
.../providers/dashscope-model-limits.ts | 66 ++++++++++++++-
src/server/providers/model-facts.ts | 5 +-
4 files changed, 154 insertions(+), 5 deletions(-)
diff --git a/src/server/providers/adapters/dashscope.ts b/src/server/providers/adapters/dashscope.ts
index ee8096d4..93acee7b 100644
--- a/src/server/providers/adapters/dashscope.ts
+++ b/src/server/providers/adapters/dashscope.ts
@@ -398,7 +398,7 @@ function applyModelLimits(
const absent = { ...model.absent }
const source = (path: string): FactSource => ({
derivation: 'docs-extracted',
- sourceUrl: url,
+ sourceUrl: doc?.sourceUrl ?? url,
...(doc ? { sourceHash: doc.sourceHash } : {}),
path,
})
@@ -482,7 +482,9 @@ async function listModels(
url,
await tryDocs(run, url, (cached) =>
cached(kv, url, async () =>
- loadDashscopeModelLimits(await fetchText(url, DOCS_INIT)),
+ loadDashscopeModelLimits(await fetchText(url, DOCS_INIT), (linked) =>
+ fetchText(linked, DOCS_INIT),
+ ),
),
),
)
diff --git a/src/server/providers/dashscope-model-limits.test.ts b/src/server/providers/dashscope-model-limits.test.ts
index aed58a5d..fa158c13 100644
--- a/src/server/providers/dashscope-model-limits.test.ts
+++ b/src/server/providers/dashscope-model-limits.test.ts
@@ -61,6 +61,45 @@ const DECISION_FIXTURE = `# decision-model-preview
| Parameter | Value | Parameter | Value |
|---|
Max Input Length | 65,536 | Max Output Length | 0 |
Context Window | 65,536 | | |
`
+/** decision-model.md, fetched 2026-11-27 (#772): an overview page. */
+const DECISION_INDEX = `# Decision Model
+
+> Overview of Alibaba Cloud Model Studio decision models.
+
+- [Decision Model API Reference](/help/en/model-studio/decision-model-api): Call via the System One protocol.
+- [decision-model Model Info](/help/en/model-studio/decision-model-stable): Model capabilities, context limits, pricing, and rate limits.
+`
+
+/** decision-model-stable.md, fetched 2026-11-27 (#772), trimmed. */
+const DECISION_STABLE = `# decision-model
+
+## Model Capabilities
+
+| Capability | Support | Capability | Support |
|---|
Input Modality | Text, image | Output Modality | Text (structured decision result) |
+
+## Context Limits
+
+| Parameter | Value | Parameter | Value |
|---|
Max Input Length | 268,288 | Max Output Length | — |
Context Window | 268,288 | | |
+
+## Pricing
+`
+
+/** qwen-audio-3-1-live.md, fetched 2026-11-27 (#772), trimmed: no Context limits section. */
+const AUDIO_LIVE = `# qwen-audio-3.1-live
+
+## Model capabilities
+
+| Capability | Supported | Capability | Supported |
+| ----------------- | ------------- | ----------------- | ------------- |
+| Input Modalities | Text, Audio | Output Modalities | Text, Audio |
+
+## Input limits
+
+The combined length of system instructions and function configuration text for the frontend model is limited to at most 65,536 tokens.
+
+## Model Pricing
+`
+
describe('dashscope model limits', () => {
it('reads context and non-thinking max output, including snapshot sections', () => {
const models = parseDashscopeModelLimits(OMNI_FIXTURE)
@@ -95,6 +134,49 @@ describe('dashscope model limits', () => {
)
})
+ it('gives a model page with no Context limits section null limits', () => {
+ expect(parseDashscopeModelLimits(AUDIO_LIVE)).toEqual({
+ 'qwen-audio-3.1-live': { contextWindow: null, maxOutput: null },
+ })
+ })
+
+ it('throws when the limits table sits under a renamed heading', () => {
+ expect(() =>
+ parseDashscopeModelLimits(
+ OMNI_FIXTURE.replaceAll('Context Limits', 'Token Limits'),
+ ),
+ ).toThrow(/parsed 0 context-limit rows/)
+ })
+
+ it('still throws when a Context limits section parses nothing', () => {
+ expect(() =>
+ parseDashscopeModelLimits(
+ `${AUDIO_LIVE}\n## Context limits\n\nSee the table below.\n`,
+ ),
+ ).toThrow(/parsed 0 context-limit rows/)
+ })
+
+ it('follows an overview page to the model info page it links', async () => {
+ const fetched: Array = []
+ const doc = await loadDashscopeModelLimits(DECISION_INDEX, (url) => {
+ fetched.push(url)
+ return Promise.resolve(DECISION_STABLE)
+ })
+ expect(fetched).toEqual([
+ 'https://www.alibabacloud.com/help/en/model-studio/decision-model-stable.md',
+ ])
+ expect(doc.sourceUrl).toBe(fetched[0])
+ expect(doc.models).toEqual({
+ 'decision-model': { contextWindow: 268288, maxOutput: null },
+ })
+ })
+
+ it('throws on an overview page when not given a fetch', async () => {
+ await expect(loadDashscopeModelLimits(DECISION_INDEX)).rejects.toThrow(
+ /parsed 0 context-limit rows/,
+ )
+ })
+
it('reads the rendered help page the .md URL serves since 2026-10-27', async () => {
const doc = await loadDashscopeModelLimits(OMNI_PAGE)
expect(doc.models).toEqual({
diff --git a/src/server/providers/dashscope-model-limits.ts b/src/server/providers/dashscope-model-limits.ts
index 5e6ab699..d857cec4 100644
--- a/src/server/providers/dashscope-model-limits.ts
+++ b/src/server/providers/dashscope-model-limits.ts
@@ -32,6 +32,8 @@ export interface DashscopeModelLimits {
export interface DashscopeLimitsDoc {
sourceHash: string
+ /** The page read when the requested one was an index linking it (#772). */
+ sourceUrl?: string
models: Record
}
@@ -122,9 +124,59 @@ function limitsFrom(rows: Array>): DashscopeModelLimits | null {
return { contextWindow, maxOutput }
}
+const LIMITS_HEADING = /^context limits$/i
+const CAPABILITIES_HEADING = /^model capabilities$/i
+const LIMIT_ROW =
+ /context window|max(?:imum)? input length|max(?:imum)? output length/i
+
+function headings(markdown: string): Array {
+ return markdown.split('\n').flatMap((line) => headingText(line) ?? [])
+}
+
+/**
+ * A model page with a capabilities table, no Context limits section and
+ * no limits table anywhere states no limits (qwen-audio-3.1-live.md,
+ * 2026-11-27): its one model, the h1, gets nulls. A page that still carries
+ * limit rows under a renamed heading is not read, so it throws.
+ */
+function statesNoLimits(
+ markdown: string,
+): Record | null {
+ const titles = headings(markdown)
+ const h1 = /^#\s+(.*)$/m.exec(markdown)?.[1]?.trim()
+ if (!h1 || !isModelId(h1)) return null
+ if (titles.some((title) => LIMITS_HEADING.test(title))) return null
+ if (!titles.some((title) => CAPABILITIES_HEADING.test(title))) return null
+ if (LIMIT_ROW.test(markdown)) return null
+ return { [h1]: { contextWindow: null, maxOutput: null } }
+}
+
+/**
+ * An overview page that only links its model's info page
+ * (`[decision-model Model Info](/help/en/model-studio/decision-model-stable)`,
+ * decision-model.md since 2026-11-23): the `.md` URL of that link.
+ */
+export function dashscopeModelInfoLink(markdown: string): string | null {
+ const titles = headings(markdown)
+ if (
+ titles.some(
+ (title) => LIMITS_HEADING.test(title) || CAPABILITIES_HEADING.test(title),
+ )
+ ) {
+ return null
+ }
+ const slug =
+ /\[[^\]]*\bModel Info\]\(\/help\/en\/model-studio\/([a-z0-9-]+)\)/i.exec(
+ markdown,
+ )?.[1]
+ return slug ? `${PAGE_ORIGIN}/${slug}.md` : null
+}
+
export function parseDashscopeModelLimits(
markdown: string,
): Record {
+ const unstated = statesNoLimits(markdown)
+ if (unstated) return unstated
const lines = markdown.split('\n')
let current: string | null = null
const models: Record = {}
@@ -132,7 +184,7 @@ export function parseDashscopeModelLimits(
const title = headingText(lines[i] ?? '')
if (!title) continue
if (isModelId(title)) current = title
- if (!/^context limits$/i.test(title) || !current) continue
+ if (!LIMITS_HEADING.test(title) || !current) continue
const limits = limitsFrom(tableRows(sectionAfter(lines, i + 1)))
if (limits) models[current] = limits
}
@@ -237,12 +289,22 @@ export function dashscopeDocText(body: string, label: string): string {
)
}
+/**
+ * One model page's limits. An overview page that links its model's info
+ * page is followed once (`fetchPage`), and the doc names the page read.
+ */
export async function loadDashscopeModelLimits(
body: string,
+ fetchPage?: (url: string) => Promise,
): Promise {
- const markdown = dashscopeDocText(body, 'dashscope model page')
+ let markdown = dashscopeDocText(body, 'dashscope model page')
+ const linked = fetchPage ? dashscopeModelInfoLink(markdown) : null
+ if (linked && fetchPage) {
+ markdown = dashscopeDocText(await fetchPage(linked), 'dashscope model page')
+ }
return {
sourceHash: await sha256Text(markdown),
+ ...(linked ? { sourceUrl: linked } : {}),
models: parseDashscopeModelLimits(markdown),
}
}
diff --git a/src/server/providers/model-facts.ts b/src/server/providers/model-facts.ts
index 191ddf06..cdc3eb86 100644
--- a/src/server/providers/model-facts.ts
+++ b/src/server/providers/model-facts.ts
@@ -304,7 +304,10 @@ export const DOCS_TTL_SECONDS = 6 * 60 * 60
// stored one after the MCP field table arrived (its JSON `string` threw, and
// a failed load is not cached). The bump drops a v49 catalog stored before
// that table.
-const DOCS_CACHE_VERSION = 'v50'
+// v51: a DashScope model page entry may name the info page it followed
+// (`sourceUrl`, #772), and a page with no Context limits section now
+// parses; a v50 entry is the old parse.
+const DOCS_CACHE_VERSION = 'v51'
/** Fresh-window key for one parsed docs page. Shared with the stale copy. */
export function docsCacheKey(url: string): string {