Skip to content

Add automated schema freshness checks#95

Merged
qwrobins merged 1 commit into
mainfrom
codex/schema-freshness
May 23, 2026
Merged

Add automated schema freshness checks#95
qwrobins merged 1 commit into
mainfrom
codex/schema-freshness

Conversation

@qwrobins

@qwrobins qwrobins commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • add best-effort startup schema freshness checks with daily caching
  • add [schema] config support for stale_after_days and opt-in auto_update
  • add stale-schema hints for GraphQL missing field/type errors
  • update docs, bundled skill text, changelog, and bump version to 0.6.9

Closes #94.

Tests

  • bun run typecheck
  • bun run test
  • bun run build
  • bun run test -- tests/core/schema/freshness.test.ts tests/core/output-envelope.test.ts tests/core/config/config-file.test.ts

Summary by CodeRabbit

  • New Features

    • Daily startup schema freshness checks that warn if the bundled schema is stale (default 14 days).
    • Optional auto-update mode that can refresh and write updated schema files when drift is detected.
    • Human-facing error messages now include a stale-schema hint for certain GraphQL failures.
  • Documentation

    • Docs updated with freshness check behavior and configuration (stale_after_days, auto_update) and example warnings.
  • Tests

    • Added tests covering freshness checks, auto-update behavior, and error-message hints.
  • Chore

    • Package version bumped to 0.6.9.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d656f50a-5b55-430a-94dc-0a3aaf86bcac

📥 Commits

Reviewing files that changed from the base of the PR and between f2dec40 and cb40714.

⛔ Files ignored due to path filters (1)
  • src/generated/embedded-skills.ts is excluded by !**/generated/**
📒 Files selected for processing (12)
  • CHANGELOG.md
  • docs/schema-and-generated.md
  • package.json
  • skills/linearctl/SKILL.md
  • src/cli/main.ts
  • src/core/config/config-file.ts
  • src/core/output/envelope.ts
  • src/core/schema/freshness.ts
  • src/index.ts
  • tests/core/config/config-file.test.ts
  • tests/core/output-envelope.test.ts
  • tests/core/schema/freshness.test.ts
✅ Files skipped from review due to trivial changes (5)
  • package.json
  • skills/linearctl/SKILL.md
  • CHANGELOG.md
  • src/index.ts
  • docs/schema-and-generated.md

📝 Walkthrough

Walkthrough

Adds a startup schema freshness check (daily throttle) invoked from the CLI, config support for [schema] (stale_after_days, auto_update), optional auto-update of bundled schema files, schema-related error hints, tests, docs, and a version bump to 0.6.9.

Changes

Schema Freshness Detection

Layer / File(s) Summary
Schema Configuration Contract
src/core/config/config-file.ts, tests/core/config/config-file.test.ts
SchemaConfig interface defines autoUpdate and staleAfterDays; parseLinearConfig/stringifyLinearConfig handle [schema] INI with validation and preserve schema across profile metadata operations.
Schema Freshness Checking
src/core/schema/freshness.ts, tests/core/schema/freshness.test.ts
maybeWarnForStaleSchema loads bundled metadata, consults a per-config freshness cache to throttle daily checks, runs GraphQL introspection to compute a live fingerprint, detects drift, writes updated schema files if autoUpdate enabled, or prints a formatted stale-schema warning to stderr; errors are swallowed and schema command is skipped.
CLI Command Dispatch Integration
src/cli/main.ts, src/index.ts
CLI imports and invokes maybeWarnForStaleSchema during command dispatch (non-blocking) and re-exports freshness helpers via package entry point.
Schema-Lookup Error Hints
src/core/output/envelope.ts, tests/core/output-envelope.test.ts
formatCommandErrorHuman matches common GraphQL field/type-not-found messages and appends a "Hint: This may be caused by a stale schema." remediation line to human-readable error output.
Documentation & Release
CHANGELOG.md, docs/schema-and-generated.md, skills/linearctl/SKILL.md, package.json
Changelog and docs describe the startup freshness warning, configuration keys (schema.stale_after_days, schema.auto_update), optional auto-update behavior, example stderr warning text, and package version bumped to 0.6.9.

Sequence Diagram

sequenceDiagram
  participant CLI as CLI Command<br/>Dispatch
  participant Freshness as maybeWarnForStaleSchema
  participant Config as Config<br/>Loading
  participant Metadata as Bundled<br/>Schema Metadata
  participant Cache as Freshness<br/>Cache
  participant API as GraphQL<br/>API
  participant Output as Schema<br/>Output/Stderr

  CLI->>Freshness: call with commandName, paths, env
  Freshness->>Freshness: skip if commandName === 'schema'
  Freshness->>Config: load LinearConfig
  Freshness->>Metadata: load bundled metadata
  Freshness->>Cache: read freshness cache (throttle)
  alt cache hit within throttle window
    Freshness-->>CLI: return (cached result)
  else
    Freshness->>API: run introspection query
    API-->>Freshness: live schema fingerprint
    Freshness->>Cache: write updated cache
    alt drift detected
      alt autoUpdate enabled
        Freshness->>Output: write schema.json, schema-meta.json
        Freshness->>Output: print update status to stderr
      else
        Freshness->>Output: print stale-schema warning
      end
    end
  end
  CLI->>CLI: execute command handler
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • qwrobins/linearctl#38: Related to formatCommandErrorHuman changes this PR extends with stale-schema hint behavior.
  • qwrobins/linearctl#5: Introduced schema metadata and introspection/pull plumbing that underpins freshness checking.

Poem

🐰 A little rabbit scurries near the tree,
"Your schema's old," it whispers quietly.
It checks, it caches, and it may refresh,
So commands won't fail in a sudden mesh.
Hop on—your GraphQL stays fresh and free!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add automated schema freshness checks' accurately summarizes the main change—implementing automatic schema drift detection on startup.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #94: startup drift detection with daily caching [#94], configurable auto-update via [schema] config [#94], and stale-schema hints for GraphQL errors [#94].
Out of Scope Changes check ✅ Passed All changes are directly related to schema freshness objectives. Documentation updates, version bump, and tests are appropriate supporting changes for the feature implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 codex/schema-freshness

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/main.ts`:
- Around line 328-336: The advisory schema check currently blocks command
execution because main awaits maybeWarnForStaleSchema before calling
registration.handler; change this so the check runs asynchronously and does not
delay the handler: invoke maybeWarnForStaleSchema(...) without awaiting (e.g.,
fire-and-forget using void or scheduling it) and attach a .catch(...) that logs
any errors to avoid unhandled rejections, then immediately return await
registration.handler(args.positionals.slice(1), options); ensure you call
maybeWarnForStaleSchema with the same arguments (commandName, args.profile,
args.configFile, args.credentialsFile, args.apiUrl, env) so the behavior is
preserved but non-blocking.

In `@tests/core/schema/freshness.test.ts`:
- Around line 85-86: Replace the fragile near-future Date instances used as the
now property in the freshness tests with a far-future fixed timestamp (e.g. new
Date("2099-01-01T00:00:00.000Z")) to avoid date-coupled flakes; update every
occurrence of the object key now: new Date("2026-05-23T...") in the freshness
test cases (the places where the tests pass a now property into the
freshness-checking helpers) to use the single far-future constant date instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 97472db1-550a-468c-a5b0-a1423925169c

📥 Commits

Reviewing files that changed from the base of the PR and between 521af15 and f2dec40.

⛔ Files ignored due to path filters (1)
  • src/generated/embedded-skills.ts is excluded by !**/generated/**
📒 Files selected for processing (12)
  • CHANGELOG.md
  • docs/schema-and-generated.md
  • package.json
  • skills/linearctl/SKILL.md
  • src/cli/main.ts
  • src/core/config/config-file.ts
  • src/core/output/envelope.ts
  • src/core/schema/freshness.ts
  • src/index.ts
  • tests/core/config/config-file.test.ts
  • tests/core/output-envelope.test.ts
  • tests/core/schema/freshness.test.ts

Comment thread src/cli/main.ts Outdated
Comment thread tests/core/schema/freshness.test.ts Outdated
@qwrobins qwrobins force-pushed the codex/schema-freshness branch from f2dec40 to cb40714 Compare May 23, 2026 05:06
@qwrobins qwrobins merged commit 6fc2988 into main May 23, 2026
2 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.

Automated schema freshness: detect drift on startup, streamline updates

1 participant