Skip to content

refactor(error-contracts): migrate browser_tools.rs to ToolError (#3576 slice)#6218

Merged
houko merged 4 commits into
mainfrom
refactor/3576-browser-tools-toolerror
Jun 19, 2026
Merged

refactor(error-contracts): migrate browser_tools.rs to ToolError (#3576 slice)#6218
houko merged 4 commits into
mainfrom
refactor/3576-browser-tools-toolerror

Conversation

@houko

@houko houko commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

One slice of the #3576 error-contracts migration: browser_tools.rs from Result<String, String> to Result<String, ToolError>. Mirrors the merged web_search slice (#6107) — same crate, same dispatch pattern.

Changes

  • crates/librefang-runtime/src/browser_tools.rs — the ten tool_browser_* dispatchers now return ToolError:
    • missing params → ToolError::MissingParameter("url" | "selector" | "text" | "expression")
    • SSRF-blocked URL (check_ssrf) → ToolError::InvalidParameter { name: "url", reason }
    • CDP transport (send_command) + command-failure responses → ToolError::upstream_msg(...)
    • Import switched to the re-exported crate::tool_runner::ToolError (same path web_search.rs uses).
  • crates/librefang-runtime/src/tool_runner/dispatch.rs — the ten browser arms drop their per-arm .map_err(ToolError::upstream_msg), so the typed variants flow through tool_result_from_typed. The None (browser-not-wired) arm still yields ToolError::Unavailable("Browser tools").

browser_tools has no other callers in the crate, and no unit tests (the dispatchers need a live CDP browser — unchanged from before).

This keeps #3576 as the umbrella tracker (hence Refs #3576, not Closes). Remaining slices per the migration roadmap: terminal_tmux.rs (anyhow), the channels bridge (needs the ChannelError-vs-ToolError decision first), librefang-cli, and the clippy::disallowed_types enforcement.

Verification

⚠️ Not built locally (no working local toolchain — disk/Docker unavailable). Statically reviewed against the ToolError API (MissingParameter(&'static str), InvalidParameter { name, reason }, upstream_msg(impl Into<String>)) and the proven web_search template; the import path was corrected to the re-exported crate::tool_runner::ToolError. CI is the verifiercargo check --workspace --lib, cargo test -p librefang-runtime, cargo clippy --workspace --all-targets -- -D warnings.

… slice)

Another slice of the structured-error-contracts migration. The ten tool_browser_* dispatchers (navigate / click / type / screenshot / read_page / close / scroll / wait / run_js / back) now return Result<String, ToolError> instead of Result<String, String>: missing params map to MissingParameter, an SSRF-blocked URL to InvalidParameter, and CDP transport / command failures to Upstream via upstream_msg.
The dispatch boundary drops its per-arm .map_err(ToolError::upstream_msg) so the typed variants flow through tool_result_from_typed; the None (browser-not-wired) arm still yields Unavailable. Mirrors the merged web_search slice.

Refs #3576
@github-actions github-actions Bot added size/M 50-249 lines changed area/docs Documentation and guides area/runtime Agent loop, LLM drivers, WASM sandbox labels Jun 18, 2026
Evan added 2 commits June 18, 2026 18:07
The Screenshot and run_js error arms were hand-written single-line but
exceed rustfmt's chain-width threshold at this indentation, so
cargo fmt --check failed in CI. Apply rustfmt's canonical output.
…ustfmt

CI's cargo xtask fmt wants each browser_tools dispatch call and its
trailing .await on one line; the prior commit only formatted
browser_tools.rs. Apply the same to the 10 dispatch arms.
@github-actions github-actions Bot added the has-conflicts PR has merge conflicts that need resolution label Jun 18, 2026
# Conflicts:
#	.secrets.baseline
@houko
houko enabled auto-merge (squash) June 19, 2026 04:51
@houko
houko merged commit ceca24f into main Jun 19, 2026
31 checks passed
@houko
houko deleted the refactor/3576-browser-tools-toolerror branch June 19, 2026 05:45
@github-actions github-actions Bot added ready-for-review PR is ready for maintainer review and removed has-conflicts PR has merge conflicts that need resolution labels Jun 19, 2026
GQAdonis pushed a commit to GQAdonis/librefang that referenced this pull request Jun 19, 2026
Merge upstream/main into the BossFang fork; origin/main was 15 commits behind.

Notable upstream changes:
- librefang#6225 scope the compaction-summary banner to the compacted session (adds canonical_sessions.compacted_summary_session_id).
- librefang#6196 deny WASM fs_write to the audit anchor via a capability deny-list.
- librefang#6226 / librefang#6227 add agent label and exit-reason metrics to the agent loop.
- librefang#6215 context-window usage indicator + honest quota-error classification.
- librefang#6217 per-instance sidecar secrets so each agent owns its own handle.
- librefang#6194 global Auto-Dream on/off switch on the Memory tab.
- librefang#6211 / librefang#6214 / librefang#6212 token/context cap fixes; librefang#6208 refuse to delete the active prompt version.
- librefang#6218 browser_tools.rs ToolError migration; librefang#6203 launchctl let-binding build fix; librefang#6224 docs dep bumps; librefang#6193 drop five orphaned email deps.

Conflict resolution:
- deny.toml: keep our RUSTSEC-2025-0141 (bincode 2.0.x) ignore entry (take ours).
- deny.toml: ignore three pre-existing unmaintained advisories newly tripped by the RustSec DB (all transitive via the UAR provider chain, none introduced by this merge): RUSTSEC-2024-0384 (instant), RUSTSEC-2024-0436 (paste), RUSTSEC-2025-0119 (number_prefix).

BossFang preservation (SurrealDB schema parity for upstream SQLite v46 / librefang#6225):
- Add crates/librefang-storage/src/migrations/sql/032_canonical_sessions_compacted_summary_session_id.surql declaring the new field on the SCHEMAFULL canonical_sessions table (SCHEMAFULL silently drops undefined fields on write), registered as version 32 in migrations/mod.rs.
- migrate/sqlite_to_surreal.rs: copy the new column so a SQLite to SurrealDB migration preserves the owning-session pointer rather than dropping it.
- backends/surreal_session.rs: preserve compacted_summary_session_id across canonical appends, since the upsert replaces the whole record.
- Cargo.lock: pick up the workspace version bump (beta.19 to beta.20) the merge introduced.

Verification:
- cargo check --workspace --lib — clean.
- cargo check -p librefang-storage -p librefang-memory -p librefang-uar-spec — clean.
- cargo test -p librefang-storage migration — ok (migration ordering / SurrealDB-3 flexible-syntax invariants).
- cargo test -p librefang-memory --lib session — 50 passed (incl. upstream's store_llm_summary round-trip test).
- cargo clippy -p librefang-storage -p librefang-memory — clean.
- python3 scripts/enforce-branding.py --check — clean; Tauri desktop audit and URL-drift scan both clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation and guides area/runtime Agent loop, LLM drivers, WASM sandbox ready-for-review PR is ready for maintainer review size/M 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant