diff --git a/aws/telegram-commands.json b/aws/telegram-commands.json index 031c34b..151ae07 100644 --- a/aws/telegram-commands.json +++ b/aws/telegram-commands.json @@ -91,6 +91,10 @@ { "command": "trade_stats", "description": "Show portfolio summary with P&L" + }, + { + "command": "stats", + "description": "Show command usage statistics" } ] } diff --git a/internal/modules/stats/stats.go b/internal/modules/stats/stats.go index 9cd6c23..f1935ad 100644 --- a/internal/modules/stats/stats.go +++ b/internal/modules/stats/stats.go @@ -31,7 +31,9 @@ type counter struct { func countKey(name string) string { return countPrefix + name } // Inc increments the persistent invocation count for the named command. -// Errors are logged and swallowed — stats are best-effort. +// Errors are logged and swallowed and concurrent invocations of the same +// command may lose updates — stats are best-effort. A future atomic +// increment (e.g. DynamoDB UpdateItem ADD) would close the race. func (c *counter) Inc(ctx context.Context, name string) { key := countKey(name) var entry countEntry diff --git a/template.yaml b/template.yaml index 71c4fdd..7cda82c 100644 --- a/template.yaml +++ b/template.yaml @@ -135,8 +135,6 @@ Resources: TELEGRAM_WEBHOOK_SECRET_PARAMETER_NAME: !Sub "/miti99bot/${StackEnv}/telegram-webhook-secret" GEMINI_API_KEY_PARAMETER_NAME: !Sub "/miti99bot/${StackEnv}/gemini-api-key" CRON_SHARED_SECRET_PARAMETER_NAME: !Sub "/miti99bot/${StackEnv}/cron-shared-secret" - # stats module uses non-atomic KV increment; concurrency > 1 would lose counts. - ReservedConcurrentExecutions: 1 FunctionUrlConfig: AuthType: NONE InvokeMode: BUFFERED