Skip to content

improve(ai): avoid model runtime imports for API key lookups - #167448

Open
RomneyDa wants to merge 3 commits into
mainfrom
fix/ai-env-key-cold-import
Open

RomneyDa wants to merge 3 commits into
mainfrom
fix/ai-env-key-cold-import

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Current repair and validation (2026-11-25)

Rebased onto current main ba6d94ec1771, preserving its Google build entries and the current auth-storage.core.ts owner. Added the narrow entry to the existing core-only native resolver and the strict bundled-package validator, including its existing missing-entry fixture matrix. No dependency or credential policy change.

Validation on this repair:

  • Qualified full pnpm build: passed (5m17s).
  • Native resolver owner: 8/8 tests passed; the missing alias regression failed before the repair.
  • Package tarball validator owner: 87/87 passed under the normal package mode umask 022; the new missing-entry case failed before the validator correction. A first run under inherited umask 077 exposed an unrelated existing permission-mode assertion; no expectation was changed.
  • Built and packed @openclaw/ai, extracted it into an isolated package installation, then resolved the new export and exercised the existing environment-key lookup with a synthetic key: passed.
  • Qualified touched-owner type-aware lint, formatting and diff checks passed. Fresh local ClawSweeper review found no correctness findings.

No new startup/memory benchmark or full Docker tarball run is claimed. Hosted CI on the published head remains required; non-draft does not mean merge-ready.


What Problem This Solves

API-key lookups during startup and model scanning load the full model runtime even though they only need environment-key resolution.

User Impact

These lookups avoid unnecessary runtime imports. Credential resolution and provider behavior are unchanged; no migration or configuration change is needed.

Why This Change Was Made

Expose the existing environment-key owner through a narrow internal package entry point and migrate the three environment-only callers. Keep the full runtime exports for their existing consumers.

Evidence

  • 87 focused tests passed across seven files on the main forward-port.
  • Fresh complete P0–P2 review found no actionable issues.
  • Full build passed (6m27s); focused type-aware lint passed. The complete changed gate passed its typechecks and guards but failed on the pre-existing, unchanged ClientVoiceToolEffect export in Talk; this PR does not change that owner.
  • The release-branch companion passed 102 affected tests and its full build. Native 80-plugin health/status replay passed, but Gateway RSS did not improve; this PR does not claim to resolve that budget failure.

Draft forward-port of the authorized 2026.10.1 release repair. Do not merge as part of this release task.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: XS labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

The branch exposes the existing environment API-key resolver through a lightweight internal package entry and switches three application callers to it.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, narrow optimization with supplemental validation, but the native source-loading repair remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) This MEMBER-authored refactor is exempt from the external-contributor proof gate. Reported focused tests and build support validation, but companion health/status replay does not establish this head's source-only resolution or import-cost improvement; no stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes
User problem: Startup credential checks unnecessarily load model-runtime machinery.
Reason: The change reduces unnecessary import coupling with minimal production growth and preserves the existing credential owner, outputs, and defaults.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR remains useful and distinct from current main, but the previously reported native source-resolution defect is still present. Maintainer-authored work also requires explicit maintainer judgment before closure.

Priority: P2
Reviewed head: 5d7d51078881c43d606b99b9a97ae6fc573cdd2f

Before merge

  • Register the new entry in the native source alias table (P2) - When native loading reaches this module in a source layout without generated packages/ai/dist outputs, the new import has no entry in INTERNAL_CORE_PACKAGE_ALIASES. It falls through to the package export targeting dist/internal/env-api-keys.mjs and fails, whereas the previous runtime import has a source alias. TypeScript paths do not repair native resolution, and a full build masks the omission. Add the entry to src/plugins/plugin-sdk-native-resolver.ts and extend the existing host-parent resolution case. This prior finding remains unchanged at the reviewed head.

Findings

  • [P2] Register the new entry in the native source alias table — src/agents/sessions/auth-storage.ts:11

Tests

  • Missing end-to-end proof: No source-only native load of the migrated callers or matched cold-import comparison is recorded for this head; the reported full build can hide the missing alias.
Agent review details

How this fits together

Startup authentication and model scanning obtain provider credentials from environment variables. The changed import route reaches the existing credential resolver without importing its broader model-runtime barrel.

flowchart TD
  A[Startup authentication] --> C[Lightweight credential entry]
  B[Model scanning] --> C
  C --> D[Existing environment resolver]
  E[Environment variables] --> D
  D --> F[Provider credential or no credential]
  G[Native source loader] --> C
Loading

Technical review

Best possible solution:

Keep one shared lightweight credential resolver and make source and packaged loading resolve it consistently while preserving credential behavior.

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

Not applicable to the performance refactor itself: source confirms the broad import route, but no matched startup benchmark was supplied. The introduced native-resolution failure is source-reproducible; this review did not execute target code.

Is this the best way to solve the issue?

Yes, exposing the existing resolver is a narrow approach that avoids duplicate credential logic; its native source alias must accompany the package and build wiring.

Full review comments:

  • [P2] Register the new entry in the native source alias table — src/agents/sessions/auth-storage.ts:11
    When native loading reaches this module in a source layout without generated packages/ai/dist outputs, the new import has no entry in INTERNAL_CORE_PACKAGE_ALIASES. It falls through to the package export targeting dist/internal/env-api-keys.mjs and fails, whereas the previous runtime import has a source alias. TypeScript paths do not repair native resolution, and a full build masks the omission. Add the entry to src/plugins/plugin-sdk-native-resolver.ts and extend the existing host-parent resolution case. This prior finding remains unchanged at the reviewed head.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/plugins/plugin-sdk-native-resolver.test.ts --maxWorkers=1.
  • [P1] pnpm test packages/ai/src/env-api-keys.test.ts --maxWorkers=1.
  • [P1] Verify native host-parent resolution without generated AI outputs in isolated state.
  • [P1] pnpm build.
  • [P1] pnpm check:changed.

What I checked:

PR surface

Source +1, Config +6, Other +1. Total +8 across 7 files. Added test files: 0.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded import-cost improvement with a focused source-loading regression.
  • merge-risk: 🚨 compatibility: The new imports fail in native source layouts without generated AI outputs because their source alias is missing.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T20:47:25.990Z sha 5d7d510 :: needs changes before merge. :: [P2] Register the new entry in the native source alias table

Reviewed October 8, 2026, 4:54 PM ET / 20:54 UTC (Revision 2).

@RomneyDa
RomneyDa marked this pull request as ready for review November 25, 2026 19:36
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@github-actions

github-actions Bot commented Nov 25, 2026 •

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: 21a8ce937fed3dc1a732c896c531ead0c898033f
  • Maintainer: @RomneyDa
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/sessions/auth-storage.core.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

Expose the existing environment-key owner through a narrow internal entrypoint and migrate all three env-only callers. Preserve runtime and auth behavior. Proof:87 focused tests, full build, focused type-aware lint and fresh P0-P2 review passed. Complete changed gate reports only inherited unchanged Talk ClientVoiceToolEffect dead export; typechecks and guards passed. Release companion native80-plugin replay does not establish Gateway RSS improvement.

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 commands Command implementations merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant