Skip to content

fix(transcripts): complete short reads within the requested tail - #3962

Merged
haelyra merged 1 commit into
affaan-m:mainfrom
Afloat16:fix/transcript-tail-short-reads-20261117
Nov 19, 2026
Merged

haelyra merged 1 commit into
affaan-m:mainfrom
Afloat16:fix/transcript-tail-short-reads-20261117

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

What Changed

Continue reading the requested transcript window until its buffer is full or the descriptor reaches EOF. Advance both buffer and file offsets by the actual byte count, then decode UTF-8 once. Keep reads bounded by the original file-size snapshot and preserve descriptor cleanup on errors.

Why This Change

A single fs.readSync() call can legally return fewer bytes than requested, including on network filesystems (Node.js documentation). The old reader returned that first chunk as the complete tail. This can drop the latest usage record and make context detection return null even though the record is present.

Testing Done

  • Six added regressions failed before the fix and now pass: short reads, multibyte UTF-8 splits, shrinking files and EOF, growing files without expanding the read window, later-read errors with descriptor closure, and the real latest-context-usage reader.
  • File-tail and transcript-context suites: 79 passed.
  • ECC_TEST_ONLY=lib/file-tail.test.js,lib/transcript-context.test.js npm test: repository validators and both selected suites passed.
  • Changed-module coverage: 95.74% lines/statements, 88.88% branches, 100% functions; all 80% gates pass.

Focused branch checks and repository validators passed. Full-suite integration is not claimed for this branch. The common upstream baseline 8abdf329 also reproduces four unrelated failing suites in this environment (statusline project plugins, hooks, observer subdirectory detection and memory vault).

Type of Change

  • fix: Preserve transcript data across valid short reads.

Security & Quality Checklist

  • Conventional commit format, independent code review, ESLint and git diff --check passed.
  • No new dependencies, permissions, network access, or credentials.

Documentation

The existing return shape and bounded-tail API are preserved.

@Afloat16
Afloat16 requested a review from affaan-m as a code owner November 17, 2026 02:40
@ecc-tools

ecc-tools Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: 5c7eeba436341bbbac653c249d5ff43251c2adce

Security evidence gate passed (success)

No security-sensitive scanner-evidence gap detected.

Mode: enforce

Scanned 2 changed file(s). No missing scanner-evidence signal was detected.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: 5c7eeba436341bbbac653c249d5ff43251c2adce

PR taxonomy review recommended (neutral)

Detected 1 PR taxonomy bucket(s): CI/CD Recommendation.

Scanned 2 changed file(s).

Roadmap taxonomy buckets:

CI/CD Recommendation

CI, dependency, coverage, and contract signals should be routed into follow-up checks or verification work.

Signals:

  • 1 CI or workflow path(s) changed

Paths:

  • tests/lib/file-tail.test.js

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: 5c7eeba436341bbbac653c249d5ff43251c2adce

Reference set readiness gaps detected (neutral)

Reference evidence present for 0/7 areas (0%) across 2 changed file(s).

This check is based on files changed in this PR. Repository-level readiness is still reported by /ecc-tools analyze comments and generated manifests.

Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: 5c7eeba436341bbbac653c249d5ff43251c2adce

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 2 changed file(s); 0 corpus scenarios had matching evidence.

This check compares PR file changes against the evaluator/RAG promotion corpus in src/analyzers/fixtures/evaluator-rag-corpus.ts.
Hosted output scoring inspected 0 completed cached hosted job results.

No evaluator corpus scenarios matched this PR.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when reading the end of a file, including when reads return partial data or the file changes during reading.
    • This helps preserve the latest transcript and usage information and handles read failures more safely.

readFileTail now handles short reads by continuing to read the requested file segment until it is complete or reaches EOF. Tests cover UTF-8 decoding, file size changes, later read errors, and transcript usage records.

Changes: File Tail Reading

Layer / File(s) Summary
Read loop and validation
scripts/lib/file-tail.js, tests/lib/file-tail.test.js
readFileTail repeats reads at the appropriate offsets until it fills the requested segment or a read returns zero. Tests check short reads, UTF-8 decoding, shrinking and growing files, later read failures, and transcript usage records.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • affaan-m/ECC#3657: Both changes modify readFileTail() and readLatestContextTokens() behavior on the transcript-tail path.

Suggested reviewers: montjeffrey

Merge Risk: Minimal · up to 5c7ee

This fixes transcript tail reads that could miss the latest usage record when a read returned fewer bytes than requested. The change is small and well covered by targeted tests, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: readFileTail now keeps reading short reads until the requested tail is filled. It matches the raw summary (loop until segment complete or readSync returns zero) and th…
Description check Passed The description is specific to the changeset. It explains the loop that continues reading until the buffer is full or EOF, the bounded reads against the file-size snapshot, the UTF-8 decode after join…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: readFileTail now keeps reading short reads until the requested tail is filled. It matches the raw summary (loop until segment complete or readSync returns zero) and the PR objectives. It is specific and conventional-commit formatted.

Full details: Description check

Explanation

The description is specific to the changeset. It explains the loop that continues reading until the buffer is full or EOF, the bounded reads against the file-size snapshot, the UTF-8 decode after joining chunks, and the descriptor cleanup. It also lists the regression tests that the raw summary describes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: affaan-m/ECC
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 8abdf32
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 9d10c90b-b9e8-4555-ba9f-14ad1849b320
Commits

Reviewing files that changed from the base of the PR and between 8abdf32 and 5c7eeba.

Files selected for processing: 2

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional context used

Code guidelines: 10

.cursor/rules/typescript-security.md — auto-discovered
.claude/rules/node.md — auto-discovered
.cursor/rules/typescript-coding-style.md — auto-discovered
.cursor/rules/common-patterns.md — auto-discovered
.cursor/rules/kotlin-testing.md — auto-discovered
.cursor/rules/python-coding-style.md — auto-discovered
.cursor/rules/swift-patterns.md — auto-discovered
.cursor/rules/common-testing.md — auto-discovered
.agents/skills/verification-loop/SKILL.md — Agent Skill
.agents/skills/ecc-conventions/SKILL.md — Agent Skill
Path-based instructions: 13

Focus on command injection, unsafe subprocess usage, path traversal, SSRF, secret exposure, and missing tests for new CLI behavior.

CodeRabbit configuration file

Files:

  • scripts/lib/file-tail.js
Source excerpt:

CodeRabbit inference engine (.cursor/rules/typescript-security.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: New scripts in `scripts/lib/` require a matching test in `tests/lib/`

CodeRabbit inference engine (.claude/rules/node.md)

Files:

  • scripts/lib/file-tail.js
Source excerpt: Use spread operator for immutable updates: Source excerpt: Use async/await with try-catch: Source excerpt: Use Zod for schema-based validation: Source excerpt: No `console.log` statements in production code Source excerpt: U...

CodeRabbit inference engine (.cursor/rules/typescript-coding-style.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: `scripts/` — Node.js utilities, hooks.

CodeRabbit inference engine (.claude/rules/node.md)

Files:

  • scripts/lib/file-tail.js
Source excerpt: `tests/` — Mirror the `scripts/` structure.

CodeRabbit inference engine (.claude/rules/node.md)

Files:

  • tests/lib/file-tail.test.js
Source excerpt: Encapsulate data access behind a consistent interface: Define standard operations: findAll, findById, create, update, delete Concrete implementations handle storage details (database, API, file, etc.) Business logic depends...

CodeRabbit inference engine (.cursor/rules/common-patterns.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: Use **Kotest** with spec styles (StringSpec, FunSpec, BehaviorSpec) and **MockK** for mocking.

CodeRabbit inference engine (.cursor/rules/kotlin-testing.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: Follow **PEP 8** conventions Source excerpt: Use **type annotations** on all function signatures Source excerpt: Prefer immutable data structures: Source excerpt: **black** for code formatting Source excerpt: **isort** for i...

CodeRabbit inference engine (.cursor/rules/python-coding-style.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: Define small, focused protocols.

CodeRabbit inference engine (.cursor/rules/swift-patterns.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: Test Types (ALL required): **Unit Tests** - Individual functions, utilities, components **Integration Tests** - API endpoints, database operations **E2E Tests** - Critical user flows (framework chosen per language)

CodeRabbit inference engine (.cursor/rules/common-testing.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: Review each changed file for: Unintended changes Source excerpt: Review each changed file for: Missing error handling Source excerpt: Review each changed file for: Potential edge cases

CodeRabbit inference engine (.agents/skills/verification-loop/SKILL.md)

Files:

  • scripts/lib/file-tail.js
  • tests/lib/file-tail.test.js
Source excerpt: Follow *.test.js naming pattern

CodeRabbit inference engine (.agents/skills/ecc-conventions/SKILL.md)

Files:

  • tests/lib/file-tail.test.js
Learnings: 1

Common learnings

Learnt from: CR
Repo: affaan-m/ECC

Timestamp: 2026-11-17T02:40:48.115Z
Learning: Source excerpt:
# Test Collaboration Governance

## 3. Convert Bugs into Regression Protection

Every bug fix must do one of the following:

1. create or link a TEST-ID; or
2. record why automation is not currently possible, plus manual verification steps and evidence.
ast-grep (0.51.1)

tests/lib/file-tail.test.js

[warning] 100-100: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(unicode, text)
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

[warning] 111-111: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(shrinking, 'abcdef')
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

[warning] 127-127: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(growing, 'abcdef')
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

[warning] 155-158: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(transcript, [1000, 170000].map(tokens => JSON.stringify({
type: 'assistant',
message: { model: 'claude-sonnet-4-6', usage: { input_tokens: tokens } }
})).join('\n'))
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Fixes readFileTail so a short read no longer drops the rest of the requested transcript tail.

  • File tails now collect the requested bytes across short reads.

No actionable issues found.

Reviews (4) · Last reviewed commit: "fix(transcripts): complete short reads w..." · Reviewed by Greptile

Copy link
Copy Markdown
Contributor Author

The latest Greptile review of 5c7eeba436341bbbac653c249d5ff43251c2adce reports no actionable issues, and the Greptile, CodeRabbit, and GitGuardian checks are successful. The PR's CI run is still action_required, so the upstream test matrix has not run.

Could a maintainer authorize that workflow and review this short-read fix for merging? The focused regression and coverage results, together with the full-suite baseline limitations, remain recorded in the PR description.

@haelyra
haelyra merged commit 669b6ac into affaan-m:main Nov 19, 2026
4 checks passed
@haelyra

haelyra commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Thank you for completing short reads within the requested transcript tail. We merged your original commit history through #4048 so the related changes could be tested together. We retained the UTF-8 regression while expressing its astral character as a Unicode escape required by the repository policy.

The resulting main commit fbb1a85c59a8468c96454fc5b48cf7e4f8f79b55 passed CI, CodeQL, and Supply-Chain Watch. Thank you for helping improve ECC!

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.

2 participants