Skip to content

feat(dry-run): implement /internal/scheduler/dry-run-replay (was a v0.1 stub)#14

Merged
ComBba merged 1 commit into
mainfrom
feat/dry-run-replay
May 12, 2026
Merged

feat(dry-run): implement /internal/scheduler/dry-run-replay (was a v0.1 stub)#14
ComBba merged 1 commit into
mainfrom
feat/dry-run-replay

Conversation

@ComBba
Copy link
Copy Markdown
Contributor

@ComBba ComBba commented May 12, 2026

Hard lock #3 (dry-run preview before Activate) was a no-op. Now the scheduled job — kicked off when a rule is compiled into the draft — replays the most recent posts through that draft rule (pure evaluation, zero actions) and writes a ${sub}:dryrun:${ruleId} summary the Dashboard renders.

  • Samples ≤10 recent posts via reddit.getNewPosts({subredditName, limit}).all()buildPostFactBagselectMatchingRules([rule], 'onPostSubmit'|'onPostReport', facts).
  • Comment-only rule → status: 'unavailable' with a "shadow-mode it to see real comments" note (v0.1 has no getNewComments).
  • Any Reddit-API/rule failure → status: 'unavailable' with the error in the note; always returns {status:'ok'} (scheduler jobs must not throw). Result TTL 7d.
  • Dashboard: new "Dry-run preview (draft rules): r_x: would match N/M recent post(s) → modqueue" section, reading ${sub}:dryrun:${id} per draft rule.

Tests: +6 in routes-scheduler.test.ts, +1 in routes-dashboard.test.ts, getNewPosts double in test/devvit-testkit.ts. 157 tests pass; tsc/lint/format clean; acceptance 4/4; vite build → loadable CJS.

(Still pending of the original 'cover everything' list: @devvit/test adoption, fast-check PBT, marketingAssets.icon, hackathon-audit run — separate PRs.)

🤖 Generated with Claude Code

….1 stub)

Hard lock #3 — dry-run preview before Activate — was previously a no-op. Now,
when a rule is compiled into the draft, the scheduled job replays the most
recent posts through that draft rule (pure evaluation, ZERO actions), and writes
a `${sub}:dryrun:${ruleId}` summary { status, sampledPosts, matched:[{thingId,
authorName, would:[actions]}], note } that the Dashboard renders ("Dry-run
preview (draft rules): r_x: would match N/M recent post(s) → modqueue").

- Samples up to 10 recent posts via reddit.getNewPosts({subredditName, limit}).all()
  → buildPostFactBag → selectMatchingRules([rule], 'onPostSubmit'|'onPostReport', facts).
- A comment-only rule (no post trigger) gets status 'unavailable' with a
  "shadow mode it to see real comments" note (v0.1 has no getNewComments).
- Any Reddit-API/rule failure → status 'unavailable' with the error in the note;
  the handler always returns { status: 'ok' } (never throws — scheduler jobs must).
- Result TTL 7 days. Dashboard reads `${sub}:dryrun:${id}` for each draft rule id.

Tests: routes-scheduler.test.ts gains 6 cases (no-draft, post-rule with matches,
zero matches, comment-only, Reddit-API failure, missing ruleId);
routes-dashboard.test.ts gains a dry-run-display case. test/devvit-testkit.ts
gains a `getNewPosts` double. 157 tests pass; tsc/lint/format clean; acceptance 4/4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Warning

Rate limit exceeded

@ComBba has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 45 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91757467-693e-42a4-ada6-d8992677fca2

📥 Commits

Reviewing files that changed from the base of the PR and between ba31ce6 and fe03f35.

📒 Files selected for processing (5)
  • src/server/index.ts
  • src/server/routes-dashboard.test.ts
  • src/server/routes-scheduler.test.ts
  • test/devvit-testkit.ts
  • test/setup.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/dry-run-replay

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.

@ComBba ComBba merged commit 8235d4d into main May 12, 2026
2 checks passed
@ComBba ComBba deleted the feat/dry-run-replay branch May 12, 2026 11:43
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a dry-run preview feature for draft rules, allowing moderators to see how new rules would have matched against recent posts before activation. The implementation includes a new scheduler endpoint to perform the replay, dashboard updates to display results, and comprehensive tests. Feedback focuses on correcting the use of the selftext property for post content (instead of body), adding error handling for JSON parsing of Redis data to prevent dashboard crashes, and ensuring the scheduler uses the provided subreddit name from the task payload.

Comment thread src/server/index.ts
{
id: p.id,
title: p.title,
body: p.body ?? '',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

In the Devvit SDK, the content of a post is stored in the selftext property, not body. Using p.body will result in an empty string for all sampled posts, causing the dry-run evaluation to be inaccurate for rules that inspect post content.

Suggested change
body: p.body ?? '',
body: p.selftext ?? '',

Comment thread src/server/index.ts
for (const r of draft?.rules ?? []) {
const raw = await redis.get(`${subredditName}:dryrun:${r.id}`);
if (!raw) continue;
const d = JSON.parse(raw) as DryRunResult;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Parsing JSON from Redis without a try-catch block can lead to a full application crash if the stored data is malformed or corrupted. Since this is in the dashboard route, it would prevent moderators from accessing the tool's management interface.

    let d: DryRunResult;
    try {
      d = JSON.parse(raw) as DryRunResult;
    } catch (e) {
      continue;
    }

Comment thread src/server/index.ts
// Full implementation reads rules:draft, builds factBags, evaluates, writes simulated audits.
const body = await c.req.json<TaskRequest<{ ruleId: string; subredditName: string }>>();
const ruleId = body.data?.ruleId;
const sub = getCurrentSubredditName();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The subredditName is explicitly passed in the task payload (body.data). It is safer to use the passed value as the primary source, falling back to the context helper if necessary, to ensure the job operates on the intended subreddit data.

Suggested change
const sub = getCurrentSubredditName();
const sub = body.data?.subredditName ?? getCurrentSubredditName();

const post = (id: string, over: Record<string, unknown> = {}) => ({
id,
title: 'a title',
body: 'a body',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The test mock should use selftext instead of body to accurately reflect the structure of a Reddit Post object in the Devvit SDK. This ensures the tests are validating the actual runtime behavior.

Suggested change
body: 'a body',
selftext: 'a body',

ComBba added a commit that referenced this pull request May 15, 2026
feat(dry-run): implement /internal/scheduler/dry-run-replay (was a v0.1 stub)
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