Skip to content

refactor(types): remove chained type assertions in core and ui - #124073

Merged
steipete merged 3 commits into
mainfrom
steipete/chained-assert-w3
Aug 15, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/chained-assert-w3

Conversation

@steipete

@steipete steipete commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Production code in the assigned core, package, Plugin SDK, session, command, and Control UI surfaces contained chained type assertions that discarded type evidence. This removes the sites that can be repaired without changing runtime behavior or exported contracts, while preserving an exact ledger of provider/native/test-contract bridges for the later rule-enablement PR.

Why This Change Was Made

The fixes follow the established no-widen-then-assert idioms: boundary guards and reconstruction for untrusted records, typed adapters for agent-core runtime dependencies, satisfies for constructed values, direct Reflect operations for dynamic keys, and precise owner-state types where the existing contract already carried the evidence.

Attempts to tighten the remaining UI and test-helper host types were reverted after the full test-type graph proved that those surfaces intentionally accept partial fixtures. Public Plugin SDK generic shapes were also left unchanged.

User Impact

No runtime behavior or public API shape changes. This is a type-safety refactor that makes future chained-assertion lint enablement possible.

Evidence

  • Anti-slop scan: 123 initial findings; 50 fixed; 73 retained exactly as listed below.
  • Focused Vitest: 7 shards, 39 files, 627 tests passed; the CI-found cron identity regression was then reproduced and fixed with all 64 tests in src/commands/doctor/cron/index.test.ts passing; the ClawSweeper settings finding was repaired with 64 focused server-preferences tests passing.
  • node scripts/check-changed.mjs: passed. Crabbox had no ready ci-fast provider, so the wrapper fell back to its serialized local path and passed core/core-test/UI/plugin/plugin-test typechecks, all lint lanes, SDK budgets, dead-export scans, i18n verification, and database/runtime guards.
  • Autoreview: clean in pre-commit local mode and committed branch mode against origin/main; no accepted/actionable findings.
  • LOC: production +205/-163 (net +42); tests +0/-0.
  • ClawSweeper P2 resolved: reset patches now retain their keyof UiSettings/value relationship through a generic typed adapter; the Reflect-based write was removed.
  • Direct Codex dependency check: ../codex/codex-rs/codex-api/src/sse/responses.rs, ../codex/codex-rs/codex-api/src/endpoint/responses_websocket.rs, and ../codex/codex-rs/codex-api/src/endpoint/realtime_websocket/protocol_v2.rs confirm that SSE response.completed and realtime response.done are distinct typed protocol paths.

Intentional leftovers (23)

  • packages/ai/src/providers/anthropic.ts:416 — request-contract mutation crosses the Anthropic SDK record declaration.
  • packages/ai/src/providers/anthropic.ts:1095 — provider supports xhigh before the Anthropic SDK union does.
  • packages/ai/src/providers/anthropic.ts:1214 — provider compaction block intentionally precedes SDK support.
  • packages/ai/src/providers/openai-chatgpt-responses.ts:851 — Codex raw events are normalized into the OpenAI Responses event union.
  • packages/ai/src/providers/openai-chatgpt-responses.ts:981 — process-global WebSocket constructor bridge.
  • packages/ai/src/transports/openai-completions-stream.ts:344 — compatible providers expose choice-level usage outside the SDK type.
  • packages/ai/src/transports/openai-completions-stream.ts:363 — compatible providers expose message in place of the typed delta.
  • packages/ai/src/transports/openai-completions-transport.ts:177 — writable side of the event-stream contract is intentionally internal.
  • packages/ai/src/transports/openai-completions-transport.ts:259 — OpenAI-compatible payload extensions exceed the SDK request type.
  • packages/ai/src/transports/openai-responses-client.ts:244 — writable side of the event-stream contract is intentionally internal.
  • packages/ai/src/transports/openai-responses-params-internal.ts:228 — legacy response-format shape is normalized to the SDK shape.
  • packages/ai/src/transports/openai-responses-params-internal.ts:233 — provider response-format passthrough exceeds the SDK union.
  • packages/ai/src/transports/openai-responses-replay-internal.ts:187 — OpenAI SDK overload selection obscures the async stream type.
  • packages/ai/src/transports/openai-responses-websocket.ts:170 — documented OpenAI SDK client declaration mismatch.
  • packages/ai/src/transports/transport-stream-shared.ts:109 — internal writable event-stream adapter.
  • src/config/sessions/session-transcript-index.ts:170 — FTS5 numeric storage intentionally differs from generated string typing.
  • src/config/sessions/session-transcript-projection-rebuild.ts:422 — same FTS5 generated-type mismatch on rebuild.
  • src/test-utils/mock-http.ts:82 — Node DOM fetch and root Undici iterator declarations differ.
  • ui/src/app/native-bridge.ts:14 — WebView2 process-global bridge slot.
  • ui/src/app/native-link-routing.ts:37 — WebKit process-global message-handler slot.
  • ui/src/app/native-link-routing.ts:46 — WebKit update-handler slot.
  • ui/src/app/native-window-drag.ts:11 — WebKit native-window handler slot.
  • ui/src/components/terminal/terminal-runtime.ts:14 — Ghostty runtime exposes an optional private mouse-up hook absent from its public type.

Deferred leftovers (50)

  • src/commands/channel-test-registry.ts:38 — partial bundled-channel test registration; tightening breaks fixture contracts.
  • src/commands/doctor/cron/legacy-repair.ts:171 — preserving the original row identity is required by the migration-ID WeakMap.
  • src/commands/doctor/cron/legacy-repair.ts:194 — same identity contract for legacy rows merged with SQLite state.
  • src/commands/doctor/cron/legacy-repair.ts:288 — normalized raw jobs are not certified as CronJob by the owning API.
  • src/commands/doctor/cron/legacy-store-migration.ts:597 — doctor intentionally carries partially invalid legacy rows before quarantine.
  • src/commands/doctor/cron/warnings.ts:147 — read-only warning logic consumes structurally validated legacy jobs.
  • src/config/schema.hints.ts:226 — Zod pipe internals expose $ZodType, not the public ZodType.
  • src/config/schema.hints.ts:309 — same Zod pipe declaration mismatch in sensitive-path traversal.
  • src/config/sessions/store-entry-shape.ts:148 — canonical projection returns the broad legacy-normalized session shape.
  • src/plugin-sdk/channel-config-helpers.ts:352 — fixing the fallback generic would change an exported Plugin SDK signature.
  • src/plugin-sdk/channel-config-helpers.ts:501 — same public accessor-account generic contract.
  • src/plugin-sdk/channel-config-helpers.ts:588 — same public hybrid-account generic contract.
  • src/plugin-sdk/provider-stream-shared.ts:143 — public provider streams intentionally normalize unknown plugin events.
  • src/plugin-sdk/qa-runtime.ts:64 — private QA facade and public runner facade have distinct exported types.
  • src/test-utils/channel-plugins.ts:22 — partial channel fixture contract.
  • src/test-utils/mock-http-response.ts:29 — deliberately minimal ServerResponse test double.
  • src/test-utils/plugin-runtime-env.ts:29 — generic test runtime fixture supports narrower caller-owned shapes.
  • src/test-utils/plugin-setup-wizard.ts:165 — partial setup-wizard plugin fixture.
  • ui/src/components/app-sidebar-session-narration.ts:540 — protocol digest fixture would require a new runtime schema validator.
  • ui/src/pages/chat/chat-commands.ts:404
  • ui/src/pages/chat/chat-commands.ts:434
  • ui/src/pages/chat/chat-commands.ts:452
  • ui/src/pages/chat/chat-commands.ts:490
  • ui/src/pages/chat/chat-gateway.ts:352
  • ui/src/pages/chat/chat-gateway.ts:415
  • ui/src/pages/chat/chat-outbox-drain.ts:211
  • ui/src/pages/chat/chat-send-actions.ts:114
  • ui/src/pages/chat/chat-send-actions.ts:126
  • ui/src/pages/chat/chat-send-delivery.ts:285
  • ui/src/pages/chat/chat-send-delivery.ts:286
  • ui/src/pages/chat/chat-send-delivery.ts:288
  • ui/src/pages/chat/chat-send-delivery.ts:295
  • ui/src/pages/chat/chat-send-delivery.ts:305
  • ui/src/pages/chat/chat-send-delivery.ts:342
  • ui/src/pages/chat/chat-send-delivery.ts:403
  • ui/src/pages/chat/chat-send-delivery.ts:416
  • ui/src/pages/chat/chat-send-delivery.ts:548
  • ui/src/pages/chat/chat-send-delivery.ts:549
  • ui/src/pages/chat/chat-send-delivery.ts:661
  • ui/src/pages/chat/chat-send-delivery.ts:677
  • ui/src/pages/chat/chat-send-queue-state.ts:86
  • ui/src/pages/chat/chat-send-submit.ts:165
  • ui/src/pages/chat/chat-send-submit.ts:192
  • ui/src/pages/chat/chat-send-submit.ts:211
  • ui/src/pages/chat/chat-send-submit.ts:465
  • ui/src/pages/chat/chat-send-submit.ts:468
  • ui/src/pages/chat/chat-state-events.ts:486
  • ui/src/pages/chat/chat-state-page.ts:138
  • ui/src/pages/chat/steer-lifecycle.ts:511
  • ui/src/pages/chat/steer-lifecycle.ts:514

The UI sites above share one reason: the production page carries the full history/lifecycle/scroll/settings state, while exported helpers and colocated tests intentionally accept partial host fixtures. Tightening those signatures would be a separate contract migration and test rewrite, which this worker scope forbids.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@steipete steipete self-assigned this Aug 15, 2026
@steipete
steipete marked this pull request as ready for review August 15, 2026 06:59
@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 Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 4:21 AM ET / 08:21 UTC.

ClawSweeper review

What this changes

Replaces selected chained TypeScript assertions in core, AI transport, session, CLI, plugin SDK, and Control UI code with guards, typed adapters, and narrower constructions.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for explicit maintainer handling: the prior typed-settings blocker is fixed at the current head, and this review found no new concrete correctness or security defect.

Priority: P3
Reviewed head: 66225822f6979bb52947e0b873ce516d5d69d271
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The prior blocker is fixed and the inspected owner boundaries remain coherent; current-main integration is the remaining merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored behavior-neutral refactor is supported by inspected focused coverage and exact-head CI remains the merge validation gate.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored behavior-neutral refactor is supported by inspected focused coverage and exact-head CI remains the merge validation gate.
Evidence reviewed 6 items Prior finding resolved: The current head uses a generic key/value-preserving helper for reset patches, then invokes it only from the clearable reset path; this removes the prior widened Object.entries/Reflect write.
Settings owner and coverage: Settings apply a Partial<UiSettings> through the single persistence seam, while existing tests cover server-side preference removal and restoration of default values.
Cron migration identity retained: The migration continues to carry and mutate the original config-row records whose identity is tracked for legacy reconciliation.
Findings None None.
Security None None.

How this fits together

This change affects type boundaries where provider events, persisted session data, CLI output, plugin adapters, and Control UI settings enter OpenClaw. Those normalized values then drive agent execution, migration, operator output, and UI state updates.

flowchart LR
A[Provider, storage, and UI inputs] --> B[Typed guards and adapters]
B --> C[Agent and transport runtime]
B --> D[Session and cron migration]
B --> E[Control UI settings]
C --> F[Model and tool execution]
D --> G[Operator commands]
E --> G
Loading

Decision needed

Question Recommendation
After rebasing and exact-head validation, should this maintainer-authored cross-cutting type-boundary refactor land as scoped, rather than expanding into the intentionally retained assertion sites? Land the scoped refactor: Accept the current boundary-preserving scope once the rebased head has green required checks.

Why: The protected maintainer label and broad compatibility-sensitive surface require a human decision on acceptable scope after current-main integration.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main, and this partial clone could not hydrate the current-main tree after its promisor remote failed DNS resolution; rebase and exact-head validation are still needed before merge.
  • Resolve merge risk (P1) - The changed AI paths depend on Anthropic and OpenAI SDK declarations, but direct declaration inspection was unavailable in this read-only environment; retain the dependency typecheck gate before landing.
Agent review details

Security

None.

PR surface

Source +42. Total +42 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 29 205 163 +42
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 29 205 163 +42

Review metrics

Metric Value Why it matters
Production vs test LOC production +42 net, tests +0 net The added code implements explicit boundary validation and typed reconstruction rather than altering product capability.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-sqlite-readers.ts, migration/backfill/repair: src/commands/doctor/cron/legacy-store-migration.ts, serialized state: src/config/sessions/session-accessor.entry-mutation.ts, serialized state: src/config/sessions/transcript.ts, unknown-data-model-change: src/commands/doctor-session-sqlite-readers.ts, unknown-data-model-change: src/commands/doctor-session-state-providers.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase and validate the exact head (recommended)
    Rebase onto current main and require the relevant type, migration, and UI checks to pass on that resulting head before merge.
  2. Pause for a narrower refactor
    Split the branch if integration identifies a compatibility-sensitive boundary that cannot be demonstrated behavior-neutral.

Technical review

Best possible solution:

Rebase onto current main, retain the resolved typed settings and migration boundaries, and land only after exact-head checks confirm the cross-cutting refactor remains behavior-neutral.

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

Not applicable: this PR is a type-safety refactor, not a report of broken user-visible behavior; its relevant existing tests were inspected but not run under the read-only review contract.

Is this the best way to solve the issue?

Yes: the current head fixes the earlier settings-boundary concern by preserving the UiSettings key/value relation, while the other edits validate or reconstruct data at their existing owners rather than adding parallel behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f1ced37ce5df.

Labels

Label justifications:

  • P3: This is a behavior-neutral type-safety cleanup with no reported user-facing regression.
  • merge-risk: 🚨 compatibility: The branch changes type handling at persisted-session, cron migration, provider-stream, plugin SDK, and UI-settings boundaries.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored behavior-neutral refactor is supported by inspected focused coverage and exact-head CI remains the merge validation gate.

Evidence

What I checked:

Likely related people:

  • steipete: Authored all three commits in this refactor and available blame/history also connects this contributor to the affected cron and session paths. (role: recent area contributor; confidence: high; commits: acb3f6dc7ba1, 359531052438, 66225822f697; files: ui/src/app/server-prefs-state.ts, src/commands/doctor/cron/legacy-store-migration.ts, packages/agent-core/src/agent-loop.ts)
  • Vincent Koc: History for the legacy transcript-import path identifies this contributor as an earlier owner; the present patch preserves that import boundary. (role: original transcript-import contributor; confidence: medium; files: src/commands/doctor-session-sqlite-readers.ts)

Rank-up moves

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

  • Rebase onto current main and confirm required checks are green on the resulting exact head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-15T07:05:13.037Z sha a0348d3673acabe6debffaca74e14c3581c342c2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T07:48:01.989Z sha 3595310 :: needs changes before merge. :: [P2] Preserve the typed reset-patch relation

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@steipete
steipete force-pushed the steipete/chained-assert-w3 branch from 2d38bc2 to 3595310 Compare August 15, 2026 07:38
@clawsweeper clawsweeper Bot added 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@steipete
steipete merged commit aaa509b into main Aug 15, 2026
207 checks passed
@steipete
steipete deleted the steipete/chained-assert-w3 branch August 15, 2026 08:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…law#124073)

* refactor(types): remove chained assertions in core and ui

* fix(types): preserve legacy cron migration identity

* fix(types): preserve settings patch key types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui cli CLI command changes commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

1 participant