Skip to content

feat: support million-token context limit suffixes - #1985

Merged
akramcodez merged 6 commits into
Nano-Collective:mainfrom
KunjMaheshwari:fix/context-max-m-suffix
Nov 23, 2026
Merged

akramcodez merged 6 commits into
Nano-Collective:mainfrom
KunjMaheshwari:fix/context-max-m-suffix

Conversation

@KunjMaheshwari

@KunjMaheshwari KunjMaheshwari commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Introduces support for million-token context limits through the m/M suffix across Nanocoder’s string-based context-limit inputs.

This allows users to configure large context windows using intuitive values such as 1m instead of 1000k.

Key Changes

  • Added case-insensitive m/M suffix support with a multiplier of 1,000,000.
  • Preserved existing k/K suffix support with a multiplier of 1,000.
  • Added fractional suffixed values, including 1.5k and 1.5m.
  • Preserved existing rounding behavior for bare positive decimal values.
  • Added validation for malformed, overflowing, and unsafe values.
  • Unified parsing across CLI flags, slash commands, inline overrides, and environment variables.
  • Fixed context-limit environment-variable parsing to correctly handle suffixes.
  • Added regression coverage, including NANOCODER_CONTEXT_LIMIT=128k.
  • Updated CLI help, error messages, completions, and documentation.

Configuration compatibility: Suffix notation applies to string-valued overrides. Numeric contextWindow and contextWindows fields in agents.config.json retain their existing numeric format.

Testing and Validation

The following checks have been performed locally:

  • Context-limit parser unit tests.
  • Context-max handler tests.
  • Model and environment-variable tests.
  • Malformed CLI input regression test.
  • TypeScript type checking.
  • Biome formatting and linting.
  • Production build.
  • Git diff whitespace validation.

The complete CLI integration suite has also been investigated. Failures involving React/Ink and ACP provider initialization must be distinguished from failures introduced by this change.

GitHub Actions status: Required CI checks are pending execution/approval and will be updated once the workflows have completed.

Release Notes

Includes a minor changeset for this user-facing feature.

Related Issue

Closes #1977 when this PR is merged.

@KunjMaheshwari

Copy link
Copy Markdown
Contributor Author

Hi maintainers! 👋

I’ve implemented the changes requested in #1977, including support for m/M suffixes, improved numeric validation, updated error messages, documentation, and regression tests.

The relevant unit tests, type checks, and build pass locally.

One known limitation: successful CLI integration tests are currently affected by an existing React duplicate-key/runtime issue.

The PR is ready for review. I’d appreciate any feedback or suggestions for improvement.

Thanks for your time!

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

nc-review: comments — 3 important, 2 nits

@KunjMaheshwari — a few things worth a look, none blocking.

The PR adds m/M (and fractional) suffixes to context-limit overrides by generalising parseContextLimit, routing the NANOCODER_CONTEXT_LIMIT env var through it (which also fixes a silent truncation bug), and threading the new syntax through the CLI flag, the /context-max command, the ?context-max= inline override, the help text, the completion spec and the docs. The parsing logic itself is sound and the test coverage for the new suffix is real, but the change also silently narrows accepted input (bare fractional limits are now rejected) which reverses a deliberately pinned decision and is not surfaced in the PR description, and the changeset is filed as patch even though this is a user-facing feature plus a behaviour change.

🟠 important · changeset · .changeset/context-limit-suffixes.md:2

This is filed as patch, but CONTRIBUTING.md defines the bump types explicitly:

  • Patch — bug fixes only, no behavior changes
  • Minor — new features, backwards-compatible
  • Major — breaking changes

This PR adds a new user-facing capability (m/M suffixes on --context-max, /context-max, ?context-max= and NANOCODER_CONTEXT_LIMIT) and changes behaviour (bare fractional limits are now rejected). That is a minor at minimum; the other feature changesets in .changeset/ (mutation-firewall.md, vscode-lazy-acp-activation.md) are already minor. Shipping a new capability under a patch bump makes the 1.32.x release notes read as if nothing was added, and the repo has an explicit help_hash/release-note discipline that this under-sells.

🟠 important · correctness · source/utils/parse-context-limit.ts

Rejecting bare fractional limits is a public-contract narrowing that rides along with the feature and is not called out anywhere a reviewer would look.

On main, parseContextLimit('1024.5') → 1025 and parseContextLimit('0.5') → 1, so nanocoder --context-max 1024.5 exited 0 and set a limit. With this diff it returns null, so the same command now exits 1 with Invalid --context-max value, and /context-max 1024.5 turns into an error message instead of a limit.

This reverses a decision the maintainers made on purpose: the base spec pins parseContextLimit('0.5') === 1 under the name "smallest values that round to a positive limit", and the sibling changeset .changeset/context-limit-zero-infinity.md says they rejected only values that become 0 or Infinity while deliberately keeping values that round to a positive limit.

The new behaviour is defensible (rejecting an ambiguous token count is arguably better than silently rounding it), but it needs to be a stated decision rather than a side effect of the regex rewrite. Either say so explicitly in the PR description and the changeset, or keep bare fractions working and scope the change to the m suffix.

🟠 important · tests · source/models/models-dev-client.spec.ts:351

The env-var path is where this PR fixes a real 1000x bug, but the new test only pins the new suffix, not the broken one.

On main the env var was read with Number.parseInt(envLimit, 10), so NANOCODER_CONTEXT_LIMIT=128k resolved to 128 tokens — a user asking for 128k got a 128-token window. The diff replaces this with parseContextLimit(envLimit), which correctly yields 128000, but the only new test is '1.5m' → 1500000. Nothing pins NANOCODER_CONTEXT_LIMIT=128k → 128000, so the actual regression-guard for the fix is missing: a future change back to parseInt would keep the suite green.

Adding one case alongside the m test closes this:

test('getModelContextLimit - env variable accepts the k suffix', async t => {
	process.env.NANOCODER_CONTEXT_LIMIT = '128k';
	t.is(await getModelContextLimit('unknown-model-12345'), 128000);
});

⚪ nit · completeness · docs/configuration/index.md:164

The new paragraph — "Context-limit overrides accept positive integers, or decimal values with a k/K (1,000) or m/M (1,000,000) suffix" — is placed at the end of the Context Limit Resolution Order section, whose list includes items 2 and 3 (contextWindows[model] and contextWindow in agents.config.json). Those two are schema-validated JSON numbers (source/types/config.ts: contextWindow?: number), so "128k" is rejected by the config schema outright — source/config/config-schema.spec.ts even asserts contextWindows must map to numbers.

As written, a reader can reasonably infer that contextWindow accepts a suffixed string. Scope the sentence to the string-valued inputs (/context-max, --context-max, ?context-max=, NANOCODER_CONTEXT_LIMIT) and say that the agents.config.json fields stay plain numbers.

⚪ nit · contributing

The PR description is still the unmodified template — every checkbox is unchecked and the body reads "Brief description of what this PR does". That is how the bare-fraction rejection above (a CLI behaviour change) ended up invisible to reviewers, since the only place it is mentioned is one clause of the changeset body. Filling in the description with what changed, which inputs are now rejected, and the bump level would make this PR reviewable at a glance.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:comments nc-review left non-blocking findings label Nov 6, 2026
@KunjMaheshwari

Copy link
Copy Markdown
Contributor Author

Hi maintainers!

I’ve addressed the automated review feedback and pushed the revisions.

I’ve also synchronized the feature branch with the latest upstream main. The focused unit tests (134), TypeScript checks, and formatting checks are passing.

I investigated the CLI integration test failures against both the original feature commit and upstream baseline and confirmed they are pre-existing runtime/test-environment issues.

The PR is ready for another review. Thank you!

@KunjMaheshwari

Copy link
Copy Markdown
Contributor Author

Hi maintainers,

I’ve completed another comprehensive audit of PR #1985 and pushed the final cleanup.

During the audit, I identified and removed four unrelated generated Playwright snapshots to keep the PR focused exclusively on the context-limit feature.

The latest commit is ef4e757.

The focused test suite (134 tests), targeted coverage, TypeScript checks, formatting, linting, dependency analysis, and production build have passed.

I also investigated the CLI integration failures against the upstream baseline and confirmed that the React/Ink and ACP provider-initialization issues are present there as well.

Could a maintainer please approve the pending GitHub Actions workflow so that the required CI checks can execute?

Once the checks complete, I’d appreciate a final code-owner review.

Thank you for your time and consideration!

@KunjMaheshwari

Copy link
Copy Markdown
Contributor Author

Hi maintainers,

Just following up on PR #1985.

I’ve completed the implementation, addressed the automated review feedback, removed unrelated generated artifacts, and performed a final validation of the changes.

The latest commit is ef4e757.

Could someone with the required permissions please approve the pending GitHub Actions workflow so that the required checks can execute?

I’d also appreciate a final code-owner review whenever convenient.

Thank you for your time and consideration!

@will-lamerton will-lamerton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @KunjMaheshwari, the change itself looks good, and you've covered the automated feedback well (minor changeset, bare decimals still rounded, the 128k env test, docs limited to the string inputs). It also fixes a real bug: on main, NANOCODER_CONTEXT_LIMIT=128k is read with parseInt and becomes 128 tokens.

Needs a rebase. The branch is about 215 commits behind main and conflicts in 6 files. The main one: #2133 moved /context-max onto StatefulCommand and deleted source/app/utils/handlers/context-max-handler.ts and its spec. That logic now lives in source/commands/context-max.ts, so the new error message and examples need to move there, along with their tests.

Once it's rebased, we'll approve the CI workflows so they run on the final head.

Nit: the Number.isFinite(parsed) early return is redundant, since Number.isSafeInteger(limit) below already rejects Infinity.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @KunjMaheshwari, thanks for this PR! It looks like a maintainer has left feedback
or review activity and there are still some outstanding items to wrap up.

Whenever you get a chance, could you take a look at the open comments?
If anything is unclear or you'd like a hand, just reply here and we'll help you get it across the line.

KunjMaheshwari and others added 6 commits November 20, 2026 23:02
… documentation

- Implemented m/M suffix support for context limits in --context-max and /context-max commands.
- Enhanced numeric validation and updated error messages for better user experience.
- Added regression tests for valid and invalid inputs to ensure reliability.
- Updated documentation to reflect new features and usage examples.
- Addressed feedback from previous reviews and improved overall code quality.
@KunjMaheshwari
KunjMaheshwari force-pushed the fix/context-max-m-suffix branch from ef4e757 to 57448b8 Compare November 20, 2026 19:14
@KunjMaheshwari

Copy link
Copy Markdown
Contributor Author

@will-lamerton Thanks for the detailed feedback!

I’ve rebased the branch onto the latest main and resolved all six conflicts.

I’ve also migrated the /context-max changes and tests to the new StatefulCommand implementation, removed the redundant Number.isFinite(parsed) check, and preserved the previously reviewed behavior and documentation updates.

All local validations are passing, including:

  • Unit and CLI integration tests (43/43 CLI tests passing).
  • TypeScript checks, linting, and formatting.
  • Production build and changeset validation.

I’ve pushed the updated changes to the existing PR.

The GitHub Actions workflow is currently awaiting approval to run against the updated PR head.

Thanks again for reviewing!

@akramcodez akramcodez left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

...

@akramcodez
akramcodez merged commit c84b829 into Nano-Collective:main Nov 23, 2026
18 checks passed

@akramcodez akramcodez left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

...

@akramcodez

Copy link
Copy Markdown
Member

Thanks @KunjMaheshwari, merged! Million-token limits like 1m now work everywhere a context limit is accepted.

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

Labels

agent:comments nc-review left non-blocking findings area:docs Documentation area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Accept an m suffix in --context-max and /context-max (1m)

3 participants