Skip to content

Let producers settle windows when act output completes - #51

Merged
asher-aqi merged 3 commits into
mainfrom
feat/settle-on-act-end
Nov 27, 2026
Merged

asher-aqi merged 3 commits into
mainfrom
feat/settle-on-act-end

Conversation

@asher-aqi

@asher-aqi asher-aqi commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

A fixed closing grace can wake an agent before output arrives or keep it waiting after output is complete.

  • A closing event can set quietForMs. The closing deadline is the latest of the default grace for closing events that omit the field and each explicit observation time plus its duration.
  • A consequence can set settles: true to end the acts already in the open window through push, attach or serial intake. It can end an active continuous stream with reason closing and wait still eligible. After a wait, a fresh act must precede the marker. Accumulating retries keep their strict deadline.
  • Reducer revision 7 retains the fields through snapshots, tails, replay and decisions. Upgrade shared-store readers and writers together before using the fields.

Evidence

  • The new regressions reproduced refusal of closing durations and a completion leaving a live stream pending. Both pass now.
  • TypeScript on Node 22 passed pnpm check with 1,671 tests passed and two existing Redis poll cases skipped. All 128 oracle tests and eight shared fixture checks passed.
  • Python 3.12 passed all 517 tests with Redis, Postgres and cross-runtime interop enabled. All 177 shared conformance tests passed. Ruff, Ruff format and Pyright passed.

Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment thread src/core/reducer.ts Outdated
Comment on lines +131 to +132
if (entry.kind === 'consequence' && entry.settles === true && state.open.summary.firstActIndex !== -1) {
state.open.endedAt = observationTime(entry);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Replay closes legacy windows early

After an upgrade, ingest treats legacy settles: true metadata in a stored consequence as a completion signal. Replay applies the new rule to old inputs. The judge misses output that arrives within the original grace period.

Learn more

Before revision 7, event copying preserved extra top-level fields without interpreting settles. The NDJSON event parser also forwards those fields to the engine. A snapshot records the open window at a checkpoint; its tail contains the accepted inputs since then. Replay uses the snapshot's policy but applies the current reducer to the tail, and scope loading schedules the resulting state. This turns an old consequence's metadata into an end deadline, even when every process has upgraded and no producer uses the new feature. Python replay has the same behavior with _ingest.

Example: A revision-6 writer accepts a save at 100 ms and a consequence with application metadata settles: true at 110 ms. With a 500 ms closing grace, the saved window is due at 600 ms. Restarting on revision 7 at 110 ms with the consequence in the tail makes it due at 110 ms. The judge sees the save and that consequence, but the real output at 120 ms lands in a background-only window instead of joining the save.

Recommended fix: Preserve revision-6 settlement semantics when replaying a pre-7 tail. Keep legacy metadata in the payload without treating it as control data. Apply the new interpretation only to inputs written under revision 7, and add upgrade tests in both runtimes that verify the deadline and judged payload.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 74b837a. replay now gives settles its meaning only when the tail sits under a snapshot taken at revision 7 or later (or under no snapshot). A tail logged under an older snapshot keeps the field as plain metadata, so the old closing grace stands. There's a regression test in each runtime (test/closing-settlement.test.ts, python/tests/test_closing_settlement.py), and docs/storage.md says so. quietForMs on a closing event can't appear in an older tail, because revision 6 refused it at admission.

A tail replayed under an older snapshot was written by a reducer that gave
settles no meaning, so it stays plain metadata there instead of ending the
window early. Both runtimes, with a regression test in each.
@asher-aqi
asher-aqi merged commit 082e1ea into main Nov 27, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant