Skip to content

fix(cloud): PR #129 bugs — u32 timestamp, entry_idx duplicates, small buffer #134

@gHashTag

Description

@gHashTag

Context

PR #129 (feat/issue-124) has 3 critical bugs found in code review. Fix them on the existing branch feat/issue-124.

Bugs to fix

1. u32 timestamp overflow (cloud_monitor.zig)

last_event_times uses u32 but std.time.timestamp() returns i64. Fix:

// BEFORE (broken):
var last_event_times: [MAX_AGENTS][2]u32 = ...
last_event_times[i][1] = @as(u32, @intCast(now));

// AFTER:
var last_event_times: [MAX_AGENTS][2]i64 = ...
last_event_times[i][1] = now;

2. entry_idx logic bug — duplicates for out-of-order JSONL (cloud_monitor.zig)

In restoreStateFromEvents, when a later JSONL line has older timestamp, entry_idx stays null but code falls through to add a duplicate. Fix:

if (latest_issue[i] == issue) {
    entry_idx = i;  // ALWAYS set entry_idx when issue matches
    if (ts > latest_ts[i]) {
        latest_ts[i] = ts;  // only update timestamp if newer
    }
    break;
}

3. appendEvent buffer too small (cloud_monitor.zig)

512-byte buffer silently drops long events. Fix:

// BEFORE:
var buf: [512]u8 = undefined;
// AFTER:
var buf: [4096]u8 = undefined;

4. JSON output buffer (tri_cloud.zig)

Increase from 65536 to handle more events, or add proper truncation with valid JSON closing.

Instructions

  1. git checkout feat/issue-124 (branch already exists with PR feat(cloud): JSONL event persistence + deduplication + JSON history format (#124) #129)
  2. Apply fixes to tools/mcp/trinity_mcp/cloud_monitor.zig and src/tri/tri_cloud.zig
  3. zig fmt src/ tools/
  4. Commit: fix(cloud): timestamp overflow, entry_idx duplicates, buffer sizes (#129)
  5. Push to feat/issue-124
  6. PR feat(cloud): JSONL event persistence + deduplication + JSON history format (#124) #129 will auto-update

Do NOT create a new PR — push to the existing branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions