feat(actor): add plan_subplan tool and decision emission #463
No reviewers
Labels
No labels
auto/needs-reevaluation
controller-managed
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cleveragents/cleveragents-core!463
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/m5-subplan-actor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Implements the
builtin/plan-subplantool that strategy actors call to emitSUBPLAN_SPAWNorSUBPLAN_PARALLEL_SPAWNdecisions when decomposing a largeplan into coordinated child plans. Validates the subplan payload, applies
sensible defaults, generates human-readable rationale text, and optionally
persists the emitted
Decisionvia an injectedDecisionService.Type of Change
Quality Checklist
Anyunless justified)nox -s typecheckpasses with no errorsnox -s lintpasses with no errorsfeatures/)robot/) if applicablenox -s coverage_report)nox -s security_scan)nox -s dead_code)Testing
All tests written before implementation (TDD). Tests cover validation,
defaults, serial vs parallel decision types, rationale generation, decision
service injection, registry registration, and ToolRunner execution.
Test Commands Run
Related Issues
ISSUES CLOSED #198
Implementation Notes
New files
src/cleveragents/tool/builtins/subplan_tool.pySubplanPayload,make_plan_subplan_spec,PLAN_SUBPLAN_SPECfeatures/plan_subplan_tool.featurefeatures/steps/plan_subplan_tool_steps.py_StubDecisionServicerobot/plan_subplan_tool.robotrobot/helper_plan_subplan_tool.pybenchmarks/subplan_actor_tool_bench.pyexamples/actors/strategy_with_subplan.yamlModified files
src/cleveragents/tool/builtins/__init__.py— addedregister_subplan_tool,SubplanPayload,make_plan_subplan_spec,ALL_SUBPLAN_TOOLSexportsCHANGELOG.md— added#198entryArchitecture decisions
Optional
DecisionServiceinjection via factory: The tool itself is apure function.
make_plan_subplan_spec(decision_service=None)creates aToolSpecwhose handler is a closure bound to the service. In production theruntime injects the real
DecisionService; in tests a list-based stub is used,keeping 100% of tool logic testable without a database.
SubplanPayloadas the single validation layer: All input constraints(non-empty goal, at least one of
resource_scopes/project_ref,max_parallel1–50, valid
merge_strategyenum, validcontext_viewvalue) are enforced by afrozen Pydantic model. Any validation failure returns
{"success": False, "error": ...}rather than raising, so the ToolRunner never sees an unhandled exception.Decision type driven by
parallelflag:parallel=FalseemitsSUBPLAN_SPAWN;parallel=TrueemitsSUBPLAN_PARALLEL_SPAWN. Thedependencieslist (sibling subplan ULIDs) is only meaningful for parallelspawns but is accepted and stored in both cases for forward compatibility.
Rationale auto-generation:
_build_rationale()constructs a multi-linehuman-readable string from the payload (goal, targeted resources, execution
mode, dependencies, context view override). This text is stored on the
Decision.rationalefield and surfaced inplan explainoutput.131be21e804c4bd74d944c4bd74d94131be21e80Code Review — Bugs & Security Findings
Reviewed commits
b888afab(feat) and131be21e(fix) onfeature/m5-subplan-actoragainst issue #198 acceptance criteria anddocs/specification.md.BUGS
B1 [High]
parent_decision_idaccepted but never returned to callerFile:
src/cleveragents/tool/builtins/subplan_tool.py:268-281The
parent_decision_idfield is accepted inSubplanPayload(line 149), stored in theDecisionobject (line 255), but the handler's return dict (lines 268-281) omits it entirely. The calling actor has no way to confirm the parent linkage was recorded.The corresponding Behave scenario ("parent_decision_id is included in the decision when provided" at
features/plan_subplan_tool.feature:112-116) only assertssuccess=Trueanddecision_type— it never verifiesparent_decision_idis present in the result, making the test name misleading and the assertion vacuous.Fix: Add
"parent_decision_id": payload.parent_decision_idto the return dict at line 281, and update the test to assert its value.B2 [Medium] "Verify all examples are documented" scenario not updated
File:
features/actor_examples.feature:665-677The fix commit (
131be21e) correctly updated the "Verify all example files exist" scenario (line 654) to expect 7 files includingstrategy_with_subplan.yaml. However, the adjacent "Verify all examples are documented" scenario (line 665) was not updated to check thatstrategy_with_subplan.yamlis referenced indocs/reference/actors_examples.md. Additionally,docs/reference/actors_examples.mddoes not appear to have been updated to reference the new example.B3 [Medium] Specification naming discrepancy
Spec:
docs/specification.md§Child Plan Spawning Mechanism:Implementation:
builtin/plan-subplan(subplan_tool.py:76)These differ in both namespace (
local/vsbuiltin/) and name (create-subplanvsplan-subplan). Either the specification or the implementation should be updated for consistency.SECURITY
S1 [High] No ULID format validation on
plan_id,dependencies,parent_decision_idFile:
src/cleveragents/tool/builtins/subplan_tool.py:115,141-143,149-151SubplanPayloadaccepts arbitrary strings forplan_id(onlymin_length=1),dependencies(no validation), andparent_decision_id(no validation). These fields semantically represent ULIDs.The
Decisionmodel in the same codebase (domain/models/core/decision.py) rigorously validates ULID fields with a regex pattern (^[0-9A-HJKMNP-TV-Z]{26}$) and dedicated@field_validatormethods. This inconsistency means:plan_idvalues pass the tool handler, then fail insideDecision(**decision_kwargs), producing a confusing error message about the Decision model rather than about the tool input.dependenciesentries flow into the rationale text completely unchecked.Fix: Add
@field_validatormethods onplan_id,dependencies, andparent_decision_idinSubplanPayloadenforcing the same ULID regex pattern used by theDecisionmodel.S2 [Medium] No path validation on
resource_scopesFile:
src/cleveragents/tool/builtins/subplan_tool.py:119-121resource_scopesaccepts arbitrary strings with no format or sanitization checks. Values like[""],["../../etc/passwd"], or extremely long strings are accepted and flow into the Decision rationale and downstream processing. Early validation (non-empty strings, no path traversal sequences) would prevent garbage from entering the decision tree.S3 [Low] Overly broad exception handling masks programming errors
File:
src/cleveragents/tool/builtins/subplan_tool.py:226This catches
ValidationError(intended) but alsoTypeError,AttributeError,KeyError, and any other exception that might indicate a bug in the validation code itself. These bugs would silently become user-facing error messages instead of surfacing as real failures.Fix: Catch
pydantic.ValidationErrorandValueErrorexplicitly.cc72ec0936eb4e6f59d9P1 — Must Fix
P1-1: Sham rationale test — asserts non-empty, not goal presence
features/steps/plan_subplan_tool_steps.py:302-305The feature scenario "Rationale is auto-generated for serial subplan" claims to verify the goal is mentioned in the rationale, but the step
step_then_rationale_goalonly assertsassert rationale(truthy / non-empty). Any non-empty string passes.Fix: Assert the actual goal text appears in the rationale. The
Whenstep for this scenario passesgoal="Refactor models", so:P1-2:
source="builtin"silently discarded —ToolSpechas nosourcefieldsrc/cleveragents/tool/builtins/subplan_tool.py:427ToolSpec(defined intool/runtime.py:39) has nosourcefield. Pydantic v2 defaults toextra="ignore", so this kwarg is silently dropped. Any downstream code that tries to inspectspec.sourcewill getAttributeError. If the intent is to tag built-in tools by origin,sourcemust be added toToolSpec, or this parameter should be removed.Fix: Either add
source: str = Field(default="custom")toToolSpec, or remove thesource="builtin"kwarg.P2 — Should Fix
P2-1:
side_effectsvalue diverges from specsrc/cleveragents/tool/builtins/subplan_tool.py:424The spec (
specification.md:18101) definesside_effects: [spawn_subplan]for the create-subplan tool. The implementation uses["emit_decision"]. While the field is free-form, using a consistent vocabulary with the spec aids auditability and tool-capability queries.Fix: Use
["spawn_subplan"]or["spawn_subplan", "emit_decision"]to align with the spec vocabulary.P2-2: Dead
TYPE_CHECKINGimport guardsrc/cleveragents/tool/builtins/subplan_tool.py:81-82The block was set up but contains only
pass. Either add the intended type-only imports or remove the dead guard.P2-3: Non-deterministic
context_viewenum order in JSON schemasrc/cleveragents/tool/builtins/subplan_tool.py:92-94, 396_VALID_CONTEXT_VIEWSis afrozenset, whose iteration order is non-deterministic. The JSON schemaenumat line 396 unpacks it via[*list(_VALID_CONTEXT_VIEWS), None], producing a different enum order on each Python process restart. This can cause spurious schema-diff noise in CI.Fix: Use a
tupleorsorted()to produce a deterministic order:P3 — Nit
P3-1: Weak assertion on parallel rationale scenario
features/plan_subplan_tool.feature:98-101The scenario "Rationale for parallel subplan mentions parallel execution" only asserts that the rationale contains
"parallel". It doesn't verifysuccess=Trueordecision_type="subplan_parallel_spawn". Other parallel scenarios do check these, so this isn't a gap in coverage, but the scenario itself is under-asserted for its title.P3-2: Subplan payload fields not structurally persisted on Decision
src/cleveragents/tool/builtins/subplan_tool.py:298-309The
Decisionobject does not carryresource_scopes,merge_strategy,max_parallel,dependencies, orcontext_viewin structured fields — they only appear in the free-textrationale. This means theplan explaintree can display them (via rationale text) but they're not queryable for programmatic use. Worth a follow-up ticket if structured querying is needed.Summary
Closing as duplicate of #198 (same title, same scope). #198 is assigned to @aditya with active branch
feature/m5-subplan-actor.New commits pushed, approval review dismissed automatically according to repository settings
Not duplicate. This is THE #198 PR. I'm assigned @aditya, on
feature/m5-subplan-actorAlready approved.