Repository navigation
Description
Problem
The Messaging service's log read never validates two of its numeric inputs — chars (maximum characters per entry) and context (entries of context around grep matches) — even though the contract schema promises PositiveInt for chars and NonNegativeInt for context (packages/schema/src/messaging.ts:392,384). Sibling issues #948 and #953 cover the same service's limit and offset; neither covers chars or context, which fail in different ways:
| Input reaching the service | Result (verified this run) |
|---|---|
chars: -5 on a 100-char entry |
clip returns 95 characters — the "maximum" is ignored and the entry's last 5 chars are silently dropped instead of the entry being clipped to a small page |
chars: NaN |
clip returns the literal string …[NaN chars]… as the entry's entire text — the real content is replaced by a garbage marker |
chars with no ceiling (e.g. 1e9) |
Every entry is returned unclipped, defeating the per-entry cap the parameter exists to enforce (defaults are 500 / 4000 for pull) |
grep context: 1.5 |
The context-selection loop iterates fractional indices (index ± 1.5, stepping by 1), all[fractional] is undefined, and the output stage throws TypeError on entry.text — the whole log call defects |
grep context: -1 or NaN |
Silently behaves like context: 0 — no error, no diagnostic, the requested context is just dropped |
Verified on main 294f03032e (code read) plus a laptop probe (~/git/fleet/probe-2026-10-30-msg-log-chars-context/probe.mjs) running the verbatim clip() body and the verbatim grep selection loop: controls pass (chars: 500 returns the entry intact; context: 0 returns just the hit; context: 1 returns hit ± 1 entry).
Evidence (file:line, main 294f030)
packages/core/src/messaging.ts:1835—log():const chars = input.chars ?? (op === "pull" ? 4000 : 500)— no floor, no ceiling, no finiteness check;charsfeedsMessagingLog.clip(entry.text, chars)in the output stage at:1848.packages/core/src/messaging/log.ts:165-180—clip(text, chars): its arithmetic (Math.ceil(chars * 0.7),text.slice(0, chars), the marker-length loop) assumes a positive finite integer; negative/NaN inputs produce the wrong-end and garbage-marker results above. (fix(core): MessagingLog.clip exceeds its maximum-characters budget at small limits — the omission marker is not counted when the tail is dropped #577 fixedclipexceeding its budget at small positive limits; unvalidated inputs reaching it are a different gap.)packages/core/src/messaging.ts:1874-1879— grep:const context = input.context ?? 0, thenfor (let near = Math.max(0, index - context); near <= Math.min(all.length - 1, index + context); near++)— a fractionalcontextmakesnearfractional, soselectedgains fractional keys andall[near]isundefinedwhen entries are materialised at:1881-1883.packages/core/src/plugin/host.ts:457— the plugin host passesloginput straight to the service (log: (input) => messaging.log(input)), with no schema decode in front of it — the same unvalidated entry path as fix(core): Messaging limits are clamped only from above — a negative limit returns every row, a fractional one defects the read #948/fix(core): Messaging offset is never validated — a negative offset makes log return the wrong end of the transcript and tail report more on an empty page #953.packages/core/src/tool/plugin/messaging.ts:181,185— the built-in messaging tool protectschars(Count= positive int) but declarescontextas bareSchema.Int, so a negativecontextis actively accepted by the tool layer while fractional values are stopped there and only arrive via the plugin host.- Contrast:
packages/core/src/kv.ts:61shows the house pattern for a service-level numeric input — floor + clamp to a range plus an explicit NaN case.
Dedup: searched open and closed issues for "messaging log chars", "messaging clip", "log context fractional" — the only hits are #577 (clip budget at small positive limits, closed), #948 (limit only) and #953 (offset only). None covers chars or context validation.
Why it matters
logis how sessions read each other's transcripts. Achars: NaNsilently replaces an entry's content with aNaN charsmarker — the caller receives plausible-looking output with the actual message destroyed.- A fractional grep
context— easy for a caller computing context from a ratio — doesn't degrade; it throws aTypeErrorthat defects the whole log call. - An unbounded
charsremoves the only per-entry size guard on a read that can return whole transcripts, so one request can materialise far more text than the defaults intend.
Acceptance criteria
- The Messaging service normalises
charsandcontextat its boundary inlog():charsbecomes a positive integer within a documented ceiling (NaN treated as absent/default, matching the fix(core): Messaging limits are clamped only from above — a negative limit returns every row, a fractional one defects the read #948 approach forlimit);contextbecomes a non-negative integer (floored, NaN treated as 0/absent). -
clipis no longer reachable with a negative, fractional, or non-finitecharsfrom the service, and the grep selection loop only ever indexesallwith integers. - The built-in messaging tool's
contextfield (tool/plugin/messaging.ts) matches the contract (NonNegativeInt-equivalent) instead of bareSchema.Int. - Tests in
packages/core/test(messaging / messaging-log tests) pin:chars: -5andchars: NaNno longer produce wrong-end or garbage-marker output; grepcontext: 1.5returns the hit with integer context instead of throwing;context: -1behaves as the documented normalised value. - Valid inputs behave exactly as today: default
chars(500, 4000 forpull), positive integerchars, andcontext: 0/ positive integer context.
Activity
dezren39 commentedon Oct 30, 2026
🤖 Agent note · filed this run by new-issue-creator-opencode
limitand fix(core): Messaging offset is never validated — a negative offset makes log return the wrong end of the transcript and tail report more on an empty page #953offset).294f03032e:packages/core/src/messaging.ts:1835takescharswith no floor/ceiling/finiteness check intoMessagingLog.clip(messaging/log.ts:165);packages/core/src/messaging.ts:1874takes grepcontextunvalidated into the fractional-index selection loop. Plugin host passesloginput straight through (plugin/host.ts:457); the built-in tool protectschars(Count) but declarescontextas bareSchema.Int(tool/plugin/messaging.ts:181).~/git/fleet/probe-2026-10-30-msg-log-chars-context, verbatimclip+ grep loop):chars:-5→ 95 of 100 chars returned;chars:NaN→ entry text replaced by…[NaN chars]…; grepcontext:1.5→ TypeError defect in the output stage; controls (chars:500,context:0/1) pass.limitonly, fix(core): Messaging offset is never validated — a negative offset makes log return the wrong end of the transcript and tail report more on an empty page #953 coversoffsetonly (its in-flight PR fix(core): normalise messaging offset at the service boundary #955 note explicitly keeps scope clear of context), fix(core): MessagingLog.clip exceeds its maximum-characters budget at small limits — the omission marker is not counted when the tail is dropped #577 covered clip's budget at small positive limits. Not self-solved — queued for the queue lane.dezren39 commentedon Oct 30, 2026
🤖 Agent note · picked up
queue/3847-957-messaging-log-chars-context23 remaining items
dezren39 commentedon Oct 30, 2026
🤖 Agent note · handed off
queuedwith attempts 2/2 (max_attempts reached) — it can never be claimed again without operator repair (raise max_attempts or supersede it). The issue's labels still claimed an active holder, so they are reset to the truth:queue/queued+status/needs-triage. The work itself exists: checkpoint stagepr_opened, PR fix(core): normalise messaging log chars and grep context at the service boundary #958 is OPEN and is the shepherd target once the task is repaired.dezren39 commentedon Oct 31, 2026
Task 3847: Attempt cap raised on this issue's queue task (2 → 4, fleet preventive standard) per owner approval 2026-10-31 — the task was dead-in-queue with attempts exhausted and its PR still open; a lane pickup can now proceed.
dezren39 commentedon Nov 1, 2026
Queue task 3847 completed (lane A shift): PR #958 squash-merged (0e50a9e). Verification: the production head had full CI green and a clean Codex review; the final head adds only a docs-string fix for CodeRabbit, and
bun test test/messaging.test.ts test/messaging-log.test.tspasses 38/38 on the laptop at that head. Note for the fleet: since commit ce6c4f0 (2026-10-30) the check/test/pr-standards workflows are main-only triggers, so PRs no longer receive automatic basic-tier runs — merges are verified via laptop tests + post-merge main CI.