Repository navigation
Conversation
… index, and an off-peak job indexes it An import over IMPORT_INDEX_MAX_LINES, or sent with index=false, now records the indexing it skipped in deferred_import_indexes. A beat task on the indexing queue works through it while IMPORT_INDEX_WINDOW (default 01:00-04:30 UTC) is open, part by part: the new versions, the mapped codes, then a partial update of is_latest_version and source_version in the documents of the versions the import superseded, so they stop showing as duplicates in HEAD search. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex review, pass 1 (codex-cli 0.169.0, commit 9b84b24)Verdict: findings: 7 findings (P1, P2).
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "full",
"commit": "9b84b24e3f76307f24492dd4bc7ff2cbe7b96fe9",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "F1.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1282,
"claim": "Deferring every latest-flag update leaves the release-triggered duplicates that criterion 1 was meant to prevent.",
"scenario": "A daytime import replaces A with B and defers indexing. A subsequent release indexes the missing B document with is_latest_version=true and HEAD membership. A keeps both values in Elasticsearch until the off-peak job runs, so HEAD and global searches can match both versions. Keeping A searchable is useful while B has no document, but the release can make B searchable hours before the deferred patch runs.",
"action": "Make the path that publishes a replacement also partially update its superseded documents. Cover a release that indexes the replacement before the off-peak window.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1370,
"claim": "Completing a part's INDEX stage does not guarantee that a current replacement is searchable when LATEST_FLAGS runs.",
"scenario": "A is searchable. Two deferred imports replace A with B and then B with C before the window opens. The first part indexes B from its current database state, where it is already superseded, then removes A from HEAD. If the window closes before the second part indexes C, the concept disappears from HEAD and global search until the next run.",
"action": "Resolve the current replacement when processing a demotion and keep the demotion pending until that replacement is searchable. Test two successive updates with a window cutoff between their parts.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.3",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1216,
"claim": "Committed import rows can lose their indexing work before it reaches the durable queue.",
"scenario": "A deploy kills an import worker after it commits new concepts with _index=False but before ImportIndexer.finish records the IDs. The IDs were held in memory and the off-peak runner only reads DeferredImportIndex. The concepts can stay missing from search with no pending record an admin can inspect. Resubmitting a create-only import skips the concepts that already exist.",
"action": "Persist indexing intent with the resource writes, or add a recovery path that can reconstruct the affected IDs from committed state after an interrupted import.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.4",
"severity": "P1",
"tag": null,
"file": "core/common/mixins.py",
"line": 881,
"claim": "The partial update leaves stale mapped-code fields on superseded concept documents.",
"scenario": "Release v1 contains concept A and its mapping to code X. While A is still latest, a HEAD mapping update changes its indexed target to Y. A later deferred concept update supersedes A. ConceptDocument.prepare now derives A's mapped codes from its release memberships, but the deferred patch leaves Y in the document, so a v1 search can match a mapping absent from v1.",
"action": "Recompute same_as_map_codes, other_map_codes, and mapped_codes for superseded concepts in the partial update using the existing document helper. Verify the release search without recomputing vectors.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.5",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1380,
"claim": "A temporary Elasticsearch outage can permanently park otherwise valid indexing work.",
"scenario": "Elasticsearch returns connection failures or HTTP 503 for five scheduled attempts. These failures are outside BatchIndexRun.is_rejected, so the row reaches the attempt cap. After Elasticsearch recovers, the worker skips that row and its part's later stages on every subsequent night until someone resets the attempts.",
"action": "Retry transient infrastructure failures with backoff across windows. Reserve manual reset for failures that require intervention and test recovery after more than five transient failures.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.6",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1346,
"claim": "A deferred row can start additional Elasticsearch batches after the off-peak cutoff.",
"scenario": "A 5,000-ID concept row starts at 04:29 UTC. Its first 500-document batch takes more than a minute. The full-index helper then starts the remaining batches, including any embedding and retries, because the runner only checks the window after the whole row returns.",
"action": "Check the deadline between the underlying batches and leave the unfinished IDs pending for the next window.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F1.7",
"severity": "P2",
"tag": null,
"file": "core/common/mixins.py",
"line": 881,
"claim": "Replacing the entire source_version list can erase a concurrent release update.",
"scenario": "A release seed captures A while it is current and finishes writing its membership after the deferred job has read A's source versions. The release task appends the release to A's Elasticsearch document before the deferred bulk request arrives. The deferred request overwrites the list with its earlier snapshot, leaving A absent from version-scoped search even after both jobs succeed.",
"action": "Apply the HEAD membership change without replacing release memberships written by other jobs, or use a conditional update that rereads memberships after a conflict.",
"lines_delta": null,
"confidence": "high"
}
]
} |
…ce their replacement is searchable, at any time of day Review pass 1 fixes: - The latest-flags rows now run on every pass of the job, inside the window or not, and update a superseded version only once its concept's current latest version has a document flagged latest; the others wait. That covers a release indexing the replacement before the window, and a version superseded again by a later import. - The update is a script that takes HEAD out of source_version without replacing the releases another job may be appending, and also sets a superseded concept's mapped codes, which prepare() takes from its releases' mappings once it isn't the latest. - Index rows run INDEX_BATCH_SIZE ids at a time, saving what's left after each batch and checking the window before the next, so a run stops within a batch of the window closing. - A failure counts as an attempt only while Elasticsearch answers, so an outage can't park rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
|
Responses to Codex pass 1 (fixes in 44af16d):
|
…uperseded versions without a document aren't indexed Review pass 2 fixes: - The latest-flags update leaves a version with no document without one, instead of fully indexing it, so a pass outside the window never embeds anything. - The window's run updates the latest flags after each row it indexes, so a version isn't left flagged while a long backlog runs. - Whether a replacement is searchable is now read with a search, not a real-time get, so a document written but not yet refreshed doesn't count. - A failed row (other than Elasticsearch refusing writes) counts one attempt and is held back for 6 hours, so the rows after it go on and an outage costs each row one attempt a night. This replaces the ping check, which a write outage could pass. - IMPORT_INDEX_WINDOW's comment says it should be at least as long as the 10 minutes between beat runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex review, pass 2 (codex-cli 0.169.0, commit 44af16d)Verdict: findings: 6 new findings (P1, P2). Earlier: F1.1 unresolved, F1.2 unresolved, F1.3 unresolved, F1.4 resolved, F1.5 unresolved, F1.6 resolved, F1.7 resolved.
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "verify",
"commit": "44af16d739b07336956a329ea09ef09f1419aec5",
"verdict": "findings",
"prior": [
{
"id": "F1.1",
"status": "unresolved"
},
{
"id": "F1.2",
"status": "unresolved"
},
{
"id": "F1.3",
"status": "unresolved"
},
{
"id": "F1.4",
"status": "resolved"
},
{
"id": "F1.5",
"status": "unresolved"
},
{
"id": "F1.6",
"status": "resolved"
},
{
"id": "F1.7",
"status": "resolved"
}
],
"findings": [
{
"id": "F2.1",
"severity": "P1",
"tag": null,
"file": "core/common/mixins.py",
"line": 898,
"claim": "The daytime flag pass can start full indexing and embedding outside the configured window.",
"scenario": "Two deferred imports create A and then supersede it with B before A gets an Elasticsearch document. A daytime release indexes B. The next flag pass tries to patch A, receives a 404, and the shared partial-update helper full-indexes A immediately. A large set of missing versions can send thousands of full writes and embedding requests during peak hours.",
"action": "Handle missing documents separately in the flag pass. Keep any required full writes in the durable off-peak queue and test a daytime pass with a searchable replacement and an absent superseded document.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1344,
"claim": "An active off-peak run can delay ready flag updates for the rest of the window.",
"scenario": "The opening flag sweep leaves A flagged because B is missing. An early full-index batch makes B searchable, but the runner keeps working through an hours-long backlog under the shared lock. Subsequent beat invocations return without processing flags, so HEAD search can show both A and B until the backlog drains or the window closes.",
"action": "Process newly ready flag updates between bounded units of full indexing, or give flag processing an independent execution path. Test a replacement indexed early in a run with more index work still pending.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.3",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1390,
"claim": "A temporary write outage can still permanently park valid deferred work.",
"scenario": "An index's primary shard is unavailable while the Elasticsearch cluster still answers ping. Bulk writes return HTTP 503, which BatchIndexRun does not classify as a retryable rejection. Five such runs exhaust the row's attempts, and the worker skips it after the shard recovers.",
"action": "Preserve transient error classifications through BatchIndexRun and keep retrying those failures across windows. Test recovery after five bulk 503 responses with a successful ping.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.4",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 229,
"claim": "Bulk retirements of previously indexed rows ignore the import's deferral choice.",
"scenario": "An inline import sent with index=false contains Concept or Mapping delete lines for existing resources whose latest versions have _index=True. The retire path inherits that flag, so it indexes the retired versions and their predecessors at import time. ImportIndexer.add skips those rows, leaving no off-peak record for them.",
"action": "Pass the effective import indexing decision into the retire path. Keep the immediate behavior for imports that index, and test deferred delete lines against previously indexed concepts and mappings.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.5",
"severity": "P2",
"tag": null,
"file": "core/common/mixins.py",
"line": 930,
"claim": "The replacement check can pass before the replacement is visible to search.",
"scenario": "On a multi-shard index, A and its replacement C are on different shards. The real-time mget sees C immediately after indexing. A's shard refreshes after the demotion and before C's shard refreshes, so a HEAD search in that interval returns neither version. [Elasticsearch multi-get](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-mget) and [refresh behavior](https://www.elastic.co/docs/manage-data/data-store/near-real-time-search).",
"action": "Check replacement visibility through search, or wait for the replacement write to become searchable before allowing the demotion. Cover a replacement that mget can see before search can.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F2.6",
"severity": "P2",
"tag": null,
"file": "core/celery.py",
"line": 46,
"claim": "The ten-minute beat interval can miss a valid configured window every night.",
"scenario": "An operator configures 03:00-03:05 UTC. Beat dispatches around 02:57 and 03:07, and the worker starts promptly. Neither invocation sees the window open. The same cadence can recur on subsequent nights, leaving the backlog untouched.",
"action": "Schedule a run at the configured start, or validate and document a minimum window length that accommodates the beat interval.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Responses to Codex pass 2 (fixes in 0742f3d):
|
…lacement too, and never-indexed versions get indexed in the window Review pass 3 fixes: - An index row no longer rewrites a version that was superseded since, while its replacement isn't searchable: that would take the only document search finds out of HEAD. It waits in a latest-flags row (usually the superseding import's own). - A superseded version with no document is fully indexed by its latest-flags row inside the window, and waits outside it, so a version created and superseded in one part still gets a document. - In the window, the latest flags are updated every 10 minutes between rows and at the end of the run, instead of after every row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex review, pass 3 (codex-cli 0.169.0, commit 0742f3d)Verdict: findings: 4 new findings (P1, P2). Earlier: F1.1 resolved, F1.2 resolved, F1.3 unresolved, F1.4 resolved, F1.5 unresolved, F1.6 unresolved, F1.7 resolved, F2.1 regressed, F2.2 unresolved, F2.3 unresolved, F2.4 unresolved, F2.5 resolved, F2.6 unresolved.
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "verify",
"commit": "0742f3d5061e24096d4af1b35f609a4e112d2448",
"verdict": "findings",
"prior": [
{
"id": "F1.1",
"status": "resolved"
},
{
"id": "F1.2",
"status": "resolved"
},
{
"id": "F1.3",
"status": "unresolved"
},
{
"id": "F1.4",
"status": "resolved"
},
{
"id": "F1.5",
"status": "unresolved"
},
{
"id": "F1.6",
"status": "unresolved"
},
{
"id": "F1.7",
"status": "resolved"
},
{
"id": "F2.1",
"status": "regressed"
},
{
"id": "F2.2",
"status": "unresolved"
},
{
"id": "F2.3",
"status": "unresolved"
},
{
"id": "F2.4",
"status": "unresolved"
},
{
"id": "F2.5",
"status": "resolved"
},
{
"id": "F2.6",
"status": "unresolved"
}
],
"findings": [
{
"id": "F3.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1409,
"claim": "An older full-index row can remove the only searchable HEAD version before its replacement is ready.",
"scenario": "A deferred import creates A, and a release indexes A before its pending INDEX row runs. A second deferred import replaces A with B. The opening flag sweep correctly leaves A alone because B is absent. The older INDEX row then rewrites A from the database with is_latest_version=false and without HEAD membership. If the window closes before B is indexed, the concept disappears from HEAD and global search until the next run.",
"action": "Apply the replacement-visibility guard to full writes that would demote an existing document. Add an Elasticsearch regression test with a release-indexed A, a pending INDEX row for A, and a window cutoff before B.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F3.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1351,
"claim": "Each completed index row triggers a rescan of every pending demotion, including those whose replacements were untouched.",
"scenario": "A backlog contains 100 flag rows of 5,000 IDs each and 100 older index rows that publish none of their replacements. The job can make 100,000 Elasticsearch searches rechecking those same replacements before reaching the relevant index rows. Those repeated reads consume the off-peak window and delay the work that would make the replacements searchable.",
"action": "Limit the immediate checks to replacements the completed batch could have published. Use a bounded periodic sweep to pick up replacements published by other tasks.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F3.3",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1280,
"claim": "A version created and superseded within one deferred part can disappear from the queue without ever getting a document.",
"scenario": "Two consecutive lines for the same concept in one index=false part create version A and then replace it with B. Recording subtracts A from the full-index IDs because it was also superseded. Once B is searchable, the partial update for A returns 404 and the job deletes its flag row. A remains missing from Elasticsearch with no pending work. The new missing-document test uses separate parts, so A still has a full-index row there.",
"action": "Track versions created by the part separately from pre-existing versions it superseded. Keep missing newly created versions queued for a full write during the window and test both lines in one part.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "F3.4",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1409,
"claim": "A rejected bulk write can start a fresh indexing attempt after the off-peak cutoff.",
"scenario": "A deferred batch starts at 04:29:55 UTC and Elasticsearch immediately returns 429. The shared helper sleeps for its default 10-second backoff, then starts preparing and sending the batch again after 04:30. Further retries can repeat that work because the window is checked only outside the helper.",
"action": "Pass the window deadline through to the full-index retry loop. Before starting another attempt, stop and leave the batch queued if the window has closed. Test a rejection just before cutoff.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Responses to Codex pass 3 (fixes in 33d6392). This was the last defect pass; a final check of the commits since follows the simplification review.
|
Simplification review (claude subagent, commit 33d6392)Verdict: findings: 2 low-confidence cuts, both tests.
Responses (nothing cut):
findings.json{
"reviewer": "claude subagent",
"perspective": "simplify",
"mode": "full",
"commit": "33d63929c37aead53d5ccea42f63bdbf57642150",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "S1",
"severity": null,
"tag": "dup-test",
"file": "core/importers/tests_deferred_index.py",
"line": 897,
"claim": "test_window_is_checked_against_the_current_time_by_default only checks that is_window_open() falls back to timezone.now(). test_window_is_in_utc and the run tests (which leave now unpatched or use a fixed one) already cover the window boundaries.",
"action": "Fold one patched-now assertion into test_window_is_in_utc, or drop the test.",
"lines_delta": -7,
"confidence": "low"
},
{
"id": "S2",
"severity": null,
"tag": "dup-test",
"file": "core/importers/tests_deferred_index.py",
"line": 1303,
"claim": "test_index_latest_flags_updates_documents_without_a_refresh_and_returns_the_missing_ones mocks batch_index_partial_by_ids and asserts its exact call arguments. It tests wiring, not behaviour. The missing-document handling is covered by test_missing_documents_are_not_failures_of_the_flags_update and the ES test test_superseded_version_without_a_document_waits_for_the_window.",
"action": "Drop the call-argument assertion, or the whole test, and keep the behavioural tests.",
"lines_delta": -14,
"confidence": "low"
}
]
} |
… goes to an index row, and parked rows don't absorb hand-overs Final review check fixes: - The latest-flags update hands a version with no document to an index row of its part instead of indexing it there, so it's indexed a batch at a time with the window checked between batches, and later passes outside the window don't resend it. - A hand-over skips only ids that a row of the same stage that isn't parked already has, so a parked row can't keep a version from being indexed or re-flagged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex check of commits 0742f3d..33d6392 (codex-cli 0.169.0, commit 33d6392)Verdict: findings: 3 findings (P1, P2).
Responses (fixes in c4d3961):
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "33d63929c37aead53d5ccea42f63bdbf57642150",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "FC.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1439,
"claim": "The missing-document fallback can start new full-index batches after the off-peak cutoff.",
"scenario": "A flags sweep finds 5,000 missing documents just before 04:30 UTC. The window closes during the first 500-document batch. The full-index helper still starts the remaining nine batches, even if Elasticsearch accepts every request.",
"action": "Check the window before each fallback batch and save the IDs that remain when it closes. Add a regression test that closes the window after the first batch.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1441,
"claim": "Daytime sweeps repeatedly send partial updates for documents already found missing.",
"scenario": "A release publishes 100,000 replacement versions before their predecessors get indexed. An outside-window sweep receives a 404 for each predecessor and keeps the same IDs in the flags rows. Each subsequent sweep recomputes mapped codes and resends the same updates until the window opens, putting repeated daytime load on Postgres and Elasticsearch.",
"action": "Persist confirmed-missing IDs as work that runs only in the indexing window. Test that a second outside-window run skips those IDs.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.3",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1450,
"claim": "A parked flags row can absorb work that an active index row was still able to complete.",
"scenario": "A release indexes version A. A later deferred import supersedes it with B, and its flags row parks after repeated failures on another ID in the same row. When A's original index row runs, B is still unsearchable. The handoff sees the parked row and removes A from the active index row. After B is indexed, A remains flagged as latest and can still match HEAD searches until someone resets the parked row.",
"action": "Exclude parked rows from handoff deduplication so eligible work remains queued for A. Add a test with an overlapping flags row at the attempt limit.",
"lines_delta": null,
"confidence": "high"
}
]
} |
…ses waits 20 minutes, so the rows after it go on Final review check fix: a row Elasticsearch keeps refusing (a circuit breaker on its batch, say) no longer stops every run at the same row. It's held back for 20 minutes, without counting an attempt, and the rows after it go on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex check of commit 33d6392..c4d3961 (codex-cli 0.169.0, commit c4d3961)Verdict: findings: 2 findings (P1, P2).
Responses (fix in 7bbdcfc):
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "c4d3961af6be52d0d36b1e51e99cf83ea1fb9549",
"verdict": "findings",
"prior": [
{
"id": "FC.1",
"status": "resolved"
},
{
"id": "FC.2",
"status": "regressed"
},
{
"id": "FC.3",
"status": "resolved"
}
],
"findings": [
{
"id": "FC.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1440,
"claim": "A rejected fallback batch can block unrelated deferred imports for the entire indexing window.",
"scenario": "An older fallback batch repeatedly trips an Elasticsearch circuit breaker while smaller writes would succeed. The rejection leaves the fallback INDEX row immediately eligible, so every scheduled run selects it first and stops before reaching newer imports. In the previous revision, the fallback failure ended the flags sweep and the regular indexing loop still ran.",
"action": "Give rejected fallback rows a retry delay that lets other rows run, or process fallback rows separately. Test that a newer INDEX row advances when the fallback keeps returning 429.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.2",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1456,
"claim": "Deduplicating against an active INDEX row can strand a missing historical document when that row later parks.",
"scenario": "A flags sweep finds a missing superseded version whose replacement is searchable. It drops the missing ID because the ID is in the second batch of an active INDEX row. A permanent error on an unrelated document in the first batch parks that row before the second batch runs. The historical version stays absent from search until manual recovery. The previous fallback could index it independently.",
"action": "Keep an independent fallback for confirmed-missing IDs or requeue them if the covering row parks. Test an overlapping INDEX row that fails before it reaches the missing ID.",
"lines_delta": null,
"confidence": "high"
}
]
} |
Codex check of commit c4d3961..7bbdcfc (codex-cli 0.169.0, commit 7bbdcfc)Verdict: clean. No findings. findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "7bbdcfc7de948d976a6327e54816dbdd74af373e",
"verdict": "clean",
"prior": [
{
"id": "FC.1",
"status": "resolved"
},
{
"id": "FC.2",
"status": "unresolved"
}
],
"findings": []
} |
snyaggarwal
left a comment
There was a problem hiding this comment.
Reviewed at 7bbdcfc, after your three Codex passes, the simplification review and the checks after them. The design holds on the paths I traced: rows survive restarts, a failed row waits without blocking the others, a superseded version keeps its flag until its replacement is searchable, and the flags script keeps the releases another job appends. Beat's expire_seconds works because beat runs django-celery-beat's database scheduler, and the lock is safe on the Redis cache. I haven't run the tests.
Before merge (inline): this branch breaks once master is merged in. #1010, merged after 7bbdcfc, moved concept mapped codes into MappedCodes:
get_latest_flags_fieldscallsConceptDocument.get_mapped_codes, which #1010 removed, so every concept flags update raisesAttributeError.- Even with that call fixed, the update leaves
release_map_codesas it was while the row was the latest.
GitHub shows no conflict, so only CI after a master merge would catch it. Master now also has #1007, #1023 and #1024, and #1007 changed the same import code.
Nits (inline): the window run holds an indexing slot for the whole window, the lock renewal doesn't check its token, and a window shorter than a beat tick may never open.
| def get_latest_flags_fields(instance): | ||
| """A superseded version's mapped codes come from its releases' mappings, not HEAD's (get_indexed_mappings).""" | ||
| from core.concepts.documents import ConceptDocument | ||
| same_as_codes, other_codes, mapped_codes = ConceptDocument.get_mapped_codes(instance) |
There was a problem hiding this comment.
Before merge: this raises AttributeError on master. #1010 removed ConceptDocument.get_mapped_codes (and get_indexed_mappings, which the docstring names) when it moved mapped codes into MappedCodes. On a merge with master, every concept flags row fails here, counts an attempt and parks after 5. The superseded versions then stay is_latest_version: true, so HEAD search keeps showing both versions.
One way, building MappedCodes once per batch instead of once per row. The hook takes the batch, and the mixin's default returns {}:
@staticmethod
def get_latest_flags_fields(instances):
"""The mapped codes prepare() gives these rows now (MappedCodes), release_map_codes included."""
from core.concepts.documents import MappedCodes
mapped_codes = MappedCodes(instances)
return {instance.id: mapped_codes.get_fields(instance) for instance in instances}get_latest_flags_actions would then list the batch's rows once, call the hook and send fields.get(instance.id, {}).
Two tests encode the codes from before #1010. Under #1010, a superseded row that no release holds reads HEAD's codes:
empty_codesinLatestFlagsTest.test_concept_actions_set_what_a_new_version_changes;(False, ['v1'], [])inDeferredImportSearchTest, wherev1is only appended in Elasticsearch, so the row has no release in the database.
There was a problem hiding this comment.
Fixed in e39f966: get_latest_flags_fields now takes the batch and returns MappedCodes(instances).get_fields(...) per row id, and get_latest_flags_actions lists the rows once and sends fields.get(instance.id, {}); the two tests now expect HEAD's codes for a superseded row no release holds (['To']).
| """A superseded version's mapped codes come from its releases' mappings, not HEAD's (get_indexed_mappings).""" | ||
| from core.concepts.documents import ConceptDocument | ||
| same_as_codes, other_codes, mapped_codes = ConceptDocument.get_mapped_codes(instance) | ||
| return {'same_as_map_codes': same_as_codes, 'other_map_codes': other_codes, 'mapped_codes': mapped_codes} |
There was a problem hiding this comment.
Before merge: release_map_codes stays stale. Under #1010, a document has a release_map_codes entry for each release whose codes differ from the document's own codes. Once a row stops being the latest, its own codes switch from HEAD's to the public releases'. This sets only the three own-code fields, so the entries stay as they were computed while the row was the latest.
Example: v1 is only in private release P, and P's codes equal HEAD's, so v1's document has no entry for P. After an import supersedes v1, its own codes become the public releases' (none here), and there's still no entry for P. A search in P for v1's mapped code then reads the empty own fields and misses it. Sending everything MappedCodes.get_fields returns, as in the comment above, covers this too.
There was a problem hiding this comment.
Fixed in e39f966 by the same change: the update sends everything MappedCodes.get_fields returns, release_map_codes included; test_superseded_version_only_in_a_private_release_keeps_that_release_s_codes is your example (v1 only in private release P, superseded by an import, ends with an entry for P holding its code).
| done = cls.update_latest_flags() | ||
| if cls.is_window_open(): | ||
| flagged_at = time.monotonic() | ||
| for row in iter(lambda: cls.get_pending().exclude(stage=cls.Stage.LATEST_FLAGS).first(), None): |
There was a problem hiding this comment.
Nit. With a backlog, this loop keeps one run_deferred_import_indexing task on the indexing queue until the window closes, up to 3.5 hours. docker-compose.prod.yml starts that worker with -c 2, so edits and releases indexed during 01:00–04:30 UTC (06:30–10:00 IST) share the one remaining slot. Could Behaviour changes say so, and is the ECS task's concurrency the same? Alternatively, stopping each run after a few minutes of batches would let the next tick resume it, with other indexing tasks running in between. The lock and the saved ids already support that.
There was a problem hiding this comment.
|
|
||
| @staticmethod | ||
| def renew_lock(): | ||
| django_cache.touch(DEFERRED_INDEX_LOCK_KEY, timeout=DEFERRED_INDEX_LOCK_SECONDS) |
There was a problem hiding this comment.
Nit. This renews the key whoever holds it, while run's finally checks the token before it deletes. If a runner stalls past DEFERRED_INDEX_LOCK_SECONDS (a long 429 backoff on one batch, say), another runner takes the lock. The first then extends the second's lock and carries on, so both work the same rows, and the first one's save of its stale ids can put back ids the other already finished. Passing the token in, renewing only while the key still holds it, and stopping the run otherwise would close that.
There was a problem hiding this comment.
Fixed in e39f966: before each batch the run renews the lock only if it still holds the run's token, and stops otherwise; test_run_stops_once_its_lock_is_another_runners covers it.
| return False | ||
| start, end = window | ||
| current = (now or timezone.now()).astimezone(dt_timezone.utc).time() | ||
| return start <= current < end if start <= end else (current >= start or current < end) |
There was a problem hiding this comment.
Nit. A window shorter than beat's 10 minutes may never contain a tick, as the interval counts from when beat started. For example, 02:00-02:05 with ticks at 01:58 and 02:08. 02:00-02:00 never opens. Either way the INDEX rows wait and nothing is logged. The settings comment asks for at least 10 minutes. get_window could treat a shorter window as paused and log an error, as it does for a value that doesn't parse.
There was a problem hiding this comment.
Fixed in e39f966: get_window treats a window shorter than the 10 minutes between beat runs, 02:00-02:00 included, as paused and logs an error, as for a value that doesn't parse.
…68-import-index Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
…MappedCodes' fields, and runs are time-boxed Review changes after merging master (#1010 moved concept mapped codes into MappedCodes): - The latest-flags update sends everything MappedCodes.get_fields gives a row, release_map_codes included, built once per batch. get_latest_flags_fields takes the batch. A version only a private release holds then keeps that release's codes in release_map_codes once an import supersedes it. - A run indexes for at most 5 minutes, then queues the next run behind the indexing tasks queued meanwhile, so the window no longer holds an indexing slot throughout. - A run renews its lock only while the lock still holds its token, and stops once it doesn't. - A window shorter than the 10 minutes between beat runs pauses the job and logs an error, as a value that doesn't parse does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
…own time budget, so it can't starve the indexing Codex check fix: the indexing's 5 minutes now start once the opening pass over the latest-flags rows is done, and each such pass stops after 5 minutes of its own. A pass takes the rows checked longest ago first, so a long list of waiting rows rotates instead of the same ones being checked every time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex check of commits 7bbdcfc..e39f966 (codex-cli 0.169.0, commit e39f966)The merge of master and the changes for the review of 7bbdcfc. Verdict: findings: 3 findings (P1, P2).
Responses:
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "e39f966fb94104c9820e54a10e5fc3b90f13cc6f",
"verdict": "findings",
"prior": [],
"findings": [
{
"id": "FC.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1445,
"claim": "The initial latest-flags scan can consume the entire time budget and prevent the indexing that would clear its backlog.",
"scenario": "A large import leaves enough LATEST_FLAGS rows for the Elasticsearch replacement checks to take more than five minutes. The replacements are still waiting in INDEX rows, so the flags scan clears nothing. The first INDEX batch then sees an expired deadline. The worker scans the flags again before requeuing, and each continuation can repeat this without indexing a single replacement.",
"action": "Bound the flags work per run and reserve time for INDEX batches. Add a regression test where the pending flags take longer than the run budget and the runner still makes progress on replacement indexing.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1438,
"claim": "With Redis Sentinel configured, the new ownership check can mistake a freshly acquired lock for a lost lock.",
"scenario": "The primary accepts the lock acquisition, but django-redis reads the token from a replica that has yet to receive it. The runner stops before starting a batch. If the replica is still behind during cleanup, the primary retains the unused lock and subsequent runs skip the backlog for up to an hour.",
"action": "Check the token and renew the lease atomically on the Redis primary. Release it with an atomic token check as well.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.3",
"severity": "P2",
"tag": null,
"file": "core/common/mixins.py",
"line": 886,
"claim": "A delayed latest-flags update can undo the mapped-code refresh that makes a release private.",
"scenario": "A superseded concept row is still used by a public collection. The deferred runner prepares its mapped-code fields while a release holding that row is public. The release becomes private, and the second indexing slot finishes the access-change refresh before the deferred bulk write lands. The deferred write restores the stale fields, so public collection search can match a code held only by the private release until another reindex.",
"action": "Use Elasticsearch document version checks for the mapped-code write and rebuild its fields from current database state on conflict.",
"lines_delta": null,
"confidence": "medium"
}
]
} |
…ags passes and the indexing, and outside the window the flags pass has no limit Codex check fixes: - In the window, a run takes about 5 minutes in all: the opening pass over the latest flags gets a third, the indexing the rest (a third at least), and the closing pass another third. It queues the next run if indexing or flags work is left. - Outside the window, where there's no indexing to make room for, the flags pass goes through every row again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex check of commits e39f966..3527f0b (codex-cli 0.169.0, commit 3527f0b)Verdict: findings: 2 findings (P1), both about how long a run holds the worker.
Responses (fixes in 1f98dcc):
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "3527f0b09cefd9c20952fc77b4d64429434591e3",
"verdict": "findings",
"prior": [
{
"id": "FC.1",
"status": "resolved"
},
{
"id": "FC.2",
"status": "unresolved"
},
{
"id": "FC.3",
"status": "unresolved"
}
],
"findings": [
{
"id": "FC.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1458,
"claim": "A flags pass that runs out of time cannot queue a continuation on its own.",
"scenario": "Outside the indexing window, a release makes a replacement searchable behind a backlog that takes 12 minutes to check. The previous runner reached it in the same invocation. The capped pass now needs three scheduled invocations because continuations require an open window and pending full-index work. HEAD search shows both versions for about ten extra minutes.",
"action": "Queue a continuation when the flags pass leaves rows unchecked, including outside the indexing window. Carry forward the sweep position so rows already checked and still waiting cannot keep the continuation running.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1449,
"claim": "Resetting the deadline after the opening flags pass makes ordinary indexing tasks wait longer for the worker.",
"scenario": "The opening pass clears four minutes of ready flags, full-index work remains, and the other indexing slot is busy. A normal save queues an indexing task during the opening pass. The previous runner yielded after five minutes. The new runner spends five more minutes on full indexing and ties up the slot for nine minutes, even with an empty closing pass.",
"action": "Give the opening flags pass a shorter slice of the worker's time budget and reserve time for full indexing before yielding. Defer remaining flags work to a subsequent task.",
"lines_delta": null,
"confidence": "high"
}
]
} |
…nutes, and checks the window again after its opening pass Codex check fixes: - The closing flags pass now ends with the run's budget: a third for the opening pass, a third for the indexing (two, if the opening pass was quick, and at least one), and the rest for the closing pass. - A run queues the next one only for indexing that's left, not for unchecked flags, so flags rows whose replacements can't be searched yet don't keep the worker busy. Beat's next run picks them up, and outside the window it goes through them all. - After the opening pass, the run checks the window again, so a pass that took it into the window is followed by indexing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K
Codex check of commits 3527f0b..1f98dcc (codex-cli 0.169.0, commit 1f98dcc)Verdict: findings: 4 findings (P1, P2), all about scheduling.
Responses (fixes in 7e6a53b):
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "1f98dccdbd14164291b8dc7c0225dc1a48a4f68b",
"verdict": "findings",
"prior": [
{
"id": "FC.1",
"status": "resolved"
},
{
"id": "FC.2",
"status": "unresolved"
}
],
"findings": [
{
"id": "FC.1",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1462,
"claim": "The closing flags pass adds 100 seconds to the five-minute budget.",
"scenario": "The opening pass uses 100 seconds and full-index work runs until the 300-second deadline. With enough flags still pending, the closing pass starts new rows until second 400. An ordinary indexing task waiting for that slot waits an extra minute and 40 seconds even when no batch overruns.",
"action": "Reserve the closing third within the shared budget. End full indexing by the start of that third and give the closing pass the shared deadline.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.2",
"severity": "P1",
"tag": null,
"file": "core/importers/models.py",
"line": 1465,
"claim": "Flags-only continuations can repeatedly scan a backlog that cannot make progress.",
"scenario": "The replacement index rows are in retry backoff and checking the waiting flags rows takes longer than a closing pass. Each continuation starts a new sweep, checks rows whose replacements are still unsearchable, and queues another task even though it finished no rows. This keeps an indexing slot busy and sends repeated Elasticsearch queries throughout the window.",
"action": "Carry a sweep boundary across continuations and stop after every row in that sweep has been checked once. Leave rows whose replacements are still unsearchable for a later scheduled run.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.3",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1452,
"claim": "A run skips full indexing if its opening flags pass crosses into the window.",
"scenario": "A scheduled run starts ten seconds before the window opens and spends 40 seconds checking flags. The previous runner started full indexing as soon as the flags pass finished. The new runner skips it using the earlier window check. For a supported ten-minute window, the next scheduled run has only ten seconds left if it starts on time.",
"action": "Check the current window again after the opening flags pass and enter full indexing if it has opened.",
"lines_delta": null,
"confidence": "high"
},
{
"id": "FC.4",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1464,
"claim": "Closing the indexing window suppresses a continuation for unchecked flags.",
"scenario": "A run starts 4 minutes and 45 seconds before the window closes, with four minutes of ready flags and a full-index backlog. The previous opening pass cleared all four minutes of flags. The new opening pass stops after about 100 seconds, indexing runs until the window closes, and the closing pass runs out of time with ready flags still unchecked. Both versions can remain visible in HEAD search until the next scheduled run because the closed window blocks the continuation.",
"action": "Allow an unfinished flags sweep to queue a continuation after the window closes. Keep the open-window check on full indexing.",
"lines_delta": null,
"confidence": "high"
}
]
} |
Codex check of commits 1f98dcc..7e6a53b (codex-cli 0.169.0, commit 7e6a53b)Verdict: findings: 1 (P2), no P0 or P1.
Response:
findings.json{
"reviewer": "codex-cli 0.169.0",
"perspective": "defects",
"mode": "final",
"commit": "7e6a53bd3a61e0f5ea6ab5300fe5c886d6181d69",
"verdict": "findings",
"prior": [
{
"id": "FC.1",
"status": "resolved"
},
{
"id": "FC.2",
"status": "resolved"
},
{
"id": "FC.3",
"status": "regressed"
},
{
"id": "FC.4",
"status": "unresolved"
}
],
"findings": [
{
"id": "FC.1",
"severity": "P2",
"tag": null,
"file": "core/importers/models.py",
"line": 1451,
"claim": "If the window closes during the opening pass, the run skips the closing flags pass even when time remains.",
"scenario": "A run starts 60 seconds before the window closes with five ready flags rows that take 30 seconds each. The opening pass finishes four rows at second 120. The previous revision processed the fifth row in its closing pass. This revision returns with 180 seconds left in the five-minute budget, so both versions for that row can remain visible in HEAD search until the next scheduled run.",
"action": "Use the second window check to gate full indexing. If the run started inside the window, still use the remaining budget for a closing flags pass. Add a test where the window closes during the opening pass.",
"lines_delta": null,
"confidence": "high"
}
]
} |
|
Changes for the review of 7bbdcfc (head now 7e6a53b):
|
OpenConceptLab/ocl_online#268
Problem
Since #917, an import over
IMPORT_INDEX_MAX_LINES(default 5,000) skips search indexing unless the request sendsindex=true, and TBv3's import screen never sendsindex. Nothing indexes those rows later, so a large import leaves:is_latest_version: true. A later release indexes the new versions but never re-flags the old ones, so HEAD search shows both. For example, a 10,643-line update import into a public source left 2,045 duplicates;Change
A large import records what it skipped, and a job indexes it off-peak.
ImportIndexer.finish()writes what it would have queued to a new table,deferred_import_indexes(DeferredImportIndex). Each row is one stage of up to 5,000 ids for one import part:index: a full index of the versions the part created or retired, their versioned objects and latest versions;mapped codes: the mapped codes in the documents of the concepts the part's mappings come from;latest flags: the documents of the versions the part superseded.run_deferred_import_indexingruns every 10 minutes from beat, on theindexingqueue:indexandmapped codesrows run only whileIMPORT_INDEX_WINDOWis open. It's a new setting,HH:MM-HH:MMin UTC, default01:00-04:30. An empty window pauses the job, and so does one shorter than the 10 minutes between beat runs, which logs an error. Rows go oldest part first, 500 ids at a time. What's left is saved after each batch and the window is checked before the next, so the job stops within a batch of the window closing and picks up there the next night.indexingqueue, behind whatever was queued meanwhile. Each pass over the latest flags has a 5-minute budget of its own.latest flagsrows run on every pass, inside the window or not. Inside the window they also run every 10 minutes between rows. A superseded version is updated once a search finds its concept's current latest version flagged latest. Until then it keeps its flag, so search finds the concept by its previous version rather than not at all. The others wait for a later pass.indexrow doesn't rewrite a version that was superseded since, while its replacement isn't searchable, because that would un-flag the only document search finds. It hands the version over to alatest flagsrow instead: the superseding import's own if one is waiting, else a new one for its part.retry_at), so the rows after it go on and an outage costs each row one attempt a night.attempts.The superseded versions are updated by a script, not reindexed. It sets
is_latest_versionfrom the database and takesHEADout ofsource_version, keeping the releases another job may be appending. For a concept, it also sets everythingMappedCodes.get_fieldsgives the row,release_map_codesincluded, built once per batch: once a version isn't the latest, its own codes come from its public releases (#1010). Nothing is re-embedded. A version with no document (one created and superseded in the same part, say) goes to anindexrow of its part instead, so it's fully indexed in the window, a batch at a time.What's waiting is visible. The table is exactly what's still waiting, with each row's import task, stage, ids, attempts and last error. For example:
Each run also logs how many rows it finished and how many are waiting.
Behaviour changes
index=falsenow defers instead of skipping. It used to mean "never indexed by the import". It now means "indexed by the off-peak job", like an import over the limit with noindex. No caller in the OCL repos sendsindex=false, and nothing in this repo relies on rows staying unindexed. Theindexparam's swagger text says so.index=trueindex as they finish, as before.Tests
core/importers/tests_deferred_index.py:index=falsedefers a small import, whileindex=trueand small imports still queue their indexing. A mapping import records its mapped codes, rows hold at most a chunk, and theimport_typesubtask records its rows with its task id;MappedCodesgives the row) and mappings, and the replacement check;release_map_codes;is_latest_version: false, noHEADand its release-based mapped codes, outside the window;index=falseand over-the-limit tests also check that the rows are recorded.TEST_ES=off --parallel=4, then the tests taggedes), with 97% coverage. pylint 4.0.9 ratescore/10.00 with no messages.Review
Three Codex passes, a simplification review and checks of every later commit, all posted below. After a maintainer's review of 7bbdcfc, master was merged in and the changes it asked for were made. Those commits were checked too.
index_mapped_codes.Deploy
importers.0001_initialcreates the new, empty tabledeferred_import_indexes. It's instant.IMPORT_INDEX_WINDOWdefaults to01:00-04:30UTC. The 01:00vacuum-and-analyze-dbbeat task runs at the start of that window.core/celery.pywhen it starts.Not in this change
IMPORT_INDEX_MAX_LINESonce indexing has its own worker (OpenConceptLab/ocl_online#250).🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qWWFiC4BMWhVDdX48K