Skip to content

docs(localai): add module contract documentation to Local AI modules - #1896

Merged
larroy merged 6 commits into
openclaw:mainfrom
larroy:refactor-local-ai
Nov 5, 2026
Merged

larroy merged 6 commits into
openclaw:mainfrom
larroy:refactor-local-ai

Conversation

@larroy

@larroy larroy commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

The Local AI modules lack top-of-file documentation blocks, so contributors must reverse-engineer each module's contract, ownership, and usage from its implementation. The new AGENTS.md coding rule requires such blocks for new modules; the existing key Local AI modules did not have them yet.

User Impact

User impact: no user-visible change; developers reading or changing the Local AI modules get a module contract header with invariants and usage examples of the main public methods.

Why This Change Was Made

Adds module header documentation to four Local AI modules (LocalAiNativeBindingStore, LocalAiGatewayConfigurationTransport, LocalAiGatewayDistroResolver, LocalAiGatewayLifecycle) documenting their contracts, invariants, and examples of their main public methods, plus an AGENTS.md coding rule requiring a top-level documentation block for new modules. All documented symbols were verified against the current API surface. Review findings were addressed: the setup route example now goes through LocalAiSetupRouteResolver.ResolveAsync (observed state and validated RecoveryTarget), the runtime start example goes through LlamaServerRuntimeService.EnsureStartedAsync (the runtime invokes CompleteStartAsync/PublishAsync as gated callbacks), and the DistroResolver doc was trimmed to essentials.

Evidence

  • Static assessment: every documented symbol was cross-checked against current source (method names, signatures, parameter lists, enum members, record fields).
  • Full build: ./build.ps1, all builds succeeded.
  • Docs gates: ./scripts/validate-docs.ps1 (69 Markdown files), ./scripts/validate-agent-skills.ps1 (13 skills, 22 Markdown files), git diff --check, all passed.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • none: documentation-only change (source comments and one AGENTS.md rule line); no capacity-dependent custom Windows proof required.

Validation

Ran at head 8b5a4298 (docs-only change; comments in two source files):

  • ./build.ps1: all builds succeeded.
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore: Passed 4650, Failed 0, Skipped 24, Total 4674. Run with OPENCLAW_REPO_ROOT set to the repository root; an initial run without it failed 5-6 MXC fixture tests that resolve the TestHost image path from that variable (pre-existing environment dependency documented in AGENTS.md, unrelated to this change; with the variable set the full suite passes).
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore: Passed 4561, Failed 0, Skipped 0, Total 4561.
  • ./scripts/validate-docs.ps1: Documentation validation passed, 69 Markdown files checked.
  • ./scripts/validate-agent-skills.ps1: Agent skill validation passed, 13 skills and 22 Markdown files checked.
  • git diff --check: clean.

Real Behavior Proof

  • Environment tested: local Windows dev workstation, repository root C:\Users\pedro\devel\openclaw-windows-node.
  • PR head or commit tested: 8b5a4298.
  • Exact steps or command run: built the repo, ran both required test suites plus the docs validators listed under Validation.
  • Evidence after fix: build succeeded; shared suite 4650 passed / 24 skipped / 0 failed; tray suite 4561 passed / 0 failed; docs validators passed.
  • Observed result: documentation-only change; source/link checks are static assessment. Runtime proof is not applicable; no behavior change is claimed.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A
  • Not verified or blocked: none for a docs-only change.

Security Impact

  • New permissions or capabilities? (No)
  • Secrets or tokens handling changed? (No)
  • New or changed network calls? (No)
  • Command or tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? (Yes)
  • Config or environment changes? (No)
  • Migration needed? (No)
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦞👀
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.

@larroy
larroy marked this pull request as draft October 27, 2026 20:16
@larroy larroy changed the title docs(localai): add module header to LocalAiNativeBindingStore docs(localai): add module contract documentation to Local AI modules Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:docs Preliminary submission classification; full source review pending. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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. and removed clawsweeper:intake:docs Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex review: needs changes before merge.

What this changes

Adds contract descriptions and usage examples to four Local AI modules and requires documentation headers for new modules.

Example: A contributor investigates first-run Local AI setup before a managed Gateway is registered.

  • Before: The resolver summary implies that ownership is always pinned at construction.
  • After: The summary explains that the first successful Resolve binds the newly registered owner.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, narrowly scoped documentation with one remaining lifecycle example correction.
Proof confidence 🌊 off-meta tidepool Not applicable: This change contains source comments and contributor guidance only; static verification against production owners is the applicable evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Docs · Worth it: Yes · Fix scope: Complete
User problem: Contributors must infer Local AI ownership and lifecycle contracts from implementation details.
Reason: The maintainer-authored direction extends established documentation practice to four remaining owners without changing product behavior.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this maintainer-authored PR open: the prior findings are fixed, but one lifecycle example still confuses normal shutdown with explicit ownership release.

Priority: P3
Reviewed head: cc111b130e0a5fee0c8dddec061d87c9ba2e956d

Before merge

  • Separate normal shutdown from explicit ownership release (P3) - The example directs ordinary shutdown to call ReleaseOwnershipAsync after draining recovery. A running native installation retains AutomaticRecoveryEnabled during shutdown, so this call throws because its receipt is not safe to release. Actual shutdown drains recovery and disposes the runtime while preserving ownership for subsequent recovery. Document that path separately, and show explicit release through runtime.ReleaseOwnershipAsync after a successful Stop and closure of setup registration. This is a late finding: GitHub confirms the entire file is identical to the earlier reviewed version, so the concern was equally visible then.

Findings

  • [P3] Separate normal shutdown from explicit ownership release — src/OpenClaw.Tray.WinUI/Services/LocalAiGatewayLifecycle.cs:42-44
Agent review details

How this fits together

Companion coordinates the native llama.cpp runtime with Gateway configuration; these modules resolve WSL ownership, execute configuration commands, and persist native Gateway ownership receipts.

flowchart LR
  A[Companion setup] --> B[Local AI runtime]
  B --> C[Gateway lifecycle]
  C --> D[Native ownership receipt]
  C --> E[Gateway configuration transport]
  E --> F[Native or WSL Gateway]
Loading

Technical review

Best possible solution:

Keep the focused documentation change and separate receipt-preserving shutdown from explicit runtime-owned ownership release.

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

Source inspection establishes the documentation mismatch: normal shutdown retains the receipt, while explicit release rejects ownership whose automatic recovery remains enabled.

Is this the best way to solve the issue?

Existing module comments are the appropriate place for these contracts, and correcting the shutdown example requires no runtime changes or additional abstractions.

Full review comments:

  • [P3] Separate normal shutdown from explicit ownership release — src/OpenClaw.Tray.WinUI/Services/LocalAiGatewayLifecycle.cs:42-44
    The example directs ordinary shutdown to call ReleaseOwnershipAsync after draining recovery. A running native installation retains AutomaticRecoveryEnabled during shutdown, so this call throws because its receipt is not safe to release. Actual shutdown drains recovery and disposes the runtime while preserving ownership for subsequent recovery. Document that path separately, and show explicit release through runtime.ReleaseOwnershipAsync after a successful Stop and closure of setup registration. This is a late finding: GitHub confirms the entire file is identical to the earlier reviewed version, so the concern was equally visible then.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is correct
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • WSL resolver ownership summary keeps the original intent (ccd64bb: Bind lifecycle commands to one explicit setup-managed WSL Gateway and reject ownership drift.)
  • Deferred first-run binding keeps the original intent (3eed1f1: Allow an existing resolver to bind after the canonical registry adopts completed setup.)
  • Native ownership and running intent keeps the original intent (7dcbc2f: Keep native Local AI ownership durable and preserve explicit running intent separately from connection recovery.)

Security

None.

Evidence

Acceptance criteria:

  • pwsh -NoProfile -File ./scripts/validate-docs.ps1
  • git diff --check

What I checked:

Likely related people:

  • Pedro Larroy: Raw commit 4c6747d adds AGENTS.md:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4c6747db3b2e; files: AGENTS.md)

Review metrics

Metric Value Why it matters
Change scope Documentation +131/-4 lines; executable code and tests unchanged The growth supplies contracts and examples without introducing production machinery or test scaffolding.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P3: Contributor-facing documentation has one inaccurate lifecycle example; runtime behavior is unchanged.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool 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 execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-27T20:38:58.583Z sha a5cf6e3 :: needs changes before merge. :: [P3] Use observed setup state and the validated recovery target | [P3] Show runtime startup through its owning service
  • reviewed 2026-10-27T21:14:02.330Z sha 8b5a429 :: needs changes before merge. :: [P3] Describe deferred binding during first-run setup

Reviewed November 2, 2026, 4:15 PM ET / 21:15 UTC (Revision 3).

@larroy

larroy commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Both review findings are addressed in 8b5a429 (verified against source before editing):

  • Use observed setup state and the validated recovery target (P3): the DistroResolver doc no longer calls LocalAiSetupRoutePolicy.Decide with hand-picked flags or reconstructs a LocalAiRecoveryTarget. It now routes setup decisions through LocalAiSetupRouteResolver.ResolveAsync and consumes setup.RecoveryTarget directly, matching the production owner that filters managed owners via FindOwners, detects observed gateway/distro state, and supplies installed model/port metadata.
  • Show runtime startup through its owning service (P3): the lifecycle doc's startup step now calls runtime.EnsureStartedAsync(ct, progress) after PrepareAsync and explicitly labels CompleteStartAsync/PublishAsync as runtime-owned callbacks invoked under the LlamaServerRuntimeService operation gate, matching SetupLocalAiHost's production start path.

Also trimmed the DistroResolver module doc and example per author feedback (63 -> 23 lines). Full build, shared (4650 passed/24 skipped/0 failed) and tray (4561 passed) suites, and docs validators all pass at the new head. Ready for re-review.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:docs Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:docs Preliminary submission classification; full source review pending. labels Oct 27, 2026
@larroy
larroy marked this pull request as ready for review October 27, 2026 21:15
@larroy
larroy requested review from joelagnel and karkarl October 27, 2026 21:15
@larroy
larroy marked this pull request as draft October 27, 2026 21:16
@larroy
larroy marked this pull request as ready for review October 27, 2026 21:58
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 29, 2026
@larroy
larroy force-pushed the refactor-local-ai branch from 6c21d05 to cc111b1 Compare October 30, 2026 00:15
@larroy

larroy commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:docs Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:docs Preliminary submission classification; full source review pending. labels Nov 2, 2026
@larroy
larroy force-pushed the refactor-local-ai branch from cc111b1 to 87513dc Compare November 4, 2026 17:53
larroy and others added 6 commits November 4, 2026 23:44
Describe the ownership-receipt purpose, pending/recovery semantics, and
cross-process lock contract, with usage examples from LocalAiGatewayLifecycle.
- Replace garbled 'or引导' with 'or guide'
- Use correct named arguments GatewayPort/ModelCatalogId/RequestedLocalAiPort
- Construct GatewayRegistry from a data directory, not a settings manager
- Route decisions go through LocalAiSetupRouteResolver.ResolveAsync,
  which supplies observed state and the RecoveryTarget; the raw
  LocalAiSetupRoutePolicy.Decide flags example was unreachable.
- Runtime startup goes through LlamaServerRuntimeService.EnsureStartedAsync;
  CompleteStartAsync/PublishAsync are runtime-owned callbacks, not a
  standalone start sequence.
- Trim the DistroResolver module doc and example to the essentials.
@larroy
larroy force-pushed the refactor-local-ai branch from 87513dc to 8188ef4 Compare November 5, 2026 07:45
@larroy
larroy merged commit 4aee38a into openclaw:main Nov 5, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. 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.

3 participants