Skip to content

fix(telemetry): resolve the repository from the host, not from payload.cwd - #892

Merged
blafourcade merged 1 commit into
ai-driven-dev:nextfrom
dkp-consult:fix/telemetry-file-written-host-cwd
Sep 20, 2026
Merged

blafourcade merged 1 commit into
ai-driven-dev:nextfrom
dkp-consult:fix/telemetry-file-written-host-cwd

Conversation

@dkp-consult

@dkp-consult dkp-consult commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🎯 What & why

handleFileWritten resolved the runs directory from payload.cwd, one host's spelling read as a rule, where handleTaskFilesObserved already reads the host's own readCwd. A host naming its workspace any other way had every write it stated dropped, and the turn-end walk then recorded the same file as observed — a loss that reads as ordinary output, which is why nothing caught it.

Split out of the Antigravity work in #859 at the maintainer's request: a defect in shipped code, no roadmap decision needed.

🛠️ How it works

One line — file-writes.cjs:107 now reads readCwd(host, payload), the same seam the observed pass uses three lines of the same shape below.

No declared host changes behaviour: the four naming no written path (Codex, Copilot, Cursor, OpenCode) return at statedRawPath before that line, and Claude Code declares readCwd: (payload) => payload.cwd. That is also why the regression test carries a test-only host: the only host that states a written path is the only one that carries cwd, so the witness is one more table entry — a workspace named in its own field, no cwd, and a hook working directory outside the repository. It lives in require.cache for the body of the test only.

🧪 How to verify

node --test scripts/__tests__/aidd-telemetry-file-writes.test.js   # 5 pass
# revert the one line to resolveRunsDir(payload.cwd) and rerun     # 4 pass, 1 fail:
#                                                                 # "the path the host stated was dropped"

That A/B is the before/after measured in #859: session_start alone, versus session_start + file_written with source: "tool-stated".

Whole suite, as the scripts-tests pre-commit command runs it, on next 83b0246e plus this branch:

pnpm install --frozen-lockfile            # and the same inside cli/, which installs independently
node scripts/check-tests-leave-git-alone.js -- node --test 'scripts/__tests__/**/*.test.js'

→ 454 tests, 454 pass, 0 fail, 0 skipped (macOS 27, Node 26.5.0, pnpm 12.3.4).

⚠️ Heads-up

🔗 Linked issue

Refs #859

✅ I certify

  • I DO CERTIFY I READ EACH LINE OF THE PULL REQUEST BECAUSE I AM A SOFTWARE ENGINEER, NOT A AI PUPPY.

@dkp-consult
dkp-consult requested a review from a team as a code owner September 20, 2026 06:30
Copilot AI lite review requested due to automatic review settings September 20, 2026 06:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The functional change is minimal and aligns handleFileWritten with existing host-abstracted behavior, with only a small test-mock consistency nit noted.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes telemetry’s handleFileWritten to resolve the repository root via the host’s readCwd(host, payload) (consistent with the observed-files pass), preventing tool-stated writes from being dropped when a host’s workspace path is not payload.cwd.

Changes:

  • Update handleFileWritten to use readCwd(host, payload) instead of payload.cwd when resolving the runs directory.
  • Add a regression test that injects a test-only host entry to validate tool-stated writes when the host reports a workspace path (without cwd).
File Description
scripts/​__tests__/​aidd-telemetry-file-writes.test.js Adds regression coverage using an injected host table entry to reproduce the workspace-vs-cwd mismatch.
plugins/​aidd-telemetry/​hooks/​lib/​file-writes.cjs Switches repo resolution for tool-stated writes to host-provided readCwd, aligning behavior with the observed pass.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +171 to +176
require.cache[indexId].exports = {
...realExports,
TOOLS_BY_HOST: tools,
toolFor: (host) => tools[host] || null,
readCwd: (host, payload) => (tools[host] ? tools[host].readCwd(payload) : undefined),
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed. readSessionId now resolves through the same merged table as toolFor and readCwd, so the stub is consistent whichever of the three a caller reaches for:

const toolFor = (host) => tools[host] || null;
readCwd: (host, payload) => (toolFor(host) ? toolFor(host).readCwd(payload) : undefined),
readSessionId: (host, payload) => (toolFor(host) ? toolFor(host).readSessionId(payload) : undefined),

Pushed in b79c7a8, which also trims the comments on both files down to the density of the code around them.

…d.cwd

handleFileWritten resolved the runs directory from payload.cwd, one host's spelling read
as a rule, where handleTaskFilesObserved already reads the host's own readCwd. A host
naming its workspace any other way had every write it stated dropped, and the turn-end
walk then recorded the same file as "observed".

No declared host changes behaviour: the four naming no written path return before that
line, and Claude Code declares readCwd: (payload) => payload.cwd. The regression test
therefore carries a test-only host entry.

Refs ai-driven-dev#859

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dkp-consult
dkp-consult force-pushed the fix/telemetry-file-written-host-cwd branch from 2764f6b to b79c7a8 Compare September 20, 2026 06:44
@blafourcade
blafourcade merged commit 949642d into ai-driven-dev:next Sep 20, 2026
24 checks passed
@aidd-bot aidd-bot Bot mentioned this pull request Sep 24, 2026
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.

3 participants