Skip to content

🚀 feat: Implement TE boost order with async EI data refresh#1914

Merged
mkmccarty merged 7 commits intomainfrom
mm-branch-1
Dec 9, 2025
Merged

🚀 feat: Implement TE boost order with async EI data refresh#1914
mkmccarty merged 7 commits intomainfrom
mm-branch-1

Conversation

@mkmccarty
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings December 9, 2025 01:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements Truth Egg (TE) count-based boost ordering with asynchronous refresh of user data from the Egg Inc API. The implementation extracts the TE count calculation logic into a separate function and adds logic to refresh TE data for users with zero TE count when the TE boost order is selected.

Key Changes:

  • Extracted TE count calculation logic into a new updateContractFarmerTE function with async API calls
  • Added automatic refresh of TE data when switching to TE boost order for users with TECount == 0
  • Replaced inline TE counting during farmer addition with a call to the new function

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/boost/boost.go Extracted TE count logic into updateContractFarmerTE function with async goroutine for API calls, and updated AddFarmerToContract to call the new function
src/boost/contract.go Added loop to refresh TE data for boosters with zero TE count when TE boost order is selected

Comment on lines 979 to 999
go func(eggIncID, userID string, b *Booster) {
backup, _ := ei.GetFirstContactFromAPI(s, eggIncID, userID, true)
virtue := backup.GetVirtue()

var allEov uint32

// virtueEggs := []string{"CURIOSITY", "INTEGRITY", "HUMILITY", "RESILIENCE", "KINDNESS"}
for i := range 5 {
eov := virtue.GetEovEarned()[i]
delivered := virtue.GetEggsDelivered()[i]

eovEarned := countTETiersPassed(delivered)
eovPending := pendingTruthEggs(delivered, eov)

allEov += max(eovEarned-eovPending, 0)
}

b.TECount = int(allEov)
refreshBoostListMessage(s, contract)

}(eggIncID, userID, b)
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The goroutine modifies the b.TECount field (line 996) and calls refreshBoostListMessage without any synchronization. This creates a race condition since:

  1. The Booster struct (b) is accessed concurrently by the goroutine and potentially by other code paths
  2. The contract struct is accessed without locking its mutex, even though the Contract type has a mutex sync.Mutex field for thread safety (line 325 in boost.go)
  3. The refreshBoostListMessage function accesses contract fields (Location, etc.) without synchronization

Consider using the contract's mutex to protect the write to b.TECount and the call to refreshBoostListMessage:

go func(eggIncID, userID string, b *Booster, contract *Contract) {
    backup, _ := ei.GetFirstContactFromAPI(s, eggIncID, userID, true)
    virtue := backup.GetVirtue()

    var allEov uint32
    for i := range 5 {
        eov := virtue.GetEovEarned()[i]
        delivered := virtue.GetEggsDelivered()[i]
        eovEarned := countTETiersPassed(delivered)
        eovPending := pendingTruthEggs(delivered, eov)
        allEov += max(eovEarned-eovPending, 0)
    }

    contract.mutex.Lock()
    b.TECount = int(allEov)
    contract.mutex.Unlock()
    
    refreshBoostListMessage(s, contract)
}(eggIncID, userID, b, contract)

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +986 to +994
for i := range 5 {
eov := virtue.GetEovEarned()[i]
delivered := virtue.GetEggsDelivered()[i]

eovEarned := countTETiersPassed(delivered)
eovPending := pendingTruthEggs(delivered, eov)

allEov += max(eovEarned-eovPending, 0)
}
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The code accesses array indices without bounds checking. If virtue.GetEovEarned() or virtue.GetEggsDelivered() returns a slice with fewer than 5 elements, this will cause an index out of bounds panic.

Add length validation:

eovEarned := virtue.GetEovEarned()
eggsDelivered := virtue.GetEggsDelivered()
if len(eovEarned) < 5 || len(eggsDelivered) < 5 {
    log.Printf("Insufficient virtue data for user %s", userID)
    return
}

for i := range 5 {
    eov := eovEarned[i]
    delivered := eggsDelivered[i]
    // ... rest of the loop
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI commented Dec 9, 2025

@mkmccarty I've opened a new pull request, #1915, to work on those changes. Once the pull request is ready, I'll request review from you.

mkmccarty and others added 5 commits December 8, 2025 17:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mkmccarty mkmccarty merged commit 011bd8e into main Dec 9, 2025
10 of 12 checks passed
@mkmccarty mkmccarty deleted the mm-branch-1 branch December 9, 2025 01:57
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.

2 participants