Ambient mode wedges permanently (Running/0 cycles) when a model call hangs — no cycle timeout, no recovery from stuck Running
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start in crates/jcode-app-core/src/ambient/runner.rs at run_loop, run_cycle, and run_once_capture, then inspect manager.rs for should_run and the Running status handling. Reproduce the stuck state with the documented jcode serve command and compare the behavior with docs/AMBIENT_MODE.md. Done means a hung cycle becomes Incomplete or timed out, status recovers, and ambient mode can proceed again.
Written by the indexing model from the issue text.
Description
Title: Ambient mode wedges permanently (Running { running agent }, 0 cycles) when the provider model call hangs — no cycle timeout and no recovery from a stuck Running status
Environment: macOS; jcode serve started with --provider openrouter --model openrouter/free; ambient enabled in config with defaults.
Summary
When ambient mode is enabled and the serve process uses a model that cannot resolve to a concrete endpoint (or any model call that stalls open-ended), the first ambient cycle hangs forever inside run_cycle → run_once_capture. The persisted state stays {"status":{"Running":{"detail":"running agent"}},...,"total_cycles":0} indefinitely. Because should_run() returns false while status is Running, the loop can never advance; the only recovery is a manual state reset, and the CLI (ambient stop/trigger) fails on a debug-socket mismatch in this setup.
Evidence (from crates/jcode-app-core/src/ambient/runner.rs and manager.rs)
- No timeout/deadline around an ambient cycle. The only
tokio::timewaits inrun_loopare idle/interval sleeps (lines ~610, 701, 711, 716, 834); none wraprun_cycleor the agentrun_once_capture(line ~965). A model call that never returns aborts nothing. - No auto-recovery from a stuck
Running. Status resets toIdleonly onstart, on a cycleErr(line ~802), or after a successful cycle'srecord_cycle. There is no watchdog that resets a wedgedRunningback toIdleafter a hang. Combined withmanager.rsshould_run()returningfalseforAmbientStatus::Running, a hung cycle wedges ambient permanently. - Consequence: 0 completed cycles, empty
transcripts/,ambient.lockmay go stale, and no notification/end_ambient_cyclecontinuity handling fires.
Expected behavior
- Ambient cycles should have a deadline (bounded model call; on timeout, record the cycle as
Incomplete/timeout, reset status toIdle, and continue — per the AMBIENT_MODE.md crash-safety design). - There should be a watchdog that resets a stale
Runningstatus (e.g. if a cycle exceeds a max age) soshould_run()can return true again, consistent with "Incomplete" recovery described indocs/AMBIENT_MODE.md.
Reproduction
- Run
jcode serve --provider openrouter --model openrouter/freewith[ambient] enabled = true(pause_on_active_session=false). - Watch
~/.jcode/ambient/state.json; it becomesRunning/ "running agent" and stays there withtotal_cycles: 0indefinitely.
Suggested fix direction
- Add a per-cycle deadline (e.g.
tokio::time::timeoutaroundrun_cycle) that produces anIncomplete/Interruptedresult on expiry. - Add a stale-
Runningwatchdog that resets status toIdle(orScheduled) if a cycle has beenRunningbeyond a threshold, so the loop can proceed on the next wake.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 1jehuang/jcode
-
OrcaRouter is in the login catalog but has no ProviderChoice, so it can't be selected explicitly Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
-
Session::save() skips untouched sessions, so is_debug and canary never persist (4 failing tests) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
area: providers autonomous: clear bug triage: reproducible
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
area: providers autonomous: no bug triage: needs-decision
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100