Skip to content

Fix wt-metadata-refresh failing on .bazelproject with commented directories#64

Merged
guodong-sq merged 1 commit intoblock:mainfrom
cshtdd:camilos/fix-metadata-refresh-comments
Apr 15, 2026
Merged

Fix wt-metadata-refresh failing on .bazelproject with commented directories#64
guodong-sq merged 1 commit intoblock:mainfrom
cshtdd:camilos/fix-metadata-refresh-comments

Conversation

@cshtdd
Copy link
Copy Markdown
Contributor

@cshtdd cshtdd commented Apr 14, 2026

Why

wt-metadata-refresh always fails when the .bazelproject file contains commented-out directories (e.g. # ca, # deposits).

What

  • Fix awk regex that failed to filter commented lines — [^#] matched the second space character instead of the #, leaking invalid paths like //# ca/... into the bazel query
  • Use --keep_going and || true so directories without BUILD files (e.g. .github, .hooks) don't kill the entire query via pipefail

Risk Assessment

Low — only affects the metadata refresh script, no production services.

Testing

Discovery: Running wt-metadata-refresh failed with Bazel query failed for base (exit code: 2). The stderr was suppressed (2>/dev/null), so the root cause wasn't visible.

Root cause analysis:

  1. Ran the awk parser in isolation and found commented lines like # ca were passing through:

    printf '  # ca\n' | awk '/^[[:space:]]+[^#]/ { print "MATCH" }'
    # Output: MATCH
    

    The regex [[:space:]]+ only consumed one space, then [^#] matched the second space — not the #.

  2. Confirmed the generated query included invalid paths like //# ca/..., causing bazel query to fail entirely.

  3. After fixing the awk regex, bazel query still failed because .github and .hooks have no BUILD files:

    bazel query "kind('.*', //.github/... + //account-status/...)" --output=label
    # ERROR: no targets found beneath '.github'  (exit code 7)
    

Validation: After both fixes, ran wt-metadata-refresh successfully — refreshed 14,949 targets and re-exported 53 metadata directories to the vault.

Generated with Amp

…tories

Two bugs caused metadata refresh to always fail:

1. The awk regex for parsing .bazelproject commented lines (e.g. '  # ca')
   didn't actually filter them out — [^#] matched the second space char,
   so invalid paths like '//# ca/...' leaked into the bazel query.

2. set -o pipefail + piping bazel query into sort meant any non-zero exit
   from bazel query (e.g. 'no targets found beneath .hooks') killed the
   whole pipeline before the exit code could be captured.

Fix: strip whitespace first then check for '#' prefix, use --keep_going
to tolerate missing targets, and || true to avoid pipefail issues.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d8e51-8b94-7615-a478-c7aa9b77f49c
@cshtdd cshtdd force-pushed the camilos/fix-metadata-refresh-comments branch from 21142b1 to 7dd25dd Compare April 14, 2026 23:33
@cshtdd cshtdd marked this pull request as ready for review April 14, 2026 23:45
@guodong-sq guodong-sq merged commit 9e202ef into block:main Apr 15, 2026
6 checks passed
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