Repository navigation
fix(agentkit): preserve late runtime prompts - #96
Conversation
Rebuild prompt context when runtime messages arrive after build_context but before model streaming, and avoid consuming prompt-affecting messages after run_model until the next turn.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe pipeline's runtime-message handling is extended to detect prompt-relevant message kinds ( ChangesRuntime Message Prompt-Change Detection and Context Rebuild Flow
Sequence DiagramsequenceDiagram
participant RunTurn as run_turn Stage Loop
participant Consume as _consume_runtime_messages
participant RaiseInterrupt as _raise_if_runtime_interrupted
participant BuildCtx as _stage_build_context
participant RunModel as _stage_run_model
participant RuntimeBus as Runtime Bus
RunTurn->>RaiseInterrupt: (for save_state/render/dispatch)
RaiseInterrupt->>RuntimeBus: Check for INTERRUPT
alt INTERRUPT found
RaiseInterrupt--xRunTurn: Raise PipelineError
end
RunTurn->>Consume: (for other stages like run_model)
Consume->>RuntimeBus: Consume messages
alt Prompt-relevant message found
Consume-->>RunTurn: return True
RunTurn->>BuildCtx: Rebuild context before run_model
BuildCtx->>RuntimeBus: Consume messages during build
BuildCtx-->>RunTurn: Context ready
else No prompt-relevant messages
Consume-->>RunTurn: return False
end
RunTurn->>RunModel: Execute run_model stage
RunModel->>Consume: (before tool iterations)
Consume->>RuntimeBus: Consume messages
alt Prompt-relevant message found
Consume-->>RunModel: return True
RunModel->>BuildCtx: Rebuild context
end
RunModel->>RuntimeBus: Execute tools
RunModel->>Consume: (after tool execution)
Consume->>RuntimeBus: Consume messages
alt Prompt-relevant message found
Consume-->>RunModel: return True
RunModel->>BuildCtx: Rebuild context before next iteration
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 44 minutes and 26 seconds.Comment |
Lock in that prompt-affecting runtime messages published during active model streaming stay queued until the next turn instead of being consumed by post-model stages.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@coding-agent/src/agentkit/runtime/pipeline.py`:
- Around line 713-714: The pre-execution consume call currently advances
ctx.runtime_message_cursor and triggers a prompt rebuild unconditionally, which
can lose non-interrupt runtime messages if subsequent tool execution or rebuild
fails; change the condition so _stage_build_context(ctx) is invoked only when
the consumed messages include interrupts—e.g., update the call to await
self._consume_runtime_messages(ctx, stage="run_model", interrupt_only=True) (or
otherwise inspect the returned value to detect interrupt-type messages) and only
call await self._stage_build_context(ctx) when those interrupt messages are
present, leaving non-interrupt messages unconsumed so they can be replayed next
turn.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 82a79dd9-b1db-420d-ad3f-05e5f9be3559
📒 Files selected for processing (2)
coding-agent/src/agentkit/runtime/pipeline.pycoding-agent/tests/agentkit/runtime/test_pipeline.py
Leave prompt-affecting runtime messages queued when a tool-call turn has not yet reached the next model invocation, so failed tool execution or rebuild paths can replay them on the next turn.
Summary
build_contextbut before model streaming.run_modelfor the next turn instead of consuming them during post-model stages.Verification
uv run pytest tests/agentkit/runtime/test_runtime_messages.py tests/agentkit/runtime/test_pipeline.py -quv run pytest tests/coding_agent/test_approval_runtime_messages.py tests/ui/test_session_manager_approval_runtime.py -quv run basedpyright src/agentkit/runtime/pipeline.py tests/agentkit/runtime/test_pipeline.py --level erroruv run python -m py_compile src/agentkit/runtime/pipeline.py tests/agentkit/runtime/test_pipeline.pyGIT_MASTER=1 git diff --checkuser_steerpublished afterbuild_contextappears in the streamed prompt.Summary by CodeRabbit
New Features
Tests