fix(runtime-core): report failed agent-added code blocks via onBlockDone#369
Conversation
Track success on blockOutputs entries and push on kernel.execute rejection so blocks the agent inserted always get an onBlockDone event matching their actual outcome. Wrap the agent call in try/finally so added blocks are drained even when executeAgentBlock throws. Also tighten add_code_block tool description and drop the redundant post-loop collectedOutputs.set / unknown[] casts. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes enhance error tracking for agent-inserted code blocks. The execution engine now records success/failure status per added block, generates error outputs on kernel failures, and moves callback reporting into a finally block to fire completion handlers even when agents fail mid-execution. A tool description was clarified to reflect the revised output contract. Sequence DiagramsequenceDiagram
participant Agent
participant ExecutionEngine
participant Kernel
Agent->>ExecutionEngine: Add code block
ExecutionEngine->>Kernel: Execute block
alt Execution succeeds
Kernel-->>ExecutionEngine: outputs + success
ExecutionEngine->>ExecutionEngine: Record success: true
else Kernel error/rejection
Kernel-->>ExecutionEngine: error/exception
ExecutionEngine->>ExecutionEngine: Generate error output<br/>Record success: false
end
ExecutionEngine->>ExecutionEngine: Finally block:<br/>Fire onOutput, onBlockDone
ExecutionEngine-->>Agent: Block complete<br/>(success reflects actual status)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## tk/agent-vscode-abstract #369 +/- ##
=========================================================
Coverage 82.80% 82.80%
=========================================================
Files 144 144
Lines 5867 5869 +2
Branches 1141 1141
=========================================================
+ Hits 4858 4860 +2
Misses 1009 1009 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Chained on top of #342. Quick fixes from the review of that PR.
What this changes
When the agent inserts a code block via
addAndExecuteCodeBlock, the runtime tracks the outcome of that kernel execution and surfaces it throughonBlockDone. Previously:kernel.executeresolution withsuccess: false(e.g. SyntaxError) was reported viaonBlockDonewithsuccess: true— the success flag was dropped betweenblockOutputsand the post-loop.kernel.executerejection was never reported viaonBlockDoneat all — the catch path returned the error string to the agent but never pushed toblockOutputs, so the post-loop skipped it. The block was already inserted intonotebook.blocks, leaving consumers with an inserted-but-never-completed block.executeAgentBlockitself threw partway through, the post-loop never ran, so even successfully-completed added blocks weren't reported.The fix
success: booleanon eachblockOutputsentry.kernel.executerejection (with a synthesized error output via the existingcreateErrorOutputhelper) so the failed block still getsonBlockDone.executeAgentBlockcall intry/finallyso added blocks are drained even when the agent throws.bo.successthrough toonBlockDoneinstead of hardcodedtrue.collectedOutputs.setin the post-loop (the per-block set insideaddAndExecuteCodeBlockalready covers all paths now).blockOutputs.outputsasIOutput[]to drop the twoas IOutput[]casts.add_code_blocktool description (it claimed "stdout, stderr, and execution results" but actually returns a single formatted string).Tests
surfaces addAndExecuteCodeBlock failures when kernel execution rejectsto assert the failed code block now getsonBlockDonewithsuccess: falseand a synthesized error output.returns failure when kernel execution failsto assertsuccess: falsepropagates for the resolved-failure path too.All 204 tests in
runtime-corepass; typecheck and biome clean.Out of scope (deliberately)
From the review:
onLogregression (docs: init readmes with spellcheck and formatting needed for them #1) —context.onLogwas never set by any caller, so the lost log lines were already no-ops.serializeNotebookContextexport ambiguity (chore: setup spell-check and root pnpm config #2) — JSDoc nudge worth doing but a separate concern.serializeNotebookContextFromBlocks(Enable Renovate for automated dependency pinning and updates #7) — covered transitively; not blocking.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests