Skip to content

Conversation

@vtemian
Copy link
Owner

@vtemian vtemian commented Jan 1, 2026

Summary

  • Fix background_task system issues (memory leak, silent errors, missing types)
  • Integrate background_task into 3 agents for true async parallelism

Changes

Background Task System Fixes

  • Remove unused field: Removed progress.lastMessage (defined but never populated)
  • Add error logging: Replaced 4 silent .catch(() => {}) with proper console.error logging
  • Add task cleanup: TTL-based cleanup (1 hour) to prevent memory leak
  • Add response types: Proper TypeScript interfaces for session API responses
  • Add unit tests: 17 test cases covering all BackgroundTaskManager functionality

Agent Prompt Updates

Agent Pattern Benefit
project-initializer Fire-and-collect Run glob/read while 5 agents work in background
planner Fire-and-collect Run context7/btca_ask while 4 agents work
executor Fire-and-check Start reviewer immediately when its implementer finishes

Testing

  • All 40 tests passing
  • TypeScript compiles cleanly

Design Document

See thoughts/shared/designs/2026-01-01-background-task-integration-design.md (gitignored)


Summary by cubic

Integrated the background_task system into executor, planner, and project-initializer for real async parallelism, and fixed stability issues in the task manager. This speeds up execution and prevents memory leaks and silent failures.

  • New Features

    • Executor uses a fire-and-check pattern: fire implementers, poll, start reviewers immediately; includes fallback to Task.
    • Planner and project-initializer use fire-and-collect: fire background research, then collect results; includes fallback rules.
    • Added background tools usage in agent prompts: background_task, background_output, background_list.
  • Bug Fixes

    • Added 1h TTL cleanup to remove completed/error tasks and stop memory leak.
    • Replaced silent catch blocks with console.error logging.
    • Added TypeScript response types for session APIs; removed unused progress.lastMessage.
    • Added tests for manager behavior, error logging, cleanup, response typing, and agent prompt integration.

Written for commit 23f96a5. Summary will update on new commits.

… unit tests

- Add error logging to replace silent catch blocks (Task 2)
- Add TTL-based cleanup to prevent memory leak (Task 3)
- Add proper response types for API calls (Task 4)
- Add comprehensive unit tests for BackgroundTaskManager (Task 5)
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 13 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="tests/tools/background-task-error-logging.test.ts">

<violation number="1" location="tests/tools/background-task-error-logging.test.ts:16">
P2: Test doesn&#39;t verify what its name claims. The assertion only checks that catch blocks have a named parameter, not that `console.error` is actually called. A catch like `.catch((err) =&gt; {})` would pass this test despite not logging anything. Consider parsing the full catch block body and verifying it contains `console.error`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

const fs = await import("node:fs/promises");
const source = await fs.readFile("src/tools/background-task/manager.ts", "utf-8");

// All .catch blocks should have console.error
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 1, 2026

Choose a reason for hiding this comment

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

P2: Test doesn't verify what its name claims. The assertion only checks that catch blocks have a named parameter, not that console.error is actually called. A catch like .catch((err) => {}) would pass this test despite not logging anything. Consider parsing the full catch block body and verifying it contains console.error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/tools/background-task-error-logging.test.ts, line 16:

<comment>Test doesn&#39;t verify what its name claims. The assertion only checks that catch blocks have a named parameter, not that `console.error` is actually called. A catch like `.catch((err) =&gt; {})` would pass this test despite not logging anything. Consider parsing the full catch block body and verifying it contains `console.error`.</comment>

<file context>
@@ -0,0 +1,23 @@
+    const fs = await import(&quot;node:fs/promises&quot;);
+    const source = await fs.readFile(&quot;src/tools/background-task/manager.ts&quot;, &quot;utf-8&quot;);
+
+    // All .catch blocks should have console.error
+    const catchBlocks = source.match(/\.catch\s*\([^)]+\)/g) || [];
+    for (const block of catchBlocks) {
</file context>
Fix with Cubic

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