Skip to content

fix(process): preserve nested path identities during normalization - #2468

Merged
baron merged 1 commit into
morluto:mainfrom
rudycelekli:fix/process-path-normalization
Oct 13, 2026
Merged

baron merged 1 commit into
morluto:mainfrom
rudycelekli:fix/process-path-normalization

Conversation

@rudycelekli

Copy link
Copy Markdown

When a selected executable or filesystem root is inside the working directory, path normalization replaces the parent first. Captures then lose the more specific identities: selected-node becomes <working-directory>/selected-node instead of <executable>, and an observed data root loses its own alias. Match original literal paths once, longest first, while retaining the existing tie priority. Version path-normalized comparison contracts so older semantics are rejected rather than compared silently.

Validation: two module regressions and one real local PTY capture fail on the original implementation. The fix passes 25 module/scenario tests, five native PTY tests (two Linux-only cases skipped on macOS), and npm run check with Node 24.18.0/npm 11.16.0. The capture checks original bytes, normalized identities, legacy-contract rejection and verified owned-process cleanup. An independent Codex review checked alias ties, regexp punctuation and replacement non-cascading on commit 807f4cc.

AI assistance: OpenAI Codex authored the analysis, code, tests and this description, with independent automated review. No human maintainer review is claimed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5 Tier: plus

[Medium impact] Changes how process paths are normalized and matched.

The PR appears safe to merge, with non-blocking follow-ups for repeated path setup and missing edge-case tests.

Findings

  1. P2 Path setup repeats per row ▶
  2. P2 Alias edge cases lack tests ▶
Fix with agent prompt
### Issue 1
src/process/capture/ProcessNormalization.ts:56-64
`normalizePathTokens` rebuilds the alias map, sorts paths, and escapes them on every call. `TerminalRenderer` calls it for every visible row and again for the saved terminal state, for each output chunk. With many observed roots or terminal rows, this repeats avoidable work even though the paths stay unchanged during a capture. Build the matcher once per scenario and temporary root, then reuse it.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
src/process/capture/ProcessNormalization.test.ts:270-278
The new tests cover nested paths and punctuation, but not equal-path priority or keeping inserted aliases untouched. A sequential longest-first rewrite could pass both tests while changing inserted aliases. Overwriting duplicate map keys could also change priority unnoticed. Add two cases:
- `temporaryRoot === scenario.working_directory` to check which alias wins.
- A relative observed root named `working-directory` to check that it cannot rewrite an inserted alias.

These guard two promised behaviors that a later rewrite could otherwise break unnoticed.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR replaces original literal paths in one pass, preferring longer paths while keeping the existing priority for equal paths.

  • Nested paths in process captures keep their selected identities.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Original captured text] --> B[Choose aliases; keep first equal path]
  B --> C[Sort paths longest first]
  C --> D[Escape literal paths]
  D --> E[Replace original matches once]
  E --> F[Apply remaining selected rules]
  G[Paths enabled] --> H[Add path version to comparison contract]
  H --> I[Commit contract digest]
  I --> J{Capture digests equal?}
  J -->|Yes| K[Compare captures]
  J -->|No| L[Reject incompatible captures]
Loading

Reviews (1) · Last reviewed commit: "fix(process): preserve nested path ident..." · Reviewed by Greptile

Comment on lines +56 to +64
const paths = [...aliases.keys()].sort(
(left, right) => right.length - left.length,
);
if (paths.length === 0) return value;
const pattern = paths
.map((path) => path.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"))
.join("|");
return value.replace(
new RegExp(pattern, "gu"),

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.

P2 Path setup repeats per row

normalizePathTokens rebuilds the alias map, sorts paths, and escapes them on every call. TerminalRenderer calls it for every visible row and again for the saved terminal state, for each output chunk. With many observed roots or terminal rows, this repeats avoidable work even though the paths stay unchanged during a capture. Build the matcher once per scenario and temporary root, then reuse it.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/capture/ProcessNormalization.ts
Line: 56-64

Comment:
**Path setup repeats per row**

`normalizePathTokens` rebuilds the alias map, sorts paths, and escapes them on every call. `TerminalRenderer` calls it for every visible row and again for the saved terminal state, for each output chunk. With many observed roots or terminal rows, this repeats avoidable work even though the paths stay unchanged during a capture. Build the matcher once per scenario and temporary root, then reuse it.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +270 to +278
it("normalizes nested paths once using the most specific selected identity", () => {
const declared = parseProcessScenario({
executable: "/workspace/project/bin/program",
working_directory: "/workspace/project",
filesystem_observation_paths: [
"/workspace/project/data",
"/workspace/project/data/cache",
],
normalization: { paths: true, pids: false, ports: false, patterns: [] },

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.

P2 Alias edge cases lack tests

The new tests cover nested paths and punctuation, but not equal-path priority or keeping inserted aliases untouched. A sequential longest-first rewrite could pass both tests while changing inserted aliases. Overwriting duplicate map keys could also change priority unnoticed. Add two cases:

  • temporaryRoot === scenario.working_directory to check which alias wins.
  • A relative observed root named working-directory to check that it cannot rewrite an inserted alias.

These guard two promised behaviors that a later rewrite could otherwise break unnoticed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/capture/ProcessNormalization.test.ts
Line: 270-278

Comment:
**Alias edge cases lack tests**

The new tests cover nested paths and punctuation, but not equal-path priority or keeping inserted aliases untouched. A sequential longest-first rewrite could pass both tests while changing inserted aliases. Overwriting duplicate map keys could also change priority unnoticed. Add two cases:
- `temporaryRoot === scenario.working_directory` to check which alias wins.
- A relative observed root named `working-directory` to check that it cannot rewrite an inserted alias.

These guard two promised behaviors that a later rewrite could otherwise break unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@baron
baron merged commit b9ee921 into morluto:main Oct 13, 2026
39 checks passed
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants