Skip to content

fix(dreamer): forward task fallbackModels & timeout, increase subagent maxSteps and verify batch size - #783

Open
izhangzhihao wants to merge 2 commits into
cortexkit:masterfrom
izhangzhihao:fix/dreamer-pi-runtime-limits
Open

izhangzhihao wants to merge 2 commits into
cortexkit:masterfrom
izhangzhihao:fix/dreamer-pi-runtime-limits

Conversation

@izhangzhihao

@izhangzhihao izhangzhihao commented Oct 26, 2026 •

Copy link
Copy Markdown

Approved issue: #784

Harness coverage (required)

For each entry select: covered / not applicable — surface does not exist there / NOT covered.

  • OpenCode 1: covered — shared Dreamer plugin logic has unit coverage
  • OpenCode 2: covered — shared Dreamer plugin logic has unit coverage
  • Pi: covered — Pi Dreamer and subagent runner tests.
  • OMP: covered — OMP runner unit cases
  • Rust module: not applicable — no Rust Dreamer task runtime/config surface.

Summary

  • Forward task-level fallbackModels and timeoutMinutes to the Pi subagent runner, honoring configured fallbacks and timeouts.
  • Increase dreamer-docs and dreamer-memory-mapper maxSteps from 60 to 400.
  • Increase memory verification VERIFY_BATCH_SIZE from 5 to 10.

Testing

  • Verified configured fallbackModels and timeoutMinutes are passed through to the runner.
  • Pi subagent runner tests: 165 passed; Plugin agent/verify tests: 50 passed; Pi Dreamer/telemetry tests: 64 passed.
  • Both package typechecks, targeted Biome checks, and git diff --check passed.

fix #784

RetriggerView in GreptileConfidence Score: 4/5

Update the stale fallback assertion before merging so the Pi Dreamer tests pass.

Findings

  1. P1 Fallback test now fails ▶

Summary

The PR forwards task timeouts to Pi, raises the documentation and memory-mapper step limits to 400, and increases verification batches to ten memories.

  • Pi Dreamer runs use each task’s configured time limit.
  • Two read-only Dreamer agents can take up to 400 steps.
  • Memory verification checks up to ten memories per batch.
  • The unavailable-provider test fixture uses a clearer name.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Task model and fallbacks] --> B[Shared retry loop]
    B --> C[Pi runner: one model per attempt]
    C --> D[Return result and token spend]
    D --> B
Loading

Reviews (2) · Last reviewed commit: "Update packages/pi-plugin/src/dreamer/in..." · Reviewed by Greptile

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 08:50
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Waiting for design-approved on #784.

This PR needs a linked issue with the design-approved label before it can be reviewed or merged. Link the approved issue with Approved issue: #<issue> (or Refs #<issue>) in the description. A maintainer will apply the design-approved label on the issue, or trivial on the pull request when there is genuinely no design to agree. The issue stays open until the change ships; maintainers take care of it then.

@magic-alfonso

magic-alfonso Bot commented Oct 26, 2026

Copy link
Copy Markdown

Thanks for the PR. We're in a focused stretch on other work right now, so this is queued and we'll review it properly when that lifts.

To help us review, could you share what you ran into? This PR changes three separate things:

  • Forwarding fallbackModels and timeoutMinutes to the Pi runner. If Pi dreamer tasks ignore their configured fallback or timeout, that's a bug, and a log excerpt showing it would help.
  • The maxSteps cap (60 to 400) on the docs and memory-mapper agents. That cap is a deliberate cost bound. Which task hit it, on which model, and did the run fail or just stop early?
  • The verify batch size (5 to 10). We tuned that against measured verify timeouts. What did you see with 5?

Knowing which of these fixes a failure you saw, and which is tuning, will let us take the parts that fit quickly.

Comment thread packages/pi-plugin/src/dreamer/index.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

1 issue found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/plugin/src/agents/hidden-agent-registrations.ts">

<violation number="1" location="packages/plugin/src/agents/hidden-agent-registrations.ts:131">
P1: This raises `dreamer-docs` to 400 steps, but OpenCode 2 still stops it at 60. `AGENT_STEPS` in `v2/hooks/hidden-child.ts` keeps `DREAMER_DOCS_AGENT` and `DREAMER_MEMORY_MAPPER_AGENT` at 60, and the step guard throws once `steps > cap`. Update those entries to 400 too, or the new cap has no effect on that harness.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

maxSteps: 60,
// Documentation investigations can span many files in larger repositories.
// Keep the read-only proposal loop bounded while allowing it to finish.
maxSteps: 400,

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.

P1: This raises dreamer-docs to 400 steps, but OpenCode 2 still stops it at 60. AGENT_STEPS in v2/hooks/hidden-child.ts keeps DREAMER_DOCS_AGENT and DREAMER_MEMORY_MAPPER_AGENT at 60, and the step guard throws once steps > cap. Update those entries to 400 too, or the new cap has no effect on that harness.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/plugin/src/agents/hidden-agent-registrations.ts, line 131:

<comment>This raises `dreamer-docs` to 400 steps, but OpenCode 2 still stops it at 60. `AGENT_STEPS` in `v2/hooks/hidden-child.ts` keeps `DREAMER_DOCS_AGENT` and `DREAMER_MEMORY_MAPPER_AGENT` at 60, and the step guard throws once `steps > cap`. Update those entries to 400 too, or the new cap has no effect on that harness.</comment>

<file context>
@@ -126,9 +126,9 @@ export function buildHiddenAgentRegistrations(args: {
-            maxSteps: 60,
+            // Documentation investigations can span many files in larger repositories.
+            // Keep the read-only proposal loop bounded while allowing it to finish.
+            maxSteps: 400,
             overrides: args.dreamerOverrides,
             // Lock so a user override can't add the memory surface back.
</file context>

Comment thread packages/pi-plugin/src/dreamer/index.ts Outdated
@izhangzhihao

izhangzhihao commented Oct 26, 2026 •

Copy link
Copy Markdown
Author

Thanks for the PR. We're in a focused stretch on other work right now, so this is queued and we'll review it properly when that lifts.

To help us review, could you share what you ran into? This PR changes three separate things:

  • Forwarding fallbackModels and timeoutMinutes to the Pi runner. If Pi dreamer tasks ignore their configured fallback or timeout, that's a bug, and a log excerpt showing it would help.
  • The maxSteps cap (60 to 400) on the docs and memory-mapper agents. That cap is a deliberate cost bound. Which task hit it, on which model, and did the run fail or just stop early?
  • The verify batch size (5 to 10). We tuned that against measured verify timeouts. What did you see with 5?

Knowing which of these fixes a failure you saw, and which is tuning, will let us take the parts that fit quickly.

Here is the context and evidence behind each change: ---

1. `fallbackModels` & `timeoutMinutes` forwarding (Bug Fix — high priority) We configured `timeout_minutes: 120` and fallback models (e.g., `gemini-3.8-flash-high` falling back to `claude-opus-4-6-thinking`) under `dreamer.pi.tasks.*`. However: 1. **Timeout ignored:** Tasks doing broad sweeps (`verify-broad`, `map-memories`) were consistently killed at exactly 30 minutes, logging:

pi subagent timed out after 1800000ms — saw 112 events ... (model was emitting events but no terminal stopReason reached)

The configured `120` minutes was ignored because `runner.run({ timeoutMs: 30 * 60 * 1000 })` hardcoded 30 minutes.
2. **Fallback ignored:** When the primary endpoint hit temporary connection errors or rate limits:

pi assistant produced empty text (provider error: Connection error.)

The fallback model was never invoked because `runner.run({ fallbackModels: undefined })` discarded `taskConfig.fallbackModels`.

This is a clear regression/omission in `createPiDreamerClient` where resolved `taskConfig` wasn't passed down.

---

### 2. `maxSteps` (60 to 400 on `dreamer-docs` and `dreamer-memory-mapper`) (Tuning / Cost Bound)
- **What happened:** In larger codebases with multiple modules, `dreamer-memory-mapper` and `dreamer-docs` (using Gemini / Claude) regularly exhausted the 60 steps while chaining `read`, `grep`, `glob`, and `aft_*` calls across directories.
- **Outcome:** The run stopped early before compiling all facts into markdown/memories, resulting in truncated context updates.
- **Feedback:** We completely understand keeping 60 as a deliberate cost bound / loop guard. Would you prefer leaving 60 as the default and instead exposing `max_steps` under `tasks.*` in the configuration schema, or dropping this from this PR?

---

### 3. `VERIFY_BATCH_SIZE` (5 to 10) (Tuning)
- **What happened:** With large memory pools, batch size 5 resulted in numerous sequential rounds. Each round pays the fixed system prompt / preface token overhead and network latency, significantly lengthening total verification duration.
- **Feedback:** If 5 was specifically calibrated against slower providers to prevent single-batch timeouts, we are happy to drop this change or make it configurable.

---

### Recommendation

If you prefer, I can update this PR right now to **only include item 1 (forwarding `fallbackModels` and `timeoutMinutes`)**, keeping it a strictly non-controversial bug fix, and we can discuss items 2 & 3 in a separate issue/feature discussion. Let me know what works best for you!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Nested fallback retries undermine budget accounting, and existing verification and OpenCode finalization tests remain incompatible with the new limits.

3 open issues
What changed in this PR

This PR updates Dreamer task configuration forwarding in Pi and increases investigation limits and verification batch sizes.

Changes:

  • Forward task-level fallback models and timeouts to the Pi subagent runner.
  • Raise documentation and memory-mapper step limits from 60 to 400.
  • Increase verification batches from 5 to 10 memories and update related tests.
File Description
packages/​plugin/​src/​features/​magic-context/​dreamer/​verify.ts Increase verification batch size and revise timing comments.
packages/​plugin/​src/​features/​magic-context/​dreamer/​verify-batches.test.ts Update batch, budget, progress, and replay expectations.
packages/​plugin/​src/​agents/​hidden-agent-registrations.ts Raise documentation and mapper step limits.
packages/​plugin/​src/​agent-registration-drift.test.ts Assert the new step limits.
packages/​pi-plugin/​src/​subagent-runner.ts Update a comment to describe the configured step cap.
packages/​pi-plugin/​src/​subagent-runner.test.ts Update mapper finalization expectations and provider fixture names.
packages/​pi-plugin/​src/​dreamer/​index.ts Forward task fallback models and configured timeouts.
packages/​pi-plugin/​src/​dreamer/​index.test.ts Assert forwarded fallback and timeout options.
packages/​e2e-tests/​tests/​dreamer-mapper-step-cap-pi.test.ts Exercise 70 reads below the increased mapper limit.

Review effort: Balanced

Comment thread packages/pi-plugin/src/dreamer/index.ts Outdated
// give the subprocess a generous ceiling so the signal is the
// authority (not a second, conflicting wall-clock here).
timeoutMs: 30 * 60 * 1000,
fallbackModels: taskConfig?.fallbackModels,
maxSteps: 60,
// A map/verify batch can require many file lookups across larger repositories.
// Keep the investigation bounded while allowing complex batches to finish.
maxSteps: 400,
*/

export const VERIFY_BATCH_SIZE = 5;
export const VERIFY_BATCH_SIZE = 10;
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

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

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.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/pi-plugin/src/dreamer/index.ts">

<violation number="1" location="packages/pi-plugin/src/dreamer/index.ts:623">
P2: This change leaves the existing Dreamer forwarding test expecting the old nested fallback array, so the focused Pi Dreamer test now fails on both runner calls. Update that test to assert that the outer retry owns the fallback chain and the runner receives no nested fallbacks, while retaining its failure-path coverage.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@@ -628,10 +621,7 @@ function createPiDreamerClient(
userMessage,
model: perTaskModel,
fallbackModels: undefined,

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.

P2: This change leaves the existing Dreamer forwarding test expecting the old nested fallback array, so the focused Pi Dreamer test now fails on both runner calls. Update that test to assert that the outer retry owns the fallback chain and the runner receives no nested fallbacks, while retaining its failure-path coverage.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/pi-plugin/src/dreamer/index.ts, line 623:

<comment>This change leaves the existing Dreamer forwarding test expecting the old nested fallback array, so the focused Pi Dreamer test now fails on both runner calls. Update that test to assert that the outer retry owns the fallback chain and the runner receives no nested fallbacks, while retaining its failure-path coverage.</comment>

<file context>
@@ -620,7 +620,7 @@ function createPiDreamerClient(
 				userMessage,
 				model: perTaskModel,
-				fallbackModels: taskConfig?.fallbackModels,
+				fallbackModels: undefined,
 				timeoutMs: (taskConfig?.timeoutMinutes ?? 30) * 60 * 1000,
 				cwd: dreamSession.directory,
</file context>

@@ -628,10 +621,7 @@ function createPiDreamerClient(
userMessage,
model: perTaskModel,
fallbackModels: undefined,

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.

P1 Fallback test now fails

Setting fallbackModels to undefined fixes the nested retries, but shared curate validation retries Pi pseudo-tool-call text with the fallback model still expects the runner to receive a fallback array. That assertion at index.test.ts:1237 now fails.

Update it to expect undefined. Keep the model-order checks to verify that the shared executor still tries the fallback.

This branch has not been deployed

No deployments
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.

Pi Dreamer ignores configured fallback_models and timeout_minutes

2 participants