Skip to content

Fix resubmit_job_to_watched_files publishing bare filename instead of archive path - #700

Merged
Dagonite merged 5 commits into
mainfrom
fix_resubmit_watched_files_path
Oct 5, 2026
Merged

Dagonite merged 5 commits into
mainfrom
fix_resubmit_watched_files_path

Conversation

@Pasarus

@Pasarus Pasarus commented Sep 30, 2026

Copy link
Copy Markdown
Member

Description

Run.filename only ever stores the bare filename (not a path), so resubmit_job_to_watched_files was publishing an unusable filename to the watched-files queue instead of a real file path.

This adds find_file_in_archive() in fia_api/core/utility.py, which resolves an instrument + filename to a real path:

  • IMAT: flat lookup directly under IMAT_DIR (default /imat).
  • All other instruments: lookup under ARCHIVE_DIR/NDX{INSTRUMENT}/Instrument/data (default ARCHIVE_DIR=/archive), using the run's run_start to guess the likely cycle folder (fast path) before falling back to a recursive search of the instrument's data directory.

resubmit_job_to_watched_files now resolves and publishes the full path, raising JobRequestError (400) if the file cannot be located anywhere.

Draft PR for review before finalising.

Run.filename only ever stores the bare filename, not a path, so
resubmit_job_to_watched_files was publishing an unusable filename to
the watched-files queue instead of a real file path.

Add find_file_in_archive() which resolves an instrument + filename to
its real path: a flat lookup under IMAT_DIR for IMAT, or a cycle-aware
lookup under ARCHIVE_DIR/NDX{INSTRUMENT}/Instrument/data for every
other instrument (using the run's start date to guess the likely cycle
folder before falling back to a recursive search). Wire this into
resubmit_job_to_watched_files, raising JobRequestError when the file
cannot be located.
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.81%. Comparing base (c172a67) to head (355c471).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #700      +/-   ##
==========================================
+ Coverage   96.76%   96.81%   +0.04%     
==========================================
  Files          50       50              
  Lines        2227     2259      +32     
==========================================
+ Hits         2155     2187      +32     
  Misses         72       72              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Real archive data shows some years have up to 6+ sub-cycles (e.g.
cycle_02_6), so widen the year-guessed fast-path candidates from 1-5
to 1-8 to reduce reliance on the recursive fallback search.
find_file_in_archive's recursive fallback delegated to
_safe_find_file_in_dir, which raises AuthError when the target
directory doesn't exist at all. This meant resubmit_job_to_watched_files
surfaced a 403 Forbidden instead of the intended 400 JobRequestError
whenever an instrument's archive data directory wasn't present, as
seen failing in CI's e2e-job-maker test_resubmit_job_file_not_found.

Guard the fallback so a missing instrument data directory is treated
as a normal not-found result.
@Pasarus
Pasarus marked this pull request as ready for review September 30, 2026 11:05
@Pasarus
Pasarus requested a review from Dagonite September 30, 2026 11:05
Comment thread fia_api/core/utility.py

for year in (run_start.year, run_start.year - 1):
for cycle_name in _cycle_candidate_names(year):
candidate = instrument_dir / cycle_name / filename

@Dagonite Dagonite Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With this line and 193, could they return 400 for valid files? Run.filename doesn’t include the extension because the job controller uses .stem. Lookups would search for MAR123456 instead of MAR123456.nxs (for example).

The tests added include extensions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are entirely correct, I've also decided that I hate the recursive archive search and how long it takes so we are only doing "fast" searches.

find_file_in_archive now appends .nxs to filename if missing, since
Run.filename is not guaranteed to include the extension even though
raw NeXus files on the archive always carry it. Also removes the
recursive fallback search of the instrument's data directory, since a
full scan is too expensive to run on every lookup - a miss on every
year-guessed cycle candidate is now treated as not found.
@Dagonite
Dagonite merged commit 9707aa0 into main Oct 5, 2026
10 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