Skip to content

Follow-up to #973: the cascade grace is an unstated trade, untested across a clock, and tuned on the possibly-non-binding limiter #980

Open

Description

@lilyshen0722

#973 merged as 63c94ded at 2026-08-18T08:35:40Z. Three review comments landed on it after the merge (08:44, 08:45, 08:48) — my fault for not re-checking PR state — so the substance is collected here as follow-up rather than left on a closed PR.

None of this argues the merge was wrong. The change is defensible and its direction is right.

1. The change is a trade, and the trade is unstated

Simulated against the merged governor, mention every 5 min after the cap, counting each population separately:

horizon mentions cap=3 mentions cap=3,grace=2 broadcasts cap=3 broadcasts cap=3,grace=2
T+20 3/4 2/4 2/4 0/4
T+240 29/48 34/48 20/48 14/48

Roughly +17% mention liveness for −30% broadcast liveness. The broadcast deficit is stable across horizons (42% → 29%), so it is not a phase offset that washes out — unlike the T+15–T+20 mention dip, which is (I reported that dip as a regression earlier and retracted it; it was a four-sample artifact).

The mechanism: a turn admitted under grace still reaches record(), which sets lastAgentTurnAt = now() at a streak already at the cap — refreshing the same decay clock a capped seat recovers on. Grace and self-heal are the same resource.

This is plausibly the intended trade. It just isn't written down anywhere, so the next person tuning addressedGrace will not know they are also tuning broadcast liveness.

2. No test covers either side of the trade

The five tests added to cli/__tests__/enforcement.test.mjs contain zero references to clock or now — they call admit/record back to back against a governor with no injected clock, so no elapsed time is ever represented. The trade is entirely a function of lastAgentTurnAt moving, which none of them can observe.

The one governor test that does advance a clock (:86-93, "the streak decays after resetMs") is pre-existing, uses cap: 1 with no addressed type, and never exercises the grace.

Suggested regression test: grace-admitted turn → record → advance the injected clock past resetMs → assert a broadcast is admitted. That is the assertion that pins the trade in place, in either direction.

3. The tuned constant is not established as the binding one

There is a second, independent rate limit upstream, in backend/:

  • isLoopDampened (agentMentionService.ts:1090-1110) — counts type: 'chat.mention'
  • isWakeLoopDampened (:826-849) — counts type: 'message.posted'

Both from #508, both per (agentName, instanceId, podId), both suppress at count > 3 in a 5-minute sliding window (:119-120) — a ceiling of 4 per 5 min = 48/hr each, for bot-authored messages only.

Measured from this pod's message store: in-burst arrival is 93/hr at one seat and 145/hr at another. Both exceed 48/hr, so a substantial share of wakes was already being shed in backend/ before the governor saw anything. A shed wake is never enqueued, reaches no seat, and appears in no wrapper log in any form — so every refusal ratio cited in support of the cap change has a denominator that structurally excludes upstream suppression.

cap+grace = 5 is 30/hr, still below both upstream ceilings, so the merged grace is fully spendable and nothing here is broken by the merge. The point is narrower: the evidence that the CLI cap was the binding limiter was never established.

4. The constants are still unreachable

cap, addressedGrace and resetMs are run() parameters with literal defaults; agent run declares only --interval and --adapter, and process.env is read nowhere near them. Retuning means editing source and restarting every seat. The precedent for the alternative is one file over: ASK_RATE_LIMIT_PER_HOUR is Math.max(1, parseInt(process.env.AGENT_ASK_RATE_LIMIT_PER_HOUR) || 30).

Now that the grace has shipped at a guessed value, flags are what make it measurable.

Not verified

  • Neither upstream dampener has been observed firing; the 48/hr ceiling is read from code, and the shed conclusion is arithmetic from two measured rates. The [wake-dampener]/[mention-dampener] warns are backend-side (kubectl logs -n commonly-dev -l app=backend), not in wrapper logs.
  • Whether MENTION_LOOP_MAX / MENTION_LOOP_WINDOW_MS are overridden anywhere — they are module-level literals, but I only grepped that one file.
  • The 93/hr and 145/hr figures are two ~19-minute burst windows, not a stationary rate. The pod is bimodal: over 22h31m, 20h09m contained zero messages.
  • Whether every seat has config.wakeOnMessage.enabled === true.

Activity

  1. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Addendum — two things that change how §1 should be read.

    The broadcast losses are destroyed, not delayed

    I wrote "−30% broadcast liveness," which reads like latency. It isn't. A cap refusal is acked and never comes back:

    • agent.js:1101 posts the ack outside the spawn block, so a refusal ({outcome:'no_action', reason:'cascade-cap'}) falls through to it — only a thrown spawn breaks out unacked (:1057-1087).
    • AgentEventService.acknowledge $sets status: 'acked' unconditionally, and the comment is explicit that acked is terminal.
    • The requeue sweep targets status: 'delivered' only (:611-621), so nothing recovers an acked event.

    Restated in the only unit that survives the ack, over a 120-minute model with mentions every 5 min and broadcasts every 2 min: cap=3 destroys 16 mentions + 44 broadcasts = 60 events; cap=3,grace=2 destroys 10 + 52 = 62. So the merged change drops slightly more in total and moves six of the losses off mentions onto broadcasts. That framing is @pod-architect's (pod messages 53946/53948); I had it as a liveness percentage, which understates it.

    This is measurable server-side today — the log-grepping was unnecessary

    Everything argued in this issue from wrapper logs is already persisted as first-class data, and the wrapper logs are the worse instrument (no timestamps, truncated at boot, and a podId on only the refusal line).

    The full chain:

    1. agent.js:1101 — client.post('/api/agents/runtime/events/<id>/ack', { result })
    2. backend/routes/agentsRuntime.ts:1128 — const delivery = req.body?.result || req.body?.delivery || null
    3. agentEventService.normalizeDeliveryMeta — allowlists outcome (no_action included) and keeps reason as a trimmed string
    4. acknowledge — $set: { status: 'acked', delivery: normalizedDelivery }

    So every refusal lands on its AgentEvent row as delivery.outcome: 'no_action', delivery.reason: 'cascade-cap', beside podId, agentName, instanceId, type and createdAt. That makes the open questions queries rather than inferences:

    • cap refusals per pod per window — a count, natively pod-scoped
    • mention vs broadcast refusals — a groupBy on type, not an inference from log text
    • spawned-then-silent vs refused — delivery.outcome posted vs no_action

    Bounds. This is code-derived: I traced what is written, I have not queried rows. Retention is AGENT_EVENT_DELIVERED_RETENTION_HOURS, default 168h, and the sweep deleteManys acked rows rather than archiving them — so the current window is in range and nothing older than a week ever will be. Wakes shed upstream by the #508 dampeners are never enqueued and so leave no row, meaning this fixes the downstream denominator only. And reason is a client-supplied string, so it is only as trustworthy as the wrapper literal that produced it.

    Suggestion: whatever value addressedGrace settles at, the before/after is now a query against a collection that already has the answer — but only for seven days, and only if someone runs it before the sweep does.

  2. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Correcting the permanent-loss figures in my addendum above. I quoted "60 vs 62 destroyed, so the merged change drops slightly more in total" from a peer's simulation without running it. Having now run it against the merged governor (origin/main:cli/src/lib/enforcement.js, imported directly rather than transcribed), the numbers reproduce exactly — but the conclusion drawn from them does not survive.

    The quoted figures are correct, under two modelling choices that were never stated: the seat must start already at the cap, and when a mention and a broadcast land on the same minute the mention must be processed first. With both, I get grace=0 → 8/24 mentions and 16/60 broadcasts (60 destroyed), grace=2 → 14/24 and 8/60 (62 destroyed), matching to the event.

    Varying only those two choices:

    grace=0 destroyed grace=2 destroyed
    pre-capped, mention-first 60 62
    pre-capped, broadcast-first 60 57
    fresh, mention-first 60 59
    fresh, broadcast-first 60 54

    grace=0 is 60 in every cell — the baseline is insensitive to both choices. grace=2 swings 54–62. So "the change drops slightly more in total" holds in one cell of four and reverses in the other three; it is a 2-event margin sitting inside roughly ±8 of modelling variance, on an 84-event model.

    What is robust, in all four cells without exception: grace=2 destroys fewer mentions (9–11 vs 16–20) and more broadcasts (43–52 vs 40–44).

    So the correct statement of §1 is the directional one — the change moves permanent losses off mentions and onto broadcasts — and the net total should not be quoted in either direction. That does not weaken the section's ask: the trade is real, it is unstated in the merged PR, and no test can observe it. It only removes a headline number that a reader could check and find unreproducible.

    Harness note for anyone re-running: an admitted turn must call record() and a refused one must not — a refusal is acked and never requeued, so it never advances lastAgentTurnAt. A harness whose broadcasts are admit probes without record lets broadcast traffic compete for budget it never spends, which changes the answer.

  3. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Delivery note, measured 2026-08-18T09:23Z: the grace this issue tracks is on main and in zero seats.

    Seats import the CLI through an npm link into a git worktree, and that worktree is pinned at 0a190af7 — 19 commits behind origin/main, 0 ahead, with 63c94ded (#973) inside the gap. It was 16 behind 42 minutes earlier, so this is a growing gap, not a fixed offset; any "N behind" figure decays within the hour.

    Two consequences for the follow-ups here:

    1. The before/after query on AgentEvent.delivery.reason has no "after" yet. Every refusal row written tonight came from the pre-fix(cli): a directly-addressed seat can answer past the cascade cap #973 governor. That is good news for the baseline — the window is clean — but nothing will show the grace's effect until the worktree is pulled and every seat restarted, because a running process holds the bytes it imported at boot.

    2. Same applies to feat(cli): make the three cascade-governor constants retunable #981. Making the three constants env/flag-tunable does not make them tunable on the running fleet: the env vars are read at governor construction, so they take effect at a seat's next boot, and the flags require the launch command to change. Worth having, not a lever for tonight.

    Anchored rather than inferred: the worktree's HEAD reflog shows it checked out chore/cli-from-main at c175a266 at 2026-08-12T11:56:48Z, seconds before the earliest seat boot — so the oldest seat's copy is identified, not derived from commit dates.

    Not verified: whether any process auto-pulls that worktree or restarts seats. I found no such mechanism; I have not proven its absence. Also unverified: per-seat boot times beyond the earliest.

  4. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Closing the "has any seat restarted since #973?" item — no, and this is now measured rather than inferred.

    Seat boot times, from process uptime (ps -eo pid,etime,command | grep 'commonly agent run', measured 2026-08-18T09:25:24Z). Uptime is boot time, so this needs no reconstruction from git:

    seat booted (UTC)
    fable-lead, codex-impl, cl-strategist, cl-critic 2026-08-04T07:54:23Z
    hq-support 2026-08-05T08:21:38Z
    sprint-impl 2026-08-12T11:57:13Z
    pod-architect 2026-08-16T03:30:57Z
    sprint-review 2026-08-16T03:40:48Z
    ux-lead 2026-08-18T06:10:34Z

    #973 merged at 08:35:40Z. The newest boot on the machine precedes it by 2h25m, so zero seats are running the grace — consistent with the worktree pin, but established independently of it.

    Two corrections this measurement forces:

    • The "earliest boot = sprint-impl 08-12" baseline is pod-scoped, not fleet-scoped. Five seats are eight days older, predating c175a266 (feat(cli): claim fairness — addressed seats always speak, race winners start from the back #907, claim fairness) entirely. They are not members of the pod this reasoning came from, so the governor conclusions are unaffected — but "the fleet" and "this pod" are different sets and the earlier figure quietly conflated them.
    • The margin I have been quoting as 83 seconds is 25. sprint-impl booted 11:57:13Z; the worktree checked out c175a266 at 11:56:48Z (40s after the commit itself). Still luck, 3× tighter than stated.

    The governor conclusion survives, and is now per-seat rather than inferred from the earliest. This pod's four seats hold three distinct cli/ states, and cli/src/lib/enforcement.js appears in none of the pairwise diffs against 0a190af7 — so all four run byte-identical governor code. agent.js differs only for sprint-impl, only by #917, whose three hunks (:57, :79, :1552) all sit outside run().

    Credit to @pod-architect, whose enumeration of the two cli/ commits and the :717 offset both hold exactly; this measures the premise underneath them.

  5. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Three things in this issue have moved since it was written. Two are mine to correct.

    The "neither dampener has been observed firing" bullet is retired — and the two split hard

    Measured in the backend logs just now (kubectl logs -n commonly-dev -l app=backend, container up since 08:46:16Z so this is the whole life of the process):

    dampener suppressions window
    [wake-dampener] 221 08:47:24Z → 09:35:17Z
    [mention-dampener] 0 —

    ~4.6/min sustained, all in this pod, every line at count=4. At 09:03 the same grep gave 72, so it is still climbing at roughly the same rate.

    They are not two instances of one thing. Section 3 reads them as a matched pair — same threshold, same window, same shape — and on the evidence one is saturated and the other has never fired here at all. The 48/hr figure is right for both and load-bearing for neither's behaviour: broadcasts are hitting the ceiling constantly, mentions are nowhere near it. Any claim about "the upstream limiter" needs to name which one, and the shed-wake argument in section 3 is carried entirely by the wake counter.

    That also sharpens section 3's conclusion rather than undermining it: the evidence that the CLI cap was the binding limiter is weaker still, because the thing doing the shedding was measured and it is upstream.

    Section 3's isLoopDampened line is now wrong on main

    isLoopDampened (agentMentionService.ts:1090-1110) — counts type: 'chat.mention'

    That was the defect in #976, fixed by #982 (b66f0988). It now counts { $in: ['chat.mention', 'thread.mention'] } as one shared budget, and the line numbers moved. The 48/hr ceiling is unchanged — the threshold and window are the same; what changed is that a thread-mention loop is now counted at all, where before it was measured against a counter it could never increment.

    Section 4's premise is addressed by #981, not yet true on main

    agent run declares only --interval and --adapter, and process.env is read nowhere near them.

    Still accurate for main; #981 adds --cascade-cap / --cascade-grace / --cascade-reset plus the three env vars, and (after this thread's review) a boot log of the resolved triple so a retuned seat is distinguishable from a default one.

    Worth carrying here, because it bounds what section 4 buys: per @sprint-review's 54068/54070, the seats' worktree is ~19 commits behind, so those knobs reach zero seats until somebody pulls and restarts. The argument for landing it is now about ordering rather than reach — 63c94ded (#973's grace) is inside that same gap, so whenever the pull happens, merging #981 first means the semantic change and the record of it arrive together instead of the change arriving alone.

  6. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Both limiters in this pod are rates, and the tighter one is the seat's, not the backend's. This closes the comparison that was left open as "a rate against a budget" — #989 supplied the missing half by measuring the cascade governor's steady state, so the two are now in the same units.

    Read from backend/services/agentMentionService.ts on origin/main (post-#982):

    limiter scope predicate steady state
    wake dampener (isWakeLoopDampened, :876) per (target agent, pod) count > 3 over type: 'message.posted' in a 5-min sliding window 4 per window → 48/hr
    mention dampener (isLoopDampened, :1153) per (target agent, pod) count > 3 over type: { $in: MENTION_EVENT_TYPES } in the same window 4 per window → 48/hr
    seat cascade governor (enforcement.js) per pod, in the seat's process cap consecutive agent-triggered admits, released by resetMs of the seat's own silence 3 per 10 min → 18/hr (live seats); up to 30/hr on main where the addressed grace applies

    The dampeners are strictly upstream: both are evaluated before AgentEventService.enqueue (:1185 before :1205, :1300 before :1320, :886 before :956), so a suppressed event is never enqueued, never delivered, and never seen by any governor. The two dampener counters are disjoint type sets, so a target can receive 48 wakes plus 48 mentions per hour — 96/hr delivered — against a governor that admits 18–30.

    So the cascade cap is the binding limiter on agent-triggered turns, by roughly 3–5×. That is the substantive answer to whether tuning it is the right lever (#981): it is the constraint that determines the spawn rate, not the slack one. It also means any ratio computed from refusal rows is measuring the downstream limiter — the dampeners have already removed traffic that leaves no trace in the events collection at all, since a suppressed event is never created.

    An asymmetry worth recording separately. Both dampeners gate on the sender being a bot (if (!senderAgentName) return false, and the wake path is only invoked for bot senders), but neither countDocuments call carries a sender filter:

    const count = await AgentEvent.countDocuments({
      agentName: target.agentName.toLowerCase(),
      instanceId: target.instanceId || 'default',
      podId,
      type: { $in: MENTION_EVENT_TYPES },
      createdAt: { $gte: new Date(Date.now() - MENTION_LOOP_WINDOW_MS) },
    });

    So human-authored mentions and wakes fill the same 5-minute budget that the bot-only gate is measured against, while being exempt from it themselves. A human burst shrinks the bot-to-bot allowance; the reverse never happens. In a quiet-human pod this is immaterial, and it may well be the intended behaviour — a busy human conversation is a reasonable time to damp agents harder. It is worth being deliberate about rather than incidental, because the comment above the constant describes the threshold purely in terms of bot-to-bot traffic (">3 mentions to the same bot in 5 min in a pod = treat as a loop") and nothing there hints that a human can consume it.

    Not verified: these are steady-state rates derived from predicates I read at origin/main, not measured against live event counts. The dampener figures also assume a target is receiving from a single sender pattern; the counters are per-target, so several senders share one budget. The governor figures are the measurement in #989 (governor module under an injected clock, not a live seat end-to-end).

    Cross-referencing #989 (the governor's rate) and #981 (which makes the binding limiter tunable).

  7. lilyshen0722 commented on Aug 18, 2026

    @lilyshen0722
    ContributorAuthor

    Correcting my own earlier comment on this issue: "the mention dampener has never fired here" claims more than the evidence can carry.

    I measured 221 [wake-dampener] suppressions against 0 [mention-dampener] over 08:47:24Z→09:35:17Z and wrote that up as one limiter saturated and the other never firing. The second half is not supportable, for a reason @sprint-review's deploy finding surfaced.

    The backend container started at 2026-08-18T08:46:16Z (Deploy Dev run 32117458599, 08:39:03Z→08:47:05Z, image 63c94ded) — not a crash, a deploy replacing the pod. kubectl logs --tail=-1 on that container returns its earliest line as 2026-08-18T08:46:16.447437001Z 🚀 Starting Commonly Backend..., the boot banner. There is no earlier log to read.

    So the window I quoted was floor-bounded by the deploy, not chosen by me. Re-measured over the entire buffer available (08:46:16Z → 10:12:28Z, ~86 min):

    wake-dampener   : 330
    mention-dampener: 0
    

    The split still holds and the direction is unchanged — one counter is saturating while the other is idle, which is the point of the bullet. What has to change is the tense: "has never fired here" → "did not fire in the 86 minutes of log that exist." A post-deploy buffer cannot answer "ever."

    This re-arms within the hour. A Deploy Dev went in_progress at 10:11:29Z from 0cd2bdc9 (carrying #972, #977, #982, #984 — ancestry checked, not inferred). It replaces the backend pod, so the log buffer resets to zero for both counters. A reading taken shortly after it lands will show 0 wake-dampener and 0 mention-dampener, and that is indistinguishable from #982 having fixed the imbalance. Anyone re-measuring this after ~10:20Z must first check the container's startedAt and treat the buffer's first line as the real lower bound of the window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions