Commit Graph
1559 Commits
Author SHA1 Message Date
chengyongruandGitHub 96eb965aae feat(webui): show the actual fallback model (#5017) 2026-07-23 15:57:13 +08:00
axelray-devandchengyongru 464f71b488 fix(session): fall back to legacy paths in metadata reads
Fixes #4940
2026-07-23 14:53:00 +08:00
chengyongruandchengyongru 15de6be0af fix(providers): fall back on authentication errors 2026-07-23 14:52:04 +08:00
Arthur K.andchengyongru 3647875aba fix: add one second to retry after delays 2026-07-23 14:10:27 +08:00
santhrealandchengyongru 299bcf491b fix(cron): skip null runHistory elements when loading jobs.json
Null entries in state.runHistory raised TypeError and quarantined the
store. Skip non-dict elements like LocalTrigger.from_dict already does.
2026-07-23 14:07:06 +08:00
santhrealandchengyongru 0191c0db73 fix(pairing): treat null approved channel lists as empty
pairing.json with "telegram": null crashed is_approved during load.
Treat non-list channel entries as an empty allow-list.
2026-07-23 14:04:53 +08:00
chengyongruandGitHub 9cf2fb19c2 feat(xai): surface hosted X Search activity (#5050) 2026-07-23 13:42:09 +08:00
chengyongruandchengyongru 5f054c0e74 fix(agent): deliver non-streamed finalization responses 2026-07-23 13:16:47 +08:00
Xubin Ren 2f4f00bb9f refactor(image): reuse the model picker 2026-07-23 12:42:24 +08:00
Xubin Ren 1616fa9f14 feat(image): apply generation settings live 2026-07-23 12:42:24 +08:00
chengyongruandGitHub c7393c785e feat(providers): add xAI Grok OAuth with capability-gated X Search (#5035) 2026-07-23 11:55:16 +08:00
chengyongruandGitHub c22efb5f7a feat(agent): make model presets session-scoped (#4866) 2026-07-23 00:38:49 +08:00
chengyongruandGitHub 66690fdb0c fix(webui): deliver late subagent results as new turns (#4992) 2026-07-22 23:04:36 +08:00
Xubin Ren aa8387fb4d feat(webui): polish agent output and app discovery 2026-07-22 22:42:31 +08:00
chengyongruandGitHub b189a37648 fix(agent): preserve agent-owned state in project workspaces (#4945) 2026-07-22 17:25:22 +08:00
chengyongruandchengyongru 80085085d9 fix(exec): retain failed owner session cleanup 2026-07-22 15:28:34 +08:00
yorkhellenandchengyongru ebf1ef5cab test(subagent): verify cascade exec termination on /stop
- terminate_by_owner kills matching sessions, skips others, handles
  empty owner case
- cancel_by_session calls terminate_by_owner on the session key
2026-07-22 15:28:34 +08:00
chengyongruandGitHub 3748f664b2 feat(config): watch runtime configuration changes (#5026) 2026-07-22 13:08:39 +08:00
seteiroandGitHub 79d9455313 fix(providers): add Qwen model-level thinking style mapping (#5023)
Add _QWEN_THINKING_MODELS to _MODEL_THINKING_STYLES with enable_thinking style. Prevents Qwen 3.5/3.6/3.7 models from exposing raw reasoning content in chat responses. Closes #4934
2026-07-22 10:46:22 +08:00
hamb1yandXubin Ren a9867a5a4e fix: quarantine invalid tool results 2026-07-22 01:59:09 +08:00
yrkandXubin Ren be1cc769d5 docs: refine ModelScope documentation wording 2026-07-22 01:35:20 +08:00
yrkandXubin Ren 9abad4746e feat(providers): add ModelScope provider for LLM and image generation 2026-07-22 01:35:20 +08:00
Kris LuandXubin Ren 89d8c055a8 fix(providers): sanitize UTF-16 surrogates at provider request boundary
Symptom
-------
LLM requests intermittently fail with:
  'utf-8' codec can't encode characters in position N-N+1: surrogates not allowed
when messages contain emoji-heavy content (e.g. HTML with mixed emoji + JSON round-trips).
This blocks the affected session until the session file is quarantined.

Root cause
----------
Surrogate sanitization was only applied at the CLI entry point
(nanobot/cli/commands.py: _sanitize_surrogates). Requests entering
the LLM provider layer through other channels (Feishu, cron, webui,
tool results, memory injection) had no defensive cleaning, so any
message that happened to carry unpaired UTF-16 surrogates (from an
upstream JSON round-trip with ensure_ascii=True on ill-formed input,
memory rehydration, or third-party content) would blow up at
json.dumps -> HTTP encode time inside the provider client.

Fix
---
1. Extract sanitize_surrogates() and sanitize_surrogates_deep() into
   nanobot/utils/helpers.py as the single source of truth. Both use
   utf-16-le round-tripping with errors='surrogatepass' / 'replace',
   so paired surrogates reconstruct back into their real code point
   and lone surrogates collapse to U+FFFD.
2. Make nanobot/cli/commands.py:_sanitize_surrogates a thin wrapper
   that re-exports the shared helper (backward compatible).
3. Add defense-in-depth at the LLM provider boundary in
   nanobot/providers/base.py:_sanitize_empty_content by running
   sanitize_surrogates_deep over each message and its content blocks
   right before requests are serialized to JSON.

Non-goals
---------
- truncate_text() is intentionally left untouched. Python str slicing
  cannot split a single code point into surrogate halves, so it is
  not the source of lone surrogates.
- session/manager storage layer is untouched. Archived sessions
  reproduced the failure only through the request path, not through
  storage.

Verification
------------
- New regression suite tests/providers/test_sanitize_surrogates.py
  covers: paired surrogate reconstruction, lone surrogate replacement,
  identity return on clean input (zero allocation), deep recursion on
  dict/list/tuple, provider _sanitize_empty_content integration, and
  full utf-8 encodability of the sanitized request body.
- 14/14 new tests pass; full existing test module also green.
- Replayed 58 archived real session messages plus adversarial
  lone-surrogate injection through the provider path with no encode
  errors after the fix.

Impact
------
- No behaviour change for clean inputs (sanitize_surrogates_deep is
  an identity return when no surrogate is present).
- Fails-safe: unpaired surrogates degrade to U+FFFD instead of
  aborting the entire request.
2026-07-21 19:17:58 +08:00
santhrealandXubin Ren b81c05581f fix(cron): coerce string schedule/state ms fields from jobs.json
jobs.json can store everyMs/atMs and next/last run timestamps as strings.
Loading left them as str, so _compute_next_run compared str to int and raised TypeError.
Coerce with an optional-int helper at from_store_dict, matching runHistory int() paths.
2026-07-21 19:07:45 +08:00
chengyongruandchengyongru 1d7bad3909 feat(providers): support Codex fast mode 2026-07-21 17:55:17 +08:00
Xubin Ren b46e7f4377 fix(config): invalidate fields with missing env refs 2026-07-21 17:35:16 +08:00
Ben LenartsandXubin Ren 4cfc99f4b3 fix(transcription): resolve ${VAR} env refs in transcription api_key/api_base
config.loader.load_config() intentionally returns the raw config with ${VAR}
references intact — env interpolation is a separate, explicit step
(resolve_config_env_vars) so that settings read/edit/save paths never
materialize secrets to disk or to the UI.

The transcription config path does not apply that step: both
channels/base.py (channel voice notes) and webui/transcription_ws.py (WebUI
recording) build their effective config via
resolve_transcription_config(load_config()). As a result a configured
api_key of "${GROQ_API_KEY}" (the documented way to reference secrets) is
passed to the provider verbatim, which fails with 401 Invalid API Key. No
amount of rotating the real key helps, because the literal placeholder
string is what gets sent.

Resolve the reference at the single choke point both callers share —
_resolve_transcription_api_key / _resolve_transcription_api_base — using a
new lenient loader.resolve_env_refs() helper (unset var -> empty string, so
a missing variable degrades to "not configured" rather than raising or
leaking). This fixes both entry points at once and cannot drift the way a
per-call-site fix does. Resolving inside load_config() was rejected: the
~20 settings-UI callers depend on it returning raw ${VAR} placeholders.

Literal keys are unaffected; the settings API only reads the derived
`configured` flag (never the key), which now reflects the resolved value.

Claude-Session: https://claude.ai/code/session_01Q3HuVaJAAQJA3kgVQVJ2Zt
2026-07-21 17:35:16 +08:00
Xubin Ren b2cf37da4a fix(config): preserve permissions during atomic save 2026-07-21 17:33:39 +08:00
santhrealandXubin Ren 28102382af fix(config): write config.json atomically via temp+replace
save_config truncated config.json in place on crash mid-write.
Route through _write_text_atomic like the pairing store so a failed write leaves the prior file intact.
2026-07-21 17:33:39 +08:00
amplifierplusandchengyongru cdb2df4982 fix(files): reject oversized reads before loading 2026-07-21 15:02:27 +08:00
chengyongruandXubin Ren d5658dbc91 fix: preserve background operator in allowlist segments
Maintainer edit: keep a top-level trailing '&' in the segment being matched so background execution cannot be checked as if the ampersand were absent. Redirection forms like 2>&1 and &> remain untouched.
2026-07-21 13:50:24 +08:00
chengyongruandXubin Ren 12c52c11d3 fix: treat single ampersand as shell segment
Maintainer edit: single '&' backgrounds the preceding command and starts another top-level shell segment, so allowPatterns must split it the same way as ';', '|', '&&', and '||'. Keep fd redirections such as 2>&1 and &> intact.
2026-07-21 13:50:24 +08:00
michaelxerandXubin Ren bbca32fea9 fix(security): validate each shell segment against exec.allowPatterns
Guard against shell-chain bypass where an attacker appends '&& malicious'
after an allowlisted prefix. The allowlist check now splits the command
on top-level chaining operators (&&, ||, ;, |) and requires every segment
to match at least one allowPattern independently.

Fixes #4521
2026-07-21 13:50:24 +08:00
KDBandXubin Ren 8981995474 fix(exec): clean up sessions on shutdown 2026-07-21 13:48:51 +08:00
KDBandXubin Ren 7cf3c71e3a fix(session): cap messages at persistence boundary
Bind SessionManager saves to the existing raw archive path so SDK imports and other bypass saves cannot persist more than the file cap without archiving unconsolidated overflow.

Add an SDK regression test that exercises the real ingest path.

Refs #4787
2026-07-21 13:47:18 +08:00
axelray-devandXubin Ren fde55d06e2 fix(runner): narrow BaseException catch to Exception in tool execution
The tool execution path caught BaseException, which includes
KeyboardInterrupt, SystemExit, MemoryError, and GeneratorExit.
These should never be caught and converted into conversational
error messages. CancelledError is already handled separately.

Change except BaseException to except Exception so fatal signals
propagate instead of being swallowed.

Adds parametrized regression test for KeyboardInterrupt and
SystemExit propagation.

Fixes #4788
2026-07-21 13:46:05 +08:00
santhrealandXubin Ren b6156fdd79 fix(cron): also coerce null createdAtMs/updatedAtMs on load
Same present-null footgun as runHistory; route all required store
ints through _store_int.
2026-07-21 13:45:02 +08:00
santhrealandXubin Ren 0b1b02f187 fix(cron): coerce null runHistory ms fields from jobs.json
Explicit JSON null for runAtMs/durationMs bypassed the missing-key
default and raised TypeError on load. Treat null/blank like missing.
2026-07-21 13:45:02 +08:00
chengyongruandchengyongru dfc3919b52 fix: stop masking runtime failures 2026-07-21 11:44:52 +08:00
sunpengcheng05andchengyongru 4a79cbb6e7 fix(session): tolerate unsupported directory fsync 2026-07-21 10:11:53 +08:00
chengyongruandGitHub 9db0d9f3c9 refactor(agent): unify internal turn lifecycle (#4993) 2026-07-21 00:14:27 +08:00
chengyongruandchengyongru b67f4b1371 fix(qq): account for SDK reconnect pacing
Use per-session retry deadlines so botpy's post-connect delay counts toward backoff, and keep unexpected failures on the channel logger.
2026-07-20 23:24:03 +08:00
golaandchengyongru ab0d28103b fix(qq): add exponential backoff to WebSocket reconnect loop
The QQ channel's _run_bot() used a fixed 5-second reconnect interval with
no backoff. When the network is unavailable (e.g., DNS failure), this
produces excessive botpy SDK error tracebacks every 5 seconds, flooding
logs.

botpy's Client.bot_connect() catches ws_connect() exceptions internally
and calls BotWebSocket.on_error(), which logs a full traceback and
immediately re-queues the session. The outer _run_bot() except never
fires for the reported DNS failure path.

Override bot_connect() on the _Bot subclass to:
- Apply exponential backoff (5s -> 300s cap) before re-queuing the session
- Log network errors (ClientConnectorDNSError, ClientConnectorError,
  OSError) compactly without traceback
- Reset backoff on successful connection
- Still call traceback.print_exc() for non-network errors

The outer _run_bot() loop retains exponential backoff as a fallback for
exceptions that escape start() entirely. The botpy library logging
redirect is elevated to ERROR to suppress redundant connection tracebacks.

Consistent with patterns already used in matrix.py and napcat.py.

Add 7 regression tests covering:
- DNS error applies backoff and re-queues session
- No traceback printed for network errors
- ClientConnectorError also triggers backoff
- Backoff doubles and caps at 300s
- Successful connection resets backoff
- Non-network errors still re-queue without backoff
- _is_network_error() classification

Fixes #4767
2026-07-20 23:24:03 +08:00
chengyongruandGitHub 8423cf3eeb fix(channels): complete dependency manifest migration (#4995)
* fix(channels): complete dependency manifest migration

* docs(docker): clarify custom uid dependency installs

* fix(channels): keep dependency preinstall internal

* refactor(channels): move dependency installer to scripts

* fix(docker): limit runtime write access
2026-07-20 15:24:57 +08:00
chengyongruandchengyongru e3de01c9f6 fix(webui): resolve build runner executable 2026-07-19 23:59:34 +08:00
chengyongruandGitHub 462a0dfb0f refactor(channels): make built-in channels self-contained (#4908)
* refactor(channels): own setup and instance contracts

* refactor(channels): isolate management contracts

* refactor(channels): normalize activation contracts

* fix(channels): enforce management contracts

* refactor(channels): finish setup ownership migration

* fix(channels): harden management contracts

* fix(channels): enforce lazy loading and runtime ownership

* fix(feishu): make multi-instance startup idempotent

* fix(webui): render channel setup contracts cleanly

* fix(feishu): stop websocket clients cleanly

* fix(channels): enforce persistence and activation gates

* fix(channels): preserve global feature action scope

* fix(channels): apply defaults for single plugins

* fix(channels): enforce management contract boundaries

* refactor(feishu): remove identity helper indirection

* fix(channels): preserve management setup contracts

* refactor(channels): generalize instance settings UI

* refactor(channels): package channel plugins with web UI metadata

* refactor(channels): make built-ins self-contained packages

* test(channels): colocate tests with channel packages

* fix(dingtalk): use official brand icon

* feat(channels): colocate webui translations

* docs(channels): clarify plugin ownership

* test(exec): remove output wait race

* refactor(channels): unify plugin descriptors

* fix(channels): enforce descriptor-owned contracts

* refactor(channels): finish package-owned plugin setup

* refactor(channels): use repository-owned packages only

* fix(channels): self-describe dependencies and runtime state

* fix(channels): warn about legacy entry points
2026-07-19 23:30:49 +08:00
chengyongruandchengyongru 7aaac37bca fix(triggers): require channel enablement predicate 2026-07-19 22:33:29 +08:00
Pei Futongandchengyongru 91514ad0b1 fix(triggers): reject deliveries to disabled channels 2026-07-19 22:33:29 +08:00
chengyongruandGitHub a6b68178aa fix(whatsapp): allow group ids in allowFrom (#4834) 2026-07-19 19:16:37 +08:00
chengyongruandGitHub 2099cb009e fix(providers): fail over across provider failure domains 2026-07-19 17:37:55 +08:00