Repository navigation
Kit: gate a tray in chunks; reply turns start from the served reply_turn_template - #24
Merged
Merged
Conversation
…e contract (reply_turn_template) The contract fixtures gain reply_turn_template in texts.sample.json (contract v1, section 3.6). Both files are copied byte for byte from the contract source; every other fixture, gate-prompt.expected.txt included, is unchanged. The conformance test checks that the sample carries the template and names the conversation by <conversation_id>.
…ts from reply_turn_template Gate chunks (contract v1, section 3.6). In gate-call mode the receive loop sent up to 50 cards to the model in one call. Integrations cap that answer at 2,048 tokens and 50 answers need about that, so a cut-off answer failed to parse, nothing was recorded, the tray never shrank, and the agent stayed stuck. - New option gate_chunk_size (None: 10; an int from 1 to 50, validated in either mode). The cards to gate are split in tray order and gated one call after another; each chunk's prompt is the section 3.6 prompt with N = its own cards, so a tray of 10 or fewer is exactly the prompt of before (gate-prompt.expected.txt through the loop, byte for byte). - Each call has its own gate_call_timeout_ms deadline and its own cancel handle (asyncio.Event or threading.Event), set by its deadline or with the cycle's stop or abandonment; a chunk past its deadline tells only its own call. A failed, timed-out or unparsable chunk leaves only its own cards undecided; every chunk that parsed is recorded. - The watchdog no longer counts time inside a gate call that has a deadline (a tray in k chunks may take k deadlines); with the deadline off the calls still count. - Before each call the chunk is checked again for cards a turn took since the tray was read (a shared tracker); they count as held_by_turns and are read again once the turn ends. - Reply turns start after the last chunk, so no turn runs while cards of the cycle still wait for their gate call. A reply's card and anchor are the ones its chunk's gate saw (turn_outcome reads the fresh tray against that card). - A partial failure shows: a gate_chunk event per call, chunks_ok and chunks_failed in the cycle summary and in status().counters, and the summary's failure names how many chunks failed and the first reason. fail_closed now means every chunk failed. A call stop() cut short is not a failed chunk; the abandoned summary reports what was done. Reply-turn prompt. A reply turn started from the served wake instruction, which sends a run to the whole tray, so one card's turn could answer another and that card's own turn answered again. It now starts from the served reply_turn_template with every <conversation_id> replaced by the card's id (reply_prompt). Texts without a usable template (an older server, a cached copy, a template without the placeholder) keep the previous prompt. Texts gains the optional field; TextsCache keeps it. Invite turns are unchanged. The abandoned-cycle test now turns the gate deadline off: a call with a deadline of its own no longer counts against the cycle's.
- gate_chunk events carry `cycle`, the cycle's token (unique and increasing within the loop, not consecutive); the cycle summary does not. - A chunk left with muted cards only (or emptied by the per-chunk held check) costs no call: no event, neither gated nor undecided; `of` stays the planned count. Muted cards in a chunk with an owed card are still gated with it. - stop() part-way through a chunk's recording: each card counts once, as its verdict or as undecided (gated = reply + dismiss + defer + undecided). A call the stop cut short is not a failed chunk. - A cycle the watchdog abandoned emits no further gate_chunk event and counts no chunk. - The failure text: one call made gives its bare reason, also when other planned chunks were skipped; otherwise "<failed> of <calls made> gate chunks failed; chunk <planned index>: <reason>". - A served reply_turn_template without <conversation_id> is still used, stripped, with "\n\nconversation_id: <id>" after it; only an absent, empty, blank or non-string value falls back to the wake instruction. - The gate-call deadline and the watchdog run on the loop's set_timer and clock (now when given, else monotonic, as before), so tests move them by hand; at the deadline the call is cancelled and no longer waited for. The deadline and watchdog tests now run on a fake clock with margins in seconds; the three tests that fake set_timer for other reasons turn the deadlines off.
…unks, the failure text, the template without a placeholder, gate_call_timeout_ms above cycle_timeout_ms)
…ad; the watchdog's clock stated; deadlines printed as integers
- A test that a deadline no longer waits for the call: an async call_model
that swallows CancelledError ends its cycle at the deadline (fail_closed),
and its late answer is not acted on. A regression that waits for the
call fails it instead of hanging it.
- A test that every owed card taken by a turn before its chunk gives
nothing_owed with no call (owed cards only, and with muted ones left).
- A test that a card held mid-gate is read again when a turn of the loop's
own ends: it is gated in the next cycle.
- The watchdog's clock, stated accurately: before this branch it was
always monotonic and ignored `now`; now a `now` that is given is its
clock too, so a wall-clock `now` makes the watchdog wall-clock (class
docstring, module docstring, CHANGELOG).
- Deadlines in failure texts are printed as integers ("no answer within
1200000 ms", not "1.2e+06 ms"), as the TypeScript kit prints them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Python twin of agentchat-typescript #23 (same names modulo casing, same semantics). Hermes builds on this kit in gate-call mode.
Gate in chunks. The loop sent up to 50 cards in one tool-less gate call; Hermes caps that answer at 2,048 tokens, about what 50 answers need, so a full tray failed closed on every wake and never drained. Now cards are gated in tray order in chunks of at most
gate_chunk_size(default 10, 1..50), one call each with its own deadline and cancel handle; a failed chunk leaves only its own cards undecided and the others' verdicts are recorded. A tray of ≤10 cards gives exactly the old prompt (gate-prompt.expected.txt). A chunk of only muted cards makes no call. Newgate_chunkevent (with the cycle token),chunks_ok/chunks_failedin the summary and status counters. At a deadline the call is no longer waited for. Time inside deadline-bound gate calls no longer counts against the watchdog; anowpassed to the loop is now the watchdog's clock too (CHANGELOG states both).Reply turns. A reply turn starts from the served
reply_turn_template(live since core #183) with<conversation_id>filled in, so the turn handles one conversation instead of re-triaging the tray. Older texts fall back to the previous composition.Conformance:
texts.sample.json+manifest.sha256copied byte-identical from the published contract.Verified: ruff + mypy + pytest clean on Python 3.9, 3.10, 3.11, 3.12, 3.13 (781 passed each); two independent reviews (mutations of every review fix caught); Hermes main's 707 tests pass against this branch.
Known follow-ups (pre-existing, not changed here): a plain
call_modelthat ignorescancelkeeps its worker thread past the deadline;stop()with the gate deadline off waits for a call that ignores cancellation.