Skip to content

embedder-openai: an over-limit input is refused, not truncated (known-model input limits, one shared token estimate) #37093

Description

@os-bob

maintainer · os-bob · session_012dn2AecKpLaYkUtNRiqtby

Filing gate: ③ maintainer-directed (topic child). Source: topic #37000 (phase 2 row 6, its embedder half); maintainer 2026-11-24 「用fable评审,并分拆第二阶段的任务」. Reviewed by an independent Fable pass before filing.
Grading: area:ai · Feature · p2 (topic) · reach: apps that mount service-knowledge with embedder-openai · evidence: read.

维护者速读

  • 问题:文本超过嵌入模型的输入上限时,服务商会悄悄截断,后半段内容搜不到,也没有任何报错。
  • 修法:已知模型表补上每个模型的输入上限;超限时报错并写明模型名和估算长度,不再截断。表里没有的模型不设上限,只警告一次。另外给出一个平台和应用共用的 token 估算公式。
  • 需要你做的:无。不改契约,不用等 ADR,可以现在派。

What

  1. packages/plugins/embedder-openai/src/index.ts: add maxInputTokens to the known-model table (each value checked against the provider's published docs and cited in the PR); OpenAIEmbedderOptions.maxInputTokens? overrides it.
  2. embed(): an input whose estimate exceeds the limit throws an error naming the model, the estimate and the limit; nothing is truncated. A model not in the table and with no option: no limit, one warning per embedder instance.
  3. One shared estimate function, exported from a place both embedder-openai and service-knowledge already depend on (@objectstack/spec shared utilities; name the module in the PR). Formula: CJK characters and full-width punctuation 1.5 each; an ASCII alphanumeric run 1; other punctuation 1; × 1.1. Documented on its docblock and in content/docs/ai/knowledge-rag.mdx.
  4. IEmbedder is not changed (same approach as embedder-openai: embed() sends every input in one request; providers with a per-request cap reject a reindex #36995).

Acceptance

  • Over-limit input → error with model, estimate, limit; under-limit input unchanged.
  • Unknown model → no error, one warning.
  • A sampled test: the estimate is never below OpenAI cl100k token counts on Chinese regulation-like text and mixed Chinese/English text (other tokenizers by documented factor only; they cannot run in CI).
  • Container run per AGENTS.md.

Out of scope

Blocked-by: none.
Parent: #37000. Reader: domain:server lane (packages/plugins/embedder-openai).
Dedupe: maxInputTokens 0 · embedder truncated 14 (open 2: seat posts only) · EMBEDDER_SERVICE 3 (none open).

Activity

  1. added
    priority:p2
    on Nov 24, 2026
  2. added theissue type on Nov 24, 2026
  3. added
    area:ai
    on Nov 24, 2026
  4. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    triage#1 · os-warren · session_01JQwxbZKP5YM48rWMWTS7wE

    Triage: first touch 2026-11-24T19:45Z

  5. added
    domain:server
    pm:queue
    on Nov 24, 2026
  6. objectstack-fleet commented on Nov 24, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL
    Claim: PM loop round 1
    Session: session_01QSeKYpRrYuqSLCvbSk9zrL
    Account: os-justin
    Branch: claude/issue-37093-embedder-input-limit
    Worktree: objectstack-issue-37093
    Domain: domain:server
    Seat: repo:objectstack#4
    Area: a4-K
    File surface: packages/plugins/embedder-openai/**, one shared estimate module in a package both embedder-openai and service-knowledge already depend on (the card names @objectstack/spec shared utilities; the dev measures that against AGENTS.md Prime Directive 2 and names the module) plus the artifacts it regenerates, content/docs/ai/knowledge-rag.mdx, .changeset/* (stop on breach; explain in the report)
    Container & model: S, mode:cloud, model: default (dispatch-gates --repo objectstack-ai/objectstack --tier: "no path-derived mandate"), effort: medium
    Clause-②: yes
    Metadata-protocol: none
    Responsibility: n/a — not a defect card
    Thread-read: 7142552576
    Premise: holds — on origin/main 6f3a8da the known-model table in packages/plugins/embedder-openai/src/index.ts carries dimensions and per-request caps (PR #37037) but no input limit; embed() sends inputs of any length.
    Serial constraints cleared: none in flight on packages/plugins/embedder-openai/**; #37096 (in flight, cloud) touches service-knowledge, knowledge-memory and two packages/spec knowledge files — disjoint from this surface; overlap-check before every push.
    Pre-claim lane: packages/plugins/embedder-openai is domain:server; inside this zone's lease roots. The shared estimate module may sit outside them — named in the PR and reviewed per contract-review.md.
    Pre-claim deps: Blocked-by: none.
    Prior rulings read: card's own (no IEmbedder change, same approach as #36995; formula verbatim); ADR-0161 K8: IEmbedder.maxInputTokens and IEmbedder.model belong to #37098 / #37100, not here.
    State: pm:queue → pm:dispatched in this stroke.

  7. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 24, 2026
  8. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Rulings recorded · 2026-11-25T01:00Z · two questions from this card's development, put to the maintainer in seat repo:objectstack#4's session.

    1. The refused draft pr_create (permission check in the dev session): 「embedder-openai: an over-limit input is refused, not truncated (known-model input limits, one shared token estimate) #37093:开 PR 放行。你应该使用 pm-dispatch 技能审核和落地pr,该放行的都放行」 — the PR is opened from claude/issue-37093-embedder-input-limit.
    2. The token-estimate formula: the card's rule counts one ASCII letter/digit run as 1 token whatever its length, which under-counts English-heavy text (long words, numbers, IDs, URLs, code), so an over-limit input passes and the provider truncates it silently — the outcome this card exists to stop. The seat's option A — count an ASCII run as ceil(length / 4) tokens, so every script errs high — was put to the maintainer, whose answer, verbatim: 「A」.

    So the PR implements A: an ASCII letter/digit run counts ceil(length / 4); CJK and the rest stay as ruled. Pins add English-heavy cases (long words, long digit strings, a URL / code line) asserting the estimate is at or above a reference tokenizer's count, beside the existing Chinese and mixed cases; the ablation (back to 1 per run) turns them red.

  9. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    os-dev report · card #37093 · head 1660e96b9a6778c03d16092ab92d0285ecac6d5d · PR #37171 (opened by the seat session under the maintainer's authorization; see the rulings comment above)

    Relayed verbatim from dev session session_01QSeKYpJCg2rG1RGK4BwAKx. The dev made no GitHub writes.

    {
      "issue": 37093,
      "status": "done",
      "branch": "claude/issue-37093-embedder-input-limit",
      "pr": 37171,
      "session": "session_01QSeKYpJCg2rG1RGK4BwAKx",
      "premise_still_valid": true,
      "summary": "Head 1660e96b. Ruling 「A」 applied: in packages/spec/src/shared/token-estimate.ts an ASCII letter/digit run counts ceil(length / 4), via the new exported constant ASCII_RUN_CHARS_PER_TOKEN = 4 and one helper asciiRunTokens(). CJK, punctuation, whitespace and the x1.1 margin are unchanged. Docblock, content/docs/ai/knowledge-rag.mdx (table row plus a limitation sentence) and the changeset (formula line plus the new export) updated; api-surface and export-origins regenerated (+1 line each).",
      "tests": "spec token-estimate.test.ts: 26 passed (10 zh/mixed fixtures and 8 English-heavy fixtures, all >= cl100k under A, plus formula cases). embedder-openai: 27 passed, typecheck exit 0 against a rebuilt spec. spec typecheck exit 0. Ablation: the run rule reverted to the old 1-per-run gives 9 failed | 17 passed (6 of 8 English pins plus 3 formula cases); restored, blob == HEAD. Full spec suite (984 files / 29879 passed) last run at 2724c5e4, not re-run on 1660e96b (declared narrowing: only token-estimate.ts/test.ts changed under spec/src; CI runs the full suite).",
      "gates": "check:generated: all 14 up to date. Derived gate list identical to the 2724c5e4 derivation (112 commands); a 45-command subset re-run on 1660e96b: 45/45 exit 0; the rest from the full reconciliation at 2724c5e4: 108 exit 0, 4 NOT MEASURED (exit 3 prerequisite). overlap-check before push: clean.",
      "dogfood_battery": "n/a",
      "line_budget": "9 files; about +470 / -6 vs base",
      "deviations": [
        "pr_create was refused by the auto-mode classifier in the dev session and was not re-sent; the seat session opened the PR",
        "long digit-run and URL pins: under A they hold for 8-12 digit runs and plain URLs, not for 16+ digit runs or a URL with a random hex id, so those are not pinned (open question below)",
        "unknown-model warning merged with the batch-size warning",
        "BigModel embedding-3 documented at 3072",
        "full spec suite not re-run on the new head (declared narrowing)"
      ],
      "open_questions": [
        "Ruling A still under-counts long random alphanumerics against cl100k: 16-20 digit runs 35 vs 36; a URL with a 32-hex id 57 vs 58; sha256 hex + base64 38 vs 81; a UUID 19 vs 40. Options: A-as-landed (document the limitation); B (digits ceil(n/3), letters ceil(n/4)); C (mixed letter+digit run ceil(n/2), digit run ceil(n/3), letter run ceil(n/4)). Dev recommends C. Routed to the maintainer through the seat."
      ],
      "security_findings": "none",
      "out_of_scope_findings": []
    }
  10. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Ruling recorded · 2026-11-25T02:26Z · a follow-up to ruling 2 in 7149124439, put to the maintainer in seat repo:objectstack#4's session.

    The question: ruling 2's formula (an ASCII letter/digit run counts ceil(length / 4)) still under-counts long identifiers. These readings were measured against the reference tokenizer during review of PR #37171:

    text estimate real
    16–20 digit numbers 35 36
    URL with a 32-hex id 57 58
    sha256 + base64 38 81
    UUID 19 40

    So inputs heavy in order numbers, hashes, UUIDs or JSON can still pass the check and be truncated by the provider without a word.

    The options:

    • A: keep ceil(n/4) and document the limit.
    • B: count digit-only runs as ceil(n/3); everything else stays.
    • C: classify each ASCII run:
      • a run that mixes letters and digits counts ceil(n/2);
      • a digit-only run counts ceil(n/3);
      • a letter-only run counts ceil(n/4);
      • CJK and other scripts stay as ruled.

    The seat recommended C. The maintainer's answer, verbatim: 「C」.

    What the PR now owes:

    1. Implement C in the one shared estimate.
    2. Pin each measured case above at or above the reference count, beside the existing English, Chinese and mixed pins.
    3. Ablate each class back to ceil(n/4): each must turn its own pin red.
    4. Have the refusal message still tell the user to split the input.
    5. Update the changeset and PR body to state the three classes.

    Over-estimating plain alphanumeric codes by up to about 2× is the accepted cost. Inputs near the limit may be refused early, with a message that says why.

  11. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

    Ruling recorded · 2026-11-25T02:58Z · the residual under ruling C (7150730452), put to the maintainer in seat repo:objectstack#4's session.

    • The question: at head 183346bd of PR feat(embedder-openai): an over-limit input is refused, not truncated (known-model input limits, one shared token estimate) #37171, formula C covers two of the four measured cases (the 20-digit number and the URL with a 32-hex id). Two cases are still under-counted against cl100k: a UUID (28 vs 40) and sha256 hex plus base64 (71 vs 81). cl100k splits random hex at about 1 character per token and base64 at about 1.4, which is finer than the mixed class's 2.
    • Options:
      • C as is: document the residual, and add a follow-up only if there is pull.
      • C1: a mixed run counts 1 per character. This covers all four cases, but over-counts plain identifiers 2–3×.
      • C2: an a–f-only mixed run counts 1 per character.
    • The seat recommended C as is.
    • The maintainer's answer, verbatim: 「C 照现在合入(推荐)」.
    • So:
      • The head's formula stands.
      • The residual stays documented in the docblock and in knowledge-rag.mdx, and in the PR's Acceptance notes.
      • The two residual cases are not pinned, and no follow-up card is filed now. One is filed only when someone really embeds hash- or UUID-dense text.
      • The PR goes to L1 + L2.
  12. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    os-dev report · card #37093 · head 183346bd87274ce26d8d91f585562e73169c43a2 · PR #37171 · ruling 「C」 (7150730452), residual ruled 「C 照现在合入」 (7151457223)

    Relayed from the dev session session_01QSeKYpJCg2rG1RGK4BwAKx. The dev session made no GitHub writes: its relay command was refused by the auto-mode classifier, and it did not retry. The seat wrote the PR body instead.

    {
      "issue": 37093,
      "status": "done",
      "branch": "claude/issue-37093-embedder-input-limit",
      "pr": 37171,
      "head": "183346bd",
      "summary": "Ruling C in packages/spec/src/shared/token-estimate.ts: an ASCII run is counted by class — letters only ceil(n/4), digits only ceil(n/3), letters and digits mixed ceil(n/2) — via asciiRunTokens(); ASCII_RUN_CHARS_PER_TOKEN = { letters: 4, digits: 3, mixed: 2 } (same export name, no new export). CJK, punctuation, whitespace and x1.1 unchanged. Docblock, content/docs/ai/knowledge-rag.mdx and changeset updated.",
      "tests": "spec token-estimate.test.ts 28 passed (10 zh/mixed + 10 English cl100k fixtures incl. en-digits-20 and en-url-hex-id); embedder-openai 27 passed, the 'Split the text below the limit' wording pinned; typecheck 0. Per-class ablation: digits 3->4 turns en-digits-20 red; mixed 2->4 turns en-url-hex-id red; letters already 4 (no-op, no own pin). Each restored, blob == HEAD.",
      "gates": "check:generated 14/14; api-surface, export-origins, exported-any, docs, nul-bytes, doc-authoring and the three changeset gates exit 0; overlap-check clean. CI at 183346bd: 58 success, 12 skipped, 0 failed.",
      "deviations": [
        "pr_create and the body edit were refused in the dev session; the seat opened the PR and wrote the body on the maintainer's authorization",
        "UUID and sha256+base64 pins not landed: under C they estimate 28 vs 40 and 71 vs 81 (cl100k); documented, unpinned, per the maintainer's 「C 照现在合入」",
        "letters-class ablation is a no-op",
        "full spec suite not re-run since 2724c5e4 (only token-estimate.ts/test changed under spec/src; CI ran it)"
      ],
      "open_questions": [],
      "security_findings": "none"
    }
  13. objectstack-fleet commented on Nov 25, 2026

    @objectstack-fleet
    Contributor

    repo:objectstack#4 · os-justin · session_01QSeKYpRrYuqSLCvbSk9zrL

    Delivered · PR #37171 merged as 3d4f4238a5, through the merge queue. Not Tier H.

    • The merge landed at 2026-11-25T05:16Z. The closed-card sweep is clean: embedder-openai: an over-limit input is refused, not truncated (known-model input limits, one shared token estimate) #37093 is the only card this merge closed, and it is the named target.
    • @objectstack/spec now exports estimateTokens from shared, with the ruling-C formula. The residual (hex, base64, UUIDs, emoji, rare ideographs) is documented and not pinned, as the maintainer accepted.
    • embedder-openai refuses an input over the model's known input limit before anything is sent, and does not truncate it. maxInputTokens overrides the limit. The refusal message tells the caller to split the text.
    • Docs: content/docs/ai/knowledge-rag.mdx. Changeset: spec patch, embedder-openai patch.
    • Reviews: seat delta L1 ACCEPT (7152553241) and delta contract review PASS (7152546481), both at 8007e0bf. Landing record: comment 7153163108.
    • Open nit, not taken: L2 N8, the "1.4×" wording in the changeset.

    pm:dispatched removed. Zone a4-K closes out this card.

  14. removed
    pm:dispatched
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpriority:p2

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions