-
Notifications
You must be signed in to change notification settings - Fork 3
fix: add more logs #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds extensive debug logging to dispute processing, introduces a manual vote-counter fallback when contract calls fail, logs post-fetch diagnostics, handles already-executed disputes with explicit logs, and adds readiness logs for phase transitions. No public API changes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Scheduler
participant Bot as kleros-liquid bot
participant Kleros as KlerosContract
Scheduler->>Bot: run()
Note over Bot: "Processing dispute <id>"
Bot->>Kleros: getDispute(disputeID)
alt Dispute already executed
Bot->>Bot: log "Dispute <id> is already executed."
Bot-->>Scheduler: continue next
else Not executed
loop Resolve vote counters
Bot->>Kleros: getVoteCounter(disputeID, i)
alt Success
Bot->>Bot: log counter
else Failure
Bot->>Bot: log "Looking up vote counter manually..."
loop Iterate votes j
Bot->>Kleros: getVote(disputeID, j)
Bot->>Bot: log "Vote for dispute <id>, choice <i>, index <j>..."
end
end
end
Bot->>Bot: log "Vote counter has N entries"
Bot->>Bot: log coherence/tie status
Note over Bot: "Checking if reay to move phase"
alt Ready staking -> generating
Bot->>Bot: log readiness
else Ready generating -> drawing
Bot->>Bot: log readiness
else Ready drawing -> staking
Bot->>Bot: log readiness
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/bots/kleros-liquid.js (1)
19-21: Heartbeat stays disabled after one error; re-enable at next loop.
doHeartbeatis set to false on error and never reset, suppressing liveness pings forever after a transient failure.while (true) { console.log("Initializing klerosLiquid loop..."); + doHeartbeat = true; // reset for this iterationOptionally improve error visibility:
- } catch (e) { - console.error("Failed to process disputes: ", e); + } catch (e) { + console.error("Failed to process disputes: %s", (e && (e.stack || e.message)) || e); doHeartbeat = false; }Also applies to: 167-169, 210-217
🧹 Nitpick comments (5)
src/bots/kleros-liquid.js (5)
178-178: Typo in log message.Change “reay” → “ready”.
- console.log(`Checking if reay to move phase`); + console.log(`Checking if ready to move phase`);
173-191: Use strict equality by normalizing phase to a number.Avoid loose equality and implicit coercions for clarity and safety.
- const phase = await klerosLiquid.methods.phase().call(); + const phase = Number(await klerosLiquid.methods.phase().call()); - if (phase == PhaseEnum.staking) { + if (phase === PhaseEnum.staking) { ... - } else if (phase == PhaseEnum.generating) { + } else if (phase === PhaseEnum.generating) { ... - } else if (phase == PhaseEnum.drawing) { + } else if (phase === PhaseEnum.drawing) {
104-104: Add dispute ID to vote-counter size log for easier correlation.- console.debug(`Vote counter has ${voteCounters.length} entries`); + console.debug(`Vote counter for dispute ${disputeID} has ${voteCounters.length} entries`);
112-114: Log array content explicitly.Template-literal interpolation of arrays prints comma-joined values; use JSON for clarity.
- console.debug( - `No tie and no coherent votes for dispute ${disputeID}: ${notTieAndNoOneCoherent}` - ); + console.debug( + `No tie and no coherent votes for dispute ${disputeID}: ${JSON.stringify(notTieAndNoOneCoherent)}` + );
37-37: Consider reducing per-ID debug noise or gating via env.This will emit one line per dispute on every run; consider sampling or enabling only with VERBOSE=true.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/bots/kleros-liquid.js(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/bots/kleros-liquid.js (1)
src/xdai-bots/x-kleros-liquid.js (12)
disputeID(46-46)executedDisputeIDs(22-22)dispute(49-51)voteCounters(56-105)notTieAndNoOneCoherent(107-112)phase(170-170)PhaseEnum(19-19)minStakingTime(178-180)lastPhaseChange(171-173)disputesWithoutJurors(174-176)readyForNextPhase(169-169)maxDrawingTime(193-195)
🔇 Additional comments (1)
src/bots/kleros-liquid.js (1)
42-45: Good: surfaced read-dispute failure with context.Replacing the silent catch with a specific error log (including the dispute ID and message) is a solid operational improvement.
| console.debug( | ||
| `Looking up vote counter manually for dispute ${disputeID}, choice ${i}` | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix fallback path: missing .call() and shape mismatch cause runtime errors.
- getVote requires
.call(); without it, the await resolves to a method object, not data. - The manual
voteCounterlackscounts, but later logic indexesv.counts[winningChoice], leading toTypeError.
Apply:
- const vote = await klerosLiquid.methods.getVote(
- disputeID,
- i,
- j
- );
+ const vote = await klerosLiquid.methods
+ .getVote(disputeID, i, j)
+ .call();And return a compatible structure with counts (stringified), ensuring the winner exists:
- voteCounter = {
- tied,
- winningChoice,
- };
+ const counts = Object.fromEntries(
+ Object.entries(_voteCounters).map(([k, v]) => [String(k), String(v)])
+ );
+ if (counts[winningChoice] === undefined) counts[winningChoice] = "0";
+ voteCounter = { tied, winningChoice, counts };Also applies to: 69-73, 95-99, 106-111
🤖 Prompt for AI Agents
In src/bots/kleros-liquid.js around lines 61-63 (and similarly at 69-73, 95-99,
106-111), the fallback path for fetching vote counters is incorrect: it calls
the contract method without .call(), which returns a method object instead of
data, and it returns an object lacking a counts array so later indexing
v.counts[winningChoice] throws. Fix by invoking the contract getter with .call()
and by returning a structure matching the expected shape: an object with counts
as an array of strings (stringify numeric values) and a winner index validated
to exist (if winner not present, set to a safe default or throw/handle
accordingly); ensure the returned counts length matches numberOfChoices to avoid
out-of-bounds indexing.
Parsa-Darbouy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Summary by CodeRabbit
Bug Fixes
Chores