[C-9399-D1-S3] enforce strictest per-tier token limits before dispatch · Issue #20060 · developing-today/code · GitHub
Skip to content

[C-9399-D1-S3] enforce strictest per-tier token limits before dispatch #20060

Backlog

Description

@developing-today-fleet

Parent: #9399 · D1-S3 · crucial · implementation repo: developing-today-forks/opencode

Goal

At the OpenCode route boundary, compute effective {input, output, cache, total} token limits independently per resolved member and tier. Each limit is a positive integer or null (unknown; not zero or unlimited). Use the minimum positive known bound for each metric across provider/model native limits, provider/door policy caps, leaf/target caps, referenced pool/tier caps, and selected pool/tier caps. Use the existing requestTokens?: number route-resolution argument as the known total/legacy-context request size (context caps map to D1 total). Build the pre-dispatch comparison shape {input, output, cache, total}: use other positive request counts only if the existing route request path explicitly supplies them; otherwise leave those fields null. Provider usage returned after the call cannot gate that same call. Unknown sizes do not skip on that metric. Do not add a tokenizer or guess counts. Skip a member with typed tier-limit-exceeded before provider dispatch when any known request size exceeds its effective cap; this route-level skip is distinct from an upstream provider/account limit failure.

Read first

Owned paths

In developing-today-forks/opencode:

  • packages/schema/src/config/model-routes.ts
  • packages/core/src/model-route.ts
  • packages/core/src/model-route-expansion.ts
  • packages/core/test/model-route-tier-limits.test.ts

Test-first oracle

Write the property test first using generated cap sets and explicit request-size vectors: adding or tightening any applicable cap can never increase that metric’s effective limit. For each input/output/cache/total metric, test independent minimum selection across the cap sources above; null/unknown behavior; rejection of zero/negative caps and cache > input when both are known; preservation of null when no bound exists; and an over-limit explicit pre-dispatch count skipped as route-level tier-limit-exceeded before any provider call, distinct from an upstream provider/account limit failure. The existing requestTokens value drives total; input/output/cache stay null unless supplied on the pre-dispatch request path. Post-call provider usage is not a request-size source. Missing counts, including cache counts known only after dispatch, remain unknown and do not cause a skip. No tokenizer or token-accounting feature is in scope. For a cross-pool reference, the effective limit is the minimum of the referenced effective limit and the receiving tier cap.

Done check: cd packages/core && bun run test test/model-route-tier-limits.test.ts

Use a property-based test oracle: each metric equals the minimum positive known applicable cap; unknown adds no numeric bound and the result remains null if all sources are unknown. Adding a stricter cap cannot increase the result. Pre-dispatch comparison consumes only explicit positive counts from the existing route request; absent counts are unknown, and this slice adds no tokenizer.

Dependencies and boundaries

Blocked by D1-S2 (#20059); do not start until that implementation is merged. Consume its ordered resolved leaves, each identified by provider/door, model, and exact native variant, with the selected tier and any referenced pool/tier caps and source provenance. The code-level TypeScript type is the one D1-S2 actually exports; adapt to it after merge rather than inventing a parallel resolved-member shape.

Use the existing requestTokens parameter as total; other dimensions are positive only when already supplied before dispatch, otherwise null. Provider usage cannot gate the completed call. No tokenizer is added. Do not introduce provider-specific empirical limits or tier rankings here.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-12-05T05:15:59Z",
    "session_id": null,
    "lane": null,
    "host": "amd",
    "worktree": "/home/user/git/code",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/user/git/code",
      "repo": "developing-today/code",
      "branch": "main",
      "sha": "b33fca1316d5d06f3cebcc5ed3d8bb33913e5f6e"
    },
    "auth_subject": "agent-next-27-local",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Acceptance criteria

  • At the OpenCode route boundary, effective {input, output, cache, total} token limits are computed independently per resolved member and tier.
  • Each limit is the minimum positive known bound across provider/model native limits, provider/door policy caps, leaf/target caps, and referenced + selected pool/tier caps; unknown limits stay null (never zero/unlimited).
  • The pre-dispatch comparison uses the existing requestTokens argument as the known total; other request counts are used only when the route path explicitly supplies them, else null.
  • Tests cover per-tier strictest-limit selection, null/unknown handling, and dispatch rejection when a known limit is exceeded.

Activity

  1. added
    kind/feature
    priority/normal
    effort/m
    task/feature-slice
    on Dec 5, 2026
  2. added
    meta/enriched
    status/needs-triage
    on Dec 5, 2026
  3. developing-today-fleet commented on Dec 5, 2026

    @developing-today-fleet
    ContributorAuthor

    Intake review

    🤖 Agent note · filed

    • Agent: fleet monitor
    • Session / ID: repo-fleet-monitor run 2026-12-05 01:14 CST
    • Found via: monitor reconciliation (intake enrichment, protocol §5)
    • Task: Intake pass on issue [C-9399-D1-S3] enforce strictest per-tier token limits before dispatch #20060: verified still live (no merged PR explicitly resolves it in this run's checks), appended acceptance criteria to the body, normalized labels, added meta/enriched.
    • Expectation: [C-9399-D1-S3] enforce strictest per-tier token limits before dispatch
    • Links: parent/related items are named in the notes below.

    Notes: Parent program issue #9399 (D1-S3 slice). Labels already kind/feature, priority/normal, effort/m; monitor added status/needs-triage + meta/enriched and appended acceptance criteria from the body's Goal section.

    Risks / suggested approach: Depends on the D1-S1 resolver contract (issue #20058) landing first, per the D1 slice map; a queued slice task for sibling D1-S2 (issue #20059, task 27592) is dep-blocked on the same contract. No merged PR explicitly resolves this issue as of this run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mkind/featuremeta/enrichedpriority/normalstatus/needs-triagetask/feature-slice

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions