Repository navigation
fix(harness): inherit parent hooks in declared subagents - #2996
ordinary-s wants to merge 10 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| * @return a new ReActAgent instance | ||
| * @throws IllegalArgumentException if required parameters are missing or invalid | ||
| */ | ||
| public ReActAgent build(Consumer<Toolkit> hookToolFilter) { |
There was a problem hiding this comment.
Non-blocking suggestion: since this callback is intended to decide which hook-contributed tools to retain, could the public API accept a Predicate<String> instead? Consumer<Toolkit> also allows callers to add or replace tools in the temporary toolkit, which is broader than the filtering contract described by the Javadoc. A predicate would express the intended keep/drop behavior more directly.
There was a problem hiding this comment.
Thanks for the suggestion. Updated the overload to build(Predicate). The predicate receives the resolved registered tool name (the same name exposed in the tool schema), with true retaining the Hook-contributed tool and false excluding it.
Filtering is applied after Hook tool resolution and only to Hook contributions. Existing tool registration, ordering/deduplication, toolkit configuration, callbacks, and reflective metadata remain unchanged. I also added regression coverage for these boundaries.
commented
Sep 17, 2026
|
Thanks for the update. I reviewed the follow-up changes. The Predicate API now matches the intended filtering contract, and the added tests cover the important boundaries: resolved tool names, Hook ordering/deduplication, existing and built-in tools, toolkit configuration/metadata, and effective child tool restrictions. The Hook inheritance Javadoc and parent-only filtering guidance also address my documentation concern. No further changes requested from my side. |
left a comment
There was a problem hiding this comment.
Summary
Declared subagents now inherit the parent's explicit Hook collection, and hook-contributed tools are filtered by the declaration allowlist plus the child's workspace policy before installation — implemented by a new ReActAgent.Builder.build(Predicate<String>) hook and a package-private HarnessAgent.Builder.build(List<String>) variant. Fixes #1578.
Verdict: COMMENT — the approach is sound and the test coverage is unusually thorough, but I want two points resolved before this is treated as ready:
- The
capturedToolsConfig != nullguard inbuildDeclaredFactoryquietly changes MCP server materialization for declared subagents that have atools:declaration and their ownworkspace/tools.json(details inline). If that is intended, it belongs in the PR description / release note, because it widens what a declared child can reach externally. - The new
build(Predicate<String>)overload is core API that cascades to harness, distribution and every extension; the name-only,null-means-no-op contract should be a deliberate decision (inline).
Strengths
- Filtering before installation is the right layer: it keeps working when the toolkit forbids runtime deletion (
allowToolDeletion(false)), which a post-registrationToolFilter.applycould not do. The test that asserts a rejected contribution leaves the child's same-name Harness tool intact pins exactly that. filterRunsAfterToolNameResolutionWithoutChangingHookOrderOrDeduplicationis the correct regression to write here: it proves the throwaway-toolkit rewrite preserves hook priority ordering, one-shottools()invocation, and duplicate-name resolution instead of just asserting the happy path.- Preserving
ToolBasemetadata (readOnly / concurrencySafe), the caller's executor and the chunk callback through the copy is verified by executing the kept tool, not by inspecting fields. - Making
childToolsConfigpackage-private rather than duplicating its strict-allow synthesis keeps one definition of the policy. - The empty-list case is handled deliberately: an empty declaration still applies the child's workspace policy instead of being read as "allow everything".
Caveat
Read-only review: nothing was compiled or executed here beyond the CI evidence below, and the 727-line HarnessAgentTest addition was reviewed for what it pins, not run.
CI on head 8d5687ba: ubuntu + windows build, Check License, Check Module Sync and codecov/patch all pass; CLA signed. MERGEABLE/BLOCKED with one human APPROVED already on record.
Automated review by github-manager-bot
left a comment
There was a problem hiding this comment.
Summary
Re-review after the follow-up push (8d5687ba → a6ad007e). The previous round's blocking concerns are addressed: contributed tools are copied in sorted name order, the new hookToolFilter setter replaces the build(Predicate) shape, the temporary-toolkit contract is now documented on both Hook.tools() and ReActAgent.Builder, and the workspace-MCP / declaration-allowlist interaction is pinned by DeclaredSubagentMcpConfigTest plus the subagentHooks_* matrix. Hook inheritance for declared subagents now matches the general-purpose path, which is the right way to close #1578.
Findings
No correctness bug found in the new commits. The remaining items are about an undocumented parent/child asymmetry and the silence of policy-driven drops:
- [Warning]
HarnessAgent.java:2969— inherited hook tools are policy-gated in declared children but never in the parent (ToolFilter.applyruns beforeinner.build()); the asymmetry should be documented. - [Warning]
HarnessAgent.java:2973— a dropped hook tool leaves no log evidence of which policy rejected it. - [Warning]
ReActAgent.java:5376— the throwaway toolkit makesHook.tools()a second-pass call and binds againstToolkitConfig.defaultConfig(); tighten the contract wording. - [Info]
HarnessAgent.java:2765,HarnessAgentBuilderSupport.java:453,ReActAgent.java:5379— precedence / snapshot / same-name-replacement clarity.
Verdict
Comment only, not an approval: build (windows-latest) is still pending on the new head and codecov/patch reports a failure, so coverage on the added filter branches should be confirmed green before this is approved. None of the findings above block a merge once CI is green — they are documentation and observability follow-ups.
Automated review by github-manager-bot
left a comment
There was a problem hiding this comment.
Summary
Re-review at 65af113f. The only change since the previous pass (a6ad007e) is a merge of upstream main: Hook.java, HookToolsRegistrationTest and DeclaredSubagentMcpConfigTest are untouched by the merge, so the earlier analysis still holds.
CI on this head is green — build (ubuntu-latest), build (windows-latest), Check License, Check Module Sync, codecov/patch, license/cla — which was the only reason the previous round stopped short of an approval.
Findings
No new issues in the merge. Open items from the previous round stay non-blocking follow-ups:
- [Warning]
HarnessAgent.java— inherited hook tools are policy-gated in declared children but not in the parent (ToolFilter.applyruns beforeinner.build()); the asymmetry deserves a doc note. - [Warning]
HarnessAgent.java— a policy-dropped hook tool leaves no log evidence of which policy rejected it; a debug log would help operators. - [Info]
ReActAgent.java— the throwaway toolkit makesHook.tools()a second-pass call bound toToolkitConfig.defaultConfig(); tighten the contract wording.
Verdict
Approving: hook inheritance for declared subagents is correct, pinned by tests, and CI + CLA are green on the current head. The items above are documentation/observability follow-ups, not merge blockers.
---Automated review by github-manager-bot
commented
Sep 24, 2026
|
This PR currently conflicts with git fetch origin
git checkout fix/1578-declared-subagent-hooks
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after the conflicts are resolved. Automated notification by github-manager-bot |
left a comment
There was a problem hiding this comment.
Summary
Re-review of the new head c2398d02, which merges upstream main (857e3e6cf1) into the previously approved 65af113f and resolves the hook-tool-registration conflicts. Scope of this pass is the merge resolution, not a re-litigation of the design.
What I verified in the resolved files:
ReActAgent.Builder.hookToolFiltersurvived the merge intact: the field, the null-checked setter, thebuild()branch that resolves hook contributions into a throwawayToolkitand copies the retained ones, and theHook.tools()javadoc that states the "plain value objects, no registration-time resource ownership" precondition this design depends on.HarnessAgent.Builder.build(inheritedHookToolAllowlist)still composes the inherited allowlist withToolFilter.isAllowed(...)before the child is built, andHarnessAgentBuilderSupport.childToolsConfigis package-private for that call site — the null/empty distinction is documented on the overload.- The conflict resolution strengthened rather than weakened the tests:
HookToolsRegistrationTestnow assertsassertNull(builderToolkit.getTool("hook_ping"))and adds a second agent registering a same-named tool, pinning both that the caller's toolkit is never mutated and that two agents keep distinct instances.
CI on this head is green — build (ubuntu-latest), build (windows-latest), Check License, Check Module Sync, codecov/patch, license/cla — and mergeStateStatus is CLEAN.
Approving. The two non-blocking items from the previous round are still open (no evidence trail for a policy-dropped hook tool, parent/child gating asymmetry deserves a doc note); one is inline above.
Automated review by github-manager-bot
Preserve the default 30-second chat wait and upstream 60-second waits for slow durable session scenarios. Validation: 115 focused tests passed across Hook tools, declared subagents, builder reuse, custom factories, and chat sessions. Relevant Spotless checks and git diff whitespace checks passed. Tests use a workspace temp directory to avoid Windows system-temp access errors.
AgentScope-Java Version
2.0.3-SNAPSHOT
Description
Fixes #1578
Automatically constructed local declared subagents now inherit their parent's explicitly configured Hook instances, matching general-purpose subagents. Programmatic declarations, static workspace Markdown and dynamic Markdown discovery use the same factory. Hook priority and deduplication remain unchanged. Hook Javadoc explains shared-instance reentrancy, agent/session state isolation and parent-only event handling.
Filter Hook-contributed tools against the declaration allowlist and effective child workspace policy before installation, including when runtime tool deletion is disabled. Rejected contributions preserve existing same-name tools; retained tools preserve execution configuration, callbacks and reflective metadata.
The core API is
ReActAgent.Builder.hookToolFilter(Predicate<String>).build(). The predicate deliberately receives only resolved public tool/schema names after duplicate resolution; it does not receive tool objects or runtime arguments. Null predicates are rejected, and omitting the setter preserves normal registration. Accepted tools are copied in sorted name order. Hook contributions must have no registration-time resource ownership or one-shot toolkit binding; this contract is documented both onHook.tools()and beside the temporary toolkit.Declared-child MCP behavior
When there is no explicit parent
ToolsConfigoverride, resolve the child'sworkspace/tools.jsonbefore deriving its declaration policy. This intentionally loads that file'smcpServers, including when the declaration contains a nonemptytools:list. Previously the synthetic strict override hid the entire workspace configuration and prevented these servers from being registered. Existing declarations with workspace MCP servers can therefore establish connections that were previously suppressed. The declaration filters exposed tools, not server connections. Explicit parent configuration still takes precedence; an explicit configuration with no MCP servers suppresses workspace MCP registration.A deterministic regression builds the real declared child and exercises workspace loading, MCP registration, tool restrictions and client closure with mocked transport clients. It pins workspace-server, explicit-server and empty-override behavior without external connections.
General-purpose behavior, custom factories, remote subagents and middleware inheritance are unchanged.
Validation
Windows, Maven 3.9.11, Temurin Java 17.0.20.1. Follow-up based on PR head
8d5687bababf1589a0f2bfb6779fff4d382f0d5a(mainc6af781836b23b1325968585104445856c57bba3).Focused Hook/MCP regressions:
mvn -pl agentscope-harness -am "-Dtest=HookToolsRegistrationTest,DeclaredSubagentMcpConfigTest,HarnessAgentTest#subagentHooks_*" -Dsurefire.failIfNoSpecifiedTests=false -DforkCount=0 test— 41 cases passed.Core full suite:
mvn -pl agentscope-core -am test— 2341 cases, 0 assertion failures, 2 errors, 8 skipped. Both errors are Windows symlink privilege failures inDangerousPathBypassTest; the same two errors reproduce on unchanged PR head8d5687bain a separate clean worktree.Harness full suite:
mvn -pl agentscope-harness -am "-Dtest=io.agentscope.harness.**" -Dsurefire.failIfNoSpecifiedTests=false -DforkCount=0 test— 1062 cases, 0 failures/errors, 15 skipped (1047 passed).Whole-repository
mvn spotless:checkand diff whitespace checks against the PR base passed.Consumer compatibility:
mvn -pl agentscope-distribution/agentscope-all -am -DskipTests package— all 63 modules built successfully, including test compilation and Javadoc packaging. This is a compilation/package check, not an extension test run.Harness retains the existing local
forkCount=0workaround. Core uses the default forked JVM: attempting the whole core suite without a fork additionally breaks existing working-directory and nested-jar classloading tests. No build/test configuration is changed, and full-reactor green status is not claimed. Skips and environment errors are not counted as passes.Checklist