Commit graph

11 commits

Author SHA1 Message Date
euxaristia
5facd8738b
feat(core): detect tool validation retry loops and inject stop directive (#3178)
Primary change: prevent the model from burning tokens in an infinite retry
loop when a tool call repeatedly fails schema validation with the same
error (observed with ask_user_question and a malformed `questions`
parameter retrying 10+ times with the same validation error).

- Track consecutive validation failures per (tool name, error message)
  pair in CoreToolScheduler via a `validationRetryCounts` Map.
- After 3 consecutive failures for the same (tool, error) pair, append a
  RETRY LOOP DETECTED directive to the error response instructing the
  model to stop, re-examine the schema, try a fundamentally different
  approach, or surface the issue to the user.
- Reset per-tool counters when the tool invocation succeeds; reset
  globally when an incoming batch shares no tool name with any
  previously failing tool; reset the per-tool counter when the tool
  returns a different validation error so unrelated mistakes do not
  accumulate toward the threshold.
- Distinct from LoopDetectionService, which tracks model-behavior loops
  (repeated thoughts, stagnant actions); this change catches tool-API
  misuse loops at the scheduler layer.

Piggyback fixes bundled in the same PR:

- packages/cli/index.ts, packages/core/src/services/shellExecutionService.ts:
  treat PTY `EAGAIN` on the read path as an expected read error alongside
  `EIO`, avoiding noisy surface-level failures from transient
  non-blocking reads.
- scripts/build.js: switch the settings-schema generation step from
  `npx tsx` to `node --import tsx/esm` for Bun compatibility.

Tests:

- Unit tests in coreToolScheduler.test.ts cover: directive injection on
  the 3rd consecutive failure, counter reset when a different tool is
  called, and counter reset after a successful invocation of the same
  tool (fail → fail → succeed → fail → fail must not trip the directive).
2026-04-18 10:24:46 +08:00
jinye
7103c905f7
feat(cli): add startup performance profiler (#3232)
feat(cli): add startup performance profiler (#3219)

  Add a lightweight startup profiler activated via QWEN_CODE_PROFILE_STARTUP=1.
  When enabled, collects performance.now() timestamps at 7 key phases in main()
  and writes a JSON report to ~/.qwen/startup-perf/. Also records
  process.uptime() at T0 to capture module loading time not covered by
  checkpoint-based measurement.

  Key design decisions:
  - Only profiles inside sandbox child process to avoid duplicate reports
  - initStartupProfiler() is idempotent (resets state on each call)
  - Filename uses report.sessionId for consistency with JSON content
  - Zero overhead when disabled (single env var check)

  Initial measurement: module loading ~1342ms (94%), main() ~85ms (6%),
  confirming barrel exports and eager dependency loading as primary
  optimization targets for #3011.

  Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-14 14:14:42 +08:00
mingholy.lmh
e950d1e8c5 fix(cli): sync PTY race condition error handling to global uncaughtException
- Handle EIO read race errors on macOS/Linux (node-pty#178)
- Handle EBADF/ioctl resize race errors
- Handle 'Cannot resize a pty that has already exited' on Windows
- Require PTY-specific message context to avoid false positives

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-23 21:23:27 +08:00
tanzhenxin
741aa436e3 fix(cli): suppress Windows pty resize race condition
Add global uncaught exception handler to suppress known race condition
in @lydell/node-pty where a deferred resize fires after the pty process
has already exited on Windows.

Tracking bug: https://github.com/microsoft/node-pty/issues/827

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-11 18:40:04 +08:00
mingholy.lmh
14ea33063f Merge tag 'v0.3.0' into chore/sync-gemini-cli-v0.3.0 2025-09-11 16:26:56 +08:00
Tommaso Sciortino
7e31577813
Standardize exit codes (#7055) 2025-08-26 04:44:45 +00:00
koalazf.99
a9d6965bef pre-release commit 2025-07-22 23:26:01 +08:00
matt korwel
04518b52c0
Auth First Run (#1207)
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
2025-06-19 16:52:22 -07:00
Jacob Richman
89aca349cf
Exit with an error message if parsing settings.json fails. (#747) 2025-06-06 09:56:45 -07:00
Brandon Keiji
ef7dcdb49e
feat: add alias to the cli bin directive (#126) 2025-04-23 01:04:34 +00:00
Brandon Keiji
f480ef4bbc
refactor: clean up build output (#53)
* refactor: clean up build output

* refactor: add index.ts to package roots
2025-04-20 12:33:39 -07:00