Skip to content

fix(chat): first chats fail with Agent error while Local AI is starting - #1738

Draft
joelagnel wants to merge 1 commit into
openclaw:mainfrom
joelagnel:fix/local-ai-chat-send-readiness
Draft

joelagnel wants to merge 1 commit into
openclaw:mainfrom
joelagnel:fix/local-ai-chat-send-readiness

Conversation

@joelagnel

@joelagnel joelagnel commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1445

What Problem This Solves

Fixes: the first chats after the companion starts (including the post-setup restart) fail with a generic Agent error when Local AI is the model.

User Impact

User impact: a chat sent while the Gateway cannot resolve its default model (for example while companion Local AI is restarting) now waits in the outgoing queue and gets a reply once the model is back, instead of failing. The composer stays usable, and a held message can be canceled from its queue card. When the default model is listed, sends go out immediately as before.

Why This Change Was Made

Companion Local AI startup withdraws the Gateway's models.providers.llamacpp route and publishes it again only after llama-server answers (about 30 s on an RTX Spark). A turn sent in that window fails with Unknown model: llamacpp/<alias> (model_not_found), which the Gateway does not retry. Root-cause logs are on #1445.

Each chat send now checks the inference endpoint the turn will use, as seen by the Gateway itself:

  • The check. Before admitting a send, the chat coordinator asks the Gateway for models.list (view: "configured") and looks for the entry tagged default. While the llamacpp route is withdrawn, that entry is gone from the list.
  • Only sessions that need it wait. If the session's own model (for example a cloud model the session was switched to) is in the list, its sends are not held. A model switch made in this app counts from the moment it is requested until sessions.list has had 30 s to reflect it. A switch the Gateway rejects, or whose request throws, is dropped, and held sessions are re-checked so a hold caused only by a rejected switch is released. Holds are tracked per session, so one session's hold never delays another session's queue.
  • Order and lifetime. Sends are admitted one at a time, so overlapping sends (MCP and UI) keep their submission order across the models.list await. Wait state is fenced by operator client: a previous client's wait cannot change what the new client's sends see.
  • The hold. If the default model is missing, the send is admitted to the outgoing queue and the queue drain waits. The coordinator re-checks every second and releases the queue as soon as the model is listed again, for at most two minutes. A wait that timed out is not repeated until the default model is listed again.
  • Unknown is not "missing". A failed or malformed models.list reply does not start a hold (sends behave as on main), and does not end a running one early. An older Gateway that does not tag models counts as listed.
  • Generic. The check does not depend on Local AI internals, so any provider whose route the Gateway temporarily cannot resolve gets the same behavior.
  • Held messages use the existing send queue: cancel from the queue card, a Failed card with retry on rejection, requeue on reconnect, and send order.

MCP: app.chat.send now also returns queued, so automation can tell a message waiting in the outgoing queue from one that was dispatched. The tool description and .agents/skills/winnode/SKILL.md are updated. Ledger: a new authoritative row in docs/ARCHITECTURE.md.

Why not fix it where the route is withdrawn. Keeping the route on the last port lets a local process squat the unowned port (ClawSweeper P1). Parking the provider at 127.0.0.1:0 is safe, but the Gateway binds a turn's baseUrl once and its retries never re-read it, so in-flight turns still fail (proven on Gateway 2026.10.3).

Known limits:

  • A send in the first seconds after start, before the Gateway has applied the withdrawal, still sees the model listed and is dispatched to the old route. On rtxspark2 the withdrawal was applied 5-7 s after launch.
  • Messages already waiting in the queue (behind an active turn, or queued while disconnected) are dispatched without a new check, unless their session is still held.
  • Each send costs one models.list round trip (2 s timeout).

Evidence

Same single-send race on both builds: restart the companion, open chat, and send one message about 10 s after the composer appears (inside the route withdrawal).

Before: main (Dev 2026.9.804.4281) After: this PR (e5c2d736, Dev 2026.9.804.4306)
before after
BEFORE3-OK #1 fails with Agent error AFTER7-OK #1 is held, then answered

Change Type

  • Bug fix

Scope

  • Tray or WinUI UX

Required proof pools

  • windows-11-arm64: the reproduction and proof run on Windows ARM64 (RTX Spark N1X) with the packaged Dev app.
  • windows-wsl-dgx-blackwell: Local AI startup and real inference through the WSL Gateway on Blackwell.

Validation

Run on Windows ARM64 (RTX Spark, rtxspark2), worktree at e5c2d736:

Check Result
./build.ps1 pass
dotnet test tests/OpenClaw.Shared.Tests 4315 passed, 34 skipped, 0 failed
dotnet test tests/OpenClaw.Tray.Tests 4090 passed, 0 failed
dotnet test tests/OpenClaw.WinNode.Cli.Tests 129 passed, 0 failed

CI classifies this diff as targeted, so it does not build a Dev MSIX. The proof package was built on rtxspark2 from the same worktree with ./build.ps1 -Project WinUI -Configuration Release -Msix Dev (the CI Dev signing path), and was installed as an in-place upgrade of the CI Dev package.

Real Behavior Proof

Windows ARM64 (RTX Spark N1X), WSL Gateway 2026.10.3, companion-managed Local AI (llama.cpp b11320, Qwen3.6-35B-A3B Q4_K_S). The UI was driven with UI Automation.

After (this PR at e5c2d736, Dev 2026.9.804.4306). Companion log (local time):

03:56:11.603 Application started (WinUI 3)
03:56:14.817 openclaw config unset models.providers.llamacpp
03:56:23.043 OpenClawChatCoordinator: holding chat sends until the Gateway lists its default model   (chat sent 03:56:23.038)
03:56:48.279 OpenClawChatCoordinator: held chat sends 25.2s until the Gateway listed its default model
03:56:50.387 Local AI router startup state: Healthy
  • The Gateway log has no Unknown model entry for this run.
  • The chat shows AFTER7-OK #1 from qwen3.6-35b-a3b-mtp-ud-q4-k-s (screenshot above).

Before (main, Dev 2026.9.804.4281), the same race:

21:51:27.194 Application started (WinUI 3)
21:51:30.469 openclaw config unset models.providers.llamacpp   (Gateway applied it at 21:51:34.2)
21:51:38.193 chat sent
Gateway: Embedded agent failed before reply: Unknown model: llamacpp/qwen3.6-35b-a3b-mtp-ud-q4-k-s
21:52:00.003 Gateway republished the route

The chat shows Agent error (screenshot above).

Not verified:

  • A session switched to a cloud model, including a send right after the switch and a rejected switch, was not exercised on the device (rtxspark2 has no cloud provider configured). These paths are covered by code review only; no new tests were added for them.
  • MCP app.chat.send returning queued: true during this hold was not re-run on this head. It was proven during a hold on an earlier head of this PR (9ba1602d), and the queued plumbing is unchanged.
  • The known limits above.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No. It adds models.list requests on the existing operator connection.
  • Command or tool execution surface changed? No
  • Data access scope changed? No

Compatibility and Migration

  • Backward compatible? Yes
  • Config or environment changes? No
  • Migration needed? No

🤖 Generated with Claude Code

@clawsweeper

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

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(chat): first chats fail with Agent error while Local AI is starting This is item 1/1 in the current shard. Shard 0/1.

This temporary status tracks the active review worker. The completed review will appear in the durable ClawSweeper review comment.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch 3 times, most recently from def6ddd to 9c2795c Compare October 15, 2026 21:18
@larroy

larroy commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

I would generalize it to check a generic inference known back-end controlled by the node app rather to only local AI if possible.

TimeSpan timeout)
{
/// <summary>Upper bound for holding one send; the send proceeds afterwards either way.</summary>
internal static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do an env variable with a default constant.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9ba1602: OPENCLAW_CHAT_SEND_HOLD_TIMEOUT_SECONDS (a positive whole number of seconds) overrides ChatSendReadiness.DefaultTimeout, which stays at two minutes. Any other value falls back to the default. Covered by the ResolveTimeout_* tests.

@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch from 9c2795c to 3a11c63 Compare October 15, 2026 21:31
@joelagnel

Copy link
Copy Markdown
Collaborator Author

@larroy thanks, done in 9ba1602. The hold now goes through a small IChatInferenceBackend interface (pending startup, IsStarting, change notifications), and ChatSendReadiness holds sends until every registered backend has settled. Companion Local AI is the only implementation today (LocalAiChatInferenceBackend). Another node-controlled backend only needs to implement the interface and be added to the list App passes to OpenClawChatCoordinator.

@joelagnel
joelagnel marked this pull request as ready for review October 15, 2026 22:20
@joelagnel

Copy link
Copy Markdown
Collaborator Author

@larroy confirm it looks good to you now?

@joelagnel

Copy link
Copy Markdown
Collaborator Author

I would like to hold off on merging this. I'm redoing the fix to be more robust.

@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch from 196d729 to 673c1dd Compare October 16, 2026 00:13
@joelagnel joelagnel changed the title fix(chat): first chats fail with Agent error while Local AI is starting fix(local-ai): first chats fail with Agent error while Local AI is starting Oct 16, 2026
@joelagnel joelagnel added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 16, 2026
@joelagnel

Copy link
Copy Markdown
Collaborator Author

@larroy I replaced the chat-side send hold with a fix at the source in 673c1dd. Startup now keeps the Gateway's llamacpp route and starts llama-server on the last verified port again, so a chat sent while Local AI starts is retried by the Gateway until llama-server answers, instead of failing as an unknown model. This removes ChatSendReadiness, IChatInferenceBackend and the OPENCLAW_CHAT_SEND_HOLD_TIMEOUT_SECONDS override from the PR, and cloud-model chats are no longer held during startup. The description is updated; device proof from this commit's CI package will follow.

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex review: needs changes before merge.

What this changes

This PR queues native chat sends while their required model is unavailable and exposes queue status through MCP.

Example: Send “Reply with exactly: AFTER7-OK #1” while the llamacpp default route is withdrawn during startup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong shipped startup evidence supports the approach, but two source-verified rejection defects block correctness approval.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The current-head packaged Windows ARM64 app exercised native chat through WSL Gateway 2026.10.3 and managed Local AI: inspected screenshots show failure before and a reply after, with logs recording the hold and release; rejected model-switch behavior remains unexercised, and earlier MCP queued-output proof covers source-verified unchanged result plumbing.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A prompt sent during Local AI startup fails with a generic Agent error.
Reason: The collaborator-authored direction has demonstrated user value, but the documented early-startup window and lack of explicit loading feedback leave part of the linked issue unresolved.

Merge readiness

⛔ Needs changes before merge - 3 items remain

Keep open: the startup hold demonstrably works, but rejection handling still permits stale holds and premature dispatch across sessions.

Priority: P2
Reviewed head: e5c2d736ae2225e9ba8ceabf5809e4a19d8ea02c

Before merge

  • Commit readiness invalidation atomically with send admission (P2) - The prior rejection scenario remains reachable when its response arrives during this await. With openai/gpt-5.4 selected and listed while the default llamacpp model is missing, request ClearModelAsync and immediately send. Admission reads the speculative default selection, then awaits models.list; if the Gateway rejects the clear meanwhile, DropPatchedModels sees no registered hold and performs no recheck. The query then completes and installs a default-model hold, delaying the usable cloud session until recovery or the two-minute timeout. Revalidate the selection generation when committing the hold and make invalidation atomic with admission. Keep the model/hold commits under ChatConversationState, as required by the ledger's closed provider-state responsibility.
  • Preserve unrelated selections when a session patch fails (P2) - Any rejected sessions.patch clears every speculative model selection, including successful or pending changes in other sessions and changes unrelated to the failed field. For example, session A clears its cloud override while the default model is absent and correctly queues a send; before sessions.list reflects A's accepted clear, a rejected model or reasoning patch in session B clears A's record. RecheckReadinessHoldAsync then sees A's stale cloud selection, removes its hold, and dispatches against the unavailable default, producing the error this PR is intended to avoid. Carry request/session correlation through patch outcomes and invalidate only the matching model operation instead of clearing the dictionary.
  • Explain or restore the original intent of Atomic conversation and queue state - f8a8825: refactor(chat): extract runtime state owners #1096 established a sole conversation lock and closed provider-owned runtime collections to preserve atomic lifecycle transitions.

Findings

  • [P2] Commit readiness invalidation atomically with send admission — src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:289-294
  • [P2] Preserve unrelated selections when a session patch fails — src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:873-879

Provenance

Tests

  • Missing end-to-end proof: The added tests exercise queue behavior with injected readiness, but no production-style rejected-patch interleaving, cross-session invalidation regression, or base-fails/head-passes result is supplied.
Agent review details

How this fits together

Native UI and MCP submissions enter the chat provider, which coordinates session selections and outgoing queues before dispatching chat.send through the Gateway connection.

flowchart LR
UI[Native chat UI] --> Provider[Chat data provider]
MCP[Local MCP] --> Provider
Provider --> Readiness[Gateway model readiness]
Provider --> Queue[Conversation queue state]
Readiness --> Gateway[Gateway connection]
Queue --> Gateway
Gateway --> Model[Inference provider]
Loading

Technical review

Best possible solution:

Correlate model-patch outcomes per request and commit model selection, readiness invalidation, and queue admission through ChatConversationState.

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

The supplied current-main screenshot and correlated Gateway logs establish the startup failure; the rejection defects are source-reproducible interleavings, not locally executed reproductions.

Is this the best way to solve the issue?

Queueing through the existing send path is useful and preserves safe route withdrawal, but model outcomes and readiness must share the established transaction boundary.

Full review comments:

  • [P2] Commit readiness invalidation atomically with send admission — src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:289-294
    The prior rejection scenario remains reachable when its response arrives during this await. With openai/gpt-5.4 selected and listed while the default llamacpp model is missing, request ClearModelAsync and immediately send. Admission reads the speculative default selection, then awaits models.list; if the Gateway rejects the clear meanwhile, DropPatchedModels sees no registered hold and performs no recheck. The query then completes and installs a default-model hold, delaying the usable cloud session until recovery or the two-minute timeout. Revalidate the selection generation when committing the hold and make invalidation atomic with admission. Keep the model/hold commits under ChatConversationState, as required by the ledger's closed provider-state responsibility.
    Confidence: 0.98
  • [P2] Preserve unrelated selections when a session patch fails — src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:873-879
    Any rejected sessions.patch clears every speculative model selection, including successful or pending changes in other sessions and changes unrelated to the failed field. For example, session A clears its cloud override while the default model is absent and correctly queues a send; before sessions.list reflects A's accepted clear, a rejected model or reasoning patch in session B clears A's record. RecheckReadinessHoldAsync then sees A's stale cloud selection, removes its hold, and dispatches against the unavailable default, producing the error this PR is intended to avoid. Carry request/session correlation through patch outcomes and invalidate only the matching model operation instead of clearing the dictionary.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 127016568ef2.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • ./build.ps1
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.WinNode.Cli.Tests/OpenClaw.WinNode.Cli.Tests.csproj --no-restore
  • Run deterministic rejected-patch regressions with controlled response ordering and verify the intended failure on the reviewed head.

What I checked:

Likely related people:

  • Barbara Kudiess: Raw commit f8a8825 adds src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:139 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f8a8825ccbb4; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • Scott Hanselman: Raw commit a1d7cb0 adds src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:775 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a1d7cb05de95; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • Caleb Eden: Raw commit c9b5476 adds src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:393 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c9b5476a873f; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The demonstrated startup failure is recoverable, and the remaining defects affect sends around model changes and rejected patches.
  • merge-risk: 🚨 message-delivery: Rejection handling can unnecessarily hold a usable cloud session or release a queued message into an unavailable default model.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (7 earlier review cycles)
  • reviewed 2026-10-16T00:18:26.950Z sha 673c1dd :: needs real behavior proof before merge. :: [P1] Keep Gateway traffic away from the released startup port | [P1] Validate the native binding before opening its listener
  • reviewed 2026-10-16T02:57:51.262Z sha 030178b :: blocked before merge. :: [P2] Refresh the endpoint before retrying a parked turn
  • reviewed 2026-10-16T03:06:09.079Z sha 196d729 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-16T03:21:18.132Z sha 196d729 :: needs changes before merge. :: [P2] [P2] Share the timeout budget across pending and Starting phases
  • reviewed 2026-10-16T05:04:21.584Z sha 21d0b7a :: needs changes before merge. :: [P2] [P2] Check the session's effective model before holding its sends | [P2] [P2] Invalidate polling work when the operator client changes | [P2] [P2] Reserve submission order before awaiting the model query
  • reviewed 2026-10-16T07:23:13.410Z sha 8480656 :: needs changes before merge. :: [P2] [P2] Settle model selection before deciding send readiness
  • reviewed 2026-10-16T09:27:23.189Z sha 0c8210d :: needs changes before merge. :: [P2] Use confirmed model-patch outcomes for readiness tracking

Reviewed October 16, 2026, 7:03 AM ET / 11:03 UTC (Revision 8).

@larroy

larroy commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

checking...

@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch from 673c1dd to 030178b Compare October 16, 2026 02:53
@joelagnel

Copy link
Copy Markdown
Collaborator Author

Both P1 findings on 673c1dd were valid, so that approach is gone. 030178b takes a different route:

  • Released startup port / credential disclosure: the companion no longer keeps the route pointed at a real port during startup. An endpoint cycle now parks the provider at http://127.0.0.1:0/v1. Nothing can listen on port 0, so no request, prompt or Local AI credential can reach another process; a turn sent meanwhile fails as fetch failed, which the Gateway retries until the real endpoint is published. There is no port reuse and no bind probe any more.
  • Native admission before launch: LlamaServerRuntimeService and ResumeAsync are back to main. Native Gateways keep the existing withdrawal and admission; parking applies only to the app-owned WSL Gateway path where No loading indicator during local AI model load — first prompt shows "Agent error" #1445 reproduces.

Checked against the real Gateway 2026.10.3: config set --dry-run accepts the parked provider, and its fetch to port 0 fails as fetch failed. Device proof from this commit's CI package will be added to the description.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Oct 16, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Oct 16, 2026
@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch from 21d0b7a to 8480656 Compare October 16, 2026 07:17
@joelagnel

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Addressed the three findings in 8480656c:

  • Session's effective model. The provider now passes the session's model and provider (from sessions.list). If that model is in the Gateway's configured list, the send is not held, whatever the default is. Holds are tracked per session, so a cloud session's queue never waits on another session's hold. Only a listed default model clears the timed-out state, so a cloud send cannot re-arm a hold that already timed out.
  • Polling after an operator client change. Wait state is guarded by a lock and a generation that SetOperatorClient bumps. A previous client's loop stops at its next tick and cannot set the timed-out state for the new client.
  • Submission order. The readiness check and queue admission now run under a per-provider gate, so overlapping sends are admitted in the order they were submitted.

Validation on 8480656c (Windows ARM64): build, Shared 4315, Tray 4090 and WinNode CLI 129 tests passed, 0 failed. Device proof from a Dev package built at this head: the send was held 21.2 s and answered, with no Unknown model in the Gateway log. The screenshot and log are in the description.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 16, 2026
@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch 2 times, most recently from 9ee462c to 0c8210d Compare October 16, 2026 09:23
@joelagnel

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Addressed "Settle model selection before deciding send readiness" in 0c8210d3:

  • A model switch made in this app (SetModelAsync / ClearModelAsync) records the requested selection when the switch starts, so a send right after it checks the newly selected model instead of the sessions.list snapshot that still shows the previous one. Clearing the override records "default".
  • Each switch owns its record: a failed patch removes only its own record, so it never erases a newer switch. A successful one expires after 30 s, once sessions.list has had time to reflect it, so a later change made elsewhere is not shadowed.
  • The d6b1a72f ordering barrier is unchanged: dispatch still awaits the pending session patch before chat.send, so the turn itself never runs on a stale model. I did not move that wait to admission, because it would delay the user's bubble and the composer until the patch returns (an existing test hangs on that).

Validation on 0c8210d3 (Windows ARM64): build, Shared 4315, Tray 4090 and WinNode CLI 129 tests passed, 0 failed. Device proof from a Dev package built at this head: held 23.3 s, then answered, with no Unknown model in the Gateway log. A switch to a cloud model was not exercised on the device (no cloud provider on the test machine).

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient Contributor real behavior proof is sufficient. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 16, 2026
Companion Local AI startup and restarts withdraw the Gateway's llama.cpp
provider until llama-server answers, about 30 s on an RTX Spark. A chat
sent in that window fails as an unknown model, and the user sees a
generic "Agent error" (openclaw#1445).

Before each send, check the Gateway's configured model list for the
model it tags as default. While it is missing, admit new messages to the
send queue and re-check every second, then drain the queue once it is
listed, for at most two minutes. The composer stays usable, and the
existing queue rules for cancel, failed-send retry, reconnect and
ordering apply to held messages. Anything the check cannot tell, such as
no connection or an older Gateway without model tags, sends as before.
MCP app.chat.send reports whether the message is queued.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@joelagnel
joelagnel force-pushed the fix/local-ai-chat-send-readiness branch from 0c8210d to e5c2d73 Compare October 16, 2026 10:58
@joelagnel

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Addressed "Use confirmed model-patch outcomes for readiness tracking" in e5c2d736:

  • The provider now observes SessionCommandCompleted. A failed sessions.patch result (a Gateway rejection, delivered after the bridge task completes) drops the recorded model switches, so readiness falls back to the sessions.list selection. The failure event carries no session key, so all records are dropped, not one; that only restores the pre-switch behavior for other sessions.
  • Holds are recomputed: every session with an active hold is re-checked against its current selection, and a session that no longer needs to wait (for example the cloud session in your scenario) has its hold removed and its queue drained right away instead of waiting for the default model or the two-minute bound.
  • A patch that throws still drops only its own record, as before.

Validation on e5c2d736 (Windows ARM64): build, Shared 4315, Tray 4090 and WinNode CLI 129 tests passed, 0 failed. Device proof from a Dev package built at this head: held 25.2 s, then answered, with no Unknown model in the Gateway log. A rejected model switch was not exercised on the device or in a new test.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 16, 2026
@joelagnel

Copy link
Copy Markdown
Collaborator Author

Status update on the chat send hold for #1445 (PR #1738):

The fix needs more work, but it is a working option. On Windows ARM64 with the WSL Gateway, a chat sent while companion Local AI restarts is held until the Gateway lists its default model again (about 20-25 s), then answered, instead of failing with "This model was not found". Before/after screenshots and logs are in the PR description.

What still needs work:

  • Each review round finds another edge case in the per-session model handling (sessions switched to a cloud model, pending or rejected model switches). That handling has roughly doubled the size of the change.
  • A send in the first seconds after start, before the Gateway applies the route withdrawal, is not held.
  • Messages already in the queue are dispatched without a new check.
  • The cloud-model paths are covered by code review only, not by device proof or new tests.

If QA considers #1445 a show stopper, we can merge this as is and follow up on the items above. Otherwise the PR stays open while a cleaner fix is worked out.

@joelagnel
joelagnel marked this pull request as draft October 16, 2026 12:30
@joelagnel joelagnel removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 16, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

Hi @joelagnel, I'm a GitHub Copilot triage bot helping with repository housekeeping, not Scott. Thanks for the clear October 16 update and the device evidence. Is the cleaner Local AI startup fix you mentioned still moving forward, and should this draft be updated against current main? If the approach has moved to another PR or you're no longer pursuing this version, you're welcome to close it with a pointer. If it's still intentionally parked, a short status note is enough. No rush, and I won't close it automatically.

@joelagnel

Copy link
Copy Markdown
Collaborator Author

This issue is still open but I am not going to get time to work on this bug. The PR is experimental and not in a mergeable state. I’m happy to hand this PR to anyone else who wants to take it further. The issue is still open AFAIK.

@roboclaw-bot

Copy link
Copy Markdown
Contributor

PR cleanup review

Reviewed head: e5c2d736ae2225e9ba8ceabf5809e4a19d8ea02c. Main comparison: e59374c064f43d68f5c72d070d4c89ef2d20ec3b.

Thanks for documenting both the working startup case and the remaining limits. I rechecked e5c2d73 against main e59374c: the hold is not superseded, but rejected-patch admission and cross-session invalidation races remain, and readiness state sits outside the conversation owner. Given your November 7 handoff note, this should remain a nonmergeable draft until a maintainer takes a focused repair through regression tests and current-head proof. The green older-base CI does not clear those races.

Action in this cleanup pass: leaving this PR open. No branch changes or runtime-proof waiver. The findings above come from source, discussion and recorded-CI review; Windows validation was not rerun in this pass.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to inactivity.
Please update it or it will be closed.

@github-actions github-actions Bot added the stale label Nov 25, 2026

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

merge-risk: 🚨 message-delivery 🚨 Merging this PR could drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. stale 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.

No loading indicator during local AI model load — first prompt shows "Agent error"

4 participants