Skip to content

refactor(agents): reuse prepared tool facts - #174349

Merged
steipete merged 1 commit into
mainfrom
deslop/z04-4-tool-facts-20261015
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
deslop/z04-4-tool-facts-20261015

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Agent tool preparation repeats work already owned by config admission, result classification, or the generated MCP configuration producer.

User Impact

No intended user-visible change. Existing policy enforcement, hostile-input handling, image limits, archive protections, and CLI capture credentials remain. Concurrent automation-list edits are best effort: repeat the read if the current job moved between pages.

Why This Change Was Made

Carry the prepared Claude/Gemini MCP configuration into capture setup instead of rereading and reparsing a file we just generated. Classify tool results once and share the Cron action predicate. Trust admitted config and media metadata rather than repeat shape/scalar checks; remove the archive-extraction rethrow wrapper.

This is the tool-area slice of a wider agents cleanup, intentionally excluding prepared-plugin publication retirement and passive-owner changes while their first-signin regression is diagnosed. It also excludes the separate coordinator-owned W6c residue and the two previously landed harness changes.

Best-effort tradeoffs accepted

  • Generated MCP config edits between preparation and capture are not supported. The producer retains its prepared settings; malformed external Gemini settings still enter through the existing file parser. Capture keys still rotate per attempt and current environment overrides are retained.
  • Invalid fabricated typed tool policies/config no longer get a second repair in the consumers. Config schemas and modifying-hook normalization remain the input boundary; authorization and policy matchers remain. Tool Search schema admission is in zod-schema.agent-runtime.ts; its redundant consumer guards originated in refactor(agents): split Tool Search internals #113296.
  • Already decoded image metadata is trusted for numeric fields. Positive dimensions, byte/pixel limits, decoding, malformed blocks, and unavailable-backend behavior remain; the original scalar probes predate the typed media owner (6b2af6c1ee0).
  • Rewrapping an already classified image-backend error adds no protection; the owning sanitizer still handles unavailability. Archive traversal and resource limits remain in the canonical extractor; only the private wrapper from fix(tools-manager): replace spawnSync extraction with safe extractArchive API #98988 is removed.
  • A job moving behind the page cursor during a concurrent automation inventory edit can be absent from that one read. fix(cron): prevent jobs disappearing during paginated refreshes #121084's mixed-page test is synthetic, not a human production report; a subsequent read sees the new inventory. Canonical page validation, cursor checks, the 50-page bound, and current-job filtering remain.
  • Provider source config may validly omit model inputs/models. Optional access remains for those omissions; only redundant shape checks disappear (d92501dbf34, 30e1556cdac, and Web runtime refactor d73bc545064).

Evidence

Production: 23 files, +163/-344, 181 net lines removed. Five test files complete signature migrations and preserve outcome precedence; total diff is 28 files. This is an area split of the preserved 896-line candidate, not its wholesale resubmission.

  • tool-result-error.test.ts: 28/28 passed (81.87s suite on a heavily loaded shared host), including hostile objects and failure precedence.
  • test/scripts/lint-suppressions.test.ts: 3/3 passed (170.63s suite, 202.46s wrapper); no new suppressions.
  • Pinned formatter: all 28 files passed. git diff --check passed.
  • Fresh independent review against base 10ee984418456ab59d59c05990a9a5b247301015: scoped-clean through P2, no actionable findings; published status/report independently inspected.
  • Exact signed head 6537a2c1f7f25ac3d0f730141b6313d8f48c2794: CI run 38921562672 passed, including production/test types, lint, security-fast, selected runtime suites and openclaw/ci-gate. No rerun or green-seeking push. A cancelled advisory auto-response job is superseded by successful job 117042431408 on the same head; no test suite is waived.
  • Focused MCP proof was stopped during cold compiled-worker preparation before assertions; it is neither a test failure nor passing proof. No local broad build, whole-graph types, or cycle check is claimed under the host's proof budget. Exact-head PR CI owns those gates and the remaining focused suites.

The full parked candidate had a genuine exact-head first-signin assertion; this slice is not advertised as fixing or inheriting that failure. The requested local single-file candidate replay entered a broad runtime build and was stopped under the local-proof budget before assertions. A separate candidate replay never obtained a remote lease within the 20-minute budget and was stopped without a test result. No retries, skips, or timeout increases were added. Exact-head CI outcomes will be linked before landing.

@clawsweeper

clawsweeper Bot commented Oct 16, 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: L labels Oct 16, 2026
@steipete
steipete marked this pull request as ready for review October 16, 2026 15:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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 ✅ Completed 2026-10-16T15:12:47.710840Z 6537a2c 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.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 6537a2c1f7f25ac3d0f730141b6313d8f48c2794
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/agent-tools.policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/tool-policy-audit.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/tool-policy-declared-context.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/tool-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses prepared MCP settings and tool-result classifications while removing redundant consumer validation and pagination retries.

Example: A Claude CLI attempt receives capture key attempt-123.

  • Before: Capture setup rereads and parses the generated MCP configuration before inserting attempt-123.
  • After: The configuration producer inserts attempt-123 using its retained settings, preserving the bearer header.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is coherent and exact-head CI is green, with confidence bounded by harness-level evidence rather than a shipped CLI round trip.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored refactor is outside the ordinary proof gate; supplied evidence covers classifier tests and configuration harnesses, while the stopped MCP replay is correctly not presented as passing runtime proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Repeated internal preparation increases runtime work and maintenance complexity.
Reason: The maintainer has approved the direction and explicitly accepted the narrow behavior tradeoffs; inspection confirms a coherent reduction in duplicate work.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: the refactor has clear ownership and simplification value, its tradeoffs are explicitly accepted, and inspection found no actionable regression.

Priority: P3
Reviewed head: 6537a2c1f7f25ac3d0f730141b6313d8f48c2794

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Claude/Gemini capture round trip is supplied; this maintainer refactor is outside the ordinary contributor proof gate.
Agent review details

How this fits together

Agent tool preparation consumes admitted configuration, tool results, and generated MCP settings to produce tool policies, sanitized results, and CLI execution settings.

flowchart TD
  A[Admitted configuration] --> B[Tool preparation]
  B --> C[Policy and media consumers]
  B --> D[Prepared MCP settings]
  D --> E[Per attempt capture setup]
  E --> F[CLI backend]
  F --> G[Tool result classification]
  G --> C
Loading

Technical review

Best possible solution:

Retain the producer-owned preparation path and the explicitly accepted best-effort pagination behavior.

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

This refactor reports repeated internal work rather than a user-visible bug; source inspection confirms the duplicated reads and classifications.

Is this the best way to solve the issue?

Producer-owned settings and shared classification reduce repeated work without adding a competing owner; removed validation remains covered by existing admission contracts.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • MCP capture settings changes intended behavior with a stated reason (c2ee9b0: Preserve owner MCP tools and per-attempt CLI capture configuration; later adapter consolidation shared the header writer.)
  • Subagent policy keeps the original intent (aad014c: Harden subagent control boundaries; the refactor preserves role-dependent denies and visible-session message handling.)
  • Tool-result classification keeps the original intent (06c5bd6: Honor completed semantic command exits without treating every nonzero exit as a failure.)
  • Tool Search configuration changes intended behavior with a stated reason (050475b: Split Tool Search internals while preserving behavior; this PR explains relying on existing schema admission instead of repeating scalar validation.)
  • Automation self-list pagination changes intended behavior with a stated reason (efb02a0: Restart mixed snapshots so a moving job cannot produce a false empty self-list; the current owner explicitly accepts that recoverable outcome.)
  • Tool-image safety keeps the original intent (6b2af6c: Keep safe images usable without a native backend; dimension, byte, pixel, malformed-block, and decode handling remain.)
  • Archive extraction keeps the original intent (be48a43: Use canonical extraction with traversal protection, resource limits, and a timeout; only the rethrow wrapper is removed.)
  • Provider model metadata keeps the original intent (d92501d: Move PDF fallback policy into metadata; optional model and input omissions remain supported.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f2b1db3 adds src/agents/cli-runner/bundle-mcp.ts:440 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f2b1db3acbd0; files: src/agents/cli-runner/bundle-mcp.ts)
  • Vincent Koc: Raw commit 6b2af6c adds src/agents/tool-images.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6b2af6c1ee01; files: src/agents/tool-images.ts)
  • Ayaan Zaidi: Raw commit d4f6966 adds src/agents/cli-runner/bundle-mcp.ts:431 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: d4f6966dbf3b; files: src/agents/cli-runner/bundle-mcp.ts)

PR surface

Source -181, Tests -9. Total -190 across 28 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 23 163 344 -181
Tests 5 23 32 -9
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 28 186 376 -190

Review metrics

Metric Value Why it matters
Production versus test LOC Production +163/-344; tests +23/-32 Production shrinks by removing duplicate preparation and validation; test changes migrate callers and preserve outcome-precedence contracts.

Labels

Label changes:

  • add P3: This is an owner-directed internal simplification with no urgent user-facing defect.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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:

  • P3: This is an owner-directed internal simplification with no urgent user-facing defect.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 October 16, 2026, 11:27 AM ET / 15:27 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Coordinator-authorized Wave-6 rule-10 landing, exact head 6537a2c1f7f25ac3d0f730141b6313d8f48c2794.

The native workflow failed twice for tooling infrastructure reasons, without a merge submission:

Native operation Observed failure Recovery / outcome
review-checkout-pr Git worktree index.lock collision No process remained; the index lock was already absent. Supported exact-OID operation-lock recovery succeeded. Retried checkout completed at the exact reviewed head.
prepare-run with GitHub gates Metadata read failed after three attempts: string rewrite protection blocked unsafe input Failed before preparation/merge submission. No merge-outcome ref or retained operation lock exists. No raw-wrapper or trust-check bypass was used.

Native review artifacts were initialized and validated for this exact head with recommendation READY FOR /prepare-pr, zero findings. Fresh independent review was scoped-clean through P2. The complete change remains the reviewed 28-path tool-area slice, 181 net production lines removed.

Exact-head CI run 38921562672 succeeded, including production/test types, lint, selected runtime suites, security-fast and openclaw/ci-gate. The complete check-run census contains no failing or pending job. Cancelled advisory auto-response job 117042411751 has successful same-head replacement 117042431408; it is not a cancelled test suite. No CI rerun, green-seeking push, or branch update was performed.

Focused local proof and remaining gaps are in the PR body: result classification 28/28 and lint-suppressions 3/3 passed; MCP cold preparation stopped before assertions. The wide candidate's first-signin regression remains explicitly unresolved and is not claimed fixed or inherited by this slice. Phase E and coordinator-owned residue are excluded.

Per the coordinator's standing rule 10, use the direct squash endpoint with this exact head SHA as its precondition. This bypasses the failed native transport, not CI, security or review requirements. Verify the returned merge commit against origin/main ancestry before reporting landed.

@steipete
steipete merged commit 7a2f433 into main Oct 16, 2026
223 of 224 checks passed
@steipete
steipete deleted the deslop/z04-4-tool-facts-20261015 branch October 16, 2026 16:04
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '14e993fff3ecb84eb1d7c9724c4ceda235d797e4': (110 commits)
  fix(decisions): align accounting ratchet evidence
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '14e993fff3ecb84eb1d7c9724c4ceda235d797e4': (110 commits)
  fix(decisions): align accounting ratchet evidence
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '0c6c7ee5837ed93f6fb09ca58b280e76878c21f1': (109 commits)
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  refactor(feishu): reuse streaming merge in dispatcher tests (#174371)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '14e993fff3ecb84eb1d7c9724c4ceda235d797e4': (110 commits)
  fix(decisions): align accounting ratchet evidence
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '0c6c7ee5837ed93f6fb09ca58b280e76878c21f1': (109 commits)
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  refactor(feishu): reuse streaming merge in dispatcher tests (#174371)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: L 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