Skip to content

fix(local-system): restore loc param when calling readLocalFile IPC#13748

Merged
Innei merged 1 commit into
lobehub:canaryfrom
octo-patch:fix/issue-13735-readlocalfile-loc-param
Apr 12, 2026
Merged

fix(local-system): restore loc param when calling readLocalFile IPC#13748
Innei merged 1 commit into
lobehub:canaryfrom
octo-patch:fix/issue-13735-readlocalfile-loc-param

Conversation

@octo-patch

Copy link
Copy Markdown
Contributor

Fixes #13735

Problem

The readLocalFile tool accepts a loc: [startLine, endLine] parameter to read a specific line range. However, when called through the Desktop Electron runtime, the loc parameter was always ignored — the returned content always started from line 0.

Root cause: A parameter conversion mismatch in LocalSystemExecutionRuntime.denormalizeParams.

The call chain is:

  1. LocalSystemExecutor.readLocalFile(params) → extracts loc → passes {startLine, endLine, path} to runtime.readFile()
  2. ComputerRuntime.readFile() → calls callService('readLocalFile', {startLine, endLine, path})
  3. LocalSystemExecutionRuntime.denormalizeParams('readLocalFile', ...)fell through to default → passed {startLine, endLine, path} unchanged to the IPC service
  4. IPC handler LocalFileCtr.readFile() expects LocalReadFileParams with loc?: [number, number], not startLine/endLine
  5. Since loc was undefined, readLocalFile defaulted to [0, 200] on every call

Solution

Added an explicit readLocalFile case in denormalizeParams that reconstructs the loc tuple from startLine and endLine before forwarding to the IPC layer:

case 'readLocalFile': {
  const loc: [number, number] | undefined =
    params.startLine !== undefined || params.endLine !== undefined
      ? [params.startLine ?? 0, params.endLine ?? 200]
      : undefined;
  return { fullContent: params.fullContent, loc, path: params.path };
}

When neither startLine nor endLine is provided, loc is undefined, which causes the readLocalFile backend to use its own default of [0, 200] — preserving existing behavior.

Testing

  • Verified with existing unit tests in packages/local-file-shell/src/file/__tests__/file.test.ts and apps/desktop/src/main/controllers/__tests__/LocalFileCtr.test.ts that the underlying readLocalFile correctly slices lines when loc is provided
  • The fix closes the gap where loc was never reaching the file-reading layer

The `denormalizeParams` method in `LocalSystemExecutionRuntime` was
missing a case for `readLocalFile`. It fell through to `default`, which
passed `{startLine, endLine, path}` as-is to the IPC layer. However,
the IPC handler (`LocalFileCtr.readFile`) expects `LocalReadFileParams`
with `loc?: [number, number]`, not `startLine`/`endLine`. As a result,
`loc` was always `undefined` on the IPC side, causing `readLocalFile`
to default to `[0, 200]` and always return content from line 0.

Fix: add an explicit `readLocalFile` case that reconstructs the `loc`
tuple from `startLine` and `endLine` before forwarding to the IPC layer.

Fixes lobehub#13735
@vercel

vercel Bot commented Apr 12, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the LobeHub OSS Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@lobehubbot

Copy link
Copy Markdown
Member

@Innei @arvinxx - This involves the Desktop Electron local-system tool runtime and tool calling (readLocalFile IPC). Please coordinate.

@codecov

codecov Bot commented Apr 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.56%. Comparing base (5b03f00) to head (6831d86).
⚠️ Report is 117 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13748      +/-   ##
==========================================
- Coverage   66.58%   66.56%   -0.03%     
==========================================
  Files        1999     2022      +23     
  Lines      165955   171262    +5307     
  Branches    19193    16654    -2539     
==========================================
+ Hits       110503   113998    +3495     
- Misses      55328    57139    +1811     
- Partials      124      125       +1     
Flag Coverage Δ
app 58.61% <ø> (+0.18%) ⬆️
database 92.49% <ø> (-0.12%) ⬇️
packages/agent-runtime 79.72% <ø> (-9.26%) ⬇️
packages/context-engine 83.33% <ø> (-2.19%) ⬇️
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (+8.05%) ⬆️
packages/model-bank 99.86% <ø> (+<0.01%) ⬆️
packages/model-runtime 84.20% <ø> (-0.46%) ⬇️
packages/prompts 69.24% <ø> (+3.44%) ⬆️
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.14% <ø> (+0.11%) ⬆️
packages/web-crawler 88.66% <ø> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 65.70% <ø> (-1.40%) ⬇️
Services 52.19% <ø> (+0.64%) ⬆️
Server 66.31% <ø> (+0.35%) ⬆️
Libs 52.83% <ø> (+1.79%) ⬆️
Utils 91.07% <ø> (+0.05%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Innei Innei merged commit 37bf1bd into lobehub:canary Apr 12, 2026
16 of 18 checks passed
@lobehubbot

Copy link
Copy Markdown
Member

❤️ Great PR @octo-patch ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

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.

[Bug] readLocalFile loc parameter is displayed in UI but ignored in actual content — always returns from line 0

3 participants