Skip to content

feat(cli): the inbox watcher tick reads a window, not the whole queue (TASK-177) - #1990

Merged
lilyshen0722 merged 3 commits into
mainfrom
kai/task177-inbox-window
Sep 28, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
kai/task177-inbox-window

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

TASK-177's client half — the last open item on the row. #1987 (server) merged as e304c4cd; this is the consumer that was supposed to benefit from it.

The row's motive was: an ops watcher tick pages the WHOLE queue — 550 open items, 11 requests — out of a 60/min bucket keyed on the caller's IP that every session on the host shares. The route can now bound that. The CLI still asked for everything, so the one-request tick did not exist where it mattered. With a --cursor-file, commonly inbox list now requests createdAt >= cursor − W and drops the attentionItemIds already delivered inside that window.

W is not a guess about clock skew

A row is stamped from the writer's clock when the write happens and becomes visible only when it commits, so a row can carry a stamp before the cursor and still be absent from the response that wrote it. Resuming exactly at the cursor never shows such a row, on that tick or any later one. The window re-reads that stretch; the delivered ids keep the re-read quiet. W must exceed commit latency plus the writer's offset, which is why the default is 60s rather than "0 plus a fudge". --window 0 restores the exact-cursor behaviour, so the previous semantics stay reachable one flag away.

Three things the spec did not name, each caught by an arm rather than by reading

  1. The cursor stamp is a high-water mark. A row printed from inside the window is older than the mark that delimited that window. Letting it become the new mark moved the next read's since backward with it and moved the prune cutoff — the read reopened ground it had already covered. Found by probing a passing test: the tick after a late-committed row was reporting a cursor stamp 31ms older than the one before it.
  2. The id set is the whole window, not the newest row in it. A set that stopped at the newest delivered id re-printed every older row inside the window on the next pass — an alternating dedupe that loses nothing but makes a watcher's output unusable.
  3. The previous cursor's ids are carried, not recomputed. items here is post-dedupe, so a row delivered last tick is absent from it; rebuilding the set from this read's items alone forgets it and re-prints it next tick. I removed the carry as "dead weight" mid-build, and the arms failed immediately — the tests earned that paragraph.

One deliberate deviation

nextSince (max createdAt delivered) is not what the client resumes from; the mark is taken from the items this read printed. --kind is filtered on this side, so the server's window can carry rows of kinds this read will never print, and advancing onto them would move the mark past a row of the requested kind that a later page has not delivered. With no kind filter the two are the same value.

Evidence

  • Cli suite: 52 suites / 1033 tests / 0 failed (this file: 52 → 61). New arms include the row's two named ones: a row stamped before the cursor but committed after it prints exactly once on the next tick; two rows sharing an instant, the second inserted after the first response was built, are both returned and only the new one prints. The arm asserts the request's since parameter, not just the output, because the parameter is the mechanism.
  • Ledger: 56 mutations, all applied, NO SURVIVORS, and no named-arm misses (/tmp/kai-177c-ledger.py). It ports the 42 from TASK-176 — this PR edits the same lines, and a needle that stopped matching would report NOT APPLIED — and adds the window arms: no W in the request, no since parameter, windowCount ignored, default W changed, each half of the window validation (NaN, negative), the window boundary made equality-only, the prune removed, the carry removed and never-pruned, the high-water mark removed. Two instruments were fixed rather than worked around: one arm's mock reported hasMore: true forever, so its mutation OOM'd instead of failing (an instrument with no report reads exactly like a clean run); and the older kind-validation mutation put kind in a temporal dead zone — a mutation that throws is not a mutation that was killed.
  • cli lint clean; no backend/frontend change; docs/cli/README.md updated (its "the route has no created-since filter yet" paragraph was false from the moment feat(attention): a created-since window on the decision queue — whole-set counts, windowCount, nextSince (TASK-177) #1987 merged).
  • Residual, named: a row stamped more than W behind a cursor that has already passed it is still missed, by construction. That bound is the whole reason W is a flag.

Review findings folded (head 000fdbbd)

Wren, 75183 — a wide window is more than one page. The route pages priority-then-newest, 50 at a time, so a window taken from an old cursor can run to several pages and its OLDEST rows sit on the last one. The loop already stopped on hasMore (an earlier mutation removed that and OOM'd on an unbounded mock, which is how the guard got armed at all), but nothing witnessed the overflow case: a tick that stopped after page one would print the newest 50, write a mark from them, and move since past the page-two rows — which no later tick could then see. The new arm builds exactly that window (cursor ten minutes old, 50 rows on page one, 5 older rows on page two) against a page that answers for the window it was asked for, so the second tick is served the way the real route would serve it. It asserts both pages print, that two requests happened, and that the mark is the newest row across both pages.

Vera, 75177 — the control that keeps the bound honest. One arm now returns a row inside the window and omits a row behind it in the same read, and it asserts the since the server was asked for, not only the output: without the behind-the-window row the arms pass on a lookback that fetches everything. Her second item, the id-set reset, was already armed in both directions (never-carry, never-prune); the never-prune mutation has been re-attributed to the arm that actually kills it, because the arm it named only ever selected the row that IS the mark — a stale label reading as a witness that is no longer one. The ledger now fails itself on any mutation that is not killed by the arm it names.

Her question about W = 60 sits in the README as its own paragraph: the row is written synchronously inside the request that records the event, so the stamp-to-visible gap is one database write round trip (milliseconds) and the writers' clock offset is whatever NTP leaves (sub-second between pods). 60s is two to three orders above both — a margin deliberately not a measurement, because too large re-prints rows the caller dedupes by id and too small loses them.

One defect neither reviewer could see from the fixture: nextCursorFrom returned at as the high-water mark but ms as the newest row printed, so the in-process object disagreed with the cursor its own file re-reads as (the file keeps only at). ms is now the mark, with an arm asserting the round trip.

Mutation map across reviewers

A description is not an edit, so two reviewers' red counts are comparable only where the edited line is. Vera re-ran seven mutations independently at 000fdbbd; four matched this ledger exactly, and the disagreements are recorded rather than reconciled in prose:

description this ledger Vera @ 000fdbbd
drop the high-water mark M52 · 3 reds 3 same
drop the carried ids M34 · 4 4 same
carry the ids forever (never prune) M35 · 2 2 same
ms: mark → ms: max M56 · 1 1 same
stop sending since to the server M44 · 4 4 same
id set = boundary only M49 · 2 5 different edits
remove the pre-filter M53 · 6 5 different edits
>= → > at the boundary M10 · 1 1 (previous head, for Vera)

M49 is nextCursorFrom's ms !== null && ms >= cutoff → === max; the pre-filter is filterItems's ms >= sinceMs. A peer editing the same idea in the other site, or with the carry folded in, arms a different set of tests and gets a different count. A count that disagrees is evidence about the edits, never about who miscounted — and the four rows that match are what make the other three worth stating rather than rounding off. Every mutation either of us ran is killed, which is the only verdict claim here.

Docs prose has no automated witness — the README paragraph is a claim, checked by reading, not by a test.

… (TASK-177)

The route grew a created-since bound in #1987; the CLI did not use it, so the
one-request tick that motivated the parameter did not exist at the consumer.
`commonly inbox list` with a cursor now asks for `createdAt >= cursor - W`
(`--window`, default 60s) and drops the ids already delivered inside W.

W is not a guess about clock skew: a row is stamped from the writer's clock when
the write happens and becomes visible only when it commits, so resuming exactly
at the cursor would never show such a row on any tick. The window re-reads that
stretch, and the delivered ids make it quiet.

Three things this required that the spec did not name:

- The cursor stamp is a HIGH-WATER MARK. A row printed from inside the window is
  older than the mark that delimited that window; letting it pull the mark back
  moved the next read's `since` back with it and moved the prune cutoff.
- The id set is the WHOLE window, not just the newest delivered row, or a tick
  re-prints every older row inside the window on the next pass.
- The previous cursor's ids are CARRIED, not recomputed from this read's items:
  `items` is post-dedupe, so a row delivered last tick is absent from it, and
  rebuilding the set from it alone alternates the dedupe every tick.

`--window 0` restores the exact-cursor behaviour. The mark is taken from what
the read PRINTED rather than the response's `nextSince`, because `--kind` is
filtered on this side and the server's window may hold kinds this read never
prints.

Tests 58 (was 52 in this file), 1030 across the cli suite; ledger 52 mutations
ported from TASK-176 plus the window arms, all applied, no survivors.
…-consistent (TASK-177)

Two review findings, both about W being a number somebody chose.

Wren (75183): the route pages priority-then-newest, 50 at a time, so a window
taken from an old cursor can run to several pages and its OLDEST rows sit on the
last one. The loop already stopped on `hasMore`, but nothing witnessed it — a
tick that stopped after page one would print the newest 50, write a mark from
them, and move `since` past the page-two rows, which no later tick could then
see. The new arm builds that window (cursor ten minutes old, 50 rows inside the
first page, 5 older ones on the second) against a page that answers for the
window it was ASKED for, so the second tick is served the way the real route
would serve it; it asserts both pages print, two requests happen, and the mark
is the newest row across both.

Vera (75177): the window needs a row INSIDE it returned and a row BEHIND it
absent in the same read — otherwise the arms pass on a lookback that fetches
everything. That pair is now one arm, and it asserts the `since` the server is
asked for as well as the output. The id-set reset she asked about was already
armed twice over (never-carry, never-prune); the never-prune-inside-the-window
mutation has been re-attributed to the arm that actually kills it, because the
one it named only ever selected the row that IS the mark.

And one defect neither of them could see from the fixture: `nextCursorFrom`
returned `at` as the high-water mark but `ms` as the newest row printed, so the
in-process object disagreed with the cursor its own file re-reads as. `ms` is
now the mark, with an arm asserting the round trip.

Also: the README's 60s paragraph now says what 60s is (a two-to-three-order
margin over a write round trip and pod-clock offset, deliberately not a
measurement) instead of asserting it is "ample"; and it documents the paging.

Tests 61 in this file (was 58), 1033 across the cli suite; ledger 56 mutations,
no survivors and no named-arm misses; cli/src lint clean.
…ts a tick costs (TASK-177)

Vera's 75189 correction about the chat line turned out to have a sibling in the
file this PR edits: the paragraph I added says a wide window pages, and the
paragraph four lines below it said "With a cursor, the window bounds a tick to
one" — the same claim, stated as a fact about request count, in a command whose
whole point is how many requests a tick costs. A wide window is one request per
50 rows of it; the ordinary watcher tick, with a cursor seconds old, is one.

Also made the residual paragraph's "60s is ample for in-cluster writers" defer
to the margin argument instead of asserting amplitude bare, so the number is
justified once rather than twice.

Prose only: no source line changes, so the ledger and suite results are the ones
already recorded at `000fdbbd` and were re-run against this head anyway
(52 suites / 1033 tests / 0 failed; 56 mutations, no survivors, no named-arm
misses).
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 28, 2026
Merged via the queue into main with commit 4e39c99 Sep 28, 2026
22 checks passed
samxu01 pushed a commit that referenced this pull request Sep 30, 2026
…ange (TASK-181)

Written by sprint-review, a Commonly agent.
Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf (message 76019)

ux-lead's non-blocking note on their own part 5, verified before applying.
My sample was `git log --no-merges -60` — 60 first-parent squash positions
on main. Describing it as "#1988-#2053" restated a positional count as a
numeric range, and that range holds 66 merged PRs: the six extras (#1990,
#1991, #1993, #1994, #1996, #1997) are each absent from the 60 and sit at
first-parent positions 61-69, confirmed per PR.

Reworded positionally rather than patching 60 to 66, because the sample was
never a number range and a re-run drifts: the same command today spans
#1988-#2054, #2054 having merged after faf43bb. "60 consecutive squash
commits ending at faf43bb" is re-derivable; a number range is not the thing
that was measured.

The 8 of 8 is the same eight PRs on either set, so no figure moves.

Numbering guard green: 50 rules, 1..50, 52 citations resolve, no lead moved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
…things are equal (TASK-181) (Team-Commonly#2055)

* docs(review): rule 50 — a fixture supplying only the input where two things are equal (TASK-181)

Written by sprint-review, a Commonly agent.
Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf (message 75951)

Filed by sprint-impl from my own generalisation in Team-Commonly#1982's artifact loop,
with the rider-or-rule call left to me. It earns its own number: rule 41's
test asks whether every check the adjacent rule sends you to run passes
here, and for rule 17 all of them do — the fixture calls the real function
with a real catalog, so the shape is genuine and only the discriminating
value is missing.

Demonstrated rather than argued, two arms on `localizeWindow`:
  A. clamp removed, test as it stands  -> 1 failed / 3 total (line 31)
  B. same mutant, only `minutes(1)` cut -> 3 passed / 3 total, GREEN
30s is 0.5min and Math.round(0.5) === 1, so the fixture's only sub-minute
input cannot see the deletion. Totals hold at 3, so neither is a rule-46
collapse. BASE 3/3, RESTORED 3/3.

Two citations in the filed row were wrong and are corrected here: the clamp
landed in Team-Commonly#1981 (79f5cb4), not Team-Commonly#1980, and the killing case is 1ms, not
the 30s originally proposed in that gate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(review): rule 50 — the discriminating input can be present and dismissed

Written by sprint-review, a Commonly agent.
Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf (message 75959)

A second citation for rule 50, earned by its own author within the hour, and
a variant the first draft did not name: the distinguishing case was PRESENT
in the fixture and got filed as an anomaly.

Gating Team-Commonly#2054 I tested `landed == PR title + " (#N)"` across nine squashes,
got 8 of 9, and explained the ninth as a presser overwriting the subject
box. The untested rival was `landed == tip commit subject`. The repo is set
to COMMIT_OR_PR_TITLE: one commit defaults to the COMMIT's subject, 2+ to
the PR title. That column splits the nine perfectly by commit count (4/4 and
5/5), and over the last 60 squashes, where the two texts diverge on a
one-commit PR, the commit subject wins 8 of 8 and the title 0 of 8.

Eight rows agreed with both readings because their candidate strings were
identical. Team-Commonly#2031 was the only row carrying information, and I discarded it.
Caught by ux-lead, who ran the column I skipped.

Numbering guard green: 50 rules, 1..50, 52 citations resolve, no lead moved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(review): rule 50's Team-Commonly#1982 citation — one PASS, and the input caught it

Written by sprint-review, a Commonly agent.
Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf (message 75951)

@ux-lead's two corrections on Team-Commonly#2055, both verified here before applying.

1. `07873c19` carried ONE PASS, not two. Enumerated the review list: my CODE
   GATE PASS (22:38:13Z) and ux-lead's UX-GATE FAIL (22:50:18Z), both at that
   head. The two PASSes exist at the NEXT head `83408e61`, after the fix — the
   original sentence conflated the two heads.

2. "ux-lead's render caught what the suite could not" was wrong about the
   mechanism, and wrong in the direction that matters for this rule. Measured:
   BASE 22/22; reverting line 527 to the pre-fix `pod: targetLabel` gives
   1 failed / 21 passed / 22 total; RESTORED 22/22. The suite CAN see it. What
   it lacked at gate time was the seat-target grant, and the test carrying that
   input was added BY the fix (`83408e61`, +24 lines), its own comment calling
   it "the fix's own control".

That is the rule stating itself: the instrument was never blind, the fixture
had no input on which the two readings differ. Sentence replaced with the
literal text ux-lead proposed.

Numbering guard green: 50 rules, 1..50, 52 citations resolve, no lead moved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(review): rule 50 — five corrections from ux-lead's gate (TASK-181)

Written by sprint-review, a Commonly agent.
Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf (message 76014)

All five applied with ux-lead's literal text; the two testable ones were
reproduced here first.

1. "every mutation" was false. Arm C, `Math.max(2, …)` on arm B's fixture:
   2 failed / 1 passed / 3 total (BASE and RESTORED 3/3). The equal-only
   fixture greens mutations that ERASE the difference, not every mutation
   of the line.
2. The clamp came in with `d331c11ea` (created localizeRelativeTime.ts,
   +106, diff contains the clamp), not `79f5cb48d` (+51, test file only).
   `git log -S` over the clamp string on main returns Team-Commonly#1981's squash; within
   the branch it is d331c11. 79f5cb4 is the pin and carries the 1ms
   measurement, and is now cited as that.
3. The Team-Commonly#1982 figure regained its head, `faf43bb2` — dropped when I applied
   ux-lead's earlier text.
4. The zh gloss inverted its source: the author's own account says
   `None == None` read as "untranslated in zh", not "already translated".
5. "Eight rows agreed with both readings" was wrong. On my own table only
   three do (Team-Commonly#2015, Team-Commonly#2046, Team-Commonly#2048); the other five agree with the title
   reading alone. Corrected, and the 60-squash anchor now names its window
   (Team-Commonly#1988-Team-Commonly#2053 up to faf43bb).

Numbering guard green: 50 rules, 1..50, 52 citations resolve, no lead moved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(review): rule 50 — the 60 is a positional sample, not a number range (TASK-181)

Written by sprint-review, a Commonly agent.
Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf (message 76019)

ux-lead's non-blocking note on their own part 5, verified before applying.
My sample was `git log --no-merges -60` — 60 first-parent squash positions
on main. Describing it as "Team-Commonly#1988-Team-Commonly#2053" restated a positional count as a
numeric range, and that range holds 66 merged PRs: the six extras (Team-Commonly#1990,
Team-Commonly#1991, Team-Commonly#1993, Team-Commonly#1994, Team-Commonly#1996, Team-Commonly#1997) are each absent from the 60 and sit at
first-parent positions 61-69, confirmed per PR.

Reworded positionally rather than patching 60 to 66, because the sample was
never a number range and a re-run drifts: the same command today spans
Team-Commonly#1988-Team-Commonly#2054, Team-Commonly#2054 having merged after faf43bb. "60 consecutive squash
commits ending at faf43bb" is re-derivable; a number range is not the thing
that was measured.

The 8 of 8 is the same eight PRs on either set, so no figure moves.

Numbering guard green: 50 rules, 1..50, 52 citations resolve, no lead moved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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