11 Commits

Author SHA1 Message Date
kongxin
5426576fa5
fix(agents): run the calls that fit when a batch crosses a per-tool loop limit (#8267)
* fix(agents): run the calls that fit when a batch crosses a per-tool loop limit

One model response with 50 or more calls to the same tool lost every
call: the per-tool frequency check stopped the run before any of them
ran (#8214).

- A per-tool limit now drops only the calls that would reach it; the
  calls within the limit run. A response in which no call fits still
  stops the run, and the identical-call hard limit still rejects the
  whole batch.
- The capped tool stays blocked for the rest of the execution, whatever
  the frequency window counts. The cap is a record in the private
  loop_cap state channel, so it survives an approval pause, the resume's
  new run_id, a Gateway restart and context compaction. before_agent
  expires a record another run left behind, which gives a later task a
  fresh budget.
- The run is loop_capped from the first dropped call, in the run record
  and in a subagent result. A resumed run is marked again from the
  record.
- The model is told on its next call how many calls were skipped and how
  many were passed on, followed by the wrap-up instructions. The notice
  is read from the record on every model call and cleared once the model
  has answered.
- The Gateway treats loop_cap as a server-owned state channel.
- middleware:loop_detection gains the action reject_excess.

* fix(agents): count after the window eviction and keep the cap record readable

Review follow-up for #8267:

- A call reaches a per-tool limit when the window would hold that many
  calls to its tool after taking the call in and dropping its oldest
  entry, as on main. Counting before the eviction rejected a call that
  only replaced an older call to the same tool, so 49 reads, one other
  call and one more read capped read_file where main admits 49 more.
- The cap record holds only what its reader accepts. A tool whose name
  the reader would reject, or one past the record's size bound, is left
  out instead of making the next read discard every cap in the record.
  The record and its notice are still written, so the drop is explained
  and the execution stays loop_capped.
- A dropped batch is audited once per tool that reached its limit in it,
  with that tool's own count and threshold.
- Tests: a seeded comparison against a plain sliding window, the
  interleaved sequence, unnameable and overflowing records, and the
  per-tool audit rows.

* fix(agents): report a partial loop cap when the run ends, not mid-run

Review follow-up for #8267. runtime.context["stop_reason"] is read in
two ways: the worker and Goal continuation read it when the run is over,
while run-input admission, the todo middleware and end-of-graph input
handling read it mid-run as "the run is ending" and skip their checks.
A partial cap wrote it at the first dropped call, while the admitted
calls of that response still had to run, so those calls skipped the
checks:

- input that arrived during inference no longer cancelled the planned
  calls, so obsolete writes ran after a steer;
- two parallel write_todos calls both ran, each replacing the plan;
- input that arrived as the run finished was dropped.

A response with no call left is still a terminal stop and is reported
at once. A partial cap is reported to the subagent channel at once and
to the run context by after_agent, which runs after the end-of-graph
input handling; another guard's earlier reason is kept. A run that
pauses for approval no longer reports a reason; the run that resumes it
reports loop_capped when it ends.

Tests drive the three cases through real compiled graphs in the lead
chain's middleware order.

* fix(agents): undo a discarded response's loop accounting and report the guard that stopped the run

Third review follow-up for #8267.

- A response whose admitted calls another middleware discards before any
  of them runs (input admission on a steer, approval on calls it cannot
  address) no longer leaves a cap or counts toward a limit. As the next
  model call starts, the frequency window, warnings and cap record go
  back to their state before that response; caps from earlier responses
  stay. Before, a steer whose replacement needed the same tool had that
  write dropped as already capped. The undo runs in wrap_model_call, not
  a before_model hook, so no graph node is added and lead runs do not
  spend an extra super-step per turn of their recursion limit.
- A partial cap reports to both channels only when the run ends, and
  only when no other guard has given the reason it stopped. A subagent
  that a later token-budget stop ended now reports token_capped, as its
  run context does, instead of loop_capped.

Tests drive the steer cases through compiled graphs with real input
admission, including a replacement that uses the capped tool and an
earlier cap that must survive the undo, and the token-budget case sync
and async.

---------

Co-authored-by: AochenShen99 <sac1063467113@hotmail.com>
2026-11-18 14:28:36 +08:00
spud
33f7b43400
fix(runtime): backfill run.terminal after confirmed recovery takeover (#7500)
* fix(runtime): backfill run.terminal on confirmed recovery takeover

* fix(runtime): isolate recovery terminal publication failures

* fix(runtime): fence recovery terminal publication lifecycle

* fix(runtime): unify recovery receipt publication

* docs(runtime): document lifecycle guard lock constraints

* fix(runtime): reuse event transaction for recovery guards

Read Run lifecycle through the active event session when SQL stores share an engine, preserving deletion fencing without a second pool checkout. Keep custom lookups and different engines on their ordinary read path. Scope memory recovery guards and deletions to per-thread locks. Add SQLite/PostgreSQL pool pressure, stale identity, fallback, and independent-thread regressions, and document the contracts.

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-25 23:22:02 +08:00
spud
e9074b7126
feat(runtime): publish owner-confirmed run.terminal evidence (#7134)
* feat(runtime): publish authoritative run terminal events

* fix(runtime): preserve terminal attribution diagnostics

* docs(runtime): consolidate terminal event docs and trim agent guidance

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-25 00:12:26 +08:00
trent87
0d73798beb
feature(skills): keep allowed-tools as compatibility metadata (#6935)
* refactor(skills): keep allowed-tools as compatibility metadata

* docs(skills): align current guides with agent tool authority

* test(skills): simplify authority regressions and sync Korean docs
2026-10-20 19:34:28 +08:00
Hyeonsang Cho
d3887531e9
docs: list the summarize event tag and scope the extension example's claims (#6582)
* docs: list the summarize event tag and scope the extension example's claims

RUN_EVENT_STREAM.md listed seven middleware tags, but the catalog and the
run event stream contract carry eight; `summarize` is emitted by
SummarizationMiddleware for every successful summary result. Add the tag,
describe the event, and pin the documented list to MIDDLEWARE_EVENT_TAGS so
the next tag cannot drift silently. summarization.md now lists all eight
`changes` fields of that event.

The extension example said it showed all five (README, pyproject, module
docstrings, test name) or every contribution kind, while ExtensionRegistry
has eight. Say it demonstrates five, name the three it does not, point to
the observers guide and the bookmarks plugin, and assert in the example's
test that the two observer kinds stay unregistered.

* docs(changelog): reference #6582

* docs: clarify extension example package layout scope

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-10 08:04:01 +08:00
yu1128-L
5ecc1c2ac2
docs(events): document durable thread seq watermark (#6532)
* docs(events): document durable thread seq watermark

RUN_EVENT_STREAM.md described seq as monotonic but did not cover the durable per-thread high-water mark that keeps allocations monotonic after a run is deleted. Record that behavior in the Record Envelope section, including that thread deletion drops the mark only when no events remain.

* test(scheduler): pin clock for scheduled-run timezone assertions

---------

Co-authored-by: yu1128-L <296164533+yu1128-L@users.noreply.github.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-10-09 08:10:41 +08:00
PeaceMaker-best
14c9d44440
feat(runtime): persist tool-progress phase transitions (#5214)
* feat(runtime): persist tool-progress phase transitions

Record bounded warn, block, and recover decisions for lead and task subagent runs while preserving event-loop isolation, fail-open behavior, and concurrent transition order.

* fix(runtime): trust server-owned tool progress attribution

* fix(runtime): centralize trusted audit attribution

* fix(runtime): preserve complete tool progress audit state

* docs: trim tool progress guidance to pass size check

* fix(runtime): fence subagent audit recorder loop

* docs(readme): sync tool-progress event coverage

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>

---------

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>
Co-authored-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>
Co-authored-by: 嗜鵼 <hy2010hy2010@qq.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-09-15 08:45:08 +08:00
PeaceMaker-best
3c36217a51
feat(observability): persist deferred tool promotions (#5183)
* feat(observability): persist deferred tool promotions

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>

* fix(ci): trim agent guidance chain

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>

---------

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>
Co-authored-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>
2026-09-05 14:03:00 +08:00
AoHanBei
9b32b5d841
feat(observability): persist loop detection events (#5127)
* feat(observability): persist loop detection events

* fix(observability): persist subagent loop events

* fix(observability): narrow subagent loop event bridge

* fix(observability): attribute subagent loop events

* fix(tests): isolate subagent executor imports
2026-09-02 10:25:37 +08:00
Nan Gao
58befaf248
fix(thread-history): keep completed subtask cards stable after reload (#4432)
* fix(thread-history): hide subagent AI responses

* refactor(thread-runs): remove unused _is_middleware_message_row helper

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-07-25 09:29:11 +08:00
MiaoRuidx
f1632cc351
fix(run): add run event stream contract (#4342)
* docs: document run event stream contract

* fix(run): address event stream review feedback

---------

Co-authored-by: MiaoRuidx <12540796+MiaoRuidx@users.noreply.github.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-07-23 21:33:57 +08:00