Skip to content

fix(core): Messaging log chars and grep context are never validated — NaN chars replaces entry text with a garbage marker, fractional context defects the read #957

Closed

Description

@dezren39

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)

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

  • log is how sessions read each other's transcripts. A chars: NaN silently replaces an entry's content with a NaN chars marker — 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 a TypeError that defects the whole log call.
  • An unbounded chars removes 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 chars and context at its boundary in log(): chars becomes 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 for limit); context becomes a non-negative integer (floored, NaN treated as 0/absent).
  • clip is no longer reachable with a negative, fractional, or non-finite chars from the service, and the grep selection loop only ever indexes all with integers.
  • The built-in messaging tool's context field (tool/plugin/messaging.ts) matches the contract (NonNegativeInt-equivalent) instead of bare Schema.Int.
  • Tests in packages/core/test (messaging / messaging-log tests) pin: chars: -5 and chars: NaN no longer produce wrong-end or garbage-marker output; grep context: 1.5 returns the hit with integer context instead of throwing; context: -1 behaves as the documented normalised value.
  • Valid inputs behave exactly as today: default chars (500, 4000 for pull), positive integer chars, and context: 0 / positive integer context.

Activity

  1. added
    kind/bug
    task/small-fix
    status/needs-triage
    source/creator
    priority/normal
    queue/queued
    app/core
    effort/s
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · filed this run by new-issue-creator-opencode

  3. added
    work/assigned
    queue/claimed
    status/in-progress
    and removed
    status/needs-triage
    queue/queued
    on Oct 30, 2026
  4. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-opencode)
    • Session / ID: queue task 3847
    • Found via: queue claim
    • Task: Normalise Messaging log() chars and grep context at the service boundary; align built-in tool context contract; pin with tests.
    • Expectation: effort s — done = PR opened with targeted tests passing, parked for CI.
    • Links: branch queue/3847-957-messaging-log-chars-context
  5. 23 remaining items

  6. removed
    status/in-progress
    queue/claimed
    work/assigned
    on Oct 30, 2026
  7. dezren39 commented on Oct 30, 2026

    @dezren39
    Author

    🤖 Agent note · handed off

    • Agent: fleet monitor (repo-fleet-monitor)
    • Session / ID: queue task 3847
    • Found via: monitor reconciliation — claim/label divergence auto-repair + dead-in-queue alert
    • Task: The claim on task 3847 evaporated and the task is now DEAD in queue: status queued with 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 stage pr_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.
    • Expectation: operator repair on task 3847; then a lane shepherds the linked PR (review CI, merge when green — do NOT re-implement).
    • Links: fix(core): normalise messaging log chars and grep context at the service boundary #958
  8. dezren39 commented on Oct 31, 2026

    @dezren39
    Author

    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.

  9. added
    work/assigned
    queue/claimed
    status/in-progress
    and removed
    status/needs-triage
    queue/queued
    on Oct 31, 2026
  10. removed
    status/in-progress
    queue/claimed
    work/assigned
    on Nov 1, 2026
  11. dezren39 commented on Nov 1, 2026

    @dezren39
    Author

    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.ts passes 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.

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

    app/coreeffort/skind/bugpriority/normalsource/creatortask/small-fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions