Tasks: add-aggregate-other-rollup
tasks16/16
1. Reference contract (schemas)
- 1.1 Add
other_count: { type: "integer", minimum: 0 }toAggregationResponseSchemainpackages/reference-contract/src/public/index.ts. Document that it is emitted whenever a grouping dimension is present (zero when all groups fit; omitted for ungrouped aggregations). Reference the openspec change in the comment. - 1.2 Update the
aggregateStreammanifest summary inpackages/reference-contract/src/public/index.tsto describeother_countand the truncation-detection guarantee.
2. Reference implementation
- 2.1
reference-implementation/server/records.js: in thegroup_bybranch, capture the sorted full group list before slicing; setresponse.other_countto the sum of counts in the truncated tail (sortedGroups.slice(aggregateRequest.limit)). - 2.2
reference-implementation/server/records.js: same change for thegroup_by_timebranch. - 2.3 Confirm that ungrouped aggregation paths (scalar
count,sum,min,max,count_distinct) do NOT emitother_count.
3. MCP adapter
- 3.1
packages/mcp-server/src/tools.js: update theaggregatetool description to mentionother_countso models know to check it for truncation detection without a second call. - 3.2
packages/mcp-server/src/tools.js: updatesummarizeAggregateto includeother_count=Nin the text summary when present on the RS response.
4. Tests
- 4.1
reference-implementation/test/aggregate-time-buckets.test.js: addassert.equal(res.other_count, 0)to the existing scalargroup_bytest (all groups fit within limit). - 4.2 Same inline assertion for the existing
group_by_timeUTC-day test. - 4.3 New test:
group_by other_count is the sum of counts for groups beyond limit— limit=2, 3 distinct values, asserts other_count=1. - 4.4 New test:
group_by other_count is 0 when all groups fit within limit— limit=100, 3 groups, asserts other_count=0. - 4.5 New test:
group_by_time other_count covers buckets truncated by limit— limit=2, 4 buckets, asserts other_count=2 (sum of tail counts).
5. Validation
- 5.1
reference-implementation/test/aggregate-time-buckets.test.js: 16 tests pass (was 13). - 5.2 Full
packages/mcp-serversuite green (136 tests). - 5.3
openspec validate --all --strictgreen. - 5.4
git diff --check; grep changed public names for consistency.
Acceptance checks
Reproducible commands:
node --test reference-implementation/test/aggregate-time-buckets.test.js
node --test packages/mcp-server/test/aggregate-tool.test.js
node --test packages/mcp-server/test/*.test.js
openspec validate add-aggregate-other-rollup --strict
openspec validate --all --strict