Skip to content

fix: keep Discord capture teardown safe after broker startup failures - #200983

Merged
roboclaw-bot merged 1 commit into
mainfrom
flake/l89-discord-capture-socket-fence
Nov 18, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
flake/l89-discord-capture-socket-fence

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

What Problem This Solves

The Discord transcript capture E2E can fail during teardown when background model catalog preparation opens the local spawn-broker socket. Its network fence mistakes IPC for an unexpected null:NaN network destination, and failed capture creation then leaves cleanup unable to finish. This signature appeared on five unrelated PR heads within three hours.

User Impact

Developers retain the test's unexpected-network protection without rejecting local IPC. Catalog resource construction failures can settle cleanly; genuine cleanup failures remain owned and visible at shutdown. No configuration or public API changes.

Why This Change Was Made

Allow nonempty IPC path options through the test fence while retaining its TCP host/port checks. Exercise a real IPC connection and negative TCP controls inside the existing E2E.

At the production owner, record whether an attachment attempted to dispatch its factory. A connection rejected before dispatch can abandon its uncreated broker claim through the existing abandonUnattached contract. After dispatch, native cleanup receipts remain mandatory. If construction cleanup itself fails, retain that obligation with the native source. The catalog pool stores only an acquired capture owner, so later close does not replay a settled creation failure.

Root cause and lifecycle producer inventory

The fence's host/port extraction was the immediate defect (test/e2e/gateway-transcripts-discord-capture.e2e.test.ts:126). Node normalizes net.connect(path) to an options object with path, without host or port. The broker client uses that exact call (src/process/spawn-broker/resource-client.ts:121).

Background catalog work is intentional: publication invokes refreshCommittedProviderCatalogs without awaiting discovery (src/agents/prepared-model-runtime.ts:590, prepared-model-runtime.refresh-scope.ts:53). Timing decides when the cold pool needs IPC. Pool preparation is joined by WorkerTaskPoolCore.close and joinWorkerTaskPreparationCleanups; there is no evidence that this signature requires an unjoined pool-startup defect.

Task producers traced through this lifecycle:

Producer Lifetime / settlement owner
Config/static publication and auth-change publication; degraded-startup continuation when enabled Publication queue, agent build completions, standalone activation tails; closeModelRuntime joins them
Post-publication catalog refresh; explicit full/native catalog and scoped auth demand Catalog access pending, nativePending, pendingAuth; generation custody spans acquisitions
Expiry refresh, native-login rechecks and failed-discovery retry timer Catalog/auth owners; retirement cancels the retry timer and rejects further work
Synthetic-auth and Codex-version probes Worker request captures, abort controllers and watchdog; stop aborts and joins probes
Catalog/auth task dispatch, notifications and host exchanges Worker request tasks, pool task custody; request finally stops the watchdog and releases credential batches
Shared pool rotation, recovery and retirement callbacks gatewayCatalog.rotating / recovery, registered process-close callback; retirement stops borrowers and closes the pool
Pool root preparation, plugin capture owner, source-root creation and worker launch preparingRoot, core preparation cleanup, releaseRoot, capture-owner close
Broker process startup, socket-connect callback/retry/deadline, initialization microtask and resource-message delivery Broker lease plus attachment; undispatched claims can be abandoned, dispatched resources require close receipts; failed constructor cleanup now remains source-owned
Capture native-load notifications and source/native root operations Plugin capture owner/client; source/native roots release before independent-owner close
Test provider handlers, Discord capture/STT scheduler work, agent turns, Gateway startup and skill watchers Existing response/error accounting, fixture close + scheduler stop, agent.wait, startupSettled, Gateway close and closeSkillsWatchers; test fence stays installed through cleanup

Previously, the rejected connect made attachment.close() throw before lease.close() / release(), producing Native resource creation cleanup failed. The pool also cached the rejected capture promise, so its own close rethrew creation failure. Process runtime close correctly aggregates failed cleanup and keeps shutdown retained; this patch fixes the resource producers rather than suppressing that safeguard.

Smallest-fix pass completed. Delta: production +22/-9 lines; tests +41/-7 lines. No shared test helper, retries, timeout increases, assertion weakening, skips, baseline or changelog edits.

Evidence

  • A dependency-free probe executed the actual fence callback through real Node sockets: base net.connect(path) reproduced unexpected socket destination null:NaN; the fix accepted string/options IPC and allowed loopback TCP, while rejecting a foreign host, foreign port, empty-path TCP and numeric-string TCP.
  • git diff --check passed. The pool regression now requires successful close after failed factory creation and adds a synchronous connect-refusal case, retaining the broker-retirement assertion.
  • Requested local E2E attempt: timeout 180s env OPENCLAW_TEST_RUNTIME=node node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts test/e2e/gateway-transcripts-discord-capture.e2e.test.ts --maxWorkers=1. It exited 2 before collection: this worktree has no node_modules. The pool suite has not run locally; test wall time and CI seconds are unavailable.
  • Touched-file lint commands for core files and this root E2E stopped before linting because dependencies are absent. The typecheck runner bootstrap also cannot resolve its compiler (tsrs/package.json); typechecking remains unverified.
  • Repeated 20x / three-shard / load proof is blocked: timeout 50s crabbox run --timing-json -- CI=1 node scripts/run-vitest.mjs test/e2e/gateway-transcripts-discord-capture.e2e.test.ts --maxWorkers=1 failed before allocation because the resolved ascii-box provider requires ASCII_BOX_API_KEY. No box or run URL was created. No stress, broad suite, install, container or browser work ran on the production host. PR CI supplies broad proof; the repeat campaign remains uncovered.
  • Shared autoreview (Codex, P0–P3) reviewed the complete local candidate against 4a44f2031e866e7ee430d01ece41340cefddac5e, identical to committed head 54b6e220fcad67cde9b9f5844a897261c544721b: scoped-clean, no actionable findings. Review included unchanged broker claims, pool preparation/close, catalog request and generation lifetime owners; it did not execute tests or builds.

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Nov 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR permits broker IPC through the Discord capture test fence and repairs resource cleanup after catalog capture construction fails.

Example: Background catalog preparation calls net.connect('/tmp/capture.sock') while the Discord capture E2E fence is installed.

  • Before: The fence rejects IPC as unexpected socket destination null:NaN, and cleanup can replay the failed capture creation.
  • After: The fence accepts IPC while preserving TCP restrictions, and failures before dispatch can release their uncreated broker claims.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) A focused, source-supported repair with green exact-head gates and no discrete correctness finding, but only partial behavioral evidence.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Developers encounter unrelated Discord capture E2E failures followed by retained cleanup errors when background catalog preparation opens broker IPC.
Reason: The maintainer-authored direction addresses an independently reported failure without changing configuration, public APIs, or recovery policy.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a concrete failure still present on current main, preserves native-resource custody, and has green exact-head CI; no actionable correctness defect was found.

Priority: P2
Reviewed head: 54b6e220fcad67cde9b9f5844a897261c544721b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a redacted real-broker trace showing connection or factory failure followed by successful pool cleanup, plus retained source ownership when constructor cleanup fails; baseline-red regression execution is also not shown.
Agent review details

How this fits together

Catalog worker preparation acquires plugin capture resources through the local spawn broker; attachment and source owners retain responsibility until construction fails safely or native cleanup is confirmed.

flowchart TD
  A[Discord capture E2E fence] --> B[Local IPC socket]
  C[Catalog worker pool] --> D[Plugin capture owner]
  D --> E[Retained native source]
  E --> F[Broker attachment]
  F --> B
  B --> G[Spawn broker resource]
  G --> E
Loading

Technical review

Best possible solution:

Keep the narrow repair in the existing fence, attachment, source, and pool owners while preserving native close receipts after dispatch.

Do we have a high-confidence way to reproduce the issue?

Current-main source exposes the IPC rejection and rejected-promise cleanup paths, corroborated by the exact-main-parent reproduction recorded in #200372; this review executed no target code.

Is this the best way to solve the issue?

The patch fixes the producers: it distinguishes IPC from TCP, abandons only undispatched claims, retains failed cleanup with the native source, and stores only successfully acquired capture owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 97b03f7428d3.

Provenance checked

  • Broker-backed capture custody keeps the original intent (907e17b: Move physical capture operations off the Gateway thread while retaining independent resource custody.)
  • Catalog pool construction failure changes intended behavior with a stated reason (907e17b: Join capture preparation and release through the pool; the original regression explicitly expected close to repeat a factory failure.)
  • Discord E2E network fence changes intended behavior with a stated reason (df958c1: Reject unexpected Node network destinations throughout the capture flow and cleanup; this PR explains why local broker IPC must remain available.)
  • Attachment failure and native receipts keeps the original intent (9c93bc3: Transport failure must not fabricate native resource settlement; synchronous connection rejection was subsequently contained by fix: native worker supervisor crashes when a resource attachment endpoint is rejected #180773.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 907e17b adds src/agents/prepared-model-catalog-worker.pool.ts:33 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 907e17b9ff49; files: src/agents/prepared-model-catalog-worker.pool.ts)
  • Dallin Romney: Raw commit adb660f adds src/infra/worker-native-lifecycle.ts:323 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: adb660f90dd5; files: src/infra/worker-native-lifecycle.ts)
  • Anmol: Raw commit a06d324 adds src/process/spawn-broker/resource-client.ts:118 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: a06d324b5cf0; files: src/process/spawn-broker/resource-client.ts)
  • matthematics1137: Raw commit 2e418fe adds src/agents/prepared-model-catalog-worker.pool.ts:21 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 2e418fed16b1; files: src/agents/prepared-model-catalog-worker.pool.ts)

PR surface

Source +13, Tests +34. Total +47 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 22 9 +13
Tests 2 41 7 +34
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 63 16 +47

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +22/-9 lines; tests +41/-7 lines The modest growth repairs existing custody owners and covers distinct IPC acceptance, TCP rejection, factory failure, and connection-refusal behavior without adding another abstraction.

Labels

Label changes:

  • add P2: A concrete developer-facing E2E failure and resource-construction cleanup defect warrant a focused repair, without evidence of an urgent production outage.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A concrete developer-facing E2E failure and resource-construction cleanup defect warrant a focused repair, without evidence of an urgent production outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the production broker and pool failure-settlement trace described in the proof assessment.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 17, 2026, 11:28 PM ET / November 18, 2026, 04:28 UTC.

@roboclaw-bot
roboclaw-bot merged commit 929f2e7 into main Nov 18, 2026
139 checks passed
@roboclaw-bot
roboclaw-bot deleted the flake/l89-discord-capture-socket-fence branch November 18, 2026 04:38
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

RomneyDa added a commit that referenced this pull request Nov 19, 2026
…#200983)

(cherry picked from commit 929f2e7)
Co-authored-by: RomneyDa <[email protected]>
Release adaptation: required #200320 companion; safely abandon native factories that never dispatched and retain cleanup obligations after broker startup failure.:
(cherry picked from commit f2af7017a4995544bfcdca0001076661681fa6c3)
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…openclaw#200983)

(cherry picked from commit 929f2e7)
Release adaptation: approved 2026.11.7 models replay; see models-hook-safe-v2/REPORT.md.
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant