Skip to content

fix(ai): preserve OpenAI types in packed declarations - #195098

Merged
steipete merged 1 commit into
mainfrom
fix/ai-packed-declaration-aliases
Nov 8, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/ai-packed-declaration-aliases

Conversation

@steipete

@steipete steipete commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

TypeScript consumers of packed @openclaw/ai fail with TS2456 when checking declarations with skipLibCheck: false.

User Impact

All public package entries can be imported and typechecked again. Runtime provider bundling and dependency versions are unchanged.

Why This Change Was Made

Bundling OpenAI 7.47.0 declarations collapses self-module namespace references into 41 self-referential aliases, such as type ChatCompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming.

Keep openai and its subpaths external only in the AI declaration bundle. The package already declares openai as a production dependency, so consumers resolve the upstream declarations without changing the bundled runtime.

Evidence

Clean main 837f871caf188401ec38bf86028c45ec71c2cddd reproduces the TS2456 failure on Node 24.22.1 and the verified pinned Bun fork (1.4.4-canary.1+191755ec1). The generated failing chunk is client-Cg-WLGuq.d.mts, matching the failure in run 42454905825. The declaration inputs and dependencies are identical between that PR head and the tested main.

With this fix:

  • packages/ai/src/package.e2e.test.ts passes on Node and the pinned Bun fork, importing and typechecking all 19 public exports with skipLibCheck: false.
  • The packed tarball contains all 19 public declarations, 46 declaration files, and zero direct self-aliases; OpenAI types resolve through the declared dependency.
  • test/scripts/tsdown-ai-package.test.ts passes, including the assertion that the OpenAI runtime remains bundled.
  • packages/sdk/src/app-sdk-external-boundary.e2e.test.ts passes through the shared declaration machinery and packed external-consumer boundary.
  • Targeted lint, formatting, and git diff --check pass.

Independent Codex autoreview of the local change against 837f871caf188401ec38bf86028c45ec71c2cddd completed scoped-clean through P2 with no findings. This is a declaration-only fix: two files, four added lines; no runtime fallback or dependency change.

Keep OpenAI declaration imports external while retaining bundled runtime clients. The declared production dependency supplies the original namespace types, avoiding self-referential aliases after declaration bundling.

Verified the packed consumer fails with TS2456 on clean main on Node and the pinned Bun fork, then passes on both with this fix. All 19 exports, the SDK packed consumer, and bundled-runtime checks pass.
@clawsweeper

clawsweeper Bot commented Nov 8, 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.

@steipete
steipete marked this pull request as ready for review November 8, 2026 07:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T07:43:03.243503Z 1fb2f18 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro 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: 👀 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-repro Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR keeps OpenAI declarations external to the AI declaration bundle and documents their dependency resolution.

Example: A TypeScript application imports packed @openclaw/ai with skipLibCheck: false.

  • Before: The reported generated declarations contain circular aliases and fail with TS2456.
  • After: Declarations reference the existing [email protected] dependency while runtime clients remain bundled.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and supported by the pinned bundler contract; validation evidence consists of reported packed-consumer test results.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored PR is outside the ordinary contributor proof gate; its body reports Node and pinned-Bun packed-consumer passes, while the inspected tests exercise installed exports and strict declaration checking.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Strict TypeScript consumers cannot typecheck the packed AI package because generated OpenAI aliases refer to themselves.
Reason: Restores the existing package-consumer contract with a narrow build correction; maintainer-authored direction is already established.

Regression provenance

Regression provenance — verified: source commit 0b4fc062a553 by Karen; canonical PR #192217 (blame-to-merge-commit).

Merge readiness

✅ Ready for maintainer review

Keep this PR: it makes a focused repair to packed TypeScript declarations while preserving intentional runtime bundling; no actionable patch defects were found.

Priority: P2
Reviewed head: 1fb2f18cc0aad719b73700a986d91e5ee2c8e85d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Validation is reported through existing packed-consumer and runtime-boundary tests; no separately inspectable after-fix consumer output is supplied.
Agent review details

How this fits together

The AI package build turns provider source into runtime bundles and public declarations; external TypeScript consumers resolve those declarations through the package export map.

flowchart LR
  A[AI provider source] --> B[tsdown build]
  B --> C[Bundled runtime clients]
  B --> D[Public declarations]
  D --> E[OpenAI dependency types]
  D --> F[TypeScript consumer]
  E --> F
Loading

Technical review

Best possible solution:

Keep the declaration-only externalization in the existing build owner while retaining bundled runtime clients and the declared OpenAI dependency.

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

The body reports clean-main TS2456 reproduction on Node and the pinned Bun fork, and source confirms the relevant bundling path; no target code was executed and the linked failure log was inaccessible.

Is this the best way to solve the issue?

The existing bundler provides the exact declaration-only control needed, and the production dependency already supplies upstream types, making this the smallest complete repair.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Focused declaration repair: The verified introduced diff adds only a declaration-specific OpenAI externalization rule and its README explanation; runtime alwaysBundle rules remain intact. (tsdown.ai.config.ts:69, 1fb2f18cc0aa)
  • Existing dependency and consumer contract: The package already declares [email protected] as a production dependency; the existing packed-consumer test installs the tarball externally and typechecks its exports with skipLibCheck disabled. (packages/ai/src/package.e2e.test.ts:176, 1fb2f18cc0aa)
  • Original bundling intent preserved: improve: reduce Gateway startup module-file overhead #192217 intentionally bundled OpenAI and ws to reduce startup module loading; its source change explains the runtime rule this PR retains. (tsdown.ai.config.ts:69, 0b4fc062a553)
  • Pinned bundler contract: OpenClaw pins tsdown 0.23.4, making its declaration-externalization contract directly relevant; upstream selects deps.dts.neverBundle for declaration importers and includes a snapshot proving declaration externalization can retain bundled runtime output. (src/features/rolldown.ts:217, 83b6fb5a5ecd)
  • Current main still needs the change: Fetched main retains runtime OpenAI bundling without the declaration-specific externalization rule. (tsdown.ai.config.ts:67, 001e82fcf99b)
  • Required scan failures are infrastructure failures: The precise-path scan and all six Security High jobs have annotations reporting GitHub installation API rate limits; these establish an external infrastructure cause rather than a diff-caused defect. (1fb2f18cc0aa)

PR surface

Docs +2, Other +2. Total +4 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 2 4 0 +4

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.

Root-cause cluster

Relationship: canonical
Canonical: #195098
Summary: This PR owns the declaration repair that blocks two otherwise distinct retention-test changes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: Repairs strict TypeScript consumption of the packed AI package without changing runtime behavior.
  • 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:

  • P2: Repairs strict TypeScript consumption of the packed AI package without changing runtime behavior.
  • 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 November 8, 2026, 2:57 AM ET / 07:57 UTC.

@steipete
steipete enabled auto-merge (squash) November 8, 2026 07:59
@steipete
steipete merged commit 8c5d74a into main Nov 8, 2026
153 of 164 checks passed
@steipete
steipete deleted the fix/ai-packed-declaration-aliases branch November 8, 2026 08:04
@steipete

steipete commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 9, 2026
Keep OpenAI declaration imports external while retaining bundled runtime clients. The declared production dependency supplies the original namespace types, avoiding self-referential aliases after declaration bundling.

Verified the packed consumer fails with TS2456 on clean main on Node and the pinned Bun fork, then passes on both with this fix. All 19 exports, the SDK packed consumer, and bundled-runtime checks pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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