Skip to content

[Bug]: HttpSelfRegistration.close() skips deregistration when a heartbeat re-register cycle is in flight (flaky HttpSelfRegistrationTest on CI) #3132

Open

Description

@thinkw

Description

While CI-testing PR #3131 on windows-latest, HttpSelfRegistrationTest. registrationUsesTenantAndDurableIdentityForHeartbeatAndDelete failed
intermittently with the deleted latch timing out at
HttpSelfRegistrationTest.java:106:

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
    at io.agentscope.extensions.aistio.transport.HttpSelfRegistrationTest
        .registrationUsesTenantAndDurableIdentityForHeartbeatAndDelete(...:106)

The runner stderr showed aistio: registered runtime-instance-key ... twice,
indicating a heartbeat-failure re-register cycle ran concurrently with
close().

Root cause

HttpSelfRegistration.close() gates the control-plane DELETE on
registered.get():

if (!registered.get()) {
    return;   // skips the DELETE even if registeredInstanceId is still set
}

heartbeatSafe() clears registered before re-registering after a
heartbeat failure. If close() runs inside that window (likely on loaded
runners where a heartbeat request can fail), the DELETE is silently skipped:
the instance is leaked on the control plane, and the test's deleted latch
times out. Fast local machines rarely hit the window, which is why the test
is green locally and only flakes on CI.

Impact

  • Real resource leak: an instance that was registered stays registered on the
    control plane after close() (ghost instance).
  • Flaky CI: HttpSelfRegistrationTest fails under load.

Suggested fix

Make close() best-effort unregister whenever an identity exists
(registeredInstanceId != null), keeping never-registered calls as a no-op
and repeat closes idempotent; widen the test latches from 2s to 10s so slow
runners don't turn slow (not stuck) callbacks into failures.

Fix will be attached to PR #3131 (discovered by its CI run).

Activity

  1. added
    bug
    on Sep 13, 2026
  2. added a commit that references this issue on Sep 13, 2026
    22bd6ac
  3. oss-maintainer commented on Sep 13, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against main @ 39cd304a.

    Root cause: close() decides whether to send the control-plane DELETE by reading registered, but the heartbeat path clears that flag before re-registering.

    • agentscope-extensions/agentscope-extensions-aistio/src/main/java/io/agentscope/extensions/aistio/transport/HttpSelfRegistration.java:143-145 — if (!registered.get()) { return; } skips the DELETE even while registeredInstanceId still holds a durable instance key.
    • HttpSelfRegistration.java:180-183 — on 404, registered.set(false) then tryRegister().
    • HttpSelfRegistration.java:185-191 — on any heartbeat exception, registered.set(false) then tryRegister().

    A close() landing inside that window therefore returns early, and the re-registration that follows is never torn down — exactly the race described.

    Impact: a registered instance stays registered on the control plane after close() (ghost instance), and HttpSelfRegistrationTest.registrationUsesTenantAndDurableIdentityForHeartbeatAndDelete times out on the deleted latch at HttpSelfRegistrationTest.java:106 under loaded runners. Severity: medium — a real lifecycle leak, but bounded to the aistio self-registration path.

    Fix assessment: the suggested approach is correct and minimal — gate close() on registeredInstanceId != null rather than registered.get(), keep never-registered calls a no-op, and clear the identity in finally so repeat closes stay idempotent. Widening the test latches from 2s to 10s is reasonable hardening for slow runners, but it is secondary: it hides the timing symptom without removing the leak.

    PR coordination: this issue says the fix will be attached to #3131, and that PR is already cross-referenced here, so we will not open a competing PR. If you would rather have an independent fix PR for this one, reply /approve and we will generate one.


    Automated evaluation by github-manager-bot

  4. added
    area/extensions
    on Sep 13, 2026
  5. oss-maintainer commented on Sep 14, 2026

    @oss-maintainer
    Collaborator

    Adjacent-PR advisory — no change to the evaluation above (supplementary context; this proposal window stays open and is not being stood down)

    While polling this window, one community PR now claims the fix described above:

    Two mechanical notes:

    What this means for the offer above: #3131 is the active path for this fix, so opening our own PR here would only duplicate it — we are treating #3131 as the carrier and are not generating a competing PR. The independent-proposal path in the evaluation above is still available: if you would rather see this fixed separately (for example if #3131 stalls, or a maintainer closes it), say so in this thread and we will open one scoped so it cannot collide with the two files above.

    No action is needed from anyone. This window closes on its own on 2026-09-16T17:07Z if the thread stays quiet.

    Automated by github-manager-bot

  6. oss-maintainer commented on Sep 16, 2026

    @oss-maintainer
    Collaborator

    Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed

    The evaluation above went 72 hours without an /approve, /revise or /reject, so per our workflow the window is closed and no competing PR will be generated. No action is needed from anyone.

    The root cause still stands, and it is still not fixed on main: as of this check origin/main @ 6c8ccc5c6 still gates the deregistration on if (!registered.get()) { return; } in HttpSelfRegistration.close() (agentscope-extensions/agentscope-extensions-aistio/src/main/java/io/agentscope/extensions/aistio/transport/HttpSelfRegistration.java), which is exactly the window the report describes.

    The fix is already in flight, carried by the PR this issue was announced alongside:

    One mechanical caveat, repeated from the note above so nobody is surprised later: #3131 is not keyword-linked to this issue — its closing references resolve to #3102 — so GitHub will not auto-close #3132 when #3131 merges. If #3131 lands, this issue still needs a manual close, or a Fixes #3132 added to that PR.

    What this issue needs next is a maintainer review of #3131, not a second implementation. If maintainers would still like an independent proposal here — for example one scoped to HttpSelfRegistration alone so it cannot collide with #3131's two files — reply on this issue and we will open one.

    Automated by github-manager-bot

  7. aiyili commented on Dec 1, 2026

    @aiyili
    Contributor

    Hit this again today, on 2.0.x: the Windows job of #4450 (108fae28) failed this test at :106 with the signature described here, aistio: registered ... logged twice.

    Two things have changed since the report, which is why I'm picking it up here:

    • agentscope-extensions-aistio no longer exists on main, so feat(agent): support recovery mechanism for streaming tool call errors #3131 cannot deliver this fix there. On 2.0.x the class is as described (close() still returns early on !registered.get()), and every PR against 2.0.x runs this test on Windows.
    • The leak is wider than a skipped DELETE. I repeated the test's scenario 300 times on unmodified 2.0.x (Linux, the test's 20 ms heartbeat): in 291 runs the heartbeat that close() interrupted registered the instance again — shutdownNow() lands while the request is on the wire, the catch path takes that for a failure and calls tryRegister() — and in 277 of them that registration reached the server after the DELETE, so the instance is registered again after it was deregistered. The skipped DELETE of this issue showed up once in an earlier batch of 300.

    I'd like to fix it on 2.0.x, in HttpSelfRegistration and its test only: no registration once close() has started, close() waiting for the interrupted heartbeat before it deregisters, and deregistering by the registered id instead of the registered flag. With a regression that pins the interleaving. It cannot collide with #3131, which targets main. Shout if you would rather handle it differently.

  8. aiyili commented on Dec 1, 2026

    @aiyili
    Contributor

    Opened #4542 against 2.0.x, on eb5d08e9.

    tryRegister() does nothing once close() has started, and close() deregisters by the registered instance id rather than the registered flag. Two regressions pin the interleavings with a local server that holds a response until close() has run; both fail on the previous code, 9 runs out of 9. The scenario repeated 300 times with the change: no second registration and no skipped DELETE, against 291 and 1 on the unmodified code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/extensionsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions