Skip to content

fix(resources): rebuild owned lifecycle guarantees on current main - #150

Merged
seonghobae merged 6 commits into
mainfrom
fix/resource-lifecycle-current-main
Aug 12, 2026
Merged

seonghobae merged 6 commits into
mainfrom
fix/resource-lifecycle-current-main

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Controlled current-main replacement for #87

The original #87 is deeply diverged from protected main and overlaps behavior already integrated through later protected work. This branch was rebuilt from protected main e0888d3befdec51f97cb710fd529a9d5055c0d05 and preserves only the still-missing package-owned PostgreSQL/resource lifecycle guarantees.

Test-first implementation

  • RED ce72e8635ee38a46ee68478785623e7157473ce9 established owned-resource lifecycle failures before changing production source.
  • PostgresConfigStore and SecretStore now close connections acquired before constructor/setup failure.
  • PostgresBatchOrchestrator.prepare_batches() closes its owned TokenCounter and PostgresConfigStore on success and failure.
  • TokenCounter.close() is idempotent, clears cached PostgreSQL state, and invalid token/resource ceilings fail closed before extension/database acquisition.
  • Configured/explicit batch record and byte ceilings require exact positive integers; explicit zero is not treated as omission.
  • Generic PostgreSQL token-counting failures no longer render lower-layer exception text into package-owned logs.
  • Existing protected-main bootstrap precedence, typed configuration, safe secret-input, provider/client, tenant/RLS, health, logging, and retention contracts remain authoritative.

The current semantic delta is confined to pg_llm_batch/config.py, pg_llm_batch/orchestrator.py, pg_llm_batch/token_counter.py, tests/test_batch_assembly.py, and tests/test_connection_lifecycle.py. It introduces no schema, migration, provider protocol, model, scheduler, or release authority.

Exact-head evidence

Current head f5a88e392b951119fd884b24765dbed77507ea81 has terminal-success direct CI, Security Scan, SAST Semgrep, CodeQL/OSV/Trivy and the current central exact-head evidence set; no failed or queued current-head check was returned in the latest inspection. Formal reviews and unresolved review threads are absent, while live organization policy requires zero approving reviews and resolved review threads.

Protected main has since advanced to ddf8d0320cdadf188799a868b9c2ff2e527eaf46 through a disjoint provider-file deletion change. Fresh compare shows this branch one protected-main commit behind, five commits ahead, and no overlap with that later main delta; GitHub reports the PR mergeable.

Replacement and merge boundary

Promote this unchanged source to Ready so current required workflows can evaluate the live PR/base relation. Merge only if the exact head remains unchanged and mergeable against then-live protected main, every required current-head CI/security/coverage/package/provenance gate is terminal-success, all valid findings are resolved, and live rules are satisfied. No #87 predecessor evidence transfers.

After protected integration, re-evaluate #87 and dependent issues (#90, #108, #111, #117, #121, #122, #123, #126, #129, #131, #134) against the actual merged behavior rather than assuming this bounded replacement closes them.

Summary by CodeRabbit

  • 버그 수정

    • 초기화 또는 배치 처리 중 오류가 발생해도 PostgreSQL 연결과 관련 리소스가 안전하게 정리됩니다.
    • 잘못된 설정값과 배치 제한값을 사전에 검증합니다.
    • 연결 종료 과정의 반복 호출과 종료 실패 상황을 안정적으로 처리합니다.
  • 테스트

    • 정상 처리와 오류 상황에서 리소스 수명주기 및 정리 동작을 검증하는 회귀 테스트를 추가했습니다.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 766f36a3-4c58-485f-a97d-8ea3190596db

📥 Commits

Reviewing files that changed from the base of the PR and between ddf8d03 and 46385b1.

📒 Files selected for processing (5)
  • pg_llm_batch/config.py
  • pg_llm_batch/orchestrator.py
  • pg_llm_batch/token_counter.py
  • tests/test_batch_assembly.py
  • tests/test_connection_lifecycle.py

📝 Walkthrough

Walkthrough

설정 저장소와 토큰 카운터의 초기화 실패 및 종료 처리를 강화했습니다. 제한값 검증을 엄격하게 적용했습니다. prepare_batches는 성공과 예외 발생 시 보유 리소스를 종료합니다. 관련 수명주기 회귀 테스트를 추가했습니다.

Changes

리소스 수명주기 및 검증

Layer / File(s) Summary
저장소 초기화 실패 정리
pg_llm_batch/config.py, tests/test_connection_lifecycle.py
PostgresConfigStore와 SecretStore가 초기화 중 예외가 발생하면 연결을 닫고 예외를 다시 발생시킵니다. 초기화 실패 테스트를 추가했습니다.
토큰 카운터 검증 및 종료
pg_llm_batch/token_counter.py, tests/test_connection_lifecycle.py
TokenCounter와 BatchAccumulator가 제한값을 양의 정수로 검증합니다. TokenCounter.close()가 연결을 안전하게 종료하고 참조를 제거합니다.
배치 조립 리소스 정리
pg_llm_batch/orchestrator.py, tests/test_batch_assembly.py, tests/test_connection_lifecycle.py
prepare_batches가 성공과 예외 경로에서 TokenCounter와 PostgresConfigStore를 닫습니다. 관련 호출 횟수와 실패 경로를 검증합니다.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • #134 — PostgresConfigStore와 SecretStore의 초기화 및 수명주기 처리를 함께 변경합니다.
  • #126 — TokenCounter의 초기화 검증과 연결 수명주기 처리를 변경합니다.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 연결 및 리소스 수명주기 보장 복구라는 주요 변경 사항을 명확하게 요약합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/resource-lifecycle-current-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seonghobae
seonghobae marked this pull request as ready for review August 12, 2026 08:39
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.

1 participant