Skip to content

Workflow builder v0.2.0: SQLite tracking, sub-agent loops, check-work tiering#49

Merged
TechNickAI merged 5 commits intomainfrom
workflow-builder-best-practices
Mar 29, 2026
Merged

Workflow builder v0.2.0: SQLite tracking, sub-agent loops, check-work tiering#49
TechNickAI merged 5 commits intomainfrom
workflow-builder-best-practices

Conversation

@TechNickAI
Copy link
Copy Markdown
Owner

Summary

  • Pattern 3 (Sub-Agent Orchestration): Added "never loop in orchestrator" rule — spawn sub-agents per item. Added check-work tiering pattern for high-frequency jobs (cheap model checks → expensive model acts).
  • Pattern 4 (State Externalization): Split into contextual state (markdown for reasoning) vs tracking state (SQLite for deduplication). Ban JSON for state files. Added schema versioning mechanism with per-workflow db-setup.md.
  • Contact steward: Migrated from processed.md to processed.db with automatic initialization, legacy migration path, and schema upgrade detection.

Test plan

  • Review workflow-builder SKILL.md patterns for clarity and completeness
  • Review contact-steward AGENT.md for correct processed.md → processed.db migration
  • Review db-setup.md schema definition and migration scenarios
  • Verify no remaining references to processed.md in contact-steward
  • Deploy to test instance and run contact-steward to verify DB initialization

🤖 Generated with Claude Code

Nick Sullivan and others added 3 commits March 29, 2026 12:57
… tiering

Three new best practices for workflow design:

- Pattern 3: Never loop over collections in orchestrator — spawn sub-agents per item
- Pattern 3: Check-work tiering — cheap model checks if work exists, expensive model acts
- Pattern 4: Split contextual state (markdown) vs tracking state (SQLite), ban JSON
- Pattern 4: Schema versioning mechanism with per-workflow db-setup.md

Contact steward migrated from processed.md to processed.db with schema versioning,
legacy migration path, and automatic initialization for new installs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- schema_meta: Add PRIMARY KEY + CHECK constraint to prevent duplicate rows
- Cleanup window: 90 days → 120 days to avoid race with 90-day scan window
- SKILL.md: Pattern 4 no longer says inline SQL — schema lives in db-setup.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SQLite has a built-in integer for version tracking in the database header.
No extra table, no constraints, no duplicate row risks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: cae6baf8b1

ℹ️ 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 on lines +238 to +239
Not in database and saved contact on platform? Check for enrichment (new messages
with contact-relevant info). If no new info, skip. e. Not a saved contact?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add path for tracked contacts with new messages

Step 5 makes enrichment conditional on Not in database and saved contact, which leaves a gap for contacts that are already in processed.db and then receive new messages: they do not match the skip branch (no new messages), the retry branch (status error), or the enrichment branch (not in database). In that common case, the workflow has no explicit action and can miss enrichment updates after the first run.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good catch. Fixed in bffd52e — step 5d no longer requires "not in database". Enrichment check now applies to all saved contacts with new messages regardless of DB state.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Incorrect — the merged code handles this at step 5b: "If found, not an error, and no new messages since last_checked → skip." Contacts with new messages fall through to step 5d (enrichment check). The bot was reading an intermediate diff revision, not the final merged code.

## Target Schema (Current: Version 1)

```sql
CREATE TABLE IF NOT EXISTS schema_meta (version INTEGER NOT 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.

P1 Badge Seed schema_meta version on initial schema creation

The target schema creates schema_meta but does not insert an initial version row. Since runtime logic checks schema_meta.version to decide whether setup/migration is needed, fresh databases can return an empty result and never reach a stable "version matches" state. Add an idempotent seed insert for version 1 during initialization.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Stale — db-setup.md and schema_meta table were both removed. Schema is now inline in AGENT.md, versioning uses PRAGMA user_version (no extra tables).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Incorrect — db-setup.md and the schema_meta table don't exist in the merged code. The final version uses PRAGMA user_version instead (set during creation at step 1 of the setup flow). Bot was commenting on an intermediate revision that was replaced before merge.

Nick Sullivan and others added 2 commits March 29, 2026 13:01
The LLM needs the schema in context to write queries — a separate file just
adds a read with no savings. Schema, setup, and migration all live in AGENT.md now.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Step 5d previously required "not in database AND saved contact" — so contacts
already in processed.db with new messages since last_checked had no explicit path.
Now enrichment check applies to all saved contacts regardless of DB state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TechNickAI TechNickAI merged commit 2d817fb into main Mar 29, 2026
10 checks passed
@TechNickAI TechNickAI deleted the workflow-builder-best-practices branch March 29, 2026 18:05
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

- **user_version lower than current** → apply any needed ALTER TABLE changes for the new
version, then update user_version
- **`processed.md` exists (legacy)** → create the database, migrate entries from the
markdown file into the processed table, archive as `processed.md.migrated`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Platform files still reference processed.md not processed.db

High Severity

The AGENT.md migrates tracking state from processed.md to processed.db (SQLite), but the platform-specific files that the agent reads each run still reference processed.md. Specifically, platforms/whatsapp.md (lines 168, 210), platforms/imessage.md (line 199), and platforms/quo.md (line 120) all instruct the agent to "check processed.md" or "log in processed.md". Since these are instructions for an LLM agent, the conflicting references will cause the agent to look for or write to the wrong state file during platform scanning.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good catch — fixed in #51. All 4 stale processed.md references updated to processed.db.

TechNickAI pushed a commit that referenced this pull request Mar 30, 2026
Platform scanner flows still referenced `processed.md` after PR #49
migrated tracking state to `processed.db` (SQLite). Updated all 4
references across whatsapp.md, imessage.md, and quo.md.

Caught by Cursor Bugbot.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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