Skip to content

Fix RecursionError crashes in JSON/Kconfig parsers, phantom JSONL events, add PyPI publish workflow and README example - #4

Merged
Jacobcdsmith merged 3 commits into
mainfrom
copilot/review-for-pptential
Aug 15, 2026
Merged

Fix RecursionError crashes in JSON/Kconfig parsers, phantom JSONL events, add PyPI publish workflow and README example#4
Jacobcdsmith merged 3 commits into
mainfrom
copilot/review-for-pptential

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Three bugs that violate the "nothing is silently dropped" contract, plus two adoption improvements.

Bugs fixed

Unbounded recursion in JSON and Kconfig parsers

Both json_parser.py and kconfig.py used recursive inner visit() closures. At ~950 nesting levels, Python raises RecursionError, which session_scope catches, rolls back the entire batch transaction, and re-raises — leaving every file in that batch with no artifact record and no diagnostic. Fixed by converting both to explicit stack-based iterative traversal.

Phantom JSONL events on DB commit failure

append_event wrote to events.jsonl inside the session_scope try block, before session.commit(). A failed commit rolled back SQLite but left the JSONL file with a record of an event that never happened. Fixed by moving the write into a SQLAlchemy after_commit hook — the file is only touched after the transaction durably commits. OSError on the post-commit write is suppressed (event is already safe in SQLite; JSONL is a best-effort mirror).

@event.listens_for(session, "after_commit", once=True)
def _write_jsonl(_session: Session) -> None:
    try:
        with events_path.open("a", encoding="utf-8") as f:
            f.write(line + "\n")
    except OSError:
        pass  # DB commit succeeded; JSONL mirror is best-effort

Regression tests added for both parsers at 1,100-level nesting depth.

Adoption improvements

PyPI publish workflow

.github/workflows/publish.yml — OIDC trusted-publisher; triggers on GitHub Release creation. No stored secrets required; one-time setup documented in the workflow file comments.

README worked example

Added a concrete five-command walkthrough showing CONFIG_WIFI_POWER_SAVE traced across a Kconfig tree, Markdown changelog, and PDF release notes — illustrating the cross-document trace value proposition immediately on landing.

Copilot AI and others added 2 commits August 10, 2026 01:54
…ow, README example

Co-authored-by: Jacobcdsmith <88069592+Jacobcdsmith@users.noreply.github.com>
…rkflow permissions

Co-authored-by: Jacobcdsmith <88069592+Jacobcdsmith@users.noreply.github.com>
Copilot AI changed the title Fix recursion bugs, add PyPI publish workflow, and add README worked example Fix RecursionError crashes in JSON/Kconfig parsers, phantom JSONL events, add PyPI publish workflow and README example Aug 10, 2026
Copilot AI requested a review from Jacobcdsmith August 10, 2026 01:58
@Jacobcdsmith
Jacobcdsmith marked this pull request as ready for review August 13, 2026 01:15
Copilot AI lite review requested due to automatic review settings August 13, 2026 01:15

Copilot AI 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.

Pull request overview

This pull request addresses reliability issues in the JSON and Kconfig parsers (avoiding RecursionError on deeply nested inputs) and fixes event-mirroring correctness so JSONL event records are not written when the DB transaction fails. It also improves adoption by adding a PyPI publish workflow and a concrete README walkthrough.

Changes:

  • Replace recursive traversal in json_parser.py and kconfig.py with an explicit stack-based traversal to avoid Python recursion limits.
  • Prevent “phantom” JSONL events by deferring events.jsonl writes until SQLAlchemy after_commit.
  • Add regression tests for 1,100-level nesting, plus a PyPI publish workflow and a README worked example.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/kairos/infrastructure/parsers/json_parser.py Switch JSON traversal to iterative stack walk to avoid recursion depth crashes; adjusts containment emission to work without recursion.
src/kairos/infrastructure/parsers/kconfig.py Switch Kconfig menu-tree traversal to iterative stack walk to avoid recursion depth crashes.
src/kairos/services/events.py Write JSONL event mirror only after a successful DB commit via after_commit hook.
tests/unit/test_parsers_json.py Add regression test ensuring deeply nested JSON parses without RecursionError.
tests/unit/test_parsers_kconfig.py Add regression test ensuring deeply nested Kconfig JSON parses without RecursionError.
README.md Add a concrete “worked example” walkthrough demonstrating cross-document tracing.
.github/workflows/publish.yml Add GitHub Release-triggered PyPI publish workflow using OIDC trusted publishing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/kairos/infrastructure/parsers/json_parser.py Outdated
Comment thread src/kairos/infrastructure/parsers/json_parser.py Outdated
Comment on lines +53 to +55
permissions:
id-token: write # required for OIDC trusted-publisher upload

Comment on lines +11 to +15
# Publisher: GitHub Actions
# Owner: Jacobcdsmith
# Repository: kairos
# Workflow name: publish.yml
# Environment name: pypi

@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: c6453bf369

ℹ️ 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 README.md
Comment on lines +181 to +182
└─ heading_contains ──► [span] lines:40-50
docs/changelog.md ← crossed document boundary

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 Correct the trace walkthrough's cross-document edge

In the walkthrough as written, once the Kconfig JSON is ingested, kairos trace CONFIG_WIFI_POWER_SAVE --depth 3 will seed from the exact Kconfig entity and return before the FTS fallback (src/kairos/services/trace.py:95-100), while Markdown only creates heading entities/mentions and the paragraph hit shown above is just a span (src/kairos/infrastructure/parsers/text_markdown.py:103-115). That means the changelog/PDF search hits are not in the trace frontier, so the documented heading_contains edge into docs/changelog.md won't appear for users copying these commands unless the example starts from a span/heading shared by the docs or the trace seeding behavior changes.

Useful? React with 👍 / 👎.

@Jacobcdsmith

Copy link
Copy Markdown
Owner

@copilot Fix the code for all comments in this review thread.

When a review comment includes a suggested change, apply the suggestion exactly.

Do not make changes beyond what is described in the linked review thread.

…ons and placeholder owner

Co-authored-by: Jacobcdsmith <88069592+Jacobcdsmith@users.noreply.github.com>

Copilot AI commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the code for all comments in this review thread.

When a review comment includes a suggested change, apply th...

All four review items addressed in the latest commit:

  1. json_parser.py line 67 — corrected "BFS/DFS" to "DFS".
  2. json_parser.py line 119 — replaced reversed(list(value.keys())) with reversed(value) to avoid the intermediate list allocation.
  3. publish.yml lines 53-55 — added contents: read alongside id-token: write in the publish job permissions.
  4. publish.yml lines 11-15 — replaced hard-coded Jacobcdsmith/kairos with <your-github-owner>/<your-repo-name> placeholders.

@Jacobcdsmith
Jacobcdsmith merged commit e5076a0 into main Aug 15, 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.

3 participants