Skip to content

irckit: add reactive anti-idle recovery and scope touchActivity to new posts - #1192

Merged
hloeung merged 3 commits into
42wim:masterfrom
hloeung:anti-idle
Dec 2, 2026
Merged

hloeung merged 3 commits into
42wim:masterfrom
hloeung:anti-idle

Conversation

@hloeung

@hloeung hloeung commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Reactive anti-idle recovery on remote away: When SyncAwayStatus = false on an ActivityRefresher bridge (such as Mattermost) and the user is not locally /AWAY on IRC, an incoming status_change: away event now wakes runAntiIdle immediately (bounded by a 30s minAntiIdleInterval cooldown, bypassing lastActivity deferral) to call RefreshActivity.
    • Recovers from automatic server away or Mattermost HA multi-pod Hub.unregister activity rewinds within milliseconds instead of waiting up to AntiIdleInterval.
    • Still preserves explicit manual away, dnd, and offline statuses because RefreshActivity sends manual=false.
  • Tighter touchActivity() scoping: Moved u.touchActivity() out of the blanket PRIVMSG hook in mm-go-irckit/commands.go (removing isLocalPrivMsg) and placed it directly on successful post-creation paths in mm-go-irckit/server_commands.go (CmdPrivMsg channel/DM sends, threadMsgChannelUser, and quoteMsgChannelUser). Reactions, edits/deletes, local service/virtual-channel messages, and failed sends no longer defer anti-idle heartbeats.

Changes

  • mm-go-irckit/antiidle.go: Added wakeAntiIdle(), force parameter to antiIdleStep, and reactive wake handling with minAntiIdleInterval cooldown in runAntiIdle.
  • mm-go-irckit/userbridge.go: Added antiIdleWake channel and lastReactiveWake on UserBridge; extracted handleSelfStatusNoSync from handleSelfStatusChangeEvent to trigger wakeAntiIdle() when appropriate.
  • mm-go-irckit/commands.go: Removed blanket PRIVMSG touchActivity() and isLocalPrivMsg.
  • mm-go-irckit/server_commands.go: Called u.touchActivity() after successful post creation in CmdPrivMsg, threadMsgChannelUser, and quoteMsgChannelUser.
  • mm-go-irckit/antiidle_test.go: Added TestRunAntiIdleReactiveWakeOnRemoteAway, TestPrivMsgLocalAndNonPostDoNotTouchActivity, and TestPrivMsgPostCreationTouchesActivity.

Testing

  • go test -count=1 -race ./...
  • golangci-lint run
  • go build ./...

…w posts

- Wake runAntiIdle immediately when an ActivityRefresher bridge receives
  a remote status_change to "away" while SyncAwayStatus is disabled and
  the IRC user is not locally /AWAY, bypassing lastActivity deferral with
  a minAntiIdleInterval (30s) cooldown. Because RefreshActivity uses
  manual=false, automatic server away and Mattermost HA WebSocket
  unregister rewinds recover to online immediately while manual away,
  DND, and offline statuses remain preserved.
- Move u.touchActivity() out of commands.Run (removing isLocalPrivMsg)
  and invoke it only on successful post creation in CmdPrivMsg (channel
  and DM sends), threadMsgChannelUser, and quoteMsgChannelUser so
  reactions, message edits/deletes, local service/virtual-channel
  messages, and failed sends no longer defer anti-idle heartbeats.
- Add TestRunAntiIdleReactiveWakeOnRemoteAway and replace
  TestLocalPrivMsgDoesNotTouchActivity with
  TestPrivMsgLocalAndNonPostDoNotTouchActivity and
  TestPrivMsgPostCreationTouchesActivity in mm-go-irckit/antiidle_test.go.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cooldown handling discards remote-away transitions instead of deferring recovery, and the threaded-post test uses an unsupported ID that bypasses the intended code path.

2 open issues
What changed in this PR

Adds reactive anti-idle recovery to the IRC bridge and limits activity tracking to successful post creation.

Changes:

  • Wakes anti-idle on eligible remote-away events, with a 30-second cooldown.
  • Stops reactions, edits, local messages, and failed sends from deferring heartbeats.
  • Adds tests for reactive recovery and post-specific activity tracking.
File Description
mm-go-irckit/​userbridge.go Adds wake state and remote-away handling.
mm-go-irckit/​server_commands.go Records activity after successful post creation.
mm-go-irckit/​commands.go Removes blanket PRIVMSG activity tracking.
mm-go-irckit/​antiidle.go Adds forced refreshes and reactive cooldown handling.
mm-go-irckit/​antiidle_test.go Tests reactive wakes and activity tracking.

Review effort: Balanced

Comment thread mm-go-irckit/antiidle.go Resolved
Comment thread mm-go-irckit/antiidle_test.go Resolved
…x thread test

- Defer remote-away reactive refreshes that arrive during the 30s
  cooldown instead of discarding them by tracking pendingWake and
  lastWake in antiIdleLoop (removing UserBridge.lastReactiveWake),
  so a follow-up away transition executes once the remaining cooldown
  expires while still bypassing lastActivity deferral and rechecking
  away/status guards.
- Log successful reactive anti-idle recoveries at DEBUG level and emit
  an IRC server NOTICE via sendServerNotice when SyncAwayStatus=false
  and a remote away status is corrected while not locally /AWAY.
- Use a valid 26-character thread ID in
  TestPrivMsgPostCreationTouchesActivity and assert MsgChannelThread is
  invoked, and extend TestRunAntiIdleReactiveWakeOnRemoteAway to cover
  deferred cooldown execution and the server NOTICE.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The cooldown test can fail despite correct behavior because waiting for the NOTICE consumes part of the cooldown, allowing a valid deferred refresh during the failure window.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread mm-go-irckit/antiidle_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the newly added quote-post activity path lacks regression coverage, leaving its behavior insufficiently verified.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@hloeung
hloeung merged commit 6872e57 into 42wim:master Dec 2, 2026
4 checks passed
@hloeung
hloeung deleted the anti-idle branch December 2, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants