MCPcopy Create free account
hub / github.com/MetapriseAI/OrgKernel / close_chain

Function close_chain

src/orgkernel/pyapi/router.py:731–754  ·  view source on GitHub ↗

Close an AuditChain. Writes the terminal entry and marks the chain as closed. Call this when a mission enters the CLOSED state.

(
    chain_id: str,
    db: Annotated[AsyncSession, Depends(get_db)],
)

Source from the content-addressed store, hash-verified

729 description="Close an AuditChain (no further entries may be appended).",
730)
731async def close_chain(
732 chain_id: str,
733 db: Annotated[AsyncSession, Depends(get_db)],
734) -> dict:
735 """
736 Close an AuditChain.
737
738 Writes the terminal entry and marks the chain as closed.
739 Call this when a mission enters the CLOSED state.
740 """
741 svc = AuditChainService()
742 try:
743 chain = await svc.close(db, chain_id)
744 return {
745 "chain_id": chain.chain_id,
746 "mission_id": chain.mission_id,
747 "agent_id": chain.agent_id,
748 "entry_count": len(chain.entries),
749 "head_hash": chain.head_hash,
750 "closed_at": chain.closed_at.isoformat() if chain.closed_at else None,
751 "message": "AuditChain closed",
752 }
753 except ValueError as e:
754 raise HTTPException(status_code=400, detail=str(e))
755
756
757@_audit.get(

Callers

nothing calls this directly

Calls 2

closeMethod · 0.95
AuditChainServiceClass · 0.90

Tested by

no test coverage detected