Skip to content

fix(execution): null guard em getLastCheckpoint/getCheckpoint (#513)#523

Open
nikolasdehor wants to merge 2 commits intoSynkraAI:mainfrom
nikolasdehor:fix/build-state-manager-checkpoint-guard
Open

fix(execution): null guard em getLastCheckpoint/getCheckpoint (#513)#523
nikolasdehor wants to merge 2 commits intoSynkraAI:mainfrom
nikolasdehor:fix/build-state-manager-checkpoint-guard

Conversation

@nikolasdehor
Copy link
Contributor

@nikolasdehor nikolasdehor commented Feb 26, 2026

Problema

Em build-state-manager.js:400, getLastCheckpoint() acessa this._state.checkpoints.length diretamente. Se this._state existe mas checkpoints é undefined (state carregado de JSON incompleto), ocorre TypeError: Cannot read property 'length' of undefined.

Mesmo bug em getCheckpoint() (linha 416): acessa .checkpoints.find() sem guard.

Correção

 getLastCheckpoint() {
-  if (!this._state || this._state.checkpoints.length === 0) {
+  if (!this._state || !this._state.checkpoints || this._state.checkpoints.length === 0) {
     return null;
   }

 getCheckpoint(checkpointId) {
-  if (!this._state) {
+  if (!this._state || !this._state.checkpoints) {
     return null;
   }

Validação

  • 49 testes do build-state-manager passando
  • Zero regressões

Closes #513

Summary by CodeRabbit

  • Bug Fixes

    • Improved checkpoint handling to prevent errors when checkpoints are missing or unavailable, increasing system reliability.
  • Chores

    • Updated release manifest metadata and recalculated file entries to reflect recent content updates.

getLastCheckpoint() acessava this._state.checkpoints.length sem
verificar se checkpoints existe. State carregado de JSON incompleto
(sem a propriedade checkpoints) causa TypeError em runtime.

Adiciona guard !this._state.checkpoints em ambos os métodos.

Closes SynkraAI#513
Copilot AI review requested due to automatic review settings February 26, 2026 12:57
@vercel
Copy link

vercel bot commented Feb 26, 2026

@nikolasdehor is attempting to deploy a commit to the Pedro Valério Lopez's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc2be9 and 52824bf.

📒 Files selected for processing (1)
  • .aios-core/install-manifest.yaml
✅ Files skipped from review due to trivial changes (1)
  • .aios-core/install-manifest.yaml

Walkthrough

Added defensive null/undefined checks in getLastCheckpoint() and getCheckpoint() of build-state-manager.js so they return null when _state.checkpoints is missing or empty; updated install manifest metadata and file hashes/sizes.

Changes

Cohort / File(s) Summary
Build state guards
.aios-core/core/execution/build-state-manager.js
Added checks for !this._state.checkpoints in getLastCheckpoint() and getCheckpoint() so both return null when checkpoints is absent or empty, preventing TypeError on partially initialized state.
Manifest update
.aios-core/install-manifest.yaml
Bumped version/timestamp and refreshed SHA256 hashes and file sizes across many entries (recomputed manifest metadata); no API or behavioral code changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding null guards to getLastCheckpoint and getCheckpoint methods in the build-state-manager to handle missing checkpoints.
Linked Issues check ✅ Passed The code changes directly address the requirements in issue #513 by adding null checks for this._state.checkpoints in both getLastCheckpoint and getCheckpoint methods.
Out of Scope Changes check ✅ Passed The changes are limited to adding null guards in two methods within build-state-manager.js; the manifest update is expected as a result of these code modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

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 pull request addresses a defensive programming issue in the BuildStateManager where accessing this._state.checkpoints without first verifying it exists could cause a TypeError. The fix adds null guards to getLastCheckpoint() and getCheckpoint() methods to prevent crashes when the state's checkpoints property is undefined.

Changes:

  • Added null guard for this._state.checkpoints in getLastCheckpoint() method
  • Added null guard for this._state.checkpoints in getCheckpoint() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.aios-core/core/execution/build-state-manager.js (1)

365-366: Consider adding a similar null guard here for consistency.

While saveCheckpoint already validates !this._state, the same corrupted-state scenario (state exists but checkpoints is undefined) could cause a TypeError at line 366. For defense-in-depth, consider initializing checkpoints if missing:

🛡️ Optional defensive initialization
     // Add to state
+    if (!this._state.checkpoints) {
+      this._state.checkpoints = [];
+    }
     this._state.checkpoints.push(checkpoint);

Alternatively, throw a more descriptive error if state integrity is compromised. This is optional and can be addressed separately if needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.aios-core/core/execution/build-state-manager.js around lines 365 - 366, The
push to this._state.checkpoints can throw if this._state exists but checkpoints
is undefined; in the saveCheckpoint method (or wherever
this._state.checkpoints.push(checkpoint) is called) add a defensive guard that
ensures this._state.checkpoints is an array before pushing (e.g. if
(!Array.isArray(this._state.checkpoints)) this._state.checkpoints = [];), or
alternatively throw a clear error indicating corrupted state; update the code
around the this._state.checkpoints.push(checkpoint) call to perform that
check/initialization to avoid a TypeError.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.aios-core/core/execution/build-state-manager.js:
- Around line 365-366: The push to this._state.checkpoints can throw if
this._state exists but checkpoints is undefined; in the saveCheckpoint method
(or wherever this._state.checkpoints.push(checkpoint) is called) add a defensive
guard that ensures this._state.checkpoints is an array before pushing (e.g. if
(!Array.isArray(this._state.checkpoints)) this._state.checkpoints = [];), or
alternatively throw a clear error indicating corrupted state; update the code
around the this._state.checkpoints.push(checkpoint) call to perform that
check/initialization to avoid a TypeError.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63db79b and 2bc2be9.

📒 Files selected for processing (1)
  • .aios-core/core/execution/build-state-manager.js

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 26, 2026
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.

bug: build-state-manager getLastCheckpoint falha se checkpoints é undefined

2 participants