Skip to content

fix(health,wrangler): real-dependency /health probe + chittytrack tail consumer - #109

Merged
chitcommit merged 4 commits into
feat/meta-executors-registryfrom
fix/real-health-probe-and-tail-consumer
Jun 4, 2026
Merged

chitcommit merged 4 commits into
feat/meta-executors-registryfrom
fix/real-health-probe-and-tail-consumer

Conversation

@chitcommit

Copy link
Copy Markdown
Contributor

Why

Compliance audit verdict (chittyos-compliance):

BLOCKER: /health violates the no-fake-endpoints rule. The endpoint returns a static {status:"ok"} regardless of dependency state and would happily report green while the worker cannot reach Neon, ChittyConnect, or its daemon — a direct violation of the chittyentity CLAUDE.md binding rule "every endpoint must return real results against a real datastore on the day it is committed".

This PR fixes that.

What

/health is now real

Old (src/index.ts, before):

app.get('/health', (c) => c.json({
  status: 'ok',
  service: 'chittycommand',
  version: '0.1.0',
  timestamp: new Date().toISOString(),
}));

New (src/index.ts, after) — delegates to src/routes/health.ts:

app.get('/health', async (c) => {
  const { body, httpStatus } = await runHealthProbes(c.env);
  return c.json(body, httpStatus);
});

Probes (each per-dep timeout 2000ms, total ≤ 5000ms via Promise.all):

Probe Mechanism Failure mode
db SELECT 1 via Neon HTTP driver Criticalstatus: down, HTTP 503
chittyconnect GET ${CHITTYCONNECT_URL}/health degraded (200) — chittycommand survives brief outages
daemon max(heartbeat_at) FROM cc_node_leases WHERE released_at IS NULL stale if > 2× daemon/loop.ts default heartbeatMs (10000 → 20000ms cutoff). Missing table → not_provisioned (degraded, NOT down) — so deploys against bases without #101 don't 503

Runs unauthenticated/health lives above the app.use('/api/*', authMiddleware) mount, so the probe never touches auth.

The probe handler is extracted to src/routes/health.ts so the integration test can exercise it in pure Node — importing src/index.ts directly drags in cloudflare: namespaced modules (Agents SDK / Durable Objects) that only resolve under workerd.

wrangler.jsonc

tail_consumers: [{ "service": "chittytrack" }] is already present on the base branch (lines 84–86). No change needed — verified.

Real Neon validation

Validated via the Neon MCP against a disposable branch of the ChittyCommand project (cool-bar-13270800 / br-spring-queen-akggkmso):

SELECT 1 AS ok;                                     -- [{"ok":1}]
SELECT EXTRACT(EPOCH FROM (NOW() - max(heartbeat_at))) * 1000
  FROM cc_node_leases WHERE released_at IS NULL;    -- relation "cc_node_leases" does not exist

This exercises both the happy path (db probe ok) and the not_provisioned fallback (parent branch has no cc_node_leases since #101 hasn't merged yet).

Sample real /health response captured by running runHealthProbes against the live Neon branch (no mocks):

{
  "status": "degraded",
  "service": "chittycommand",
  "version": "0.1.0",
  "timestamp": "2026-06-04T05:27:16.111Z",
  "probes": {
    "db": { "status": "ok", "latency_ms": 226 },
    "chittyconnect": {
      "status": "degraded", "latency_ms": 0,
      "error": "CHITTYCONNECT_URL not configured"
    },
    "daemon": {
      "status": "not_provisioned", "newest_heartbeat_age_ms": null,
      "error": "relation \"cc_node_leases\" does not exist"
    }
  }
}

HTTP status: 200 (db ok → not down; chittyconnect/daemon degraded surfaces as degraded not down).

Test plan

  • npm run typecheck clean
  • SKIP_INTEGRATION=1 npm test — 15 passed / 15 skipped (no regressions)
  • DATABASE_URL=<neon-branch> npx vitest run tests/health/health-probe.spec.ts — 2/2 pass against real Neon
  • Integration test asserts:
    • DB probe returns ok with latency_ms > 0 against the real Neon branch
    • Daemon probe returns one of ok | stale | not_provisioned (under-asserted — depends on whether the branch has cc_node_leases provisioned and an active node)
    • Invalid DB connection string → status: down, HTTP 503, probes.db.status === 'down'
  • Response shape matches the documented spec

Not in this PR (explicitly)

  • No tier-doc changes (CHARTER.md / CHITTY.md / CLAUDE.md untouched)
  • No new endpoints
  • No auth changes (/health remains unauthenticated, same as before)
  • No changes to meta/, daemon/, or the executor registry
  • No wrangler.jsonc changes — tail_consumers: chittytrack was already present

Assumptions documented inline

  • Daemon stale-cutoff = 2× daemon/loop.ts default heartbeatMs (10000ms) = 20000ms. If the daemon is run with a different heartbeatMs, this cutoff would need to be reconsidered. Documented in src/routes/health.ts:25-26.

Auto-merge OFF. No deploy.

🤖 Generated with Claude Code

chitcommit and others added 2 commits June 4, 2026 03:36
…tch → heartbeat)

Stacked on #106. Replaces the injected-executor abstraction in daemon/loop.ts
with a direct call to meta/intent.ts::executeIntent, closing the
meta-orchestrator loop. Status transitions, audit-row writes, and the second
sovereignty gate are all owned by executeIntent → dispatch; the loop's
responsibility is leader lifecycle, intent claiming, heartbeats, and outcome
classification.

Four outcomes are handled distinctly:

  - ok=true (executed)      → bump processed counter, reset error backoff
  - ok=true (replayed)      → bump replayed counter, no backoff, no double-count
  - ok=false (refused)      → bump refused counter, no backoff (steady-state)
  - ok=false (exec error)   → bump errored counter, bounded exp backoff

Sovereignty refusals are identified by canonical error prefixes emitted by
meta/executors/dispatch.ts ("sovereignty re-reckon:" /
"sovereignty snapshot stale ..."). Refusals are NOT treated as transient
faults — they are valid outcomes and do not trigger backoff.

The loop honors options.signal via AbortController throughout, including
inside the sleep helper, so SIGTERM from daemon/runtime/entrypoint.ts (PR #105)
unwinds cleanly through releaseLeadership.

tests/daemon/loop.spec.ts — real Neon integration. Seeds two pending intents
against the update_obligation_status executor, runs runLeaderLoop with
maxIntents=2, asserts:
  - both intents reach status='done'
  - each produces exactly one cc_actions_log row (attempt=1, key set, status='completed')
  - cc_obligations rows actually moved to 'deferred'
  - cc_node_leases shows leadership released on clean exit
  - log stream contains intent_heartbeat_before / intent_heartbeat_after pairs

Out of scope (not in this PR):
  - new executors (mercury, etc.)
  - production deploy
  - multi-node coordination beyond single-node leader
  - schema additions on cc_intents / cc_actions_log

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…l consumer

The previous /health returned a static {status:"ok",...} regardless of
whether the worker could reach its real dependencies — a direct violation
of the chittyentity CLAUDE.md "No Mocks, Fake Data, or Placeholder
Endpoints" binding rule ("every endpoint must return real results against
a real datastore on the day it is committed").

This change replaces /health with a real probe that executes against the
worker's actual dependencies:

  * db            — SELECT 1 via Neon HTTP driver. Critical: failure -> 503.
  * chittyconnect — GET ${CHITTYCONNECT_URL}/health. Degraded if unreachable.
  * daemon        — newest cc_node_leases.heartbeat_at, stale if older than
                    2x daemon/loop.ts default heartbeatMs (10000ms ->
                    20000ms cutoff). Missing table -> not_provisioned
                    (degraded, NOT down) so deploys against bases without
                    #101 don't 503.

Per-dep timeout 2000ms; total probe bounded ≤ 5000ms via Promise.all.
Runs unauthenticated (no auth middleware on /health).

The probe handler is extracted to src/routes/health.ts so it can be
integration-tested in pure Node — importing src/index.ts directly drags
in `cloudflare:` modules (Agents SDK / DOs) that only resolve under
workerd. Integration test exercises the handler against a real Neon
branch (no mocks), validates DB probe ok and shape of all three probes,
and asserts 503 + status=down when DB is unreachable.

wrangler.jsonc already declares `tail_consumers: [{service: chittytrack}]`
(present on the base branch) — no change required there.

Verified against Neon branch br-spring-queen-akggkmso of project
cool-bar-13270800 (ChittyCommand). Sample real response:

{
  "status": "degraded",
  "service": "chittycommand",
  "version": "0.1.0",
  "timestamp": "2026-06-04T05:27:16.111Z",
  "probes": {
    "db": { "status": "ok", "latency_ms": 226 },
    "chittyconnect": {
      "status": "degraded", "latency_ms": 0,
      "error": "CHITTYCONNECT_URL not configured"
    },
    "daemon": {
      "status": "not_provisioned", "newest_heartbeat_age_ms": null,
      "error": "relation \"cc_node_leases\" does not exist"
    }
  }
}

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
chittycommand 35506e4 Jun 04 2026, 12:59 PM

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d5627dd-5f7c-4e44-bfb5-2b0243c93050

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/real-health-probe-and-tail-consumer

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 and usage tips.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
  1. @coderabbitai review
  2. @copilot review
  3. @codex review
  4. @claude review
    Adversarial review request: evaluate security, policy bypass paths, regression risk, and merge-gating bypass attempts.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f0a11bbd89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/routes/health.ts Outdated
const rows = (await withTimeout(
sql`SELECT EXTRACT(EPOCH FROM (NOW() - max(heartbeat_at))) * 1000 AS age_ms
FROM cc_node_leases
WHERE released_at IS NULL`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use the actual lease schema in the daemon probe

In environments where cc_node_leases is provisioned, this query still fails because the table defined in src/db/schema.ts has no released_at column; releases are represented by nulling heartbeat_at/lease_expires_at in daemon/leader.ts. The catch block then matches the resulting “column released_at does not exist” error as not_provisioned, so /health will never report the daemon as ok or stale based on real heartbeats once the table exists.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e476115. Replaced WHERE released_at IS NULL with WHERE heartbeat_at IS NOT NULL to match the actual release semantics in daemon/leader.ts (release = NULL out heartbeat_at + lease_expires_at). Once cc_node_leases is provisioned with held leases the probe will now return ok/stale based on real heartbeat age instead of mis-classifying the SQL error as not_provisioned.

Addresses Codex P2 on PR #109. The cc_node_leases schema in
src/db/schema.ts has no released_at column — release is represented by
NULLing heartbeat_at/lease_expires_at in daemon/leader.ts. The previous
WHERE released_at IS NULL clause raised 'column released_at does not
exist', which the catch block then mis-classified as 'not_provisioned',
so /health would never report ok/stale based on real heartbeats.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
  1. @coderabbitai review
  2. @copilot review
  3. @codex review
  4. @claude review
    Adversarial review request: evaluate security, policy bypass paths, regression risk, and merge-gating bypass attempts.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Base automatically changed from feat/daemon-loop-executes-intents to feat/meta-executors-registry June 4, 2026 12:58
@chitcommit
chitcommit merged commit 45d4dff into feat/meta-executors-registry Jun 4, 2026
9 of 11 checks passed
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
  1. @coderabbitai review
  2. @copilot review
  3. @codex review
  4. @claude review
    Adversarial review request: evaluate security, policy bypass paths, regression risk, and merge-gating bypass attempts.

@chitcommit
chitcommit deleted the fix/real-health-probe-and-tail-consumer branch June 4, 2026 12:59
@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

chitcommit added a commit that referenced this pull request Jun 10, 2026
…l consumer (#109)

* feat(daemon): loop body wires executeIntent end-to-end (claim → dispatch → heartbeat)

Stacked on #106. Replaces the injected-executor abstraction in daemon/loop.ts
with a direct call to meta/intent.ts::executeIntent, closing the
meta-orchestrator loop. Status transitions, audit-row writes, and the second
sovereignty gate are all owned by executeIntent → dispatch; the loop's
responsibility is leader lifecycle, intent claiming, heartbeats, and outcome
classification.

Four outcomes are handled distinctly:

  - ok=true (executed)      → bump processed counter, reset error backoff
  - ok=true (replayed)      → bump replayed counter, no backoff, no double-count
  - ok=false (refused)      → bump refused counter, no backoff (steady-state)
  - ok=false (exec error)   → bump errored counter, bounded exp backoff

Sovereignty refusals are identified by canonical error prefixes emitted by
meta/executors/dispatch.ts ("sovereignty re-reckon:" /
"sovereignty snapshot stale ..."). Refusals are NOT treated as transient
faults — they are valid outcomes and do not trigger backoff.

The loop honors options.signal via AbortController throughout, including
inside the sleep helper, so SIGTERM from daemon/runtime/entrypoint.ts (PR #105)
unwinds cleanly through releaseLeadership.

tests/daemon/loop.spec.ts — real Neon integration. Seeds two pending intents
against the update_obligation_status executor, runs runLeaderLoop with
maxIntents=2, asserts:
  - both intents reach status='done'
  - each produces exactly one cc_actions_log row (attempt=1, key set, status='completed')
  - cc_obligations rows actually moved to 'deferred'
  - cc_node_leases shows leadership released on clean exit
  - log stream contains intent_heartbeat_before / intent_heartbeat_after pairs

Out of scope (not in this PR):
  - new executors (mercury, etc.)
  - production deploy
  - multi-node coordination beyond single-node leader
  - schema additions on cc_intents / cc_actions_log

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(health,wrangler): real-dependency /health probe + chittytrack tail consumer

The previous /health returned a static {status:"ok",...} regardless of
whether the worker could reach its real dependencies — a direct violation
of the chittyentity CLAUDE.md "No Mocks, Fake Data, or Placeholder
Endpoints" binding rule ("every endpoint must return real results against
a real datastore on the day it is committed").

This change replaces /health with a real probe that executes against the
worker's actual dependencies:

  * db            — SELECT 1 via Neon HTTP driver. Critical: failure -> 503.
  * chittyconnect — GET ${CHITTYCONNECT_URL}/health. Degraded if unreachable.
  * daemon        — newest cc_node_leases.heartbeat_at, stale if older than
                    2x daemon/loop.ts default heartbeatMs (10000ms ->
                    20000ms cutoff). Missing table -> not_provisioned
                    (degraded, NOT down) so deploys against bases without
                    #101 don't 503.

Per-dep timeout 2000ms; total probe bounded ≤ 5000ms via Promise.all.
Runs unauthenticated (no auth middleware on /health).

The probe handler is extracted to src/routes/health.ts so it can be
integration-tested in pure Node — importing src/index.ts directly drags
in `cloudflare:` modules (Agents SDK / DOs) that only resolve under
workerd. Integration test exercises the handler against a real Neon
branch (no mocks), validates DB probe ok and shape of all three probes,
and asserts 503 + status=down when DB is unreachable.

wrangler.jsonc already declares `tail_consumers: [{service: chittytrack}]`
(present on the base branch) — no change required there.

Verified against Neon branch br-spring-queen-akggkmso of project
cool-bar-13270800 (ChittyCommand). Sample real response:

{
  "status": "degraded",
  "service": "chittycommand",
  "version": "0.1.0",
  "timestamp": "2026-06-04T05:27:16.111Z",
  "probes": {
    "db": { "status": "ok", "latency_ms": 226 },
    "chittyconnect": {
      "status": "degraded", "latency_ms": 0,
      "error": "CHITTYCONNECT_URL not configured"
    },
    "daemon": {
      "status": "not_provisioned", "newest_heartbeat_age_ms": null,
      "error": "relation \"cc_node_leases\" does not exist"
    }
  }
}

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(health): query active leases by heartbeat_at, not released_at

Addresses Codex P2 on PR #109. The cc_node_leases schema in
src/db/schema.ts has no released_at column — release is represented by
NULLing heartbeat_at/lease_expires_at in daemon/leader.ts. The previous
WHERE released_at IS NULL clause raised 'column released_at does not
exist', which the catch block then mis-classified as 'not_provisioned',
so /health would never report ok/stale based on real heartbeats.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: chitcommit <noreply@chitty.cc>
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