Skip to content

Bind hook queue-full overflow hooks to Python - #15

Merged
LeStarch merged 8 commits into
fprime-community:mainfrom
lestarch-autobot:devin/1793293160-hook-port
Oct 29, 2026
Merged

LeStarch merged 8 commits into
fprime-community:mainfrom
lestarch-autobot:devin/1793293160-hook-port

Conversation

@lestarch-autobot

@lestarch-autobot lestarch-autobot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Binds FPP hook queue-full behavior to Python. When a component's queue is full, F Prime calls an overflow hook instead of queuing the message; this PR generates the C++ override that forwards each hook into Python plus a Python template stub.

Member Generated hook Arguments
async input port p: P hook p_overflowHook portNum + port args
internal port i(...) hook i_overflowHook internal port args
async command C(...) hook C_cmdOverflowHook opCode, cmdSeq only

Changes

  • view.py: OverflowHookView, a synthetic HandlerView for each hooked member, appended to ComponentView.handlers, so the existing generators emit the forwarding override and stub unchanged. The old "hook unsupported" rejection is removed.
  • component_generator.py: the generated init throws pybind11::attribute_error at startup if the Python class lacks any overflow hook (hooks only run on overflow, so a missing one would otherwise surface on the caller's thread at the worst moment). The lookup is on the class (so the base class's fall-through to the C++ object cannot satisfy it) and m_self is released before throwing. The command-hook template stub answers BUSY, since F Prime drops an overflowed command unanswered.
  • README.md: new "Queue-Full Overflow Hooks" section (naming, arguments, caller-thread/GIL cost, concurrency, buffer ownership, command response, exceptions); hook removed from the unsupported-features table.
  • Tests: tests/fixtures/Hooks.fpp + command stand-ins in tests/fixtures/Config.fpp; generator tests for hook signatures, GIL acquisition, Python stubs, the init check, and no hook for drop/unhooked members.
  • SDD: no change. The repo's only SDD (FprimePython/PythonRateGroupDriver/docs/sdd.md) covers the rate-group driver, not the autocoder; the README is the autocoder's design doc.

Not in scope

  • An exception raised inside a Python hook is not caught, the same as every other forwarded handler; a common exception boundary remains future work.

Validation

  • mypy (strict) clean; pytest tests 13/13.
  • fprime-python-reference with a temporary hook on PythonGc.referenceTracked and a hooked internal port: builds; integration tests 4/4; flooding a 10-deep queue with 64 internal messages called the Python hook 54 times.
  • Same deployment with referenceTracked_overflowHook removed from the Python class: setup raises PythonGc does not implement overflow hook referenceTracked_overflowHook. The reference fsw_main.py then calls teardown on the half-built topology, which asserts in BufferManager::cleanup (m_buffers != nullptr); that happens after any setup failure and is outside this PR.
  • Local multi-lens review (code, correctness, design, architecture, operational, docs, maintainability, tests, security, supply chain), nothing posted to GitHub; all must-fix findings addressed.

Co-authored-by: M Starch LeStarch@googlemail.com

Model each overflow hook as a HandlerView so the existing generators emit the forwarding C++ override and the Python stub; drop the unsupported-feature rejection.

Co-authored-by: M Starch <LeStarch@googlemail.com>
lestarch-autobot and others added 7 commits October 29, 2026 17:24
F Prime drops an overflowed command unanswered, so the template's command hook sends BUSY; hook kinds read as '<member kind> overflow hook'.

Co-authored-by: M Starch <LeStarch@googlemail.com>
Hooks.fpp fixture covers async input port, internal port and async command hooks, and a drop port that gets none; Config.fpp gains command port stand-ins.

Co-authored-by: M Starch <LeStarch@googlemail.com>
Co-authored-by: M Starch <LeStarch@googlemail.com>
The generated init checks the Python object implements every overflow hook, so a missing one fails at startup instead of at the first overflow on the caller's thread. OverflowHookView derives its own name and generated comment.

Co-authored-by: M Starch <LeStarch@googlemail.com>
Cover the GIL taken by each hook, the init check, an async command without hook, and avoid the 'msg' name that shadows a local in F Prime's internal port invoke.

Co-authored-by: M Starch <LeStarch@googlemail.com>
Co-authored-by: M Starch <LeStarch@googlemail.com>
…e throwing

Looking the hook up on the class keeps the base class's fall-through to the C++ object from satisfying it; releasing m_self first keeps it from outliving the interpreter when teardown is skipped. Pin the generated hook comments in the tests and rewrap long docstrings.

Co-authored-by: M Starch <LeStarch@googlemail.com>
@LeStarch
LeStarch merged commit ab2601b into fprime-community:main Oct 29, 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.

2 participants