Skip to content

fix(python): stop memory event reconnects during shutdown - #1142

Open
remote-controlled-man wants to merge 1 commit into
Agent-Field:mainfrom
remote-controlled-man:codex/prflow-73313d539a93
Open

remote-controlled-man wants to merge 1 commit into
Agent-Field:mainfrom
remote-controlled-man:codex/prflow-73313d539a93

Conversation

@remote-controlled-man

Copy link
Copy Markdown
Contributor

Summary

MemoryEventClient.close() could trigger a reconnect when the listener received the socket's close notification, and in-flight or queued connections could become active after shutdown. Track and stop the client's background connection/listener/retry tasks and discard connections that finish after a close. Explicitly connecting the same client again remains supported.

Prepared with AI assistance, independently reviewed and tested.

Type of change

  • Bug fix

Test plan

  • Reproduce an unwanted second connection after close() on the original implementation.
  • Reproduce an in-flight connection becoming active after shutdown; verify connection requests queued before close are discarded; cover retry backoff cancellation, cancellation during close, and explicit reuse with a real local WebSocket server.
  • ./scripts/test-all.sh (control plane, Go SDK, Python SDK with coverage, TypeScript SDK, and web UI). Go tests use an isolated Linux Go 1.25.14 runtime with controlled public/invalid DNS responses; Python and JavaScript tests run natively on macOS.
  • Python SDK ruff check and mypy --config-file mypy.ini agentfield/.
  • Memory event tests with websockets 12.0 and 15.0.1.

Test coverage

  • Tests cover the changed surface and the new shutdown paths.
  • No coverage baselines were lowered.
  • The coverage gate check is green in CI before requesting review. (Awaiting GitHub CI.)

Checklist

  • Read docs/CONTRIBUTING.md and docs/DEVELOPMENT.md.
  • Commits are signed and follow conventional-commits style. (The commit uses conventional-commits style; it is unsigned.)

Related issues / PRs

No existing Python shutdown issue found. This is separate from the earlier TypeScript memory client cleanup in #157.

Copilot AI balanced review requested due to automatic review settings October 31, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 84%, aggregate ≥ 85%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 88.20% 87.40% ↑ +0.80 pp 🟡
sdk-go 93.70% 92.00% ↑ +1.70 pp 🟢
sdk-python 94.73% 93.73% ↑ +1.00 pp 🟢
sdk-typescript 92.27% 90.42% ↑ +1.85 pp 🟢
web-ui 84.90% 84.79% ↑ +0.11 pp 🟡
aggregate 86.12% 85.75% ↑ +0.37 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions

Copy link
Copy Markdown
Contributor

Performance

SDK Memory Δ Latency Δ Tests Status
Python 9.1 KB - 0.32 µs -9% ✓ ✓

✓ No regressions detected

@github-actions

Copy link
Copy Markdown
Contributor

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 — ➖ no changes
sdk-go 0 — ➖ no changes
sdk-python 0 — ➖ no changes
sdk-typescript 0 — ➖ no changes
web-ui 0 — ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants