Skip to content

feat(core): explicit activePoints() declarations win; undeclared middlewares are auto-detected - #3579

Merged
juruoO-o merged 10 commits into
agentscope-ai:mainfrom
xzxiaoshan:feat/explicit-activepoints
Nov 11, 2026
Merged

juruoO-o merged 10 commits into
agentscope-ai:mainfrom
xzxiaoshan:feat/explicit-activepoints

Conversation

@xzxiaoshan

@xzxiaoshan xzxiaoshan commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3576

Summary

MiddlewareBase#activePoints() keeps its default — fully source- and binary-compatible: no compile errors, precompiled third-party jars keep running — but the contract is now three-tier:

  1. Explicit declarations win. A non-null set is authoritative, read once at agent construction: exactly these points participate. EnumSet.noneOf(...) keeps registration with zero participation (runtime switch); EnumSet.allOf(...) explicitly opts into every point.
  2. Undeclared (null, the default) = auto-detection. Participation is inferred per class — computed once and cached — from the hook methods the class actually implements; implementations inherited from superclasses count. ExtensionPoint constants now carry their hook method name to drive detection.
  3. Every middleware should declare explicitly. The javadoc says so for humans and AI coding tools alike; the null default exists solely for API compatibility with middlewares written before this contract and may change in a future release — do not rely on it. All in-repo middlewares declare.

New ActivePointsResolver owns participation in both dimensions: resolve/infer (middleware → points) and middlewaresAt(point, Supplier)/groupByPoint (points → middleware). ReActAgent delegates its construction-time grouping to it; its frozen snapshot and public middlewaresAt(point) behavior are unchanged.

Why

  • Under the old all-points default, every middleware that didn't override activePoints() participated at every point — including points added in future releases — so middlewaresAt(point) mixed real participants with middlewares swept in by default, and the documented "no participants → no wrapper" optimization was unreachable on any real chain.
  • Auto-detection makes the participation set truthful without breaking anyone: an undeclared middleware now participates exactly where it has logic; its vacuous participation elsewhere disappears with zero observable behavior change (those hooks ran pass-through defaults anyway).
  • Explicit declaration remains the recommended statement of intent — it expresses what inference cannot: intentional opt-out, or participating at a point without implementing its hook.
  • Review rule for future points: activation with side effects beyond the declaring middleware requires an explicit declaration or an explicit switch — never !middlewaresAt(point).isEmpty().

Behavioral note (compatible, but visible)

  • null previously meant "all points"; it now means "auto-detect from implemented hooks". For code that relied on the old default this only removes vacuous participation (pass-through slots); hooks that are actually implemented keep firing. middlewaresAt() results shrink accordingly — that is the fix.
  • Known inference boundary: a hook overridden only by a pass-through base class still lights up its point; the escape hatch is an explicit declaration.

Changes

  • Core: new ActivePointsResolver (explicit-wins resolution, per-class ClassValue-cached hook detection, point-dimension queries); activePoints() default returns null with rewritten javadoc; ExtensionPoint constants carry their hook method name; ReActAgent groups via the resolver at construction (frozen map and public behavior unchanged).
  • All in-repo implementations (core, harness, extensions, examples, service-dataplane) declare exactly the points they hook.
  • Tests: inference semantics (null/default declarations, inherited implementations, zero-hook middlewares stay out, empty set, construction-time freezing, per-point filtering), resolver unit tests, and declaration-consistency checks (shipped middlewares declare every point whose hook they implement) folded into the core and harness *ActivePointsTests.
  • Docs: EN/ZH middleware guide updated to the three-tier contract.

activePoints() is now abstract: participation is only what a middleware
explicitly declares — no default "active everywhere", and a null
declaration fails fast at agent construction. middlewaresAt() lists only
explicit declarants. All in-repo implementations now declare exactly the
points they hook; EN/ZH middleware docs updated.

Also give ChatSessionsTest a single calibrated 30s wait bound; the old
15s block timed out on loaded parallel builds.

Migration: implement activePoints() with the hooked points (or
EnumSet.allOf to keep prior behavior); rebuild third-party middleware
jars against this version.
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/jev/evaluation/JevTraceEvaluationMiddleware.java 0.00% 1 Missing ⚠️
...s/judge/jev/integration/JevResponseMiddleware.java 0.00% 1 Missing ⚠️
...udge/jev/supervision/JevSupervisionMiddleware.java 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Conflict and semantic resolutions:
- ChatSessionsTest#injectionDoesNotStartExecutionAndSurvivesRestart:
  keep main's 60s await ceiling (upstream deflake for the 16.5s CI run
  under -T1C) instead of the branch's 30s constant at this site; the
  ceiling only bounds the failure deadline, so the happy path is
  unchanged.
- SubagentFactoryDeclarationTest (new on main): the anonymous
  MiddlewareBase now declares activePoints() = ON_AGENT as required by
  this branch's explicit active-points contract.
…oints

Semantic conflict resolutions (activePoints() is now abstract):
- OpenAIDecisionsMiddlewareExample.ModelAudit declares ON_MODEL_CALL
- A2aAgentTest anonymous middlewares declare ON_REASONING / ON_AGENT
@mintlify

mintlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

✅ Preview approved

@juruoO-o approved a Mintlify preview for commit 0722483.

…oints

Conflict resolution and contract adaptation:
- ContextConventionsMiddleware: keep our explicit activePoints()
  declaration alongside main's new order() override and reset-warning
  logging (mutually orthogonal changes)
- Adapt main's new anonymous MiddlewareBase tests to the abstract
  activePoints() contract: ReActAgentPostActingFeedbackTest and
  StructuredOutputRequestPreparationTest declare ON_MODEL_CALL,
  ContextConventionsResetOrderTest declares ON_SYSTEM_PROMPT
…under -T1C contention

notificationReachesModelRequestUnderRealScheduling asserted on
MockModel.getLastMessages(), but the HarnessAgent post-call memory
maintenance (flush -> consolidation) reuses the same model and appends
its consolidation request shortly after the call returns. Under -T1C
full-verify load the consolidation request can land before the test
reads the last recorded request, so the assertion saw the consolidation
prompt instead of this call's reasoning request (PR CI, ubuntu job).

Select the reasoning request by its user message from
getRecordedMessages() instead of racing the background pipeline on the
last entry.
@jujn jujn added the P2 重要不紧急 label Nov 3, 2026
…lewares are auto-detected

Replace the abstract activePoints() contract with a compatible three-tier
design: explicit non-null declarations are authoritative (read once at
agent construction), the null default delegates participation to per-class
auto-detection of implemented hooks (inherited implementations count,
cached via ClassValue), and the empty set keeps registration with zero
participation.

- MiddlewareBase: activePoints() keeps its default (returns null);
  ExtensionPoint constants carry their hook method name for detection;
  javadoc documents the compatibility-only null default and the new-point
  review rule (side-effect activation never by detection alone)
- new ActivePointsResolver: resolve/infer (middleware dimension) and
  middlewaresAt(point, Supplier)/groupByPoint (point dimension);
  ReActAgent delegates construction-time grouping, frozen snapshot
  unchanged
- tests: inference semantics (null/default, inherited, zero-hook),
  resolver unit tests, declaration-consistency checks folded into the
  core/harness ActivePoints tests
- docs: EN/ZH middleware guide updated to the three-tier contract
@xzxiaoshan xzxiaoshan changed the title feat(core)!: make MiddlewareBase#activePoints() abstract — participation must be declared feat(core): explicit activePoints() declarations win; undeclared middlewares are auto-detected Nov 9, 2026
xzxiaoshan and others added 3 commits November 9, 2026 21:03
…udgets under -T2C contention

doesNotLoseMessageWhenCursorPersistenceInterruptsThePoll used a 10s method
timeout with a 4s latch await while exercising the same loopback polling
machinery as its sibling test (which already uses 30s/10s). Under -T2C
reactor contention the failed-save redelivery cycle exceeds those budgets
and JUnit cuts the method mid-await. Align both budgets with the sibling
test; assertions unchanged.
…gets under -T2C contention

The routing tests await the async submit -> factory -> agent-run ->
status=success pipeline with 5s budgets; under -T2C reactor contention
the full cycle can exceed them (observed at 21s elapsed). Raise the await
ceiling to 30s — the 25ms poll returns as soon as the condition holds,
so the budget only matters under contention; assertions unchanged.
@CLAassistant

CLAassistant commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the explicit-declaration-first resolution and null/default hook inference, including inherited implementations and per-class caching. The implementation matches the agreed design; no blocking issues found. The previous revision passed 40 focused Core/Harness tests locally; the latest update merges main without changing the resolver contract. Merge remains subject to the latest required CI and CLA checks passing.

@juruoO-o
juruoO-o merged commit 6b9d584 into agentscope-ai:main Nov 11, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: MiddlewareBase#activePoints() 应改为抽象方法——参与集只认显式声明

4 participants