@@ -21,12 +21,13 @@ const KB_STATS_FLAGS = {
2121 start : {
2222 type : "string" ,
2323 valueHint : "<time>" ,
24- description : "Range start: Unix seconds or ISO date (default: 24 hours ago)" ,
24+ description :
25+ "Range start: Unix seconds or ISO date, must be in the past (default: 24 hours ago)" ,
2526 } ,
2627 end : {
2728 type : "string" ,
2829 valueHint : "<time>" ,
29- description : "Range end: Unix seconds or ISO date (default: now)" ,
30+ description : "Range end: Unix seconds or ISO date, must be in the past (default: now)" ,
3031 } ,
3132 ...WORKSPACE_FLAG ,
3233} satisfies FlagsDef ;
@@ -56,6 +57,7 @@ export default defineCommand({
5657 notes : [
5758 "Defaults to the last 24 hours when --start/--end are omitted." ,
5859 "Timestamps are normalized to epoch seconds as required by the server." ,
60+ "Future timestamps are rejected for --start and clamped to now for --end, since the monitor API only returns past data." ,
5961 ] ,
6062 exampleArgs : [
6163 "--index-id idx-xxx --workspace-id ws-xxx" ,
@@ -70,7 +72,21 @@ export default defineCommand({
7072 const startTimestamp = flags . start
7173 ? toEpochSecondsString ( flags . start )
7274 : String ( nowSeconds - 24 * 3600 ) ;
73- const endTimestamp = flags . end ? toEpochSecondsString ( flags . end ) : String ( nowSeconds ) ;
75+ let endTimestamp = flags . end ? toEpochSecondsString ( flags . end ) : String ( nowSeconds ) ;
76+
77+ // The monitor API rejects future timestamps with a misleading
78+ // "missing or invalid" error — validate here with a clear message.
79+ if ( Number ( startTimestamp ) > nowSeconds ) {
80+ throw new BailianError (
81+ `Start time is in the future; the monitor API only accepts past or current timestamps.` ,
82+ ExitCode . USAGE ,
83+ "Use a start date/time at or before now, or omit --start to default to 24 hours ago." ,
84+ ) ;
85+ }
86+ const clampedEnd = Number ( endTimestamp ) > nowSeconds ;
87+ if ( clampedEnd ) {
88+ endTimestamp = String ( nowSeconds ) ;
89+ }
7490
7591 const body = { indexId : flags . indexId , startTimestamp, endTimestamp } ;
7692 const endpoint = ragEndpoint ( workspaceId , RAG_PATHS . indexMonitor ) ;
@@ -90,6 +106,9 @@ export default defineCommand({
90106 emitResult ( response , format === "text" ? "json" : format ) ;
91107 return ;
92108 }
109+ if ( clampedEnd ) {
110+ emitBare ( "note: end time was in the future, clamped to now." ) ;
111+ }
93112 // Shape verified against the live API: the monitor fields are objects, not arrays
94113 const storage = response . data ?. storageMonitorData ;
95114 const qps = response . data ?. qpsMonitorData ;
0 commit comments