Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/python-process-owner.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 服务统一由 run.py 启动和执行进程重启。HTTP 请求 DEBUG 日志省略查询参数。Core 统一排空可观测性队列并关闭导出器,移除已停用的 Logtail 写入器及旧 PostgreSQL 日志队列。
2 changes: 1 addition & 1 deletion .changes/python-runtime-hardening.fixed.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
提高 PDF、HTTP 与 CA 证书依赖的安全版本下限,并在两种服务启动方式中移除 Uvicorn 访问日志的查询参数,避免记录 OAuth 回调凭据。
提高 PDF、HTTP 与 CA 证书依赖的安全版本下限,并移除 Uvicorn 访问日志的查询参数,避免记录 OAuth 回调凭据。
14 changes: 0 additions & 14 deletions app/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@
from inkcre_core.libs.obsrv.main import get_logger


SENSITIVE_QUERY_PARAMETERS = frozenset(
{"access_token", "client_secret", "code", "refresh_token", "state", "token"}
)


def logged_query_params(request: Request) -> str:
"""Render query diagnostics without persisting OAuth or credential material."""
return "&".join(
f"{key}={'<redacted>' if key.lower() in SENSITIVE_QUERY_PARAMETERS else value}"
for key, value in request.query_params.multi_items()
)


def create_peer_jwt(
secret: str, *, now: float | None = None, lifetime_seconds: int | None = None
) -> str:
Expand Down Expand Up @@ -97,7 +84,6 @@ async def dispatch(self, request: Request, call_next: Callable) -> Response:
extra={
"method": request.method,
"path": request.url.path,
"query_params": logged_query_params(request),
},
)

Expand Down
3 changes: 0 additions & 3 deletions app/persistence/observability/__init__.py

This file was deleted.

10 changes: 0 additions & 10 deletions app/persistence/observability/uow.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/40-deployment/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ operational helpers:
The service has no entry point and defaults to `python scripts/container.py web`, which keeps
Heroku's shell-based `CMD` behavior explicit. Call other supported commands with the full prefix:

- `python scripts/container.py web`: start Uvicorn on `0.0.0.0:$PORT`
- `python scripts/container.py web`: restore enabled Extensions, then run `run.py --host 0.0.0.0 --port "$PORT"`
- `python scripts/container.py db <command>`: run the explicit lifecycle surface documented in
[database-contract.md](database-contract.md)
- `python scripts/container.py ready`: compatibility entry point for runtime-profile readiness
Expand Down
9 changes: 5 additions & 4 deletions docs/40-deployment/runtime-orchestration.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ starts from an image without Extension wheels and its writable environment is no
distribution that cannot be resolved, downloaded, applied, or verified prevents that dyno from starting. The separate
`ready` command and HTTP `/readyz` remain read-only and never provision packages.

The web process starts only after pre-start restoration succeeds. The `scripts/web.py` runner waits for Uvicorn’s graceful
shutdown and resource cleanup, then replaces itself with a fresh Python process after an environment application.
The new process reimports installed packages, restores exact enabled selections, and publishes readiness only after
bootstrap succeeds. If pip application fails, Core keeps the Peer paused, reports the failure in management status,
Once pre-start restoration succeeds, the container replaces its bootstrap process with `run.py`, the same Uvicorn runner
used locally. The container binds to `0.0.0.0:$PORT`, defaulting to port 8000. Local runs use the application settings by
default and accept the same `--host` and `--port` overrides. After an environment application, the runner waits for
graceful shutdown and replaces itself with the same command line. The new process reimports the installed packages,
starts the exact enabled selections, and publishes readiness after bootstrap succeeds. If pip application fails, Core keeps the Peer paused, reports the failure in management status,
and does not claim that dependencies were restored. An operator must repair the environment and restart the process.

Active Agent Turns are ordinary caller-owned asyncio Tasks,not scheduler jobs or deployment work records。The MVP Thread
Expand Down
29 changes: 0 additions & 29 deletions inkcre_core/libs/obsrv/log_handler_logtail.py

This file was deleted.

75 changes: 0 additions & 75 deletions inkcre_core/libs/obsrv/log_handler_postgresql.py

This file was deleted.

11 changes: 0 additions & 11 deletions inkcre_core/libs/obsrv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,3 @@ def get_logger() -> logging.Logger:
"""
global LOGGER
return LOGGER


def start_obsrv() -> None:
"""Compatibility entry; the App starts its bound runtime after config admission."""


async def close_obsrv() -> None:
from .telemetry import close_telemetry

await close_telemetry()
# Core.aclose owns its selected backend and drains it before closing the DB.
1 change: 0 additions & 1 deletion inkcre_core/persistence/observability/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions inkcre_core/persistence/observability/uow.py

This file was deleted.

10 changes: 0 additions & 10 deletions libs/obsrv/log_handler_logtail.py

This file was deleted.

10 changes: 0 additions & 10 deletions libs/obsrv/log_handler_postgresql.py

This file was deleted.

38 changes: 1 addition & 37 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ app = [
"semantic-version (>=2.10.0,<3.0.0)",
"uvicorn (>=0.35.0,<0.36.0)",
"apscheduler>=3.11.0",
"logtail-python>=0.3.0",
"python-telegram-bot==22.8",
"alembic>=1.16.4",
"alembic-utils>=0.8.8",
Expand Down
52 changes: 26 additions & 26 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Run API Service."""

import argparse
import asyncio
import contextlib
import datetime
Expand All @@ -12,7 +13,7 @@
from fastapi.responses import JSONResponse

# Setup logging
from inkcre_core.libs.obsrv.main import close_obsrv, setup_obsrv, start_obsrv
from inkcre_core.libs.obsrv.main import setup_obsrv

from app.settings import settings
from app.access_log import access_log_config
Expand Down Expand Up @@ -95,20 +96,11 @@
from app.scheduler import drain_scheduler, scheduler, start_scheduler, with_trace_id


_CURRENT_SERVER: uvicorn.Server | None = None
_REQUEST_CONDITION = asyncio.Condition()
_PEER_EXECUTION_OPEN = True
_ACTIVE_PEER_REQUESTS = 0


def _request_uvicorn_exit() -> None:
if _CURRENT_SERVER is not None:
_CURRENT_SERVER.should_exit = True


configure_process_restart(_request_uvicorn_exit)


async def pause_peer_execution() -> None:
"""Drain Core work before a shared Python environment can be changed."""
global _PEER_EXECUTION_OPEN
Expand Down Expand Up @@ -260,7 +252,6 @@ async def bootstrap_when_database_is_ready(app: fastapi.FastAPI) -> None:

@contextlib.asynccontextmanager
async def lifespan(app: fastapi.FastAPI):
start_obsrv()
logger.info("Application startup")
RUNTIME_STATUS.set(RuntimePhase.STARTING, "runtime_bootstrap_pending")
bootstrap_task = asyncio.create_task(bootstrap_when_database_is_ready(app))
Expand All @@ -286,10 +277,7 @@ async def lifespan(app: fastapi.FastAPI):
if runtime_was_ready:
await PeerManager.clear_self_lease()
finally:
try:
await close_obsrv()
finally:
await CORE.aclose()
await CORE.aclose()


api_app = fastapi.FastAPI(title="InKCre", lifespan=lifespan)
Expand Down Expand Up @@ -394,16 +382,28 @@ async def readiness() -> JSONResponse:
core_router.include_router(observability_router)
api_app.include_router(core_router)

if __name__ == "__main__":

async def serve() -> None:
global _CURRENT_SERVER
config = uvicorn.Config(
api_app, host=settings.host, port=settings.port, log_config=access_log_config()
)
_CURRENT_SERVER = uvicorn.Server(config)
await _CURRENT_SERVER.serve()
if process_restart_requested():
os.execv(sys.executable, [sys.executable, *sys.argv])
async def serve(host: str, port: int) -> None:
server = uvicorn.Server(
uvicorn.Config(api_app, host=host, port=port, log_config=access_log_config())
)

asyncio.run(serve())
def request_exit() -> None:
server.should_exit = True

configure_process_restart(request_exit)
await server.serve()


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--host", default=settings.host)
parser.add_argument("--port", type=int, default=settings.port)
args = parser.parse_args()
asyncio.run(serve(args.host, args.port))
if process_restart_requested():
os.execv(sys.executable, [sys.executable, *sys.argv])


if __name__ == "__main__":
main()
Loading
Loading