Skip to content

feat: invert token limits priority to .waza.yaml first #59#64

Open
wbreza wants to merge 6 commits intomainfrom
squad/59-token-limits-priority
Open

feat: invert token limits priority to .waza.yaml first #59#64
wbreza wants to merge 6 commits intomainfrom
squad/59-token-limits-priority

Conversation

@wbreza
Copy link
Collaborator

@wbreza wbreza commented Mar 4, 2026

Closes #59
Part of #20

What changed

  • resolveLimitsConfig() now checks .waza.yaml tokens.limits first
  • .token-limits.json is legacy fallback only
  • Deprecation warning when .token-limits.json is the active source
  • Updated both call sites (check.go, suggest.go) for new return signature

Testing

  • 8 new tests covering all 4 scenarios (waza-only, legacy-only, both, neither)
  • Existing TestCheck_ConfigLimits and TestCheck_DefaultLimitsWhenNoConfig pass
  • go test ./... green

@wbreza wbreza requested review from chlowell and spboyer as code owners March 4, 2026 22:44
Copilot AI review requested due to automatic review settings March 4, 2026 22:44
@wbreza wbreza requested a review from richardpark-msft as a code owner March 4, 2026 22:44
@github-actions github-actions bot enabled auto-merge (squash) March 4, 2026 22:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates token limits configuration precedence to support the ongoing config consolidation work: .waza.yaml tokens.limits is now the primary source, with .token-limits.json treated as a legacy fallback and accompanied by a deprecation warning when used.

Changes:

  • Inverted resolveLimitsConfig() precedence to prefer .waza.yaml tokens.limits, falling back to .token-limits.json, then built-in defaults.
  • Updated check and suggest flows to handle the new (cfg, usedLegacy) return and emit a deprecation warning when legacy config is active.
  • Added unit + integration tests and new fixtures for .waza.yaml limits and “both present” precedence.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
cmd/waza/tokens/helpers.go Changes limits resolution order and returns a legacy-usage flag.
cmd/waza/tokens/check.go Uses new helper return signature; emits legacy deprecation warning.
cmd/waza/tokens/suggest.go Uses new helper return signature; emits legacy deprecation warning.
cmd/waza/tokens/helpers_test.go Adds unit tests for precedence scenarios.
cmd/waza/tokens/check_test.go Adds integration tests validating .waza.yaml precedence in check.
cmd/waza/tokens/testdata/check/waza-yaml-limits/* New fixtures for .waza.yaml-based limits.
cmd/waza/tokens/testdata/check/both-configs/* New fixtures for “both configs present; .waza.yaml wins”.
.squad/agents/linus/history.md Documents the change and testing summary.

@wbreza
Copy link
Collaborator Author

wbreza commented Mar 4, 2026

Rusty architecture review summary:

  • Priority is correctly inverted (.waza.yaml first, .token-limits.json fallback, defaults last).
  • Deprecation warning text is clear and actionable.
  • (cfg, usedLegacy) is the right signature; warning emission belongs at call sites and both check/suggest are wired correctly.
  • Coverage includes all 4 source-resolution scenarios and preserves legacy-only behavior.

I cannot submit an approve review on this PR because GitHub blocks approving your own pull request, but this is architecturally good to merge.

@richardpark-msft
Copy link
Member

@copilot, are there any relevant spots to add documentation for this? I think users will need to know how all the configs and overrides intersect.

Copy link
Contributor

Copilot AI commented Mar 4, 2026

@richardpark-msft I've opened a new pull request, #70, to work on those changes. Once the pull request is ready, I'll request review from you.

wbreza added a commit that referenced this pull request Mar 4, 2026
- Fix gofmt indentation in resolveLimitsConfig (helpers.go)
- Handle overrides-only edge case in resolveLimitsConfig (helpers.go)
- Route deprecation warning through io.Writer/cmd.ErrOrStderr() (check.go)
- Route deprecation warning through cmd.ErrOrStderr() (suggest.go)
- Fix json.Marshal error handling in tests (helpers_test.go)
- Add TestResolveLimitsConfig_OverridesOnly test (helpers_test.go)
- Add TestCheck_LegacyWarningEmitted and TestCheck_NoWarningWithWazaYaml (check_test.go)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 4, 2026 23:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

site/src/content/docs/guides/token-limits.mdx:57

  • This section says fallbackLimit is “Limit applied to files that match no pattern”, but token limit fallback for waza tokens check/suggest is currently hard-coded to 2000 via internal/checks.FallbackLimit, and .waza.yaml tokens.fallbackLimit isn’t used in the token limits checker. Please clarify what fallbackLimit actually affects today (or implement support for it).
| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `warningThreshold` | integer | `2500` | Token count at which a soft warning is shown |
| `fallbackLimit` | integer | `1000` | Limit for files that match no pattern |
| `limits.defaults` | map | (built-in) | Glob patterns → token limits |
| `limits.overrides` | map | `{}` | Exact file paths → token limits (take precedence over `defaults`) |

Both `limits.defaults` and `limits.overrides` are optional — you can set only one of them. If `tokens.limits` is present in `.waza.yaml` but neither map is set, `.token-limits.json` is **not** consulted as a fallback; `.waza.yaml` is the definitive source.

Copy link
Member

@spboyer spboyer left a comment

Choose a reason for hiding this comment

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

Rusty (Opus 4.6) — Lint Still Failing

Last commit: \ ix: gofmt helpers.go\ (March 4) — but the Lint check is still ❌. Tests pass on both ubuntu and windows, but golangci-lint fails.

Action needed: Run \golangci-lint run\ locally, fix the remaining lint issue, and push.

@spboyer
Copy link
Member

spboyer commented Mar 5, 2026

Fixed lint errors and rebased on main.

spboyer pushed a commit to spboyer/waza-fk that referenced this pull request Mar 5, 2026
- Fix gofmt indentation in resolveLimitsConfig (helpers.go)
- Handle overrides-only edge case in resolveLimitsConfig (helpers.go)
- Route deprecation warning through io.Writer/cmd.ErrOrStderr() (check.go)
- Route deprecation warning through cmd.ErrOrStderr() (suggest.go)
- Fix json.Marshal error handling in tests (helpers_test.go)
- Add TestResolveLimitsConfig_OverridesOnly test (helpers_test.go)
- Add TestCheck_LegacyWarningEmitted and TestCheck_NoWarningWithWazaYaml (check_test.go)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
wbreza and others added 5 commits March 5, 2026 09:25
resolveLimitsConfig() now checks .waza.yaml tokens.limits as the primary
source. .token-limits.json is only used as a legacy fallback when .waza.yaml
has no limits configured, and emits a deprecation warning when active.

Priority order:
  1. .waza.yaml tokens.limits (primary)
  2. .token-limits.json (legacy fallback with deprecation warning)
  3. Built-in defaults

Tests cover all four scenarios: waza-only, legacy-only, both-present
(.waza.yaml wins), and neither-present.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Initial plan

* docs: add token limits configuration guide and update schema/CLI references

Co-authored-by: richardpark-msft <51494936+richardpark-msft@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: richardpark-msft <51494936+richardpark-msft@users.noreply.github.com>
- Fix gofmt indentation in resolveLimitsConfig (helpers.go)
- Handle overrides-only edge case in resolveLimitsConfig (helpers.go)
- Route deprecation warning through io.Writer/cmd.ErrOrStderr() (check.go)
- Route deprecation warning through cmd.ErrOrStderr() (suggest.go)
- Fix json.Marshal error handling in tests (helpers_test.go)
- Add TestResolveLimitsConfig_OverridesOnly test (helpers_test.go)
- Add TestCheck_LegacyWarningEmitted and TestCheck_NoWarningWithWazaYaml (check_test.go)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assign fmt.Fprintf return values to _ in check.go and suggest.go to
satisfy golangci-lint errcheck. These are warning messages to stderr
where ignoring the error is the standard Go pattern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@wbreza wbreza force-pushed the squad/59-token-limits-priority branch from e6eedcb to f36fedf Compare March 5, 2026 17:27
Copilot AI review requested due to automatic review settings March 5, 2026 17:27
@wbreza wbreza closed this Mar 5, 2026
auto-merge was automatically disabled March 5, 2026 17:37

Pull request was closed

@wbreza wbreza reopened this Mar 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@wbreza wbreza force-pushed the squad/59-token-limits-priority branch from 087617e to c7e2d06 Compare March 5, 2026 17:44
@wbreza wbreza closed this Mar 5, 2026
@wbreza wbreza reopened this Mar 5, 2026
@github-actions github-actions bot enabled auto-merge (squash) March 5, 2026 17:51
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.

Invert token limits priority: .waza.yaml first, .token-limits.json as legacy fallback

5 participants