Skip to content

fix: collectors keep failing after valid late structured output - #187444

Open
wyf027 wants to merge 1 commit into
openclaw:mainfrom
wyf027:fix/collector-late-output-138018-20261029
Open

wyf027 wants to merge 1 commit into
openclaw:mainfrom
wyf027:fix/collector-late-output-138018-20261029

Conversation

@wyf027

@wyf027 wyf027 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138018

What Problem This Solves

Fixes: agents_wait keeps reporting a collector as failed when valid structured output arrives after successful execution has frozen a missing-output result.

User Impact

User impact: an authorized late result repairs that missing-output failure and remains available to later waits. Real execution failures, other schema failures, existing results, expired authority, and duplicate submissions remain rejected.

Why This Change Was Made

The existing registry mutation owner now reconciles only a successful execution with a payload-free failure whose diagnostic is exactly structured_output was not called. It preserves the existing atomic commit and authority checks. The result tool consumes the committed completion fact after awaiting persistence, so it cannot recreate the retired in-memory capture.

Thanks to @datrab for the report and production-boundary reproduction. The related merged fixes #146715 and #146716 handle CLI tool exposure and yielded collectors; #112989 and #157940 handle other persistence and retirement ordering. Open #164949 concerns cron result-consumption receipts. This fixes the late-result rejection in the current registry owner.

AI-assisted implementation and verification. Simplification kept the repair in two existing owners: production +47/-11 lines, regression tests +185, and a separate exact test-line allocation +2. No new store, schema, rollback mechanism, permission, or state writer is introduced.

Evidence

The committed public-tool regression fails on unchanged main 9a3bf9584db0d1f6be90e46d0224d228118fc3b6 with Failed to persist structured_output: collector run is unavailable (1 failed / 3 passed). It passes with the fix. Seven owner/consumer suites passed 393 tests across four canonical Vitest shards in 340.01 seconds. The final lint-only edits remove an unused initial assignment and add braces; the two directly affected suites were rerun afterward: all 28 tests passed in 98.27 seconds (the changed integration file has 12 cases; the schema-tool file has 16).

The main regression uses the production swarm tool group, collector authority checks, schema tool, actual SQLite writer, and native agents_wait. It verifies the frozen failure, late success, revoked writer/requester refusal, duplicate refusal, cache retirement, and repeated retained reads after clearing resident state. A separate worker-failure case verifies no publication before commit; a shared table retains execution errors, timeout, killed, other schema errors, existing payloads, and yielded-without-result failures. The main regression took 936 ms in the seven-suite run; hosted CI passed as linked below, without a separate per-test hosted timing claim.

Independent final autoreview --mode local --base 9a3bf9584db0d1f6be90e46d0224d228118fc3b6 --max-priority P3 reviewed the complete changed owners and tool assembly, collector freezer, native wait, mutation, generation, memory, and schema-tool consumers: scoped-clean, no actionable findings. The earlier authentication-failed attempt is not counted as a successful review. The reviewer inspected source; the commands below were executed separately.

Built Gateway, actual agent/tool execution, and SQLite capture

The same external recorder ran against separately built base 9a3bf9584db0d1f6be90e46d0224d228118fc3b6 and the exact production bytes of head c71502019fcd1fd488aadafb93002d47d2182778. Each run starts an isolated built Gateway and its normal OpenClaw agent with a loopback Responses provider. Authenticated chat.send starts the parent; the model invokes real sessions_spawn, structured_output, and three agents_wait calls. Deferred tools use the advertised dispatch_action and normal catalog authorization. The capture retains normalized provider call IDs and returned tool results.

The test plugin only controls the reported ordering: in the actual child's before_tool_call hook, it uses the public SDK emitAgentEvent to deliver a successful lifecycle observation before letting that same tool continue. The ordinary registry listener/freezer creates the missing-output result. The recorder waits for the SQLite row using a read-only connection, lets the parent collect the failure, then releases the pending real schema tool. The hook receives the actual run/session identity; its abort signal is false before and after execution. No registry/result writer, tool implementation, returned wait result, or authority check is replaced. This deterministic ordering does not measure how often a real scheduler produces the race.

Captured unchanged base (exit 0 means the expected bug was observed):

qaRuntime build: exit 0, 282.58s
built Gateway flow: exit 0, 204.36s
SQLite before: execution.outcome.status=ok
  collectorCompletion={"status":"failed","schemaError":"structured_output was not called"}
native agents_wait before: failed / structured_output was not called
real structured_output: Failed to persist structured_output: collector run is unavailable
native agents_wait after: failed / structured_output was not called
native agents_wait repeat: failed / structured_output was not called
SQLite after: same missing-output failure, structuredOutput=null

Captured current head with the unchanged recorder:

qaRuntime build: exit 0, 226.57s
built Gateway flow: exit 0, 193.27s
SQLite before: execution.outcome.status=ok
  collectorCompletion={"status":"failed","schemaError":"structured_output was not called"}
native agents_wait before: failed / structured_output was not called
real structured_output: {"status":"recorded"}; abortSignal=false
SQLite after: collectorCompletion={"status":"done","structured":{"answer":42}}
  structuredOutput=null
native agents_wait after: done / {"answer":42}, no schemaError
native agents_wait repeat: done / {"answer":42}, no schemaError
parent agent.wait: ok
child terminalReceipt.successfulToolNames: ["structured_output"]
recorder assertions: passed

Actual commands, from the isolated checkout:

node --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime
node --import ./scripts/tsx.mjs \
  ../../work/openclaw-pr-monitor-round-20261029/providers/collector-gateway-proof.mts \
  "$PWD" <capture-directory> <base-or-head>

The recorder SHA-256 is e8df4eed3da3fdd640bfcff76571a5db4e084ba7b4df8e0494c3367a63be72a0. Capture directory/phase change only evidence output and assertions. Both builds and both complete flow captures exited 0. Earlier recorder setup attempts and the ENOSPC interruption are excluded from the verdict.

The earlier separate source-runtime capture additionally clears resident registry/read caches, proves two retained reads, confirms the process-local structured-output cache is absent after publication, and rejects revoked/duplicate writes. Those assertions support the full Gateway evidence above; they are not described as Gateway execution.

Limits: the Responses provider is a deterministic loopback fixture; no external account or live-model service result is claimed. The successful lifecycle observation is deliberately ordered by the test plugin. This does not claim natural race frequency, release-upgrade behavior, or a process-restart test. No state layout or stored schema changes.

Validation commands

Node 24, pnpm 12, task-owned checkout and physical dependencies:

OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs \
  src/agents/subagents/registry/subagent-registry-public-api.read.test.ts \
  src/agents/tools/structured-output-tool.test.ts \
  src/agents/subagents/registry/subagent-registry.test.ts \
  src/agents/subagents/registry/subagent-registry-lifecycle.test.ts \
  src/agents/tools/agents-wait-tool.test.ts \
  src/gateway/tool-resolution.swarm-collector.test.ts \
  src/agents/subagents/registry/subagent-registry-worker.test.ts --maxWorkers=1
# 393 passed; 7 files; 4 shards; 340.01 seconds

node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental \
  --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.agents-sessions.json --incremental
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.agents-tools.json --incremental
# all exit 0

Targeted canonical lint and format cover the two production files and changed test file. The line-cap/max-lines, test-mock-export, assertion-safety ratchets and git diff --cached --check pass. The separate 185-line allocation covers the meaningful regression growth; shared ceilings and check rules are unchanged.

The Ready-triggered hosted CI run completed successfully, and the current-head hosted review accepts the scoped Gateway proof with no actionable findings. The Gateway evidence update changes no product or test code.

@clawsweeper

clawsweeper Bot commented Oct 29, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T08:25:51.924557Z
We couldn’t complete this review. Comment @codex review to try again.
c715020 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Oct 29, 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Allow authorized late structured output to repair a collector’s frozen missing-output failure after successful execution.

Example: A successful collector submits schema-valid {"answer":42} after its missing-output failure is frozen.

  • Before: The submission is rejected, and repeated agents_wait calls return failed.
  • After: The result commits as done, and subsequent waits return {"answer":42} without schemaError.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, correct repair with supplied Gateway proof and meaningful regression boundaries; the deterministic provider and injected lifecycle ordering keep the evidence scoped.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Supplied built-Gateway base/head logs exercise normal agent dispatch, sessions_spawn, the real schema tool, SQLite publication, and repeated native waits returning answer 42 after repair. A deterministic loopback Responses provider and public lifecycle hook force the ordering; external-provider inference, natural race frequency, and restart behavior are not claimed. Supporting production-path evidence covers revoked writes and retained reads after resident state is cleared, resolving the previous review’s Gateway-flow gap.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Successful collector work remains permanently failed in later waits when its valid structured result arrives after missing-output completion freezes.
Reason: The change resolves a demonstrated contradiction in collector state while preserving the existing failure, authorization, and persistence contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused repair for a current collector bug, with no actionable correctness findings.

Priority: P2
Reviewed head: c71502019fcd1fd488aadafb93002d47d2182778

Before merge

None.

Findings

None.

Agent review details

How this fits together

Collector agents submit validated results through the registry’s existing mutation owner, which persists completion facts consumed by agents_wait.

flowchart LR
 A[Collector agent] --> B[Schema tool]
 B --> C[Current run authority]
 C --> D[Registry mutation owner]
 E[Lifecycle freezer] --> D
 D --> F[SQLite collector result]
 F --> G[Native agents wait]
Loading

Technical review

Best possible solution:

Keep the narrow reconciliation in the existing atomic registry owner and retire the local capture only after its committed completion is returned.

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

Current main deterministically rejects the reported frozen-completion state, supported by datrab’s boundary trace and the supplied built-Gateway base comparison; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs the authoritative completion through the existing mutation owner, preserves genuine failures and current authority, and avoids adding a competing state writer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Frozen collector completion rejection changes intended behavior with a stated reason (4cd327e: The behavior-neutral public-API extraction carried the existing terminal-completion rejection; the later ordered-writer repair retained it while centralizing persistence.)
  • Structured-output capture publication keeps the original intent (3f761a8: The ordered registry repair publishes local capture only after persistence succeeds; the new committed-completion result preserves that ordering without restoring a retired capture.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +36, Tests +185, Other +2. Total +223 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 47 11 +36
Tests 1 185 0 +185
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 234 11 +223

Review metrics

Metric Value Why it matters
Production versus regression growth Production +47/-11 lines; tests +185 lines Growth stays in two existing production owners; regression coverage protects persistence, authority, retained reads, and genuine failure boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded collector-ordering defect persistently reports successful delegated work as failed.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-29T07:25:47.670Z sha c715020 :: needs real behavior proof before merge. :: none

Reviewed October 29, 2026, 4:37 AM ET / 08:37 UTC (Revision 2).

@wyf027
wyf027 marked this pull request as draft October 29, 2026 07:48
@wyf027
wyf027 marked this pull request as ready for review October 29, 2026 08:22

wyf027 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR body now includes the required actual built Gateway/agent/model comparison for unchanged head c71502019fcd1fd488aadafb93002d47d2182778. The same loopback recorder drives native sessions_spawn, the authorized structured_output, and three agents_wait calls. On base, the late result is rejected and later waits retain the missing-output failure. On this head it commits to SQLite as done with {"answer":42}, both later waits return that result without schemaError, and the child's terminal receipt records successful structured_output. The test plugin only orders a lifecycle observation via the public SDK; the body states that limitation and records both builds and complete flow results. No product/test code changed in this evidence update.

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026

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

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

Swarm collector can freeze missing structured output before a valid terminal tool call is recorded

1 participant