Repository navigation
fix(jobs): derive SyncLectureMetadata's scope once, so the log and the query cannot disagree - #720
Conversation
… log The opening log line read `where ? ... : 'all lectures'`. `where` is an object on both branches of the ternary above it, so it is always truthy and the unscoped arm was unreachable. On a run with no input, `lectureIds!.length` then threw a TypeError before the first lecture was read — and the monthly schedule (`0 3 1 * *`) is exactly that run. Every case in the int spec passed `lectureIds`, so the one path that runs in production had no cover. The new case runs the handler with no input at all and asserts the logged scope. Reintroducing `where ?` turns it red with the production TypeError, which is how it was confirmed. Closes #715 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EgER1gbKXnNKyM8qGLvwhV
|
🚅 Deployed to the SahajCloud-pr-720 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Holistic assessment. Right-sized: 24/-1 across two files, and every line of it traces to #715's acceptance criteria — no refactor smuggled in, no config knob, where genuinely untouched. The diagnosis holds up against the code: where is an object on both branches, the unscoped arm was dead, and the monthly 0 3 1 * * run is the only caller that hits it. The new case is non-vacuous and was confirmed red at the causing site. Nothing here touches a cross-repo contract.
The one shape question is that the fix repairs the instance and leaves the cause in place: whether the run is scoped is still decided twice, in two differently-written expressions, ten lines apart — which is precisely how they came to disagree. Deriving it once costs the same line of behaviour change and also retires the ! assertion and the explanatory comment. Everything else is small.
Findings
should-fix—SyncLectureMetadata.ts:79: the scoped-ness test is still duplicated (Array.isArray(lectureIds) && lectureIds.length > 0vslectureIds?.length), and the two can still disagree for a non-arrayjsoninput. Deriving it once removes the class, not the instance. [thread]consider—SyncLectureMetadata.ts:77-78: the added comment explains the deleted code rather than the code that is there; #715, the PR body and the commit message already hold that story. [thread]consider—sync-lecture-metadata.int.spec.ts:185: the only case in the file that bypassesrunTask, over a distinction (undefinedvs{}input) the handler cannot observe. [thread]
What was checked
- #715 read in full and measured against the diff — both acceptance criteria (
scope: 'all lectures'on an unscoped run, scoped runs still logginglectureIds[N]) are met by the one changed line, and the "fails when the defect is reintroduced" criterion is evidenced in the PR body's table. src/jobs/SyncLectureMetadata/SyncLectureMetadata.tsread whole at2cfcf46. Confirmed the fix does not alterwhere(lines 70-73) and so cannot change which lectures are swept; confirmedlectureIds?.lengthandArray.isArray(…) && length > 0agree for everynumber[] | undefinedinput, and diverge only for a non-array truthy with alength.- Does the class generalise?
grep -rn "where ?" src/,grep -rn '!\.length' src/, andgrep -rn 'scope:' src/jobs/each return this line and nothing else. This is the only instance insrc/— no follow-up ticket is warranted. tests/int/sync-lecture-metadata.int.spec.tsread whole, plustests/utils/taskRunner.ts. Confirmed the new case is self-sufficient (creates its own lecture, sototalProcessed > 0does not depend on test order), thatvi.spyOnis installed after setup and restored infinally, and that the unscoped sweep re-syncing earlier tests' lectures is harmless because no later case reads one.- #714's diff checked for overlap. It rewrites lines 1, 13-22, 48-58 and 67 of the same file and ~line 103 of the same spec — it does not touch line 77, so this fix is not duplicated there. One correction to the PR body: at ten lines and ~70 lines of separation respectively, the two branches should merge without a textual conflict in either order.
- Contract surfaces: none. Internal job, no generated-type flow, no endpoint or embed surface.
- Reviewer profile read from
workflow/skills/adversarial-review/reviewer-profile.md.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
…e scheduled shape Addresses the review on #720. The fix in 2cfcf46 made the log line and the query agree for the array case. It left the cause in place: whether a run is scoped was still decided twice, ten lines apart, in two differently-written expressions. `input` is an unvalidated `json` field, so the two could still disagree — a manual run passing `{ lectureIds: "abc" }` takes the unfiltered `where` branch while the log line reads `lectureIds[3]`, the same lie about scope one input shape over. `scopedIds` is now derived once and both readers use it. That retires the `!` assertion and the comment explaining the deleted code. The spec's `runTask` helper no longer defaults `input` to `{}`, so `runTask(payload)` reproduces the scheduled run's literally absent input, and the new case stops being the only one that bypasses the helper. The handler reads `input?.lectureIds`, so `{}` and absent were never distinguishable — the default was not what hid this defect. Nothing had called `runTask(payload)` at all. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015PxdvGktTVasmM1TrVUwi2
|
Revised in The scope is now derived once as Title updated: the change is no longer "test One correction to the PR body, from the third finding: the helper's The integration spec was not re-run here: no Postgres is reachable from this session. Lint, both typechecks and the unit lane are green; CI runs the int lane. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#720 and #717 landed on main while this PR was open. #720 rewrote the scope derivation in SyncLectureMetadata.ts, a few lines from this branch's own edits to the same file. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017yU3grG7LTeRqSccKfdm91 # Conflicts: # src/jobs/SyncLectureMetadata/SyncLectureMetadata.ts
…e scheduled shape Addresses the review on #720. The fix in e9c503d made the log line and the query agree for the array case. It left the cause in place: whether a run is scoped was still decided twice, ten lines apart, in two differently-written expressions. `input` is an unvalidated `json` field, so the two could still disagree — a manual run passing `{ lectureIds: "abc" }` takes the unfiltered `where` branch while the log line reads `lectureIds[3]`, the same lie about scope one input shape over. `scopedIds` is now derived once and both readers use it. That retires the `!` assertion and the comment explaining the deleted code. The spec's `runTask` helper no longer defaults `input` to `{}`, so `runTask(payload)` reproduces the scheduled run's literally absent input, and the new case stops being the only one that bypasses the helper. The handler reads `input?.lectureIds`, so `{}` and absent were never distinguishable — the default was not what hid this defect. Nothing had called `runTask(payload)` at all. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_015PxdvGktTVasmM1TrVUwi2
#720 and #717 landed on main while this PR was open. #720 rewrote the scope derivation in SyncLectureMetadata.ts, a few lines from this branch's own edits to the same file. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017yU3grG7LTeRqSccKfdm91 # Conflicts: # src/jobs/SyncLectureMetadata/SyncLectureMetadata.ts
Closes #715.
The failure this prevents
SyncLectureMetadata's opening log line dereferencedlectureIdsbehind a guard that can never be false:whereis assigned an object on both branches, so it is always truthy and the'all lectures'arm was unreachable. On a run with no input,lectureIdsisundefinedandlectureIds!.lengththrows aTypeError— before a single lecture is read.The monthly schedule (
0 3 1 * *, queuemonthly) is exactly that run. It passes no input, so the job has been throwing on its own first log line on every scheduled sweep.The change
The scope is decided once, and both readers use it:
The first revision fixed the instance — it tested
lectureIds?.lengthinstead ofwhere. Review pointed out that the cause survived: "is this run scoped?" was still asked twice, ten lines apart, in two differently-written expressions, which is how the two came to disagree in the first place. They could still disagree, too:lectureIdsarrives from an unvalidatedjsoninput field, so{ lectureIds: "abc" }takes the unfilteredwherebranch while the log line readslectureIds[3]— the same lie about scope, one input shape over.Same one line of behaviour change. The
!assertion goes with it, and the filtering behaviour is unchanged.Why no test caught it
Every case in
tests/int/sync-lecture-metadata.int.spec.tspassedlectureIds, so the one path that runs in production was uncovered. Nothing had calledrunTask(payload)at all — that, not the helper's oldinput ?? {}default, is why this was invisible. The handler readsinput?.lectureIds, so{}and an absentinputwere never distinguishable to it.The helper now passes
inputthrough, so it can express the scheduled shape:and the new case is
await runTask(payload), asserting the logged scope. It is no longer the only case in the file that bypasses the helper.Test results
The new case was confirmed failing first, by reintroducing the defect at the site that causes it:
scope: where ? …back in placeruns unscoped when the schedule passes no input at all→TypeError: Cannot read properties of undefined (reading 'length'). 1 failed, 8 passedThat table was measured on the first revision (
2cfcf46), against a real Postgres.Re-run after the review changes (
8084a0e5):pnpm lint✓pnpm typecheck✓ ·pnpm typecheck:tests✓pnpm test:unit✓ — 125 files, 1601 teststests/int/sync-lecture-metadata.int.spec.ts— not re-run. No Postgres is reachable from the session that made these changes. CI runs it against itspostgres:18container.Notes for reviewer
This was flagged by two independent review passes on #714, which edits the line above it. It is filed separately because #714 is a type-level refactor and this is a behaviour fix. The two branches both touch
SyncLectureMetadata.tswithin a few lines, so whichever merges second will want a trivial conflict resolution.🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_015PxdvGktTVasmM1TrVUwi2