Session statistics (no persistence) #46

Closed
opened 2026-02-15 04:14:27 +03:00 by NiXTheDev · 0 comments
NiXTheDev commented 2026-02-15 04:14:27 +03:00 (Migrated from github.com)

Description

Show real-time processing statistics for the current message chain without persisting any data.

Use Case

Users want visibility into how their substitutions are performing without storing data long-term.

Implementation Plan

  1. In-memory tracking (per message only)

    • Track substitution count in current chain
    • Measure compilation and execution time
    • Count cache hits/misses
    • No persistence beyond message processing
  2. Smart placement logic
    Calculate dynamically if performance text fits:

    available_space = 4096 - result_length - performance_length - 1 (for newline)
    

    If fits: Append to result message with newline separator

    Result text
    
    Performed X substitutions in Yms
    

    If doesn't fit: Send as separate message

  3. Edit handling (complex logic)
    When user edits the sed command:

    a) Removing 'p' flag:

    • Delete the performance message (if separate)
    • Or edit result to remove performance line

    b) Adding 'p' flag:

    • Check if fits in result message
    • If yes: Inline it
    • If no: Send as separate message

    c) Command changed (different result):

    • Recalculate space availability
    • If was separate and now fits: Delete separate message, inline in result
    • If was inline and now doesn't fit: Remove from result, send as separate
    • If still doesn't fit: Update both messages
    • If still fits inline: Update result message only
  4. Time unit logic

    • < 1000ms: "Xms"
    • < 60000ms: "Xs" (e.g., "1.2s")
    • < 3600000ms: "Xm Ys"
    • = 3600000ms: "Xh Ym"

  5. Data to collect

    • Number of successful substitutions
    • Total processing time
    • Cache hit/miss count (optional)
    • Time per substitution (optional)
  6. Storage for edits

    • Store bot message IDs in memory:
      • Result message ID
      • Performance message ID (if separate)
    • Track if performance is inlined or separate
    • Clean up after edit window expires (48h)

In-Memory Tracking (No Persistence)

Store performance message metadata in memory only:

interface PerformanceMessageInfo {
	chatId: number;
	targetMessageId: number; // User's sed command message
	resultMessageId: number; // Bot's reply with substitution result
	performanceMessageId?: number; // Separate performance message (undefined if inlined)
	isInlined: boolean;
	timestamp: number;
}

// In-memory Map: key = `${chatId}:${targetMessageId}`
const performanceMessageTracker = new Map<string, PerformanceMessageInfo>();

// Cleanup old entries periodically (after 48h, matching Telegram edit window)

Acceptance Criteria

  • Calculates available space dynamically (includes newline)
  • Inlines performance when space available
  • Sends separate message when no space
  • Handles edit: removing 'p' flag
  • Handles edit: adding 'p' flag
  • Handles edit: result changes (inline ↔ separate transition)
  • Updates correct messages on edits
  • Time units scale appropriately
  • No persistent storage of statistics

Example Scenarios

Scenario 1: Short result, fits inline

User: s/foo/bar/gp
Bot: bar baz

      Performed 1 substitution in 8ms

Scenario 2: Long result, separate message

User: s/complex_pattern/replacement/gp (result is 4064+ chars)
Bot [msg 1]: replacement text (4064 chars)
Bot [msg 2]: Performed 1 substitution in 2.5s

Scenario 3: Edit removes 'p' flag

User edits: s/foo/bar/gp → s/foo/bar/
Bot: Edits message to remove "Performed..." line
[Or deletes separate performance message]

Scenario 4: Edit changes result size (now fits)

Original: Long result, performance separate
Edit: Shorter result
Bot: Deletes performance message
Bot: Edits result to inline performance

Scenario 5: Edit changes result size (no longer fits)

Original: Short result, performance inline
Edit: Longer result
Bot: Edits result to remove performance line
Bot: Sends new performance message

Part of Epic #38
Merged from #49 (enhanced performance flag with substitution count)

## Description Show real-time processing statistics for the current message chain without persisting any data. ## Use Case Users want visibility into how their substitutions are performing without storing data long-term. ## Implementation Plan 1. **In-memory tracking** (per message only) - Track substitution count in current chain - Measure compilation and execution time - Count cache hits/misses - No persistence beyond message processing 2. **Smart placement logic** Calculate dynamically if performance text fits: ``` available_space = 4096 - result_length - performance_length - 1 (for newline) ``` If fits: Append to result message with newline separator ``` Result text Performed X substitutions in Yms ``` If doesn't fit: Send as separate message 3. **Edit handling (complex logic)** When user edits the sed command: a) **Removing 'p' flag:** - Delete the performance message (if separate) - Or edit result to remove performance line b) **Adding 'p' flag:** - Check if fits in result message - If yes: Inline it - If no: Send as separate message c) **Command changed (different result):** - Recalculate space availability - If was separate and now fits: Delete separate message, inline in result - If was inline and now doesn't fit: Remove from result, send as separate - If still doesn't fit: Update both messages - If still fits inline: Update result message only 4. **Time unit logic** - < 1000ms: "Xms" - < 60000ms: "Xs" (e.g., "1.2s") - < 3600000ms: "Xm Ys" - > = 3600000ms: "Xh Ym" 5. **Data to collect** - Number of successful substitutions - Total processing time - Cache hit/miss count (optional) - Time per substitution (optional) 6. **Storage for edits** - Store bot message IDs in memory: - Result message ID - Performance message ID (if separate) - Track if performance is inlined or separate - Clean up after edit window expires (48h) ## In-Memory Tracking (No Persistence) Store performance message metadata in memory only: ```typescript interface PerformanceMessageInfo { chatId: number; targetMessageId: number; // User's sed command message resultMessageId: number; // Bot's reply with substitution result performanceMessageId?: number; // Separate performance message (undefined if inlined) isInlined: boolean; timestamp: number; } // In-memory Map: key = `${chatId}:${targetMessageId}` const performanceMessageTracker = new Map<string, PerformanceMessageInfo>(); // Cleanup old entries periodically (after 48h, matching Telegram edit window) ``` ## Acceptance Criteria - [ ] Calculates available space dynamically (includes newline) - [ ] Inlines performance when space available - [ ] Sends separate message when no space - [ ] Handles edit: removing 'p' flag - [ ] Handles edit: adding 'p' flag - [ ] Handles edit: result changes (inline ↔ separate transition) - [ ] Updates correct messages on edits - [ ] Time units scale appropriately - [ ] No persistent storage of statistics ## Example Scenarios **Scenario 1: Short result, fits inline** ``` User: s/foo/bar/gp Bot: bar baz Performed 1 substitution in 8ms ``` **Scenario 2: Long result, separate message** ``` User: s/complex_pattern/replacement/gp (result is 4064+ chars) Bot [msg 1]: replacement text (4064 chars) Bot [msg 2]: Performed 1 substitution in 2.5s ``` **Scenario 3: Edit removes 'p' flag** ``` User edits: s/foo/bar/gp → s/foo/bar/ Bot: Edits message to remove "Performed..." line [Or deletes separate performance message] ``` **Scenario 4: Edit changes result size (now fits)** ``` Original: Long result, performance separate Edit: Shorter result Bot: Deletes performance message Bot: Edits result to inline performance ``` **Scenario 5: Edit changes result size (no longer fits)** ``` Original: Short result, performance inline Edit: Longer result Bot: Edits result to remove performance line Bot: Sends new performance message ``` ## Related Part of Epic #38 Merged from #49 (enhanced performance flag with substitution count)
Sign in to join this conversation.
No description provided.