Skip to content

feat(config): add per-project container snapshot policy#1042

Merged
aaight merged 1 commit intodevfrom
feature/per-project-snapshot-policy
Mar 24, 2026
Merged

feat(config): add per-project container snapshot policy#1042
aaight merged 1 commit intodevfrom
feature/per-project-snapshot-policy

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 24, 2026

Summary

Implements per-project container snapshot policy stored in config so that router workers can resolve snapshot behavior consistently.

  • Schema: Adds nullable snapshot_enabled (BOOLEAN) and snapshot_ttl_ms (INTEGER) columns to the projects table via migration 0046_add_snapshot_policy.sql. Null means fall back to router defaults — no behavior change for existing projects.
  • Config pipeline: Extends ProjectRow, ProjectConfigRaw, and ProjectConfigSchema so snapshotEnabled and snapshotTtlMs flow through mapProjectRow()loadConfigFromDb()loadProjectConfig() alongside all existing project settings.
  • Router defaults: Adds four snapshot-related fields to RouterConfig and routerConfig backed by env vars (SNAPSHOT_ENABLED, SNAPSHOT_DEFAULT_TTL_MS, SNAPSHOT_MAX_COUNT, SNAPSHOT_MAX_SIZE_BYTES). Project-level values override these defaults when set; null/missing project values fall back to router defaults.
  • Tests: Adds unit coverage in configMapper.test.ts (null→undefined mapping, explicit true/false, TTL value), configRepository.test.ts (end-to-end schema mapping including null fallback), and router/config.test.ts (all four snapshot defaults).
  • Refactoring: Extracted buildBaseProjectFields() from mapProjectRow() to keep the function within biome's cognitive complexity limit.

Trello card: https://trello.com/c/IIIkvePP/555-as-the-system-i-need-per-project-container-snapshot-policy-stored-in-config-so-that-router-workers-can-resolve-snapshot-behavior

Test plan

  • All unit tests pass (npm test)
  • Lint passes (npm run lint)
  • TypeScript type checks pass (npm run typecheck)
  • configMapper.test.ts — snapshot field null/true/false/value cases all pass
  • configRepository.test.ts — snapshot config mapping group all pass
  • router/config.test.ts — snapshot default values all pass

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/db/repositories/configMapper.ts 95.83% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

Summary

LGTM — clean, well-structured config plumbing for per-project container snapshot policy.

The implementation correctly follows existing patterns throughout:

  • Migration: Simple nullable ALTER TABLE ADD COLUMN — no behavior change for existing projects, null semantics are correct for fallback-to-defaults.
  • Schema pipeline: snapshotEnabled and snapshotTtlMs flow correctly through ProjectRowbuildBaseProjectFields()ProjectConfigRawProjectConfigSchema with proper null→undefined coercion via ??.
  • Critical edge case: snapshotEnabled: false is correctly preserved — the ?? operator doesn't coalesce on false, so an explicit disable at the project level won't be silently ignored.
  • Router defaults: Env var parsing follows the established Number(...) || default pattern. All four defaults are sensible (disabled, 24h TTL, 5 max, 10GB max size).
  • Refactoring: Extracting buildBaseProjectFields() is clean — all fields verified accounted for, and agentModels/agentEngineSettings correctly remain in mapProjectRow since they depend on projectAgentConfigs.
  • Tests: Good coverage of the null/true/false/value matrix for snapshot fields across mapper, repository, and router config layers.
  • Bonus fix: maxInFlightItems: null was correctly added to baseProjectRow test fixture (was missing previously).

All CI checks pass.

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit 684ea89 into dev Mar 24, 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