Skip to content

fix(search-index): use portable URL ids and automate CI rebuild#472

Open
vipulpandey21 wants to merge 1 commit into
krkn-chaos:mainfrom
vipulpandey21:fix/search-index-portable-ids-ci-rebuild
Open

fix(search-index): use portable URL ids and automate CI rebuild#472
vipulpandey21 wants to merge 1 commit into
krkn-chaos:mainfrom
vipulpandey21:fix/search-index-portable-ids-ci-rebuild

Conversation

@vipulpandey21

@vipulpandey21 vipulpandey21 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #471

static/search-index.json -- the file the AI chatbot uses to power
documentation search -- was committed with absolute filesystem paths from
a specific contributor's machine hardcoded into every document id field
(/Users/sahil/website-1/content/en/... across all 167 documents), and
frozen since February 13, 2026.

The chatbot's DocumentationIndex.js fetches this file at runtime, so
the AI assistant was searching a 3-month-old, path-polluted index and
returning no results for any doc page added since then.

Root cause: scripts/build-search-index.js used id: filePath (raw
absolute OS path) instead of the already-computed relative URL. The CI
workflow only POSTed to the live Netlify serverless function, which runs
on a read-only filesystem and cannot write back to the static file — so
static/search-index.json was never actually regenerated by CI.

Changes

scripts/build-search-index.js (1 line)

  • id: filePathid: url
  • url is already computed two lines above as a portable relative path
    (e.g. /docs/scenarios/pod-scenario/). No other logic changes.

.gitignore

  • Add static/search-index.json to prevent contributors from
    accidentally committing a locally-built, machine-specific version.
    The CI workflow intentionally force-adds it via git add -f.

.github/workflows/rebuild-docs-index.yml

  • Add Node.js setup + node scripts/build-search-index.js to regenerate
    the static file from source on every content change.
  • Commit the fresh index back to main with [skip ci] to prevent
    workflow loops.
  • Use fetch-depth: 0 + explicit GITHUB_TOKEN so the push
    authenticates correctly in the Actions runner.
  • Demote the Netlify API reload to non-fatal since the static file is
    now the source of truth.

Testing

  • Verified all 167 document id fields in the committed index contain
    /Users/sahil/website-1/... (another contributor's Mac path).
  • Verified buildTime: 2026-02-13 — index was 3+ months stale.
  • Confirmed git log -- static/search-index.json shows only 3 commits
    ever, none triggered by CI automation.
  • The one-line fix in build-search-index.js is the only change to the
    indexer logic; all other fields were already correct.

Signed-off-by

Signed-off-by: Vipul Pandey vipulpandey7917@gmail.com

@netlify

netlify Bot commented May 16, 2026

Copy link
Copy Markdown

Deploy Preview for krkn-chaos ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9256a17
🔍 Latest deploy log https://app.netlify.com/projects/krkn-chaos/deploys/6a0d531085fe6300085a2218
😎 Deploy Preview https://deploy-preview-472--krkn-chaos.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the needs-dco Commits are missing a Signed-off-by line label May 16, 2026
@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Fix search index portable IDs and automate CI rebuild

🐞 Bug fix ✨ Enhancement

Grey Divider

Walkthroughs

Description
• Fix hardcoded machine-specific paths in search index document IDs
  - Replace absolute filesystem paths with portable relative URLs
• Automate search index regeneration in CI workflow
  - Add Node.js setup and build step to rebuild index on content changes
  - Commit regenerated index back to main branch
• Prevent accidental commits of locally-built search index
  - Add static/search-index.json to .gitignore
  - CI uses git add -f to intentionally track canonical version
• Demote Netlify API reload to non-fatal operation
  - Static file now source of truth instead of serverless function
Diagram
flowchart LR
  A["Markdown content files"] -->|"build-search-index.js"| B["Search index with portable URLs"]
  B -->|"CI workflow"| C["static/search-index.json"]
  C -->|"git commit + push"| D["Repository main branch"]
  D -->|"runtime fetch"| E["Chatbot DocumentationIndex.js"]
  E -->|"search results"| F["AI Assistant"]
Loading

Grey Divider

File Changes

1. scripts/build-search-index.js 🐞 Bug fix +1/-1

Replace absolute paths with portable URLs

• Changed document id field from filePath (absolute OS path) to url (portable relative path)
• Fixes hardcoded machine-specific paths like /Users/sahil/website-1/... in all 167 documents
• Ensures search index is path-portable across all environments

scripts/build-search-index.js


2. .gitignore ⚙️ Configuration changes +0/-0

Exclude generated search index from version control

• Add static/search-index.json to prevent accidental commits of locally-built versions
• CI workflow intentionally force-adds via git add -f to track canonical version
• Prevents contributors from committing machine-specific generated artifacts

.gitignore


3. .github/workflows/rebuild-docs-index.yml ✨ Enhancement +42/-9

Automate search index rebuild and commit in CI

• Add Node.js setup (v20) with npm caching for build environment
• Add build step to regenerate static/search-index.json from source markdown
• Add git commit-back step to push updated index to main with [skip ci] flag
• Configure checkout with fetch-depth: 0 and explicit GITHUB_TOKEN for push authentication
• Demote Netlify API reload from fatal to non-fatal operation with updated messaging
• Update step names and output messages to reflect static file as source of truth

.github/workflows/rebuild-docs-index.yml


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented May 16, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Action required

1. Stale index after merge 🐞 Bug ≡ Correctness
Description
The generator now emits portable IDs (id: url), but the committed static/search-index.json in
this branch still contains absolute /Users/... IDs; merging this PR alone will not necessarily
rebuild that file because the workflow only triggers on content/en/**/*.md changes. This leaves
the production-served index polluted/stale until the next docs content change or a manual run that
rebuilds and commits the file.
Code

scripts/build-search-index.js[57]

+                    id: url,
Evidence
The script change makes IDs portable, but the currently tracked index file still contains absolute
/Users/... IDs, and the workflow is configured to run only when markdown under content/en/
changes; therefore merging this PR alone may not regenerate the committed index.

scripts/build-search-index.js[52-66]
.github/workflows/rebuild-docs-index.yml[8-13]
static/search-index.json[1-22]
api/services/DocumentationIndex.js[30-53]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`scripts/build-search-index.js` now correctly sets `document.id = url`, but the tracked `static/search-index.json` currently checked into this branch still contains absolute machine paths. Because the rebuild workflow is path-filtered to only run on documentation markdown changes, merging this PR without any `content/en/**/*.md` change will not automatically regenerate and commit the corrected index.

## Issue Context
- Runtime loads `/search-index.json` from the deployed site; if the tracked file stays polluted, search continues to serve bad IDs.
- Current workflow trigger is restricted to `content/en/**/*.md`.

## Fix Focus Areas
- Regenerate and commit `static/search-index.json` in this PR (force-add since it’s gitignored), **and/or**
- Expand workflow `on.push.paths` to include `scripts/build-search-index.js` (and any other generator inputs) so merging this PR triggers a rebuild.

### References
- .github/workflows/rebuild-docs-index.yml[8-13]
- scripts/build-search-index.js[52-66]
- static/search-index.json[1-22]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. npm ci likely fails 🐞 Bug ☼ Reliability
Description
The workflow runs npm ci, but the repository ignores package-lock.json, which makes a lockfile
unlikely to be present in the checkout and can cause the install step to fail. If dependency install
fails, the CI job will never rebuild/commit static/search-index.json.
Code

.github/workflows/rebuild-docs-index.yml[R41-43]

+      - name: Install dependencies
+        run: npm ci
+
Evidence
The workflow explicitly runs npm ci, while the repo configuration ignores package-lock.json; the
index build script depends on packages declared in the root package.json, so a failed install
breaks the rebuild automation.

.github/workflows/rebuild-docs-index.yml[35-47]
.gitignore[15-22]
package.json[9-46]
scripts/build-search-index.js[8-13]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The rebuild workflow uses `npm ci`, which requires a committed lockfile. This repo’s `.gitignore` ignores `package-lock.json`, so `npm ci` is at high risk of failing on GitHub Actions runners.

## Issue Context
The index rebuild step (`node scripts/build-search-index.js`) depends on Node dependencies from the root `package.json`. If `npm ci` fails, the workflow cannot rebuild or commit the updated index.

## Fix Focus Areas
- Either commit a root `package-lock.json` and stop ignoring it, or
- Change the workflow step from `npm ci` to `npm install` (less deterministic but compatible with no lockfile).

### References
- .github/workflows/rebuild-docs-index.yml[35-47]
- .gitignore[15-22]
- package.json[9-46]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Manual reload can be stale 🐞 Bug ☼ Reliability
Description
On workflow_dispatch, the job can push an updated static/search-index.json but skips the Netlify
deployment wait (only runs on push) and still immediately calls the Netlify reload endpoint. This
can reload the serverless cache before the new static index is deployed, leaving the live function
serving stale data.
Code

.github/workflows/rebuild-docs-index.yml[R49-63]

+      - name: Commit updated index
+        run: |
+          git config user.name "github-actions[bot]"
+          git config user.email "github-actions[bot]@users.noreply.github.com"
+          # Use -f because static/search-index.json is listed in .gitignore
+          # (it is a generated artifact, but we intentionally track the canonical
+          # copy so the Netlify serverless function can fetch it at runtime)
+          git add -f static/search-index.json
+          if git diff --staged --quiet; then
+            echo "ℹ️  No index changes to commit."
+          else
+            git commit -m "chore: rebuild search index [skip ci]"
+            git push origin HEAD:main
+            echo "✅ Updated search index committed and pushed."
+          fi
Evidence
The workflow conditionally waits only on push, but the newly added commit-and-push step runs for
all events and the reload call is unconditional, creating a timing window where reload happens
before the new static asset is deployed.

.github/workflows/rebuild-docs-index.yml[49-70]
.github/workflows/rebuild-docs-index.yml[82-107]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
When manually triggered (`workflow_dispatch`), the workflow may push a new commit and then immediately notify the Netlify function to reload without waiting for the site to deploy the new `search-index.json`.

## Issue Context
- `Wait for Netlify deployment` is guarded by `if: github.event_name == 'push'`.
- The reload notification step has no guard and runs for both push and manual dispatch.

## Fix Focus Areas
- Apply the wait step (or a deployment-polling loop) to `workflow_dispatch` as well when a commit was pushed, or
- Guard the notify step so it runs only for `push`, and document that manual runs require a later reload.

### References
- .github/workflows/rebuild-docs-index.yml[49-70]
- .github/workflows/rebuild-docs-index.yml[82-107]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo


const document = {
id: filePath,
id: url,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Stale index after merge 🐞 Bug ≡ Correctness

The generator now emits portable IDs (id: url), but the committed static/search-index.json in
this branch still contains absolute /Users/... IDs; merging this PR alone will not necessarily
rebuild that file because the workflow only triggers on content/en/**/*.md changes. This leaves
the production-served index polluted/stale until the next docs content change or a manual run that
rebuilds and commits the file.
Agent Prompt
## Issue description
`scripts/build-search-index.js` now correctly sets `document.id = url`, but the tracked `static/search-index.json` currently checked into this branch still contains absolute machine paths. Because the rebuild workflow is path-filtered to only run on documentation markdown changes, merging this PR without any `content/en/**/*.md` change will not automatically regenerate and commit the corrected index.

## Issue Context
- Runtime loads `/search-index.json` from the deployed site; if the tracked file stays polluted, search continues to serve bad IDs.
- Current workflow trigger is restricted to `content/en/**/*.md`.

## Fix Focus Areas
- Regenerate and commit `static/search-index.json` in this PR (force-add since it’s gitignored), **and/or**
- Expand workflow `on.push.paths` to include `scripts/build-search-index.js` (and any other generator inputs) so merging this PR triggers a rebuild.

### References
- .github/workflows/rebuild-docs-index.yml[8-13]
- scripts/build-search-index.js[52-66]
- static/search-index.json[1-22]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +41 to +43
- name: Install dependencies
run: npm ci

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. Npm ci likely fails 🐞 Bug ☼ Reliability

The workflow runs npm ci, but the repository ignores package-lock.json, which makes a lockfile
unlikely to be present in the checkout and can cause the install step to fail. If dependency install
fails, the CI job will never rebuild/commit static/search-index.json.
Agent Prompt
## Issue description
The rebuild workflow uses `npm ci`, which requires a committed lockfile. This repo’s `.gitignore` ignores `package-lock.json`, so `npm ci` is at high risk of failing on GitHub Actions runners.

## Issue Context
The index rebuild step (`node scripts/build-search-index.js`) depends on Node dependencies from the root `package.json`. If `npm ci` fails, the workflow cannot rebuild or commit the updated index.

## Fix Focus Areas
- Either commit a root `package-lock.json` and stop ignoring it, or
- Change the workflow step from `npm ci` to `npm install` (less deterministic but compatible with no lockfile).

### References
- .github/workflows/rebuild-docs-index.yml[35-47]
- .gitignore[15-22]
- package.json[9-46]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@vipulpandey21 vipulpandey21 force-pushed the fix/search-index-portable-ids-ci-rebuild branch from ed6e5dc to 2a65215 Compare May 16, 2026 21:33
@github-actions github-actions Bot removed the needs-dco Commits are missing a Signed-off-by line label May 16, 2026
@vipulpandey21 vipulpandey21 force-pushed the fix/search-index-portable-ids-ci-rebuild branch from 2a65215 to d594fc0 Compare May 16, 2026 21:36
The committed static/search-index.json contained absolute filesystem
paths from a specific developer's machine (/Users/sahil/website-1/...)
baked into every document id field, and was frozen since February 2026
(167 docs). The CI workflow only pinged the live Netlify API (read-only
filesystem) so the static file was never actually regenerated by CI.

Changes:
- scripts/build-search-index.js: replace id:filePath (absolute OS path)
  with id:url so the index is path-portable across all environments
- static/search-index.json: rebuilt locally with the fixed indexer;
  now contains 208 portable relative-URL ids and a current buildTime
- .gitignore: exclude static/search-index.json from accidental manual
  commits; the CI workflow intentionally force-adds it via git add -f
- .github/workflows/rebuild-docs-index.yml: add Node setup + index
  rebuild + git commit-back steps so the file stays current on every
  content change; use npm install (not npm ci) because package-lock.json
  is listed in .gitignore and would not be present in the CI checkout;
  use fetch-depth:0 and explicit GITHUB_TOKEN for push authentication;
  validate SITE_URL starts with https:// before passing to curl;
  demote Netlify reload to non-fatal since static file is source of truth

Fixes krkn-chaos#471

Signed-off-by: vipulpandey21 <vipulpandey7917@gmail.com>
@vipulpandey21 vipulpandey21 force-pushed the fix/search-index-portable-ids-ci-rebuild branch from d594fc0 to 9256a17 Compare May 20, 2026 06:22
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: search-index.json contains hardcoded machine paths and is never rebuilt by CI

1 participant