Skip to content

FIX: learned costs survive updates, reset only by a declared cost epoch - #99

Merged
Jules-GP merged 1 commit into
DCBIA-OrthoLab:mainfrom
Jules-GP:fix/costs-survive-updates
Oct 30, 2026
Merged

Jules-GP merged 1 commit into
DCBIA-OrthoLab:mainfrom
Jules-GP:fix/costs-survive-updates

Conversation

@Jules-GP

Copy link
Copy Markdown
Collaborator

Why

The server learns what each tool costs in RAM and VRAM (tool_costs.json), and admission packs runs on the card from it. In the production service that file lived in SCHEMA_CACHE_DIR=/tmp/schema-cache, inside the container. Every update, server or tools, recreates the container, so every update silently forgot every measurement: each tool went back to "unmeasured", reserved the whole budget and ran alone until the table refilled.

Change

  • The table has its own setting, COST_TABLE_PATH, set for inference and inference-cpu to /workspace/server/.costs/tool_costs.json: in the bind-mounted checkout, gitignored, beside .history and .update, which already outlive the container the same way. The update agent only git pull --ff-onlys, so it never removes it. Kept separate from the schema cache on purpose: a schema cache is something one deletes to force a regeneration, the cost table cannot be regenerated. Empty, the setting keeps the old location, so other deployments (the venvs image's volume, a plain checkout) do not move. Nothing under docker/ changed.
  • A reset happens only when a release says so, at two levels:
    • per tool: [tool.sadt] cost_epoch = N in the tool's pyproject.toml (absent = 0). Each entry records the epoch it was learned under; a tool whose declared epoch changed loses its own entry and relearns, the others are untouched. A tool release that does not change cost_epoch keeps everything.
    • whole server: costs.TABLE_EPOCH, bumped in a server release to discard the whole table once. Stored as a reserved integer key in the same file, in the same atomic write; known(), the banner, /status, the admin panel and the nested runner never take it for a tool.
    • A missing marker or cost_epoch counts as 0, so every existing table and entry is kept. A cost_epoch that is not an integer is ignored with one warning (a typo must not reset anything, nor take the tool away).
  • Every reset is logged at WARNING with the tool and both epochs; the costs banner names the table's path; a table that cannot be written says so once at WARNING instead of a debug line.
  • Docs: ADDING_A_TOOL.md ("When a release changes what the tool costs"), docs/INTERNALS.md, server/README.md, .env.example. Bump cost_epoch when a release changes what a tool costs (a new model, different input handling), not for every release.

Tests

test_cost_table_lifetime.py (new) and two in test_schema_registry.py, each failing before the change: the production services keep the table where a recreate cannot reach it (parses the compose file); two processes with fresh /tmps sharing the persistent path keep every tool's figures (the actual defect); an unchanged epoch keeps everything, a bump drops only that tool, old entries count as epoch 0, a tool not loaded keeps its entry; a server epoch bump discards the table once; the marker is never listed as a tool anywhere; the registry reads cost_epoch and ignores a non-integer with one warning. Server suite: 1573 passed, known test_dev_mounts failure unchanged.

Deployment

The table currently in the running container's /tmp is lost one last time by the recreate this update causes. It only holds what was measured since the previous update. The server creates server/.costs/ itself; it needs server/ writable by the container user, which .history and .update already rely on, and a warning in the log says so if not.

Companion: SADT-VISOR documents cost_epoch in CONTRIBUTING.md and the tool template.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 03:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Jules-GP
Jules-GP merged commit 4a2ab5b into DCBIA-OrthoLab:main Oct 30, 2026
9 checks passed
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.

2 participants