Skip to content

feat: add spec_id field for linking issues to specification documents#1372

Closed
anupamchugh wants to merge 1 commit intosteveyegge:mainfrom
anupamchugh:feature/spec-id
Closed

feat: add spec_id field for linking issues to specification documents#1372
anupamchugh wants to merge 1 commit intosteveyegge:mainfrom
anupamchugh:feature/spec-id

Conversation

@anupamchugh
Copy link

Summary

Adds first-class spec linking to beads, addressing #976.

Instead of manually embedding doc references in --desc, users can now use a dedicated spec_id field:

# Link issue to spec document
bd create "Implement auth flow" --spec-id "docs/plans/auth-design.md"

# Filter by spec (or prefix)
bd list --spec "docs/plans/"

# Show displays the linked spec
bd show bd-xxx
# Output includes: Spec: docs/plans/auth-design.md

Changes

  • Add spec_id field to Issue type
  • Migration 041 adds column + index
  • --spec-id and --spec flags on create/update
  • --spec filter on list (prefix matching)
  • Spec displayed in bd show

Testing

bd create "Test" --spec-id "specs/test.md"
bd list --spec "specs/"
bd show bd-xxxx

Closes #976

Copy link
Owner

@steveyegge steveyegge left a comment

Choose a reason for hiding this comment

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

PR Review: Reject — Critical bugs from bad rebase

Recommendation: Reject (needs rework)

The feature concept (first-class spec linking) is reasonable, but this PR has multiple critical bugs that appear to result from a bad rebase or merge conflict resolution. It cannot be merged as-is and would break the build.


Critical Bugs

1. SQL syntax error in CloseIssue (2 locations)

Both queries.go and transaction.go change:

UPDATE issues SET ... closed_by_session = ?

to:

UPDATE issues SET ... closed_by_session = ? = NULL

= ? = NULL is invalid SQL. This breaks all issue closing, not just spec-related functionality.

2. Scan/SELECT column mismatches (3+ locations)

The diff removes scan arguments without replacing them, causing the number of Scan() args to not match the number of selected columns. This will panic at runtime.

  • GetIssue (queries.go): &dueAt, &deferUntil removed from Scan, &specID never added. SELECT has due_at, defer_until, spec_id — 3 columns with 0 scan targets.
  • GetIssueByExternalRef (queries.go): &awaitType, &awaitID, &timeoutNs, &waiters removed from Scan but spec_id added to SELECT — 5 columns with 0 scan targets.
  • scanIssueRow (transaction.go): Same pattern — &dueAt, &deferUntil removed, &specID never added.

3. INSERT value/placeholder mismatches (4 functions)

In insertIssue, insertIssueStrict, insertIssues, and insertIssuesStrict:

  • Column list adds spec_id (+1 column) and placeholder count goes from 40 to 42 (+2 placeholders)
  • But issue.DueAt, issue.DeferUntil values are deleted and issue.SpecID is never added
  • Result: 42 placeholders with ~38 values — will not compile or will crash

4. Non-existent spec_changed_at column scanned

scanIssues and scanIssuesWithDependencyType in dependencies.go declare and scan specChangedAt sql.NullTime, but:

  • The SELECT does not include spec_changed_at
  • The migration does not create a spec_changed_at column
  • The schema does not define it

This will panic on every dependency query.


Medium Issues

5. Undeclared struct fields referenced in tests

list_filters_test.go references args.SpecChanged and filter.SpecChanged, but:

  • SpecChanged is not defined on ListArgs
  • SpecChanged is not defined on IssueFilter

This will not compile.

6. Phantom features documented but not implemented

CLI_REFERENCE.md documents several features with no backing code:

  • bd spec scan, bd spec list, bd spec show, bd spec coverage — no spec.go command file exists
  • --spec-changed flag on bd list — not registered in list.go init()

Minor Issues

7. Excessive whitespace reformatting

A large portion of the diff is alignment changes to unrelated struct fields, constants, and comments across protocol.go, types.go, etc. This creates unnecessary merge conflicts and makes the actual changes harder to review. Cosmetic reformatting should be in a separate commit or omitted entirely.


Summary

The core idea (linking issues to spec documents via spec_id) is fine and the migration is clean. But the implementation has at least 4 categories of bugs that would crash the application on basic operations (closing issues, querying issues, inserting issues, dependency queries). These look like artifacts of a bad rebase where conflict markers were resolved incorrectly.

Recommendation: Start fresh from current main, apply only the intended changes, and verify with go build ./... and go test ./... before resubmitting.

@anupamchugh
Copy link
Author

anupamchugh commented Jan 30, 2026

Fixed the spec_id PR on a fresh branch from upstream/main

  • Added spec_id column + migration + schema/index
  • Updated inserts/selects/scans and content hash
  • Added CLI flags (--spec-id, --spec) and show output
  • Added spec_id prefix filter and tests

Tests:

  • go build ./... (pass)
  • go test ./internal/storage/sqlite -run TestSearchIssues (pass)
  • go test ./... (fails: internal/compact/compactor_unit_test.go:271:24 undefined: Result; appears unrelated)

@steveyegge
Copy link
Owner

PR Sheriff note: Contributor has pushed a new commit since the changes-requested review. Quick scan shows the critical bugs from the review appear to be addressed:

  • = ? = NULL SQL syntax error: no longer present
  • Phantom spec_changed_at column: removed
  • Undeclared SpecChanged fields: removed
  • Phantom bd spec subcommands: removed

This is a feature PR (adding spec_id field), so flagging for human re-review rather than auto-approving. The diff is much cleaner now - focused on adding spec_id to create/update/list/show without the rebase artifacts.

Copy link
Owner

@steveyegge steveyegge left a comment

Choose a reason for hiding this comment

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

PR Sheriff: APPROVE (re-review)

All critical issues from the previous review have been addressed:

  1. SQL syntax error = ? = NULL — Fixed ✅
  2. Scan/SELECT column mismatches — Fixed, spec_id properly added to all SELECT and Scan calls ✅
  3. INSERT value/placeholder mismatches — Fixed, column/placeholder/value counts all match ✅
  4. Non-existent spec_changed_at — Removed ✅
  5. Undeclared SpecChanged struct fields — Removed ✅
  6. Phantom bd spec CLI commands — Removed from docs ✅

Feature implementation is clean and follows the existing external_ref pattern:

  • SpecID field on Issue type with content hash inclusion
  • SQLite migration 041 + Dolt schema update
  • All storage backends (sqlite, dolt, memory) properly handle spec_id
  • CLI: --spec-id on create/update, --spec filter on list, displayed in show
  • Tests cover spec_id prefix filtering

Minor note: Excessive whitespace reformatting in protocol.go, types.go, etc. (cosmetic, not blocking).

@steveyegge
Copy link
Owner

Hi @anupamchugh — this PR is approved but now has merge conflicts after #1464 was merged (CI fix that touched some of the same query files). Could you rebase onto current main to resolve the conflicts? Once the conflicts are resolved, we can merge.

steveyegge added a commit that referenced this pull request Feb 3, 2026
…#1372)

Add first-class spec linking to beads (closes #976):
- Add spec_id field to Issue type
- Migration adds column + index
- --spec-id flag on create/update, --spec filter on list
- Spec displayed in bd show

Original-Author: anupamchugh <[email protected]>
Co-Authored-By: anupamchugh <[email protected]>
@steveyegge
Copy link
Owner

Rebased onto main (resolved conflicts with metadata column), tested, and merged locally with attribution. Thanks for the contribution!

@steveyegge
Copy link
Owner

Closing as superseded — these changes were already merged to main (commit cf185ce). Thank you for the contribution!

@steveyegge steveyegge closed this Feb 3, 2026
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.

Question: Best practices for using Beads alongside detailed planning docs

2 participants

Comments