Skip to content

fix(topic-memory): stop redispatching exhausted work windows - #1842

Merged
Teingi merged 2 commits into
oceanbase:masterfrom
knqiufan:codex/fix-topic-memory-terminal-frontier
Oct 9, 2026
Merged

Teingi merged 2 commits into
oceanbase:masterfrom
knqiufan:codex/fix-topic-memory-terminal-frontier

Conversation

@knqiufan

@knqiufan knqiufan commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

Closes #1841. Aligns the Topic Memory and Artifact Processing Supervisor contracts in RFCs #1417 and #1515.

Rationale for this change

An exhausted Topic Memory frontier was repeatedly dispatched to a full child Worker, rejected before inference and counted as another processing failure. Legacy rows with attempts=3 and an empty failure_code exhibit the same problem.

The Supervisor needs to retain an unchanged terminal frontier without spawning more Workers or discarding accepted work. A failed metadata recheck must preserve that state, and checking other Scopes must not shorten a healthy Scope's probe allowance.

What changes are included in this PR?

  • Register a Topic-owned admission probe for the current Cursor, target/Source head and durable budget. Apply it to explicit requests, automatic admission and retries. Source selection, token estimation and model work stay in the child.
  • Keep exhausted frontiers in quiet waiting, with metadata rechecks after five minutes, a newer explicit flush or automatic admission. Preserve accepted work, Sources, Pending, Cursor and allowance; keep Worker guards and allow the eligible third attempt to finish.
  • Preserve cached terminal state, failure history and the five-minute interval when a recheck encounters I/O failure or timeout. Track the attempted request generation so ordinary wakes cannot bypass the interval; another explicit generation can still recheck promptly.
  • Report the first or changed recheck availability error as artifact_processing.block_recheck_failed WARNING, suppressing identical repeats until a successful check.
  • Give each metadata probe its full two-second I/O timeout. The shared two-second Family quantum controls whether another probe starts; it does not truncate an in-flight probe. The allowance per cycle is at most one quantum plus one probe timeout. Genuine probe failures retain ordinary per-key backoff and other Families receive admission time.
  • Return typed terminal-block diagnostics when allowance changes after parent admission. Preserve child stage/code for genuine failures and bounded-cache/durable-intent rediscovery for evicted keys.
  • Retain operational stage, code, Family, binding, Scope, Window range and counters in console/JSON logs without serializing arbitrary extras, Source/model content or traceback payloads.
  • Give the usage queue-capacity fixture the full accepted-prefix write/flush budget while retaining exact capacity, persisted-count and sensitive-log assertions.
  • Update both English and Chinese RFCs and cover block retention, probe fairness, worker behavior and recovery.

Are there any user-facing changes?

An exhausted window emits an actionable artifact_processing.blocked warning and waits for remediation. Unchanged cached rechecks do not spawn Workers or manufacture execution failures. Failed rechecks preserve the last observed terminal state, and deliberate repair can restore eligibility without restart.

Flush, restart and model changes do not reset durable allowance. Existing attempt/request/token ceilings and data-retention rules remain in force. No public API, database schema, migration or automatic reset is added.

How was this change tested?

Validated head: 0b4eec6, based on master 77cf867.

  • Windows CPython 3.12: 190 focused runtime cases verified across the combined suite (189 passed) and an isolated automatic cache-overflow run (1 passed). Coverage includes scheduler fairness, terminal-frontier retention, work budgets, usage recording and processing composition.
  • Worker lifecycle, server logging, terminal-frontier HTTP and generic Topic API tests — 37 passed.
  • Windows CPython 3.14: both requested and automatic 1005-Scope cache-overflow cases — 2 passed.
  • Whole-project Linux-target types, Windows types for all changed Python files, Ruff, formatting, all non-type pre-commit hooks, lock consistency and diff checks passed. The type hook was checked separately with the platform targets above.

The 1005-Scope automatic cache-overflow fixture exceeded its existing 20-second watchdog in the Windows 3.12 combined run and a two-case rerun. An isolated run passed with the original watchdog and assertions. Diagnostic sampling also showed continuous scan progress with no failed processing or degraded state. This fixture has timing sensitivity on this host; production deadlines and test assertions are unchanged.

uv run --locked python -X utf8 -m pytest -q tests/builtin/runtime/test_processing_scheduler.py tests/builtin/runtime/test_scheduler.py tests/builtin/runtime/test_processing_scan_rollback.py tests/builtin/runtime/test_topic_memory_terminal_frontier.py tests/builtin/runtime/test_topic_memory_processing.py tests/builtin/runtime/test_topic_memory_work_budget.py tests/builtin/runtime/test_model_usage_recorder.py tests/builtin/runtime/test_processing_composition.py --tb=short
uv run --locked python -X utf8 -m pytest -q tests/builtin/runtime/test_artifact_processing.py tests/test_server_logging.py tests/e2e/test_topic_memory_terminal_frontier.py tests/e2e/test_topic_memory_generic_api.py --tb=short
uv run --locked python -X utf8 -m pytest -q tests/builtin/runtime/test_processing_scheduler.py::test_terminal_cache_overflow_does_not_launch_blocked_workers_or_starve_healthy_tail[automatic] --tb=short --durations=1
uv run --locked --isolated --python 3.14 python -X utf8 -m pytest -q tests/builtin/runtime/test_processing_scheduler.py::test_terminal_cache_overflow_does_not_launch_blocked_workers_or_starve_healthy_tail --tb=short --durations=2
uv run --locked ty check --python-platform linux

The terminal-frontier end-to-end regression uses file-backed SQLite, production Server/HTTP bindings, genuine spawned Workers and a local OpenAI-compatible model stub. This establishes local behavior; it does not establish terminal-frontier-specific live OceanBase or remote-model execution.

AI usage statement

OpenAI Codex assisted with implementation, review and validation. Open Code Review was used in delegation mode for deterministic file selection and rule resolution.

if state.binding.work_block is not None:
try:
async with asyncio.timeout_at(admission_deadline), self._database.transaction() as connection:
await self._leases.require_fence(connection, fence)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] A probe timeout on a blocked key erases the cached block and collapses its recheck spacing

_defer is called here without block=, and its last line unconditionally overwrites the entry:

state.retries[scope] = _RetryState(failures, deadline, block, request_generation)

block defaults to None, so when the metadata probe raises — including the TimeoutError that asyncio.timeout_at(admission_deadline) raises whenever the probe overruns the shared 2.0s batch budget — a key that was already in terminal waiting loses its cached ArtifactProcessingBlock.

I reproduced this against 28685ce7 with the real ArtifactProcessingSupervisor and a stub probe that returns the same unchanged ArtifactProcessingBlock both times, only differing in whether it sleeps past _DISCOVERY_TIMEOUT_SECONDS:

=== step 1: clean recheck of a terminal frontier ===
block cached            : True
failures                : 0
recheck spacing         : 300.0s (blocked_check_seconds=300)

=== step 2: identical block, but the probe overruns the 2.0s budget ===
block still cached      : False
failures                : 1
recheck spacing         : 30.0s (retry_base=30)

Impact, against the contract this PR states in docs/en/rfcs/1515_artifact_processing_supervisor.md ("Unchanged cached checks neither spawn Workers nor add failures or repeated error logs") and in docs/zh/rfcs/1417_topic_memory.md:

  • The 300s recheck spacing collapses to the 30s transient-failure backoff, so an unchanged terminal frontier is re-probed and re-reported roughly 10x more often while the database is under load.
  • failures increments even though nothing about the scope changed, which feeds the ordinary exponential backoff and the retry_wait/failed counters that this PR otherwise keeps at zero for terminal keys.
  • The dedup in _wait_for_block (if previous is None or previous.block != block) can no longer suppress the repeat, because previous.block is now None rather than the cached block.

The failure branch already knows whether it was deferring a previously blocked key — retry.block is not None is in scope. Please carry that block (and its request_generation) into _defer on the probe-error path, or re-derive it before deferring, so a probe timeout is recorded as a recheck attempt rather than converting terminal waiting into ordinary failure backoff.

Probe: oceanbase-powercontext-pr-1842/probes/block_erasure_probe.py. Related, same root cause: the batch's single admission_deadline means whichever scope is in flight when the budget expires is charged a full retry failure and an artifact_processing.failed ERROR log with error_code='TimeoutError', although nothing is wrong with that scope. probes/admission_timeout_attribution_probe.py shows the attribution.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this and providing the reproductions. I confirmed both issues and fixed them in a18d184: failed rechecks now preserve the terminal block, waiting interval and diagnostic deduplication, and each probe gets its full I/O timeout independently of earlier Scopes. Regression tests are included, and all 25 CI checks now pass, including Python 3.11–3.14.

@knqiufan
knqiufan force-pushed the codex/fix-topic-memory-terminal-frontier branch from a18d184 to a547cca Compare October 7, 2026 14:54
@knqiufan
knqiufan force-pushed the codex/fix-topic-memory-terminal-frontier branch from a547cca to 0b4eec6 Compare October 9, 2026 14:52
@Teingi
Teingi merged commit ee24d6b into oceanbase:master Oct 9, 2026
28 checks passed
guamiao added a commit to guamiao/powercontext that referenced this pull request Oct 9, 2026
Bring in the database-migration prototype (oceanbase#1771/oceanbase#1772), loopback proxy
bypass (oceanbase#1888), topic-memory window fixes (oceanbase#1842/oceanbase#1898) and related work.

Resolve three conflicts:
- database.py: keep the split transaction/_transaction so cancellation
  cleanup still owns the connection; adopt the upstream nested-snapshot
  comment.
- test_sqlite_profile.py: keep this branch's SyncConnection/event imports
  and its invalidation + commit-mark regression tests.
- test_topic_memory_generic_api.py: adopt upstream's reworked cancellation
  e2e (completion-flush rendezvous with busy_timeout_ms=100), which retains
  the cancellation, normal/storage-failure, settlement and recovery-usage
  assertions through the public flush boundary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hidb4ai hidb4ai added the 1.3.0 label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: a terminal topic-memory window is redispatched forever and logged as a new processing failure

3 participants