5 Commits

Author SHA1 Message Date
Handsome-wzw
7b45527b5b fix(tools): an array sent as its own JSON is still an array
## Summary

Reported as "deliver_files is broken". It is not: **the tool never ran.**

Every `deliver_files` call on one install was refused before dispatch -- five in a row in a single session -- and nothing was ever delivered:

```
Error: Invalid parameters for tool 'deliver_files': files should be array
```

What the model sent was the array, spelled as a string:

```json
{"files": "[{\"path\": \"...poster.png\", \"title\": \"...\"}]", "message": "..."}
```

`cast_params` already forgives that spelling for every scalar type -- `"3"` for an integer, `"true"` for a boolean -- and did not for arrays or objects, which are exactly the types a model is most likely to stringify.

## Type

- [x] Fix
- [ ] Feature

## The edge of the forgiving is the design

When the value is a string, try `json.loads`, and take the result **only if it is the type the schema asked for**. A string that is not JSON, or is JSON of the wrong shape, is returned unchanged so the validator still names the real problem -- the point is to widen what is accepted, not to swallow a type error.

**Nothing here can raise.** Turning "your argument has the wrong type" into a traceback would be worse than the refusal it replaces, so the parse is wrapped and failure falls through.

**A `type: "string"` field is never parsed.** JSON is ordinary text in a message body or a file's content, and replacing it would hand the tool something it never asked for. Two independent things prevent it today (the string branch returns before the parse is reached, and the parse only wins on a type match), which is why the case pinning it is a tripwire rather than a load-bearing assertion -- said so in its own docstring rather than left to look like coverage.

## Not just deliver_files

Six built-in tools declare an array or object parameter and were all exposed:

| tool | parameter |
|---|---|
| `deliver_files` | `files` |
| `ask_user` | `questions` |
| `image_generate` | `images` |
| `message` | `media` |
| `create_playbook` | `skills` |
| `video_generate` | `params` |

The same failure was already seen from the other side: `acp_client/acp_agent.py` records `update_task_state` and `operations should be array` from a real dispatch.

## Verification

```
make lint-python    ruff check + ruff format --check, 1850 files
make lint-imports   9 contracts kept, 0 broken
pytest tests/       19,699 passed, 7 failed (all pre-existing, see below)
```

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots -- no user-facing string

**End to end, through the real tool**, with the exact payload that failed five times in production:

```
files sent as:            str -> [{"path": ".../poster.png", "title": "..."}]
returned:                 Delivered 1 file(s): poster.png (72 B).
still "should be array":  False
registered in the store:  True
```

Twelve cases, five mutations, each killing at least one:

| mutation | red |
|---|---|
| drop the whole branch (the old behaviour) | 3 |
| raise instead of falling through on a parse failure | 5 |
| accept the parse whatever type it yielded | 1 |
| do not re-cast the parsed value, so items are not cast | 1 |
| widen the tuple to include `string` | **survived -- unreachable** |

The last is worth stating rather than hiding: that mutation cannot change behaviour, because the `type == "string"` branch returns earlier and the type check would refuse the result anyway. I also tried moving the new block above that branch, alone and combined with widening the tuple, and neither reddens anything either. The invariant holds by construction; the case that documents it says so.

**Pre-existing failures, checked against the base.** 7 failed in the full run, all in `tests/test_security_network.py` (`test_a_redirect_to_a_dangerous_address_is_refused` and siblings). Running that file alone on this same tree gives 4 -- the count is order-dependent -- and the change touches only `raven/agent/tools/params.py` plus a new test file, neither of which `raven/security/network.py` imports. The failures are the box's resolver: it returns poisoned answers roughly half the time, which I measured separately (`en.wikipedia.org` came back as `2001::1` on 3 of 6 lookups). Not introduced here, and worth someone's attention on its own.

## Risk

- [x] Security impact considered -- widens what reaches a tool's own validation, not what bypasses it. A parsed value is still validated against the same schema, and a parse that yields the wrong type is refused exactly as before
- [x] Backward compatibility considered -- a call that worked before takes the identical path; the new branch is reached only by a `str` where an array or object is declared, which previously always failed
- [x] Rollback path is clear -- single-commit revert

## Related Issues

N/A

## Swept

`mr-review-patterns` pre-submit sweep, over `git diff origin/main...HEAD`.

- **1 (a write location moved)** -- nothing moved; a branch was added to an existing dispatch on `target_type`. Grepped every caller of `cast_params`: the registry is the only one, and it runs `validate_params` right after, which is the reader this affects.
- **2 (a value with several entry points)** -- the cast is the single funnel every tool argument passes through, which is why the fix belongs here and not in `deliver_files`.
- **3 (a guard)** -- checked both directions: what it wrongly lets through (JSON of the wrong type, non-JSON text -- both refused, with cases) and what it wrongly refuses (a real list, unaffected, with a case).
- **4 (tests)** -- five mutations above, one honestly reported as unreachable. Failing-ID sets diffed against the base rather than counts.
- **6 (stale text)** -- the module docstring enumerated what is coerced ("a string that should be an integer"); it now names arrays and objects too. Grepped the tracked tree for other statements of the rule: none.
- **9 (error handling)** -- the new path adds one way to end and it is caught: `json.loads` raises `ValueError` on bad text and `TypeError` on a non-string, and both fall through to the untouched value.
- **11** -- `git ls-files | grep -c node_modules` is 0; the commit-message gate was run, not eyeballed.

Not applicable, with reasons: **3b, 3c, 3d, 3e** (no tool schema produced, no state moved, one lane, no assertion lost its symbol); **4b, 4c, 4d** (no platform branch, no shell, no rendered number); **5, 5b** (no dependency; `json` is stdlib and already imported across this package); **6b, 6c** (no backup, no generated artifact); **7, 7b** (nothing on disk); **8** (no asset, no secret); **10** (no prompt text).

## Deliberately not fixed

The error text still ends with `[Analyze the error above and try a different approach.]`, and the model plainly did not -- it sent the same shape five times. A message naming the expected spelling (`files must be a JSON array, not a string containing one`) would give it something to act on. That is a change to the registry's error surface, affects every tool, and deserves its own argument.

## Moved from !594

Opened on a compliant source branch. AGENTS.md 2.1 asks for a 3-5 word snake_case description and the previous branch had seven; GitLab cannot change an existing merge request's source branch, so the change moves rather than the name.

Same commits, rebased onto `c2a9768f`. Both code findings from the review on !594 are already in them -- `RecursionError` caught with its regression case, and the implementation comment reduced to the two non-obvious reasons. Nothing else changed, so that review carries.
2026-09-09 15:42:36 +00:00
forrestjgq
f01231fef6 fix(cli): overhaul trajectory browser interaction ux (#379)
## Summary

Overhaul the interactive `raven trajectory` browser end to end, fixing
every
issue from real-terminal testing:

- Navigation: every screen opens with a help area under its title (page
  purpose plus "[Key] function" hotkey hints, rendered in a new readable
help color). Esc walks one level up (action -> attempt -> session); on
the
top-level session screen Esc stays put and quitting is Ctrl+C only,
which
prints a single exit notice. Esc inside a running action cancels just
that
action through a dedicated exception at the action boundary, so the back
  sentinel can never reach a conversion or the data layer; a cancelled
  report keeps its pre-confirm bundle-and-pin side effects (the existing
  declined-report contract). Back/Exit menu entries are gone; answered
  prompts erase themselves and navigation is echoed as breadcrumb lines
  with markup-escaped untrusted text.
- Tables: the session list is TITLE | ATTEMPTS | LAST ACTIVITY and the
  attempt list is # | STARTED | TURNS | SPANS | VERDICT | PIN | MERGED |
PREVIEW with green check cells. Time cells keep the year. The layout is
  budgeted per screen build from the live terminal width (row indent, a
safety margin, and inter-column gaps are all part of the math); PREVIEW
  drops as a whole column when it no longer fits, and below the dynamic
  minimum width the tightest layout is kept while the renderer clips
  overlong lines at the terminal edge. Every dynamic cell passes a
  single-line sanitization gate before width math (verdict sidecars only
  guarantee a non-empty string), cells are measured and truncated by
terminal display width (CJK is 2 cells), and fixed column widths always
  fit their headers.
- Space preview: Space on an attempt row prints that attempt's per-turn
input/output previews, collected in the same snapshot scan and sorted by
a fully-stringified key so ordering never follows log source order (the
  table PREVIEW cell derives from the same sorted collection). Any key,
arrow keys included, returns with the cursor kept on the row; the waiter
  passes the terminal's CPR reply through to the renderer instead of
  treating it as a keypress, and Ctrl+C keeps the browser-wide cancel.
- Merge hotkey: with two or more attempts, m/M opens the multi-select
merge
  (advertised in the help line; the old "Merge attempts" menu entry is
gone). The checkbox screen carries its own help line for toggle,
confirm,
  and cancel. A single attempt neither binds nor advertises the key.
- Theme and feel: new success (green check) and help (readable hint
text)
colors in both palettes, all WCAG AA on their backgrounds; a lone ESC is
flushed after 50ms instead of prompt_toolkit's 0.5s default, removing
the
  laggy Esc feel.

The data layer is untouched: changes are confined to
raven/cli/trajectory_browse.py, raven/cli/_theme.py, and their tests.
The
id-taking subcommands (raven trajectory save/list/...) behave as before.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- `COLORTERM=truecolor uv run pytest tests/test_cli_theme.py
tests/test_cli_trajectory_browse.py
tests/test_cli_trajectory_commands.py -q` -> 220 passed
- `COLORTERM=truecolor uv run pytest tests/ --ignore=tests/integration
-q` -> 6917 passed; the 10 failed + 20 errors are the pre-existing
environment-dependent set, identical file-by-file on a clean main
checkout (cron, everos server, config loader, tracing viewer)
- `uv run ruff check` and `uv run ruff format --check` on the four
touched files -> clean
- PTY smoke on a CPR-answering pseudo terminal at 100 and 58 columns:
full flow (preview, merge cancel, action screen, staged Esc backout,
Ctrl+C quit) and the narrow-width degradation contract
- New coverage includes real pipe-input key-binding tests (Esc on all
four prompt kinds, Space/m/M hits, waiter key paths with CPR
pass-through), table budget/clipping boundaries at the computed minimum
width, and corrupt verdict/timestamp corpora

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

## Risk

- The interactive browser's look and key protocol change wholesale (that
is
  the point of this PR): Esc no longer quits from the top level (Ctrl+C
  does), Back/Exit entries are gone, and lists render as tables. The
machine-facing subcommands and the trajectory data layer are untouched.
- Rollback: revert the squash commit; the browser returns to the
previous
  interaction wholesale, no data migration involved.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

N/A

---------

Co-authored-by: 江国庆 <guoqingjiang@deepglint.com>
Co-authored-by: Claude (claude-fable-5) <noreply@anthropic.com>
2026-09-05 23:58:20 +08:00
0xKT
e26ecfa90b feat(provider): expand provider catalog and settings experience
## Summary

- Add LM Studio, NVIDIA NIM, and separate MiniMax Global and MiniMax CN provider paths across configuration, routing, onboarding, and model discovery.
- Add bundled provider icons and accessible connected or disconnected status indicators to provider lists.
- Add provider homepage metadata to the RPC contract and link provider names in Settings, onboarding, and the model picker.
- Preserve the latest main branch per-model protocol metadata while mapping provider UI rows.

![image.png](/uploads/73442917d65ca16c07026e9017153777/image.png){width=876 height=600}

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed
- [ ] `uv run pytest tests/test_provider_catalog.py tests/test_rpc_model.py tests/test_rpc_schema_match.py tests/test_rpc_contract_shapes.py -x` - 534 passed, 4 skipped.
  * `npm test` from `ui-web/` - 1,378 passed.
  * `npm run type-check`, `npm run gen:check`, and `npm run build` from `ui-web/` - passed.
  * `npm run type-check` and `npm run lint:rpc` from `ui-tui/` - passed.
  * `.venv/bin/ruff check raven/providers/registry.py raven/rpc/methods/model.py raven/rpc/models.py tests/test_provider_catalog.py tests/test_rpc_model.py` - passed.
  * `make check-source-language check-large-files` - passed.
  * `git diff --check origin/main...HEAD` - passed.
  * Visually verified the assembled Settings and onboarding provider lists; repository rules prohibit committing standalone screenshots.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

The RPC homepage field is optional, and existing provider configuration remains compatible. Provider routing changes are covered by focused resolution, factory, and RPC tests. Roll back by reverting this feature commit.

## Related Issues

N/A
2026-09-08 06:05:27 +00:00
KevinHuSh
cee84a6f60 feat(provider): expand provider catalog and settings experience
## Summary

- Add LM Studio, NVIDIA NIM, and separate MiniMax Global and MiniMax CN provider paths across configuration, routing, onboarding, and model discovery.
- Add bundled provider icons and accessible connected or disconnected status indicators to provider lists.
- Add provider homepage metadata to the RPC contract and link provider names in Settings, onboarding, and the model picker.
- Preserve the latest main branch per-model protocol metadata while mapping provider UI rows.

![image.png](/uploads/73442917d65ca16c07026e9017153777/image.png){width=876 height=600}

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed
- [ ] `uv run pytest tests/test_provider_catalog.py tests/test_rpc_model.py tests/test_rpc_schema_match.py tests/test_rpc_contract_shapes.py -x` - 534 passed, 4 skipped.
  * `npm test` from `ui-web/` - 1,378 passed.
  * `npm run type-check`, `npm run gen:check`, and `npm run build` from `ui-web/` - passed.
  * `npm run type-check` and `npm run lint:rpc` from `ui-tui/` - passed.
  * `.venv/bin/ruff check raven/providers/registry.py raven/rpc/methods/model.py raven/rpc/models.py tests/test_provider_catalog.py tests/test_rpc_model.py` - passed.
  * `make check-source-language check-large-files` - passed.
  * `git diff --check origin/main...HEAD` - passed.
  * Visually verified the assembled Settings and onboarding provider lists; repository rules prohibit committing standalone screenshots.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

The RPC homepage field is optional, and existing provider configuration remains compatible. Provider routing changes are covered by focused resolution, factory, and RPC tests. Roll back by reverting this feature commit.

## Related Issues

N/A
2026-09-08 06:05:27 +00:00
TongLi31
63193e299a feat(agents): raven-code manifest over acp, real effort tiers, and the !512 fixes on trunk
## Summary

Retires raven-code's worktree isolation and moves its workspace report off the reply text and onto the ACP wire; gives raven-code real effort tiers named after the host's ladder; and ports the two engine fixes of MR !512 from the retired vendored fork to trunk `raven/`, which is the engine the `agents/raven-code` product actually runs (the host discovers `agents/*/subagent.json` only, so !512's fixes protected code the host no longer launches). Rebased onto main after per-model API protocols (4fe30b0a) landed; what that changed for this branch is called out below.

Three product decisions behind the first part: an unattended dispatch has nobody to answer the write gate's authorization question, so a dirty checkout parked the node until its timeout; the coordination between parallel raven-code sessions becomes a prompt-level contract, told only when it applies; and the host keeps getting a machine-read report of what each session did to the working directory, without reading it out of prose.

- Retire the write gate and its worktree isolation (`agents/raven-code/plugins/code-flow`): the gate, the worktree allocation and the release observer go, the launcher renders no arming, and the roster line stops promising an authorization prompt. The vendored A side under `subagents/` is frozen and untouched.
- Tell parallel sessions about each other: the code-flow hook books each session into a process-wide ledger at its turn start, and when other sessions are mid-turn in the same working directory it puts a concurrency notice in front of this turn's prompt (the model's view of this turn only). A lone session hears nothing. Parallel DAG nodes are sessions of one raven-code process on one directory, so the process can count them itself; the host has no per-node place to say it.
- Relay a turn's `acp_meta` observer stash as the prompt response's `_meta` (`raven/acp/methods.py`): the loop_hooks paper already files what a hook stashes under `metadata["observers"]` onto the turn's last substantive assistant message and saves the session before the turn's ending reaches the stream; the methods layer reads that entry back and answers with it under `_meta`, the field ACP reserves for an agent's own metadata. Only messages the turn appended are read; a turn that filed nothing answers exactly as before. Generic: nothing in `raven/` knows what any plugin puts there.
- File raven-code's workspace report through it: at the send the hook measures the directory against the base commit pinned at the session's first turn (root, branch, head, commits past base, working tree, diff stat, a status that is ready only when every fact answered) and stashes it as `raven.harnessManifest`. Nothing comes from model prose; a directory outside git is reported as plain. The report is workspace-scoped (`scope: workspace`): with no worktree, HEAD is shared by every session in the directory, so `baseCommit..HEAD` is what the tree gained since the session's base, by whoever wrote it. The ledger remembers which sessions shared a directory (peers, for the rest of their lives); a report from a session with peers carries `attribution: shared` and `sharedWith`, keeps the git facts, but takes the status `shared_workspace` with the blocker spelled out and is never ready. A lone session keeps `attribution: session` and the previous statuses.
- Keep the response `_meta` on the run record (`raven/acp_client/acp_agent.py`, `RunActivity.response_meta`): verbatim, namespaced as the agent sent it, as `acp_response_meta` -- so it reaches the spawn record's `meta.json` and the DAG run's per-node entry through the same channel as the frame pointer. The host reads none of it.
- Give raven-code real effort tiers on the agents/ tree, named after the host's ladder: the product had no tiers of its own and fell back to raven's three built-in rungs, which by design leave raven's own effort untouched, so a host asking for `medium` or `max` changed nothing about the model's reasoning (and the vendored twin's `low` / `high` / `max` catalogue was one the host's clamp refused to map `medium` onto). main now carries the engine side itself (4fe30b0a: `AcpModeConfig.reasoningEffort`, carried through the resolved profile and the session policy onto every model call of the turn; the built-in tiers leave it inherited and stay inert for raven itself), so this branch keeps only what main lacks there: the tools-disabled wrap-up call a turn makes when it exhausts its iterations asks for the same effort, plus the tests for the knob. On top of it the launcher declares `medium` / `high` / `max` with `medium` and `max` as overlays moving exactly `agents.defaults.reasoningEffort` and `high` as the baseline, and the LiteLLM provider mirrors the effort into OpenRouter's `extra_body.reasoning.effort`, which litellm's `drop_params` never touches -- without that mirror the effort could be silently dropped for any model litellm cannot map behind the gateway. Verified against OpenRouter's documented vocabulary (`max` / `xhigh` / `high` / `medium` / `low` / `minimal` / `none`; for Anthropic, thinking budgets of roughly 95 / 80 / 50 / 20 percent of `max_tokens` for `max` / `high` / `medium` / `low`).
- Never prefill a thinking-only turn on a model that refuses it (`raven/agent/loop/recovery.py`, `turn_path.py`, `raven/contracts/llm_provider.py`, `raven/providers/*`). Empty-response recovery re-fed a thinking-only response as a trailing assistant message; Anthropic rejects that request while thinking is on, and through the gateway the rejection arrived as a stream that never produced a byte, so the turn sat on the request budget (the 2026-09-01 dispatched-run report, item 1). Providers now answer `supports_assistant_prefill(model)` -- default True; `LiteLLMProvider` says no for the Anthropic family by the same rule that puts `thinking_blocks` on the wire, and the lazy / per-model / resolving / endpoint-rotor wrappers forward the question to the provider they wrap. The classifier consults it before the prefill budget: a refused prefill takes the post-tool nudge when a tool just ran, else the plain retry budget, else gives up, so no request handed to such a provider ends on an assistant message. Nothing changes for a provider that accepts the prefill. The native Anthropic Messages provider needs no answer of its own: it already rewrites a trailing assistant message into user-side text, so no request it sends ends on an assistant message.
- Give the LLM stream its own idle timeout (`raven/providers/litellm_provider.py`, `raven/contracts/llm_provider.py`, `raven/config/schema.py`, `raven/providers/factory.py`, `resolving_provider.py`). `chat_stream` waited the whole request budget for every chunk, so behind `llmCallTimeout: 1800` a dead stream cost half an hour (report item 2). `agents.defaults.streamIdleTimeout` (default 180s, 0 disables) decides whether the stream is dead and resets on every chunk; the request budget is enforced separately on top, so a backend that trickles forever is still bounded. Every wait in the LiteLLM stream -- the open, the first pull, the retry after a refused cache breakpoint, each later chunk -- takes the smaller of the idle line and what is left of the budget. Per-model protocols now route a claude model onto the native Anthropic Messages provider and a gpt model onto the OpenAI Responses provider by default, so the deployed raven-code route (OpenRouter, `anthropic/claude-opus-5`) no longer streams through LiteLLM at all; both native SSE consumers had the same single cap and take the idle line beside the budget too, and the Anthropic provider, the Responses provider and the Codex request helper hand their idle line to the consumer.
- Replay the incident end to end (`tests/test_agent_loop_incident_replay.py`): the real `LiteLLMProvider` built from `agents/raven-code/config.json`'s provider and defaults blocks, driven over the streaming call with `acompletion` faked to behave as the gateway did. The replay pins the model to the chat protocol, the transport the incident ran on (per-model protocols arrived later); the native providers' idle line has its own suite. Run against `origin/main` before the fixes it reproduces the incident (requests end on an assistant message and the turn waits out the scaled budget; a dead stream stalls for the whole budget; the deployed block arms no idle line). On this branch all four tests pass.
- The two provider shape changes are on the contract tier, so `CONTRACTS_VERSION` moves 7 -> 8 -> 9 with the ledger pin (main took 6 -> 7 for `ChatDelta.thinking_blocks`). `CONTEXT.md` gains Response Meta, Harness Manifest and Concurrency Notice, the Session Mode entry names its third knob, and the Empty-Response Recovery entry names the new question.

Deliberately not in this MR: a main-model-visible summary line of the report (dag_tool / manager), a capability declaration for the relay in the initialize handshake, and a report for a turn that failed or was cancelled (`after_send` does not fire there; the host sees the stop reason). Also not ported from !512: the turn-policy pin against a concurrent `session/set_mode` (the host sends `set_mode` before `session/prompt` and never during a running turn of the same session, so the race is unreachable in this deployment) and `extra="forbid"` on the `acp` config block (trunk's stated posture for such fields is warn-and-drop, and the raven-code launcher writes that block from code).

Known limit, same as in !512: the loop asks about the model the call was made for, so a routing fallback onto an Anthropic model mid-call would not be guarded (no routing is configured for raven-code, and the streaming path has no fallback).

Review round one on !529, three findings, all addressed here. (1) Blocking, effort did not cover compaction: the two head-summary calls transcript compaction pays for (proactive over the trigger line, reactive after an overflow) called `provider.chat` with no effort, so a `max` session that compacted mid-turn summarized at the connection's default; `_summarize_head` now takes the turn's effort and both call sites pass the policy the turn read at its start, with two tests driving a turn across the context limit. (2) Blocking, the report claimed shared commits: two sessions from one base, A commits, B does nothing, and B's `baseCommit..HEAD` listed A's commit as B's, even ready for integration; fixed by the workspace scope and attribution described above -- git alone cannot say whose commit is whose, so the report says whether it may be read as one session's at all. (3) Nonblocking, the ledger's in-flight mark was refreshed only at a turn's start and send, so a turn longer than the ttl vanished from the count its peers were told; the hook now refreshes the mark at every iteration, and the ttl keeps expiring only a turn that stopped reporting. The pipeline failure on the previous head was the test job hitting the runner's 45-minute limit ("Node is not ready" at about 43 percent), not a test verdict; the same job reproduced in the CI image on this head passes completely (see Verification).

Review round two on !529, one blocking finding, addressed here: the session effort still bypassed the in-turn watch-work classifier. After a relevant tool result the turn may pay for one more model call, the judgement of whether the request touches an on-call agent's watched path (two call sites in `_note_watch_work`: the look at a path, and the shape of a hand-off); both went through `_llm_call_stream` with no effort, so a medium/max session with an on-call watcher ran that classifier at the provider default. `_note_watch_work` now takes the turn's pinned effort and hands it to both calls, and the turn path passes the policy it read at its start; three unit tests read the kwargs each classifier call was made with, and one loop-level test checks the turn path hands the pinned effort to the helper for every tool result it judges. Left nonblocking, as the review marked them: a single provider or tool wait longer than the ledger's one-hour ttl still has no heartbeat inside it (the mark is refreshed at every iteration, not mid-wait), and the recovery-rung suggestion.

## Type

- [x] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- `uv run pytest tests/test_watch_work.py tests/test_agent_loop_session_effort.py -q` -> 75 passed (round two: the watch-work classifier is called with the pinned effort at both sites, nothing when none is pinned, and the turn path hands it over)
- `uv run pytest tests/test_agent_loop_session_effort.py tests/test_agents_code_flow_manifest.py tests/test_agents_code_flow_sessions.py tests/test_agents_code_flow_plugin.py tests/test_agent_loop_context_overflow.py tests/test_plugin_session_observers.py tests/test_agent_hook_contract.py tests/test_agents_code_launcher.py -q` -> 169 passed (the round-one fixes: the compaction summary carries the session's effort across the context limit; a shared directory turns the report to `shared_workspace` and unready; a long turn stays counted)
- `uv run pytest tests/test_agent_loop_incident_replay.py tests/test_providers_native_stream_idle.py -q` -> 19 passed; the replay file against a clean `origin/main` worktree -> 3 failed on exactly the incident's three symptoms (four requests in a row end on an assistant message; the dead stream stalls for the whole scaled budget; `GenerationSettings` has no idle line), 1 passed
- Targeted suites on the rebased branch (`-p no:xdist`): code-flow plugin / sessions / manifest, both launchers, `test_acp_methods` / `test_acp_modes` / `test_acp_server`, `test_subagent_acp` (against the real stub server, which gained a `meta` mode that answers a prompt with `_meta`), `test_agent_loop_session_effort` / `test_agent_loop_iteration_hooks`, `test_litellm_provider_reasoning`, `test_agent_hook_contract` (the hook surface fingerprint is unchanged; the relay reads an existing seam), `test_contracts_two_tier_ledger` (the pin at 9), `test_plugin_tool_gates` / `test_plugin_session_observers`, `test_agent_loop_empty_recovery` (13 new tests), `test_litellm_provider_timeout` (5 new), `test_litellm_provider_stream`, `test_provider_stream_fallback`, `test_providers_factory`, `test_resolving_provider`, `test_openai_codex_provider`, `test_provider_protocol`, `test_agent_loop_context_overflow`, `test_watch_work`, `test_agents_oncall_flow_hooks` -> 888 passed
- `make lint-python` green; `make lint-imports` -> 8 contracts kept, 0 broken; `make check-large-files`, `make check-vendored-subagents` and `make check-vendored-invariants` green (nothing under `subagents/` changed); `git diff --check` clean
- The CI `tests` job reproduced locally in its own image and command sequence (`python:3.12-slim`, `uv sync --locked --all-extras --dev`, `uv run --all-extras pytest -q`, four xdist workers) on this head -> 19250 passed, 192 skipped, 0 failed in 5m40s. The pipeline on the branch's first head died with the runner's node ("Node is not ready" at about 43 percent, then the 45-minute cap hit during after_script and cleanup), not on a test verdict: the same job reproduced on that commit (a78636b3, a real clone) -> 19014 passed, 0 failed, and pipeline 2826205430 on the round-one head passed.
- Full host suite (`make test-python`) on the rebased branch -> 19269 passed; the failing set is the pre-existing cron timezone family only (6 failed + 20 errors, no tzdata on the machine), nothing else

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

## Risk

Behaviour changes for raven-code: no more first-write authorization prompt and no worktree; parallel sessions on one directory can write the same file, and are told so; a host `medium` or `max` session now actually changes the model's reasoning effort (it used to change nothing), and every OpenRouter-routed request carries the effort in the gateway's own `reasoning` object. The prompt response of a raven-serving-ACP agent gains a `_meta` key only when a hook filed one; existing clients that read `stopReason` alone are unaffected (the ACP schema declares `_meta` on the response). The host's run records gain one optional key. The workspace report's `readyForIntegration` is false whenever another Raven-Code session shared the directory, so an integration step reading it must expect `shared_workspace` on parallel DAG nodes and handle that case itself.

Behaviour changes for every raven-serving product on trunk, not only raven-code: a thinking-only empty response on an Anthropic-family model is now retried or nudged instead of prefilled (previously a hang behind a gateway, a 400 direct); a stream silent for 180s is reported as a timeout instead of waiting out `llmCallTimeout` (a backend that stays silent while thinking for longer than that needs `streamIdleTimeout` raised or set to 0) -- on the LiteLLM path and on the native Anthropic Messages, OpenAI Responses and Codex paths alike. Providers that accept a prefill and streams that keep producing bytes see no change.

Rollback is a revert of the branch's commits.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

Follows MR !512, which carried the same two engine fixes on the retired vendored line under `subagents/`; the host no longer launches that line.

Co-authored-by: Claude (claude-fable-5-1) <noreply@anthropic.com>
2026-09-08 06:04:58 +00:00