Skip to content

chore: sync core lib and CLAUDE.md from agent-core#29

Merged
avifenesh merged 1 commit into
mainfrom
chore/sync-core-sync-docs-20260426-131127
Apr 26, 2026
Merged

chore: sync core lib and CLAUDE.md from agent-core#29
avifenesh merged 1 commit into
mainfrom
chore/sync-core-sync-docs-20260426-131127

Conversation

@avifenesh
Copy link
Copy Markdown
Contributor

@avifenesh avifenesh commented Apr 26, 2026

Automated sync of lib/ and CLAUDE.md from agent-core.


Note

Medium Risk
Touches security-sensitive runtime binary download/extraction and changes tasks.json read/write semantics (now throws on corruption and adds optimistic locking), which could affect install reliability and workflow state under concurrency.

Overview
Hardens runtime installation of the agent-analyzer binary. Downloads are now SHA-256 verified via a required <asset>.sha256 sidecar (with an explicit skipChecksum escape hatch), and archives are extracted into an isolated scratch dir with path-traversal/absolute-path/UNC checks; only the expected binary is then copied into place (Windows zip extraction is replaced with a PowerShell -File helper that validates entries and is safe with spaces/brackets).

Adds coverage and new repo-intel/query API surface. Introduces lib/binary/index.test.js to validate checksum parsing, entry validation, scratch cleanup, and Windows script structure, and adds lib/repo-intel/queries.js as JSON-parsing wrappers around agent-analyzer repo-intel query ... with a dedicated RepoIntelMissingError.

Updates workflow tasks state format and concurrency behavior. tasks.json now uses a canonical schema ({ active, tasks, _version }), throws on corrupted JSON (instead of silently defaulting), and adds _writerId-stamped writes plus new updateTasks/claimTask/releaseTask helpers with optimistic retry.

Reviewed by Cursor Bugbot for commit 79ca49a. Configure here.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces security hardening for binary downloads, including SHA-256 checksum verification and strict archive entry validation to prevent path traversal. It also adds typed wrappers for repository intelligence queries and enhances task state management with optimistic locking to handle concurrent updates. Feedback suggests addressing potential filename escaping issues in query arguments and replacing a busy-wait loop with a non-blocking sleep mechanism to improve performance during update retries.

Comment thread lib/repo-intel/queries.js
if (!files.every(f => typeof f === 'string')) {
throw new TypeError('diffRisk: all entries in files must be strings');
}
const joined = files.join(',');
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.

medium

Joining filenames with a comma without escaping can lead to incorrect behavior if any filename contains a comma. If the agent-analyzer binary expects a comma-separated list, consider validating that the input filenames do not contain commas, or check if the binary supports an alternative way to pass file lists (e.g., via multiple flags or a file).

Comment on lines +221 to +223
const jitter = Math.floor(Math.random() * 20);
const start = Date.now();
while (Date.now() - start < jitter) { /* busy-wait for short jitter */ }
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.

medium

This busy-wait loop blocks the Node.js event loop, which can degrade performance and responsiveness, even for short durations. Since sleepForRetry is already imported and used elsewhere in this file (e.g., in updateFlow), it should be used here as well for a more efficient wait mechanism.

Suggested change
const jitter = Math.floor(Math.random() * 20);
const start = Date.now();
while (Date.now() - start < jitter) { /* busy-wait for short jitter */ }
const jitter = Math.floor(Math.random() * 20);
sleepForRetry(jitter);

@avifenesh avifenesh merged commit f8281a9 into main Apr 26, 2026
8 checks passed
@avifenesh avifenesh deleted the chore/sync-core-sync-docs-20260426-131127 branch April 26, 2026 13:16
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 4 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 79ca49a. Configure here.

// Another writer won — retry with jitter
const jitter = Math.floor(Math.random() * 20);
const start = Date.now();
while (Date.now() - start < jitter) { /* busy-wait for short jitter */ }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Busy-wait loop blocks event loop instead of using sleepForRetry

Low Severity

The updateTasks function uses a synchronous busy-wait loop for retry jitter, which blocks the event loop and consumes CPU for up to 20ms per retry. The sleepForRetry utility, which uses Atomics.wait for non-blocking sleep, is already imported and used by updateFlow in the same file.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 79ca49a. Configure here.

return updateTasks(tasks => {
tasks.tasks = tasks.tasks.filter(t => t.id !== taskId);
return tasks;
}, projectPath);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Concurrent task writes can silently lose claimed tasks

Medium Severity

setActiveTask and clearActiveTask perform a full read-modify-write of tasks.json without using the new updateTasks optimistic locking, while the newly introduced claimTask/releaseTask do use it. If setActiveTask reads the file, then claimTask writes a new entry to tasks[], then setActiveTask writes back its stale snapshot, the claimed task entry is silently lost. Since setActiveTask has no retry logic, this data loss is permanent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 79ca49a. Configure here.

} catch (e) {
console.error(`[CRITICAL] Corrupted tasks.json at ${tasksPath}: ${e.message}`);
return { active: null };
throw new Error(`Corrupted tasks.json at ${tasksPath}: ${e.message}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Throwing readTasks breaks clearActiveTask in workflow completions

Medium Severity

readTasks changed from catching JSON parse errors (returning a default) to throwing. setActiveTask, clearActiveTask, and hasActiveTask call readTasks without try-catch. In completeWorkflow and abortWorkflow, the flow is already updated via updateFlow before clearActiveTask is called — so a corrupted tasks.json now causes an unhandled throw after the flow state has been committed, leaving flow.json and tasks.json in an inconsistent state.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 79ca49a. Configure here.

return { active: null };
throw new Error(`Corrupted tasks.json at ${tasksPath}: ${e.message}`);
}
return normalizeTasksData(data);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

normalizeTasksData crashes on null from valid JSON parse

Low Severity

normalizeTasksData is called outside the try-catch in readTasks. If tasks.json contains the valid JSON literal null, JSON.parse succeeds and returns null, then Object.prototype.hasOwnProperty.call(null, 'active') throws an unhandled TypeError. The old code's broader try-catch caught this same crash and returned a safe default; the new narrower try-catch only covers JSON.parse, so the TypeError escapes with an unhelpful message.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 79ca49a. Configure here.

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.

1 participant