Skip to content

fix: use minute-level granularity for MOIM timestamps#1

Closed
sihyeonn wants to merge 1 commit intomainfrom
fix/moim-timestamp-minute-granularity
Closed

fix: use minute-level granularity for MOIM timestamps#1
sihyeonn wants to merge 1 commit intomainfrom
fix/moim-timestamp-minute-granularity

Conversation

@sihyeonn
Copy link
Owner

Summary

Fixes agent infinite loop caused by second-level timestamp changes in MOIM (Minus One Info Message) injection.

Problem

Agent repeatedly updates files every 5-7 seconds, only changing the datetime comment:

editing /Users/user/Work/Oss/AIP/apisix/scripts/adc-preload.sh

# First edit - adds timestamp comment
old_str: #!/bin/bash # ADC Script...
new_str: #!/bin/bash # ADC Script...
         #
         # <info-msg>
         # Datetime: 2025-12-29 09:06:51
         # </info-msg>

# 7 seconds later - updates only timestamp
old_str: # Datetime: 2025-12-29 09:06:51
new_str: # Datetime: 2025-12-29 09:06:58

# 5 seconds later - updates again
old_str: # Datetime: 2025-12-29 09:06:58
new_str: # Datetime: 2025-12-29 09:07:03

# Continues indefinitely...

Root Cause

  1. collect_moim() generates timestamp with second-level precision (%Y-%m-%d %H:%M:%S)
  2. This <info-msg> is injected into conversation via inject_moim()
  3. Agent interprets it as file content and adds as comment
  4. Next turn (5-7s later): new timestamp → agent detects "outdated" datetime → updates file
  5. Repeat forever

Solution

Use minute-level granularity by fixing seconds to :00:

// Before: Changes every second
let timestamp = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();

// After: Changes every minute
let timestamp = chrono::Local::now().format("%Y-%m-%d %H:%M:00").to_string();

This keeps conversation stable within a 1-minute window, preventing infinite loop for 99% of use cases (tasks completing within 1 minute).

Impact

  • Minimal change: Only 1 line modified + 1 simple test added
  • No breaking changes: Existing behavior preserved
  • All tests pass: No modifications to existing tests needed
  • Practical solution: Solves the issue for typical agent tasks

Type of Change

  • Bug fix
  • Performance improvement

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Added test to verify minute-level granularity:

#[tokio::test]
async fn test_collect_moim_uses_minute_granularity() {
    let em = ExtensionManager::new_without_provider();
    if let Some(moim) = em.collect_moim().await {
        assert!(moim.contains(":00\n"), "Timestamp should use minute granularity");
    }
}

All existing tests continue to pass (6 existing + 1 new = 7 total).

Manual testing confirmed the infinite loop no longer occurs for tasks completing within 1 minute.

Related Issues

Builds on block#6101 which changed datetime format from "Datetime:" to "It is currently" to help LLMs recognize the current year.

While block#6101 improved LLM understanding, it didn't address the infinite loop issue caused by second-level timestamp changes. This PR completes the fix by using minute-level granularity.

Relates to block#6066

Screenshots/Demos (for UX changes)

N/A - Internal behavior change only

@sihyeonn sihyeonn force-pushed the fix/moim-timestamp-minute-granularity branch from 5605b89 to 81116ff Compare December 29, 2025 06:24
Prevents agent infinite loop by using minute-level timestamps (:00)
instead of second-level timestamps. This keeps conversation stable
within a 1-minute window, preventing agents from repeatedly updating
timestamp comments in files.

Fixes the reported issue where agents would edit files every 5-7
seconds to update datetime comments like:
  # Datetime: 2025-12-29 09:06:51
  # Datetime: 2025-12-29 09:06:58  (7s later)
  # Datetime: 2025-12-29 09:07:03  (5s later)
  ... continuing indefinitely

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
@sihyeonn sihyeonn force-pushed the fix/moim-timestamp-minute-granularity branch from 81116ff to 3620572 Compare December 29, 2025 06:27
@sihyeonn sihyeonn closed this Dec 30, 2025
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.

1 participant