Accumulate sequentially when ecalli=trace is enabled#948
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThree files are modified to support trace logging integration with accumulation logic. A new static helper method Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/jam/transition/accumulate/accumulate.ts (1)
89-99: Move option resolution/logging out of the constructor.Line 91–Line 99 introduces branching and logging in a non-private constructor. Please shift this logic into a
staticbuilder/factory and keep the constructor assignment-only.Proposed refactor sketch
export class Accumulate { public readonly options: AccumulateOptions; - constructor( + private constructor( public readonly chainSpec: ChainSpec, public readonly blake2b: Blake2b, public readonly state: AccumulateState, - options: AccumulateOptions, + options: AccumulateOptions, ) { - const ecalliTraceEnabled = EcalliTraceLogger.isTraceEnabled(); - const accumulateSequentially = options.accumulateSequentially === true || ecalliTraceEnabled; - this.options = { ...options, accumulateSequentially }; - - if (ecalliTraceEnabled && options.accumulateSequentially !== true) { - logger.warn`⚠️ ecalli trace logging is enabled: forcing sequential accumulation to keep the trace output ordered.`; - } else if (accumulateSequentially) { - logger.warn`⚠️ Parallel accumulation is disabled. Running in sequential mode.`; - } + this.options = options; } + + static create( + chainSpec: ChainSpec, + blake2b: Blake2b, + state: AccumulateState, + options: AccumulateOptions, + ): Accumulate { + const ecalliTraceEnabled = EcalliTraceLogger.isTraceEnabled(); + const accumulateSequentially = options.accumulateSequentially === true || ecalliTraceEnabled; + const resolvedOptions = { ...options, accumulateSequentially }; + + if (ecalliTraceEnabled && options.accumulateSequentially !== true) { + logger.warn`⚠️ ecalli trace logging is enabled: forcing sequential accumulation to keep the trace output ordered.`; + } else if (accumulateSequentially) { + logger.warn`⚠️ Parallel accumulation is disabled. Running in sequential mode.`; + } + + return new Accumulate(chainSpec, blake2b, state, resolvedOptions); + } }As per coding guidelines, "For constructors, avoid logic inside non-private constructors: constructors should just assign fields (logic goes into
staticbuilder methods), and avoid constructor overloading."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/jam/transition/accumulate/accumulate.ts` around lines 89 - 99, The constructor currently computes accumulateSequentially, mutates this.options and emits logs (using EcalliTraceLogger and logger) — move that branching and logging out of the non-private constructor into a new static factory method (e.g., Accumulate.create or Accumulate.fromOptions) that accepts AccumulateOptions, computes ecalliTraceEnabled and accumulateSequentially, logs the appropriate warnings, and then calls a private constructor that only assigns fields (this.options = ...). Ensure references to EcalliTraceLogger, options.accumulateSequentially, and logger.warn are moved to the static method and the public constructor becomes assignment-only.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/jam/transition/accumulate/accumulate.ts`:
- Around line 89-99: The constructor currently computes accumulateSequentially,
mutates this.options and emits logs (using EcalliTraceLogger and logger) — move
that branching and logging out of the non-private constructor into a new static
factory method (e.g., Accumulate.create or Accumulate.fromOptions) that accepts
AccumulateOptions, computes ecalliTraceEnabled and accumulateSequentially, logs
the appropriate warnings, and then calls a private constructor that only assigns
fields (this.options = ...). Ensure references to EcalliTraceLogger,
options.accumulateSequentially, and logger.warn are moved to the static method
and the public constructor becomes assignment-only.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b540417e-7511-42b8-9874-4f2ec960f801
📒 Files selected for processing (3)
packages/core/pvm-host-calls/ecalli-trace-logger.tspackages/jam/executor/index.tspackages/jam/transition/accumulate/accumulate.ts
View all
Benchmarks summary: 83/83 OK ✅ |
No description provided.